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