Awali
Another Weighted Automata library
exp_support.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_ALGOS_EXP_SUPPORT_HH
18 # define AWALI_ALGOS_EXP_SUPPORT_HH
19 
20 #include <awali/sttc/ctx/fwd.hh>
21 #include <awali/sttc/ctx/traits.hh>
24 
25 namespace awali { namespace sttc {
26 
27  namespace rat
28  {
31  template <typename RatExpSet>
33  : public RatExpSet::const_visitor
34  {
35  public:
36  using in_ratexpset_t = RatExpSet;
39 
42  using ratexp_t = typename in_ratexpset_t::ratexp_t;
43  using out_ratexp_t = typename out_ratexpset_t::ratexp_t;
44 
45  using super_type = typename RatExpSet::const_visitor;
46 
47  constexpr static const char* me() { return "exp support"; }
48 
50  : in_ratexpset_ (ratexpset)
51  {}
52 
54  operator()(const ratexp_t& v)
55  {
56  v->accept(*this);
57  return res_;
58  }
59 
61  {
62  res_ = out_ratexpset_.zero();
63  }
64 
66  {
67  res_ = out_ratexpset_.one();
68  }
69 
71  {
72  res_ = out_ratexpset_.atom(e.value());
73  }
74 
76  {
77  auto r = out_ratexpset_.zero();
78  for (auto c: e)
79  {
80  c->accept(*this);
81  r = out_ratexpset_.add(r, res_);
82  }
83  res_ = r;
84  }
85 
91 
93  {
94  auto r = out_ratexpset_.one();
95  for (auto c: e)
96  {
97  c->accept(*this);
98  r = out_ratexpset_.mul(r, res_);
99  }
100  res_ = r;
101  }
102 
104  {
105  e.sub()->accept(*this);
106  res_ = out_ratexpset_.star(res_);
107  }
108 
110  {
111  e.sub()->accept(*this);
112  }
113 
115  {
116  e.sub()->accept(*this);
117  }
118 
120  return out_ratexpset_;
121  }
122 
123  private:
124  const in_ratexpset_t& in_ratexpset_;
125  out_context_t out_context_{*in_ratexpset_.labelset(), b()};
126  out_ratexpset_t out_ratexpset_{out_context_, in_ratexpset_.identities()};
127  typename out_ratexpset_t::ratexp_t res_;
128  };
129 
130  } // rat::
131 
141  template <typename RatExpSet>
142  auto
143  ratexp_support(const typename RatExpSet::ratexp_t& exp,
144  const RatExpSet& ratexpset)
146  {
148  return copyer(exp);
149  }
150  template <typename RatExpSet>
157  auto
158  support_ratexpset(const RatExpSet& ratexpset)
160  {
162  return copyer.get_ratexpset();
163  }
164  }
165 }//end of ns awali::stc
166 
167 #endif // !AWALI_ALGOS_EXP_COPY_HH
The Boolean semring.
Definition: b.hh:38
The semiring of complex numbers.
Definition: c.hh:44
const labelset_ptr & labelset() const
Definition: context.hh:152
The semiring of floating Numbers.
Definition: r.hh:35
Definition: ratexp.hh:280
Definition: ratexp.hh:262
Definition: exp_support.hh:34
expsupport_visitor(const in_ratexpset_t &ratexpset)
Definition: exp_support.hh:49
AWALI_RAT_VISIT(star, e)
Definition: exp_support.hh:103
context< labelset_t, sttc::b > out_context_t
Definition: exp_support.hh:40
AWALI_RAT_VISIT(rweight, e)
Definition: exp_support.hh:114
typename in_ratexpset_t::ratexp_t ratexp_t
Definition: exp_support.hh:42
RatExpSet in_ratexpset_t
Definition: exp_support.hh:36
labelset_t_of< in_context_t > labelset_t
Definition: exp_support.hh:38
AWALI_RAT_VISIT(lweight, e)
Definition: exp_support.hh:109
typename out_ratexpset_t::ratexp_t out_ratexp_t
Definition: exp_support.hh:43
out_ratexpset_t get_ratexpset()
Definition: exp_support.hh:119
AWALI_RAT_VISIT(one,)
Definition: exp_support.hh:65
constexpr static const char * me()
Definition: exp_support.hh:47
AWALI_RAT_VISIT(atom, e)
Definition: exp_support.hh:70
AWALI_RAT_VISIT(zero,)
Definition: exp_support.hh:60
AWALI_RAT_VISIT(sum, e)
Definition: exp_support.hh:75
ratexpset_of< out_context_t > out_ratexpset_t
Definition: exp_support.hh:41
typename RatExpSet::const_visitor super_type
Definition: exp_support.hh:45
context_t_of< in_ratexpset_t > in_context_t
Definition: exp_support.hh:37
out_ratexp_t operator()(const ratexp_t &v)
Definition: exp_support.hh:54
Definition: ratexp.hh:176
An inner node with multiple children.
Definition: ratexp.hh:115
An inner node implementing a weight.
Definition: ratexp.hh:208
typename internal::context_t_of_impl< internal::base_t< ValueSet > >::type context_t_of
Helper to retrieve the type of the context of a value set.
Definition: traits.hh:66
typename internal::labelset_t_of_impl< internal::base_t< ValueSet > >::type labelset_t_of
Helper to retrieve the type of the labelset of a value set.
Definition: traits.hh:76
auto ratexp_support(const typename RatExpSet::ratexp_t &exp, const RatExpSet &ratexpset) -> typename rat::expsupport_visitor< RatExpSet >::out_ratexp_t
support of a rational expression
Definition: exp_support.hh:143
auto support_ratexpset(const RatExpSet &ratexpset) -> typename rat::expsupport_visitor< RatExpSet >::out_ratexpset_t
Compute a derived ratexpset.
Definition: exp_support.hh:158
Main namespace of Awali.
Definition: ato.hh:22
Provide a variadic mul on top of a binary mul(), and one().
Definition: weightset.hh:38
value_t mul(const Ts &... ts) const
Definition: weightset.hh:49
#define AWALI_RAT_UNSUPPORTED(Type)
Definition: visitor.hh:73