17#ifndef MCRL2_LPS_PROBABILISTIC_DATA_EXPRESSION_H
18#define MCRL2_LPS_PROBABILISTIC_DATA_EXPRESSION_H
33#ifdef MCRL2_ENABLE_MACHINENUMBERS
34 inline utilities::big_natural_number make_bnn_nat(
const data::data_expression& n)
36 utilities::big_natural_number result;
37 data::data_expression
const* n_walker=&n;
43 std::size_t v=atermpp::down_cast<data::machine_number>(
data::sort_nat::arg(*n_walker)).value();
52 inline utilities::big_natural_number make_bnn_pos(
const data::data_expression& n)
54 utilities::big_natural_number result;
55 data::data_expression
const* n_walker=&n;
66 inline const data::data_expression make_nat_bnn(
const utilities::big_natural_number& b)
73 data::data_expression result;
74 data::data_expression word;
87 inline const data::data_expression make_pos_bnn(
const utilities::big_natural_number& b)
92 data::data_expression result;
93 data::data_expression word;
114 const std::size_t temp=x; x=y; y=temp;
117 std::size_t remainder=y % x;
130 enumerator=enumerator/gcd;
131 denominator=denominator/gcd;
164 return std::stoul(s);
167#ifdef MCRL2_ENABLE_MACHINENUMBERS
174 bool negate_first=
false;
175 bool negate_second=is_minus;
176 bool second_is_negative=
false;
183 negate_second=!negate_second;
184 second_is_negative=
true;
193 std::size_t n_this_enumerator=atermpp::down_cast<data::machine_number>(
data::sort_nat::arg(this_enumerator_arg)).value();
194 std::size_t n_other_enumerator=atermpp::down_cast<data::machine_number>(
data::sort_nat::arg(other_enumerator_arg)).value();
195 std::size_t n_this_denominator=atermpp::down_cast<data::machine_number>(
data::sort_pos::arg(this_denominator)).value();
196 std::size_t n_other_denominator=atermpp::down_cast<data::machine_number>(
data::sort_pos::arg(other_denominator)).value();
201 std::size_t n_this_denominator_with_gcd=n_this_denominator;
202 n_this_denominator = n_this_denominator / gcd;
203 n_other_denominator = n_other_denominator / gcd;
205 std::size_t left_carry=0;
206 std::size_t right_carry=0;
207 std::size_t denominator_carry=0;
213 std::size_t new_enumerator_carry=0;
214 std::size_t new_enumerator=0;
215 bool result_is_negative=negate_first;
216 if (negate_first==negate_second)
220 else if (left_result>=right_result)
222 new_enumerator=left_result-right_result;
226 new_enumerator=right_result-left_result;
227 result_is_negative=!result_is_negative;
229 if (left_carry==0 && right_carry==0 && denominator_carry==0 && new_enumerator_carry==0)
236 if (result_is_negative)
252 const utilities::big_natural_number bnn_this_enumerator=
254 detail::make_bnn_pos(this_enumerator_arg):
255 detail::make_bnn_nat(this_enumerator_arg);
256 const utilities::big_natural_number bnn_other_enumerator=
258 detail::make_bnn_pos(other_enumerator_arg):
259 detail::make_bnn_nat(other_enumerator_arg);
260 const utilities::big_natural_number bnn_this_denominator=detail::make_bnn_pos(this_denominator);
261 const utilities::big_natural_number bnn_other_denominator=detail::make_bnn_pos(other_denominator);
262 const utilities::probabilistic_arbitrary_precision_fraction left_arg(bnn_this_enumerator, bnn_this_denominator);
263 const utilities::probabilistic_arbitrary_precision_fraction right_arg(bnn_other_enumerator, bnn_other_denominator);
264 data::data_expression result1, result2;
265 if (negate_first==negate_second)
267 utilities::probabilistic_arbitrary_precision_fraction result=left_arg+right_arg;
268 result2 = detail::make_pos_bnn(result.denominator());
271 result1 = detail::make_pos_bnn(result.enumerator());
276 result1 = detail::make_nat_bnn(result.enumerator());
280 else if (left_arg>right_arg)
282 utilities::probabilistic_arbitrary_precision_fraction result=left_arg-right_arg;
283 result2 = detail::make_pos_bnn(result.denominator());
286 result1 = detail::make_pos_bnn(result.enumerator());
291 result1 = detail::make_nat_bnn(result.enumerator());
297 utilities::probabilistic_arbitrary_precision_fraction result=right_arg-left_arg;
298 result2 = detail::make_pos_bnn(result.denominator());
301 result1 = detail::make_nat_bnn(result.enumerator());
306 result1 = detail::make_pos_bnn(result.enumerator());
322 using namespace data;
330 using namespace data;
353 assert(denominator!=0);
363 assert(enumerator.size() <= denominator.size());
373#ifdef MCRL2_ENABLE_MACHINENUMBERS
389 throw mcrl2::runtime_error(
"Equality between fractions does not rewrite to true or false: " +
pp(result) +
".");
404#ifdef MCRL2_ENABLE_MACHINENUMBERS
409 bool negate_outcome=
false;
439 std::size_t n_this_enumerator=atermpp::down_cast<data::machine_number>(
data::sort_nat::arg(this_enumerator_arg)).value();
440 std::size_t n_other_enumerator=atermpp::down_cast<data::machine_number>(
data::sort_nat::arg(other_enumerator_arg)).value();
441 std::size_t n_this_denominator=atermpp::down_cast<data::machine_number>(
data::sort_pos::arg(this_denominator)).value();
442 std::size_t n_other_denominator=atermpp::down_cast<data::machine_number>(
data::sort_pos::arg(other_denominator)).value();
443 std::size_t left_carry=0;
444 std::size_t right_carry=0;
447 if (left_carry<right_carry ||
448 (left_carry==right_carry && left_result<right_result))
451 return !negate_outcome;
456 return negate_outcome;
467 bnn_this_enumerator.
multiply(bnn_other_denominator, bnn_left_result, bnn_buffer);
468 bnn_other_enumerator.
multiply(bnn_this_denominator, bnn_right_result, bnn_buffer);
469 if (bnn_left_result<bnn_right_result)
471 return !negate_outcome;
475 return negate_outcome;
487 throw mcrl2::runtime_error(
"Comparison of fraction does not rewrite to true or false: " +
pp(result) +
".");
502 return other.operator<(*this);
509 return other.operator<=(*this);
517#ifdef MCRL2_ENABLE_MACHINENUMBERS
518 return calculate_plus_minus(other,
false);
529#ifdef MCRL2_ENABLE_MACHINENUMBERS
530 return calculate_plus_minus(other,
true);
549 return out << static_cast<data::data_expression>(x);
564 hash<atermpp::aterm> aterm_hasher;
565 return aterm_hasher(p);
This file contains a class big_natural_number that stores big positive numbers of arbitrary size....
size_type size() const
Returns the number of arguments of this term.
data_expression()
\brief Default constructor X3.
sort_expression sort() const
Returns the sort of the data expression.
Rewriter that operates on data expressions.
void add_sort(const basic_sort &s)
Adds a sort to this specification.
This class contains labels for probabilistic transistions, consisting of a numerator and a denumerato...
static const data::rewriter & m_rewriter()
static probabilistic_data_expression one()
Constant one.
probabilistic_data_expression operator+(const probabilistic_data_expression &other) const
Standard addition operator. Note that the expression is not evaluated. For this the rewriter has to b...
probabilistic_data_expression(const data::data_expression &d)
Construct a probabilistic_data_expression from a data_expression, which must be of sort real.
bool operator==(const probabilistic_data_expression &other) const
probabilistic_data_expression(std::size_t enumerator, std::size_t denominator)
bool operator!=(const probabilistic_data_expression &other) const
bool operator>=(const probabilistic_data_expression &other) const
bool operator<(const probabilistic_data_expression &other) const
bool operator<=(const probabilistic_data_expression &other) const
bool operator>(const probabilistic_data_expression &other) const
probabilistic_data_expression(const std::string &enumerator, const std::string &denominator)
static std::size_t to_number_t(const std::string &s)
probabilistic_data_expression operator-(const probabilistic_data_expression &other) const
Standard subtraction operator.
static data::data_specification data_specification_with_real()
probabilistic_data_expression()
static probabilistic_data_expression zero()
Constant zero.
Standard exception class for reporting runtime errors.
void multiply(const big_natural_number &other, big_natural_number &result, big_natural_number &calculation_buffer_for_multiplicand) const
const function_symbol & false_()
Constructor for function symbol false.
const function_symbol & true_()
Constructor for function symbol true.
const data_expression & arg(const data_expression &e)
Function for projecting out argument. arg from an application.
void make_cneg(data_expression &result, const data_expression &arg0)
Make an application of function symbol @cNeg.
bool is_cneg_application(const atermpp::aterm &e)
Recogniser for application of @cNeg.
bool is_cint_application(const atermpp::aterm &e)
Recogniser for application of @cInt.
const function_symbol & cint()
Constructor for function symbol @cInt.
void make_cint(data_expression &result, const data_expression &arg0)
Make an application of function symbol @cInt.
const basic_sort & int_()
Constructor for sort expression Int.
const basic_sort & nat()
Constructor for sort expression Nat.
void make_most_significant_digit_nat(data_expression &result, const data_expression &arg0)
Make an application of function symbol @most_significant_digitNat.
const data_expression & arg2(const data_expression &e)
Function for projecting out argument. arg2 from an application.
const data_expression & arg1(const data_expression &e)
Function for projecting out argument. arg1 from an application.
void make_concat_digit(data_expression &result, const data_expression &arg0, const data_expression &arg1)
Make an application of function symbol @concat_digit.
bool is_concat_digit_application(const atermpp::aterm &e)
Recogniser for application of @concat_digit.
const data_expression & arg(const data_expression &e)
Function for projecting out argument. arg from an application.
bool is_most_significant_digit_nat_application(const atermpp::aterm &e)
Recogniser for application of @most_significant_digitNat.
const data_expression & arg(const data_expression &e)
Function for projecting out argument. arg from an application.
void make_most_significant_digit(data_expression &result, const data_expression &arg0)
Make an application of function symbol @most_significant_digit.
const data_expression & arg1(const data_expression &e)
Function for projecting out argument. arg1 from an application.
const data_expression & arg2(const data_expression &e)
Function for projecting out argument. arg2 from an application.
bool is_most_significant_digit_application(const atermpp::aterm &e)
Recogniser for application of @most_significant_digit.
bool is_concat_digit_application(const atermpp::aterm &e)
Recogniser for application of @concat_digit.
const basic_sort & pos()
Constructor for sort expression Pos.
void make_concat_digit(data_expression &result, const data_expression &arg0, const data_expression &arg1)
Make an application of function symbol @concat_digit.
function_symbol plus(const sort_expression &s0, const sort_expression &s1)
const function_symbol & creal()
Constructor for function symbol @cReal.
data_expression & real_one()
data_expression & real_zero()
NUMERIC_TYPE value(const data_expression &r, typename std::enable_if< std::is_floating_point< NUMERIC_TYPE >::value >::type *=nullptr)
Yields the real value of a data expression.
function_symbol minus(const sort_expression &s0, const sort_expression &s1)
const basic_sort & real_()
Constructor for sort expression Real.
const data_expression & right(const data_expression &e)
Function for projecting out argument. right from an application.
const data_expression & left(const data_expression &e)
Function for projecting out argument. left from an application.
void make_creal(data_expression &result, const data_expression &arg0, const data_expression &arg1)
Make an application of function symbol @cReal.
void make_machine_number(atermpp::aterm &t, size_t n)
function_symbol less(const sort_expression &s)
Constructor for function symbol <.
function_symbol equal_to(const sort_expression &s)
Constructor for function symbol ==.
void remove_common_divisor(std::size_t &enumerator, std::size_t &denominator)
std::size_t greatest_common_divisor(std::size_t x, std::size_t y)
std::string pp(const action_summand &x)
std::ostream & operator<<(std::ostream &out, const action_summand &x)
void remove_common_divisor(std::size_t &p, std::size_t &q)
std::size_t multiply_single_number(const std::size_t n1, const std::size_t n2, std::size_t &multiplication_carry)
std::size_t add_single_number(const std::size_t n1, const std::size_t n2, std::size_t &carry)
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
This file contains a class that contains labels for probabilistic transitions. These consist of a 64 ...
Contains a number of auxiliary functions to recognize reals.
std::size_t operator()(const mcrl2::lps::probabilistic_data_expression &p) const