diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..5758feb --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,46 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/python +{ + "name": "Python 3", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm", + "features": { + "ghcr.io/devcontainers/features/github-cli:1": { + "installDirectlyFromGitHubRelease": true, + "version": "latest" + }, + "ghcr.io/devcontainers-contrib/features/markdownlint-cli2:1": { + "version": "latest" + }, + "ghcr.io/devcontainers-contrib/features/mkdocs:2": { + "version": "latest", //mkdocstrings[crystal,python] + "plugins": "mkdocs-material pymdown-extensions mkdocs-monorepo-plugin mkdocs-pdf-export-plugin mkdocs-awesome-pages-plugin pygments mkdocs-bibtex markdown-aafigure mkdocs-build-plantuml-plugin Markdown" + }, + "ghcr.io/devcontainers-contrib/features/pipenv:2": { + "version": "latest" + }, + "ghcr.io/devcontainers-contrib/features/pipx-package:1": { + "includeDeps": true, + "package": "black", + "version": "latest", + "injections": "pylint pytest", + "interpreter": "python3" + }, + "ghcr.io/akhildevelops/devcontainer-features/pip:0": {} + } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pip3 install --user -r requirements.txt", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/docs/user/quicktour/appendix.md b/docs/quicktour/appendix.md similarity index 100% rename from docs/user/quicktour/appendix.md rename to docs/quicktour/appendix.md diff --git a/docs/user/quicktour/figures/SMTButton.png b/docs/quicktour/figures/SMTButton.png similarity index 100% rename from docs/user/quicktour/figures/SMTButton.png rename to docs/quicktour/figures/SMTButton.png diff --git a/docs/user/quicktour/figures/autoModeStart.png b/docs/quicktour/figures/autoModeStart.png similarity index 100% rename from docs/user/quicktour/figures/autoModeStart.png rename to docs/quicktour/figures/autoModeStart.png diff --git a/docs/user/quicktour/figures/classfunctionality_new.eps b/docs/quicktour/figures/classfunctionality_new.eps similarity index 100% rename from docs/user/quicktour/figures/classfunctionality_new.eps rename to docs/quicktour/figures/classfunctionality_new.eps diff --git a/docs/user/quicktour/figures/editFile.png b/docs/quicktour/figures/editFile.png similarity index 100% rename from docs/user/quicktour/figures/editFile.png rename to docs/quicktour/figures/editFile.png diff --git a/docs/user/quicktour/figures/errorDialogUnknownType.png b/docs/quicktour/figures/errorDialogUnknownType.png similarity index 100% rename from docs/user/quicktour/figures/errorDialogUnknownType.png rename to docs/quicktour/figures/errorDialogUnknownType.png diff --git a/docs/user/quicktour/figures/goalBack.png b/docs/quicktour/figures/goalBack.png similarity index 100% rename from docs/user/quicktour/figures/goalBack.png rename to docs/quicktour/figures/goalBack.png diff --git a/docs/user/quicktour/figures/infoTab.png b/docs/quicktour/figures/infoTab.png similarity index 100% rename from docs/user/quicktour/figures/infoTab.png rename to docs/quicktour/figures/infoTab.png diff --git a/docs/user/quicktour/figures/keyprover_new.eps b/docs/quicktour/figures/keyprover_new.eps similarity index 100% rename from docs/user/quicktour/figures/keyprover_new.eps rename to docs/quicktour/figures/keyprover_new.eps diff --git a/docs/user/quicktour/figures/keyprover_new.png b/docs/quicktour/figures/keyprover_new.png similarity index 100% rename from docs/user/quicktour/figures/keyprover_new.png rename to docs/quicktour/figures/keyprover_new.png diff --git a/docs/user/quicktour/figures/methfunctionality_new.eps b/docs/quicktour/figures/methfunctionality_new.eps similarity index 100% rename from docs/user/quicktour/figures/methfunctionality_new.eps rename to docs/quicktour/figures/methfunctionality_new.eps diff --git a/docs/user/quicktour/figures/methpattern_new.eps b/docs/quicktour/figures/methpattern_new.eps similarity index 100% rename from docs/user/quicktour/figures/methpattern_new.eps rename to docs/quicktour/figures/methpattern_new.eps diff --git a/docs/user/quicktour/figures/oneStepSimplifier.png b/docs/quicktour/figures/oneStepSimplifier.png similarity index 100% rename from docs/user/quicktour/figures/oneStepSimplifier.png rename to docs/quicktour/figures/oneStepSimplifier.png diff --git a/docs/user/quicktour/figures/open.png b/docs/quicktour/figures/open.png similarity index 100% rename from docs/user/quicktour/figures/open.png rename to docs/quicktour/figures/open.png diff --git a/docs/user/quicktour/figures/openMostRecent.png b/docs/quicktour/figures/openMostRecent.png similarity index 100% rename from docs/user/quicktour/figures/openMostRecent.png rename to docs/quicktour/figures/openMostRecent.png diff --git a/docs/user/quicktour/figures/overview_new.eps b/docs/quicktour/figures/overview_new.eps similarity index 100% rename from docs/user/quicktour/figures/overview_new.eps rename to docs/quicktour/figures/overview_new.eps diff --git a/docs/user/quicktour/figures/paycard-grab1_new.eps b/docs/quicktour/figures/paycard-grab1_new.eps similarity index 100% rename from docs/user/quicktour/figures/paycard-grab1_new.eps rename to docs/quicktour/figures/paycard-grab1_new.eps diff --git a/docs/user/quicktour/figures/paycard-grab2_new.eps b/docs/quicktour/figures/paycard-grab2_new.eps similarity index 100% rename from docs/user/quicktour/figures/paycard-grab2_new.eps rename to docs/quicktour/figures/paycard-grab2_new.eps diff --git a/docs/user/quicktour/figures/pobProofObligations.png b/docs/quicktour/figures/pobProofObligations.png similarity index 100% rename from docs/user/quicktour/figures/pobProofObligations.png rename to docs/quicktour/figures/pobProofObligations.png diff --git a/docs/user/quicktour/figures/proofManagementButton.png b/docs/quicktour/figures/proofManagementButton.png similarity index 100% rename from docs/user/quicktour/figures/proofManagementButton.png rename to docs/quicktour/figures/proofManagementButton.png diff --git a/docs/user/quicktour/figures/proofObligationBrowser.png b/docs/quicktour/figures/proofObligationBrowser.png similarity index 100% rename from docs/user/quicktour/figures/proofObligationBrowser.png rename to docs/quicktour/figures/proofObligationBrowser.png diff --git a/docs/user/quicktour/figures/proofTreeTab.png b/docs/quicktour/figures/proofTreeTab.png similarity index 100% rename from docs/user/quicktour/figures/proofTreeTab.png rename to docs/quicktour/figures/proofTreeTab.png diff --git a/docs/user/quicktour/figures/proofmanagement.png b/docs/quicktour/figures/proofmanagement.png similarity index 100% rename from docs/user/quicktour/figures/proofmanagement.png rename to docs/quicktour/figures/proofmanagement.png diff --git a/docs/user/quicktour/figures/proofmanagement_paycard.png b/docs/quicktour/figures/proofmanagement_paycard.png similarity index 100% rename from docs/user/quicktour/figures/proofmanagement_paycard.png rename to docs/quicktour/figures/proofmanagement_paycard.png diff --git a/docs/user/quicktour/figures/proverWithLoadedPO.png b/docs/quicktour/figures/proverWithLoadedPO.png similarity index 100% rename from docs/user/quicktour/figures/proverWithLoadedPO.png rename to docs/quicktour/figures/proverWithLoadedPO.png diff --git a/docs/user/quicktour/figures/pruneProof.png b/docs/quicktour/figures/pruneProof.png similarity index 100% rename from docs/user/quicktour/figures/pruneProof.png rename to docs/quicktour/figures/pruneProof.png diff --git a/docs/user/quicktour/figures/saveFile.png b/docs/quicktour/figures/saveFile.png similarity index 100% rename from docs/user/quicktour/figures/saveFile.png rename to docs/quicktour/figures/saveFile.png diff --git a/docs/user/quicktour/figures/strategyTab.png b/docs/quicktour/figures/strategyTab.png similarity index 100% rename from docs/user/quicktour/figures/strategyTab.png rename to docs/quicktour/figures/strategyTab.png diff --git a/docs/user/quicktour/index.md b/docs/quicktour/index.md similarity index 100% rename from docs/user/quicktour/index.md rename to docs/quicktour/index.md diff --git a/docs/user/quicktour/install.md b/docs/quicktour/install.md similarity index 100% rename from docs/user/quicktour/install.md rename to docs/quicktour/install.md diff --git a/docs/user/quicktour/jml/gui/ChargeUI.java b/docs/quicktour/jml/gui/ChargeUI.java similarity index 100% rename from docs/user/quicktour/jml/gui/ChargeUI.java rename to docs/quicktour/jml/gui/ChargeUI.java diff --git a/docs/user/quicktour/jml/gui/IssueCardUI.java b/docs/quicktour/jml/gui/IssueCardUI.java similarity index 100% rename from docs/user/quicktour/jml/gui/IssueCardUI.java rename to docs/quicktour/jml/gui/IssueCardUI.java diff --git a/docs/user/quicktour/jml/gui/Start.java b/docs/quicktour/jml/gui/Start.java similarity index 100% rename from docs/user/quicktour/jml/gui/Start.java rename to docs/quicktour/jml/gui/Start.java diff --git a/docs/user/quicktour/jml/paycard/CardException.java b/docs/quicktour/jml/paycard/CardException.java similarity index 100% rename from docs/user/quicktour/jml/paycard/CardException.java rename to docs/quicktour/jml/paycard/CardException.java diff --git a/docs/user/quicktour/jml/paycard/LogFile.java b/docs/quicktour/jml/paycard/LogFile.java similarity index 100% rename from docs/user/quicktour/jml/paycard/LogFile.java rename to docs/quicktour/jml/paycard/LogFile.java diff --git a/docs/user/quicktour/jml/paycard/LogRecord.java b/docs/quicktour/jml/paycard/LogRecord.java similarity index 100% rename from docs/user/quicktour/jml/paycard/LogRecord.java rename to docs/quicktour/jml/paycard/LogRecord.java diff --git a/docs/user/quicktour/jml/paycard/PayCard.java b/docs/quicktour/jml/paycard/PayCard.java similarity index 100% rename from docs/user/quicktour/jml/paycard/PayCard.java rename to docs/quicktour/jml/paycard/PayCard.java diff --git a/docs/user/quicktour/loading.md b/docs/quicktour/loading.md similarity index 100% rename from docs/user/quicktour/loading.md rename to docs/quicktour/loading.md diff --git a/docs/user/quicktour/proving.md b/docs/quicktour/proving.md similarity index 100% rename from docs/user/quicktour/proving.md rename to docs/quicktour/proving.md diff --git a/docs/user/quicktour/quicktour.zip b/docs/quicktour/quicktour.zip similarity index 100% rename from docs/user/quicktour/quicktour.zip rename to docs/quicktour/quicktour.zip diff --git a/docs/user/ADTs.md b/docs/user/ADTs.md index 8d8b395..faf1467 100644 --- a/docs/user/ADTs.md +++ b/docs/user/ADTs.md @@ -1,23 +1,201 @@ +author: Alexander Weigl +date: 2023-09-24 +title: ADTs +--- + # User-defined abstract data types -Currently (as of KeY 2.4), it is not entirely possible to define new data types -as a user which are available in JML specifications. Even though functions, -predicates, and proof rules are defined in `.key` files, some things need to be -hard-coded. - -The type 'Free' is meant as a basis for adding user-defined theories. It is -used for 'quick and (not completely) dirty' addition of user-defined theories -which can be given in the taclet language. The data type is built-in into KeY -and can be accessed in JML as `\free`. In JML, functions and predicates can be -accessed through the escape keyword `\dl_` ([details](JavaDLinJML)). - -The type always contains at least one unique function 'atom', the neutral -element. Otherwise, you can define your theory around it by adding functions, -predicates, and rules. To conform with KeY's guidelines, please mark your rules -as either axiomatic or lemma. In order to prove lemma rules in KeY, axiomatic -rules need to syntactically appear before others in the file. - -The theory must be defined in file -`key/key.core/resources/de/uka/ilkd/key/proof/rules/freeADT.key`. Example -theories can be found under key/key.ui/examples/theories. Copy one of these -files to this location and run 'ant compile' in `key/key.core` +!!! abstract + + KeY allows you to define abstract data types and use them inside the logic and JML specifications. + + +## Introduction + +Abstract data types comes in many favours. Often we think on ADTs as the typical *algebraic* data type defined by the its constructor, e.g., a simple list is defined by + +```ocaml +type 'a List = Nil | Cons(a, List) +``` + +in Ocaml. But Abstract Data Types are wider category, it also contains co-inductive or non-generated data types. Let us model a set inside of KeY. Of course, a set can be modelled using a list and an uniqueness constraint on the list elements, but this model would not be able to reflect infinite sets such as natural numbers or all possible objects. Such data types are defined co-inductive, which comes in an opaque sort, and obeserver functions upon them. + +KeY supports both. + +## Algebraic Data Types (before KeY-2.14.0) + +You need to split your Algebraic Data Type into a sort and (constructor) functions. For example, a list would be defined as + +```key +\sorts { List; } +\functions{ \unique List Nil; \unique List Cons(any,List); } +``` +You can now define lists inside of JavaDL, .e.g, `Cons(1, Cons(2, Nil))` for the list $\langle 1,2 \rangle$. To reason about the list, you normally need to define an induction scheme. In KeY you declare a Taclet: + +```key +\rules { + \schemaVariables { + \schemavar List list; + \schemavar formula fml; + } + induction_on_list { + \varcond( \notFreeIn(list, fml) ) + + "Nil Case" : \add( ==> {\subst fml; Nil} fml ); + "Cons(any,List) Case" : + \add( ==> + ( \forall List l; {\subst list; l} fml ) + -> ( \forall List tail; \forall any ele; {\subst list; Cons(ele,tail)} fml ) + ); + + "Use Case" : \add( \forall List l; {\subst list; l} fml ==> ); + }; +} +``` + +The Taclet `induction_on_list` corresponds to the rule: + +$$ + \begin{matrix} + \Gamma \Rightarrow \Delta, \phi(nil) + \\ + \Gamma \Rightarrow \Delta, + (\forall x : List.~\phi(x)) \rightarrow (\forall e : Any.~\forall tail : List.~~\phi(Cons(e,tail))) + \\ + \Gamma, \forall x : List.~\phi(x) \Rightarrow \Delta + \\ \hline + \Gamma \Rightarrow \Delta, \forall x : List.~\phi(x) + \end{matrix} +$$ + +[A complete example can be found in the KeY repo, in `standard_key/adt/list.key`](https://github.com/KeYProject/key/blob/main/key.ui/examples/standard_key/adt/list.key) + +## Algebraic Data Types (with KeY-2.14.0 and beyond) + +Since version 2.14.0, the KeY grammar supports the direct notation of algebraic data types. The grammar for ADTs follows the typical syntax in KeY combined with functional language. ADTs are defined within a `\datatypes { ... }` block, and are translated onto the existing infrastructure (Sorts, Functions, Taclets). The grammar is as follows: + +```key +\datatypes { + = | ... | ; + ... + } +``` +where constructor is a function definition `( , ...)` with named arguments. From a datatype definition, we derive the following logical entities for the signature, on the example of a list `\datatypes { List = Nil | Cons(any element, List tail); }`: + +1. a sort named after the ADT name, e.g., here it would be `List`. +2. a function for each constructor which takes arguments of the constructor and evaluates to the ADT. + Here, we would have: + ```key + \functions{ List Nil(); List Cons(any,List); } + ``` +3. Three taclets for the use in reasoning on the ADT structure. + 1. Axiom taclets that adds the induction principle as an axiom on the sequence. +$$ +\frac{ +(\forall a \in ADT.~ \phi) \leftrightarrow \phi[a/c_1] \wedge \ldots \wedge \phi[a/c_n] +\Longrightarrow +}{ +\forall a \in ADT.~ \phi[a] +} +$$ + + 2. Induction taclets for proving a sentence for all ADTs. (Like the induction rule above.) +$$ +\frac{ +\begin{matrix} + \forall a \in ADT; \phi \Longrightarrow \\ + \Longrightarrow \phi[a/c_1] \\ + \Longrightarrow \ldots \\ + \Longrightarrow phi[a/c_n] +\end{matrix} +}{ +\Longrightarrow \forall a \in ADT.~ \phi[a] +} +$$ + + This taclet is a direct consequence of the induction formula. + + 3. A case distinction taclet, which allows you to split a proof attempt along the possible different values of an ADT. + + This is a direct consequence of the disjunction $x = c_1 \vee\ldots\vee x = c_n$ resulting from the construction principles of ADTs. This is valid for *generated* ADTs where the values can only be constructed using the constructors. This allows us to make a case distinction about the various constructors. + +\[ +\frac{ +\begin{matrix} + x = c_1 \Longrightarrow \\ + \ldots \Longrightarrow \\ + x = c_n \Longrightarrow +\end{matrix} +}{ + x : ADT ~ \text{(anywhere)} +} +\] + +Following our example we obtain the following taclets: + +```key +List_Axiom { + \schemaVar \formula phi; + \schemaVar \variables List x; + + \find(\forall x; phi) + \varcond(\notFreeIn(x, phi)) + \add( + \forall x; phi + <-> {\subst x;Nil}phi + & \forall List tail; \forall any head; ({\subst x;tail}phi -> {\subst x;Cons(head, tail)}phi) + ==> + ) + \displayname "Axiom for List" + } + +List_Ind { + \schemaVar \formula phi; + + "Nil": \add(==> {\subst x;Nil}phi); + "Cons(anyhead,Listtail)": + \add( + ==> + \forall tail; \forall head; ({\subst x;tail}phi -> {\subst x;Cons(head, tail)}phi) + ); + "Use case of List": + \add(\forall x; phi ==>) + \displayname "Induction for List" +} + +List_ctor_split { + \schemaVar \term MyList var; + \schemaVar \skolemTerm any head; + \schemaVar \skolemTerm MyList tail; + + \find(var) + \sameUpdateLevel + "#var = Nil": \add(var = Nil ==>); + "#var = Cons": \add(var = Cons(head, tail) ==>) + \displayname "case distinction of List" +} +``` + +## Co-inductive Data Types + +Co-inductive types are also possible in KeY. For example, the built-in sorts `Heap` and `LocSet` are co-inductive. There is no direct syntactical support for these datatypes. + + +## Using a Data Type in JML + +You can use any sort of the logical signature in JML. For this, you need the prefix the sort name with the `\dl_` to access the JavaDL scope. Some sorts are also direct built-in into JML, like `\map`, and are direct reachable. + +A typical pattern is to have a ghost variable, that represents the current state of a class by using logical datatype and uninterpreted functions. + +```java +public class MyMap { + //@ public ghost \map logical_dt; + + public void put(Object k, Object v) { + //@ set logical_dt = \dl_map_put(logical_dt, k, v); + ... + } +} +``` + +Instead of `\map` you can also use `\dl_map` which points to the same sort. diff --git a/docs/user/ProofCachingDialog.png b/docs/user/ProofCaching/ProofCachingDialog.png similarity index 100% rename from docs/user/ProofCachingDialog.png rename to docs/user/ProofCaching/ProofCachingDialog.png diff --git a/docs/user/ProofCachingStatusLine.png b/docs/user/ProofCaching/ProofCachingStatusLine.png similarity index 100% rename from docs/user/ProofCachingStatusLine.png rename to docs/user/ProofCaching/ProofCachingStatusLine.png diff --git a/docs/user/ProofCachingTree.png b/docs/user/ProofCaching/ProofCachingTree.png similarity index 100% rename from docs/user/ProofCachingTree.png rename to docs/user/ProofCaching/ProofCachingTree.png diff --git a/docs/user/ProofCaching.md b/docs/user/ProofCaching/index.md similarity index 100% rename from docs/user/ProofCaching.md rename to docs/user/ProofCaching/index.md diff --git a/docs/user/ProofSlicing.png b/docs/user/ProofSlicing/ProofSlicing.png similarity index 100% rename from docs/user/ProofSlicing.png rename to docs/user/ProofSlicing/ProofSlicing.png diff --git a/docs/user/ProofSlicingDependencyGraph.png b/docs/user/ProofSlicing/ProofSlicingDependencyGraph.png similarity index 100% rename from docs/user/ProofSlicingDependencyGraph.png rename to docs/user/ProofSlicing/ProofSlicingDependencyGraph.png diff --git a/docs/user/ProofSlicingDependencyGraphAnalyzed.png b/docs/user/ProofSlicing/ProofSlicingDependencyGraphAnalyzed.png similarity index 100% rename from docs/user/ProofSlicingDependencyGraphAnalyzed.png rename to docs/user/ProofSlicing/ProofSlicingDependencyGraphAnalyzed.png diff --git a/docs/user/ProofSlicingNewProof.png b/docs/user/ProofSlicing/ProofSlicingNewProof.png similarity index 100% rename from docs/user/ProofSlicingNewProof.png rename to docs/user/ProofSlicing/ProofSlicingNewProof.png diff --git a/docs/user/ProofSlicing.md b/docs/user/ProofSlicing/index.md similarity index 100% rename from docs/user/ProofSlicing.md rename to docs/user/ProofSlicing/index.md diff --git a/mkdocs.yml b/mkdocs.yml index 4e0cfd9..7b3077e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -46,8 +46,8 @@ markdown_extensions: permalink: true - markdown_aafigure: format: svg - - markdown_blockdiag: - format: svg +# - markdown_blockdiag: +# format: svg extra_javascript: - 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML' @@ -88,6 +88,12 @@ theme: nav: - Home: index.md + - Quicktour: + - quicktour/index.md + - quicktour/install.md + - quicktour/loading.md + - quicktour/proving.md + - quicktour/appendix.md - User Guide: - user/index.md - changelog.md @@ -99,17 +105,11 @@ nav: - user/RemoveGenerics.md - user/Polarity.md - user/JavaGrammar.md - - Quicktour: - - user/quicktour/index.md - - user/quicktour/install.md - - user/quicktour/loading.md - - user/quicktour/proving.md - - user/quicktour/appendix.md - UI Features: - user/Exploration.md - user/NodeDiff.md - - user/ProofSlicing.md - - user/ProofCaching.md + - user/ProofSlicing/index.md + - user/ProofCaching/index.md - Languages: - user/HowToTaclet.md - user/JMLGrammar.md