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 symbol res(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());
165 return this->open_(o, indices);
169 template <
typename... Args>
172 return this->value_(args, indices);
176 template <
typename... Args>
185 return this->genset_(indices);
192 return this->generators_(indices);
197 return is_free_(indices);
201 template <
typename... Args>
203 word(
const std::tuple<Args...>&
v)
const
206 return this->word_(
v, indices);
213 return equal_(l, r, indices);
217 template <
typename LhsValue,
typename RhsValue>
219 less(
const LhsValue& l,
const RhsValue&
r)
229 return less_(l,
r, indices);
235 return special_(indices);
241 return is_special_(l, indices);
247 return this->zero_(indices);
253 return is_zero_(l, indices);
256 static constexpr
bool
259 return has_lightening_weights_(indices);
262 static constexpr
bool
265 return has_one_(indices);
268 static constexpr
bool
271 return is_expressionset_(indices);
274 static constexpr
bool
277 return is_letterized_(indices);
281 template <std::size_t... I>
293 template <
typename Indices = indices_t>
294 static auto one() -> decltype(one_(Indices{}))
296 return one_(Indices{});
302 return is_one_(l, indices);
308 return show_one_(indices);
323 [](
const auto& vs,
const auto& l,
const auto& r)
333 template <
typename LhsValue,
typename RhsValue>
335 mul(
const LhsValue& l,
const RhsValue&
r)
const
338 return this->mul_(l,
r, indices);
346 [](
const auto& vs,
const auto& l,
const auto& r)
348 return vs.lgcd(l, r);
357 [](
const auto& vs,
const auto& l,
const auto& r)
359 return vs.rdiv(l, r);
368 [](
const auto& vs,
const auto& l,
const auto& r)
370 return vs.ldiv(l, r);
378 typename valueset_t<0>::value_t
381 return this->lnormalize_here_(v, indices);
389 [](
const auto& vs,
const auto& v)
400 template <
typename Value>
404 return this->delimit_(l, indices);
408 template <
typename Value>
412 return this->undelimit_(l, indices);
422 template <
typename Value>
426 return this->transpose_(l, indices);
432 return hash_(v, indices);
444 return v ? one() : zero();
448 template <
typename... VS>
453 return this->conv_(vs, v, indices);
457 template <
typename... VS>
462 return conv(*vs.labelset(), vs.get_value(v));
467 conv(std::istream& i,
bool quoted =
true)
const
471 constexpr
auto has_label_one
477 template <
typename Fun>
478 void convs(std::istream& i, Fun&& fun)
const
482 [
this,fun](
const letter_t& l) { fun(value(l)); });
489 return this->print_set_(o, fmt, indices);
500 fmt.delimit() ?
"(" :
"",
501 fmt.is_for_labels() ?
"|" :
",",
502 fmt.delimit() ?
")" :
"",
507 template <std::size_t... I>
510 std::string res =
"lat<";
511 const char *sep =
"";
522 template <std::size_t... I>
523 static constexpr
bool
526 return all_<valueset_t<I>::is_commutative()...>();
529 template <std::size_t... I>
530 static constexpr
bool
533 return all_<valueset_t<I>::is_idempotent()...>();
536 template <std::size_t... I>
539 #if VCSN_HAVE_CORRECT_LIST_INITIALIZER_ORDER
540 return self_t{(eat_separator_<I>(i),
544 ((eat_separator_<
sizeof...(ValueSets)-1 -I>(i),
545 valueset_t<
sizeof...(ValueSets)-1 -I>::make(i))...);
549 template <std::size_t... I>
552 using swallow =
int[];
553 (
void) swallow { set<I>().open(o)... };
554 std::swap(o, open__);
560 template <
typename Value, std::
size_t I>
569 template <
typename Value, std::
size_t I>
570 static constexpr
auto size_(
const Value&, ...)
576 template <
typename Value, std::size_t... I>
579 return std::max({size_<Value, I>(
v, 0)...});
582 template <
typename... Args, std::size_t... I>
585 return value_t{set<I>().value(std::get<I>(args))...};
588 template <std::size_t... I>
595 template <std::size_t... I>
602 template <std::size_t... I>
603 static constexpr
bool
606 return all_<valueset_t<I>::is_free()...>();
609 template <
typename... Args, std::size_t... I>
613 return word_t{set<I>().word(std::get<I>(l))...};
616 template <std::size_t... I>
627 template <
typename LhsValue,
typename RhsValue, std::size_t... I>
635 std::get<I>(l)))...})
643 template <std::size_t... I>
653 template <std::size_t... I>
660 template <std::size_t... I>
670 template <std::size_t... I>
674 return value_t{set<I>().zero()...};
677 template <std::size_t... I>
681 for (
auto n: {set<I>().is_zero(std::get<I>(l))...})
687 template <std::size_t... I>
688 static constexpr
bool
691 return all_<valueset_t<I>::has_lightening_weights()...>();
694 template <std::size_t... I>
695 static constexpr
bool
698 return all_<valueset_t<I>::has_one()...>();
701 template <std::size_t... I>
702 static constexpr
bool
705 return all_<valueset_t<I>::is_expressionset()...>();
708 template <std::size_t... I>
709 static constexpr
bool
715 template <std::size_t... I>
725 template <std::size_t... I>
736 template <
typename Fun>
740 return map_impl_(v, std::forward<Fun>(fun), indices);
743 template <
typename Fun, std::size_t... I>
747 return value_t{fun(set<I>(), std::get<I>(v))...};
751 template <
typename Fun>
755 return map_impl_(l, r, std::forward<Fun>(fun), indices);
758 template <
typename Fun, std::size_t... I>
762 return value_t{fun(set<I>(), std::get<I>(l), std::get<I>(r))...};
765 template <
typename LhsValue,
typename RhsValue, std::size_t... I>
770 return word_t{set<I>().mul(std::get<I>(l), std::get<I>(
r))...};
773 template <std::size_t... I>
774 typename valueset_t<0>::value_t
778 for (
auto v: {std::get<I>(vs)...})
779 res = set<0>().
lgcd(res, v);
780 using swallow =
int[];
781 (
void) swallow { (set<0>().ldiv_here(res, std::get<I>(vs)), 0)... };
785 template <
typename Value, std::size_t... I>
789 return Value{set<I>().delimit(std::get<I>(l))...};
792 template <
typename Value, std::size_t... I>
796 return Value{set<I>().undelimit(std::get<I>(l))...};
799 template <
typename... VS, std::size_t... I>
805 return value_t{set<I>().
conv(vs.template set<I>(), std::get<I>(
v))...};
811 conv_(std::istream& i,
bool quoted, std::true_type)
const
817 return conv_(i, quoted, std::false_type{});
822 conv_(std::istream& i,
bool quoted, std::false_type)
const
824 bool par = i.peek() ==
'(';
827 value_t res = conv_(i, quoted, indices);
833 template <std::size_t... I>
837 #if VCSN_HAVE_CORRECT_LIST_INITIALIZER_ORDER
838 return value_t{(eat_separator_<I>(i),
839 set<I>().conv(i, quoted))...};
841 constexpr
auto S =
sizeof...(ValueSets)-1;
844 set<S - I>().
conv(i, quoted))...);
852 template <std::
size_t I>
857 eat(i, i.peek() ==
',' ?
',' :
'|');
858 while (isspace(i.peek()))
863 template <std::size_t... I>
874 using swallow =
int[];
877 (o << (I == 0 ? pre : sep),
878 set<I>().print(std::get<I>(l), o, fmt),
886 template <std::size_t... I>
891 const char *sep =
"";
892 const char *close =
"";
913 using swallow =
int[];
916 (o << (I == 0 ?
"" : sep),
917 set<I>().print_set(o, fmt),
924 template <
typename Value, std::size_t... I>
928 return Value{set<I>().
transpose(std::get<I>(l))...};
932 template <std::size_t... I>
936 return self_t{
meet(set<I>(), rhs.template set<I>())...};
944 return lhs.meet_(rhs, indices);
966 mutable bool open__ =
false;
970 template <std::size_t... I>
975 #if VCSN_HAVE_CORRECT_LIST_INITIALIZER_ORDER
976 return letter_t{(eat_separator_<I>(i),
977 set<I>().get_letter(i, quoted))...};
979 constexpr
auto S =
sizeof...(ValueSets)-1;
982 set<S - I>().get_letter(i, quoted))...);
987 template <
typename Value, std::size_t... I>
996 template <
typename Value,
typename... Defaults, std::size_t... I>
999 const std::tuple<Defaults...>& def,
seq<I...>) const
1001 this->
set<I>().letters_of_padded(
std::get<I>(v),
1002 std::get<I>(def))...))
1005 set<I>().letters_of_padded(std::get<I>(v),
1006 std::get<I>(def))...);
1010 template <std::size_t... I>
1013 -> decltype(this->get_letter_(i, quoted, indices))
1015 bool par = i.peek() ==
'(';
1018 auto res = get_letter_(i, quoted, indices);
1029 template <
typename Value>
1032 -> decltype(letters_of_(v, indices))
1034 return letters_of_(v, indices);
1042 template <
typename Value,
typename... Defaults>
1045 -> decltype(this->letters_of_padded_(v, def, indices))
1047 return letters_of_padded_(v, def, indices);
1051 template <
typename... ValueSets>
1064 template <
typename ValueSet>
1069 template <
typename... ValueSet>
1074 template <
typename LabelSet,
typename WeightSet>
1081 template <
typename T1,
typename T2>
1089 template <
typename... T1,
typename... T2>
1097 template <
typename... LabelSets>
1102 template <std::size_t... I>
1108 template <std::size_t... I>
1123 template <std::size_t... I>
1132 template <
typename... LabelSets>
1134 std::enable_if_t<tupleset<LabelSets...>::has_one()>>
1145 template <
typename... LabelSets>
1147 std::enable_if_t<!tupleset<LabelSets...>::has_one()>>
1159 template <
typename LabelSet>
1170 template <
typename... LabelSets>
1176 template <std::size_t... I>
1189 template <
typename... VS1,
typename... VS2>
1192 static_assert(
sizeof...(VS1) ==
sizeof...(VS2),
1193 "join: tuplesets must have the same sizes");
1199 template <std::size_t... I>
1203 return {
::vcsn::join(lhs.template set<I>(), rhs.template set<I>())...};
1209 return join(lhs, rhs,
1215 template <
typename... VS1,
typename VS2>
1221 "join: cannot mix tuplesets and non tuplesets");
1231 template <
size_t Tape,
typename LabelSet>
1236 template <
size_t Tape,
typename LabelSet>
1240 template <
size_t Tape,
typename... LabelSets>
1244 using type =
typename labelset_t::template valueset_t<Tape>;
1248 template <
size_t Tape,
typename Context>
1262 template <
size_t Tape,
typename Context>
value_t rdiv(const value_t &l, const value_t &r) const
Pointwise right division (l / r).
ValueSet::value_t tuple(const ValueSet &vs, const typename ValueSets::value_t &...v)
typename project_labelset_impl< Tape, LabelSet >::type project_labelset
The type of the resulting apparent LabelSet when keeping only tape Tape.
value_t map_impl_(const value_t &l, const value_t &r, Fun &&fun, seq< I... >) const
static value_t special_(seq< I... >)
std::integral_constant< bool, B > bool_constant
auto join(const ValueSet &vs) -> ValueSet
The join of a single valueset.
static labelset_t labelset(const tupleset< LabelSets... > &ls)
static std::size_t hash_(const value_t &v, seq< I... >)
static bool is_one(const value_t &l)
static size_t size(const Value &v)
Get the max of the sizes of the tapes.
static constexpr bool has_lightening_weights_(seq< I... >)
static auto less(const LhsValue &l, const RhsValue &r) -> bool
Whether l < r.
value_t conv(b, b::value_t v) const
static auto less_(const LhsValue &l, const RhsValue &r, seq< I... >) -> bool
auto mul(const LhsValue &l, const RhsValue &r) const -> word_t
The product (possibly concatenation) of l and r.
genset_ptr genset() const
static labelset_t labelset_(const tupleset< LabelSets... > &ls, seq< I... >)
const valueset_t< I > & set() const
The Ith component valueset.
Print as rich UTF-8 text, escaped.
static void eat_separator_(std::istream &i)
Read the separator from the input stream i if I is not 0.
tupleset_impl(ValueSets...ls)
bool is_letterized(const Aut &aut)
Check if the transitions are all letters.
static auto letters_of(const Value &v) -> decltype(letters_of_(v, indices))
Iterate over the letters of v.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
value_t map_impl_(const value_t &v, Fun &&fun, seq< I... >) const
value_t conv_(std::istream &i, bool quoted, seq< I... >) const
Implementation of labels are nullables (letter or empty).
value_t value_(const std::tuple< Args... > &args, seq< I... >) const
typename labelset_types< ValueSets... >::word_t word_t
A tuple of words if meaningful, void otherwise.
Whether a ValueSet, or a context, is multitape.
friend self_t meet(const self_t &lhs, const self_t &rhs)
The meet with another tupleset.
static type value(const labelset_t &ls)
Request the set implementation (bool weights).
static type value(const tupleset< LabelSet > &ls)
value_t zero_(seq< I... >) const
Value transpose_(const Value &l, seq< I... >) const
genset_t generators() const
The generators. Meaningful for labelsets only.
static constexpr auto size_(const Value &,...) -> size_t
The size of the Ith element, if its valueset does not feature a size() function.
static constexpr bool has_one_(seq< I... >)
A traits to compute the letterized context.
friend self_t meet(const b &, const self_t &rhs)
The meet with the B weightset.
tuple_element_t< I, valuesets_t > valueset_t
The Ith valueset type.
static constexpr bool has_one()
std::ostream & print(const value_t &l, std::ostream &o, format fmt={}) const
letter_t value_type
To be iterable.
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.
bool is_zero(const value_t &l) const
Print as is. For instance, don't try to escape labels.
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.
static constexpr bool is_expressionset()
static constexpr bool is_expressionset_(seq< I... >)
tupleset< ValueSets... > make_tupleset(const ValueSets &...vss)
static bool show_one_(seq< I... >)
value_t lgcd(const value_t &l, const value_t &r) const
Pointwise left GCD.
ValueSet::value_t lgcd(const ValueSet &vs, const typename ValueSet::value_t &lhs, const typename ValueSet::value_t &rhs)
Left-division of values.
weightset_mixin< detail::r_impl > r
An input/output format for valuesets.
static constexpr bool is_letterized_(seq< I... >)
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.
char eat(std::istream &is, char c)
Check lookahead character and advance.
static type join(const vs1_t &lhs, const vs2_t &rhs, index_sequence< I... >)
Provide a variadic mul on top of a binary mul(), and one().
static constexpr std::size_t size()
Number of tapes.
void print_(std::ostream &o, const T &arg, long)
Serialize arg into o.
value_t conv(const tupleset< VS... > &vs, const typename tupleset< VS... >::value_t &v) const
Convert a value from tupleset<...> to value_t.
std::tuple< typename ValueSets::letter_t... > letter_t
Aut transpose(const transpose_automaton< Aut > &aut)
std::tuple< typename ValueSets::value_t... > word_t
Same as value_t.
auto word(const std::tuple< Args... > &v) const -> word_t
Convert to a word.
Value delimit(const Value &l) const
Add the special character first and last.
zip_sequences< Sequences... > zip(Sequences &&...seqs)
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.
Provide a range that allows to iterate over the cross product of the provided ranges.
auto mul_(const LhsValue &l, const RhsValue &r, seq< I... >) const -> word_t
static auto one_(seq< I... >) -> decltype(value_t
static type join(const vs1_t &lhs, const vs2_t &rhs)
The resulting valueset.
static type value(const labelset_t &ls)
constant< type_t::one, Context > one
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.
static bool is_one_(const value_t &l, seq< I... >)
Value undelimit_(const Value &l, seq< I... >) const
void hash_combine(std::size_t &seed, const T &v)
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...
A structure that implements the computation of join(V1, V2).
auto get_letter_(std::istream &i, bool quoted, seq< I... >) const -> letter_t
Must be declared before, as we use its result in decltype.
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))
bool is_zero_(const value_t &l, seq< I... >) const
static constexpr bool has_lightening_weights()
static bool equal(const value_t &l, const value_t &r)
Whether l equals r.
value_t add(const value_t &l, const value_t &r) const
Pointwise addition.
static type value(const labelset_t &ls)
Value undelimit(const Value &l) const
Remove first and last characters, that must be "special".
typename std::tuple_element< I, T >::type tuple_element_t
C++14.
std::tuple< typename ValueSets::genset_ptr... > genset_ptr
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
std::ostream & print_set(std::ostream &o, format fmt={}) const
auto meet(const expressionset< Ctx1 > &a, const expressionset< Ctx2 > &b) -> expressionset< meet_t< Ctx1, Ctx2 >>
The meet of two expressionsets.
bool open(bool o) const
Whether unknown letters should be added, or rejected.
static constexpr bool is_commutative_(seq< I... >)
Print as plain (ASCII) text, escaped.
bool open_(bool o, seq< I... >) const
static constexpr bool is_idempotent_(seq< I... >)
const valuesets_t & sets() const
The componants valuesets, as a tuple.
The type of the resulting apparent LabelSet when keeping only tape Tape.
zip_sequences_padded< zip_sequences< Sequences... > > zip_with_padding(const std::tuple< typename Sequences::value_type... > &pad, const Sequences &...seq)
value_t star(const value_t &v) const
Pointwise star.
tupleset_impl(valuesets_t vs)
static self_t make_(std::istream &i, seq< I... >)
A traits so that tupleset may define types that may exist.
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.
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...
bool is_special(const Aut &aut, transition_t_of< Aut > t)
Whether this transition is from pre or to post.
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.
friend self_t meet(const self_t &lhs, const b &)
The meet with the B weightset.
static bool is_special_(const value_t &l, seq< I... >)
From a labelset, its non-nullable labelset.
std::set< letter_t, vcsn::less< tupleset< ValueSets... >, letter_t >> letters_t
std::istringstream is
The input stream: the specification to translate.
valuesets_t sets_
The tupled valuesets.
law_t< LabelSet > make_wordset(const LabelSet &ls)
The wordset of a labelset.
value_t conv_(std::istream &i, bool quoted, std::false_type) const
Read a tuple in the stream, possibly parenthesized.
static self_t make(std::istream &is)
Build from the description in is.
std::ostream & print_(const value_t &l, std::ostream &o, format fmt, const char *pre, const char *sep, const char *post, seq< I... >) const
word_t word_(const std::tuple< Args... > &l, seq< I... >) const
Print as a parsable type string.
static size_t size_(const Value &v, seq< I... >)
static bool is_special(const value_t &l)
valueset_t< 0 >::value_t lnormalize_here(value_t &v) const
Eliminate the LGCD between all the tapes.
static constexpr bool is_letterized_(seq< I... >)
std::ostream & print_set_(std::ostream &o, format fmt, seq< I... >) const
static auto one() -> decltype(one_(Indices
A tuple of ones.
self_t meet_(const self_t &rhs, seq< I... >) const
The intersection with another tupleset.
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 type value(const labelset_t &ls, index_sequence< I... >)
A ValueSet which is a Cartesian product of ValueSets.
std::enable_if_t<!is_letterized_t< labelset_t_of< Aut > >{}, bool > is_letterized(const Aut &aut)
The smallest nullableset which includes LabelSet.
typename labelset_t::template valueset_t< Tape > type
genset_ptr genset_(seq< I... >) const
void convs(std::istream &i, Fun &&fun) const
Fun: (label_t) -> void.
static constexpr bool is_free_(seq< I... >)
static constexpr bool is_commutative()
value_t conv(std::istream &i, bool quoted=true) const
Read one label from i, return the corresponding value.
typename labelset_types< ValueSets... >::genset_ptr genset_ptr
genset_t generators_(seq< I... >) const
context join(const context &c1, const context &c2)
Bridge.
static value_t conv(self_t, value_t v)
static constexpr star_status_t star_status()
static std::string sname_(seq< I... >)
letterized_t< LabelSet > make_letterized(const LabelSet &ls)
static size_t hash(const value_t &v)
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
bool is_letter(const value_t &) const
std::tuple< typename ValueSets::word_t... > word_t
cross_sequences< Sequences... > cross(Sequences &&...seqs)
typename labelset_types< ValueSets... >::letters_t letters_t
A set of letters if meaningful, void otherwise.
static constexpr bool is_letterized()
value_t tuple(Args &&...args) const
Construct a value.
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.
static constexpr bool is_idempotent()
Value delimit_(const Value &l, seq< I... >) const
typename labelset_types< ValueSets... >::genset_t genset_t
A tuple of generators if meaningful, void otherwise.
Functor to compare Values of ValueSets.
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 is_free()
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 ldiv(const value_t &l, const value_t &r) const
Pointwise left division (l \ r).
static bool equal_(const value_t &l, const value_t &r, seq< I... >)