Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProB 2 Jupyter Kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
ProB 2 Jupyter Kernel
Commits
679d97b9
Commit
679d97b9
authored
2 years ago
by
Michael Leuschel
Browse files
Options
Downloads
Patches
Plain Diff
add another notebook
Signed-off-by:
Michael Leuschel
<
leuschel@uni-duesseldorf.de
>
parent
e491e06f
No related branches found
No related tags found
No related merge requests found
Pipeline
#101915
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
notebooks/presentations/Prolog50_2022.ipynb
+284
-0
284 additions, 0 deletions
notebooks/presentations/Prolog50_2022.ipynb
notebooks/presentations/img/SendMoreMoney.png
+0
-0
0 additions, 0 deletions
notebooks/presentations/img/SendMoreMoney.png
with
284 additions
and
0 deletions
notebooks/presentations/Prolog50_2022.ipynb
0 → 100644
+
284
−
0
View file @
679d97b9
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# ProB's Prolog Constraint Solver\n",
"## Demo using Jupyter\n",
"\n",
"### Prolog Day 2022\n",
"\n",
"https://gitlab.cs.uni-duesseldorf.de/general/stups/prob2-jupyter-kernel\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"We highlight some of the features of ProB's constraint solving kernel written in Prolog,\n",
"dealing with unbounded arithmetic, higher-order and possibly infinite sets:"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Some Features"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Automatically detecting infinite sets:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false,
"vscode": {
"languageId": "classicalb"
}
},
"outputs": [],
"source": [
"Primes = {x|x>1 & !y.(y:2..x-1 => x mod y >0)}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Generating some prime > 100 and using Unicode notation:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Primes = {x∣x>1 ∧ ∀y.(y∈2..x-1⇒ x mod y>0)} ∧\n",
"some_prime ∈ Primes & some_prime > 100"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Getting first 100 primes by intersection:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"vscode": {
"languageId": "python"
}
},
"outputs": [],
"source": [
"1..100 ∩ {x∣x>1∧∀y.(y∈2..x-1⇒ x mod y>0)}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Getting first 1000 primes; observe that P1000 is computed explicitly while Primes is automatically kept symbolic:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"P1000 = 1..1000 ∩ Primes ∧\n",
"Primes = {x∣x>1 ∧ ∀y.(y∈2..x-1⇒ x mod y>0)}"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Solving the famous SEND+MORE = MONEY Puzzle with\n",
"multiline input:\n",
"\n",
"<div>\n",
"<img src=\"./img/SendMoreMoney.png\" width=\"400\"/>\n",
"</div>\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"outputs": [],
"source": [
":table {S,E,N,D,M,O,R,Y |\n",
"\n",
"{S, E, N, D, M, O, R, Y} ⊆ 0..9\n",
"∧ S > 0 ∧ M > 0\n",
"∧ card({S, E, N, D, M, O, R, Y}) = 8\n",
"∧\n",
" S*1000 + E*100 + N*10 + D\n",
"+ M*1000 + O*100 + R*10 + E\n",
"= M*10000 + O*1000 + N*100 + E*10 + Y\n",
"\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Find distinct digits such that this multiplication becomes true:\n",
"\n",
"\n",
"\n",
"(This is a more difficult version of the Send+More=Money puzzle.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"outputs": [],
"source": [
":table {K,I,S,P,A,O,N | {K,P} ⊆ 1..9 ∧\n",
" {I,S,A,O,N} ⊆ 0..9 ∧\n",
" (1000*K+100*I+10*S+S) * (1000*K+100*I+10*S+S) \n",
" = 1000000*P+100000*A+10000*S+1000*S+100*I+10*O+N ∧\n",
" card({K, I, S, P, A, O, N}) = 7}"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Visualisation\n",
"\n",
"In B, sequences are also functions, functions are relations, and relations are sets.\n",
"Relations can be displayed visually:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"outputs": [],
"source": [
"{x,y | x∈1..5 ∧ y∈1..5 ∧ x>y}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
},
"vscode": {
"languageId": "python"
}
},
"outputs": [],
"source": [
":pref DOT_ENGINE=circo"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"outputs": [],
"source": [
":dot expr_as_graph (\"K5\", {x,y | x∈1..5 ∧ y∈1..5 ∧ x>y})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
":dot expr_as_graph (\"K6\", {x,y | x∈1..6 ∧ y∈1..6 ∧ x>y})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "ProB 2",
"language": "prob",
"name": "prob2"
},
"language_info": {
"codemirror_mode": "prob2_jupyter_repl",
"file_extension": ".prob",
"mimetype": "text/x-prob2-jupyter-repl",
"name": "prob"
},
"vscode": {
"interpreter": {
"hash": "301501caf4ced90c88b4867a75dc974b7f77d88824feb914d0cf4e75e12213b3"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% 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

%% 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:

(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
```
This diff is collapsed.
Click to expand it.
notebooks/presentations/img/SendMoreMoney.png
0 → 100644
+
0
−
0
View file @
679d97b9
26.4 KiB
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment