Awali
Another Weighted Automata library
tupleset.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2021 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_LABELSET_TUPLESET_HH
18 # define AWALI_LABELSET_TUPLESET_HH
19 
20 # include <iosfwd>
21 # include <istream>
22 # include <set>
23 # include <tuple>
24 
25 #include <awali/common/version.hh>
26 
27 #include <awali/sttc/config.hh> // AWALI_HAVE_CORRECT_LIST_INITIALIZER_ORDER
29 //#include <awali/sttc/labelset/labelset.hh>
31 #include <awali/sttc/misc/raise.hh>
33 #include <awali/sttc/core/kind.hh>
34 
35 #include <awali/common/tuple.hh>
36 #include <awali/sttc/misc/cross.hh>
37 #include <awali/sttc/misc/raise.hh>
38 #include <awali/sttc/misc/zip.hh>
42 
43 namespace awali {
44  namespace sttc {
45 
46  namespace internal
47  {
52  template <typename Enable = void, typename... ValueSets>
54  {
55  using genset_t = void;
56  using letter_t = void;
57  using word_t = void;
58  };
59 
61  template <typename... ValueSets>
62  struct labelset_types<decltype(pass{typename ValueSets::word_t()...}, void()),
63  ValueSets...>
64  {
65  using genset_t = internal::cross_sequences<decltype(std::declval<ValueSets>().genset())...>;
66  using letter_t = std::tuple<typename ValueSets::letter_t...>;
67  using word_t = std::tuple<typename ValueSets::word_t...>;
68  };
69  }
70 
71  template <typename... ValueSets>
72  using labelset_types = internal::labelset_types<void, ValueSets...>;
73 
78  template <typename... ValueSets>
79  class tupleset
80  {
81  public:
82  using valuesets_t = std::tuple<ValueSets...>;
83  using indices_t = awali::internal::make_index_sequence<sizeof...(ValueSets)>;
84  static constexpr indices_t indices{};
85  template <std::size_t... I>
87 
89  template <std::size_t I>
90  using valueset_t = typename std::tuple_element<I, valuesets_t>::type;
91 
92  public:
94  using is_tupleset_t = bool;
95 
97  using value_t = std::tuple<typename ValueSets::value_t...>;
98 
100  using letter_t = typename labelset_types<ValueSets...>::letter_t;
102  using genset_t = typename labelset_types<ValueSets...>::genset_t;
104  using word_t = typename labelset_types<ValueSets...>::word_t;
105 
108 
110 
112  : sets_(vs)
113  {}
114 
115  tupleset(ValueSets... ls)
116  : sets_(ls...)
117  {}
118 
119  static std::string sname()
120  {
121  return sname_(indices);
122  }
123 
124  std::string vname(bool full = true) const
125  {
126  return vname_(full, indices);
127  }
128 
129  static constexpr std::size_t size()
130  {
131  return sizeof...(ValueSets);
132  }
133 
134  template <std::size_t... I>
135  static constexpr bool
137  {
138  return all_<valueset_t<I>::is_commutative_semiring()...>();
139  }
140 
142  static tupleset make(std::istream& is)
143  {
144  // name: lat<law_char(abc), law_char(xyz)>
145  kind_t::make(is);
146  auto res = make_(is, indices);
147  eat(is, '>');
148  return res;
149  }
150 
152  const valuesets_t& sets() const
153  {
154  return sets_;
155  }
156 
158  template <size_t I>
159  const valueset_t<I>& set() const
160  {
161  return std::get<I>(sets());
162  }
163 
167  bool open(bool o) const
168  {
169  return open_(o, indices);
170  }
171 
173  template <typename... Args>
174  value_t value(const std::tuple<Args...>& args) const
175  {
176  return value_(args, indices);
177  }
178 
180  genset_t
181  genset() const
182  {
183  return genset_(indices);
184  }
185 
186  static constexpr bool is_free()
187  {
188  return is_free_(indices);
189  }
190 
191  private:
193  template <typename Value, std::size_t... I>
194  static auto
195  letters_of_(const Value& v, seq<I...>)
196  -> decltype(internal::zip(valueset_t<I>::letters_of(std::get<I>(v))...))
197  {
198  return internal::zip(valueset_t<I>::letters_of(std::get<I>(v))...);
199  }
200 
201  public:
207  template <typename Value>
208  static auto
209  letters_of(const Value& v)
210  -> decltype(letters_of_(v, indices))
211  {
212  return letters_of_(v, indices);
213  }
214 
216  template <typename... Args>
217  auto
218  word(const std::tuple<Args...>& v) const
219  -> word_t
220  {
221  return word_(v, indices);
222  }
223 
224  static bool
225  equals(const value_t& l, const value_t& r)
226  {
227  return equals_(l, r, indices);
228  }
229 
231  static bool
232  less_than(const value_t& l, const value_t& r)
233  {
234  return less_than_(l, r, indices);
235  }
236 
237  static value_t
239  {
240  return special_(indices);
241  }
242 
243  static bool
244  is_special(const value_t& l)
245  {
246  return is_special_(l, indices);
247  }
248 
249  value_t
250  zero() const
251  {
252  return zero_(indices);
253  }
254 
255  bool
256  is_zero(const value_t& l) const
257  {
258  return is_zero_(l, indices);
259  }
260 
261  static constexpr bool
263  {
264  return has_one_(indices);
265  }
266 
267  static constexpr bool
269  {
270  return is_ratexpset_(indices);
271  }
272 
273  static constexpr bool
275  {
276  return is_letterized_(indices);
277  }
278 
279  static value_t
280  one()
281  {
282  return one_(indices);
283  }
284 
285  static bool
286  is_one(const value_t& l)
287  {
288  return is_one_(l, indices);
289  }
290 
291  static bool
293  {
294  return show_one_(indices);
295  }
296 
297  bool
298  is_letter(const value_t&) const
299  {
300  return false;
301  }
302 
303  value_t
304  add(const value_t& l, const value_t& r) const
305  {
306  return add_(l, r, indices);
307  }
308 
309  value_t
310  mul(const value_t& l, const value_t& r) const
311  {
312  return mul_(l, r, indices);
313  }
314 
315  value_t
316  rdiv(const value_t& l, const value_t& r) const
317  {
318  return rdiv_(l, r, indices);
319  }
320 
321  value_t
322  ldiv(const value_t& l, const value_t& r) const
323  {
324  return ldiv_(l, r, indices);
325  }
326 
327  value_t
328  star(const value_t& l) const
329  {
330  return star_(l, indices);
331  }
332 
338  template <typename Value>
339  Value
340  delimit(const Value& l) const
341  {
342  return delimit_(l, indices);
343  }
344 
346  template <typename Value>
347  Value
348  undelimit(const Value& l) const
349  {
350  return undelimit_(l, indices);
351  }
352 
353  // FIXME: this needs to be computed.
354  static constexpr star_status_t star_status()
355  {
357  }
358 
359  template <typename LhsValue, typename RhsValue>
360  word_t
361  concat(const LhsValue& l, const RhsValue& r) const
362  {
363  return concat_(l, r, indices);
364  }
365 
366  value_t
367  transpose(const value_t& l) const
368  {
369  return transpose_(l, indices);
370  }
371 
372  static size_t
373  hash(const value_t& v)
374  {
375  return hash_(v, indices);
376  }
377 
378  static value_t
380  {
381  return v;
382  }
383 
384  template<typename T>
385  value_t
386  conv(const T& tset, typename T::value_t v) const
387  {
388  return conv_(tset, v, indices);
389  }
390 
391  value_t
392  conv(b, b::value_t v) const
393  {
394  return v ? one() : zero();
395  }
396 
398  value_t
399  conv(std::istream& i) const
400  {
401  value_t res = conv_(i, indices);
402  eat(i, ']');
403  return res;
404  }
405 
406  std::set<value_t> convs(std::istream&) const
407  {
408  raise("tupleset: ranges not implemented");
409  }
410 
411  std::ostream&
412  print_set(std::ostream& o, const std::string& format = "text") const
413  {
414  return print_set_(o, format, indices);
415  }
416 
417 
418  template<unsigned version = version::fsm_json>
420  const
421  {
422  switch (version) {
423  case 0:
424  throw parse_exception("[tupleset] Unsupported fsm-json version:"
425  + std::to_string(version));
426  case 1:
427  default:
428  return to_json<version>(indices);
429  }
430  }
431 
432 
433  template<unsigned version = version::fsm_json>
435  const
436  {
437  switch (version) {
438  case 0:
439  throw parse_exception("[tupleset] Unsupported fsm-json version:"
440  + std::to_string(version));
441  case 1:
442  default:
443  return value_to_json<version>(v, indices);
444  }
445  }
446 
447 
448 
449  template <unsigned version, std::size_t... I>
450  value_t
451  value_from_json(std::vector<json::node_t*> const& v, seq<I...>)
452  const
453  {return value_t{set<I>().template value_from_json<version>(v[I])...};}
454 
455 
456  template<unsigned version = version::fsm_json>
457  value_t
459  {
460  return value_from_json<version>(p->array()->values, indices);
461  }
462 
463  value_t
464  parse(const std::string& s, size_t& p, bool fixed_domain=true) const {
465  if(s[--p]!=']')
466  throw parse_exception("Invalid tuple");
467 # if AWALI_HAVE_CORRECT_LIST_INITIALIZER_ORDER
468  value_t r= parse_(s, p, fixed_domain, typename awali::internal::reverseseq<typename indices_t::type>::type());
469 #else
470  value_t r= parse_(s, p, fixed_domain, indices);
471 #endif
472  if(s[--p]!='[')
473  throw parse_exception("Invalid tuple");
474  return r;
475  }
476 
477  template <std::size_t... I>
478  void comma(const std::string& s, size_t& p, char& c) const {
479  if(c=='x') {
480  c=',';
481  return;
482  }
483  if(s[--p]!=',')
484  throw parse_exception("Invalid letter");
485  }
486 
487  template <std::size_t... I>
488  value_t
489  parse_(const std::string& s, size_t& p, bool fixed_domain, seq<I...>) const {
490  char c = 'x';
491 # if AWALI_HAVE_CORRECT_LIST_INITIALIZER_ORDER
492  value_t r=
493  awali::internal::make_inv_tuple((comma<I>(s, p, c),
494  std::get<I>(sets_).parse(s,p,fixed_domain))...);
495 #else
496  value_t r = std::make_tuple((comma<I>(s, p, c),
497  set<I>().parse(s,p,fixed_domain))...);
498 #endif
499  return r;
500  }
501 
502 
503  std::ostream&
504  print(const value_t& l, std::ostream& o,
505  const std::string& format = "text") const
506  {
507  return print_(l, o, format, indices);
508  }
509 
510  private:
511  template <std::size_t... I>
512  static std::string sname_(seq<I...>)
513  {
514  std::string res = "lat<";
515  const char *sep = "";
516  for (auto n: {valueset_t<I>::sname()...})
517  {
518  res += sep;
519  res += n;
520  sep = ",";
521  }
522  res.push_back('>');
523  return res;
524  }
525 
526  template <typename T, std::size_t... I>
527  value_t
528  conv_(const T& tset, typename T::value_t v, seq<I...>) const
529  {
530  return std::make_tuple(std::get<I>(this->sets()).conv(std::get<I>(tset.sets()),std::get<I>(v))...);
531  }
532 
533 
534  template <std::size_t... I>
535  std::string vname_(bool full, seq<I...>) const
536  {
537  std::string res = "lat<";
538  const char *sep = "";
539  for (auto n: {set<I>().vname(full)...})
540  {
541  res += sep;
542  res += n;
543  sep = ",";
544  }
545  res.push_back('>');
546  return res;
547  }
548 
549  template <std::size_t... I>
550  static tupleset make_(std::istream& i, seq<I...>)
551  {
552 # if AWALI_HAVE_CORRECT_LIST_INITIALIZER_ORDER
553  return tupleset{(eat_separator_<I>(i, '<', ','),
554  valueset_t<I>::make(i))...};
555 # else
556  return make_inv_tuple
557  ((eat_separator_<sizeof...(ValueSets)-1 -I>(i, '<', ','),
558  valueset_t<sizeof...(ValueSets)-1 -I>::make(i))...);
559 # endif
560  }
561 
562  template <std::size_t... I>
563  bool open_(bool o, seq<I...>) const
564  {
565  using swallow = int[];
566  (void) swallow { set<I>().open(o)... };
567  std::swap(o, open__);
568  return o;
569  }
570 
571  template <typename... Args, std::size_t... I>
572  value_t value_(const std::tuple<Args...>& args, seq<I...>) const
573  {
574  return value_t{set<I>().value(std::get<I>(args))...};
575  }
576 
577  template <std::size_t... I>
578  genset_t
579  genset_(seq<I...>) const
580  {
581  return internal::cross(set<I>().genset()...);
582  }
583 
584  template <std::size_t... I>
585  static constexpr bool
586  is_free_(seq<I...>)
587  {
588  return all_<valueset_t<I>::is_free()...>();
589  }
590 
591  template <typename... Args, std::size_t... I>
592  word_t
593  word_(const std::tuple<Args...>& l, seq<I...>) const
594  {
595  return word_t{set<I>().word(std::get<I>(l))...};
596  }
597 
598  template <std::size_t... I>
599  static bool
600  equals_(const value_t& l, const value_t& r, seq<I...>)
601  {
602  for (auto n: {valueset_t<I>::equals(std::get<I>(l),
603  std::get<I>(r))...})
604  if (!n)
605  return false;
606  return true;
607  }
608 
609  template <std::size_t... I>
610  static bool
611  less_than_(const value_t& l, const value_t& r, seq<I...>)
612  {
613  for (auto n: {std::make_pair(valueset_t<I>::less_than(std::get<I>(l),
614  std::get<I>(r)),
615  valueset_t<I>::less_than(std::get<I>(r),
616  std::get<I>(l)))...})
617  if (n.first)
618  return true;
619  else if (n.second)
620  return false;
621  return false;
622  }
623 
624  template <std::size_t... I>
625  static std::size_t
626  hash_(const value_t& v, seq<I...>)
627  {
628  std::size_t res = 0;
629  for (auto h: {valueset_t<I>::hash(std::get<I>(v))...})
630  std::hash_combine(res, h);
631  return res;
632  }
633 
634  template <std::size_t... I>
635  static value_t
636  special_(seq<I...>)
637  {
638  return std::make_tuple(valueset_t<I>::special()...);
639  }
640 
641  template <std::size_t... I>
642  static bool
643  is_special_(const value_t& l, seq<I...>)
644  {
645  for (auto n: {valueset_t<I>::is_special(std::get<I>(l))...})
646  if (!n)
647  return false;
648  return true;
649  }
650 
651  template <std::size_t... I>
652  value_t
653  zero_(seq<I...>) const
654  {
655  return value_t{set<I>().zero()...};
656  }
657 
658  template <std::size_t... I>
659  bool
660  is_zero_(const value_t& l, seq<I...>) const
661  {
662  for (auto n: {set<I>().is_zero(std::get<I>(l))...})
663  if (!n)
664  return false;
665  return true;
666  }
667 
668  template <std::size_t... I>
669  static constexpr bool
670  has_one_(seq<I...>)
671  {
672  return all_<valueset_t<I>::has_one()...>();
673  }
674 
675  template <std::size_t... I>
676  static constexpr bool
677  is_ratexpset_(seq<I...>)
678  {
679  return all_<valueset_t<I>::is_ratexpset()...>();
680  }
681 
682  template <std::size_t... I>
683  static constexpr bool
684  is_letterized_(seq<I...>)
685  {
686  return all_<valueset_t<I>::is_letterized()...>();
687  }
688 
689  template <std::size_t... I>
690  static value_t
691  one_(seq<I...>)
692  {
693  return value_t{valueset_t<I>::one()...};
694  }
695 
696  template <std::size_t... I>
697  static bool
698  is_one_(const value_t& l, seq<I...>)
699  {
700  for (auto n: {valueset_t<I>::is_one(std::get<I>(l))...})
701  if (!n)
702  return false;
703  return true;
704  }
705 
706  template <std::size_t... I>
707  static bool
708  show_one_(seq<I...>)
709  {
710  for (auto n: {valueset_t<I>::show_one()...})
711  if (n)
712  return true;
713  return false;
714  }
715 
716  template <std::size_t... I>
717  value_t
718  add_(const value_t& l, const value_t& r, seq<I...>) const
719  {
720  return value_t{set<I>().add(std::get<I>(l), std::get<I>(r))...};
721  }
722 
723  template <std::size_t... I>
724  value_t
725  mul_(const value_t& l, const value_t& r, seq<I...>) const
726  {
727  return value_t{set<I>().mul(std::get<I>(l), std::get<I>(r))...};
728  }
729 
730  template <std::size_t... I>
731  value_t
732  rdiv_(const value_t& l, const value_t& r, seq<I...>) const
733  {
734  return value_t{set<I>().rdiv(std::get<I>(l), std::get<I>(r))...};
735  }
736 
737  template <std::size_t... I>
738  value_t
739  ldiv_(const value_t& l, const value_t& r, seq<I...>) const
740  {
741  return value_t{set<I>().ldiv(std::get<I>(l), std::get<I>(r))...};
742  }
743 
744  template <std::size_t... I>
745  value_t
746  star_(value_t const& l, seq<I...>) const
747  {
748  return value_t{set<I>().star(std::get<I>(l))...};
749  }
750 
751  template <typename Value, std::size_t... I>
752  Value
753  delimit_(Value const& l, seq<I...>) const
754  {
755  return Value{set<I>().delimit(std::get<I>(l))...};
756  }
757 
758  template <typename Value, std::size_t... I>
759  Value
760  undelimit_(Value const& l, seq<I...>) const
761  {
762  return Value{set<I>().undelimit(std::get<I>(l))...};
763  }
764 
765  template <typename LhsValue, typename RhsValue, std::size_t... I>
766  word_t
767  concat_(const LhsValue& l, const RhsValue& r, seq<I...>) const
768  {
769  return word_t{set<I>().concat(std::get<I>(l), std::get<I>(r))...};
770  }
771 
772  template <std::size_t... I>
773  value_t
774  conv_(std::istream& i, seq<I...>) const
775  {
776 # if AWALI_HAVE_CORRECT_LIST_INITIALIZER_ORDER
777  return std::make_tuple((eat_separator_<I>(i, '[', ','),
778  set<I>().conv(i))...);
779 # else
780  return
781  awali::internal::make_inv_tuple((eat_separator_<sizeof...(ValueSets)-1 - I>(i, '[', ','),
782  std::get<sizeof...(ValueSets)-1 - I>(sets_).conv(i))...);
783 # endif
784  }
785 
789  template <std::size_t I>
790  static void
791  eat_separator_(std::istream& i, char first, char tail)
792  {
793  eat(i, I == 0 ? first : tail);
794  while (isspace(i.peek()))
795  i.ignore();
796  }
797 
798 
799  template <std::size_t... I>
800  std::ostream&
801  print_(value_t const& l, std::ostream& o,
802  const std::string& format, seq<I...>) const
803  {
804  if (!is_special(l))
805  {
806  using swallow = int[];
807  (void) swallow
808  {
809  (o << (I == 0 ? '[' : ','),
810  set<I>().print(std::get<I>(l), o, format),
811  0)...
812  };
813  o << ']';
814  }
815  return o;
816  }
817 
818  template <std::size_t... I>
819  std::ostream&
820  print_set_(std::ostream& o, const std::string& format,
821  seq<I...>) const
822  {
823  const char *sep = "";
824  if (format == "latex")
825  sep = " \\times ";
826  else if (format == "text")
827  {
828  o << "lat<";
829  sep = ",";
830  }
831  else
832  raise("invalid format: ", format);
833  using swallow = int[];
834  (void) swallow
835  {
836  (o << (I == 0 ? "" : sep),
837  set<I>().print_set(o, format),
838  0)...
839  };
840  if (format == "text")
841  o << '>';
842  return o;
843  }
844 
845  template <unsigned version,std::size_t... I>
846  json::object_t*
847  to_json(seq<I...>) const
848  {
849  switch(version) {
850  case 0:
851  throw parse_exception("[tupleset] Unsupported fsm-json version:"
852  + std::to_string(version));
853  case 1:
854  default:
855  json::object_t* obj = new json::object_t();
856  obj->push_back("labelKind", new json::string_t("Multi-tape"));
857  json::array_t* l = new json::array_t();
858  for (auto x: {this->set<I>().template to_json<version>()...})
859  l->push_back(x);
860  obj->push_back("tapeLabels", l);
861  return obj;
862  }
863  }
864 
865 
866  template <unsigned version,std::size_t... I>
867  json::array_t*
868  value_to_json(value_t value, seq<I...> const) const
869  {
870  switch(version) {
871  case 0:
872  throw parse_exception("[tupleset] Unsupported fsm-json version:"
873  + std::to_string(version));
874  case 1:
875  default:
876  json::array_t* l = new json::array_t();
877  for (auto a : {this->set<I>().template value_to_json<version>(std::get<I>(value))...})
878  l->push_back(a);
879  return l;
880  }
881  }
882 
883 
884  template <std::size_t... I>
885  value_t
886  transpose_(value_t const& l, seq<I...>) const
887  {
888  return value_t{(set<I>().transpose(std::get<I>(l)))...};
889  }
890 
892  template <std::size_t... I>
893  tupleset
894  meet_(const tupleset& rhs, seq<I...>) const
895  {
896  return tupleset{meet(set<I>(), rhs.set<I>())...};
897  }
898 
900  template <std::size_t... I>
901  tupleset
902  join_(const tupleset& rhs, seq<I...>) const
903  {
904  return tupleset{join(set<I>(), rhs.set<I>())...};
905  }
906 
908  friend
909  tupleset
910  meet(const tupleset& lhs, const tupleset& rhs)
911  {
912  return lhs.meet_(rhs, indices);
913  }
914 
916  friend
917  tupleset
918  meet(const tupleset& lhs, const b&)
919  {
920  return lhs;
921  }
922 
924  friend
925  tupleset
926  meet(const b&, const tupleset& rhs)
927  {
928  return rhs;
929  }
930 
932  friend
933  tupleset
934  join(const tupleset& lhs, const tupleset& rhs)
935  {
936  return lhs.join_(rhs, indices);
937  }
938 
940  friend
941  tupleset
942  join(const tupleset& lhs, const b&)
943  {
944  return lhs;
945  }
946 
948  friend
949  tupleset
950  join(const b&, const tupleset& rhs)
951  {
952  return rhs;
953  }
954 
955  valuesets_t sets_;
956  mutable bool open__ = false;
957  };
958 
959  template<typename... Valuesets>
960  auto
961  make_tupleset(std::tuple<Valuesets...> t) -> tupleset<Valuesets...> {
962  return {t};
963  }
964 
965 
966  namespace internal
967  {
968  template <typename T1, typename T2>
969  struct concat_tupleset;
970 
971  template <typename... T1, typename... T2>
972  struct concat_tupleset<tupleset<T1...>, tupleset<T2...>>
973  {
974  using type = tupleset<T1..., T2...>;
975  };
976 
977  }
978 
979 
980  }
981 }//end of ns awali::stc
982 
983 #endif // !AWALI_LABELSET_TUPLESET_HH
std::vector< node_t * > const & values
Definition: node.hh:429
Definition: node.hh:191
virtual array_t const * array() const
Casts this node to array_t.
Definition: node.hh:205
The Boolean semring.
Definition: b.hh:38
bool value_t
Definition: b.hh:56
The semiring of complex numbers.
Definition: c.hh:44
The semiring of Natural numbers.
Definition: n.hh:34
The semiring of floating Numbers.
Definition: r.hh:35
A ValueSet which is a Cartesian product of ValueSets.
Definition: tupleset.hh:80
typename labelset_types< ValueSets... >::letter_t letter_t
A tuple of letters if meaningful, void otherwise.
Definition: tupleset.hh:100
tupleset(ValueSets... ls)
Definition: tupleset.hh:115
value_t rdiv(const value_t &l, const value_t &r) const
Definition: tupleset.hh:316
static constexpr bool has_one()
Definition: tupleset.hh:262
json::node_t * to_json() const
Definition: tupleset.hh:419
value_t conv(std::istream &i) const
Read one letter from i, return the corresponding value.
Definition: tupleset.hh:399
static constexpr bool is_ratexpset()
Definition: tupleset.hh:268
static constexpr bool is_commutative_semiring()
Definition: tupleset.hh:136
std::ostream & print_set(std::ostream &o, const std::string &format="text") const
Definition: tupleset.hh:412
genset_t genset() const
The generators. Meaningful for labelsets only.
Definition: tupleset.hh:181
value_t value(const std::tuple< Args... > &args) const
Construct a value.
Definition: tupleset.hh:174
value_t add(const value_t &l, const value_t &r) const
Definition: tupleset.hh:304
static constexpr bool is_free()
Definition: tupleset.hh:186
static std::string sname()
Definition: tupleset.hh:119
static bool equals(const value_t &l, const value_t &r)
Definition: tupleset.hh:225
value_t ldiv(const value_t &l, const value_t &r) const
Definition: tupleset.hh:322
value_t star(const value_t &l) const
Definition: tupleset.hh:328
std::tuple< typename ValueSets::value_t... > value_t
A tuple of values.
Definition: tupleset.hh:97
value_t value_from_json(json::node_t const *p) const
Definition: tupleset.hh:458
std::string vname(bool full=true) const
Definition: tupleset.hh:124
static constexpr bool is_letterized()
Definition: tupleset.hh:274
void comma(const std::string &s, size_t &p, char &c) const
Definition: tupleset.hh:478
tupleset(valuesets_t vs)
Definition: tupleset.hh:111
static value_t conv(self_type, value_t v)
Definition: tupleset.hh:379
static constexpr std::size_t size()
Definition: tupleset.hh:129
typename std::tuple_element< I, valuesets_t >::type valueset_t
The Ith valueset type.
Definition: tupleset.hh:90
word_t concat(const LhsValue &l, const RhsValue &r) const
Definition: tupleset.hh:361
value_t conv(const T &tset, typename T::value_t v) const
Definition: tupleset.hh:386
static tupleset make(std::istream &is)
Build from the description in is.
Definition: tupleset.hh:142
letter_t value_type
To be iterable.
Definition: tupleset.hh:107
static auto letters_of(const Value &v) -> decltype(letters_of_(v, indices))
Iterate over the letters of v.
Definition: tupleset.hh:209
static value_t special()
Definition: tupleset.hh:238
std::tuple< ValueSets... > valuesets_t
Definition: tupleset.hh:82
std::ostream & print(const value_t &l, std::ostream &o, const std::string &format="text") const
Definition: tupleset.hh:504
static value_t one()
Definition: tupleset.hh:280
Value undelimit(const Value &l) const
Remove first and last characters, that must be "special".
Definition: tupleset.hh:348
value_t parse(const std::string &s, size_t &p, bool fixed_domain=true) const
Definition: tupleset.hh:464
bool open(bool o) const
Whether unknown letters should be added, or rejected.
Definition: tupleset.hh:167
Value delimit(const Value &l) const
Add the special character first and last.
Definition: tupleset.hh:340
static bool less_than(const value_t &l, const value_t &r)
Whether l < r.
Definition: tupleset.hh:232
static bool is_one(const value_t &l)
Definition: tupleset.hh:286
std::set< value_t > convs(std::istream &) const
Definition: tupleset.hh:406
typename labelset_types< ValueSets... >::word_t word_t
A tuple of words if meaningful, void otherwise.
Definition: tupleset.hh:104
bool is_letter(const value_t &) const
Definition: tupleset.hh:298
static size_t hash(const value_t &v)
Definition: tupleset.hh:373
value_t zero() const
Definition: tupleset.hh:250
value_t conv(b, b::value_t v) const
Definition: tupleset.hh:392
bool is_zero(const value_t &l) const
Definition: tupleset.hh:256
static constexpr star_status_t star_status()
Definition: tupleset.hh:354
value_t transpose(const value_t &l) const
Definition: tupleset.hh:367
typename labelset_types< ValueSets... >::genset_t genset_t
A tuple of gensets if meaningful, void otherwise.
Definition: tupleset.hh:102
static bool is_special(const value_t &l)
Definition: tupleset.hh:244
static bool show_one()
Definition: tupleset.hh:292
bool is_tupleset_t
Definition: tupleset.hh:94
value_t value_from_json(std::vector< json::node_t * > const &v, seq< I... >) const
Definition: tupleset.hh:451
json::node_t * value_to_json(value_t v) const
Definition: tupleset.hh:434
const valuesets_t & sets() const
The componants valuesets, as a tuple.
Definition: tupleset.hh:152
value_t mul(const value_t &l, const value_t &r) const
Definition: tupleset.hh:310
auto word(const std::tuple< Args... > &v) const -> word_t
Convert to a word.
Definition: tupleset.hh:218
value_t parse_(const std::string &s, size_t &p, bool fixed_domain, seq< I... >) const
Definition: tupleset.hh:489
const valueset_t< I > & set() const
The Ith component valueset.
Definition: tupleset.hh:159
star_status_t
The different behaviours a weightset may have with respect to the star.
Definition: enums.hh:161
@ STARRABLE
The star of every element exists.
Definition: enums.hh:163
any_t word_t
Type for words; it is an alias to any_t since the precise type depends on the context (most of the ti...
Definition: typedefs.hh:67
auto make_inv_tuple() -> std::tuple<>
Definition: tuple.hh:179
Definition: tuple.hh:43
Definition: tuple.hh:70
node_t * parse(std::istream &)
zip_sequences< Sequences... > zip(Sequences &&... seqs)
Definition: zip.hh:231
void genset_t
Definition: tupleset.hh:55
void word_t
Definition: tupleset.hh:57
void letter_t
Definition: tupleset.hh:56
cross_sequences< Sequences... > cross(Sequences &&... seqs)
Definition: cross.hh:257
std::tuple< typename ValueSets::letter_t... > letter_t
Definition: tupleset.hh:66
A traits so that tupleset may define types that may exist.
Definition: tupleset.hh:54
constant< type_t::one, Label, Weight > one
Definition: fwd.hh:116
std::string to_string(identities i)
void eat(std::istream &is, char c)
Check lookahead character and advance.
Definition: stream.hh:62
RatExpSet::ratexp_t less_than(const RatExpSet &rs, const typename RatExpSet::ratexp_t &v)
Definition: less_than.hh:166
RatExpSet::ratexp_t equals(const RatExpSet &rs, const typename RatExpSet::ratexp_t &v)
Definition: equal_visit.hh:153
auto format(const ValueSet &vs, const typename ValueSet::value_t &v, Args &&... args) -> std::string
Format v via vs.print.
Definition: stream.hh:109
auto conv(const ValueSet &vs, const std::string &str, Args &&... args) -> decltype(vs.conv(std::declval< std::istream & >(), std::forward< Args >(args)...))
Parse str via vs.conv.
Definition: stream.hh:45
static const std::string full
Completely version of Awali as a std::string.
Definition: version.hh:40
Main namespace of Awali.
Definition: ato.hh:22
Exceptions thrown during parsing.
Definition: parse_exception.hh:26
Ignore its arguments.
Definition: raise.hh:34
marker type for labelsets where labels are tuples
Definition: kind.hh:84