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

add comment on how to lock

parent 063b72e1
Branches
Tags
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Exercice Sheet # Exercice Sheet: B Expressions
You are given a B machine with three given sets: You are given a B machine with three given sets:
* a set ```S``` of online shops * a set ```S``` of online shops
* a set ```A``` of articles that can be ordered * a set ```A``` of articles that can be ordered
* a set ```C``` of clients * a set ```C``` of clients
You are also given two relations: You are also given two relations:
* a relation ```delivers:S<->A``` describing which shops can deliver which articles * 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. * a relation ```orders:C<->POW(A)``` describing current outstanding orders, an order consisting of a set of articles.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
::load ::load
MACHINE exercise1 MACHINE exercise1
DEFINITIONS "LibraryHash.def" DEFINITIONS "LibraryHash.def"
SETS SETS
S = {s1,s2,s3,s4,s5} /* Shops */ ; S = {s1,s2,s3,s4,s5} /* Shops */ ;
A = {a1,a2,a3,a4,a5} /* Articles that can be ordered */; A = {a1,a2,a3,a4,a5} /* Articles that can be ordered */;
C = {c1,c2,c3} /* Clients */ C = {c1,c2,c3} /* Clients */
CONSTANTS delivers, orders CONSTANTS delivers, orders
PROPERTIES PROPERTIES
delivers = {s1↦a1,s1↦a2, s2↦a4, s3↦a3, s3↦a2, s4↦a4, s4↦a5} & 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}} orders = {c1 ↦ {a1,a5}, c1 ↦ {a4}, c2 ↦ {a1,a3,a5}, c3 ↦ {a2,a3}, c3 ↦ {a1}}
END END
``` ```
%% Output %% Output
Loaded machine: exercise1 Loaded machine: exercise1
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:constants :constants
``` ```
%% Output %% Output
Machine constants set up using operation 0: $setup_constants() Machine constants set up using operation 0: $setup_constants()
%% Cell type:markdown id: tags: %% 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. 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: %% Cell type:markdown id: tags:
## Exercise 1 ## 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. 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: %% Cell type:code id: tags:
``` prob ``` prob
:let sol1 {c| a5 : union(orders[{c}])} :let sol1 {c| a5 : union(orders[{c}])}
``` ```
%% Output %% Output
$\{\mathit{c1},\mathit{c2}\}$ $\{\mathit{c1},\mathit{c2}\}$
{c1,c2} {c1,c2}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:assert SHA_HASH_HEX(sol1) = "26365f212fb4cbe0ef2adc9eb42d3c6fac15442b" :assert SHA_HASH_HEX(sol1) = "26365f212fb4cbe0ef2adc9eb42d3c6fac15442b"
``` ```
%% Output %% Output
:assert: Error while evaluating assertion: Computation not completed: Could not infer type of T,Could not infer type of sol1 :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: %% Cell type:markdown id: tags:
## Exercise 2 ## 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. 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: %% Cell type:code id: tags:
``` prob ``` prob
:let sol2 union(ran(orders)) :let sol2 union(ran(orders))
``` ```
%% Output %% Output
$\{\mathit{a1},\mathit{a2},\mathit{a3},\mathit{a4},\mathit{a5}\}$ $\{\mathit{a1},\mathit{a2},\mathit{a3},\mathit{a4},\mathit{a5}\}$
{a1,a2,a3,a4,a5} {a1,a2,a3,a4,a5}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
SHA_HASH_HEX(sol2) SHA_HASH_HEX(sol2)
``` ```
%% Output %% Output
$\text{"29bac35e283e6637fd22c2c8ee4a17a8d4ff52a3"}$ $\text{"29bac35e283e6637fd22c2c8ee4a17a8d4ff52a3"}$
"29bac35e283e6637fd22c2c8ee4a17a8d4ff52a3" "29bac35e283e6637fd22c2c8ee4a17a8d4ff52a3"
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:assert SHA_HASH_HEX(sol2) = "29bac35e283e6637fd22c2c8ee4a17a8d4ff52a3" :assert SHA_HASH_HEX(sol2) = "29bac35e283e6637fd22c2c8ee4a17a8d4ff52a3"
``` ```
%% Output
:assert: Error while evaluating assertion: Computation not completed: Could not infer type of T,Could not infer type of sol2
%% Cell type:markdown id: tags:
# Comments:
To lock cells you can do this:
* menu: view → cell toolbar → edit metadata.
* make this like
```
{
"trusted": true,
"editable": false,
"deletable": false
}
```
%% Cell type:code id: tags:
``` prob
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment