Vcsn  2.1
Be Rational
vcsn::rat::expansionset< ExpSet > Struct Template Reference

#include <expansionset.hh>

Inheritance diagram for vcsn::rat::expansionset< ExpSet >:
Collaboration diagram for vcsn::rat::expansionset< ExpSet >:

Classes

struct  tuple_impl
 Denormalize a pack of one-tape expansions. More...
 
struct  value_t
 An expansion. More...
 

Public Types

using expressionset_t = ExpSet
 
using context_t = context_t_of< expressionset_t >
 
using labelset_t = labelset_t_of< context_t >
 
using label_t = label_t_of< context_t >
 
using expression_t = typename expressionset_t::value_t
 
using weightset_t = weightset_t_of< expressionset_t >
 
using weight_t = typename weightset_t::value_t
 
using polynomialset_t = expression_polynomialset_t< expressionset_t >
 
using polynomial_t = typename polynomialset_t::value_t
 
using monomial_t = typename polynomialset_t::monomial_t
 
using polys_t = std::map< label_t, polynomial_t, vcsn::less< labelset_t >>
 
template<unsigned Tape>
using focus_t = expansionset< typename expressionset_t::template focus_t< Tape >>
 The type of the expansionsset for tape Tape. More...
 

Public Member Functions

 expansionset (const expressionset_t &rs)
 
const expressionset_texpressionset () const
 The expressionset. More...
 
std::ostream & print_set (std::ostream &o, format fmt={}) const
 Print this valueset. More...
 
std::ostream & print (const value_t &v, std::ostream &o, format fmt={}) const
 Print this expansion. More...
 
value_tnormalize (value_t &res) const
 Normalize: move the constant term to the label one. More...
 
value_tnormalize_ (value_t &res, std::true_type) const
 Normalize res: There must not remain a constant-term associated to one: put it with the constant term of the expansion. More...
 
value_tnormalize_ (value_t &res, std::false_type) const
 Normalize when there is no label one: identity. More...
 
value_tdenormalize (value_t &res) const
 Move the constant to the polynomial associated to one. More...
 
value_tdenormalize_ (value_t &res, std::true_type) const
 Denormalize res move the constant to the polynomial associated to one. More...
 
value_tdenormalize_ (value_t &res, std::false_type) const
 Denormalize when there is no label one: identity. More...
 
value_t zero () const
 The zero. More...
 
value_t one () const
 The one. More...
 
value_t atom (const label_t &l) const
 A single label. More...
 
void add_here (value_t &lhs, const value_t &rhs) const
 In place addition. More...
 
value_tlmul_here (const weight_t &w, value_t &res) const
 Inplace left-multiplication by w of res. More...
 
value_t rmul (const value_t &lhs, const weight_t &w) const
 Right-multiplication of lhs by w. More...
 
value_trmul_here (value_t &res, const expression_t &rhs) const
 In place right multiplication by an expression. More...
 
value_tldiv_here (const weight_t &w, value_t &res) const
 Inplace left-division by w of res. More...
 
value_t conjunction (value_t l, value_t r) const
 The conjunction of l and r. More...
 
value_t shuffle (const value_t &lhs_xpn, const expression_t &lhs_xpr, const value_t &rhs_xpn, const expression_t &rhs_xpr) const
 The shuffle product of l and r. More...
 
value_t infiltration (const value_t &lhs_xpn, const expression_t &lhs_xpr, const value_t &rhs_xpn, const expression_t &rhs_xpr) const
 The infiltration product of l and r. More...
 
value_t complement (const value_t &v) const
 The complement of v. More...
 
value_t determinize (const value_t &v) const
 Turn the polynomials into (normalized) monomials. More...
 
template<unsigned Tape>
auto focus () const -> focus_t< Tape >
 The expansionsset for tape Tape. More...
 
template<typename... Expansions>
auto tuple (Expansions &&...es) const -> value_t
 The tuplization of single-tape expansions into a multitape expansion. More...
 

Static Public Member Functions

static constexpr const charme ()
 
static symbol sname ()
 The static name. More...
 

Private Member Functions

template<typename Conjunction >
void conjunctions_with_one_ (value_t &, const value_t &, const value_t &, std::false_type, Conjunction) const
 
template<typename Conjunction >
void conjunctions_with_one_ (value_t &res, const value_t &l, const value_t &r, std::true_type, Conjunction conjunction) const
 
template<typename LabelSet = labelset_t, typename Conjunction >
auto conjunction_ (value_t l, value_t r, Conjunction conjunction) const -> enable_if_t< detail::is_letterized_t< LabelSet >
 The conjunction of l and r. More...
 
 denormalize (l)
 
 denormalize (r)
 
 for (const auto &p:zip_maps(l.polynomials, r.polynomials)) res.polynomials[p.first]
 
 conjunctions_with_one_ (res, l, r, has_one, conjunction)
 
 normalize (res)
 
template<typename LabelSet = labelset_t, typename Conjunction >
auto conjunction_ (value_t lhs, value_t rhs, Conjunction conjunction) const -> enable_if_t<!detail::is_letterized_t< LabelSet >
 The conjunction of l and r. More...
 
 for (const auto &l:lhs.polynomials) for(const auto &r
 
template<typename Shuffle >
value_tshuffle_ (value_t &res, const value_t &lhs_xpn, const expression_t &lhs_xpr, const value_t &rhs_xpn, const expression_t &rhs_xpr, Shuffle shuffle) const
 The shuffle product of l and r. More...
 
template<bool IsFree>
vcsn::enable_if_t<!IsFree, value_tcomplement_ (const value_t &) const
 Cannot complement on a non-free labelset. More...
 
template<bool IsFree>
vcsn::enable_if_t< IsFree, value_tcomplement_ (const value_t &v) const
 Complement on a free labelset. More...
 

Private Attributes

 value_t
 
res constant = ws_.mul(l.constant, r.constant)
 
auto has_one = bool_constant<context_t::has_one()>()
 
return res
 
expressionset_t rs_
 The expressionset used for the expressions. More...
 
const labelset_tls_ = *rs_.labelset()
 Shorthand to the labelset. More...
 
const weightset_tws_ = *rs_.weightset()
 Shorthand to the weightset. More...
 
polynomialset_t ps_ = make_expression_polynomialset(rs_)
 The polynomialset for the polynomials. More...
 

Detailed Description

template<typename ExpSet>
struct vcsn::rat::expansionset< ExpSet >

Definition at line 17 of file expansionset.hh.

Member Typedef Documentation

template<typename ExpSet>
using vcsn::rat::expansionset< ExpSet >::context_t = context_t_of<expressionset_t>

Definition at line 21 of file expansionset.hh.

template<typename ExpSet>
using vcsn::rat::expansionset< ExpSet >::expression_t = typename expressionset_t::value_t

Definition at line 24 of file expansionset.hh.

template<typename ExpSet>
using vcsn::rat::expansionset< ExpSet >::expressionset_t = ExpSet

Definition at line 20 of file expansionset.hh.

template<typename ExpSet>
template<unsigned Tape>
using vcsn::rat::expansionset< ExpSet >::focus_t = expansionset<typename expressionset_t::template focus_t<Tape>>

The type of the expansionsset for tape Tape.

Definition at line 439 of file expansionset.hh.

template<typename ExpSet>
using vcsn::rat::expansionset< ExpSet >::label_t = label_t_of<context_t>

Definition at line 23 of file expansionset.hh.

template<typename ExpSet>
using vcsn::rat::expansionset< ExpSet >::labelset_t = labelset_t_of<context_t>

Definition at line 22 of file expansionset.hh.

template<typename ExpSet>
using vcsn::rat::expansionset< ExpSet >::monomial_t = typename polynomialset_t::monomial_t

Definition at line 30 of file expansionset.hh.

template<typename ExpSet>
using vcsn::rat::expansionset< ExpSet >::polynomial_t = typename polynomialset_t::value_t

Definition at line 29 of file expansionset.hh.

Definition at line 28 of file expansionset.hh.

template<typename ExpSet>
using vcsn::rat::expansionset< ExpSet >::polys_t = std::map<label_t, polynomial_t, vcsn::less<labelset_t>>

Definition at line 37 of file expansionset.hh.

template<typename ExpSet>
using vcsn::rat::expansionset< ExpSet >::weight_t = typename weightset_t::value_t

Definition at line 26 of file expansionset.hh.

template<typename ExpSet>
using vcsn::rat::expansionset< ExpSet >::weightset_t = weightset_t_of<expressionset_t>

Definition at line 25 of file expansionset.hh.

Constructor & Destructor Documentation

template<typename ExpSet>
vcsn::rat::expansionset< ExpSet >::expansionset ( const expressionset_t rs)
inline

Definition at line 46 of file expansionset.hh.

Member Function Documentation

template<typename ExpSet>
void vcsn::rat::expansionset< ExpSet >::add_here ( value_t lhs,
const value_t rhs 
) const
inline

In place addition.

Definition at line 176 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
value_t vcsn::rat::expansionset< ExpSet >::atom ( const label_t l) const
inline

A single label.

Definition at line 170 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
value_t vcsn::rat::expansionset< ExpSet >::complement ( const value_t v) const
inline

The complement of v.

Definition at line 387 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
template<bool IsFree>
vcsn::enable_if_t<!IsFree, value_t> vcsn::rat::expansionset< ExpSet >::complement_ ( const value_t ) const
inlineprivate

Cannot complement on a non-free labelset.

Definition at line 397 of file expansionset.hh.

template<typename ExpSet>
template<bool IsFree>
vcsn::enable_if_t<IsFree, value_t> vcsn::rat::expansionset< ExpSet >::complement_ ( const value_t v) const
inlineprivate

Complement on a free labelset.

Definition at line 405 of file expansionset.hh.

template<typename ExpSet>
value_t vcsn::rat::expansionset< ExpSet >::conjunction ( value_t  l,
value_t  r 
) const
inline

The conjunction of l and r.

Definition at line 336 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
template<typename LabelSet = labelset_t, typename Conjunction >
auto vcsn::rat::expansionset< ExpSet >::conjunction_ ( value_t  l,
value_t  r,
Conjunction  conjunction 
) const -> enable_if_t<detail::is_letterized_t<LabelSet>
inlineprivate

The conjunction of l and r.

When labelset is letterized.

Definition at line 266 of file expansionset.hh.

template<typename ExpSet>
template<typename LabelSet = labelset_t, typename Conjunction >
auto vcsn::rat::expansionset< ExpSet >::conjunction_ ( value_t  lhs,
value_t  rhs,
Conjunction  conjunction 
) const -> enable_if_t<!detail::is_letterized_t<LabelSet>
inlineprivate

The conjunction of l and r.

When labelset is not letterized.

Definition at line 289 of file expansionset.hh.

template<typename ExpSet>
template<typename Conjunction >
void vcsn::rat::expansionset< ExpSet >::conjunctions_with_one_ ( value_t ,
const value_t ,
const value_t ,
std::false_type  ,
Conjunction   
) const
inlineprivate

Definition at line 224 of file expansionset.hh.

template<typename ExpSet>
template<typename Conjunction >
void vcsn::rat::expansionset< ExpSet >::conjunctions_with_one_ ( value_t res,
const value_t l,
const value_t r,
std::true_type  ,
Conjunction  conjunction 
) const
inlineprivate

Definition at line 232 of file expansionset.hh.

template<typename ExpSet>
vcsn::rat::expansionset< ExpSet >::conjunctions_with_one_ ( res  ,
,
r  ,
has_one  ,
conjunction   
)
private
template<typename ExpSet>
value_t& vcsn::rat::expansionset< ExpSet >::denormalize ( value_t res) const
inline

Move the constant to the polynomial associated to one.

Definition at line 131 of file expansionset.hh.

template<typename ExpSet>
vcsn::rat::expansionset< ExpSet >::denormalize ( )
private
template<typename ExpSet>
vcsn::rat::expansionset< ExpSet >::denormalize ( r  )
private
template<typename ExpSet>
value_t& vcsn::rat::expansionset< ExpSet >::denormalize_ ( value_t res,
std::true_type   
) const
inline

Denormalize res move the constant to the polynomial associated to one.

Definition at line 139 of file expansionset.hh.

template<typename ExpSet>
value_t& vcsn::rat::expansionset< ExpSet >::denormalize_ ( value_t res,
std::false_type   
) const
inline

Denormalize when there is no label one: identity.

Definition at line 152 of file expansionset.hh.

template<typename ExpSet>
value_t vcsn::rat::expansionset< ExpSet >::determinize ( const value_t v) const
inline

Turn the polynomials into (normalized) monomials.

Definition at line 423 of file expansionset.hh.

template<typename ExpSet>
const expressionset_t& vcsn::rat::expansionset< ExpSet >::expressionset ( ) const
inline

The expressionset.

Definition at line 58 of file expansionset.hh.

template<typename ExpSet>
template<unsigned Tape>
auto vcsn::rat::expansionset< ExpSet >::focus ( ) const -> focus_t<Tape>
inline

The expansionsset for tape Tape.

Definition at line 443 of file expansionset.hh.

template<typename ExpSet>
vcsn::rat::expansionset< ExpSet >::for ( const auto &p:  zip_mapsl.polynomials, r.polynomials)
private
template<typename ExpSet>
vcsn::rat::expansionset< ExpSet >::for ( const auto &l:lhs.  polynomials) const
inlineprivate

Definition at line 296 of file expansionset.hh.

template<typename ExpSet>
value_t vcsn::rat::expansionset< ExpSet >::infiltration ( const value_t lhs_xpn,
const expression_t lhs_xpr,
const value_t rhs_xpn,
const expression_t rhs_xpr 
) const
inline

The infiltration product of l and r.

Definition at line 361 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
value_t& vcsn::rat::expansionset< ExpSet >::ldiv_here ( const weight_t w,
value_t res 
) const
inline

Inplace left-division by w of res.

Definition at line 212 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
value_t& vcsn::rat::expansionset< ExpSet >::lmul_here ( const weight_t w,
value_t res 
) const
inline

Inplace left-multiplication by w of res.

Definition at line 184 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
static constexpr const char* vcsn::rat::expansionset< ExpSet >::me ( )
inlinestatic

Definition at line 32 of file expansionset.hh.

template<typename ExpSet>
value_t& vcsn::rat::expansionset< ExpSet >::normalize ( value_t res) const
inline

Normalize: move the constant term to the label one.

Definition at line 97 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
vcsn::rat::expansionset< ExpSet >::normalize ( res  )
private
template<typename ExpSet>
value_t& vcsn::rat::expansionset< ExpSet >::normalize_ ( value_t res,
std::true_type   
) const
inline

Normalize res: There must not remain a constant-term associated to one: put it with the constant term of the expansion.

Definition at line 106 of file expansionset.hh.

template<typename ExpSet>
value_t& vcsn::rat::expansionset< ExpSet >::normalize_ ( value_t res,
std::false_type   
) const
inline

Normalize when there is no label one: identity.

Definition at line 125 of file expansionset.hh.

template<typename ExpSet>
value_t vcsn::rat::expansionset< ExpSet >::one ( ) const
inline

The one.

Definition at line 164 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
std::ostream& vcsn::rat::expansionset< ExpSet >::print ( const value_t v,
std::ostream &  o,
format  fmt = {} 
) const
inline

Print this expansion.

Definition at line 72 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::print_().

template<typename ExpSet>
std::ostream& vcsn::rat::expansionset< ExpSet >::print_set ( std::ostream &  o,
format  fmt = {} 
) const
inline

Print this valueset.

Definition at line 64 of file expansionset.hh.

template<typename ExpSet>
value_t vcsn::rat::expansionset< ExpSet >::rmul ( const value_t lhs,
const weight_t w 
) const
inline

Right-multiplication of lhs by w.

Definition at line 193 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
value_t& vcsn::rat::expansionset< ExpSet >::rmul_here ( value_t res,
const expression_t rhs 
) const
inline

In place right multiplication by an expression.

Definition at line 204 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
value_t vcsn::rat::expansionset< ExpSet >::shuffle ( const value_t lhs_xpn,
const expression_t lhs_xpr,
const value_t rhs_xpn,
const expression_t rhs_xpr 
) const
inline

The shuffle product of l and r.

Definition at line 347 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::VCSN_RAT_VISIT().

template<typename ExpSet>
template<typename Shuffle >
value_t& vcsn::rat::expansionset< ExpSet >::shuffle_ ( value_t res,
const value_t lhs_xpn,
const expression_t lhs_xpr,
const value_t rhs_xpn,
const expression_t rhs_xpr,
Shuffle  shuffle 
) const
inlineprivate

The shuffle product of l and r.

Definition at line 315 of file expansionset.hh.

template<typename ExpSet>
static symbol vcsn::rat::expansionset< ExpSet >::sname ( )
inlinestatic

The static name.

Definition at line 51 of file expansionset.hh.

template<typename ExpSet>
template<typename... Expansions>
auto vcsn::rat::expansionset< ExpSet >::tuple ( Expansions &&...  es) const -> value_t
inline

The tuplization of single-tape expansions into a multitape expansion.

Another implementation is possible, based on the following two-tape example taking e0 and e1, two single-tape expansions:

auto res = zero(); res.constant = ws_.mul(e0.constant, e1.constant); for (const auto& p0: e0.polynomials) for (const auto& p1: e1.polynomials) { auto l = label_t{p0.first, p1.first}; ps_.add_here(res.polynomials[l], ps_.tuple(p0.second, p1.second)); } if (!ws_.is_zero(e0.constant)) { auto rs0 = detail::make_project<0>(rs_); using p0_t = typename polynomialset_t::template focus_t<0>; auto p0 = p0_t{{rs0.one(), e0.constant}}; for (const auto& p1: e1.polynomials) { auto l = label_t{detail::label_one(*rs0.labelset()), p1.first}; ps_.add_here(res.polynomials[l], ps_.tuple(p0, p1.second)); } } if (!ws_.is_zero(e1.constant)) { auto rs1 = detail::make_project<1>(rs_); using p1_t = typename polynomialset_t::template focus_t<1>; auto p1 = p1_t{{rs1.one(), e1.constant}}; for (const auto& p0: e0.polynomials) { auto l = label_t{p0.first, detail::label_one(*rs1.labelset())}; ps_.add_here(res.polynomials[l], ps_.tuple(p0.second, p1)); } } return res;

The first part, the two nested for-loops that deal with the polynomial part of the expansions, is easy to scale to variadic tuples (that's a Cartesian product). The second part, the two if's and loop that deal with the constant terms, is more tricky.

Rather than making the code more complex, since the constant part of the expansions is just the weight of the unit polynomial for the unit label, let's denormalize the expansions, let the general laws apply, and then normalize the result.

Definition at line 543 of file expansionset.hh.

Referenced by vcsn::rat::to_expansion_visitor< ExpSet >::visit_tuple< bool, Dummy >::work_().

template<typename ExpSet>
value_t vcsn::rat::expansionset< ExpSet >::zero ( ) const
inline

Member Data Documentation

template<typename ExpSet>
res vcsn::rat::expansionset< ExpSet >::constant = ws_.mul(l.constant, r.constant)
private

Definition at line 274 of file expansionset.hh.

template<typename ExpSet>
auto vcsn::rat::expansionset< ExpSet >::has_one = bool_constant<context_t::has_one()>()
private

Definition at line 279 of file expansionset.hh.

template<typename ExpSet>
const labelset_t& vcsn::rat::expansionset< ExpSet >::ls_ = *rs_.labelset()
private

Shorthand to the labelset.

Definition at line 563 of file expansionset.hh.

template<typename ExpSet>
polynomialset_t vcsn::rat::expansionset< ExpSet >::ps_ = make_expression_polynomialset(rs_)
private

The polynomialset for the polynomials.

Definition at line 567 of file expansionset.hh.

template<typename ExpSet>
return vcsn::rat::expansionset< ExpSet >::res
private

Definition at line 282 of file expansionset.hh.

Referenced by vcsn::rat::expansionset< expressionset_t >::sname().

template<typename ExpSet>
expressionset_t vcsn::rat::expansionset< ExpSet >::rs_
private

The expressionset used for the expressions.

Definition at line 561 of file expansionset.hh.

Referenced by vcsn::rat::expansionset< expressionset_t >::expressionset().

template<typename ExpSet>
vcsn::rat::expansionset< ExpSet >::value_t
private
Initial value:

Definition at line 270 of file expansionset.hh.

template<typename ExpSet>
const weightset_t& vcsn::rat::expansionset< ExpSet >::ws_ = *rs_.weightset()
private

Shorthand to the weightset.

Definition at line 565 of file expansionset.hh.


The documentation for this struct was generated from the following file: