Vcsn  2.4
Be Rational
prefix.hh
Go to the documentation of this file.
1 #pragma once
2 
4 #include <vcsn/dyn/automaton.hh> // dyn::make_automaton
5 #include <vcsn/dyn/fwd.hh>
7 
8 namespace vcsn
9 {
10  /*---------.
11  | suffix. |
12  `---------*/
13 
15  template <Automaton Aut>
16  Aut&
17  suffix_here(Aut& aut)
18  {
19  for (auto s : accessible_states(aut))
20  if (s != aut->pre()
21  && s != aut->post()
22  && !aut->is_initial(s))
23  aut->set_initial(s);
24  return aut;
25  }
26 
27  template <Automaton Aut>
28  auto
29  suffix(const Aut& aut)
30  ->decltype(::vcsn::copy(aut))
31  {
32  auto res = ::vcsn::copy(aut);
34  return res;
35  }
36 
37  namespace dyn
38  {
39  namespace detail
40  {
42  template <Automaton Aut>
43  automaton
44  suffix(const automaton& aut)
45  {
46  const auto& a = aut->as<Aut>();
48  }
49  }
50  }
51 
52 
53  /*---------.
54  | prefix. |
55  `---------*/
56 
58  template <Automaton Aut>
59  Aut&
60  prefix_here(Aut& aut)
61  {
62  auto t = transpose(aut);
63  suffix_here(t);
64  return aut;
65  }
66 
67  template <Automaton Aut>
68  auto
69  prefix(const Aut& aut)
70  ->decltype(::vcsn::copy(aut))
71  {
72  auto res = ::vcsn::copy(aut);
74  return res;
75  }
76 
77  namespace dyn
78  {
79  namespace detail
80  {
82  template <Automaton Aut>
83  automaton
84  prefix(const automaton& aut)
85  {
86  const auto& a = aut->as<Aut>();
88  }
89  }
90  }
91 
92  /*---------.
93  | factor. |
94  `---------*/
95 
97  template <Automaton Aut>
98  Aut&
99  factor_here(Aut& aut)
100  {
101  return suffix_here(prefix_here(aut));
102  }
103 
104  template <Automaton Aut>
105  auto
106  factor(const Aut& aut)
107  ->decltype(::vcsn::copy(aut))
108  {
109  auto res = ::vcsn::copy(aut);
110  factor_here(res);
111  return res;
112  }
113 
114  namespace dyn
115  {
116  namespace detail
117  {
119  template <Automaton Aut>
120  automaton
121  factor(const automaton& aut)
122  {
123  const auto& a = aut->as<Aut>();
125  }
126  }
127  }
128 
129  /*----------.
130  | subword. |
131  `----------*/
132 
135  template <Automaton Aut>
136  Aut&
137  subword_here(Aut& aut)
138  {
139  const auto one = aut->labelset()->one();
140 
141  auto ts = std::vector<transition_t_of<Aut>>{};
142  for (auto s : aut->states())
143  {
144  ts.clear();
145  for (auto t : out(aut, s))
146  if (!aut->labelset()->is_one(aut->label_of(t)))
147  ts.emplace_back(t);
148  for (auto t : ts)
149  aut->add_transition(s, aut->dst_of(t), one, aut->weight_of(t));
150  }
151 
152  return aut;
153  }
154 
156  template <Automaton Aut>
157  auto
158  subword(const Aut& aut)
159  -> decltype(make_nullable_automaton(aut->context()))
160  {
161  auto res = make_nullable_automaton(aut->context());
162  copy_into(aut, res);
163  subword_here(res);
164  return res;
165  }
166 
167  namespace dyn
168  {
169  namespace detail
170  {
172  template <Automaton Aut>
173  automaton
174  subword(const automaton& aut)
175  {
176  const auto& a = aut->as<Aut>();
178  }
179  }
180  }
181 } // namespace vcsn
auto make_nullable_automaton(const Context &ctx)
auto subword(const Aut &aut) -> decltype(make_nullable_automaton(aut->context()))
Apply subword_here() to a copy of aut.
Definition: prefix.hh:158
auto prefix(const Aut &aut) -> decltype(::vcsn::copy(aut))
Definition: prefix.hh:69
void copy_into(const AutIn &in, AutOut &out, KeepState keep_state, KeepTrans keep_trans)
Copy selected states and transitions of an automaton.
Definition: copy.hh:267
return res
Definition: multiply.hh:398
automaton suffix(const automaton &aut)
Bridge.
Definition: prefix.hh:44
Aut & factor_here(Aut &aut)
Make each useful state both initial and final.
Definition: prefix.hh:99
auto factor(const Aut &aut) -> decltype(::vcsn::copy(aut))
Definition: prefix.hh:106
automaton prefix(const automaton &aut)
Bridge.
Definition: prefix.hh:84
automaton factor(const automaton &aut)
Bridge.
Definition: prefix.hh:121
Definition: a-star.hh:8
auto suffix(const Aut &aut) -> decltype(::vcsn::copy(aut))
Definition: prefix.hh:29
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
Definition: automaton.hh:85
Aut & subword_here(Aut &aut)
Add spontaneous transitions for each non spontaneous transition, with same source, destination and weight.
Definition: prefix.hh:137
automaton subword(const automaton &aut)
Bridge.
Definition: prefix.hh:174
Aut & prefix_here(Aut &aut)
Make all coaccessible states final.
Definition: prefix.hh:60
A dyn automaton.
Definition: automaton.hh:17
states_t< Aut > accessible_states(const Aut &aut, bool strict=true)
The set of accessible states, including pre(), and possibly post().
Definition: accessible.hh:27
auto copy(const AutIn &input, KeepState keep_state, KeepTrans keep_trans) -> decltype(keep_state(input->null_state()), keep_trans(input->null_transition()), make_fresh_automaton< AutIn, AutOut >(input))
A copy of input keeping only its states that are accepted by keep_state, and transitions accepted by ...
Definition: copy.hh:322
auto & as()
Extract wrapped typed automaton.
Definition: automaton.hh:37
Aut & suffix_here(Aut &aut)
Make all accessible states initial.
Definition: prefix.hh:17
Aut transpose(const transpose_automaton< Aut > &aut)
The transpose of a transpose automaton is the original automaton.
Definition: transpose.hh:253