Skip to content
Snippets Groups Projects
Commit b0b7e346 authored by Aron Strandberg's avatar Aron Strandberg
Browse files

update math eqs

parent 3c32ced1
No related branches found
No related tags found
No related merge requests found
...@@ -199,8 +199,9 @@ An expression can be either a ...@@ -199,8 +199,9 @@ An expression can be either a
- f, function - f, function
Function sequence Function sequence
```math
$<f, σ>⇓σ'$ <f, σ>⇓σ'
```
```rust ```rust
fn main() { fn main() {
...@@ -210,8 +211,9 @@ fn main() { ...@@ -210,8 +211,9 @@ fn main() {
The function call moves the current state, $σ$ to the new derived state $σ'$ in the function, test()'s context. A function can evaluate void (none), i32 and bool. The function call moves the current state, $σ$ to the new derived state $σ'$ in the function, test()'s context. A function can evaluate void (none), i32 and bool.
Command sequence Command sequence
```math
$\frac{<c1,σ> ⇓ σ' <c2,σ'> ⇓ σ''}{<c1;c2,σ> ⇓ σ''}$ \frac{<c1,σ> ⇓ σ' <c2,σ'> ⇓ σ''}{<c1;c2,σ> ⇓ σ''}
```
```rust ```rust
let x : i32 = 2; let x : i32 = 2;
...@@ -220,8 +222,9 @@ test(); ...@@ -220,8 +222,9 @@ test();
A sequence is a composition of commands where the first command is first executed then the second command. Otherwise the intermediate step, $σ'$ would be lost. A sequence is a composition of commands where the first command is first executed then the second command. Otherwise the intermediate step, $σ'$ would be lost.
Operands for lhs, rhs arithmetic expressions Operands for lhs, rhs arithmetic expressions
```math
$\frac{<e1,σ> ⇓ n1 <e2, σ> ⇓ n2}{<e1 + e2, σ> ⇓ n1 \text{ } plus \text{ } n2}$ \frac{<e1,σ> ⇓ n1 <e2, σ> ⇓ n2}{<e1 + e2, σ> ⇓ n1 \text{ } plus \text{ } n2}
```
plus is addition as implemented in the computer. Other arithmetic operands imlemented are plus is addition as implemented in the computer. Other arithmetic operands imlemented are
- -, minus - -, minus
...@@ -238,8 +241,9 @@ plus is addition as implemented in the computer. Other arithmetic operands imlem ...@@ -238,8 +241,9 @@ plus is addition as implemented in the computer. Other arithmetic operands imlem
``` ```
Operands for lhs, rhs boolean expressions Operands for lhs, rhs boolean expressions
```math
$\frac{<e1,σ> ⇓ b1 <e2, σ> ⇓ b2}{<e1 == e2, σ> ⇓ b1 \text{ } equal \text{ } b2}$ \frac{<e1,σ> ⇓ b1 <e2, σ> ⇓ b2}{<e1 == e2, σ> ⇓ b1 \text{ } equal \text{ } b2}
```
how equal is evaluated is up to the computer. Other boolean operands implemented are how equal is evaluated is up to the computer. Other boolean operands implemented are
...@@ -254,24 +258,29 @@ how equal is evaluated is up to the computer. Other boolean operands implemented ...@@ -254,24 +258,29 @@ how equal is evaluated is up to the computer. Other boolean operands implemented
If true If true
```math
$\frac{<b, σ> ⇓ true <c1, σ> ⇓ σ'}{<if \text{ } b \text{ } then \text{ } c1> ⇓ σ}$ \frac{<b, σ> ⇓ true <c1, σ> ⇓ σ'}{<if \text{ } b \text{ } then \text{ } c1> ⇓ σ}
```
then the state, $σ$ will change immediately to $σ'$. then the state, $σ$ will change immediately to $σ'$.
If false If false
```math
$\frac{<b, σ> ⇓ false <c1, σ> ⇓ σ''}{<if \text{ } b \text{ } then \text{ } c1> ⇓ σ}$ \frac{<b, σ> ⇓ false <c1, σ> ⇓ σ''}{<if \text{ } b \text{ } then \text{ } c1> ⇓ σ}
```
the state, $σ'$ will be changed at the second command to $σ''$. the state, $σ'$ will be changed at the second command to $σ''$.
While false While false
```math
$\frac{<b,σ> ⇓ false}{<while \text{ } b \text{ } do \text{ } c,σ> ⇓ σ}$ \frac{<b,σ> ⇓ false}{<while \text{ } b \text{ } do \text{ } c,σ> ⇓ σ}
```
While true While true
```math
\frac{<b, σ> ⇓ true <c,σ> ⇓ σ' <while \text{ } b \text{ } do \text{ } c, σ'> ⇓ σ''}{<while \text{ } b \text{ } do \text{ } c,σ> ⇓ σ''}
```
$\frac{<b, σ> ⇓ true <c,σ> ⇓ σ' <while \text{ } b \text{ } do \text{ } c, σ'> ⇓ σ''}{<while \text{ } b \text{ } do \text{ } c,σ> ⇓ σ''}$
```rust ```rust
let a : i32 = 0; let a : i32 = 0;
while a < 5 { while a < 5 {
...@@ -282,8 +291,9 @@ while a < 5 { ...@@ -282,8 +291,9 @@ while a < 5 {
then $σ'$ is the result of the current state, $σ$ and the last state $σ''$ is the result of $σ'$. then $σ'$ is the result of the current state, $σ$ and the last state $σ''$ is the result of $σ'$.
Let assignment expression Let assignment expression
```math
$\frac{<x, σ><let \text{ } x:=e, σ>⇓σ'}{<let \text{ } x := e, σ> ⇓ σ[x := e]}$ \frac{<x, σ>⇓<let \text{ } x:=e, σ>⇓σ'}{<let \text{ } x := e, σ> ⇓ σ[x := e]}
```
```rust ```rust
let a : i32 = 1; let a : i32 = 1;
let b : bool = true; let b : bool = true;
...@@ -292,8 +302,9 @@ let c : i32 = test(); // c will be assigned whaterver test() returns ...@@ -292,8 +302,9 @@ let c : i32 = test(); // c will be assigned whaterver test() returns
For let commands, if the variable is already declared the state $σ$ will be changed to the one of the second command, state $σ'$, the variable will be lost. Otherwise the variable will be assigned to the state, $σ$. For let commands, if the variable is already declared the state $σ$ will be changed to the one of the second command, state $σ'$, the variable will be lost. Otherwise the variable will be assigned to the state, $σ$.
Assignment expression Assignment expression
```math
$\frac{}{<x := e, σ> ⇓ σ[x := e]}$ \frac{}{<x := e, σ> ⇓ σ[x := e]}
```
```rust ```rust
x = 1; x = 1;
...@@ -307,8 +318,9 @@ For assignment, when the variable is assigned to a number, boolean or function t ...@@ -307,8 +318,9 @@ For assignment, when the variable is assigned to a number, boolean or function t
Return Return
```math
$\frac{<f, σ>⇓σ}{<return : e, σ> ⇓ σ[return : e]}$ \frac{<f, σ>⇓σ}{<return : e, σ> ⇓ σ[return : e]}
```
```rust ```rust
fn main() -> i32 { fn main() -> i32 {
...@@ -351,15 +363,17 @@ Types are now defined as ...@@ -351,15 +363,17 @@ Types are now defined as
Command sequence Command sequence
```math
$\frac{<c1,σ> ⇓ σ' <c2,σ'> ⇓ σ''}{<c1;c2,σ> ⇓ σ''}$ \frac{<c1,σ> ⇓ σ' <c2,σ'> ⇓ σ''}{<c1;c2,σ> ⇓ σ''}
```
as described in the SOS rules of the interpreter. as described in the SOS rules of the interpreter.
Operands for i32 types Operands for i32 types
```math
$\frac{<e1,σ> ⇓ i32 <e2, σ> ⇓ i32}{<e1 + e2, σ> ⇓ i32}$ \frac{<e1,σ> ⇓ i32 <e2, σ> ⇓ i32}{<e1 + e2, σ> ⇓ i32}
```
To operate these operands the expression need to evaluate to i32. Other arithmetic operands imlemented are To operate these operands the expression need to evaluate to i32. Other arithmetic operands imlemented are
- -, minus - -, minus
...@@ -376,8 +390,9 @@ To operate these operands the expression need to evaluate to i32. Other arithmet ...@@ -376,8 +390,9 @@ To operate these operands the expression need to evaluate to i32. Other arithmet
``` ```
Operands for boolean types Operands for boolean types
```math
$\frac{<e1,σ> ⇓ bool <e2, σ> ⇓ bool}{<e1 == e2, σ> ⇓ bool}$ \frac{<e1,σ> ⇓ bool <e2, σ> ⇓ bool}{<e1 == e2, σ> ⇓ bool}
```
To operate these operands the expression need to evaluate to boolean. Other boolean operands implemented are To operate these operands the expression need to evaluate to boolean. Other boolean operands implemented are
...@@ -392,8 +407,9 @@ true || false; ...@@ -392,8 +407,9 @@ true || false;
``` ```
If true/false If true/false
```math
$\frac{<e, σ> ⇓ bool <c1, σ> ⇓ σ'}{<if \text{ } bool \text{ } then \text{ } c1> ⇓ σ}$ \frac{<e, σ> ⇓ bool <c1, σ> ⇓ σ'}{<if \text{ } bool \text{ } then \text{ } c1> ⇓ σ}
```
```rust ```rust
if false { if false {
...@@ -402,22 +418,25 @@ if false { ...@@ -402,22 +418,25 @@ if false {
``` ```
While true/false While true/false
```math
$\frac{<e, σ> ⇓ bool <c,σ> ⇓ σ' <while \text{ } bool \text{ } do \text{ } c, σ'> ⇓ σ''}{<while \text{ } bool \text{ } do \text{ } c,σ> ⇓ σ''}$ \frac{<e, σ> ⇓ bool <c,σ> ⇓ σ' <while \text{ } bool \text{ } do \text{ } c, σ'> ⇓ σ''}{<while \text{ } bool \text{ } do \text{ } c,σ> ⇓ σ''}
```
For both if and while commands their block/scope are evluated as long as their condition is evaluted to the type boolean. This differ from the interpreter which only executes the block/scope if the condition is true. For both if and while commands their block/scope are evluated as long as their condition is evaluted to the type boolean. This differ from the interpreter which only executes the block/scope if the condition is true.
Let assignment i32 expression Let assignment i32 expression
```math
$\frac{<x, σ>⇓i32<let \text{ } x:=i32, σ>⇓σ'}{<let \text{ } x := i32, σ> ⇓ σ[x := i32]}$ \frac{<x, σ>⇓i32<let \text{ } x:=i32, σ>⇓σ'}{<let \text{ } x := i32, σ> ⇓ σ[x := i32]}
```
```rust ```rust
let a : i32 = 1; let a : i32 = 1;
let b : i32 = test(); // test() must return type i32 otherwise Error let b : i32 = test(); // test() must return type i32 otherwise Error
``` ```
Let assignment bool expression Let assignment bool expression
```math
$\frac{<x, σ>⇓bool<let \text{ } x:=bool, σ>⇓σ'}{<let \text{ } x := bool, σ> ⇓ σ[x := bool]}$ \frac{<x, σ>⇓bool<let \text{ } x:=bool, σ>⇓σ'}{<let \text{ } x := bool, σ> ⇓ σ[x := bool]}
```
```rust ```rust
let a : bool = true; let a : bool = true;
let b : bool = test(); // test() must return type bool otherwise Error let b : bool = test(); // test() must return type bool otherwise Error
...@@ -425,15 +444,17 @@ let b : bool = test(); // test() must return type bool otherwise Error ...@@ -425,15 +444,17 @@ let b : bool = test(); // test() must return type bool otherwise Error
As previously mentioned, let assignment are unique declerations. Thus, the same variable can not be declared twice in the same scope. Here, the given return type of the variable is checked with rhs evluated type. As previously mentioned, let assignment are unique declerations. Thus, the same variable can not be declared twice in the same scope. Here, the given return type of the variable is checked with rhs evluated type.
Assignment i32 expression Assignment i32 expression
```math
$\frac{<x, σ> ⇓ i32<e, σ> i32}{<x := i32, σ> ⇓ σ[x := i32]}$ \frac{<x, σ> ⇓ i32<e, σ> i32}{<x := i32, σ> ⇓ σ[x := i32]}
```
```rust ```rust
x = 1; x = 1;
``` ```
Assignment bool expression Assignment bool expression
```math
$\frac{<x, σ> ⇓ bool<e, σ> bool}{<x := bool, σ> ⇓ σ[x := bool]}$ \frac{<x, σ> ⇓ bool<e, σ> bool}{<x := bool, σ> ⇓ σ[x := bool]}
```
```rust ```rust
x = true; x = true;
...@@ -443,8 +464,9 @@ For any assigment, the variable typed stored with the rhs evaluated type is chec ...@@ -443,8 +464,9 @@ For any assigment, the variable typed stored with the rhs evaluated type is chec
Return i32 Return i32
```math
$\frac{<f, σ>⇓σ}{<return : i32, σ> ⇓ σ[return : i32]}$ \frac{<f, σ>⇓σ}{<return : i32, σ> ⇓ σ[return : i32]}
```
```rust ```rust
fn main() -> i32 { fn main() -> i32 {
...@@ -455,8 +477,9 @@ The function is declared to return a type i32. ...@@ -455,8 +477,9 @@ The function is declared to return a type i32.
Return bool Return bool
```math
$\frac{<f, σ>⇓σ}{<return : bool, σ> ⇓ σ[return : bool]}$ \frac{<f, σ>⇓σ}{<return : bool, σ> ⇓ σ[return : bool]}
```
```rust ```rust
fn main() -> bool { fn main() -> bool {
...@@ -466,8 +489,9 @@ fn main() -> bool { ...@@ -466,8 +489,9 @@ fn main() -> bool {
The function is declared to return a type boolean. The function is declared to return a type boolean.
Void (none) Void (none)
```math
$\frac{<f, σ>⇓σ}{<none, σ> ⇓ σ[none]}$ \frac{<f, σ>⇓σ}{<none, σ> ⇓ σ[none]}
```
```rust ```rust
fn main() { fn main() {
...@@ -492,7 +516,9 @@ SOS rules of the type checker that has not been described above are the type che ...@@ -492,7 +516,9 @@ SOS rules of the type checker that has not been described above are the type che
TO DISCUSS: TO DISCUSS:
Alternative answer would be to defined the SOS rules for functions as Alternative answer would be to defined the SOS rules for functions as
$<f, i32>⇓i32$, $<f, bool>⇓bool$, $<f, none>⇓none$. ```math
<f, i32>⇓i32, <f, bool>⇓bool, <f, none>⇓none.
```
The type checker will return a custom error with sufficient information except location e.g. The type checker will return a custom error with sufficient information except location e.g.
```rust ```rust
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment