Vcsn  2.4
Be Rational
info.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 
10 #include <vcsn/algos/is-acyclic.hh>
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/value.hh>
21 #include <vcsn/misc/static-if.hh>
22 #include <vcsn/misc/type_traits.hh>
23 
24 namespace vcsn
25 {
26 
27  namespace detail
28  {
29  /*-------------------------------.
30  | num_spontaneous_transitions. |
31  `-------------------------------*/
32 
33  template <Automaton Aut>
34  ATTRIBUTE_CONST
35  std::enable_if_t<!labelset_t_of<Aut>::has_one(), size_t>
37  {
38  return 0;
39  }
40 
41  template <Automaton Aut>
42  std::enable_if_t<labelset_t_of<Aut>::has_one(), size_t>
44  {
45  size_t res = 0;
46  for (auto t : transitions(aut))
47  res += aut->labelset()->is_one(aut->label_of(t));
48  return res;
49  }
50 
51  /*-------------------.
52  | num_lazy_states. |
53  `-------------------*/
54 
55  template <Automaton Aut>
56  size_t
57  num_lazy_states(const Aut& a)
58  {
59  size_t res = 0;
60  for (auto s: a->all_states())
61  res += a->is_lazy(s);
62  return res;
63  }
64  }
65 
66  /*--------------------------.
67  | info(automaton, stream). |
68  `--------------------------*/
69 
71  template <Automaton Aut>
72  std::ostream&
73  info(const Aut& aut, std::ostream& out = std::cout, unsigned details = 2)
74  {
75  const char* sep = "";
76  if (2 <= details)
77  {
78  out << "type: ";
79  aut->print_set(out, format::sname);
80  sep = "\n";
81  }
82 #define ECHO(Level, Name, Value) \
83  do { \
84  if (Level <= details) \
85  out << sep << Name ": " << Value; \
86  sep = "\n"; \
87  } while (false)
88 
89 #define VCSN_IF_FREE(Fun, Aut) \
90  detail::static_if<labelset_t_of<decltype(Aut)>::is_free()> \
91  ([](auto a) { return Fun(a); }, \
92  [](auto) { return "N/A"; })(Aut)
93 
94  ECHO(1, "number of states", aut->num_states());
95  ECHO(2, "number of lazy states", detail::num_lazy_states(aut));
96  ECHO(1, "number of initial states", aut->num_initials());
97  ECHO(1, "number of final states", aut->num_finals());
98  ECHO(2, "number of accessible states", num_accessible_states(aut));
99  ECHO(2, "number of coaccessible states", num_coaccessible_states(aut));
100  ECHO(1, "number of useful states", num_useful_states(aut));
101  ECHO(2, "number of codeterministic states",
103  ECHO(2, "number of deterministic states",
105  ECHO(1, "number of transitions", aut->num_transitions());
106  ECHO(2, "number of spontaneous transitions",
108  ECHO(3, "number of strongly connected components",
109  num_components(scc(aut)));
110  ECHO(3, "is ambiguous", VCSN_IF_FREE(is_ambiguous, aut));
111  ECHO(2, "is complete", VCSN_IF_FREE(is_complete, aut));
112  ECHO(3, "is cycle ambiguous", VCSN_IF_FREE(is_cycle_ambiguous, aut));
113  ECHO(2, "is deterministic", VCSN_IF_FREE(is_deterministic, aut));
114  ECHO(2, "is codeterministic", VCSN_IF_FREE(is_codeterministic, aut));
115  ECHO(2, "is empty", is_empty(aut));
116  ECHO(2, "is eps-acyclic", is_eps_acyclic(aut));
117  ECHO(2, "is normalized", is_normalized(aut));
118  ECHO(2, "is proper", is_proper(aut));
119  ECHO(2, "is standard", is_standard(aut));
120  ECHO(3, "is synchronizing", VCSN_IF_FREE(is_synchronizing, aut));
121  ECHO(2, "is trim", is_trim(aut));
122  ECHO(2, "is useless", is_useless(aut));
123  ECHO(2, "is valid", is_valid(aut));
124 #undef VCSN_IF_FREE
125 #undef ECHO
126  return out;
127  }
128 
129 
130  namespace dyn
131  {
132  namespace detail
133  {
135  template <Automaton Aut, typename Ostream, typename Bool>
136  std::ostream& info(const automaton& aut, std::ostream& out,
137  unsigned details)
138  {
139  info(aut->as<Aut>(), out, details);
140  return out;
141  }
142  }
143  }
144 
145 
146  /*----------------------------.
147  | info(expression, stream). |
148  `----------------------------*/
149 
151  template <typename ExpSet>
152  void
153  info(const ExpSet& rs, const typename ExpSet::value_t& e,
154  std::ostream& o = std::cout)
155  {
156  o << "type: ";
157  rs.print_set(o, format::sname);
158 
159  // `length` and `size` are synonymous.
160  auto s = rat::size<ExpSet>(e);
161  o << "\nsize: " << s
162  << "\nlength: " << s;
163 
164  auto info = rat::make_info<ExpSet>(e);
165  o << "\nwidth: " << info.atom;
166 #define ECHO(Type) \
167  o << "\n" #Type ": " << info.Type
168  ECHO(add);
169  ECHO(atom);
170  ECHO(complement);
171  ECHO(compose);
172  ECHO(conjunction);
173  ECHO(depth);
174  ECHO(infiltrate);
175  ECHO(ldivide);
176  ECHO(lweight);
177  ECHO(one);
178  ECHO(mul);
179  ECHO(rweight);
180  ECHO(shuffle);
181  ECHO(star);
182  ECHO(transposition);
183  ECHO(tuple);
184  ECHO(zero);
185 #undef ECHO
186  }
187 
188 
189  namespace dyn
190  {
191  namespace detail
192  {
194  template <typename ExpSet, typename Ostream>
195  std::ostream& info_expression(const expression& exp, std::ostream& o)
196  {
197  const auto& e = exp->as<ExpSet>();
198  vcsn::info(e.valueset(), e.value(), o);
199  return o;
200  }
201  }
202  }
203 }
bool is_synchronizing(const Aut &aut)
Whether this automaton is synchronizing, i.e., has synchronizing words.
auto transitions(const Aut &aut) -> decltype(all_transitions(aut, is_special_t< Aut >
All the transition indexes between visible states.
Definition: automaton.hh:247
Print as a parsable type string.
Definition: format.hh:26
size_t num_deterministic_states(const Aut &aut)
Number of non-deterministic states.
auto rs
Definition: lift.hh:152
return res
Definition: multiply.hh:398
bool is_valid(const Aut &aut)
Definition: is-valid.hh:139
fresh_automaton_t_of< Aut > rweight(const Aut &aut, const weight_t_of< Aut > &w, Tag tag={})
Right-multiplication of an automaton by a weight.
Definition: weight.hh:329
auto lweight(const weight_t_of< Aut > &w, const Aut &aut, Tag tag={}) -> fresh_automaton_t_of< Aut >
Left-multiplication of an automaton by a weight.
Definition: weight.hh:126
bool is_deterministic(const Aut &aut, state_t_of< Aut > s)
Whether state s is deterministic in aut.
ATTRIBUTE_CONST std::enable_if_t<!labelset_t_of< Aut >::has_one(), size_t > num_spontaneous_transitions(const Aut &)
Definition: info.hh:36
bool is_normalized(const Aut &a)
Whether a is standard and co-standard.
Definition: normalize.hh:12
ValueSet::value_t compose(const ValueSet &vs, const typename ValueSet::value_t &lhs, const typename ValueSet::value_t &rhs)
Composition of values.
ValueSet::value_t tuple(const ValueSet &vs, const typename ValueSets::value_t &...v)
Definition: tuple.hh:73
auto infiltrate(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:861
bool is_codeterministic(const Aut &aut)
Whether the transposed automaton is deterministic.
auto complement(const Aut &aut) -> decltype(copy(aut))
Definition: complement.hh:48
ATTRIBUTE_CONST std::enable_if_t< context_t_of< Aut >::has_one(), bool > is_eps_acyclic(const Aut &aut)
Detect epsilon-circuits.
Definition: is-acyclic.hh:116
#define VCSN_IF_FREE(Fun, Aut)
auto add(const Aut1 &lhs, const Aut2 &rhs, deterministic_tag)
Definition: add.hh:71
bool is_proper(const Aut &aut)
Test whether an automaton is proper.
Definition: is-proper.hh:47
auto shuffle(const Auts &...as) -> tuple_automaton< decltype(join_automata(as...)), Auts... >
The (accessible part of the) shuffle product.
Definition: conjunction.hh:784
bool is_complete(const Aut &aut)
Whether aut is complete.
Definition: is-complete.hh:14
Definition: a-star.hh:8
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
Definition: automaton.hh:85
auto conjunction(const Aut &aut, to exp) -> fresh_automaton_t_of< Aut >
Repeated conjunction of a automaton.
Definition: conjunction.hh:951
std::ostream & info_expression(const expression &exp, std::ostream &o)
Bridge (info).
Definition: info.hh:195
bool is_ambiguous(const Aut &aut)
Whether an automaton is ambiguous.
Definition: is-ambiguous.hh:85
size_t num_useful_states(const Aut &a)
Number of accessible states, not counting pre() and post().
Definition: accessible.hh:113
scc_automaton< Aut > scc(const Aut &aut, const std::string &algo="auto")
Get scc_automaton from aut.
Definition: scc.hh:693
bool is_cycle_ambiguous(const Aut &aut)
Whether aut is cycle-ambiguous.
bool is_useless(const Aut &a)
Whether all no state is useful.
Definition: accessible.hh:168
size_t num_codeterministic_states(const Aut &aut)
Number of non-deterministic states of transposed automaton.
A dyn automaton.
Definition: automaton.hh:17
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:718
size_t num_accessible_states(const Aut &a)
Number of accessible states, not counting pre() and post().
Definition: accessible.hh:90
bool is_standard(const Aut &a)
Whether a is standard.
Definition: standard.hh:28
bool is_empty(const Aut &a) ATTRIBUTE_PURE
Whether has no states.
Definition: accessible.hh:192
#define ECHO(Level, Name, Value)
auto star(const Aut &aut, Tag tag={}) -> decltype(detail::make_join_automaton(tag, aut))
Star of an automaton.
Definition: star.hh:108
std::ostream & info(const Aut &aut, std::ostream &out=std::cout, unsigned details=2)
Print info about an automaton.
Definition: info.hh:73
value_impl< detail::expression_tag > expression
Definition: fwd.hh:25
std::ostream & info(const automaton &aut, std::ostream &out, unsigned details)
Bridge.
Definition: info.hh:136
size_t num_lazy_states(const Aut &a)
Definition: info.hh:57
auto & as()
Extract wrapped typed automaton.
Definition: automaton.hh:37
auto ldivide(const Aut1 &lhs, const Aut2 &rhs, auto_tag={})
Compute the left quotient.
Definition: conjunction.hh:684
bool is_trim(const Aut &a)
Whether all its states are useful.
Definition: accessible.hh:161