From 7ac669e52ef4f440c1aca2b8128981afc1b8f880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20M=C3=A9ric?= Date: Mon, 31 Jan 2022 17:38:37 +0100 Subject: [PATCH] Update invariants section --- .../scholarly_paper/2021-ITP-PMTI/paper.thy | 76 +++++++++++-------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/examples/scholarly_paper/2021-ITP-PMTI/paper.thy b/examples/scholarly_paper/2021-ITP-PMTI/paper.thy index 3766b96..ec3b6be 100644 --- a/examples/scholarly_paper/2021-ITP-PMTI/paper.thy +++ b/examples/scholarly_paper/2021-ITP-PMTI/paper.thy @@ -270,11 +270,12 @@ text\ HOL-types, allowing for formal \<^emph>\links\ to and between ontological concepts. For example, the basic concept of requirements from CENELEC 50128~@{cite "bsi:50128:2014"} is captured in ODL as follows: - \begin{isar} + @{theory_text [display,indent=10, margin=70] +\ doc_class requirement = text_element + (* derived from text_element *) ~ long_name ::"string option" (* an optional string attribute *) ~ is_concerned::"role set" (* roles working with this req. *) - \end{isar} +\} This ODL class definition maybe part of one or more Isabelle theory--files capturing the entire ontology definition. Isabelle's session management allows for pre-compiling them before being imported in the actual target documentation required to be compliant to this ontology. @@ -300,9 +301,10 @@ text\\<^dof>'s generated antiquotations are part of a general mechanism of Isabelle's standard antiquotations heavily used in various papers and technical reports. For example, in the following informal text, the antiquotation \<^verbatim>\thm refl\ refers to the reflexivity axiom from HOL: - \begin{isar} +@{theory_text [display,indent=10, margin=70] +\ textAccording to the reflexivity axiom <@>{thm refl}, we obtain in \ - for <@>{term fac 5} the result <@>{value fac 5}.\end{isar} + for <@>{term fac 5} the result <@>{value fac 5}.\} In the PDF output, this is represented as follows: \begin{out} According to the reflexivity axiom $x = x$, we obtain in \\\ for $\operatorname{fac} 5$ the result $120$. @@ -336,17 +338,18 @@ text\ A novel mechanism to specify invariants is implemented and can now be specified in common HOL syntax. % These invariants can be checked when an instance of the class is defined. -% To enable the checking of the invariants, the \<^emph>\invariants\_checking\ +% To enable the checking of the invariants, the \<^theory_text>\invariants_checking\ % theory attribute must be set: -% \begin{isar} -% declare[[invariants_checking = true]] -% \end{isar} +% @{theory_text [display,indent=10, margin=70] + \ + declare[[invariants_checking = true]] + \} If we take back the ontology example of~@{cite "brucker.ea:isabelledof:2019"}, we can now specify the constraints, like that any instance of a \<^emph>\result\ class finally has - a non-empty property list, if its \<^emph>\kind\ is \<^emph>\proof\, or that - the \<^emph>\establish\ relation between \<^emph>\claim\ and - \<^emph>\result\ is total, using the keyword \<^emph>\invariant\ in the class definition: - \begin{isar} + a non-empty property list, if its \<^theory_text>\kind\ is \<^theory_text>\proof\, or that + the \<^theory_text>\establish\ relation between \<^theory_text>\claim\ and + \<^theory_text>\result\ is total, using the keyword \<^theory_text>\invariant\ in the class definition: +@{theory_text [display,indent=10, margin=70] \ doc_class title = short_title :: "string option" <= "None" doc_class author = @@ -387,26 +390,35 @@ datatype kind = expert_opinion | argument | "proof" establish :: "(claim \ result) set" invariant total_rel :: "\ x. x \ Domain (establish \) \ (\ y \ Range (establish \). (x, y) \ establish \)" -\end{isar} +\} - In our example, the invariant \<^emph>\author\_finite\ enforces that the user sets the - \<^emph>\authored\_by\ set. - The \<^emph>\$\sigma$\ symbol is reserved and references the future instance class. + In our example, the invariant \<^theory_text>\author_finite \ enforces that the user sets the + \<^theory_text>\authored_by\ set. + The \<^theory_text>\\\ symbol is reserved and references the future instance class. By relying on the implementation of the Records in Isabelle/HOL~@{cite "wenzel:isabelle-isar:2020"}, one can reference an attribute of an instance using its selector function. - For example, \<^emph>\establish $\sigma$\ denotes the value - of the \<^emph>\establish\ attribute - of the future instance of the class \<^emph>\conclusion\. + For example, \<^theory_text>\establish \\ denotes the value + of the \<^theory_text>\establish\ attribute + of the future instance of the class \<^theory_text>\conclusion\. if we define some instances like: (ADD EXAMPLE !!!) + +@{theory_text [display,indent=10, margin=70] \ +text*[church::author, email="\church@lambda.org\"]\\ +text*[introduction1::introduction, authored_by = "{@{author \church\}}"]\\ +(*text*[introduction2::introduction]\\*) +text*[resultProof::result, evidence = "proof", property="[@{thm \HOL.refl\}]"]\\ +text*[resultArgument::result, evidence = "argument"]\\ + +\} The value of each attribute defined for the instances is checked at run-time against their class invariants. SPEAK ABOUT INVARIANTS INHERITAGE ??? - As the class \<^emph>\class\_inv2\ is a subsclass - of the class \<^emph>\class\_inv1\, it inherits \<^emph>\class\_inv1\ invariants. - Hence the \<^emph>\inv1\ invariant is checked - when the instance \<^emph>\testinv2\ is defined. + As the class \<^theory_text>\class_inv2\ is a subsclass + of the class \<^theory_text>\class_inv1\, it inherits \<^theory_text>\class_inv1\ invariants. + Hence the \<^theory_text>\inv1\ invariant is checked + when the instance \<^theory_text>\testinv2\ is defined. \ subsection\Example and Queries\ @@ -417,24 +429,24 @@ text\ A new mechanism to make query on instances is available and uses the HOL implementation of Lists. So complex queries can be defined using functions over the instances list. With the class: -\begin{isar} +@{theory_text [display,indent=10, margin=70] \ doc_class Z = z::"int" -\end{isar} +\} and some instances: -\begin{isar} +@{theory_text [display,indent=10, margin=70] \ text*[test1Z::Z, z=1]\lorem ipsum...\ text*[test2Z::Z, z=4]\lorem ipsum...\ text*[test3Z::Z, z=3]\lorem ipsum...\ -\end{isar} +\} we can get all the instances of the class Z: -\begin{isar} +@{theory_text [display,indent=10, margin=70] \ value*\@{Z-instances}\ -\end{isar} -or the instances of the class Z whose attribute z > 2: -\begin{isar} +\} +or the instances of the class Z whose attribute \<^theory_text>\z > 2\: +@{theory_text [display,indent=10, margin=70] \ value*\filter (\\. Z.z \ > 2) @{Z-instances}\ -\end{isar} +\} EXPLAIN VALUE* ??? \