Vcsn  2.2
Be Rational
others.cc
Go to the documentation of this file.
3 #include <vcsn/dyn/algos.hh>
4 #include <vcsn/dyn/label.hh>
5 #include <vcsn/dyn/automaton.hh>
6 #include <vcsn/dyn/context.hh>
7 #include <vcsn/dyn/polynomial.hh>
8 #include <vcsn/dyn/registries.hh>
10 #include <vcsn/dyn/translate.hh>
11 #include <vcsn/misc/builtins.hh>
12 #include <vcsn/misc/getargs.hh>
13 
14 namespace vcsn
15 {
16  namespace dyn
17  {
18 
19  /*---------------.
20  | conjunction. |
21  `---------------*/
22 
23  // Implement the binary case on top of the variadic one, to avoid
24  // compiling it twice.
25  automaton
26  conjunction(const automaton& lhs, const automaton& rhs, bool lazy)
27  {
28  auto auts = std::vector<automaton>{lhs, rhs};
29  return conjunction(auts, lazy);
30  }
31 
32 
33  /*---------.
34  | focus. |
35  `---------*/
36 
37  static
39  {
40  return integral_constant{symbol("std::integral_constant<unsigned, "
41  + std::to_string(tape) + '>')};
42  }
43 
44  REGISTRY_DEFINE(focus);
45  automaton
46  focus(const automaton& aut, unsigned tape)
47  {
48  auto t = to_integral_constant(tape);
49  return detail::focus_registry().call(aut, t);
50  }
51 
52 
53  /*----------------.
54  | infiltration. |
55  `----------------*/
56 
57  automaton
58  infiltration(const automaton& lhs, const automaton& rhs)
59  {
60  auto auts = std::vector<automaton>{lhs, rhs};
61  return infiltration(auts);
62  }
63 
64 
65  /*-------------------------.
66  | lift(automaton, tapes). |
67  `-------------------------*/
68 
69  REGISTRY_DEFINE(lift_automaton);
70  automaton
71  lift(const automaton& aut,
72  const std::vector<unsigned>& tapes, vcsn::rat::identities ids)
73  {
74  std::string signame;
75  for (auto t : tapes)
76  {
77  if (!signame.empty())
78  signame += ", ";
79  signame += ("std::integral_constant<unsigned, "
80  + std::to_string(t) + '>');
81  }
82  auto t = integral_constant{symbol("const std::tuple<" + signame + ">&")};
83  signature sig;
84  sig.sig.emplace_back(vname(aut));
85  sig.sig.emplace_back("vcsn::rat::identities");
86  for (const auto& t: tapes)
87  sig.sig.emplace_back("std::integral_constant<unsigned, "
88  + std::to_string(t) + '>');
89  return detail::lift_automaton_registry().call(sig, aut, ids, t);
90  }
91 
92 
93  /*---------------.
94  | make_context. |
95  `---------------*/
96 
97  REGISTRY_DEFINE(make_context);
98  context
99  make_context(const std::string& n)
100  {
102  std::string full_name = ast::normalize_context(n, true);
103  if (!detail::make_context_registry().get0({sname}))
104  compile(sname);
105  return detail::make_context_registry().call({sname}, full_name);
106  }
107 
108 
109  /*---------.
110  | project. |
111  `---------*/
112 
113  REGISTRY_DEFINE(project);
114  automaton
115  project(const automaton& aut, unsigned tape)
116  {
117  auto t = to_integral_constant(tape);
118  return detail::project_registry().call(aut, t);
119  }
120 
121  REGISTRY_DEFINE(project_context);
122  context
123  project(const context& ctx, unsigned tape)
124  {
125  auto t = to_integral_constant(tape);
126  return detail::project_context_registry().call(ctx, t);
127  }
128 
129  REGISTRY_DEFINE(project_polynomial);
130  polynomial
131  project(const polynomial& p, unsigned tape)
132  {
133  auto t = to_integral_constant(tape);
134  return detail::project_polynomial_registry().call(p, t);
135  }
136 
137  REGISTRY_DEFINE(project_label);
138  label
139  project(const label& l, unsigned tape)
140  {
141  auto t = to_integral_constant(tape);
142  return detail::project_label_registry().call(l, t);
143  }
144 
145  /*-----------.
146  | shuffle. |
147  `-----------*/
148 
149  automaton
150  shuffle(const automaton& lhs, const automaton& rhs)
151  {
152  auto auts = std::vector<automaton>{lhs, rhs};
153  return shuffle(auts);
154  }
155 
156 
157  /*----------------.
158  | to_automaton. |
159  `----------------*/
160 
161  automaton
162  to_automaton(const expression& exp, const std::string& algo)
163  {
164  static const auto map
166  {
167  "to_automaton algorithm",
168  {
169  {"auto", "expansion"},
170  {"derivation", [](const expression& r) {
171  return strip(trim(strip(derived_term(r, "derivation"))));
172  }},
173  {"derived_term", "expansion"},
174  {"expansion", [](const expression& r) {
175  return strip(trim(strip(derived_term(r))));
176  }},
177  {"standard", [](const expression& r) {
178  return standard(r);
179  }},
180  {"thompson", [](const expression& r) {
181  return thompson(r);
182  }},
183  {"zpc", [](const expression& r) {
184  return strip(trim(zpc(r)));
185  }},
186  {"zpc_compact", [](const expression& r) {
187  return strip(trim(zpc(r, "compact")));
188  }},
189  }
190  };
191  return map[algo](exp);
192  }
193 
194 
195  /*---------.
196  | tuple. |
197  `---------*/
198 
199  expression
200  tuple(const expression& lhs, const expression& rhs)
201  {
202  auto auts = std::vector<expression>{lhs, rhs};
203  return tuple(auts);
204  }
205 
206  std::string type(const automaton& a)
207  {
208  return a->vname();
209  }
210  }
211 }
std::shared_ptr< const detail::polynomial_base > polynomial
Definition: fwd.hh:70
expansion tuple(const std::vector< expansion > &rs)
Build a k-tape expansion from k expansions.
automaton focus(const automaton &aut, unsigned tape)
Focus on a specific tape of a tupleset automaton.
Definition: others.cc:46
context< project_labelset< Tape, labelset_t_of< Context >>, weightset_t_of< Context >> project_context
The type of the resulting apparent context when keeping only tape Tape.
Definition: tupleset.hh:1265
An expressionset can implement several different sets of identities on expressions.
Definition: identities.hh:21
label project_label(const label &lbl, integral_constant)
Bridge (project).
Definition: project.hh:106
A simple placeholder for integral constants.
Definition: name.hh:198
Definition: a-star.hh:8
polynomial project_polynomial(const polynomial &poly, integral_constant)
Bridge (project).
Definition: project.hh:82
std::string normalize_context(const std::string &ctx, bool full=true)
A context, normalized.
std::string type(const automaton &a)
The implementation type of a.
Definition: others.cc:206
weightset_mixin< detail::r_impl > r
Definition: fwd.hh:54
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
static integral_constant to_integral_constant(unsigned tape)
Definition: others.cc:38
std::shared_ptr< const detail::label_base > label
Definition: fwd.hh:61
A mapping from strings to Values.
Definition: getargs.hh:33
automaton zpc(const expression &exp, const std::string &algo="auto")
The ZPC automaton of exp.
Definition: zpc.hh:366
automaton trim(const automaton &aut)
The trim subautomaton of aut.
Definition: accessible.hh:224
automaton strip(const automaton &a)
The automaton in a with its metadata layers removed.
Definition: strip.hh:46
symbol vname(T &t)
Definition: name.hh:101
automaton shuffle(const automaton &lhs, const automaton &rhs)
The shuffle product of automata lhs and rhs.
Definition: others.cc:150
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
std::shared_ptr< const detail::context_base > context
A dyn::context.
Definition: fwd.hh:43
automaton project(const automaton &aut, unsigned tape)
Keep a single tape from a multiple-tape automaton.
Definition: others.cc:115
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:69
automaton conjunction(const automaton &lhs, const automaton &rhs, bool lazy=false)
The conjunction (aka synchronized product) of automata.
Definition: others.cc:26
automaton thompson(const expression &e)
The Thompson automaton of e.
Definition: thompson.hh:208
symbol sname()
Definition: name.hh:67
automaton lift(const automaton &aut, const std::vector< unsigned > &tapes={}, rat::identities ids={})
Lift some tapes of the transducer, or turn an automaton into a spontaneous automaton.
Definition: others.cc:71
context make_context(const std::string &name)
Build a context from its name.
Definition: others.cc:99
static dyn::context ctx(const driver &d)
Get the context of the driver.
Definition: parse.cc:82
std::string to_string(identities i)
Wrapper around operator<<.
Definition: identities.cc:17
automaton infiltration(const automaton &lhs, const automaton &rhs)
The infiltration of automata lhs and rhs.
Definition: others.cc:58
automaton standard(const automaton &a)
A standardized a.
Definition: standard.hh:138
automaton derived_term(const expression &exp, const std::string &algo="auto")
The derived-term automaton of exp.
std::shared_ptr< detail::expression_base > expression
Definition: expression.hh:92
automaton lift_automaton(const automaton &aut, vcsn::rat::identities ids, integral_constant)
Bridge.
Definition: lift.hh:260
static identities ids(const driver &d)
Get the identities of the driver.
Definition: parse.cc:89
automaton to_automaton(const expression &exp, const std::string &algo="auto")
An automaton denoting the language of exp.
Definition: others.cc:162
void compile(const std::string &ctx)
Compile, and load, a DSO with instantiations for ctx.
Definition: translate.cc:388
Signature of a function call.
Definition: signature.hh:15