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

add exercise experiment

parent 36d0e4a8
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Exercice Sheet
You are given a B machine with three given sets:
* a set ```S``` of online shops
* a set ```A``` of articles that can be ordered
* a set ```C``` of clients
You are also given two relations:
* a relation ```delivers:S<->A``` describing which shops can deliver which articles
* a relation ```orders:C<->POW(A)``` describing current outstanding orders, an order consisting of a set of articles.
%% Cell type:code id: tags:
``` prob
::load
MACHINE exercise1
DEFINITIONS "LibraryHash.def"
SETS
S = {s1,s2,s3,s4,s5} /* Shops */ ;
A = {a1,a2,a3,a4,a5} /* Articles that can be ordered */;
C = {c1,c2,c3} /* Clients */
CONSTANTS delivers, orders
PROPERTIES
delivers = {s1↦a1,s1↦a2, s2↦a4, s3↦a3, s3↦a2, s4↦a4, s4↦a5} &
orders = {c1 ↦ {a1,a5}, c1 ↦ {a4}, c2 ↦ {a1,a3,a5}, c3 ↦ {a2,a3}, c3 ↦ {a1}}
END
```
%% Output
Loaded machine: exercise1
%% Cell type:code id: tags:
``` prob
:constants
```
%% Output
Machine constants set up using operation 0: $setup_constants()
%% Cell type:markdown id: tags:
The above machine also contains particular instantiations of the above sets and relations, which will be used in the exercises below.
%% Cell type:markdown id: tags:
## Exercise 1
Write a B expression to compute the set of clients that have ordered article a5. Use the ```:let sol1 EXPRESSION``` in the cell below.
%% Cell type:code id: tags:
``` prob
:let sol1 {c| a5 : union(orders[{c}])}
```
%% Output
$\{\mathit{c1},\mathit{c2}\}$
{c1,c2}
%% Cell type:code id: tags:
``` prob
:assert SHA_HASH_HEX(sol1) = "26365f212fb4cbe0ef2adc9eb42d3c6fac15442b"
```
%% Output
:assert: Error while evaluating assertion: Computation not completed: Could not infer type of T,Could not infer type of sol1
%% Cell type:markdown id: tags:
## Exercise 2
Write a B expression which computes the set of all articles ordered by at least one client. Use the ```:let sol2 EXPRESSION``` in the cell below.
%% Cell type:code id: tags:
``` prob
:let sol2 union(ran(orders))
```
%% Output
$\{\mathit{a1},\mathit{a2},\mathit{a3},\mathit{a4},\mathit{a5}\}$
{a1,a2,a3,a4,a5}
%% Cell type:code id: tags:
``` prob
SHA_HASH_HEX(sol2)
```
%% Output
$\text{"29bac35e283e6637fd22c2c8ee4a17a8d4ff52a3"}$
"29bac35e283e6637fd22c2c8ee4a17a8d4ff52a3"
%% Cell type:code id: tags:
``` prob
:assert SHA_HASH_HEX(sol2) = "29bac35e283e6637fd22c2c8ee4a17a8d4ff52a3"
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment