Vcsn  2.2
Be Rational
polynomial.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 
6 #include <vcsn/dyn/fwd.hh>
7 #include <vcsn/misc/symbol.hh>
8 #include <vcsn/weightset/fwd.hh>
9 
10 namespace vcsn
11 {
12  namespace dyn
13  {
14  namespace detail
15  {
16 
19  {
20  public:
22  virtual symbol vname() const = 0;
23 
24  template <typename PolynomialSet>
25  auto& as()
26  {
28  }
29 
30  template <typename PolynomialSet>
31  auto& as() const
32  {
33  return dyn_cast<const polynomial_wrapper<PolynomialSet>&>(*this);
34  }
35 
37  virtual bool empty() const = 0;
38  };
39 
41  template <typename PolynomialSet>
42  class polynomial_wrapper final: public polynomial_base
43  {
44  public:
45  using polynomialset_t = PolynomialSet;
47  using polynomial_t = typename polynomialset_t::value_t;
49  : polynomialset_(ps)
50  , polynomial_(p)
51  {}
52  virtual ~polynomial_wrapper() {}
53 
54  virtual symbol vname() const override
55  {
56  return polynomialset().sname();
57  }
58 
60  {
61  return polynomialset_;
62  }
63 
64  const polynomial_t polynomial() const
65  {
66  return polynomial_;
67  }
68 
70  virtual bool empty() const override
71  {
72  return polynomial_.empty();
73  }
74 
75  private:
80  };
81 
84  template <typename PolynomialSetLhs, typename PolynomialSetRhs>
85  auto
86  join(const polynomial& lhs, const polynomial& rhs)
87  {
88  const auto& l = lhs->as<PolynomialSetLhs>();
89  const auto& r = rhs->as<PolynomialSetRhs>();
90  auto rs = join(l.polynomialset(), r.polynomialset());
91  auto lr = rs.conv(l.polynomialset(), l.polynomial());
92  auto rr = rs.conv(r.polynomialset(), r.polynomial());
93  return std::make_tuple(rs, lr, rr);
94  }
95 
96  } // namespace detail
97 
98  using polynomial = std::shared_ptr<const detail::polynomial_base>;
99 
100  template <typename PolynomialSet>
101  inline
102  polynomial
103  make_polynomial(const PolynomialSet& ps,
104  const typename PolynomialSet::value_t& p)
105  {
107  return std::make_shared<wrapper_t>(ps, p);
108  }
109  } // namespace dyn
110 } // namespace vcsn
polynomial_wrapper(const polynomialset_t &ps, const polynomial_t &p)
Definition: polynomial.hh:48
std::shared_ptr< const detail::polynomial_base > polynomial
Definition: fwd.hh:70
polynomial make_polynomial(const PolynomialSet &ps, const typename PolynomialSet::value_t &p)
Definition: polynomial.hh:103
Definition: a-star.hh:8
const polynomial_t polynomial_
The polynomial.
Definition: polynomial.hh:79
typename polynomialset_t::value_t polynomial_t
Definition: polynomial.hh:47
virtual bool empty() const =0
Whether is zero.
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
To dyn_cast(From &&from)
A dynamic_cast in debug mode, static_cast with NDEBUG.
Definition: fwd.hh:16
const polynomialset_t & polynomialset() const
Definition: polynomial.hh:59
virtual symbol vname() const override
A description of the polynomial.
Definition: polynomial.hh:54
const polynomialset_t polynomialset_
The polynomial set.
Definition: polynomial.hh:77
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:23
auto rs
Definition: lift.hh:151
Aggregate a polynomial and its polynomialset.
Definition: fwd.hh:68
const polynomial_t polynomial() const
Definition: polynomial.hh:64
virtual symbol vname() const =0
A description of the polynomial.
context join(const context &c1, const context &c2)
Bridge.
virtual bool empty() const override
Whether is zero.
Definition: polynomial.hh:70
An abstract polynomial.
Definition: polynomial.hh:18