Awali
Another Weighted Automata library
tupleset.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 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  version::check_fsmjson<version>();
423  switch (version) {
424  case 1:
425  default:
426  return to_json<version>(indices);
427  }
428  }
429 
430 
431  template<unsigned version = version::fsm_json>
433  const
434  {
435  version::check_fsmjson<version>();
436  switch (version) {
437  case 1:
438  default:
439  return value_to_json<version>(v, indices);
440  }
441  }
442 
443 
444 
445  template<unsigned version = version::fsm_json>
446  value_t
448  {
449  version::check_fsmjson<version>();
450  return value_from_json<version>(p->array()->values, indices);
451  }
452 
453  value_t
454  parse(const std::string& s, size_t& p, bool fixed_domain=true) const {
455  if(s[--p]!=']')
456  throw parse_exception("Invalid tuple");
457 # if AWALI_HAVE_CORRECT_LIST_INITIALIZER_ORDER
458  value_t r= parse_(s, p, fixed_domain, typename awali::internal::reverseseq<typename indices_t::type>::type());
459 #else
460  value_t r= parse_(s, p, fixed_domain, indices);
461 #endif
462  if(s[--p]!='[')
463  throw parse_exception("Invalid tuple");
464  return r;
465  }
466 
467  template <std::size_t... I>
468  void comma(const std::string& s, size_t& p, char& c) const {
469  if(c=='x') {
470  c=',';
471  return;
472  }
473  if(s[--p]!=',')
474  throw parse_exception("Invalid letter");
475  }
476 
477  template <std::size_t... I>
478  value_t
479  parse_(const std::string& s, size_t& p, bool fixed_domain, seq<I...>) const {
480  char c = 'x';
481 # if AWALI_HAVE_CORRECT_LIST_INITIALIZER_ORDER
482  value_t r=
483  awali::internal::make_inv_tuple((comma<I>(s, p, c),
484  std::get<I>(sets_).parse(s,p,fixed_domain))...);
485 #else
486  value_t r = std::make_tuple((comma<I>(s, p, c),
487  set<I>().parse(s,p,fixed_domain))...);
488 #endif
489  return r;
490  }
491 
492 
493  std::ostream&
494  print(const value_t& l, std::ostream& o,
495  const std::string& format = "text") const
496  {
497  return print_(l, o, format, indices);
498  }
499 
500  private:
501  template <std::size_t... I>
502  static std::string sname_(seq<I...>)
503  {
504  std::string res = "lat<";
505  const char *sep = "";
506  for (auto n: {valueset_t<I>::sname()...})
507  {
508  res += sep;
509  res += n;
510  sep = ",";
511  }
512  res.push_back('>');
513  return res;
514  }
515 
516  template <typename T, std::size_t... I>
517  value_t
518  conv_(const T& tset, typename T::value_t v, seq<I...>) const
519  {
520  return std::make_tuple(std::get<I>(this->sets()).conv(std::get<I>(tset.sets()),std::get<I>(v))...);
521  }
522 
523 
524  template <std::size_t... I>
525  std::string vname_(bool full, seq<I...>) const
526  {
527  std::string res = "lat<";
528  const char *sep = "";
529  for (auto n: {set<I>().vname(full)...})
530  {
531  res += sep;
532  res += n;
533  sep = ",";
534  }
535  res.push_back('>');
536  return res;
537  }
538 
539  template <std::size_t... I>
540  static tupleset make_(std::istream& i, seq<I...>)
541  {
542 # if AWALI_HAVE_CORRECT_LIST_INITIALIZER_ORDER
543  return tupleset{(eat_separator_<I>(i, '<', ','),
544  valueset_t<I>::make(i))...};
545 # else
546  return make_inv_tuple
547  ((eat_separator_<sizeof...(ValueSets)-1 -I>(i, '<', ','),
548  valueset_t<sizeof...(ValueSets)-1 -I>::make(i))...);
549 # endif
550  }
551 
552  template <std::size_t... I>
553  bool open_(bool o, seq<I...>) const
554  {
555  using swallow = int[];
556  (void) swallow { set<I>().open(o)... };
557  std::swap(o, open__);
558  return o;
559  }
560 
561  template <typename... Args, std::size_t... I>
562  value_t value_(const std::tuple<Args...>& args, seq<I...>) const
563  {
564  return value_t{set<I>().value(std::get<I>(args))...};
565  }
566 
567  template <std::size_t... I>
568  genset_t
569  genset_(seq<I...>) const
570  {
571  return internal::cross(set<I>().genset()...);
572  }
573 
574  template <std::size_t... I>
575  static constexpr bool
576  is_free_(seq<I...>)
577  {
578  return all_<valueset_t<I>::is_free()...>();
579  }
580 
581  template <typename... Args, std::size_t... I>
582  word_t
583  word_(const std::tuple<Args...>& l, seq<I...>) const
584  {
585  return word_t{set<I>().word(std::get<I>(l))...};
586  }
587 
588  template <std::size_t... I>
589  static bool
590  equals_(const value_t& l, const value_t& r, seq<I...>)
591  {
592  for (auto n: {valueset_t<I>::equals(std::get<I>(l),
593  std::get<I>(r))...})
594  if (!n)
595  return false;
596  return true;
597  }
598 
599  template <std::size_t... I>
600  static bool
601  less_than_(const value_t& l, const value_t& r, seq<I...>)
602  {
603  for (auto n: {std::make_pair(valueset_t<I>::less_than(std::get<I>(l),
604  std::get<I>(r)),
605  valueset_t<I>::less_than(std::get<I>(r),
606  std::get<I>(l)))...})
607  if (n.first)
608  return true;
609  else if (n.second)
610  return false;
611  return false;
612  }
613 
614  template <std::size_t... I>
615  static std::size_t
616  hash_(const value_t& v, seq<I...>)
617  {
618  std::size_t res = 0;
619  for (auto h: {valueset_t<I>::hash(std::get<I>(v))...})
620  std::hash_combine(res, h);
621  return res;
622  }
623 
624  template <std::size_t... I>
625  static value_t
626  special_(seq<I...>)
627  {
628  return std::make_tuple(valueset_t<I>::special()...);
629  }
630 
631  template <std::size_t... I>
632  static bool
633  is_special_(const value_t& l, seq<I...>)
634  {
635  for (auto n: {valueset_t<I>::is_special(std::get<I>(l))...})
636  if (!n)
637  return false;
638  return true;
639  }
640 
641  template <std::size_t... I>
642  value_t
643  zero_(seq<I...>) const
644  {
645  return value_t{set<I>().zero()...};
646  }
647 
648  template <std::size_t... I>
649  bool
650  is_zero_(const value_t& l, seq<I...>) const
651  {
652  for (auto n: {set<I>().is_zero(std::get<I>(l))...})
653  if (!n)
654  return false;
655  return true;
656  }
657 
658  template <std::size_t... I>
659  static constexpr bool
660  has_one_(seq<I...>)
661  {
662  return all_<valueset_t<I>::has_one()...>();
663  }
664 
665  template <std::size_t... I>
666  static constexpr bool
667  is_ratexpset_(seq<I...>)
668  {
669  return all_<valueset_t<I>::is_ratexpset()...>();
670  }
671 
672  template <std::size_t... I>
673  static constexpr bool
674  is_letterized_(seq<I...>)
675  {
676  return all_<valueset_t<I>::is_letterized()...>();
677  }
678 
679  template <std::size_t... I>
680  static value_t
681  one_(seq<I...>)
682  {
683  return value_t{valueset_t<I>::one()...};
684  }
685 
686  template <std::size_t... I>
687  static bool
688  is_one_(const value_t& l, seq<I...>)
689  {
690  for (auto n: {valueset_t<I>::is_one(std::get<I>(l))...})
691  if (!n)
692  return false;
693  return true;
694  }
695 
696  template <std::size_t... I>
697  static bool
698  show_one_(seq<I...>)
699  {
700  for (auto n: {valueset_t<I>::show_one()...})
701  if (n)
702  return true;
703  return false;
704  }
705 
706  template <std::size_t... I>
707  value_t
708  add_(const value_t& l, const value_t& r, seq<I...>) const
709  {
710  return value_t{set<I>().add(std::get<I>(l), std::get<I>(r))...};
711  }
712 
713  template <std::size_t... I>
714  value_t
715  mul_(const value_t& l, const value_t& r, seq<I...>) const
716  {
717  return value_t{set<I>().mul(std::get<I>(l), std::get<I>(r))...};
718  }
719 
720  template <std::size_t... I>
721  value_t
722  rdiv_(const value_t& l, const value_t& r, seq<I...>) const
723  {
724  return value_t{set<I>().rdiv(std::get<I>(l), std::get<I>(r))...};
725  }
726 
727  template <std::size_t... I>
728  value_t
729  ldiv_(const value_t& l, const value_t& r, seq<I...>) const
730  {
731  return value_t{set<I>().ldiv(std::get<I>(l), std::get<I>(r))...};
732  }
733 
734  template <std::size_t... I>
735  value_t
736  star_(value_t const& l, seq<I...>) const
737  {
738  return value_t{set<I>().star(std::get<I>(l))...};
739  }
740 
741  template <typename Value, std::size_t... I>
742  Value
743  delimit_(Value const& l, seq<I...>) const
744  {
745  return Value{set<I>().delimit(std::get<I>(l))...};
746  }
747 
748  template <typename Value, std::size_t... I>
749  Value
750  undelimit_(Value const& l, seq<I...>) const
751  {
752  return Value{set<I>().undelimit(std::get<I>(l))...};
753  }
754 
755  template <typename LhsValue, typename RhsValue, std::size_t... I>
756  word_t
757  concat_(const LhsValue& l, const RhsValue& r, seq<I...>) const
758  {
759  return word_t{set<I>().concat(std::get<I>(l), std::get<I>(r))...};
760  }
761 
762  template <std::size_t... I>
763  value_t
764  conv_(std::istream& i, seq<I...>) const
765  {
766 # if AWALI_HAVE_CORRECT_LIST_INITIALIZER_ORDER
767  return std::make_tuple((eat_separator_<I>(i, '[', ','),
768  set<I>().conv(i))...);
769 # else
770  return
771  awali::internal::make_inv_tuple((eat_separator_<sizeof...(ValueSets)-1 - I>(i, '[', ','),
772  std::get<sizeof...(ValueSets)-1 - I>(sets_).conv(i))...);
773 # endif
774  }
775 
779  template <std::size_t I>
780  static void
781  eat_separator_(std::istream& i, char first, char tail)
782  {
783  eat(i, I == 0 ? first : tail);
784  while (isspace(i.peek()))
785  i.ignore();
786  }
787 
788 
789  template <std::size_t... I>
790  std::ostream&
791  print_(value_t const& l, std::ostream& o,
792  const std::string& format, seq<I...>) const
793  {
794  if (!is_special(l))
795  {
796  using swallow = int[];
797  (void) swallow
798  {
799  (o << (I == 0 ? '[' : ','),
800  set<I>().print(std::get<I>(l), o, format),
801  0)...
802  };
803  o << ']';
804  }
805  return o;
806  }
807 
808  template <std::size_t... I>
809  std::ostream&
810  print_set_(std::ostream& o, const std::string& format,
811  seq<I...>) const
812  {
813  const char *sep = "";
814  if (format == "latex")
815  sep = " \\times ";
816  else if (format == "text")
817  {
818  o << "lat<";
819  sep = ",";
820  }
821  else
822  raise("invalid format: ", format);
823  using swallow = int[];
824  (void) swallow
825  {
826  (o << (I == 0 ? "" : sep),
827  set<I>().print_set(o, format),
828  0)...
829  };
830  if (format == "text")
831  o << '>';
832  return o;
833  }
834 
835  template <unsigned version, std::size_t... I>
836  value_t
837  value_from_json(std::vector<json::node_t*> const& v, seq<I...>)
838  const
839  {return value_t{set<I>().template value_from_json<version>(v[I])...};}
840 
841  template <unsigned version,std::size_t... I>
842  json::object_t*
843  to_json(seq<I...>) const
844  {
845  switch(version) {
846  case 1:
847  default:
848  json::object_t* obj = new json::object_t();
849  obj->push_back("labelKind", new json::string_t("Multi-tape"));
850  json::array_t* l = new json::array_t();
851  for (auto x: {this->set<I>().template to_json<version>()...})
852  l->push_back(x);
853  obj->push_back("tapeLabels", l);
854  return obj;
855  }
856  }
857 
858 
859  template <unsigned version,std::size_t... I>
860  json::array_t*
861  value_to_json(value_t value, seq<I...> const) const
862  {
863  switch(version) {
864  case 1:
865  default:
866  json::array_t* l = new json::array_t();
867  for (auto a : {this->set<I>().template value_to_json<version>(std::get<I>(value))...})
868  l->push_back(a);
869  return l;
870  }
871  }
872 
873 
874  template <std::size_t... I>
875  value_t
876  transpose_(value_t const& l, seq<I...>) const
877  {
878  return value_t{(set<I>().transpose(std::get<I>(l)))...};
879  }
880 
882  template <std::size_t... I>
883  tupleset
884  meet_(const tupleset& rhs, seq<I...>) const
885  {
886  return tupleset{meet(set<I>(), rhs.set<I>())...};
887  }
888 
890  template <std::size_t... I>
891  tupleset
892  join_(const tupleset& rhs, seq<I...>) const
893  {
894  return tupleset{join(set<I>(), rhs.set<I>())...};
895  }
896 
898  friend
899  tupleset
900  meet(const tupleset& lhs, const tupleset& rhs)
901  {
902  return lhs.meet_(rhs, indices);
903  }
904 
906  friend
907  tupleset
908  meet(const tupleset& lhs, const b&)
909  {
910  return lhs;
911  }
912 
914  friend
915  tupleset
916  meet(const b&, const tupleset& rhs)
917  {
918  return rhs;
919  }
920 
922  friend
923  tupleset
924  join(const tupleset& lhs, const tupleset& rhs)
925  {
926  return lhs.join_(rhs, indices);
927  }
928 
930  friend
931  tupleset
932  join(const tupleset& lhs, const b&)
933  {
934  return lhs;
935  }
936 
938  friend
939  tupleset
940  join(const b&, const tupleset& rhs)
941  {
942  return rhs;
943  }
944 
945  valuesets_t sets_;
946  mutable bool open__ = false;
947  };
948 
949  template<typename... Valuesets>
950  auto
951  make_tupleset(std::tuple<Valuesets...> t) -> tupleset<Valuesets...> {
952  return {t};
953  }
954 
955 
956  namespace internal
957  {
958  template <typename T1, typename T2>
959  struct concat_tupleset;
960 
961  template <typename... T1, typename... T2>
962  struct concat_tupleset<tupleset<T1...>, tupleset<T2...>>
963  {
964  using type = tupleset<T1..., T2...>;
965  };
966 
967  }
968 
969 
970  }
971 }//end of ns awali::stc
972 
973 #endif // !AWALI_LABELSET_TUPLESET_HH
std::vector< node_t * > const & values
Definition: node.hh:436
Definition: node.hh:193
virtual array_t const * array() const
Casts this node to array_t.
Definition: node.hh:207
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:447
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:468
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:494
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:454
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
json::node_t * value_to_json(value_t v) const
Definition: tupleset.hh:432
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:479
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:163
@ STARRABLE
The star of every element exists.
Definition: enums.hh:165
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 &, bool stop_after_metadata=false)
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
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:42
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