8 #include <vcsn/config.hh>
29 template <
typename Enable =
void,
typename... ValueSets>
41 template <
typename... ValueSets>
55 template <
typename... ValueSets>
62 template <
typename... ValueSets>
69 template <std::size_t... I>
73 template <std::
size_t I>
98 : sets_(
std::move(vs))
107 static auto res =
symbol{sname_(indices)};
112 static constexpr std::size_t
size()
114 return sizeof...(ValueSets);
118 template <
typename Value>
121 return size_(v, indices);
124 static constexpr
bool
127 return is_commutative_(indices);
130 static constexpr
bool
133 return is_idempotent_(indices);
142 auto res = make_(is, indices);
157 return std::get<I>(sets());
177 return std::get<I>(
v);
185 return this->open_(o, indices);
189 template <
typename... Args>
192 return this->value_(args, indices);
196 template <
typename... Args>
205 return this->genset_(indices);
212 return this->generators_(indices);
217 return is_free_(indices);
221 template <
typename... Args>
223 word(
const std::tuple<Args...>&
v)
const
226 return this->word_(
v, indices);
233 return equal_(l, r, indices);
237 template <
typename LhsValue,
typename RhsValue>
239 less(
const LhsValue& l,
const RhsValue&
r)
249 return less_(l,
r, indices);
255 return special_(indices);
261 return is_special_(l, indices);
267 return this->zero_(indices);
273 return is_zero_(l, indices);
276 static constexpr
bool
279 return has_lightening_weights_(indices);
282 static constexpr
bool
285 return has_one_(indices);
288 static constexpr
bool
291 return is_expressionset_(indices);
294 static constexpr
bool
297 return is_letterized_(indices);
301 template <std::size_t... I>
313 template <
typename Indices = indices_t>
314 static auto one() -> decltype(one_(Indices{}))
316 return one_(Indices{});
322 return is_one_(l, indices);
328 return show_one_(indices);
343 [](
const auto& vs,
const auto& l,
const auto& r)
353 template <
typename LhsValue,
typename RhsValue>
355 mul(
const LhsValue& l,
const RhsValue&
r)
const
358 return this->mul_(l,
r, indices);
366 [](
const auto& vs,
const auto& l,
const auto& r)
368 return vs.lgcd(l, r);
377 [](
const auto& vs,
const auto& l,
const auto& r)
379 return vs.rdivide(l, r);
388 [](
const auto& vs,
const auto& l,
const auto& r)
390 return vs.ldivide(l, r);
398 typename valueset_t<0>::value_t
401 return this->lnormalize_here_(v, indices);
409 [](
const auto& vs,
const auto& v)
420 template <
typename Value>
424 return this->delimit_(l, indices);
428 template <
typename Value>
432 return this->undelimit_(l, indices);
442 template <
typename Value>
446 return this->transpose_(l, indices);
452 return hash_(v, indices);
464 return v ? one() : zero();
468 template <
typename... VS>
473 return this->conv_(vs, v, indices);
477 template <
typename... VS>
482 return conv(*vs.labelset(), vs.get_value(v));
487 conv(std::istream& i,
bool quoted =
true)
const
491 constexpr
auto has_label_one
497 template <
typename Fun>
498 void convs(std::istream& i, Fun&& fun)
const
502 [
this,fun](
const letter_t& l) { fun(value(l)); });
509 return this->print_set_(o, fmt, indices);
520 fmt.delimit() ?
"(" :
"",
521 fmt.is_for_labels() ?
"|" :
",",
522 fmt.delimit() ?
")" :
"",
527 template <std::size_t... I>
530 std::string
res =
"lat<";
531 const char *sep =
"";
542 template <std::size_t... I>
543 static constexpr
bool
546 return all_<valueset_t<I>::is_commutative()...>();
549 template <std::size_t... I>
550 static constexpr
bool
553 return all_<valueset_t<I>::is_idempotent()...>();
556 template <std::size_t... I>
559 #if VCSN_HAVE_CORRECT_LIST_INITIALIZER_ORDER
560 return self_t{(eat_separator_<I>(i),
564 ((eat_separator_<
sizeof...(ValueSets)-1 -I>(i),
565 valueset_t<
sizeof...(ValueSets)-1 -I>::make(i))...);
569 template <std::size_t... I>
572 using swallow =
int[];
573 (
void) swallow { set<I>().open(o)... };
574 std::swap(o, open__);
580 template <
typename Value, std::
size_t I>
589 template <
typename Value, std::
size_t I>
590 static constexpr
auto size_(
const Value&, ...)
596 template <
typename Value, std::size_t... I>
599 return std::max({size_<Value, I>(
v, 0)...});
602 template <
typename... Args, std::size_t... I>
605 return value_t{set<I>().value(std::get<I>(args))...};
608 template <std::size_t... I>
615 template <std::size_t... I>
622 template <std::size_t... I>
623 static constexpr
bool
626 return all_<valueset_t<I>::is_free()...>();
629 template <
typename... Args, std::size_t... I>
633 return word_t{set<I>().word(std::get<I>(l))...};
636 template <std::size_t... I>
647 template <
typename LhsValue,
typename RhsValue, std::size_t... I>
655 std::get<I>(l)))...})
663 template <std::size_t... I>
673 template <std::size_t... I>
680 template <std::size_t... I>
690 template <std::size_t... I>
694 return value_t{set<I>().zero()...};
697 template <std::size_t... I>
701 for (
auto n: {set<I>().is_zero(std::get<I>(l))...})
707 template <std::size_t... I>
708 static constexpr
bool
711 return all_<valueset_t<I>::has_lightening_weights()...>();
714 template <std::size_t... I>
715 static constexpr
bool
718 return all_<valueset_t<I>::has_one()...>();
721 template <std::size_t... I>
722 static constexpr
bool
725 return all_<valueset_t<I>::is_expressionset()...>();
728 template <std::size_t... I>
729 static constexpr
bool
735 template <std::size_t... I>
745 template <std::size_t... I>
756 template <
typename Fun>
760 return map_impl_(v, std::forward<Fun>(fun), indices);
763 template <
typename Fun, std::size_t... I>
767 return value_t{fun(set<I>(), std::get<I>(v))...};
771 template <
typename Fun>
775 return map_impl_(l, r, std::forward<Fun>(fun), indices);
778 template <
typename Fun, std::size_t... I>
782 return value_t{fun(set<I>(), std::get<I>(l), std::get<I>(r))...};
785 template <
typename LhsValue,
typename RhsValue, std::size_t... I>
790 return word_t{set<I>().mul(std::get<I>(l), std::get<I>(
r))...};
793 template <std::size_t... I>
794 typename valueset_t<0>::value_t
798 for (
auto v: {std::get<I>(vs)...})
799 res = set<0>().
lgcd(res, v);
800 using swallow =
int[];
801 (
void) swallow { (set<0>().ldivide_here(res, std::get<I>(vs)), 0)... };
805 template <
typename Value, std::size_t... I>
809 return Value{set<I>().delimit(std::get<I>(l))...};
812 template <
typename Value, std::size_t... I>
816 return Value{set<I>().undelimit(std::get<I>(l))...};
819 template <
typename... VS, std::size_t... I>
825 return value_t{set<I>().
conv(vs.template set<I>(), std::get<I>(
v))...};
831 conv_(std::istream& i,
bool quoted, std::true_type)
const
837 return conv_(i, quoted, std::false_type{});
842 conv_(std::istream& i,
bool quoted, std::false_type)
const
844 bool par = i.peek() ==
'(';
847 value_t res = conv_(i, quoted, indices);
853 template <std::size_t... I>
857 #if VCSN_HAVE_CORRECT_LIST_INITIALIZER_ORDER
858 return value_t{(eat_separator_<I>(i),
859 set<I>().conv(i, quoted))...};
861 constexpr
auto S =
sizeof...(ValueSets)-1;
864 set<S - I>().
conv(i, quoted))...);
872 template <std::
size_t I>
877 eat(i, i.peek() ==
',' ?
',' :
'|');
878 while (isspace(i.peek()))
883 template <std::size_t... I>
894 using swallow =
int[];
897 (o << (I == 0 ? pre : sep),
898 set<I>().print(std::get<I>(l), o, fmt),
906 template <std::size_t... I>
911 const char *sep =
"";
912 const char *close =
"";
933 using swallow =
int[];
936 (o << (I == 0 ?
"" : sep),
937 set<I>().print_set(o, fmt),
944 template <
typename Value, std::size_t... I>
948 return Value{set<I>().
transpose(std::get<I>(l))...};
952 template <std::size_t... I>
956 return self_t{
meet(set<I>(), rhs.template set<I>())...};
964 return lhs.meet_(rhs, indices);
986 mutable bool open__ =
false;
990 template <std::size_t... I>
995 #if VCSN_HAVE_CORRECT_LIST_INITIALIZER_ORDER
996 return letter_t{(eat_separator_<I>(i),
997 set<I>().get_letter(i, quoted))...};
999 constexpr
auto S =
sizeof...(ValueSets)-1;
1002 set<S - I>().get_letter(i, quoted))...);
1007 template <
typename Value, std::size_t... I>
1016 template <
typename Value,
typename... Defaults, std::size_t... I>
1019 const std::tuple<Defaults...>& def,
seq<I...>) const
1021 this->
set<I>().letters_of_padded(
std::get<I>(v),
1022 std::get<I>(def))...))
1025 set<I>().letters_of_padded(std::get<I>(v),
1026 std::get<I>(def))...);
1030 template <std::size_t... I>
1033 -> decltype(this->get_letter_(i, quoted, indices))
1035 bool par = i.peek() ==
'(';
1038 auto res = get_letter_(i, quoted, indices);
1049 template <
typename Value>
1052 -> decltype(letters_of_(v, indices))
1054 return letters_of_(v, indices);
1062 template <
typename Value,
typename... Defaults>
1065 -> decltype(this->letters_of_padded_(v, def, indices))
1067 return letters_of_padded_(v, def, indices);
1071 template <
typename... ValueSets>
1084 template <
typename ValueSet>
1089 template <
typename... ValueSet>
1094 template <
typename LabelSet,
typename WeightSet>
1099 template <
typename Context>
1106 template <
typename T1,
typename T2>
1114 template <
typename... T1,
typename... T2>
1122 template <
typename... LabelSets>
1127 template <std::size_t... I>
1133 template <std::size_t... I>
1148 template <std::size_t... I>
1157 template <
typename... LabelSets>
1159 std::enable_if_t<tupleset<LabelSets...>::has_one()>>
1170 template <
typename... LabelSets>
1172 std::enable_if_t<!tupleset<LabelSets...>::has_one()>>
1184 template <
typename LabelSet>
1195 template <
typename... LabelSets>
1201 template <std::size_t... I>
1214 template <
typename... VS1,
typename... VS2>
1217 static_assert(
sizeof...(VS1) ==
sizeof...(VS2),
1218 "join: tuplesets must have the same sizes");
1224 template <std::size_t... I>
1228 return {
::vcsn::join(lhs.template set<I>(), rhs.template set<I>())...};
1234 return join(lhs, rhs,
1240 template <
typename... VS1,
typename VS2>
1246 "join: cannot mix tuplesets and non tuplesets");
1256 template <
size_t Tape,
typename LabelSet>
1261 template <
size_t Tape,
typename LabelSet>
1265 template <
size_t Tape,
typename... LabelSets>
1269 using type =
typename valueset_t::template project_t<Tape>;
1273 template <
size_t Tape,
typename Context>
1277 using type =
typename valueset_t::template project_t<Tape>;
1286 template <
size_t Tape,
typename Context>
static self_t make(std::istream &is)
Build from the description in is.
static constexpr star_status_t star_status()
static size_t hash(const value_t &v)
static auto less_(const LhsValue &l, const RhsValue &r, seq< I... >) -> bool
value_t value_(const std::tuple< Args... > &args, seq< I... >) const
value_t conv(const tupleset< VS... > &vs, const typename tupleset< VS... >::value_t &v) const
Convert a value from tupleset<...> to value_t.
typename labelset_types< ValueSets... >::letters_t letters_t
A set of letters if meaningful, void otherwise.
auto word(const std::tuple< Args... > &v) const -> word_t
Convert to a word.
value_t tuple(Args &&...args) const
Construct a value.
value_t zero_(seq< I... >) const
typename valueset_t::template project_t< Tape > type
Aut transpose(const transpose_automaton< Aut > &aut)
A traits so that tupleset may define types that may exist.
tupleset< ValueSets... > make_tupleset(const ValueSets &...vss)
typename std::tuple_element< I, T >::type tuple_element_t
C++14.
static constexpr bool is_idempotent()
Value transpose(const Value &l) const
Transpose a word_t or a value_t.
valueset_t< 0 >::value_t lnormalize_here_(value_t &vs, seq< I... >) const
static size_t size(const Value &v)
Get the max of the sizes of the tapes.
Value delimit_(const Value &l, seq< I... >) const
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
value_t conv(const nullableset< tupleset< VS... >> &vs, const typename nullableset< tupleset< VS... >>::value_t &v) const
Convert a value from nullableset> to value_t.
value_t map_(const value_t &v, Fun &&fun) const
Apply a unary function pointwise, and return the tuple of results.
law_t< LabelSet > make_wordset(const LabelSet &ls)
The wordset of a labelset.
std::tuple< ValueSets... > valuesets_t
value_t conv_(const tupleset< VS... > &vs, const typename tupleset< VS... >::value_t &v, seq< I... >) const
static constexpr bool has_one()
letter_t value_type
To be iterable.
friend self_t meet(const self_t &lhs, const self_t &rhs)
The meet with another tupleset.
bool is_letterized(const Aut &aut)
Check if the transitions are all letters.
auto map_impl_(Fun f, const std::tuple< Ts... > &ts, index_sequence< I... >)
std::tuple< typename ValueSets::value_t... > value_t
A tuple of values.
typename labelset_types< ValueSets... >::letter_t letter_t
A tuple of base letters if meaningful, void otherwise.
Value transpose_(const Value &l, seq< I... >) const
const valueset_t< I > & set() const
The Ith component valueset.
value_t add(const value_t &l, const value_t &r) const
Pointwise addition.
static constexpr bool is_expressionset()
tupleset_impl(ValueSets...ls)
static constexpr bool has_one_(seq< I... >)
static value_t conv(self_t, value_t v)
static std::string sname_(seq< I... >)
std::enable_if_t<!is_letterized_t< labelset_t_of< Aut > >{}, bool > is_letterized(const Aut &aut)
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
value_t star(const value_t &v) const
Pointwise star.
std::tuple< typename ValueSets::genset_ptr... > genset_ptr
tupleset_impl(valuesets_t vs)
static void eat_separator_(std::istream &i)
Read the separator from the input stream i if I is not 0.
value_t conv_(std::istream &i, bool quoted, std::true_type) const
When the valuesets are labelsets and support one, accept the empty string to denote one...
auto join(const ValueSet &vs) -> ValueSet
The join of a single valueset.
A structure that implements the computation of join(V1, V2).
value_t map_impl_(const value_t &v, Fun &&fun, seq< I... >) const
static constexpr bool is_free()
value_t conv_(std::istream &i, bool quoted, seq< I... >) const
typename labelset_types< ValueSets... >::word_t word_t
A tuple of words if meaningful, void otherwise.
auto get_letter_(std::istream &i, bool quoted, seq< I... >) const -> letter_t
Must be declared before, as we use its result in decltype.
Print as a parsable type string.
cross_sequences< Sequences... > cross(Sequences &&...seqs)
valueset_t< I > project_t
The type of the I-th tape valueset.
letterized_t< LabelSet > make_letterized(const LabelSet &ls)
std::tuple< typename ValueSets::value_t... > word_t
Same as value_t.
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.
zip_sequences< Sequences... > zip(Sequences &&...seqs)
genset_t generators() const
The generators. Meaningful for labelsets only.
Implementation of labels are nullables (letter or empty).
std::ostream & print_(const value_t &l, std::ostream &o, format fmt, const char *pre, const char *sep, const char *post, seq< I... >) const
std::ostream & print_set(std::ostream &o, format fmt={}) const
friend self_t meet(const b &, const self_t &rhs)
The meet with the B weightset.
static constexpr bool is_letterized_(seq< I... >)
static constexpr bool is_commutative_(seq< I... >)
bool open(bool o) const
Whether unknown letters should be added, or rejected.
static constexpr bool is_idempotent_(seq< I... >)
bool open_(bool o, seq< I... >) const
constant< type_t::one, Context > one
auto tuple(const Auts &...as)
Build the (accessible part of the) tuple.
std::tuple< typename ValueSets::letter_t... > letter_t
const valuesets_t & sets() const
The componants valuesets, as a tuple.
bool is_zero(const value_t &l) const
self_t meet_(const self_t &rhs, seq< I... >) const
The intersection with another tupleset.
static type value(const labelset_t &ls)
static self_t make_(std::istream &i, seq< I... >)
ValueSet::value_t lgcd(const ValueSet &vs, const typename ValueSet::value_t &lhs, const typename ValueSet::value_t &rhs)
Left-division of values.
static auto one_(seq< I... >) -> decltype(value_t
static constexpr std::size_t size()
Number of tapes.
std::set< letter_t, vcsn::less< tupleset< ValueSets... >, letter_t >> letters_t
static constexpr bool is_commutative()
The smallest nullableset which includes LabelSet.
Value delimit(const Value &l) const
Add the special character first and last.
static constexpr bool has_lightening_weights()
static type join(const vs1_t &lhs, const vs2_t &rhs)
The resulting valueset.
static bool equal(const value_t &l, const value_t &r)
Whether l equals r.
A ValueSet which is a Cartesian product of ValueSets.
Whether a ValueSet, or a context, is multitape.
static auto size_(const Value &v, int) -> decltype(valueset_t< I >::size(std::get< I >(v)))
The size of the Ith element, if its valueset features a size() function.
auto letters_of_padded_(const Value &v, const std::tuple< Defaults... > &def, seq< I... >) const -> decltype(zip_with_padding(def, this->set< I >().letters_of_padded(std::get< I >(v), std::get< I >(def))...))
Must be declared before, as we use its result in decltype.
friend self_t meet(const self_t &lhs, const b &)
The meet with the B weightset.
bool is_special(const Aut &aut, transition_t_of< Aut > t)
Whether this transition is from pre or to post.
tuple_element_t< I, valuesets_t > valueset_t
The Ith valueset type.
static bool is_one_(const value_t &l, seq< I... >)
static bool is_special(const value_t &l)
value_t value(const std::tuple< Args... > &args) const
Construct a value.
auto get_letter(std::istream &i, bool quoted=true) const -> decltype(this->get_letter_(i, quoted, indices))
valueset_t< 0 >::value_t lnormalize_here(value_t &v) const
Eliminate the LGCD between all the tapes.
An input/output format for valuesets.
static labelset_t labelset(const tupleset< LabelSets... > &ls)
static auto one() -> decltype(one_(Indices
A tuple of ones.
static type join(const vs1_t &lhs, const vs2_t &rhs, index_sequence< I... >)
typename valueset_t::template project_t< Tape > type
std::ostream & print_set_(std::ostream &o, format fmt, seq< I... >) const
Value undelimit(const Value &l) const
Remove first and last characters, that must be "special".
context join(const context &c1, const context &c2)
Bridge.
typename labelset_types< ValueSets... >::genset_t genset_t
A tuple of generators if meaningful, void otherwise.
auto meet(const expressionset< Ctx1 > &a, const expressionset< Ctx2 > &b) -> expressionset< meet_t< Ctx1, Ctx2 >>
The meet of two expressionsets.
static type value(const tupleset< LabelSet > &ls)
value_t lgcd(const value_t &l, const value_t &r) const
Pointwise left GCD.
static auto letters_of_(const Value &v, seq< I... >) -> decltype(zip(valueset_t< I >::letters_of(std::get< I >(v))...))
Must be declared before, as we use its result in decltype.
Functor to compare Values of ValueSets.
static bool equal_(const value_t &l, const value_t &r, seq< I... >)
static bool is_special_(const value_t &l, seq< I... >)
Print as is. For instance, don't try to escape labels.
genset_ptr genset_(seq< I... >) const
static labelset_t labelset_(const tupleset< LabelSets... > &ls, seq< I... >)
Request the set implementation (bool weights).
Provide a range that allows to iterate over the cross product of the provided ranges.
const valueset_t< I > & project() const
The Ith component valueset.
std::ostream & print(const value_t &l, std::ostream &o=std::cout, format fmt={}) const
A traits to compute the letterized context.
static auto less(const LhsValue &l, const RhsValue &r) -> bool
Whether l < r.
Print as rich UTF-8 text, escaped.
auto mul_(const LhsValue &l, const RhsValue &r, seq< I... >) const -> word_t
auto project(const value_t &v) const
The I-th component of the value.
auto letters_of_padded(const Value &v, const std::tuple< Defaults... > &def) const -> decltype(this->letters_of_padded_(v, def, indices))
Iterate over the letters of v.
value_t conv(b, b::value_t v) const
void hash_combine(std::size_t &seed, const T &v)
Value undelimit_(const Value &l, seq< I... >) const
static constexpr bool is_letterized()
bool is_zero_(const value_t &l, seq< I... >) const
valuesets_t sets_
The tupled valuesets.
static auto letters_of(const Value &v) -> decltype(letters_of_(v, indices))
Iterate over the letters of v.
value_t conv_(std::istream &i, bool quoted, std::false_type) const
Read a tuple in the stream, possibly parenthesized.
word_t word_(const std::tuple< Args... > &l, seq< I... >) const
typename project_labelset_impl< Tape, LabelSet >::type project_labelset
The type of the resulting apparent LabelSet when keeping only tape Tape.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
bool is_letter(const value_t &) const
static size_t size_(const Value &v, seq< I... >)
void convs(std::istream &i, Fun &&fun) const
Fun: (label_t) -> void.
static value_t special_(seq< I... >)
static constexpr bool is_free_(seq< I... >)
static std::size_t hash_(const value_t &v, seq< I... >)
std::tuple< typename ValueSets::word_t... > word_t
typename labelset_types< ValueSets... >::genset_ptr genset_ptr
value_t map_impl_(const value_t &l, const value_t &r, Fun &&fun, seq< I... >) const
static bool is_one(const value_t &l)
std::integral_constant< bool, B > bool_constant
static constexpr bool is_letterized_(seq< I... >)
From a labelset, its non-nullable labelset.
static type value(const labelset_t &ls)
static constexpr auto size_(const Value &,...) -> size_t
The size of the Ith element, if its valueset does not feature a size() function.
Provide a variadic mul on top of a binary mul(), and one().
Print as plain (ASCII) text, escaped.
static constexpr bool has_lightening_weights_(seq< I... >)
char eat(std::istream &is, char c)
Check lookahead character and advance.
zip_sequences_padded< zip_sequences< Sequences... > > zip_with_padding(const std::tuple< typename Sequences::value_type... > &pad, const Sequences &...seq)
auto mul(const LhsValue &l, const RhsValue &r) const -> word_t
The product (possibly concatenation) of l and r.
static type value(const labelset_t &ls, index_sequence< I... >)
static type value(const labelset_t &ls)
auto make_gcc_tuple(Ts &&...ts) -> decltype(reverse_tuple(std::make_tuple(std::forward< Ts >(ts)...)))
Same as make_tuple, unless the evaluation of arguments if right-to-left, in which case reverse the re...
LabelSet::letters_t conv_label_class_(const LabelSet &ls, std::istream &i)
Read a set of letters (hence, guaranteed in order, and unique).
value_t conv(std::istream &i, bool quoted=true) const
Read one label from i, return the corresponding value.
genset_ptr genset() const
value_t map_(const value_t &l, const value_t &r, Fun &&fun) const
Apply a binary function pointwise, and return the tuple of results.
The type of the resulting apparent LabelSet when keeping only tape Tape.
value_t rdivide(const value_t &l, const value_t &r) const
Pointwise right division (l / r).
static constexpr bool is_expressionset_(seq< I... >)
genset_t generators_(seq< I... >) const
value_t ldivide(const value_t &l, const value_t &r) const
Pointwise left division (l \ r).
static bool show_one_(seq< I... >)
void print_(std::ostream &o, const T &arg, long)
Serialize arg into o.
weightset_mixin< detail::r_impl > r