5 #include <boost/optional.hpp>
29 template <
typename Context,
typename Tapes,
typename Enable =
void>
33 template <
typename Context>
67 template <
typename... LabelSets,
typename WeightSet,
71 std::enable_if_t<(0 < sizeof...(Tapes))>>
74 using in_labelset_t =
tupleset<LabelSets...>;
76 using in_label_t =
typename in_labelset_t::value_t;
79 template <std::size_t... I>
83 template <
typename S,
typename L>
87 template <
typename LabelSet>
88 struct tape_set<seq<>, LabelSet>
93 template <
size_t... I,
typename LabelSet>
94 struct tape_set<seq<I...>, LabelSet>
96 using type = tupleset<typename LabelSet::template valueset_t<I>...>;
106 using tape_labelset_t =
typename in_labelset_t::template valueset_t<I>;
117 using weight_index_t = seq<Tapes...>;
123 using inner_context_t = context<weight_tapes_t, WeightSet>;
126 using weightset_t = expressionset<inner_context_t>;
129 using context_t = context<labelset_t, weightset_t>;
132 static context_t value(
const in_context_t&
ctx,
135 return value_(ctx, ids, weight_index_t{}, kept_index_t{});
138 template <
size_t... WeightTapes,
size_t... KeptTapes>
139 static context_t value_(
const in_context_t& ctx,
149 = weight_tapes_t{ctx.labelset()->template set<WeightTapes>()...};
157 static typename labelset_t::value_t
163 template <
size_t... I>
164 static typename labelset_t::value_t
167 return typename labelset_t::value_t{std::get<I>(l)...};
171 static typename weight_tapes_t::value_t
177 template <
size_t... I>
178 static typename weight_tapes_t::value_t
181 return typename weight_tapes_t::value_t{std::get<I>(l)...};
186 template <
typename Ctx,
size_t... Tapes>
189 template <
Automaton Aut,
size_t... Tapes>
192 Tapes...>::context_t>;
195 template <
typename LabelSet,
typename WeightSet,
size_t... Tapes>
212 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.lmul(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.lmul(a->weight_of(t), rs_in.one()));
246 (map[a->src_of(t)], map[a->dst_of(t)],
248 rs_in.lmul(a->weight_of(t),
258 template <
Automaton Aut,
typename Ids,
typename... Tapes>
263 const auto& a = aut->as<Aut>();
264 return make_automaton(::vcsn::lift<Aut, Tapes::value...>(a, ids));
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>
293 typename detail::lifted_expressionset_t<ExpSet>::value_t
294 lift(
const ExpSet& rs,
const typename ExpSet::value_t& e)
297 return lrs.lmul(e, lrs.one());
306 template <
typename ExpSet>
310 const auto& e = exp->as<ExpSet>();
311 const auto& es = e.expressionset();
static context_t value(const in_context_t &ctx, vcsn::rat::identities ids)
Lift a context.
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.
static in_label_t weight_label(const in_label_t &l)
Weight in the output.
expressionset< typename lifter_t< context_t_of< ExpSet >>::context_t > lifted_expressionset_t
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
std::shared_ptr< detail::mutable_automaton_impl< Context >> mutable_automaton
static oneset::value_t kept_label(const in_label_t &)
Label in the output.
An expressionset can implement several different sets of identities on expressions.
static weight_tapes_t::value_t weight_label_(const in_label_t &l, seq< I... >)
A simple placeholder for integral constants.
label_t_of< in_context_t > in_label_t
std::string type(const automaton &a)
The implementation type of a.
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
static labelset_t::value_t kept_label(const in_label_t &l)
Label in the output.
Helper structure for a lift of several tapes.
std::shared_ptr< detail::automaton_base > automaton
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.
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
Context in_context_t
Input context.
std::shared_ptr< const node< Context >> expression
static dyn::context ctx(const driver &d)
Get the context of the driver.
Implementation of labels are ones: there is a single instance of label.
expression lift_expression(const expression &exp)
Bridge (lift).
std::shared_ptr< detail::expression_base > expression
static labelset_t::value_t kept_label_(const in_label_t &l, seq< I... >)
automaton lift_automaton(const automaton &aut, vcsn::rat::identities ids, integral_constant)
Bridge.
static identities ids(const driver &d)
Get the identities of the driver.
auto all_transitions(const Aut &aut)
All the transition indexes between all states (including pre and post).
static weight_tapes_t::value_t weight_label(const in_label_t &l)
Weight in the output.
typename index_sequence_difference< typename S1::type, typename S2::type >::type sequence_difference
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
mutable_automaton< typename lifter_t< context_t_of< Aut >, Tapes... >::context_t > lifted_automaton_t
detail::lifted_automaton_t< Aut, Tapes... > lift(const Aut &a, vcsn::rat::identities ids={})
Lift some tapes of the transducer.
expression make_expression(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