Skip to content

Commit

Permalink
introduce zero_expr() and one_expr() for number types
Browse files Browse the repository at this point in the history
This adds ::zero_expr() and ::one_expr() for integers, natural numbers,
rationals and reals.
  • Loading branch information
kroening committed Sep 5, 2024
1 parent 27b845c commit cd513b5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/util/mathematical_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Author: Daniel Kroening, kroening@kroening.com

#include "mathematical_types.h"

#include "std_expr.h"

/// Returns true if the type is a rational, real, integer, natural, complex,
/// unsignedbv, signedbv, floatbv or fixedbv.
bool is_number(const typet &type)
Expand All @@ -21,3 +23,43 @@ bool is_number(const typet &type)
id == ID_natural || id == ID_complex || id == ID_unsignedbv ||
id == ID_signedbv || id == ID_floatbv || id == ID_fixedbv;
}

constant_exprt integer_typet::zero_expr() const
{
return constant_exprt{ID_0, *this};
}

constant_exprt integer_typet::one_expr() const
{
return constant_exprt{ID_1, *this};
}

constant_exprt natural_typet::zero_expr() const
{
return constant_exprt{ID_0, *this};
}

constant_exprt natural_typet::one_expr() const
{
return constant_exprt{ID_1, *this};
}

constant_exprt rational_typet::zero_expr() const
{
return constant_exprt{ID_0, *this};
}

constant_exprt rational_typet::one_expr() const
{
return constant_exprt{ID_1, *this};
}

constant_exprt real_typet::zero_expr() const
{
return constant_exprt{ID_0, *this};
}

constant_exprt real_typet::one_expr() const
{
return constant_exprt{ID_1, *this};
}
14 changes: 14 additions & 0 deletions src/util/mathematical_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ Author: Daniel Kroening, kroening@kroening.com
#include "invariant.h"
#include "type.h"

class constant_exprt;

/// Unbounded, signed integers (mathematical integers, not bitvectors)
class integer_typet : public typet
{
public:
integer_typet() : typet(ID_integer)
{
}

constant_exprt zero_expr() const;
constant_exprt one_expr() const;
};

/// Natural numbers including zero (mathematical integers, not bitvectors)
Expand All @@ -33,6 +38,9 @@ class natural_typet : public typet
natural_typet() : typet(ID_natural)
{
}

constant_exprt zero_expr() const;
constant_exprt one_expr() const;
};

/// Unbounded, signed rational numbers
Expand All @@ -42,6 +50,9 @@ class rational_typet : public typet
rational_typet() : typet(ID_rational)
{
}

constant_exprt zero_expr() const;
constant_exprt one_expr() const;
};

/// Unbounded, signed real numbers
Expand All @@ -51,6 +62,9 @@ class real_typet : public typet
real_typet() : typet(ID_real)
{
}

constant_exprt zero_expr() const;
constant_exprt one_expr() const;
};

/// A type for mathematical functions (do not confuse with functions/methods
Expand Down

0 comments on commit cd513b5

Please sign in to comment.