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
8014ecdd
Commit
8014ecdd
authored
May 6, 2019
by
Michael Leuschel
Browse files
Options
Downloads
Patches
Plain Diff
add Bad Honnef presentation
parent
fbe232dd
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
notebooks/presentations/BadHonnef_2019.ipynb
+1007
-0
1007 additions, 0 deletions
notebooks/presentations/BadHonnef_2019.ipynb
with
1007 additions
and
0 deletions
notebooks/presentations/BadHonnef_2019.ipynb
0 → 100644
+
1007
−
0
View file @
8014ecdd
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Ein Jupyter-Kernel für Logik und Mengentheorie\n",
"\n",
"### David Geleßus, Michael Leuschel\n",
"### Bad Honnef, 2019"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Einführung: Notebooks, Jupyter"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Was ist ein Notebook?\n",
"\n",
"* Dokument mit Text und ausführbaren Code-Abschnitten\n",
"* Code kann interaktiv ausgeführt werden\n",
"* Ergebnisse erscheinen im Notebook unter dem jeweiligem Code\n",
"* Ähnlich wie eine REPL (read-eval-print-loop), mit einigen Unterschieden:\n",
" * Code-Abschnitte können \"außer der Reihe\" bearbeitet und ausgeführt werden\n",
" * Ausgaben können formatierten Text und Grafiken enthalten\n",
" * Speicherbar als Datei\n",
" * Code kann später neu ausgeführt werden\n",
" * Weitergabe an andere Nutzer möglich\n",
"* Implementierungen: Mathematica, Maple, Jupyter, u. a."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Jupyter Notebook\n",
"\n",
"* Browserbasierte Notebook-Oberfläche\n",
"* Open Source und plattformübergreifend\n",
"* Stammt aus der Python-Community, in Python implementiert\n",
"* Jupyter-Notebooks können aber verschiedene Programmiersprachen verwenden\n",
"* Dazu trennt Jupyter strikt zwischen Frontend und Kernel:\n",
" * Das allgemeine **Frontend** implementiert z. B. Benutzeroberfläche und Dateiformat\n",
" * Ein sprachspezifischer **Kernel** stellt die Sprache dem Frontend zur Verfügung\n",
"* Schnittstellen zwischen Frontend und Kernel sind sprachneutral\n",
" * Kernel können in (fast) jeder Sprache implementiert werden, kein Python-Code nötig"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## ProB\n",
"\n",
"* Werkzeug zur Animation, Verifikation und Visualisierung formeller Spezifikationen\n",
"* Grundlage: Solver für Prädikatenlogik, Mengentheorie mit Relationen, Funktionen und Arithmetik.\n",
"* Unterstützt hauptsächlich B-Spezifikationen (klassisches B, Event-B)\n",
"* Versteht auch andere Sprachen wie TLA<sup>+</sup> und CSP<sub>M</sub>\n",
"* ProBs APIs sind für alle Sprachen gleich\n",
" * Der ProB 2-Jupyter-Kernel unterstützt daher (fast) alle Sprachen, die ProB versteht"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Architektur von ProB\n",
"\n",
"* **`probcli`:** Kern/Hauptteil von ProB\n",
" * Implementiert in SICStus Prolog\n",
" * Erlaubt Animation, Visualisierung, Verifikation von formellen Spezifikationen\n",
" * Unterstützt u. A. (klassisches) B, Event-B, TLA<sup>+</sup>, CSP<sub>M</sub>\n",
" * Kommandozeilentool oder interaktive REPL\n",
"* **ProB 2-Java-API:** (aka ProB 2-Kernel; ≠ ProB 2-Jupyter-Kernel!)\n",
" * Objektorientierte Java-Schnittstelle für ProB\n",
" * Verwaltet automatisch eine oder mehrere `probcli`-Instanzen\n",
"* **ProB 2-Jupyter-Kernel:** Jupyter-Kernel-Implementierung für ProB\n",
" * In Java implementiert\n",
" * Ansteuerung von ProB durch ProB 2-Java-API\n",
" * Kommunikation mit Jupyter durch Jupyter-JVM-BaseKernel"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Formeln auswerten\n",
"\n",
"* B-Ausdrücke auswerten und Prädikate lösen wie in `probcli -repl`\n",
"\n",
"Zum Beispiel, Primzahlen bis 50 ausgeben:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47\\}$"
],
"text/plain": [
"{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"{x | x > 1 & x < 50 & not(#y.(y > 1 & y < x & x mod y = 0))}"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\mathit{x} > 1 \\wedge \\mathit{x} < 50 \\wedge \\neg (\\exists \\mathit{y}\\cdot (\\mathit{y} > 1 \\wedge \\mathit{y} < \\mathit{x} \\wedge \\mathit{x} \\mod \\mathit{y} = 0))$"
],
"text/plain": [
"x > 1 ∧ x < 50 ∧ ¬(∃y·(y > 1 ∧ y < x ∧ x mod y = 0))"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":prettyprint x > 1 & x < 50 & not(#y.(y > 1 & y < x & x mod y = 0))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Eingabe als Unicode ist auch erlaubt:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47\\}$"
],
"text/plain": [
"{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"{x | x>1 ∧ x<50 ∧ ¬(∃y.(y>1 ∧ y<x ∧ x mod y=0))}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Mehrzeilige Eingabe ist möglich, es gibt Syntax-Highlighting und Code Completion."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\mathit{TRUE}$\n",
"\n",
"**Solution:**\n",
"* $\\mathit{R} = 8$\n",
"* $\\mathit{S} = 9$\n",
"* $\\mathit{D} = 7$\n",
"* $\\mathit{E} = 5$\n",
"* $\\mathit{Y} = 2$\n",
"* $\\mathit{M} = 1$\n",
"* $\\mathit{N} = 6$\n",
"* $\\mathit{O} = 0$"
],
"text/plain": [
"TRUE\n",
"\n",
"Solution:\n",
"\tR = 8\n",
"\tS = 9\n",
"\tD = 7\n",
"\tE = 5\n",
"\tY = 2\n",
"\tM = 1\n",
"\tN = 6\n",
"\tO = 0"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"{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"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Mithilfe der Mengentheorie kann man alle Lösungen finden, und mit dem ```:table``` Kommando als Tabelle ausgeben."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"|S|E|N|D|M|O|R|Y|\n",
"|---|---|---|---|---|---|---|---|\n",
"|$9$|$5$|$6$|$7$|$1$|$0$|$8$|$2$|\n"
],
"text/plain": [
"S\tE\tN\tD\tM\tO\tR\tY\n",
"9\t5\t6\t7\t1\t0\t8\t2\n"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"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": [
"In B sind Folgen auch Funktionen, Funktionen auch Relationen, Relationen auch Mengen.\n",
"Relationen können in Jupyter auch grafisch dargestellt werden."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.28.0 (20110509.1545)\n",
" -->\n",
"<!-- Title: state Pages: 1 -->\n",
"<svg width=\"197pt\" height=\"404pt\"\n",
" viewBox=\"0.00 0.00 197.00 404.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph1\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 400)\">\n",
"<title>state</title>\n",
"<polygon fill=\"white\" stroke=\"white\" points=\"-4,5 -4,-400 194,-400 194,5 -4,5\"/>\n",
"<!-- 5 -->\n",
"<g id=\"node1\" class=\"node\"><title>5</title>\n",
"<polygon fill=\"#cdba96\" stroke=\"#cdba96\" points=\"96,-396 42,-396 42,-360 96,-360 96,-396\"/>\n",
"<text text-anchor=\"middle\" x=\"69\" y=\"-373.8\" font-family=\"Times,serif\" font-size=\"14.00\">5</text>\n",
"</g>\n",
"<!-- 4 -->\n",
"<g id=\"node3\" class=\"node\"><title>4</title>\n",
"<polygon fill=\"#cdba96\" stroke=\"#cdba96\" points=\"132,-306 78,-306 78,-270 132,-270 132,-306\"/>\n",
"<text text-anchor=\"middle\" x=\"105\" y=\"-283.8\" font-family=\"Times,serif\" font-size=\"14.00\">4</text>\n",
"</g>\n",
"<!-- 5->4 -->\n",
"<g id=\"edge2\" class=\"edge\"><title>5->4</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M76.1124,-359.614C81.2737,-346.998 88.3479,-329.705 94.2038,-315.391\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"97.4779,-316.631 98.0248,-306.05 90.999,-313.981 97.4779,-316.631\"/>\n",
"<text text-anchor=\"middle\" x=\"97\" y=\"-328.8\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node5\" class=\"node\"><title>3</title>\n",
"<polygon fill=\"#cdba96\" stroke=\"#cdba96\" points=\"132,-216 78,-216 78,-180 132,-180 132,-216\"/>\n",
"<text text-anchor=\"middle\" x=\"105\" y=\"-193.8\" font-family=\"Times,serif\" font-size=\"14.00\">3</text>\n",
"</g>\n",
"<!-- 5->3 -->\n",
"<g id=\"edge4\" class=\"edge\"><title>5->3</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M62.3241,-359.922C54.9337,-338.461 45.2688,-300.719 55,-270 60.3407,-253.141 71.2853,-236.824 81.5768,-224.093\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"84.4013,-226.173 88.18,-216.275 79.0535,-221.656 84.4013,-226.173\"/>\n",
"<text text-anchor=\"middle\" x=\"62\" y=\"-283.8\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node7\" class=\"node\"><title>2</title>\n",
"<polygon fill=\"#cdba96\" stroke=\"#cdba96\" points=\"189,-126 135,-126 135,-90 189,-90 189,-126\"/>\n",
"<text text-anchor=\"middle\" x=\"162\" y=\"-103.8\" font-family=\"Times,serif\" font-size=\"14.00\">2</text>\n",
"</g>\n",
"<!-- 5->2 -->\n",
"<g id=\"edge6\" class=\"edge\"><title>5->2</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M92.1315,-359.919C108.172,-346.874 128.772,-327.522 141,-306 173.209,-249.313 168.396,-227.196 169,-162 169.074,-154 169.788,-151.961 169,-144 168.749,-141.464 168.398,-138.84 167.985,-136.221\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"171.421,-135.548 166.172,-126.345 164.536,-136.813 171.421,-135.548\"/>\n",
"<text text-anchor=\"middle\" x=\"174\" y=\"-238.8\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node9\" class=\"node\"><title>1</title>\n",
"<polygon fill=\"#cdba96\" stroke=\"#cdba96\" points=\"101,-36 47,-36 47,-0 101,-0 101,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"74\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"<!-- 5->1 -->\n",
"<g id=\"edge8\" class=\"edge\"><title>5->1</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M44.0894,-359.841C24.3252,-344 0,-318.51 0,-289 0,-289 0,-289 0,-107 0,-80.6259 19.7116,-58.035 38.788,-42.3476\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"41.1268,-44.9623 46.8653,-36.0561 36.8253,-39.4398 41.1268,-44.9623\"/>\n",
"<text text-anchor=\"middle\" x=\"7\" y=\"-193.8\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 4->3 -->\n",
"<g id=\"edge10\" class=\"edge\"><title>4->3</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M105,-269.614C105,-257.24 105,-240.369 105,-226.22\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"108.5,-226.05 105,-216.05 101.5,-226.05 108.5,-226.05\"/>\n",
"<text text-anchor=\"middle\" x=\"112\" y=\"-238.8\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 4->2 -->\n",
"<g id=\"edge12\" class=\"edge\"><title>4->2</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M113.828,-269.93C116.76,-264.235 120.033,-257.85 123,-252 131.091,-236.046 134.867,-232.804 141,-216 149.463,-192.81 149.264,-186.227 154,-162 155.632,-153.652 157.118,-144.509 158.355,-136.202\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"161.827,-136.646 159.78,-126.251 154.898,-135.653 161.827,-136.646\"/>\n",
"<text text-anchor=\"middle\" x=\"157\" y=\"-193.8\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 4->1 -->\n",
"<g id=\"edge14\" class=\"edge\"><title>4->1</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M93.3702,-269.809C84.7406,-255.958 73.691,-235.625 69,-216 54.8228,-156.69 62.8115,-84.4693 68.9724,-46.0684\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"72.4294,-46.6159 70.6417,-36.173 65.527,-45.4514 72.4294,-46.6159\"/>\n",
"<text text-anchor=\"middle\" x=\"68\" y=\"-148.8\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 3->2 -->\n",
"<g id=\"edge16\" class=\"edge\"><title>3->2</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M116.261,-179.614C124.59,-166.755 136.066,-149.038 145.439,-134.568\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"148.457,-136.346 150.956,-126.05 142.582,-132.541 148.457,-136.346\"/>\n",
"<text text-anchor=\"middle\" x=\"145\" y=\"-148.8\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 3->1 -->\n",
"<g id=\"edge18\" class=\"edge\"><title>3->1</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M102.028,-179.933C96.6346,-148.966 85.1981,-83.2989 78.7247,-46.1292\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"82.1273,-45.2669 76.9634,-36.0157 75.2311,-46.468 82.1273,-45.2669\"/>\n",
"<text text-anchor=\"middle\" x=\"99\" y=\"-103.8\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 2->1 -->\n",
"<g id=\"edge20\" class=\"edge\"><title>2->1</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M146.087,-89.5211C136.408,-79.0452 123.697,-65.5585 112,-54 108.345,-50.3889 104.424,-46.6415 100.538,-42.9996\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"102.902,-40.4186 93.1876,-36.1896 98.1443,-45.5534 102.902,-40.4186\"/>\n",
"<text text-anchor=\"middle\" x=\"135\" y=\"-58.8\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<Dot visualization: expr_as_graph [(\"k5\",{x,y|x:1..5 & y:1..5 & x>y})]>"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":dot expr_as_graph (\"k5\",{x,y|x:1..5 & y:1..5 & x>y})"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Preference changed: DOT_ENGINE = circo\n"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":pref DOT_ENGINE=circo"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.28.0 (20110509.1545)\n",
" -->\n",
"<!-- Title: state Pages: 1 -->\n",
"<svg width=\"243pt\" height=\"235pt\"\n",
" viewBox=\"0.00 0.00 243.39 234.72\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph1\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 230.72)\">\n",
"<title>state</title>\n",
"<polygon fill=\"white\" stroke=\"white\" points=\"-4,5 -4,-230.72 240.386,-230.72 240.386,5 -4,5\"/>\n",
"<!-- 5 -->\n",
"<g id=\"node1\" class=\"node\"><title>5</title>\n",
"<polygon fill=\"#cdba96\" stroke=\"#cdba96\" points=\"166.103,-36 112.103,-36 112.103,-0 166.103,-0 166.103,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"139.103\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">5</text>\n",
"</g>\n",
"<!-- 4 -->\n",
"<g id=\"node3\" class=\"node\"><title>4</title>\n",
"<polygon fill=\"#cdba96\" stroke=\"#cdba96\" points=\"235.386,-131.36 181.386,-131.36 181.386,-95.3602 235.386,-95.3602 235.386,-131.36\"/>\n",
"<text text-anchor=\"middle\" x=\"208.386\" y=\"-109.16\" font-family=\"Times,serif\" font-size=\"14.00\">4</text>\n",
"</g>\n",
"<!-- 5->4 -->\n",
"<g id=\"edge2\" class=\"edge\"><title>5->4</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M152.461,-36.3864C162.879,-50.7254 177.49,-70.8353 189.165,-86.9044\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"186.594,-89.3207 195.303,-95.3536 192.257,-85.2062 186.594,-89.3207\"/>\n",
"<text text-anchor=\"middle\" x=\"179.813\" y=\"-50.4454\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node5\" class=\"node\"><title>3</title>\n",
"<polygon fill=\"#cdba96\" stroke=\"#cdba96\" points=\"54,-190.296 1.42109e-14,-190.296 1.42109e-14,-154.296 54,-154.296 54,-190.296\"/>\n",
"<text text-anchor=\"middle\" x=\"27\" y=\"-168.096\" font-family=\"Times,serif\" font-size=\"14.00\">3</text>\n",
"</g>\n",
"<!-- 5->3 -->\n",
"<g id=\"edge4\" class=\"edge\"><title>5->3</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M126.024,-36.0017C106.385,-63.0326 69.1556,-114.274 46.3626,-145.646\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"43.3895,-143.783 40.3432,-153.931 49.0526,-147.898 43.3895,-143.783\"/>\n",
"<text text-anchor=\"middle\" x=\"95.1931\" y=\"-93.6237\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node7\" class=\"node\"><title>2</title>\n",
"<polygon fill=\"#cdba96\" stroke=\"#cdba96\" points=\"166.103,-226.72 112.103,-226.72 112.103,-190.72 166.103,-190.72 166.103,-226.72\"/>\n",
"<text text-anchor=\"middle\" x=\"139.103\" y=\"-204.52\" font-family=\"Times,serif\" font-size=\"14.00\">2</text>\n",
"</g>\n",
"<!-- 5->2 -->\n",
"<g id=\"edge6\" class=\"edge\"><title>5->2</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M139.103,-36.2871C139.103,-69.6799 139.103,-140.734 139.103,-180.418\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"135.603,-180.489 139.103,-190.489 142.603,-180.489 135.603,-180.489\"/>\n",
"<text text-anchor=\"middle\" x=\"131.103\" y=\"-104.152\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node9\" class=\"node\"><title>1</title>\n",
"<polygon fill=\"#cdba96\" stroke=\"#cdba96\" points=\"54,-72.4243 0,-72.4243 0,-36.4243 54,-36.4243 54,-72.4243\"/>\n",
"<text text-anchor=\"middle\" x=\"27\" y=\"-50.2243\" font-family=\"Times,serif\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"<!-- 5->1 -->\n",
"<g id=\"edge8\" class=\"edge\"><title>5->1</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M111.966,-26.8173C97.6137,-31.4806 79.779,-37.2754 64.1603,-42.3502\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"62.7045,-39.143 54.2756,-45.562 64.8677,-45.8004 62.7045,-39.143\"/>\n",
"<text text-anchor=\"middle\" x=\"91.063\" y=\"-40.3838\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 4->3 -->\n",
"<g id=\"edge10\" class=\"edge\"><title>4->3</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M181.231,-122.183C150.018,-132.325 98.6277,-149.023 63.8291,-160.33\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"62.4733,-157.09 54.0443,-163.509 64.6364,-163.747 62.4733,-157.09\"/>\n",
"<text text-anchor=\"middle\" x=\"125.53\" y=\"-147.056\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 4->2 -->\n",
"<g id=\"edge12\" class=\"edge\"><title>4->2</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M195.027,-131.747C184.609,-146.086 169.999,-166.196 158.324,-182.265\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"155.231,-180.566 152.185,-190.714 160.895,-184.681 155.231,-180.566\"/>\n",
"<text text-anchor=\"middle\" x=\"185.676\" y=\"-159.806\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 4->1 -->\n",
"<g id=\"edge14\" class=\"edge\"><title>4->1</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M181.231,-104.537C150.018,-94.3953 98.6277,-77.6976 63.8291,-66.3908\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"64.6364,-62.9731 54.0443,-63.2116 62.4733,-69.6305 64.6364,-62.9731\"/>\n",
"<text text-anchor=\"middle\" x=\"119.53\" y=\"-91.2639\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 3->2 -->\n",
"<g id=\"edge16\" class=\"edge\"><title>3->2</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M54.1369,-181.113C68.4889,-185.777 86.3236,-191.571 101.942,-196.646\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"101.235,-200.096 111.827,-199.858 103.398,-193.439 101.235,-200.096\"/>\n",
"<text text-anchor=\"middle\" x=\"81.0396\" y=\"-174.68\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 3->1 -->\n",
"<g id=\"edge18\" class=\"edge\"><title>3->1</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M27,-154.137C27,-135.157 27,-105.11 27,-82.9567\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"30.5001,-82.7983 27,-72.7983 23.5001,-82.7983 30.5001,-82.7983\"/>\n",
"<text text-anchor=\"middle\" x=\"35\" y=\"-114.347\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"<!-- 2->1 -->\n",
"<g id=\"edge20\" class=\"edge\"><title>2->1</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M126.024,-190.719C106.385,-163.688 69.1556,-112.447 46.3626,-81.0746\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"49.0526,-78.8226 40.3432,-72.7896 43.3895,-82.9371 49.0526,-78.8226\"/>\n",
"<text text-anchor=\"middle\" x=\"77.1931\" y=\"-138.697\" font-family=\"Times,serif\" font-size=\"14.00\">k5</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<Dot visualization: expr_as_graph [(\"k5\",{x,y|x:1..5 & y:1..5 & x>y})]>"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":dot expr_as_graph (\"k5\",{x,y|x:1..5 & y:1..5 & x>y})"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Anwendungsmöglichkeiten"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Interaktive Nutzung als REPL\n",
"\n",
"* Jupyter Notebook kann wie eine REPL benutzt werden\n",
"* Vorteile: mehrzeilige Eingaben, formatierte Ausgaben, verbesserte Editor-Funktionen, speicherbar\n",
"* Alternative: `jupyter console` ermöglicht Verwendung von Jupyter-Kerneln im Terminal\n",
" * Verhält sich wie eine klassische REPL, arbeitet nicht mit Notebooks\n",
" * Unterstützt trotzdem erweiterte Funktionen: Eingabeverlauf, Code-Vervollständigung"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Interaktive Experimentierung\n",
"\n",
"* Beliebige Stellen im Notebook können bearbeitet und neu ausgeführt werden\n",
"* Vereinfacht Testen von Änderungen am Code, z. B.:\n",
" * Andere Konstanten-/Präferenzwerte\n",
" * Hinzufügen/Entfernen von Invarianten/Guards\n",
" * Ändern der Operationsfolge\n",
"* Auch Notebooks von anderen Nutzern können ohne Weiteres bearbeitet werden\n",
" * Notebook-Dateien sind nie \"schreibgeschützt\"\n",
" * Anzeige und Bearbeitung nutzen die gleiche Oberfläche\n",
"* Anwendungen:\n",
" * ProB-Notebook als Dokumentation und Beispielcode zu einem B-Modell\n",
" * ProB-Notebook\n",
" * Übungsblätter für Lehrveranstaltungen (B, Logik, Mengentheorie, theoretische Informatik) als Notebooks"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Anwendung als Dokumentation (Bibliothek von ProB)\n",
"\n",
"## LibraryRegex\n",
"\n",
"This library provides various facilities for pattern matching with regular expressions.\n",
"You can obtain the definitions below by putting the following into your DEFINITIONS clause:\n",
"\n",
"`DEFINITIONS \"LibraryRegex.def\"`\n",
"\n",
"The file `LibraryRegex.def` is also bundled with ProB and can be found in the `stdlib` folder (as of version 1.8.3-beta4)."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Loaded machine: Jupyter_LibraryRegex"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"::load\n",
"MACHINE Jupyter_LibraryRegex\n",
"DEFINITIONS \"LibraryRegex.def\"; \"LibraryStrings.def\"\n",
"END"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### REGEX_SEARCH_ALL\n",
"This external function searches for **all** occurences of a pattern in a string and returns the matched strings as a B sequence.\n",
"It always starts to match at the beginning.\n",
"\n",
"Type: $STRING \\times STRING \\rightarrow seq(STRING)$."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\{(1\\mapsto\\text{\"234\"}),(2\\mapsto\\text{\"567\"})\\}$"
],
"text/plain": [
"{(1↦\"234\"),(2↦\"567\")}"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"REGEX_SEARCH_ALL(\"abcdef000234daf567\",\"([1-9])([0-9]*)\")"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$[\\text{\"a\"},\\text{\"b\"},\\text{\"c\"},\\text{\"ä\"},\\text{\"é\"},\\text{\"à\"}]$"
],
"text/plain": [
"[\"a\",\"b\",\"c\",\"ä\",\"é\",\"à\"]"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"REGEX_SEARCH_ALL(\"abc-äéà-123\",\"[[:alpha:]]\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Anwendung: Interaktive Skripte\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"::load\n",
"MACHINE BaseTypes\n",
"SETS PERSONS = {peter,paul,mary}; COLOURS = {red,green,blue}\n",
"END"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In mathematics a binary relation over the sets $A$ and $B$ is defined to be\n",
" a subset of $A\\times B$.\n",
"The Cartesian product $A \\times B$ in turn is defined to be the set of pairs\n",
" $a \\mapsto b$ such that $a\\in A$ and $b\\in B$.\n",
" For example, we have:"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\{(\\mathit{peter}\\mapsto \\mathit{red}),(\\mathit{peter}\\mapsto \\mathit{green}),(\\mathit{peter}\\mapsto \\mathit{blue}),(\\mathit{paul}\\mapsto \\mathit{red}),(\\mathit{paul}\\mapsto \\mathit{green}),(\\mathit{paul}\\mapsto \\mathit{blue}),(\\mathit{mary}\\mapsto \\mathit{red}),(\\mathit{mary}\\mapsto \\mathit{green}),(\\mathit{mary}\\mapsto \\mathit{blue})\\}$"
],
"text/plain": [
"{(peter↦red),(peter↦green),(peter↦blue),(paul↦red),(paul↦green),(paul↦blue),(mary↦red),(mary↦green),(mary↦blue)}"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"PERSONS × COLOURS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A particular relation could be the following one, which is a subset of PERSONS × COLOURS:"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\{(\\mathit{peter}\\mapsto \\mathit{green}),(\\mathit{peter}\\mapsto \\mathit{blue}),(\\mathit{mary}\\mapsto \\mathit{blue})\\}$"
],
"text/plain": [
"{(peter↦green),(peter↦blue),(mary↦blue)}"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"{peter|->green,peter|->blue,mary|->blue}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can visualize this relation graphically as follows:"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.28.0 (20110509.1545)\n",
" -->\n",
"<!-- Title: state Pages: 1 -->\n",
"<svg width=\"166pt\" height=\"208pt\"\n",
" viewBox=\"0.00 0.00 166.00 208.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph1\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 204)\">\n",
"<title>state</title>\n",
"<polygon fill=\"white\" stroke=\"white\" points=\"-4,5 -4,-204 163,-204 163,5 -4,5\"/>\n",
"<g id=\"graph2\" class=\"cluster\"><title>cluster_PERSONS</title>\n",
"<polygon fill=\"lightgrey\" stroke=\"lightgrey\" points=\"8,-118 8,-192 150,-192 150,-118 8,-118\"/>\n",
"<text text-anchor=\"middle\" x=\"79\" y=\"-177.2\" font-family=\"Times,serif\" font-size=\"12.00\">PERSONS</text>\n",
"</g>\n",
"<g id=\"graph3\" class=\"cluster\"><title>cluster_COLOURS</title>\n",
"<polygon fill=\"lightgrey\" stroke=\"lightgrey\" points=\"8,-8 8,-82 150,-82 150,-8 8,-8\"/>\n",
"<text text-anchor=\"middle\" x=\"79\" y=\"-67.2\" font-family=\"Times,serif\" font-size=\"12.00\">COLOURS</text>\n",
"</g>\n",
"<!-- mary -->\n",
"<g id=\"node1\" class=\"node\"><title>mary</title>\n",
"<polygon fill=\"#efdf84\" stroke=\"#efdf84\" points=\"70,-162 16,-162 16,-126 70,-126 70,-162\"/>\n",
"<text text-anchor=\"middle\" x=\"43\" y=\"-139.8\" font-family=\"Times,serif\" font-size=\"14.00\">mary</text>\n",
"</g>\n",
"<!-- blue -->\n",
"<g id=\"node3\" class=\"node\"><title>blue</title>\n",
"<polygon fill=\"#bdef6b\" stroke=\"#bdef6b\" points=\"70,-52 16,-52 16,-16 70,-16 70,-52\"/>\n",
"<text text-anchor=\"middle\" x=\"43\" y=\"-29.8\" font-family=\"Times,serif\" font-size=\"14.00\">blue</text>\n",
"</g>\n",
"<!-- mary->blue -->\n",
"<g id=\"edge2\" class=\"edge\"><title>mary->blue</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M43,-125.648C43,-108.564 43,-82.215 43,-62.3195\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"46.5001,-62.309 43,-52.309 39.5001,-62.309 46.5001,-62.309\"/>\n",
"<text text-anchor=\"middle\" x=\"48.8303\" y=\"-94.8\" font-family=\"Times,serif\" font-size=\"14.00\">r1</text>\n",
"</g>\n",
"<!-- peter -->\n",
"<g id=\"node4\" class=\"node\"><title>peter</title>\n",
"<polygon fill=\"#efdf84\" stroke=\"#efdf84\" points=\"142,-162 88,-162 88,-126 142,-126 142,-162\"/>\n",
"<text text-anchor=\"middle\" x=\"115\" y=\"-139.8\" font-family=\"Times,serif\" font-size=\"14.00\">peter</text>\n",
"</g>\n",
"<!-- peter->blue -->\n",
"<g id=\"edge4\" class=\"edge\"><title>peter->blue</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M103.432,-125.648C91.728,-108.092 73.5006,-80.7508 60.1229,-60.6843\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"62.9986,-58.6881 54.5393,-52.309 57.1742,-62.571 62.9986,-58.6881\"/>\n",
"<text text-anchor=\"middle\" x=\"95.8303\" y=\"-94.8\" font-family=\"Times,serif\" font-size=\"14.00\">r1</text>\n",
"</g>\n",
"<!-- green -->\n",
"<g id=\"node7\" class=\"node\"><title>green</title>\n",
"<polygon fill=\"#bdef6b\" stroke=\"#bdef6b\" points=\"142,-52 88,-52 88,-16 142,-16 142,-52\"/>\n",
"<text text-anchor=\"middle\" x=\"115\" y=\"-29.8\" font-family=\"Times,serif\" font-size=\"14.00\">green</text>\n",
"</g>\n",
"<!-- peter->green -->\n",
"<g id=\"edge6\" class=\"edge\"><title>peter->green</title>\n",
"<path fill=\"none\" stroke=\"firebrick\" d=\"M115,-125.648C115,-108.564 115,-82.215 115,-62.3195\"/>\n",
"<polygon fill=\"firebrick\" stroke=\"firebrick\" points=\"118.5,-62.309 115,-52.309 111.5,-62.309 118.5,-62.309\"/>\n",
"<text text-anchor=\"middle\" x=\"120.83\" y=\"-94.8\" font-family=\"Times,serif\" font-size=\"14.00\">r1</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<Dot visualization: expr_as_graph [(\"r1\",{(peter,green),(peter,blue),(mary,blue)})]>"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":dot expr_as_graph (\"r1\",{peter|->green,peter|->blue,mary|->blue})"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"|prj1|prj2|\n",
"|---|---|\n",
"|$\\mathit{peter}$|$\\mathit{green}$|\n",
"|$\\mathit{peter}$|$\\mathit{blue}$|\n",
"|$\\mathit{mary}$|$\\mathit{blue}$|\n"
],
"text/plain": [
"prj1\tprj2\n",
"peter\tgreen\n",
"peter\tblue\n",
"mary\tblue\n"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":table {peter|->green,peter|->blue,mary|->blue}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As in B a relation is a set of pairs, all set operators can be applied to relations.\n",
"For example,"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\{(\\mathit{peter}\\mapsto \\mathit{green}),(\\mathit{peter}\\mapsto \\mathit{blue})\\}$"
],
"text/plain": [
"{(peter↦green),(peter↦blue)}"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"{peter|->green,peter|->blue,mary|->blue} - {mary|->blue}"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\{(\\mathit{mary}\\mapsto \\mathit{blue})\\}$"
],
"text/plain": [
"{(mary↦blue)}"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"{peter|->green,peter|->blue,mary|->blue} /\\ {mary}*COLOURS"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Slideshow",
"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"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:markdown id: tags:
# Ein Jupyter-Kernel für Logik und Mengentheorie
### David Geleßus, Michael Leuschel
### Bad Honnef, 2019
%% Cell type:markdown id: tags:
# Einführung: Notebooks, Jupyter
%% Cell type:markdown id: tags:
## Was ist ein Notebook?
*
Dokument mit Text und ausführbaren Code-Abschnitten
*
Code kann interaktiv ausgeführt werden
*
Ergebnisse erscheinen im Notebook unter dem jeweiligem Code
*
Ähnlich wie eine REPL (read-eval-print-loop), mit einigen Unterschieden:
*
Code-Abschnitte können "außer der Reihe" bearbeitet und ausgeführt werden
*
Ausgaben können formatierten Text und Grafiken enthalten
*
Speicherbar als Datei
*
Code kann später neu ausgeführt werden
*
Weitergabe an andere Nutzer möglich
*
Implementierungen: Mathematica, Maple, Jupyter, u. a.
%% Cell type:markdown id: tags:
## Jupyter Notebook
*
Browserbasierte Notebook-Oberfläche
*
Open Source und plattformübergreifend
*
Stammt aus der Python-Community, in Python implementiert
*
Jupyter-Notebooks können aber verschiedene Programmiersprachen verwenden
*
Dazu trennt Jupyter strikt zwischen Frontend und Kernel:
*
Das allgemeine
**Frontend**
implementiert z. B. Benutzeroberfläche und Dateiformat
*
Ein sprachspezifischer
**Kernel**
stellt die Sprache dem Frontend zur Verfügung
*
Schnittstellen zwischen Frontend und Kernel sind sprachneutral
*
Kernel können in (fast) jeder Sprache implementiert werden, kein Python-Code nötig
%% Cell type:markdown id: tags:
## ProB
*
Werkzeug zur Animation, Verifikation und Visualisierung formeller Spezifikationen
*
Grundlage: Solver für Prädikatenlogik, Mengentheorie mit Relationen, Funktionen und Arithmetik.
*
Unterstützt hauptsächlich B-Spezifikationen (klassisches B, Event-B)
*
Versteht auch andere Sprachen wie TLA
<sup>
+
</sup>
und CSP
<sub>
M
</sub>
*
ProBs APIs sind für alle Sprachen gleich
*
Der ProB 2-Jupyter-Kernel unterstützt daher (fast) alle Sprachen, die ProB versteht
%% Cell type:markdown id: tags:
## Architektur von ProB
*
**`probcli`:**
Kern/Hauptteil von ProB
*
Implementiert in SICStus Prolog
*
Erlaubt Animation, Visualisierung, Verifikation von formellen Spezifikationen
*
Unterstützt u. A. (klassisches) B, Event-B, TLA
<sup>
+
</sup>
, CSP
<sub>
M
</sub>
*
Kommandozeilentool oder interaktive REPL
*
**ProB 2-Java-API:**
(aka ProB 2-Kernel; ≠ ProB 2-Jupyter-Kernel!)
*
Objektorientierte Java-Schnittstelle für ProB
*
Verwaltet automatisch eine oder mehrere
`probcli`
-Instanzen
*
**ProB 2-Jupyter-Kernel:**
Jupyter-Kernel-Implementierung für ProB
*
In Java implementiert
*
Ansteuerung von ProB durch ProB 2-Java-API
*
Kommunikation mit Jupyter durch Jupyter-JVM-BaseKernel
%% Cell type:markdown id: tags:
## Formeln auswerten
*
B-Ausdrücke auswerten und Prädikate lösen wie in
`probcli -repl`
Zum Beispiel, Primzahlen bis 50 ausgeben:
%% Cell type:code id: tags:
```
prob
{x | x > 1 & x < 50 & not(#y.(y > 1 & y < x & x mod y = 0))}
```
%% Output
$\{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47\}$
{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}
%% Cell type:code id: tags:
```
prob
:prettyprint x > 1 & x < 50 & not(#y.(y > 1 & y < x & x mod y = 0))
```
%% Output
$\mathit{x} > 1 \wedge \mathit{x} < 50 \wedge \neg (\exists \mathit{y}\cdot (\mathit{y} > 1 \wedge \mathit{y} < \mathit{x} \wedge \mathit{x} \mod \mathit{y} = 0))$
x > 1 ∧ x < 50 ∧ ¬(∃y·(y > 1 ∧ y < x ∧ x mod y = 0))
%% Cell type:markdown id: tags:
Eingabe als Unicode ist auch erlaubt:
%% Cell type:code id: tags:
```
prob
{x | x>1 ∧ x<50 ∧ ¬(∃y.(y>1 ∧ y<x ∧ x mod y=0))}
```
%% Output
$\{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47\}$
{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}
%% Cell type:markdown id: tags:
Mehrzeilige Eingabe ist möglich, es gibt Syntax-Highlighting und Code Completion.
%% Cell type:code id: tags:
```
prob
{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
```
%% Output
$\mathit{TRUE}$
**Solution:**
* $\mathit{R} = 8$
* $\mathit{S} = 9$
* $\mathit{D} = 7$
* $\mathit{E} = 5$
* $\mathit{Y} = 2$
* $\mathit{M} = 1$
* $\mathit{N} = 6$
* $\mathit{O} = 0$
TRUE
Solution:
R = 8
S = 9
D = 7
E = 5
Y = 2
M = 1
N = 6
O = 0
%% Cell type:markdown id: tags:
Mithilfe der Mengentheorie kann man alle Lösungen finden, und mit dem
```:table```
Kommando als Tabelle ausgeben.
%% 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
}
```
%% Output
|S|E|N|D|M|O|R|Y|
|---|---|---|---|---|---|---|---|
|$9$|$5$|$6$|$7$|$1$|$0$|$8$|$2$|
S E N D M O R Y
9 5 6 7 1 0 8 2
%% Cell type:markdown id: tags:
In B sind Folgen auch Funktionen, Funktionen auch Relationen, Relationen auch Mengen.
Relationen können in Jupyter auch grafisch dargestellt werden.
%% Cell type:code id: tags:
```
prob
:dot expr_as_graph ("k5",{x,y|x:1..5 & y:1..5 & x>y})
```
%% Output
<Dot visualization: expr_as_graph [("k5",{x,y|x:1..5 & y:1..5 & x>y})]>
%% Cell type:code id: tags:
```
prob
:pref DOT_ENGINE=circo
```
%% Output
Preference changed: DOT_ENGINE = circo
%% Cell type:code id: tags:
```
prob
:dot expr_as_graph ("k5",{x,y|x:1..5 & y:1..5 & x>y})
```
%% Output
<Dot visualization: expr_as_graph [("k5",{x,y|x:1..5 & y:1..5 & x>y})]>
%% Cell type:markdown id: tags:
# Anwendungsmöglichkeiten
%% Cell type:markdown id: tags:
## Interaktive Nutzung als REPL
*
Jupyter Notebook kann wie eine REPL benutzt werden
*
Vorteile: mehrzeilige Eingaben, formatierte Ausgaben, verbesserte Editor-Funktionen, speicherbar
*
Alternative:
`jupyter console`
ermöglicht Verwendung von Jupyter-Kerneln im Terminal
*
Verhält sich wie eine klassische REPL, arbeitet nicht mit Notebooks
*
Unterstützt trotzdem erweiterte Funktionen: Eingabeverlauf, Code-Vervollständigung
%% Cell type:markdown id: tags:
## Interaktive Experimentierung
*
Beliebige Stellen im Notebook können bearbeitet und neu ausgeführt werden
*
Vereinfacht Testen von Änderungen am Code, z. B.:
*
Andere Konstanten-/Präferenzwerte
*
Hinzufügen/Entfernen von Invarianten/Guards
*
Ändern der Operationsfolge
*
Auch Notebooks von anderen Nutzern können ohne Weiteres bearbeitet werden
*
Notebook-Dateien sind nie "schreibgeschützt"
*
Anzeige und Bearbeitung nutzen die gleiche Oberfläche
*
Anwendungen:
*
ProB-Notebook als Dokumentation und Beispielcode zu einem B-Modell
*
ProB-Notebook
*
Übungsblätter für Lehrveranstaltungen (B, Logik, Mengentheorie, theoretische Informatik) als Notebooks
%% Cell type:markdown id: tags:
# Anwendung als Dokumentation (Bibliothek von ProB)
## LibraryRegex
This library provides various facilities for pattern matching with regular expressions.
You can obtain the definitions below by putting the following into your DEFINITIONS clause:
`DEFINITIONS "LibraryRegex.def"`
The file
`LibraryRegex.def`
is also bundled with ProB and can be found in the
`stdlib`
folder (as of version 1.8.3-beta4).
%% Cell type:code id: tags:
```
prob
::load
MACHINE Jupyter_LibraryRegex
DEFINITIONS "LibraryRegex.def"; "LibraryStrings.def"
END
```
%% Output
Loaded machine: Jupyter_LibraryRegex
%% Cell type:markdown id: tags:
### REGEX_SEARCH_ALL
This external function searches for
**all**
occurences of a pattern in a string and returns the matched strings as a B sequence.
It always starts to match at the beginning.
Type: $STRING
\t
imes STRING
\r
ightarrow seq(STRING)$.
%% Cell type:code id: tags:
```
prob
REGEX_SEARCH_ALL("abcdef000234daf567","([1-9])([0-9]*)")
```
%% Output
$\{(1\mapsto\text{"234"}),(2\mapsto\text{"567"})\}$
{(1↦"234"),(2↦"567")}
%% Cell type:code id: tags:
```
prob
REGEX_SEARCH_ALL("abc-äéà-123","[[:alpha:]]")
```
%% Output
$[\text{"a"},\text{"b"},\text{"c"},\text{"ä"},\text{"é"},\text{"à"}]$
["a","b","c","ä","é","à"]
%% Cell type:markdown id: tags:
# Anwendung: Interaktive Skripte
%% Cell type:code id: tags:
```
prob
::load
MACHINE BaseTypes
SETS PERSONS = {peter,paul,mary}; COLOURS = {red,green,blue}
END
```
%% Cell type:markdown id: tags:
In mathematics a binary relation over the sets $A$ and $B$ is defined to be
a subset of $A
\t
imes B$.
The Cartesian product $A
\t
imes B$ in turn is defined to be the set of pairs
$a
\m
apsto b$ such that $a
\i
n A$ and $b
\i
n B$.
For example, we have:
%% Cell type:code id: tags:
```
prob
PERSONS × COLOURS
```
%% Output
$\{(\mathit{peter}\mapsto \mathit{red}),(\mathit{peter}\mapsto \mathit{green}),(\mathit{peter}\mapsto \mathit{blue}),(\mathit{paul}\mapsto \mathit{red}),(\mathit{paul}\mapsto \mathit{green}),(\mathit{paul}\mapsto \mathit{blue}),(\mathit{mary}\mapsto \mathit{red}),(\mathit{mary}\mapsto \mathit{green}),(\mathit{mary}\mapsto \mathit{blue})\}$
{(peter↦red),(peter↦green),(peter↦blue),(paul↦red),(paul↦green),(paul↦blue),(mary↦red),(mary↦green),(mary↦blue)}
%% Cell type:markdown id: tags:
A particular relation could be the following one, which is a subset of PERSONS × COLOURS:
%% Cell type:code id: tags:
```
prob
{peter|->green,peter|->blue,mary|->blue}
```
%% Output
$\{(\mathit{peter}\mapsto \mathit{green}),(\mathit{peter}\mapsto \mathit{blue}),(\mathit{mary}\mapsto \mathit{blue})\}$
{(peter↦green),(peter↦blue),(mary↦blue)}
%% Cell type:markdown id: tags:
We can visualize this relation graphically as follows:
%% Cell type:code id: tags:
```
prob
:dot expr_as_graph ("r1",{peter|->green,peter|->blue,mary|->blue})
```
%% Output
<Dot visualization: expr_as_graph [("r1",{(peter,green),(peter,blue),(mary,blue)})]>
%% Cell type:code id: tags:
```
prob
:table {peter|->green,peter|->blue,mary|->blue}
```
%% Output
|prj1|prj2|
|---|---|
|$\mathit{peter}$|$\mathit{green}$|
|$\mathit{peter}$|$\mathit{blue}$|
|$\mathit{mary}$|$\mathit{blue}$|
prj1 prj2
peter green
peter blue
mary blue
%% Cell type:markdown id: tags:
As in B a relation is a set of pairs, all set operators can be applied to relations.
For example,
%% Cell type:code id: tags:
```
prob
{peter|->green,peter|->blue,mary|->blue} - {mary|->blue}
```
%% Output
$\{(\mathit{peter}\mapsto \mathit{green}),(\mathit{peter}\mapsto \mathit{blue})\}$
{(peter↦green),(peter↦blue)}
%% Cell type:code id: tags:
```
prob
{peter|->green,peter|->blue,mary|->blue} /\ {mary}*COLOURS
```
%% Output
$\{(\mathit{mary}\mapsto \mathit{blue})\}$
{(mary↦blue)}
%% Cell type:code id: tags:
```
prob
```
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