Vcsn  2.3
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, bool detailed = false)
74  {
75  out << "type: ";
76  aut->print_set(out, format::sname) << '\n';
77 #define ECHO(Name, Value) \
78  out << Name ": " << Value << '\n'
79 #define VCSN_IF_FREE(Fun, Aut) \
80  detail::static_if<labelset_t_of<decltype(Aut)>::is_free()> \
81  ([](auto a) { return Fun(a); }, \
82  [](auto) { return "N/A"; })(Aut)
83 
84  ECHO("number of states", aut->num_states());
85  ECHO("number of lazy states", detail::num_lazy_states(aut));
86  ECHO("number of initial states", aut->num_initials());
87  ECHO("number of final states", aut->num_finals());
88  ECHO("number of accessible states", num_accessible_states(aut));
89  ECHO("number of coaccessible states", num_coaccessible_states(aut));
90  ECHO("number of useful states", num_useful_states(aut));
91  ECHO("number of codeterministic states",
93  ECHO("number of deterministic states",
95  ECHO("number of transitions", aut->num_transitions());
96  ECHO("number of spontaneous transitions",
98  if (detailed)
99  ECHO("number of strongly connected components",
100  num_components(scc(aut)));
101  if (detailed)
102  ECHO("is ambiguous", VCSN_IF_FREE(is_ambiguous, aut));
103  ECHO("is complete", VCSN_IF_FREE(is_complete, aut));
104  if (detailed)
105  ECHO("is cycle ambiguous", VCSN_IF_FREE(is_cycle_ambiguous, aut));
106  ECHO("is deterministic", VCSN_IF_FREE(is_deterministic, aut));
107  ECHO("is codeterministic", VCSN_IF_FREE(is_codeterministic, aut));
108  ECHO("is empty", is_empty(aut));
109  ECHO("is eps-acyclic", is_eps_acyclic(aut));
110  ECHO("is normalized", is_normalized(aut));
111  ECHO("is proper", is_proper(aut));
112  ECHO("is standard", is_standard(aut));
113  if (detailed)
114  ECHO("is synchronizing", VCSN_IF_FREE(is_synchronizing, aut));
115  ECHO("is trim", is_trim(aut));
116  ECHO("is useless", is_useless(aut));
117 #undef VCSN_IF_FREE
118 #undef ECHO
119  // No eol for the last one.
120  out << "is valid: " << is_valid(aut);
121  return out;
122  }
123 
124 
125  namespace dyn
126  {
127  namespace detail
128  {
130  template <Automaton Aut, typename Ostream, typename Bool>
131  std::ostream& info(const automaton& aut, std::ostream& out,
132  bool detailed)
133  {
134  info(aut->as<Aut>(), out, detailed);
135  return out;
136  }
137  }
138  }
139 
140 
141  /*----------------------------.
142  | info(expression, stream). |
143  `----------------------------*/
144 
146  template <typename ExpSet>
147  void
148  info(const ExpSet& rs, const typename ExpSet::value_t& e,
149  std::ostream& o = std::cout)
150  {
151  o << "type: ";
152  rs.print_set(o, format::sname);
153 
154  // `length` and `size` are synonymous.
155  auto s = rat::size<ExpSet>(e);
156  o << "\nsize: " << s
157  << "\nlength: " << s;
158 
159  auto info = rat::make_info<ExpSet>(e);
160  o << "\nwidth: " << info.atom;
161 #define ECHO(Type) \
162  o << "\n" #Type ": " << info.Type
163  ECHO(add);
164  ECHO(atom);
165  ECHO(complement);
166  ECHO(compose);
167  ECHO(conjunction);
168  ECHO(depth);
169  ECHO(infiltrate);
170  ECHO(ldivide);
171  ECHO(lweight);
172  ECHO(one);
173  ECHO(mul);
174  ECHO(rweight);
175  ECHO(shuffle);
176  ECHO(star);
177  ECHO(transposition);
178  ECHO(tuple);
179  ECHO(zero);
180 #undef ECHO
181  }
182 
183 
184  namespace dyn
185  {
186  namespace detail
187  {
189  template <typename ExpSet, typename Ostream>
190  std::ostream& info_expression(const expression& exp, std::ostream& o)
191  {
192  const auto& e = exp->as<ExpSet>();
193  vcsn::info(e.valueset(), e.value(), o);
194  return o;
195  }
196  }
197  }
198 }
size_t num_codeterministic_states(const Aut &aut)
Number of non-deterministic states of transposed automaton.
bool is_complete(const Aut &aut)
Whether aut is complete.
Definition: is-complete.hh:13
auto ldivide(const Aut1 &lhs, const Aut2 &rhs, auto_tag={})
Compute the left quotient.
Definition: conjunction.hh:684
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_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:226
bool is_empty(const Aut &a) ATTRIBUTE_PURE
Whether has no states.
Definition: accessible.hh:192
bool is_useless(const Aut &a)
Whether all no state is useful.
Definition: accessible.hh:168
size_t num_lazy_states(const Aut &a)
Definition: info.hh:57
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
Definition: automaton.hh:64
Print as a parsable type string.
Definition: format.hh:26
bool is_ambiguous(const Aut &aut)
Definition: is-ambiguous.hh:41
scc_automaton< Aut > scc(const Aut &aut, const std::string &algo="auto")
Get scc_automaton from aut.
Definition: scc.hh:693
return res
Definition: multiply.hh:398
ValueSet::value_t tuple(const ValueSet &vs, const typename ValueSets::value_t &...v)
Definition: tuple.hh:43
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
bool is_standard(const Aut &a)
Whether a is standard.
Definition: standard.hh:28
bool is_deterministic(const Aut &aut, state_t_of< Aut > s)
Whether state s is deterministic in aut.
auto shuffle(const Auts &...as) -> tuple_automaton< decltype(join_automata(as...)), Auts... >
The (accessible part of the) shuffle product.
Definition: conjunction.hh:780
auto rs
Definition: lift.hh:152
auto add(const Aut1 &lhs, const Aut2 &rhs, deterministic_tag)
Definition: add.hh:71
Definition: a-star.hh:8
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
size_t num_accessible_states(const Aut &a)
Number of accessible states, not counting pre() and post().
Definition: accessible.hh:90
A dyn automaton.
Definition: automaton.hh:17
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:857
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
std::size_t num_components(const scc_automaton< Aut > &aut)
Get number of strongly connected components.
Definition: scc.hh:718
#define ECHO(Name, Value)
bool is_valid(const Aut &aut)
Definition: is-valid.hh:139
bool is_proper(const Aut &aut)
Test whether an automaton is proper.
Definition: is-proper.hh:47
auto conjunction(const Aut &aut, to exp) -> fresh_automaton_t_of< Aut >
Repeated conjunction of a automaton.
Definition: conjunction.hh:947
ValueSet::value_t compose(const ValueSet &vs, const typename ValueSet::value_t &lhs, const typename ValueSet::value_t &rhs)
Composition of values.
bool is_normalized(const Aut &a)
Whether a is standard and co-standard.
Definition: normalize.hh:12
size_t num_coaccessible_states(const Aut &a)
Number of accessible states, not counting pre() and post().
Definition: accessible.hh:105
bool is_cycle_ambiguous(const Aut &aut)
Whether aut is cycle-ambiguous.
std::ostream & info_expression(const expression &exp, std::ostream &o)
Bridge (info).
Definition: info.hh:190
bool is_codeterministic(const Aut &aut)
Whether the transposed automaton is deterministic.
auto & as()
Extract wrapped typed automaton.
Definition: automaton.hh:37
std::ostream & info(const Aut &aut, std::ostream &out=std::cout, bool detailed=false)
Print info about an automaton.
Definition: info.hh:73
#define VCSN_IF_FREE(Fun, Aut)
std::ostream & info(const automaton &aut, std::ostream &out, bool detailed)
Bridge.
Definition: info.hh:131
value_impl< detail::expression_tag > expression
Definition: fwd.hh:25
bool is_trim(const Aut &a)
Whether all its states are useful.
Definition: accessible.hh:161
size_t num_deterministic_states(const Aut &aut)
Number of non-deterministic states.
auto star(const Aut &aut, Tag tag={}) -> decltype(detail::make_join_automaton(tag, aut))
Star of an automaton.
Definition: star.hh:108
auto complement(const Aut &aut) -> decltype(copy(aut))
Definition: complement.hh:48
size_t num_useful_states(const Aut &a)
Number of accessible states, not counting pre() and post().
Definition: accessible.hh:113