Vcsn  2.8
Be Rational
compose-expression.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/dyn/context.hh>
4 #include <vcsn/dyn/value.hh>
5 #include <vcsn/misc/tuple.hh>
7 
8 namespace vcsn
9 {
10  /*--------------------.
11  | compose_labelset. |
12  `--------------------*/
13 
14  namespace detail
15  {
16  template <typename... LS1, typename... LS2,
17  std::size_t... I1, std::size_t... I2>
18  auto
20  const tupleset<LS2...>& ls2,
23  {
24  return make_tupleset(ls1.template set<I1>()...,
25  ls2.template set<I2>()...);
26  }
27  }
28 
29  template <typename... LS1, typename... LS2>
30  auto
32  const tupleset<LS2...>& ls2)
33  {
34  // Tape of the lhs on which we compose.
35  constexpr auto out = tupleset<LS1...>::size() - 1;
36  // Tape of the rhs on which we compose.
37  constexpr auto in = 0;
38  using indices1_t = detail::punched_sequence<tupleset<LS1...>::size(), out>;
39  using indices2_t = detail::punched_sequence<tupleset<LS2...>::size(), in>;
40  return detail::compose_labelset_impl(ls1, ls2,
41  indices1_t{}, indices2_t{});
42  }
43 
44 
45  /*-------------------------------.
46  | compose_context(context...). |
47  `-------------------------------*/
48 
49  template <typename Ctx1, typename Ctx2>
50  auto
51  compose_context(const Ctx1& ctx1, const Ctx2& ctx2)
52  {
53  auto ls = compose_labelset(*ctx1.labelset(), *ctx2.labelset());
54  auto ws = join(*ctx1.weightset(), *ctx2.weightset());
55  return make_context(ls, ws);
56  }
57 
58  namespace dyn
59  {
60  namespace detail
61  {
63  template <typename ContextLhs, typename ContextRhs>
64  context
65  compose_context(const context& lhs, const context& rhs)
66  {
67  return ::vcsn::compose_context(lhs.as<ContextLhs>(),
68  rhs.as<ContextRhs>());
69  }
70  }
71  }
72 
73 
74  /*-------------------------.
75  | compose(Value, Value). |
76  `-------------------------*/
77 
79  template <typename ValueSet>
80  typename ValueSet::value_t
81  compose(const ValueSet& vs,
82  const typename ValueSet::value_t& lhs,
83  const typename ValueSet::value_t& rhs)
84  {
85  return vs.compose(lhs, rhs);
86  }
87 
88 
89  /*---------------------------------.
90  | compose(expansion, expansion). |
91  `---------------------------------*/
92 
93  namespace dyn
94  {
95  namespace detail
96  {
98  template <typename ExpSetLhs, typename ExpSetRhs>
99  expansion
100  compose_expansion(const expansion& lhs, const expansion& rhs)
101  {
102  auto join_elts = join<ExpSetLhs, ExpSetRhs>(lhs, rhs);
103  return {std::get<0>(join_elts),
104  ::vcsn::compose(std::get<0>(join_elts),
105  std::get<1>(join_elts),
106  std::get<2>(join_elts))};
107  }
108  }
109  }
110 
111  /*-----------------------------------.
112  | compose(expression, expression). |
113  `-----------------------------------*/
114 
115  namespace dyn
116  {
117  namespace detail
118  {
120  template <typename ExpSetLhs, typename ExpSetRhs>
121  expression
122  compose_expression(const expression& lhs, const expression& rhs)
123  {
124  auto join_elts = join<ExpSetLhs, ExpSetRhs>(lhs, rhs);
125  return {std::get<0>(join_elts),
126  ::vcsn::compose(std::get<0>(join_elts),
127  std::get<1>(join_elts),
128  std::get<2>(join_elts))};
129  }
130  }
131  }
132 
133  /*-------------------------.
134  | compose(label, label). |
135  `-------------------------*/
136 
137  namespace dyn
138  {
139  namespace detail
140  {
142  template <typename LabelSetLhs, typename LabelSetRhs>
143  label
144  compose_label(const label& lhs, const label& rhs)
145  {
146  const auto& l1 = lhs->as<LabelSetLhs>();
147  const auto& l2 = rhs->as<LabelSetRhs>();
148  auto ls = compose_labelset(l1.valueset(), l2.valueset());
149  return {ls,
150  ls.compose(l1.valueset(), l1.value(),
151  l2.valueset(), l2.value())};
152  }
153  }
154  }
155 
156  /*-----------------------------------.
157  | compose(polynomial, polynomial). |
158  `-----------------------------------*/
159 
160  template <typename Ctx1, typename Ctx2>
161  auto
163  const polynomialset<Ctx2>& ps2)
164  {
165  return make_polynomialset(compose_context(ps1.context(),
166  ps2.context()));
167  }
168 
169  namespace dyn
170  {
171  namespace detail
172  {
174  template <typename PolSetLhs, typename PolSetRhs>
175  polynomial
176  compose_polynomial(const polynomial& lhs, const polynomial& rhs)
177  {
178  const auto& p1 = lhs->as<PolSetLhs>();
179  const auto& p2 = rhs->as<PolSetRhs>();
180  auto ps = compose_polynomialset(p1.valueset(), p2.valueset());
181  return {ps,
182  ps.compose(p1.valueset(), p1.value(),
183  p2.valueset(), p2.value())};
184  }
185  }
186  }
187 }
value_impl< detail::expansion_tag > expansion
Definition: fwd.hh:30
tupleset< ValueSets... > make_tupleset(const ValueSets &... vss)
Definition: tupleset.hh:1238
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
expansion compose_expansion(const expansion &lhs, const expansion &rhs)
Bridge (compose).
expression compose_expression(const expression &lhs, const expression &rhs)
Bridge (compose).
auto & as()
Extract wrapped typed value.
Definition: value.hh:55
auto compose_labelset(const tupleset< LS1... > &ls1, const tupleset< LS2... > &ls2)
polynomialset< Context, Kind > make_polynomialset(const Context &context)
value_impl< detail::polynomial_tag > polynomial
Definition: fwd.hh:33
Ctx make_context(const std::string &name)
Build a context from its name.
Definition: make-context.hh:21
context compose_context(const context &lhs, const context &rhs)
Bridge (compose).
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
auto join(const ValueSet &vs) -> ValueSet
The join of a single valueset.
Definition: join.hh:44
A dyn Value/ValueSet.
Definition: fwd.hh:29
Template-less root for contexts.
Definition: context.hh:16
auto compose_polynomialset(const polynomialset< Ctx1 > &ps1, const polynomialset< Ctx2 > &ps2)
Definition: a-star.hh:8
auto in(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions arriving to state s.
Definition: automaton.hh:135
ValueSet::value_t compose(const ValueSet &vs, const typename ValueSet::value_t &lhs, const typename ValueSet::value_t &rhs)
Composition of values.
auto & as()
Downcast to the exact type.
Definition: context.hh:36
A static list of size_t.
Definition: tuple.hh:32
polynomial compose_polynomial(const polynomial &lhs, const polynomial &rhs)
Bridge (compose).
label compose_label(const label &lhs, const label &rhs)
Bridge (compose).
auto compose_context(const Ctx1 &ctx1, const Ctx2 &ctx2)
value_impl< detail::expression_tag > expression
Definition: fwd.hh:31
auto compose_labelset_impl(const tupleset< LS1... > &ls1, const tupleset< LS2... > &ls2, detail::index_sequence< I1... >, detail::index_sequence< I2... >)
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
Definition: automaton.hh:86