Vcsn  2.1
Be Rational
divide.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/dyn/expression.hh>
4 #include <vcsn/dyn/polynomial.hh>
5 
6 namespace vcsn
7 {
8 
9  /*----------------------.
10  | ldiv(value, value). |
11  `----------------------*/
12 
14  template <typename ValueSet>
15  inline
16  typename ValueSet::value_t
17  ldiv(const ValueSet& vs,
18  const typename ValueSet::value_t& lhs,
19  const typename ValueSet::value_t& rhs)
20  {
21  return vs.ldiv(lhs, rhs);
22  }
23 
24 
25  namespace dyn
26  {
27  namespace detail
28  {
30  template <typename ExpressionSetLhs, typename ExpressionSetRhs>
32  ldiv_expression(const expression& lhs, const expression& rhs)
33  {
34  const auto& l = lhs->as<ExpressionSetLhs>();
35  const auto& r = rhs->as<ExpressionSetRhs>();
36  auto rs = join(l.expressionset(), r.expressionset());
37  auto lr = rs.conv(l.expressionset(), l.expression());
38  auto rr = rs.conv(r.expressionset(), r.expression());
39  return make_expression(rs, ldiv(rs, lr, rr));
40  }
41 
43  template <typename PolynomialSetLhs, typename PolynomialSetRhs>
45  ldiv_polynomial(const polynomial& lhs, const polynomial& rhs)
46  {
47  const auto& l = lhs->as<PolynomialSetLhs>();
48  const auto& r = rhs->as<PolynomialSetRhs>();
49  auto rs = join(l.polynomialset(), r.polynomialset());
50  auto lr = rs.conv(l.polynomialset(), l.polynomial());
51  auto rr = rs.conv(r.polynomialset(), r.polynomial());
52  return make_polynomial(rs, ldiv(rs, lr, rr));
53  }
54  }
55  }
56 
57  /*--------------------------------.
58  | lgcd(polynomial, polynomial). |
59  `--------------------------------*/
60 
62  template <typename ValueSet>
63  inline
64  typename ValueSet::value_t
65  lgcd(const ValueSet& vs,
66  const typename ValueSet::value_t& lhs,
67  const typename ValueSet::value_t& rhs)
68  {
69  return vs.lgcd(lhs, rhs);
70  }
71 
72 
73  namespace dyn
74  {
75  namespace detail
76  {
78  template <typename PolynomialSetLhs, typename PolynomialSetRhs>
80  lgcd_polynomial(const polynomial& lhs, const polynomial& rhs)
81  {
82  const auto& l = lhs->as<PolynomialSetLhs>();
83  const auto& r = rhs->as<PolynomialSetRhs>();
84  auto rs = join(l.polynomialset(), r.polynomialset());
85  auto lr = rs.conv(l.polynomialset(), l.polynomial());
86  auto rr = rs.conv(r.polynomialset(), r.polynomial());
87  return make_polynomial(rs, lgcd(rs, lr, rr));
88  }
89  }
90  }
91 
92  /*----------------------.
93  | rdiv(value, value). |
94  `----------------------*/
95 
97  template <typename ValueSet>
98  inline
99  typename ValueSet::value_t
100  rdiv(const ValueSet& vs,
101  const typename ValueSet::value_t& lhs,
102  const typename ValueSet::value_t& rhs)
103  {
104  return vs.rdiv(lhs, rhs);
105  }
106 
107  namespace dyn
108  {
109  namespace detail
110  {
112  template <typename ExpressionSetLhs, typename ExpressionSetRhs>
113  expression
114  rdiv_expression(const expression& lhs, const expression& rhs)
115  {
116  const auto& l = lhs->as<ExpressionSetLhs>();
117  const auto& r = rhs->as<ExpressionSetRhs>();
118  auto rs = join(l.expressionset(), r.expressionset());
119  auto lr = rs.conv(l.expressionset(), l.expression());
120  auto rr = rs.conv(r.expressionset(), r.expression());
121  return make_expression(rs, rdiv(rs, lr, rr));
122  }
123  }
124  }
125 }
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
expression rdiv_expression(const expression &lhs, const expression &rhs)
Bridge (rdiv).
Definition: divide.hh:114
ValueSet::value_t rdiv(const ValueSet &vs, const typename ValueSet::value_t &lhs, const typename ValueSet::value_t &rhs)
Right-division of values.
Definition: divide.hh:100
expression ldiv_expression(const expression &lhs, const expression &rhs)
Bridge (ldiv).
Definition: divide.hh:32
polynomial make_polynomial(const PolynomialSet &ps, const typename PolynomialSet::value_t &p)
Definition: polynomial.hh:88
polynomial ldiv_polynomial(const polynomial &lhs, const polynomial &rhs)
Bridge (ldiv).
Definition: divide.hh:45
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
expression rdiv(const expression &lhs, const expression &rhs)
Right-division of two expressions (lhs \ rhs).
auto rs
Definition: lift.hh:151
std::shared_ptr< const detail::polynomial_base > polynomial
Definition: fwd.hh:68
expression make_expression(const ExpSet &rs, const typename ExpSet::value_t &r)
Definition: expression.hh:83
polynomial lgcd_polynomial(const polynomial &lhs, const polynomial &rhs)
Bridge (lgcd).
Definition: divide.hh:80
polynomial lgcd(const polynomial &lhs, const polynomial &rhs)
Left greatest common divisor of two polynomials (lhs \ rhs).
std::shared_ptr< detail::expression_base > expression
Definition: expression.hh:78
context join(const context &c1, const context &c2)
Bridge.
Definition: make-context.hh:92
ValueSet::value_t lgcd(const ValueSet &vs, const typename ValueSet::value_t &lhs, const typename ValueSet::value_t &rhs)
Left-division of values.
Definition: divide.hh:65