1 #ifndef VCSN_CORE_RAT_EXPRESSIONSET_HH
2 # define VCSN_CORE_RAT_EXPRESSIONSET_HH
29 template <
typename Context>
41 using weight_t =
typename weightset_t::value_t;
50 # define DEFINE(Type) \
51 using Type ## _t = vcsn::rat::Type<context_t>
79 template <type_t Type>
81 template <type_t Type>
101 bool open(
bool o)
const;
117 return atom(labelset_t::special());
155 return weightset_t::is_idempotent();
188 template <
typename GenSet>
197 template <
typename Ctx2>
243 template <
typename... Value>
268 template <
typename... Args>
278 template <
typename Fun>
279 static void convs(std::istream&, Fun)
281 raise(
sname(),
": ranges not implemented");
292 template <
unsigned Tape,
typename Ctx = context_t>
297 template <
typename Sequence>
300 template <
size_t... I>
308 return {detail::make_project<I>(
self)...};
313 template <
typename Ctx = context_t>
318 template <
typename Ctx = context_t>
336 const self_t&
self()
const {
return static_cast<const self_t&
>(*this); }
363 template <type_t Type>
370 template <type_t Type>
379 template <
typename LabelSet_,
typename... Args>
383 template <
typename LabelSet_>
386 typename LabelSet_::letter_t>> chars,
388 std::false_type)
const;
391 template <
typename Dummy =
void>
397 return is_label_(v, labelset_t::indices);
404 return as_label_(v, labelset_t::indices);
407 template <
size_t... I>
412 && labelset_t::template valueset_t<I>::has_one()))...})
418 template <
size_t... I>
431 (std::get<I>(v.
sub()))->value();
446 template <
typename Ctx>
457 template <
typename Ctx>
468 template <
typename Ctx1,
typename Ctx2>
476 return {
vcsn::join(lhs.context(), rhs.context()),
477 vcsn::join(lhs.identities(), rhs.identities())};
483 template <
typename GenSet1,
typename Ctx2>
493 return {context_t{
vcsn::join(a, *b.labelset()), *b.weightset()},
499 template <
typename Context>
509 template <
typename W1,
typename W2>
512 template <
typename WeightSet,
typename Context>
520 return {context_t{*rs.labelset(),
vcsn::join(ws, *rs.weightset())},
524 #define JOIN_IMPL_SIMPLE(WS) \
525 template <typename Context> \
526 struct join_impl<WS, expressionset<Context>> \
527 : public join_impl_simple<WS, expressionset<Context>> \
536 #undef JOIN_IMPL_SIMPLE
541 template <
typename Context>
549 template <
typename Ctx1,
typename Ctx2>
555 return {
meet(a.context(),
b.context()),
556 meet(a.identities(),
b.identities())};
563 #endif // !VCSN_CORE_RAT_EXPRESSIONSET_HH
typename node_t::value_t value_t
An expression (a shared pointer to a tree).
static constexpr star_status_t star_status()
When used as WeightSet.
static label_t as_label_(const tuple_t &v, detail::index_sequence< I...>)
static constexpr bool show_one()
When used as WeightSet.
typename context_t::labelset_ptr labelset_ptr
static void convs(std::istream &, Fun)
Read a range of expressions.
value_t concat_(const value_t &l, const value_t &r, std::true_type) const
If labelset is wordset.
weightset_t_of< context_t > weightset_t
auto as_tupleset() const -> enable_if_t< Ctx::is_lat, as_tupleset_t< Ctx >>
If we are multitape, ourself as a tupleset.
static bool less_linear(const value_t &l, const value_t &r)
Whether l < r, ignoring lweight.
Implementation of labels are letters.
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
The root from which to derive the final node types.
static constexpr bool is_commutative()
When used as WeightSet.
label_t_of< context_t > label_t
static bool is_special(const value_t &v)
When used as a LabelSet.
static type join(const letterset< GenSet1 > &a, const expressionset< Ctx2 > &b)
auto label_one() -> enable_if_t< LabelSet::has_one(), typename LabelSet::value_t >
This LabelSet's one(), if supported.
static focus_t< I >::label_t as_label_(const tuple_t &v)
rat::identities identities_t
const identities_t ids_
The set of rewriting rules to apply.
identities_t identities() const
Accessor to the identities set.
value_t ldiv(const value_t &l, const value_t &r) const
The abstract parameterized, root for all rational expression types.
A structure that implements the computation of join(V1, V2).
std::string type(const automaton &a)
The implementation type of a.
context_t ctx_
The context of the expressions.
type_t
The possible types of expressions.
auto join(const ValueSet &vs) -> ValueSet
The join of a single valueset.
std::istringstream is
The input stream: the specification to translate.
static size_t size(const value_t &v)
The size of v.
static constexpr bool is_letterized()
When used as a labelset.
Turn a tuple of expressions that are labels into a multi-tape label.
static type value(const type &ls)
static size_t hash(const value_t &v)
Hash v.
vcsn::rat::sum< context_t > sum_t
value_t power(const value_t &e, unsigned n) const
Add a power operator.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
labelset_t_of< context_t > labelset_t
static value_t special()
When used as a LabelSet.
typename std::enable_if< Cond, T >::type enable_if_t
value_t letter_class(Args &&...chars) const
An expression matching one character amongst chars.
static bool equal(const value_t &l, const value_t &r)
Whether l == r.
static value_t unwrap_possible_lweight_(const value_t &e)
If e is an lweight, then its child, otherwise e.
word_t word(label_t l) const
Make a `word' out of an expression.
#define DEFINE(Type)
Type of expressions.
static type value(const self_t &self)
typename context_t::weightset_ptr weightset_ptr
value_t complement(const value_t &e) const
Add a complement operator.
value_t mul(const value_t &l, const value_t &r) const
static type join(const b &, const expressionset< Context > &rhs)
static constexpr bool has_one()
When used as WeightSet.
typename as_tupleset_impl< typename labelset_t_of< Ctx >::indices_t::type >::type as_tupleset_t
If we are multitape, our type as a tupleset.
value_t add(const value_t &l, const value_t &r) const
value_t letter_class_(const Args &&...chars, std::true_type) const
If labelset is oneset.
typename node_t::values_t values_t
A list (vector) of expressions.
const labelset_ptr & labelset() const
Accessor to the labelset.
static dyn::context ctx(const driver &d)
Get the context of the driver.
std::vector< value_t > values_t
static bool is_label_(const tuple_t &v, detail::index_sequence< I...>)
typename node_t::type_t type_t
Type tag for AST classes.
#define JOIN_IMPL_SIMPLE(WS)
value_t transposition(const value_t &e) const
Add a transposition operator.
bool open(bool o) const
Whether unknown letters should be added, or rejected.
value_t shuffle(const value_t &l, const value_t &r) const
expressionset_impl(const context_t &ctx, identities_t ids={})
Constructor.
value_t star(const value_t &e) const
Provide a variadic mul on top of a binary mul(), and one().
static bool less(const value_t &l, const value_t &r)
Whether l < r.
bool is_letter(value_t) const
When used as a LabelSet.
rat::type_t type_t
The possible types of expressions.
value_t rdiv(const value_t &l, const value_t &r) const
static type join(const WeightSet &ws, const expressionset< Context > &rs)
bool is_zero(const value_t &v) const ATTRIBUTE_PURE
When used as WeightSet.
Implementation of nodes of tuple of rational expressions.
value_t conv(const letterset< GenSet > &ls, typename letterset< GenSet >::value_t v) const
static identities ids(const driver &d)
Get the identities of the driver.
static type value(const type &ls)
decltype(join(std::declval< ValueSets >()...)) join_t
The type of the join of the ValueSets.
const weightset_ptr & weightset() const
Accessor to the weightset.
std::ostream & print_set(std::ostream &o, format fmt={}) const
Format the description of this expressionset.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
value_t conjunction(const value_t &l, const value_t &r) const
static type join(const expressionset< Ctx1 > &lhs, const expressionset< Ctx2 > &rhs)
const context_t & context() const
Accessor to the context.
std::ostream & print(const value_t &v, std::ostream &o, format fmt={}) const
expressionset< Context > make_expressionset(const Context &ctx, rat::identities identities={})
Shorthand to expressionset constructor.
static constexpr bool is_free()
When used as WeightSet.
typename weightset_t::value_t weight_t
static weight_t possibly_implicit_lweight_(const value_t &e)
The weight of e if it's an lweight, otherwise the weight one().
static label_t as_label(const tuple_t &v)
All the components are (single-tape) labels: make this a multitape label.
static self_t make(std::istream &is)
Build from the description in is.
value_t tuple(Value &&...v) const
static bool is_label(const tuple_t &v)
Are all the components labels?
std::shared_ptr< const node_t > value_t
An expression usable with value semantics.
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
An expressionset can implement several different sets of identities on expressions.
static symbol sname()
Static description key.
expressionset< detail::project_context< Tape, Ctx >> focus_t
The type of the expressionset for the Tape-th tape.
static constexpr bool is_expressionset()
When used as WeightSet.
The smallest nullableset which includes LabelSet.
static auto atom(const label_t &v) -> value_t
Build a label.
value_t infiltration(const value_t &l, const value_t &r) const
pair_automaton< Aut > pair(const Aut &aut, bool keep_initials=false)
identities meet(identities i1, identities i2)
value_t add_(values_t &&vs) const
From a list of values, build a sum, taking care of the empty and singleton cases. ...
value_t transpose(const value_t &e) const
The transposed of this rational expression.
An inner node implementing a weight.
static bool is_one(const value_t &v) ATTRIBUTE_PURE
When used as WeightSet.
const values_t sub() const
value_t rmul(const value_t &e, const weight_t &w) const
Right-multiplication by a weight.
void gather_(values_t &res, const value_t &v) const
Push v in res, applying associativity if possible.
value_t add_linear_(const sum_t &addends, const value_t &r) const
static type_t type_ignoring_lweight_(const value_t &e)
The type of e, or the type of its child if e is a lweight.
value_t concat(const value_t &l, const value_t &r) const
Similar to mul, but in the case of LAW, merge the labels.
static constexpr bool is_idempotent()
When used as WeightSet.
expressionset< Context > self_t
value_t lmul(const weight_t &w, const value_t &e) const
Left-multiplication by a weight.
rat::identities identities(const expression &exp)
Bridge.
An inner node with multiple children.