cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
mathematical_types.h
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Mathematical types
4
5
Author: Daniel Kroening, kroening@kroening.com
6
Maria Svorenova, maria.svorenova@diffblue.com
7
8
\*******************************************************************/
9
12
13
#ifndef CPROVER_UTIL_MATHEMATICAL_TYPES_H
14
#define CPROVER_UTIL_MATHEMATICAL_TYPES_H
15
16
#include "
expr_cast.h
"
// IWYU pragma: keep
17
#include "
invariant.h
"
18
#include "
type.h
"
19
20
class
constant_exprt
;
21
23
class
integer_typet
:
public
typet
24
{
25
public
:
26
integer_typet
() :
typet
(ID_integer)
27
{
28
}
29
30
constant_exprt
zero_expr
()
const
;
31
constant_exprt
one_expr
()
const
;
32
};
33
35
class
natural_typet
:
public
typet
36
{
37
public
:
38
natural_typet
() :
typet
(ID_natural)
39
{
40
}
41
42
constant_exprt
zero_expr
()
const
;
43
constant_exprt
one_expr
()
const
;
44
};
45
47
class
rational_typet
:
public
typet
48
{
49
public
:
50
rational_typet
() :
typet
(ID_rational)
51
{
52
}
53
54
constant_exprt
zero_expr
()
const
;
55
constant_exprt
one_expr
()
const
;
56
};
57
59
class
real_typet
:
public
typet
60
{
61
public
:
62
real_typet
() :
typet
(ID_real)
63
{
64
}
65
66
constant_exprt
zero_expr
()
const
;
67
constant_exprt
one_expr
()
const
;
68
};
69
72
class
mathematical_function_typet
:
public
type_with_subtypest
73
{
74
public
:
75
// the domain of the function is composed of zero, one, or
76
// many variables, given by their type
77
using
domaint
= std::vector<typet>;
78
79
mathematical_function_typet
(
const
domaint
&_domain,
const
typet
&_codomain)
80
:
type_with_subtypest
(
81
ID_mathematical_function,
82
{
type_with_subtypest
(
irep_idt
(), _domain), _codomain})
83
{
84
}
85
86
domaint
&
domain
()
87
{
88
return
(
domaint
&)
to_type_with_subtypes
(
subtypes
()[0]).
subtypes
();
89
}
90
91
const
domaint
&
domain
()
const
92
{
93
return
(
const
domaint
&)
to_type_with_subtypes
(
subtypes
()[0]).
subtypes
();
94
}
95
96
void
add_variable
(
const
typet
&_type)
97
{
98
domain
().push_back(_type);
99
}
100
103
typet
&
codomain
()
104
{
105
return
subtypes
()[1];
106
}
107
109
const
typet
&
codomain
()
const
110
{
111
return
subtypes
()[1];
112
}
113
};
114
118
template
<>
119
inline
bool
can_cast_type<mathematical_function_typet>
(
const
typet
&type)
120
{
121
return
type.
id
() == ID_mathematical_function;
122
}
123
132
inline
const
mathematical_function_typet
&
133
to_mathematical_function_type
(
const
typet
&type)
134
{
135
PRECONDITION
(
can_cast_type<mathematical_function_typet>
(type));
136
return
static_cast<
const
mathematical_function_typet
&
>
(type);
137
}
138
140
inline
mathematical_function_typet
&
to_mathematical_function_type
(
typet
&type)
141
{
142
PRECONDITION
(
can_cast_type<mathematical_function_typet>
(type));
143
return
static_cast<
mathematical_function_typet
&
>
(type);
144
}
145
146
bool
is_number
(
const
typet
&type);
147
148
#endif
// CPROVER_UTIL_MATHEMATICAL_TYPES_H
constant_exprt
A constant literal expression.
Definition
std_expr.h:2997
integer_typet::one_expr
constant_exprt one_expr() const
Definition
mathematical_types.cpp:32
integer_typet::zero_expr
constant_exprt zero_expr() const
Definition
mathematical_types.cpp:27
integer_typet::integer_typet
integer_typet()
Definition
mathematical_types.h:26
irept::id
const irep_idt & id() const
Definition
irep.h:388
mathematical_function_typet
A type for mathematical functions (do not confuse with functions/methods in code).
Definition
mathematical_types.h:73
mathematical_function_typet::domain
const domaint & domain() const
Definition
mathematical_types.h:91
mathematical_function_typet::codomain
const typet & codomain() const
Return the codomain, i.e., the set of values that the function maps to (the "target").
Definition
mathematical_types.h:109
mathematical_function_typet::codomain
typet & codomain()
Return the codomain, i.e., the set of values that the function maps to (the "target").
Definition
mathematical_types.h:103
mathematical_function_typet::add_variable
void add_variable(const typet &_type)
Definition
mathematical_types.h:96
mathematical_function_typet::domain
domaint & domain()
Definition
mathematical_types.h:86
mathematical_function_typet::mathematical_function_typet
mathematical_function_typet(const domaint &_domain, const typet &_codomain)
Definition
mathematical_types.h:79
mathematical_function_typet::domaint
std::vector< typet > domaint
Definition
mathematical_types.h:77
natural_typet::zero_expr
constant_exprt zero_expr() const
Definition
mathematical_types.cpp:37
natural_typet::natural_typet
natural_typet()
Definition
mathematical_types.h:38
natural_typet::one_expr
constant_exprt one_expr() const
Definition
mathematical_types.cpp:42
rational_typet::zero_expr
constant_exprt zero_expr() const
Definition
mathematical_types.cpp:47
rational_typet::one_expr
constant_exprt one_expr() const
Definition
mathematical_types.cpp:52
rational_typet::rational_typet
rational_typet()
Definition
mathematical_types.h:50
real_typet::zero_expr
constant_exprt zero_expr() const
Definition
mathematical_types.cpp:57
real_typet::real_typet
real_typet()
Definition
mathematical_types.h:62
real_typet::one_expr
constant_exprt one_expr() const
Definition
mathematical_types.cpp:62
type_with_subtypest::type_with_subtypest
type_with_subtypest(const irep_idt &_id, const subtypest &_subtypes)
Definition
type.h:226
type_with_subtypest::subtypes
subtypest & subtypes()
Definition
type.h:237
typet
The type of an expression, extends irept.
Definition
type.h:29
typet::typet
typet()
Definition
type.h:31
expr_cast.h
Templated functions to cast to specific exprt-derived classes.
can_cast_type
bool can_cast_type(const typet &base)
Check whether a reference to a generic typet is of a specific derived class.
is_number
bool is_number(const typet &type)
Returns true if the type is a rational, real, integer, natural, complex, unsignedbv,...
Definition
mathematical_types.cpp:19
to_mathematical_function_type
const mathematical_function_typet & to_mathematical_function_type(const typet &type)
Cast a typet to a mathematical_function_typet.
Definition
mathematical_types.h:133
can_cast_type< mathematical_function_typet >
bool can_cast_type< mathematical_function_typet >(const typet &type)
Check whether a reference to a typet is a mathematical_function_typet.
Definition
mathematical_types.h:119
invariant.h
PRECONDITION
#define PRECONDITION(CONDITION)
Definition
invariant.h:463
type.h
Defines typet, type_with_subtypet and type_with_subtypest.
to_type_with_subtypes
const type_with_subtypest & to_type_with_subtypes(const typet &type)
Definition
type.h:252
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
util
mathematical_types.h
Generated by
1.17.0