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

add another notebook

parent e491e06f
Branches
Tags
No related merge requests found
Pipeline #101915 passed
%% Cell type:markdown id: tags:
# ProB's Prolog Constraint Solver
## Demo using Jupyter
### Prolog Day 2022
https://gitlab.cs.uni-duesseldorf.de/general/stups/prob2-jupyter-kernel
![ProB](./img/prob_logo.png)
%% Cell type:markdown id: tags:
We highlight some of the features of ProB's constraint solving kernel written in Prolog,
dealing with unbounded arithmetic, higher-order and possibly infinite sets:
%% Cell type:markdown id: tags:
# Some Features
%% Cell type:markdown id: tags:
Automatically detecting infinite sets:
%% Cell type:code id: tags:
``` prob
Primes = {x|x>1 & !y.(y:2..x-1 => x mod y >0)}
```
%% Cell type:markdown id: tags:
Generating some prime > 100 and using Unicode notation:
%% Cell type:code id: tags:
``` prob
Primes = {x∣x>1 ∧ ∀y.(y∈2..x-1⇒ x mod y>0)} ∧
some_prime ∈ Primes & some_prime > 100
```
%% Cell type:markdown id: tags:
Getting first 100 primes by intersection:
%% Cell type:code id: tags:
``` prob
1..100 ∩ {x∣x>1∧∀y.(y∈2..x-1⇒ x mod y>0)}
```
%% Cell type:markdown id: tags:
Getting first 1000 primes; observe that P1000 is computed explicitly while Primes is automatically kept symbolic:
%% Cell type:code id: tags:
``` prob
P1000 = 1..1000 ∩ Primes ∧
Primes = {x∣x>1 ∧ ∀y.(y∈2..x-1⇒ x mod y>0)}
```
%% Cell type:markdown id: tags:
Solving the famous SEND+MORE = MONEY Puzzle with
multiline input:
<div>
<img src="./img/SendMoreMoney.png" width="400"/>
</div>
%% Cell type:code id: tags:
``` prob
:table {S,E,N,D,M,O,R,Y |
{S, E, N, D, M, O, R, Y} ⊆ 0..9
∧ S > 0 ∧ M > 0
∧ card({S, E, N, D, M, O, R, Y}) = 8
S*1000 + E*100 + N*10 + D
+ M*1000 + O*100 + R*10 + E
= M*10000 + O*1000 + N*100 + E*10 + Y
}
```
%% Cell type:markdown id: tags:
Find distinct digits such that this multiplication becomes true:
![ProB](./img/KissKissPassion.png)
(This is a more difficult version of the Send+More=Money puzzle.)
%% Cell type:code id: tags:
``` prob
:table {K,I,S,P,A,O,N | {K,P} ⊆ 1..9 ∧
{I,S,A,O,N} ⊆ 0..9 ∧
(1000*K+100*I+10*S+S) * (1000*K+100*I+10*S+S)
= 1000000*P+100000*A+10000*S+1000*S+100*I+10*O+N ∧
card({K, I, S, P, A, O, N}) = 7}
```
%% Cell type:markdown id: tags:
## Visualisation
In B, sequences are also functions, functions are relations, and relations are sets.
Relations can be displayed visually:
%% Cell type:code id: tags:
``` prob
{x,y | x∈1..5 ∧ y∈1..5 ∧ x>y}
```
%% Cell type:code id: tags:
``` prob
:pref DOT_ENGINE=circo
```
%% Cell type:code id: tags:
``` prob
:dot expr_as_graph ("K5", {x,y | x∈1..5 ∧ y∈1..5 ∧ x>y})
```
%% Cell type:code id: tags:
``` prob
:dot expr_as_graph ("K6", {x,y | x∈1..6 ∧ y∈1..6 ∧ x>y})
```
%% Cell type:code id: tags:
``` prob
```
notebooks/presentations/img/SendMoreMoney.png

26.4 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment