Skip to content
Snippets Groups Projects
Commit 0f88d81c authored by Michael Leuschel's avatar Michael Leuschel
Browse files

add float/reals manual

parent ba2dc4a1
Branches
Tags
No related merge requests found
Pipeline #99408 passed
%% Cell type:markdown id:85001897 tags:
# Reals and Floats in ProB
### Michael Leuschel
%% Cell type:markdown id:42473a5e tags:
## Classical B
In Atelier-B the following two types were added to the B language:
* REAL
* FLOAT
ProB treats these keywords as synonyms for a new base type.
The current representation in ProB are floating point numbers; but this
will probably change in the future, at least for the REAL type.
One can now also use literals in decimal point notation for REAL and FLOAT.
%% Cell type:code id:cf76baf3 tags:
``` prob
1.0
```
%% Output
$1.0$
1.0
%% Cell type:code id:941433ba tags:
``` prob
1.0 : REAL & 1.0 : FLOAT
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:markdown id:f7398e0e tags:
### Arithmetic Operators
The documentation of Atelier-B is not entirely consistent according to which
operators to use.
In ProB you can use the standard arithmetic operators also for
floats:
%% Cell type:code id:65a66ec9 tags:
``` prob
1.0 + 1.0
```
%% Output
$2.0$
2.0
%% Cell type:code id:35ce95d5 tags:
``` prob
2.0 * 2.0 < 2.1
```
%% Output
$\mathit{FALSE}$
FALSE
%% Cell type:code id:531aa72d tags:
``` prob
2.0 * 2.0 < 2.0 + 2.0
```
%% Output
$\mathit{FALSE}$
FALSE
%% Cell type:markdown id:9066aa50 tags:
You can control whether to allow arithmetic operators for reals
in ProB via the preference ```ALLOW_REALS```.
By default reals are allowed for classical B and disallowed for Event-B.
The only disadvantage of allowing reals is that the arithmetic operators
are overloaded, which may require stronger typing.
E.g., without ```x:INT``` you get an error that the type of x and y cannot be inferred, when reals are allowed:
%% Cell type:code id:528e647d tags:
``` prob
x:INT & x < y
```
%% Output
$\mathit{TRUE}$
**Solution:**
* $\mathit{x} = -1$
* $\mathit{y} = 0$
TRUE
Solution:
x = −1
y = 0
%% Cell type:markdown id:02b86510 tags:
### Constraint solving
Constraint solving and enumeration is very limited in ProB.
This will change in future.
Currently ProB will enumerate a few random values for unspecified reals,
and then stop with an enumeration warning.
%% Cell type:code id:9356ea2c tags:
``` prob
x:REAL
```
%% Output
$\mathit{TRUE}$
**Solution:**
* $\mathit{x} = 0.0$
TRUE
Solution:
x = 0.0
%% Cell type:code id:b6d8671d tags:
``` prob
x + 1.0 = 2.0
```
%% Output
$\mathit{TRUE}$
**Solution:**
* $\mathit{x} = 1.0$
TRUE
Solution:
x = 1.0
%% Cell type:markdown id:13388af0 tags:
### Other Operators
The standard library ```LibraryReals.def``` provides many functions
over reals as external functions.
These functions typically start with a capital R.
The functions are available in the REPL (aka console) but
one needs to import ```LibraryReals.def``` to use them in a B machine.
%% Cell type:code id:df6d2cd0 tags:
``` prob
RSQRT(2.0)
```
%% Output
$1.4142135623730951$
1.4142135623730951
%% Cell type:code id:d2daab50 tags:
``` prob
RSIN(RPI)
```
%% Output
$1.2246467991473532E-16$
1.2246467991473532E-16
%% Cell type:code id:481e4f68 tags:
``` prob
r=RPOW(RSIN(x),2.0)+RPOW(RCOS(x),2.0) & x=0.5
```
%% Output
$\mathit{TRUE}$
**Solution:**
* $\mathit{r} = 1.0$
* $\mathit{x} = 0.5$
TRUE
Solution:
r = 1.0
x = 0.5
%% Cell type:code id:bfd74a24 tags:
``` prob
r=RPOW(RSIN(x),2.0)+RPOW(RCOS(x),2.0) & x=10.5
```
%% Output
$\mathit{TRUE}$
**Solution:**
* $\mathit{r} = 1.0$
* $\mathit{x} = 10.5$
TRUE
Solution:
r = 1.0
x = 10.5
%% Cell type:code id:34ca2773 tags:
``` prob
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment