-**Ausdrücke** (Expressions): haben einen Wert, verändern den Zustand einer B Maschine *nicht*
-**Prädikate** (Predicates): sind wahr oder falsch, haben *keinen* Wert und verändern den Zustand der Maschine *nicht*
-**Anweisungen** (Substitutions, Statements): haben keinen Wert, können aber den Zustand einer Maschine verändern
Anweisungen sind zB `x := x+1` und können nur in Maschinen, nicht in Kontexten verwendet werden.
%% Cell type:markdown id: tags:
Dies ist ein Ausdruck in B:
%% Cell type:code id: tags:
``` prob
2+3
```
%% Output
$5$
5
%% Cell type:markdown id: tags:
Dies ist ein Prädikat in B:
%% Cell type:code id: tags:
``` prob
2>3
```
%% Output
$\mathit{FALSE}$
FALSE
%% Cell type:markdown id: tags:
B unterscheidet streng zwischen den Bool'schen Werten TRUE und FALSE und zwischen Prädikaten die wahr und falsch sind. Folgendes ist ein valider Ausdruck in B und beschreibt die Menge bestehend aus dem Bool'schen Wert `FALSE`:
%% Cell type:code id: tags:
``` prob
{FALSE}
```
%% Output
$\{\mathit{FALSE}\}$
{FALSE}
%% Cell type:markdown id: tags:
Folgendes ist **kein** valider Ausdruck in B:
%% Cell type:code id: tags:
``` prob
{bool(2>3)}
```
%% Output
$\{\mathit{FALSE}\}$
{FALSE}
%% Cell type:markdown id: tags:
## Syntax
Die meisten Operatoren in B können entweder als ASCII Zeichenkette oder als Unicode Symbol eingegeben werden.
Die Syntax von Event-B und klassischem B unterscheidet sich leicht.
In Rodin muss man Event-B Syntax verwenden; Jupyter verwendet momentan nur klassisches B.
Zum Beispiel benutzt Rodin `^` zum Potenzieren, während man im klassische B `**` verwendet:
%% Cell type:code id: tags:
``` prob
2**100
```
%% Output
$1267650600228229401496703205376$
1267650600228229401496703205376
%% Cell type:markdown id: tags:
In Rodin wird `**` für das kartesische Produkt verwendet, im klassischen B verwendet man dafür `*`.
Wir laden jetzt ein leeres Event-B Modell um den Parser in den Event-B Modus zu wechseln.
Man kann auch das Kommando ```:language event_b``` verwenden um den Parser umzustellen.
Mit ```:language classical_b``` kann man zurück zum normalen B Parser wechseln.
%% Cell type:code id: tags:
``` prob
:load models/empty_ctx.eventb
```
%% Output
Loaded machine: empty_ctx
%% Cell type:code id: tags:
``` prob
2^100
```
%% Output
$1267650600228229401496703205376$
1267650600228229401496703205376
%% Cell type:markdown id: tags:
## Semantische Grundlage von B
* Arithmetik (ganze Zahlen) ÷ + − ≤
* Prädikatenlogik ⇒ ∀
* Mengentheorie ∩ ∪ ⊆ ∈
* Paare
* Relationen,Funktionen, Sequenzen/Folgen, Bäume
%% Cell type:markdown id: tags:
## Aussagenlogik
B unterstützt folgende Junktoren der Aussagenlogik:
Junktor | ASCII | Unicode
-------|-------|-----
Konjunktion | & | ∧
Disjunktion | or | ∨
Negation | not | ¬
Implikation | => | ⇒
Äquivalenz | <=> | ⇔
Mit `:prettyprint` kann man sich die Unicode Version einer Formel ausgeben lassen:
* in Rodin/Event-B haben Konjunktion und Disjunktion die gleiche Priorität und dürfen nicht ohne Klammerung gemischt werden. In klassischem B schon.
* Das gleiche gilt für => und <=>.
* In Rodin ist auch keine Assoziativität für => oder <=> definiert worden. Man darf diese Operatoren also auch nicht untereinander ohne Klammern mischen.
%% Cell type:code id: tags:
``` prob
2>1 or 2>3 & 3>4
```
%% Output
de.prob.animator.domainobjects.EvaluationException: Could not parse formula:
Parsing predicate failed because: Operator: ∨ is not compatible with: ∧, parentheses are required
Operator: ∨ is not compatible with: ∧, parentheses are required
Parsing expression failed because: Operator: ∨ is not compatible with: ∧, parentheses are required
Operator: ∨ is not compatible with: ∧, parentheses are required
Parsing substitution failed because: Unknown operator: (expected to find an assignment operator)
Unknown operator: (expected to find an assignment operator)
Code: 2>1 or 2>3 & 3>4
Unicode translation: 2>1 ∨ 2>3 ∧ 3>4
%% Cell type:markdown id: tags:
## Prädikate
In Event-B gibt es die Aussagen true (⊤) und false (⊥) (nicht verwechseln mit den Bool'schen Datenwerten TRUE und FALSE). Im klassichen B gibt es diese beiden Aussagen nicht (wobei ProB `btrue` und `bfalse` akzeptiert).
%% Cell type:code id: tags:
``` prob
true or false
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:markdown id: tags:
Wahrheitswerte können über Prädikate hergestellt werden:
* ein n-äres Pradikat bekommt n Datenwerte und bildet diese auf einen Wahrheitswert ab
Für alle Datentypen gibt es die binären Pradikate = und ≠ (wobei gilt x ≠ y ⇔ ¬(x=y)).
Für Zahlen gibt es die mathematischen Vergleichsoperatoren. Für Mengen werden noch weitere Prädikate hinzukommen.
%% Cell type:code id: tags:
``` prob
2 = 3-1
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:code id: tags:
``` prob
3 ≠ 3+1
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:code id: tags:
``` prob
4 >= 2+2
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:markdown id: tags:
## Quantoren
In B gibt es zwei Quantoren die neue Variablen einführen:
* den Existenzquantor (mindestens eins)
- #x.(P) ∃x.(P)
* den Allquantor/Universalquantor (alle / jeder)
- !x.(P => Q) ∀(x).(P ⇒ Q)
%% Cell type:code id: tags:
``` prob
∃x .( x>2 )
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:code id: tags:
``` prob
∀x .( x>2 ⇒ x>3 )
```
%% Output
$\mathit{FALSE}$
**Solution:**
* $\mathit{x} = 3$
FALSE
Solution:
x = 3
%% Cell type:code id: tags:
``` prob
∀x .( x>2 & x < 100 ⇒ ∃y.(x=y+y))
```
%% Output
$\mathit{FALSE}$
**Solution:**
* $\mathit{x} = 3$
FALSE
Solution:
x = 3
%% Cell type:code id: tags:
``` prob
∀x .( x>2 & x < 100 ⇒ ∃y.(x=y+y) or ∃y.(x=y+y+1))
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:markdown id: tags:
### Typisierung bei Quantoren
B basiert auf typisierter Logik
* Bei Quantoren, zum Beispiel, müssen die neuen Variablen typisiert werden
- ∃x.(2>3) ist nicht erlaubt
Generell: für ∃x.(P) und ∀(x).(P ⇒ Q) muss P den Typen von x bestimmbar machen
%% Cell type:markdown id: tags:
## Arithmetik
B bietet Arithmetik über *ganzen* Zahlen an.
Folgende Zahlenmengen sind vordefiniert:
* INT, ℤ
* NAT = {x|x≥0}, ℕ
* NAT1= {x|x≥1}, ℕ1
In Atelier-B (klassisches B für die Softwareentwicklung, nicht in Rodin) wird zwischen mathematischen und implementierbaren Zahlen unterschieden:
Man kann Mengen durch **explizite Aufzählung** (Enumeration, set extension auf Englisch) definieren:
%% Cell type:code id: tags:
``` prob
{1,1+1,2,2+2,3,4}
```
%% Output
$\{1,2,3,4\}$
{1,2,3,4}
%% Cell type:markdown id: tags:
Mengen können auch mit Hilfe eines Prädikats definiert werden (set comprehension auf Englisch). Die Syntaxform ist `{x | P}`.
%% Cell type:code id: tags:
``` prob
{x | x>0 & x<5}
```
%% Output
$\{1,2,3,4\}$
{1,2,3,4}
%% Cell type:code id: tags:
``` prob
{x|x>2+2}
```
%% Output
$\{\mathit{x}\mid \mathit{x} > 4\}$
{x∣x > 4}
%% Cell type:markdown id: tags:
Eine Menge an Zahlen kann auch mit der Intervallnotation ``a..b`` definiert werden:
%% Cell type:code id: tags:
``` prob
1..4
```
%% Output
$\{1,2,3,4\}$
{1,2,3,4}
%% Cell type:markdown id: tags:
Die Kardinalität (Mächtigkeit) einer endlichen Menge kann mit dem card Operator bestimmt werden:
%% Cell type:code id: tags:
``` prob
card({1,1+1,2,2+2,3,4})
```
%% Output
$4$
4
%% Cell type:code id: tags:
``` prob
card({x|x>2})
```
%% Output
:eval: NOT-WELL-DEFINED:
card applied to very large set, cardinality not representable in ProB: closure([x],[integer],b(greater(b(identifier(...),integer,[...]),b(value(...),integer,[...])),pred,[nodeid(none)]))