Vcsn  2.1
Be Rational
info.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 
11 #include <vcsn/algos/normalize.hh>
12 #include <vcsn/algos/is-valid.hh>
14 #include <vcsn/algos/scc.hh>
15 #include <vcsn/algos/standard.hh>
17 #include <vcsn/core/rat/info.hh>
18 #include <vcsn/core/rat/size.hh>
19 #include <vcsn/dyn/fwd.hh>
20 #include <vcsn/dyn/expression.hh>
21 #include <vcsn/misc/type_traits.hh>
22 
23 namespace vcsn
24 {
25 
26  namespace detail_info
27  {
28  /*---------------.
29  | is-ambiguous. |
30  `---------------*/
31  template <typename Aut>
33  is_ambiguous(const Aut& a)
34  {
35  return vcsn::is_ambiguous(a);
36  }
37 
38  template <typename Aut>
40  is_ambiguous(const Aut&)
41  {
42  return "N/A";
43  }
44 
45  /*--------------.
46  | is-complete. |
47  `--------------*/
48  template <typename Aut>
50  is_complete(const Aut& a)
51  {
52  return vcsn::is_complete(a);
53  }
54 
55  template <typename Aut>
57  is_complete(const Aut&)
58  {
59  return "N/A";
60  }
61 
62  /*---------------------.
63  | is_cycle_ambiguous. |
64  `---------------------*/
65  template <typename Aut>
67  is_cycle_ambiguous(const Aut& a)
68  {
69  return vcsn::is_cycle_ambiguous(a);
70  }
71 
72  template <typename Aut>
74  is_cycle_ambiguous(const Aut&)
75  {
76  return "N/A";
77  }
78 
79  /*---------------------.
80  | is_codeterministic. |
81  `---------------------*/
82  template <typename Aut>
84  is_codeterministic(const Aut& a)
85  {
86  return vcsn::is_codeterministic(a);
87  }
88 
89  template <typename Aut>
91  is_codeterministic(const Aut&)
92  {
93  return "N/A";
94  }
95 
96  /*-------------------.
97  | is_deterministic. |
98  `-------------------*/
99  template <typename Aut>
101  is_deterministic(const Aut& a)
102  {
103  return vcsn::is_deterministic(a);
104  }
105 
106  template <typename Aut>
108  is_deterministic(const Aut&)
109  {
110  return "N/A";
111  }
112 
113  /*-------------------.
114  | is_synchronizing. |
115  `-------------------*/
116  template <typename Aut>
118  is_synchronizing(const Aut& a)
119  {
120  return vcsn::is_synchronizing(a);
121  }
122 
123  template <typename Aut>
125  is_synchronizing(const Aut&)
126  {
127  return "N/A";
128  }
129 
130  /*------------------------------.
131  | num_codeterministic_states. |
132  `------------------------------*/
133  template <typename Aut>
136  {
138  }
139 
140  template <typename Aut>
143  {
144  return "N/A";
145  }
146 
147  /*---------------------------.
148  | num_deterministic_states. |
149  `---------------------------*/
150  template <typename Aut>
153  {
155  }
156 
157  template <typename Aut>
160  {
161  return "N/A";
162  }
163 
164  /*-------------------------------.
165  | num_spontaneous_transitions. |
166  `-------------------------------*/
167 
168  template <typename Aut>
169  ATTRIBUTE_CONST
172  {
173  return 0;
174  }
175 
176  template <typename Aut>
179  {
180  size_t res = 0;
181  for (auto t : aut->transitions())
182  res += aut->labelset()->is_one(aut->label_of(t));
183  return res;
184  }
185 
186  /*-------------------.
187  | num_lazy_states. |
188  `-------------------*/
189 
190  template <typename Aut>
191  size_t
192  num_lazy_states(const Aut& a)
193  {
194  size_t res = 0;
195  for (auto s: a->all_states())
196  res += !a->state_is_strict(s);
197  return res;
198  }
199  }
200 
201  /*--------------------------.
202  | info(automaton, stream). |
203  `--------------------------*/
204 
205  template <typename Aut>
206  std::ostream&
207  info(const Aut& aut, std::ostream& out, bool detailed = false)
208  {
209  out << "type: ";
210  aut->print_set(out, format::text) << '\n';
211 #define ECHO(Name, Value) \
212  out << Name ": " << Value << '\n'
213  ECHO("number of states", aut->num_states());
214  ECHO("number of lazy states", detail_info::num_lazy_states(aut));
215  ECHO("number of initial states", aut->num_initials());
216  ECHO("number of final states", aut->num_finals());
217  ECHO("number of accessible states", num_accessible_states(aut));
218  ECHO("number of coaccessible states", num_coaccessible_states(aut));
219  ECHO("number of useful states", num_useful_states(aut));
220  ECHO("number of codeterministic states",
222  ECHO("number of deterministic states",
224  ECHO("number of transitions", aut->num_transitions());
225  ECHO("number of spontaneous transitions",
227  if (detailed)
228  ECHO("number of strongly connected components",
229  num_components(scc(aut)));
230  if (detailed)
231  ECHO("is ambiguous", detail_info::is_ambiguous(aut));
232  ECHO("is complete", detail_info::is_complete(aut));
233  if (detailed)
234  ECHO("is cycle ambiguous", detail_info::is_cycle_ambiguous(aut));
235  ECHO("is deterministic", detail_info::is_deterministic(aut));
236  ECHO("is codeterministic", detail_info::is_codeterministic(aut));
237  ECHO("is empty", is_empty(aut));
238  ECHO("is eps-acyclic", is_eps_acyclic(aut));
239  ECHO("is normalized", is_normalized(aut));
240  ECHO("is proper", is_proper(aut));
241  ECHO("is standard", is_standard(aut));
242  if (detailed)
243  ECHO("is synchronizing", detail_info::is_synchronizing(aut));
244  ECHO("is trim", is_trim(aut));
245  ECHO("is useless", is_useless(aut));
246 #undef ECHO
247  // No eol for the last one.
248  out << "is valid: " << is_valid(aut);
249  return out;
250  }
251 
252  namespace dyn
253  {
254  namespace detail
255  {
257  template <typename Aut, typename Ostream, typename Bool>
258  std::ostream& info(const automaton& aut, std::ostream& out,
259  bool detailed)
260  {
261  info(aut->as<Aut>(), out, detailed);
262  return out;
263  }
264  }
265  }
266 
267 
268  /*----------------------------.
269  | info(expression, stream). |
270  `----------------------------*/
271 
272  template <typename ExpSet>
273  void
274  info(const ExpSet& rs, const typename ExpSet::value_t& e,
275  std::ostream& o)
276  {
277  o << "type: ";
278  rs.print_set(o, format::text);
279 
280  o << "\nsize: " << rat::size<ExpSet>(e);
281 
282  auto info = rat::make_info<ExpSet>(e);
283  o << "\nwidth: " << info.atom;
284 #define ECHO(Type) \
285  o << "\n" #Type ": " << info.Type
286  ECHO(atom);
287  ECHO(complement);
288  ECHO(conjunction);
289  ECHO(depth);
291  ECHO(ldiv);
292  ECHO(lweight);
293  ECHO(one);
294  ECHO(prod);
295  ECHO(rweight);
296  ECHO(shuffle);
297  ECHO(star);
298  ECHO(sum);
299  ECHO(tuple);
300  ECHO(zero);
301 #undef ECHO
302  }
303 
304 
305  namespace dyn
306  {
307  namespace detail
308  {
310  template <typename ExpSet, typename Ostream>
311  std::ostream& info_expression(const expression& exp, std::ostream& o)
312  {
313  const auto& e = exp->as<ExpSet>();
314  vcsn::info(e.expressionset(), e.expression(), o);
315  return o;
316  }
317  }
318  }
319 }
ATTRIBUTE_CONST bool is_eps_acyclic(const Aut &aut)
size_t num_useful_states(const Aut &a)
Number of accessible states, not counting pre() and post().
Definition: accessible.hh:113
vcsn::enable_if_t< labelset_t_of< Aut >::is_free(), bool > is_complete(const Aut &a)
Definition: info.hh:50
ATTRIBUTE_CONST vcsn::enable_if_t<!labelset_t_of< Aut >::has_one(), size_t > num_spontaneous_transitions(const Aut &)
Definition: info.hh:171
vcsn::enable_if_t< labelset_t_of< Aut >::is_free(), size_t > num_codeterministic_states(const Aut &a)
Definition: info.hh:135
vcsn::enable_if_t< labelset_t_of< Aut >::is_free(), bool > is_cycle_ambiguous(const Aut &a)
Definition: info.hh:67
ValueSet::value_t ldiv(const ValueSet &vs, const typename ValueSet::value_t &lhs, const typename ValueSet::value_t &rhs)
Left-division of values.
Definition: divide.hh:17
#define ECHO(Name, Value)
size_t num_deterministic_states(const Aut &aut)
Number of non-deterministic states.
typename std::enable_if< Cond, T >::type enable_if_t
Definition: type_traits.hh:16
bool is_synchronizing(const Aut &aut)
Whether this automaton is synchronizing, i.e., has synchronizing words.
bool is_useless(const Aut &a)
Whether all no state is useful.
Definition: accessible.hh:168
auto infiltration(const A1 &a1, const A2 &a2) -> tuple_automaton< decltype(join_automata(a1, a2)), A1, A2 >
The (accessible part of the) infiltration product.
Definition: conjunction.hh:713
ValueSet::value_t tuple(const ValueSet &vs, const typename ValueSets::value_t &...v)
Definition: tuple.hh:28
vcsn::enable_if_t< labelset_t_of< Aut >::is_free(), bool > is_deterministic(const Aut &a)
Definition: info.hh:101
bool is_ambiguous(const Aut &aut)
Definition: is-ambiguous.hh:40
auto shuffle(const Auts &...as) -> tuple_automaton< decltype(join_automata(as...)), Auts...>
The (accessible part of the) shuffle product.
Definition: conjunction.hh:634
scc_automaton< Aut > scc(const Aut &aut, const std::string &algo="auto")
Get scc_automaton from aut.
Definition: scc.hh:633
vcsn::enable_if_t< labelset_t_of< Aut >::is_free(), size_t > num_deterministic_states(const Aut &a)
Definition: info.hh:152
bool is_standard(const Aut &a)
Whether a is standard.
Definition: standard.hh:27
bool is_complete(const Aut &aut)
Whether aut is complete.
Definition: is-complete.hh:13
fresh_automaton_t_of< Aut > star(const Aut &aut)
Star of a standard automaton.
Definition: star.hh:60
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:69
auto conjunction(const Auts &...as) -> tuple_automaton< decltype(meet_automata(as...)), Auts...>
Build the (accessible part of the) conjunction.
Definition: conjunction.hh:553
size_t num_coaccessible_states(const Aut &a)
Number of accessible states, not counting pre() and post().
Definition: accessible.hh:105
std::size_t num_components(const scc_automaton< Aut > &aut)
Get number of strongly connected components.
Definition: scc.hh:660
std::ostream & info_expression(const expression &exp, std::ostream &o)
Bridge (info).
Definition: info.hh:311
bool is_empty(const Aut &a) ATTRIBUTE_PURE
Whether has no states.
Definition: accessible.hh:192
bool is_trim(const Aut &a)
Whether all its states are useful.
Definition: accessible.hh:161
auto rs
Definition: lift.hh:151
size_t num_lazy_states(const Aut &a)
Definition: info.hh:192
vcsn::enable_if_t< labelset_t_of< Aut >::is_free(), bool > is_codeterministic(const Aut &a)
Definition: info.hh:84
bool is_codeterministic(const Aut &aut)
Whether the transpositive automaton is deterministic.
bool is_valid(const Aut &aut)
Definition: is-valid.hh:141
bool is_normalized(const Aut &a)
Whether a is standard and co-standard.
Definition: normalize.hh:12
auto sum(const A &lhs, const B &rhs) -> decltype(join_automata(lhs, rhs))
Definition: sum.hh:64
bool is_cycle_ambiguous(const Aut &aut)
Whether aut is cycle-ambiguous.
bool is_proper(const Aut &aut)
Test whether an automaton is proper.
Definition: is-proper.hh:48
bool is_deterministic(const Aut &aut, state_t_of< Aut > s)
Whether state s is deterministic in aut.
vcsn::enable_if_t< labelset_t_of< Aut >::is_free(), bool > is_ambiguous(const Aut &a)
Definition: info.hh:33
auto complement(const Aut &aut) -> decltype(copy(aut))
Definition: complement.hh:47
std::shared_ptr< detail::expression_base > expression
Definition: expression.hh:78
std::ostream & info(const automaton &aut, std::ostream &out, bool detailed)
Bridge.
Definition: info.hh:258
vcsn::enable_if_t< labelset_t_of< Aut >::is_free(), bool > is_synchronizing(const Aut &a)
Definition: info.hh:118
std::ostream & info(const Aut &aut, std::ostream &out, bool detailed=false)
Definition: info.hh:207
size_t num_codeterministic_states(const Aut &aut)
Number of non-deterministic states of transpositive automaton.
size_t num_accessible_states(const Aut &a)
Number of accessible states, not counting pre() and post().
Definition: accessible.hh:90