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