17 #ifndef AWALI_WEIGHTSET_C_HH 
   18 #define AWALI_WEIGHTSET_C_HH 
   52         std::string 
vname(
bool = 
true)
 const 
  108           if (std::norm(v) < 1)
 
  112             raise(
sname(), 
": star: invalid value: ", 
format(*
this, v));
 
  122           return v.real() == 0 && v.imag() == 0;
 
  128           return v.real() == 1 && v.imag() == 0;
 
  139           if(std::norm(lhs) == std::norm(rhs))
 
  140             return std::arg(lhs) < std::arg(rhs);
 
  141           return std::norm(lhs) < std::norm(rhs);
 
  184           return {double(v.
num) / double(v.
den)};
 
  206           std::ostringstream os;
 
  208           if (i.peek()==
'+' || i.peek()==
'-')
 
  210           while((maybe = i.peek()) == 
'.' || (maybe >=
'0' && maybe <=
'9')) {
 
  214           if(os.str().empty()) {
 
  219             throw std::runtime_error(
sname() + 
" : invalid real");
 
  222           std::istringstream is(os.str());
 
  234           if ((maybe = i.peek()) == 
'i') { 
 
  239           if ((maybe = i.peek()) == 
'i') { 
 
  243           if ((maybe = i.peek()) == 
'+' || maybe == 
'-'){ 
 
  255           for(; i>0 && ((s[i-1]>=
'0' && s[i-1]<=
'9') || s[i-1]==
'.'); --i)
 
  259             std::istringstream st(s.substr(i, p-i));
 
  274         parse(
const std::string & s, 
size_t& p) {
 
  288               const std::string& 
format = 
"text")
 
  292             if(v.real()!=0 || v.imag()==0) {
 
  293               o << 
"\"re\":" << v.real();
 
  295                 o<< 
", \"im\":" << v.imag();
 
  298               o<< 
"\"im\":" << v.imag();
 
  308             double im = v.imag();
 
  316           if(v.real()==0 && v.imag()==0)
 
  326           else if (
format == 
"text")
 
  329             raise(
"invalid format: ", 
format);
 
  333     template<
unsigned version = version::fsm_json>
 
  348     template<
unsigned version = version::fsm_json>
 
  362           else if (v.real() == 0.)
 
  372         template<
unsigned version = version::fsm_json>
 
  385                   std::vector<json::node_t*> 
const& v = p->
array()->
values;
 
  390                     a[i]=v[i]->to_double();
 
  410                   size_t pos = str.length();
 
  420                                              + 
" node to a complex number.",
 
  427   inline c join(
const c&, 
const c&) { 
return {}; }
 
  429   inline c join(
const r&, 
const c&) { 
return {}; }
 
  430   inline c join(
const c&, 
const r&) { 
return {}; }
 
  432   inline c join(
const q&, 
const c&) { 
return {}; }
 
  433   inline c join(
const c&, 
const q&) { 
return {}; }
 
  435   inline c join(
const z&, 
const c&) { 
return {}; }
 
  436   inline c join(
const c&, 
const z&) { 
return {}; }
 
  438   inline c join(
const n&, 
const c&) { 
return {}; }
 
  439   inline c join(
const c&, 
const n&) { 
return {}; }
 
  441   inline c join(
const b&, 
const c&) { 
return {}; }
 
  442   inline c join(
const c&, 
const b&) { 
return {}; }
 
std::vector< node_t * > const  & values
Definition: node.hh:429
Exception used when trying to coerce a node to a given type.
Definition: exceptions.hh:83
The main exception for json manipulation.
Definition: exceptions.hh:26
virtual node_t * at(std::string const &key)
virtual double to_double() const
Coerces this node_t to a double
Definition: node.hh:341
virtual string_t const  * string() const
Casts this node to string_t.
Definition: node.hh:213
virtual bool has_child(std::string const &) const
Definition: node.hh:282
node_kind_t const kind
Definition: node.hh:194
virtual unsigned arity() const
Definition: node.hh:353
virtual array_t const  * array() const
Casts this node to array_t.
Definition: node.hh:205
object_t * push_back(std::string key, node_t *node)
std::string value
Definition: node.hh:528
The Boolean semring.
Definition: b.hh:38
bool value_t
Definition: b.hh:56
The semiring of complex numbers.
Definition: c.hh:43
static value_t zero()
Definition: c.hh:67
static c make(std::istream &is)
Build from the description in is.
Definition: c.hh:58
static bool is_special(const value_t)
Definition: c.hh:115
static bool equals(const value_t l, const value_t r)
Definition: c.hh:131
static value_t conv(q, q::value_t v)
Definition: c.hh:182
static double parse_simple_real(const std::string &s, size_t &p, double def=0)
Definition: c.hh:253
std::string vname(bool=true) const
Definition: c.hh:52
json::node_t * to_json() const
Definition: c.hh:335
static double greedy(std::istream &i)
Definition: c.hh:205
value_t value_from_json(json::node_t const *p) const
Definition: c.hh:374
static value_t abs(const value_t v)
Definition: c.hh:150
std::complex< double > value_t
Definition: c.hh:64
json::node_t * value_to_json(value_t v) const
Definition: c.hh:350
static value_t conv(b, b::value_t v)
Definition: c.hh:200
static bool less_than(value_t lhs, value_t rhs)
Whether lhs < rhs.
Definition: c.hh:137
static value_t conv(self_type, value_t v)
Definition: c.hh:170
static std::ostream & print(const value_t v, std::ostream &o, const std::string &format="text")
Definition: c.hh:287
static value_t transpose(const value_t v)
Definition: c.hh:156
static constexpr bool show_one()
Definition: c.hh:146
static value_t conv(std::istream &i)
Definition: c.hh:230
static value_t parse(const std::string &s, size_t &p)
Definition: c.hh:274
static value_t one()
Definition: c.hh:72
std::ostream & print_set(std::ostream &o, const std::string &format="text") const
Definition: c.hh:322
static size_t hash(value_t v)
Definition: c.hh:161
static bool is_one(const value_t v)
Definition: c.hh:125
value_t star(const value_t v) const
Definition: c.hh:105
static std::string sname()
Definition: c.hh:47
static value_t ldiv(const value_t l, const value_t r)
Definition: c.hh:100
static bool is_zero(const value_t v)
Definition: c.hh:120
static constexpr bool is_commutative_semiring()
Definition: c.hh:144
static value_t sub(const value_t l, const value_t r)
Definition: c.hh:82
static value_t mul(const value_t l, const value_t r)
Definition: c.hh:87
static value_t conv(n, n::value_t v)
Definition: c.hh:194
static value_t rdiv(const value_t l, const value_t r)
Definition: c.hh:93
static value_t conv(r, r::value_t v)
Definition: c.hh:176
static value_t add(const value_t l, const value_t r)
Definition: c.hh:77
static constexpr star_status_t star_status()
Definition: c.hh:147
static value_t conv(z, z::value_t v)
Definition: c.hh:188
The semiring of Natural numbers.
Definition: n.hh:33
unsigned int value_t
Definition: n.hh:54
The semiring of rational numbers.
Definition: q.hh:41
The semiring of floating Numbers.
Definition: r.hh:34
double value_t
Definition: r.hh:55
static value_t parse(const std::string &s, size_t &p)
Definition: r.hh:201
The semiring of Integers.
Definition: z.hh:34
int value_t
Definition: z.hh:55
star_status_t
The different behaviours a weightset may have with respect to the star.
Definition: enums.hh:161
@ ABSVAL
Definition: enums.hh:166
std::string const  & string_of(node_kind_t kind)
@ OBJECT
Definition: node.hh:90
@ ARRAY
Definition: node.hh:91
@ STRING
Definition: node.hh:94
std::string to_string(identities i)
void eat(std::istream &is, char c)
Check lookahead character and advance.
Definition: stream.hh:62
ATTRIBUTE_NORETURN void fail_reading(std::istream &is, std::string explanation)
Throw an exception after failing to read from is.
Definition: stream.hh:93
auto join(const ratexpset< Ctx1 > &a, const ratexpset< Ctx2 > &b) -> ratexpset< join_t< Ctx1, Ctx2 >>
The union of two ratexpsets.
Definition: ratexpset.hh:448
auto format(const ValueSet &vs, const typename ValueSet::value_t &v, Args &&... args) -> std::string
Format v via vs.print.
Definition: stream.hh:109
void require(bool b, Args &&... args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:55
std::size_t hash_value(const T &v)
Definition: hash.hh:76
Main namespace of Awali.
Definition: ato.hh:22
Exceptions thrown during parsing.
Definition: parse_exception.hh:26
Definition: qfraction.hh:26
int num
Definition: qfraction.hh:27
unsigned int den
Definition: qfraction.hh:28