cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
algebraic_number.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Algebraic Numbers
4
5
Author: Michael Tautschnig
6
7
\*******************************************************************/
8
11
12
#include "
algebraic_number.h
"
13
14
#include "
mathematical_types.h
"
15
#include "
rational_tools.h
"
16
17
constant_exprt
algebraic_numbert::as_expr
()
const
18
{
19
if
(
coefficients
.size() == 2 &&
coefficients
.back().is_one())
20
{
21
// root of x - c
22
auto
c =
from_rational
(-
coefficients
.front());
23
c.type() =
real_typet
{};
24
return
c;
25
}
26
else
27
{
28
std::ostringstream oss;
29
oss << *
this
;
30
return
constant_exprt
{oss.str(),
real_typet
{}};
31
}
32
}
33
34
std::ostream &
operator<<
(std::ostream &out,
const
algebraic_numbert
&a)
35
{
36
out <<
"x ∈ ℝ.("
;
37
38
const
auto
&coefficients = a.
get_coefficients
();
39
40
bool
need_plus =
false
;
41
for
(std::size_t d = coefficients.size(); d > 0; --d)
42
{
43
if
(coefficients[d - 1].is_zero())
44
continue
;
45
if
(need_plus)
46
out <<
" + "
;
47
if
(d == 1)
48
out << coefficients[d - 1];
49
else
50
{
51
if
(!coefficients[d - 1].is_one())
52
out << coefficients[d - 1] <<
"*"
;
53
out <<
"x^"
<< d - 1;
54
}
55
need_plus =
true
;
56
}
57
58
if
(!need_plus)
59
out <<
"0"
;
60
out <<
" = 0)"
;
61
62
return
out;
63
}
operator<<
std::ostream & operator<<(std::ostream &out, const algebraic_numbert &a)
Definition
algebraic_number.cpp:34
algebraic_number.h
algebraic_numbert
Represents real numbers as roots (zeros) of a polynomial with rational coefficients.
Definition
algebraic_number.h:18
algebraic_numbert::as_expr
constant_exprt as_expr() const
Definition
algebraic_number.cpp:17
algebraic_numbert::coefficients
coefficientst coefficients
Definition
algebraic_number.h:22
algebraic_numbert::get_coefficients
const coefficientst & get_coefficients() const
Definition
algebraic_number.h:47
constant_exprt
A constant literal expression.
Definition
std_expr.h:2997
real_typet
Unbounded, signed real numbers.
Definition
mathematical_types.h:60
mathematical_types.h
Mathematical types.
from_rational
constant_exprt from_rational(const rationalt &a)
Definition
rational_tools.cpp:89
rational_tools.h
util
algebraic_number.cpp
Generated by
1.17.0