5 #include <boost/optional.hpp>
30 template <
typename Context,
typename Tapes,
typename Enable =
void>
34 template <
typename Context>
68 template <
typename... LabelSets,
typename WeightSet,
72 std::enable_if_t<(0 < sizeof...(Tapes))>>
75 using in_labelset_t =
tupleset<LabelSets...>;
77 using in_label_t =
typename in_labelset_t::value_t;
80 template <std::size_t... I>
84 template <
typename S,
typename L>
88 template <
typename LabelSet>
89 struct tape_set<seq<>, LabelSet>
94 template <
size_t... I,
typename LabelSet>
95 struct tape_set<seq<I...>, LabelSet>
97 using type = tupleset<typename LabelSet::template valueset_t<I>...>;
107 using tape_labelset_t =
typename in_labelset_t::template valueset_t<I>;
118 using weight_index_t = seq<Tapes...>;
124 using inner_context_t = context<weight_tapes_t, WeightSet>;
127 using weightset_t = expressionset<inner_context_t>;
130 using context_t = context<labelset_t, weightset_t>;
133 static context_t value(
const in_context_t&
ctx,
136 return value_(ctx, ids, weight_index_t{}, kept_index_t{});
139 template <
size_t... WeightTapes,
size_t... KeptTapes>
140 static context_t value_(
const in_context_t& ctx,
150 = weight_tapes_t{ctx.labelset()->template set<WeightTapes>()...};
158 static typename labelset_t::value_t
164 template <
size_t... I>
165 static typename labelset_t::value_t
168 return typename labelset_t::value_t{std::get<I>(l)...};
172 static typename weight_tapes_t::value_t
178 template <
size_t... I>
179 static typename weight_tapes_t::value_t
182 return typename weight_tapes_t::value_t{std::get<I>(l)...};
187 template <
typename Ctx,
size_t... Tapes>
190 template <
Automaton Aut,
size_t... Tapes>
193 Tapes...>::context_t>;
196 template <
typename LabelSet,
typename WeightSet,
size_t... Tapes>
213 template <
Automaton Aut,
size_t... Tapes>
217 using auto_in_t = Aut;
218 using state_in_t = state_t_of<auto_in_t>;
220 using lifter = detail::lifter_t<context_t_of<Aut>, Tapes...>;
221 auto ctx_out = lifter::value(a->context(),
ids);
224 const auto& rs_in = *ctx_out.weightset();
227 using state_out_t = state_t_of<auto_out_t>;
228 auto_out_t
res = make_shared_ptr<auto_out_t>(ctx_out);
231 auto map = std::map<state_in_t, state_out_t>{};
232 map[a->pre()] = res->pre();
233 map[a->post()] = res->post();
234 for (
auto s: a->states())
235 map[s] = res->new_state();
238 if (a->src_of(t) == a->pre())
239 res->add_initial(map[a->dst_of(t)],
240 rs_in.lweight(a->weight_of(t), rs_in.one()));
241 else if (a->dst_of(t) == a->post())
242 res->add_final(map[a->src_of(t)],
243 rs_in.lweight(a->weight_of(t), rs_in.one()));
246 (map[a->src_of(t)], map[a->dst_of(t)],
248 rs_in.lweight(a->weight_of(t),
258 template <
Automaton Aut,
typename Ids,
typename... Tapes>
263 const auto& a = aut->
as<Aut>();
275 template <
typename ExpSet>
280 template <
typename Context>
283 boost::optional<vcsn::rat::identities> ids = {})
286 return {
lift_context(rs.context()), ids.get_value_or(rs.identities())};
291 template <
typename ExpSet>
292 typename detail::lifted_expressionset_t<ExpSet>::value_t
293 lift(
const ExpSet& rs,
const typename ExpSet::value_t& e)
296 return lrs.lweight(e, lrs.one());
305 template <
typename ExpSet>
309 const auto& e = exp->as<ExpSet>();
310 const auto& es = e.valueset();
static in_label_t weight_label(const in_label_t &l)
Weight in the output.
struct lifter_impl< context< tupleset< LabelSets... >, WeightSet >, vcsn::detail::index_sequence< Tapes... >, std::enable_if_t<(0< sizeof...(Tapes))> >{using in_labelset_t=tupleset< LabelSets... >;using in_context_t=context< in_labelset_t, WeightSet >;using in_label_t=typename in_labelset_t::value_t;template< std::size_t...I > using seq=detail::index_sequence< I... >;template< typename S, typename L > struct tape_set;template< typename LabelSet > struct tape_set< seq<>, LabelSet >{using type=oneset;};template< size_t...I, typename LabelSet > struct tape_set< seq< I... >, LabelSet >{using type=tupleset< typename LabelSet::template valueset_t< I >... >;};using index_t=typename detail::make_index_sequence< in_labelset_t::size()>::type;static constexpr size_t number_of_tapes=in_labelset_t::size();template< size_t I > using tape_labelset_t=typename in_labelset_t::template valueset_t< I >;using kept_index_t=sequence_difference< index_t, seq< Tapes... > >;using labelset_t=typename tape_set< kept_index_t, in_labelset_t >::type;using weight_index_t=seq< Tapes... >;using weight_tapes_t=typename tape_set< weight_index_t, in_labelset_t >::type;using inner_context_t=context< weight_tapes_t, WeightSet >;using weightset_t=expressionset< inner_context_t >;using context_t=context< labelset_t, weightset_t >;static context_t value(const in_context_t &ctx, vcsn::rat::identities ids){return value_(ctx, ids, weight_index_t{}, kept_index_t{});}template< size_t...WeightTapes, size_t...KeptTapes > static context_t value_(const in_context_t &ctx, vcsn::rat::identities ids, seq< WeightTapes... >, seq< KeptTapes... >){auto ls=labelset_t{ctx.labelset() -> template set< KeptTapes >()...}
Specialization: lift only some tapes.
static identities ids(const driver &d)
Get the identities of the driver.
Implementation of labels are ones: there is a single instance of label.
static weight_tapes_t::value_t weight_label_(const in_label_t &l, seq< I... >)
static weight_tapes_t::value_t weight_label(const in_label_t &l)
Weight in the output.
std::shared_ptr< const node< Context >> expression
static labelset_t::value_t kept_label(const in_label_t &l)
Label in the output.
std::shared_ptr< detail::mutable_automaton_impl< Context >> mutable_automaton
Provide a variadic mul on top of a binary mul(), and one().
lifted_expressionset_t< expressionset< Context > > lift_expressionset(const expressionset< Context > &rs, boost::optional< vcsn::rat::identities > ids={})
lift(expressionset) -> expressionset
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
Context in_context_t
Input context.
detail::lifted_expressionset_t< ExpSet >::value_t lift(const ExpSet &rs, const typename ExpSet::value_t &e)
Move all the labels to the weights.
Helper structure for a lift of several tapes.
typename index_sequence_difference< typename S1::type, typename S2::type >::type sequence_difference
std::string type(const automaton &a)
The implementation type of a.
static context_t value(const in_context_t &ctx, vcsn::rat::identities ids)
Lift a context.
expressionset< typename lifter_t< context_t_of< ExpSet >>::context_t > lifted_expressionset_t
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
lifter_t< context< LabelSet, WeightSet >, Tapes... >::context_t lift_context(const context< LabelSet, WeightSet > &ctx)
lift(ctx) -> ctx
static oneset::value_t kept_label(const in_label_t &)
Label in the output.
static labelset_t::value_t kept_label_(const in_label_t &l, seq< I... >)
expression lift_expression(const expression &exp)
Bridge (lift).
automaton lift_automaton(const automaton &aut, identities ids, integral_constant)
Bridge.
An expressionset can implement several different sets of identities on expressions.
auto map(const std::tuple< Ts... > &ts, Fun f) -> decltype(map_tuple_(f, ts, make_index_sequence< sizeof...(Ts)>()))
Map a function on a tuple, return tuple of the results.
A simple placeholder for integral constants.
mutable_automaton< typename lifter_t< context_t_of< Aut >, Tapes... >::context_t > lifted_automaton_t
value_impl< detail::expression_tag > expression
label_t_of< in_context_t > in_label_t
auto & as()
Extract wrapped typed automaton.
auto all_transitions(const Aut &aut)
All the transition indexes between all states (including pre and post).
detail::lifted_automaton_t< Aut, Tapes... > lift(const Aut &a, vcsn::rat::identities ids={})
Lift some tapes of the transducer.