(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Wolfram 14.3' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 154, 7] NotebookDataLength[ 1130492, 26060] NotebookOptionsPosition[ 1045032, 24828] NotebookOutlinePosition[ 1045440, 24844] CellTagsIndexPosition[ 1045397, 24841] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["License, terms of use and compatibility", "Section",ExpressionUUID->"48e737c5-1928-47b4-8664-7a92815820d3"], Cell[TextData[{ "This software is Copyright (C) 2024 Maciej Sobczak (", ButtonBox["www.inspirel.com)", BaseStyle->"Hyperlink", ButtonData->{ URL["http://www.inspirel.com"], None}, ButtonNote->"http://www.inspirel.com"], "." }], "Text",ExpressionUUID->"1e3d6943-9081-4c68-af40-f9421d9cf082"], Cell[TextData[{ "This file is distributed under the ", ButtonBox["GPL 3.0 license", BaseStyle->"Hyperlink", ButtonData->{ URL["https://opensource.org/license/gpl-3-0/"], None}, ButtonNote->"https://opensource.org/license/gpl-3-0/"], "." }], "Text",ExpressionUUID->"f7a311bf-bcb5-49d8-836e-a2e554fe6ab6"], Cell["\<\ This assistant is intended for evaluation and as support for education \ activities. Please contact Inspirel if you need other terms of use or if you would like \ to deploy this assistant in a professional, commercial or industrial \ environment. Or for any other reason.\ \>", "Text",ExpressionUUID->"049f7ac9-6712-4e36-977d-a604d6895794"], Cell["This notebook was entirely tested with:", "Text",ExpressionUUID->"4fcb9f02-aad4-4d19-aab4-d353015c9e2f"], Cell[CellGroupData[{ Cell[BoxData["$Version"], "Input", CellLabel-> "In[294]:=",ExpressionUUID->"9f040ab0-b22b-4d23-9489-b3072a310b6c"], Cell[BoxData["\<\"14.3.0 for Microsoft Windows (64-bit) (July 8, 2025)\"\>"], \ "Output", CellChangeTimes->{3.9721151138401833`*^9}, CellLabel-> "Out[294]=",ExpressionUUID->"0887015f-e6b0-3c44-b9ab-3bd6bccaf458"] }, {2}]], Cell["\<\ It should work with comparable Wolfram installations as well.\ \>", "Text", CellChangeTimes->{{3.9721151299862537`*^9, 3.9721151308189335`*^9}},ExpressionUUID->"00b76dfe-9af7-4f91-b113-\ 652697a60046"], Cell["\<\ Since the underlying (Wolfram) engine might change with each update, its \ capability to solve different verification problems can change, too. This \ means in that in future versions some examples and models presented here \ might be simplified.\ \>", "Text",ExpressionUUID->"991429fe-ba16-406d-94f9-5f4c603403ee"] }, Closed]], Cell[CellGroupData[{ Cell["Documentation", "Section",ExpressionUUID->"fc5bdc44-316c-4303-9749-9246a7e75626"], Cell[CellGroupData[{ Cell["How to use this document", "Subsection",ExpressionUUID->"35fe5105-53c0-406b-b030-909aeb2fd1d5"], Cell["\<\ This file is a Wolfram notebook that combines source code for useful \ functions and definitions, documentation (this section) and a set of examples.\ \>", "Text", CellChangeTimes->{{3.9721151723521156`*^9, 3.9721151732485676`*^9}},ExpressionUUID->"ec07c978-81d4-47d4-8aa5-\ 95eb808aec80"], Cell["\<\ Only the source code needs to be here to support your own work. It is \ configured as initialization code, so that it will evaluate automatically \ before any other code is executed. As such, the easiest way to use this \ notebook is to write and just evaluate your own code at the bottom of this \ notebook. Good luck!\ \>", "Text", CellChangeTimes->{{3.9721151993820457`*^9, 3.972115203523546*^9}},ExpressionUUID->"5e52fe1d-eca1-4776-90f2-\ a4567cdd1973"], Cell["\<\ The documentation part and examples can be safely removed if you need to \ reduce the size of this file, or if you prefer to work with multiple \ documents (for your own projects, perhaps) but don\[CloseCurlyQuote]t need to \ keep the copies of documentation and examples everywhere.\ \>", "Text",ExpressionUUID->"5d7b8895-14c8-43db-b33c-793b5bcd9de5"], Cell["\<\ The examples are relatively complete demonstrations of what can be done and \ can be also used as a catalogue of patterns and idioms for reuse. In a sense, \ the set of examples also serves as a set of regression tests for the main \ source code.\ \>", "Text", CellChangeTimes->{{3.972115220039665*^9, 3.9721152212499104`*^9}},ExpressionUUID->"4cc3b4cf-b9dd-4e99-b131-\ e906f57d208b"], Cell["\<\ Many examples (especially the ones for Event-B modeling) were inspired by \ models described in the book \"Modeling in Event-B\" by Jean-Raymond Abrial \ and no amount of comment can replace the complete exposition in that book, \ but still, hopefully, the models are clear enough to be understood on their \ own. Note that even though the variable names and general modeling strategy \ correspond to book examples, some details were changed to reflect the Wolfram \ syntax rules and supported theories.\ \>", "Text",ExpressionUUID->"dba0a6af-8599-45cc-a76d-2584dd3653c4"] }, Closed]], Cell[CellGroupData[{ Cell["What it can do", "Subsection",ExpressionUUID->"4befac73-5c29-4bae-892d-70d5adec30e9"], Cell["\<\ The functionality of Formal Assistant is built on top of standard Wolfram \ functions and the general capability of the Wolfram language to perform \ symbolic computations and to solve both arithmetic and logic problems. The \ Formal Assistant is supposed to be modular and extendable and to support \ these goals it is designed in layers.\ \>", "Text",ExpressionUUID->"22597b90-eb53-45ea-ae15-3354fe721e07"], Cell["\<\ The most basic layer (let\[CloseCurlyQuote]s call it \ \[OpenCurlyDoubleQuote]Level 0\[CloseCurlyDoubleQuote]) is of course the \ Wolfram system itself - everything it can do, can be embedded and mixed with \ other things, so in this sense the expressive capability of the Assistant is \ unlimited. On the other hand, the basic Wolfram functions and language syntax \ have their own limits that influence what and how things can be expressed and \ solved.\ \>", "Text",ExpressionUUID->"4383d9d3-f6ae-4b35-accc-74a4c122c022"], Cell["\<\ The first layer of added functionality (\[OpenCurlyDoubleQuote]Level 1\ \[CloseCurlyDoubleQuote]) deals with the general concept of deduction. That \ is, given a set of symbols or values, and a set of transformation rules, the \ Assistant can deduce something by repeatedly applying the given rules. The \ deduction layer can also generate a trace of deductions and can display the \ results by linking them with inputs and applicable rules.\ \>", "Text",ExpressionUUID->"32dfe053-d573-478c-b23a-5ab70f67707a"], Cell["\<\ A set of \[OpenCurlyDoubleQuote]standard rules\[CloseCurlyDoubleQuote] exist \ to support deduction by means of reducing, simplifying and solving sets of \ equations, inequalities and logic statements. These standard rules can be \ plugged explicitly to the deduction layer, but they also form implicit \ foundation for higher level functions.\ \>", "Text",ExpressionUUID->"ca107bd2-7a5a-46a6-96bc-a424beda6dc8"], Cell["\<\ Further (\[OpenCurlyDoubleQuote]Level 2\[CloseCurlyDoubleQuote]), two \ high-level functions support validation and satisfiability checks that are \ key tools in formal verification. These functions have multiple options that \ allow to plug in customized \[OpenCurlyDoubleQuote]theorems\ \[CloseCurlyDoubleQuote] that are automatically combined with given \ questions. Basic set definitions, n-ary predicates and quantifiers with those \ predicates are also supported in a way that allows to efficiently resolve \ typical verification questions.\ \>", "Text",ExpressionUUID->"8cda5970-09a9-4c68-8673-6890ac9d94cd"], Cell["\<\ Finally (\[OpenCurlyDoubleQuote]Level 3\[CloseCurlyDoubleQuote]), a \ relatively complete modeling method (inspired by Event-B) is supported by \ means of function that gathers information from the given model and generates \ multiple verification checks to ensure correctness of the model and its \ subsequent refinements.\ \>", "Text",ExpressionUUID->"cb6dc8f2-93da-4882-8ea4-7fe555f96e31"], Cell["\<\ Most likely future developments of the Formal Assistant will focus on \ expanding the capability and expressiveness of \[OpenCurlyDoubleQuote]Level 3\ \[CloseCurlyDoubleQuote] - either by improving the Event-B modeling, or by \ supporting other modeling methods.\ \>", "Text",ExpressionUUID->"38273fd8-5a01-43e2-b562-220dd0c377ad"] }, Closed]], Cell[CellGroupData[{ Cell["Base functions (Level 1)", "Subsection",ExpressionUUID->"8cd3b6ad-bda8-4d95-934d-40a0bc8aaece"], Cell[CellGroupData[{ Cell["deduceStep", "Subsubsection",ExpressionUUID->"49f884cf-1c21-408f-9486-5e0cfeaaf82d"], Cell[BoxData[ RowBox[{ RowBox[{"deduceStep", "[", RowBox[{"knowns_", ",", "rules_", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"finalTerms", "\[Rule]", RowBox[{"{", "}"}]}], ",", RowBox[{"knownIndexThreshold", "\[Rule]", "1"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", "..."}]], "Input",ExpressionUUID->"3463075c-7605-440a-bd7b-262e4b0370cd"], Cell[TextData[{ "This function performs a single deduction step and returns a list of \ results, each being a triple ", Cell[BoxData[ FormBox[ RowBox[{"{", RowBox[{"res", ",", "ruleNum", ",", "inputs"}], "}"}], TraditionalForm]], ExpressionUUID->"716bb57b-91f5-43db-8e48-9d3031773667"], ", where ", Cell[BoxData[ FormBox["res", TraditionalForm]],ExpressionUUID-> "4b0a05b7-d42d-44d7-a337-3252c211fc70"], " is a new value, ", Cell[BoxData[ FormBox["ruleNum", TraditionalForm]],ExpressionUUID-> "063a31a8-8491-46ef-b2a4-17dec5bb89e5"], " is the index of rule that produced that value and ", Cell[BoxData[ FormBox["inputs", TraditionalForm]],ExpressionUUID-> "73de854c-2960-445f-bde9-6bf60edc5df6"], " is a list of positions from knowns." }], "Text",ExpressionUUID->"6fdb8fca-9807-4614-9ce9-c5b538110ef7"], Cell[TextData[{ Cell[BoxData[ FormBox[ StyleBox["knowns", FontWeight->"Bold"], TraditionalForm]],ExpressionUUID-> "0c421f66-a761-47bf-afe4-b67e7a7dc091"], " is a list of \[OpenCurlyDoubleQuote]things\[CloseCurlyDoubleQuote] - \ values, symbols, expressions, etc." }], "Text",ExpressionUUID->"bd7f75cc-36c9-4758-8914-f20ba43eb7af"], Cell[TextData[{ StyleBox["rules", FontWeight->"Bold"], " is a list of transformation rules. Each rule (expressed with ", Cell[BoxData[ FormBox[ RowBox[{"Rule", "[", RowBox[{"a", ",", "b"}], "]"}], TraditionalForm]],ExpressionUUID-> "b4e2d377-179c-4665-99cd-861af4c8ab90"], " or just ", Cell[BoxData[ FormBox[ RowBox[{"a", "\[Rule]", "b"}], TraditionalForm]],ExpressionUUID-> "86cd4f77-7e8c-422b-a7ab-1e4b0dd10eb5"], ") defines how the elements from the list of knowns (left-hand can be a list \ for n-ary transformations) should be selected and transformed into new value \ (which can be a list as well).\nAs a special case, right-hand can be a ", Cell[BoxData[ FormBox["Function", TraditionalForm]],ExpressionUUID-> "14d7f13a-8c20-494e-92f3-55d6b18be63b"], ", which is evaluated to produce the new value.\nAll rules are applied to \ all relevant combinations of knowns (depending on arity of the given rule) in \ a single deduction step." }], "Text",ExpressionUUID->"5179017f-9d04-4aa3-aa2a-6fed1b267595"], Cell[TextData[{ StyleBox["finalTerms", FontWeight->"Bold"], " is an optional list of values (or a test ", Cell[BoxData[ FormBox["Function", TraditionalForm]],ExpressionUUID-> "15d33ff2-490d-47ab-9d98-769487efb587"], ") that terminate the deduction." }], "Text",ExpressionUUID->"25c57995-5f58-4d8a-8e7a-0b43e302bb7f"], Cell[TextData[{ StyleBox["knownIndexThreshold", FontWeight->"Bold"], " is an index in the list of knowns above which rules are applied (that is, \ knowns below that index are not used)." }], "Text",ExpressionUUID->"6ea69bbe-3a9f-4082-bb62-fcc63a827319"], Cell[TextData[{ StyleBox["verbose", FontWeight->"Bold"], " can be ", Cell[BoxData[ FormBox["False", TraditionalForm]],ExpressionUUID-> "c82b097d-d9a6-45fa-9547-31fc62030351"], ", ", Cell[BoxData[ FormBox["Counts", TraditionalForm]],ExpressionUUID-> "242aef41-ede6-4028-8164-7ed1200e3c8a"], ", ", Cell[BoxData[ FormBox["True", TraditionalForm]],ExpressionUUID-> "e029ef47-3267-4850-b2a3-9e51c9d9ad84"], " or ", Cell[BoxData[ FormBox["Automatic", TraditionalForm]],ExpressionUUID-> "3218cbd2-cbd7-4866-8806-36033fc9d4de"], " to select various levels of verbosity." }], "Text",ExpressionUUID->"12224095-bd44-42ba-a33b-d6ab7c071a8a"] }, Closed]], Cell[CellGroupData[{ Cell["deduce", "Subsubsection",ExpressionUUID->"03b970cb-42b6-47eb-a9dd-824d893de0c6"], Cell[BoxData[ RowBox[{ RowBox[{"deduce", "[", RowBox[{"knowns_List", ",", "rules_List", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"finalTerms", "\[Rule]", RowBox[{"{", "}"}]}], ",", RowBox[{"withTrace", "\[Rule]", "False"}], ",", RowBox[{"maxSteps", "\[Rule]", "10"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", "..."}]], "Input",ExpressionUUID->"9f2f2f74-d588-4fec-9eb7-cefe4257c040"], Cell["\<\ This function repeatedly performs deduction steps as long as new (distinct) \ values are produced or until a final term is reached or maximum number of \ steps is executed.\ \>", "Text",ExpressionUUID->"8c8579c2-1ad5-4962-a2d5-2531cc0c64f5"], Cell[TextData[{ StyleBox["knowns", FontWeight->"Bold"], ", ", StyleBox["rules", FontWeight->"Bold"], ", ", StyleBox["finalTerms", FontWeight->"Bold"], " and ", StyleBox["verbose", FontWeight->"Bold"], " are as in ", Cell[BoxData[ FormBox["deduceStep", TraditionalForm]],ExpressionUUID-> "dc8c7ea7-7fe8-4b43-9d02-9b3c321d754e"], "." }], "Text",ExpressionUUID->"2c435960-58ea-49d6-8727-b6d675914b46"], Cell[TextData[{ StyleBox["withTrace", FontWeight->"Bold"], " decides if the rule and input trace (in the form as in ", Cell[BoxData[ FormBox["deduceStep", TraditionalForm]],ExpressionUUID-> "8708cc50-ab44-45ed-9d72-49708753960f"], ") is part of the output, in which case it is a second element of the pair \ ", Cell[BoxData[ FormBox[ RowBox[{"{", RowBox[{"result", ",", "trace"}], "}"}], TraditionalForm]],ExpressionUUID-> "8385834f-91b7-4395-a7e9-b34b2a264eba"], "." }], "Text",ExpressionUUID->"c59d830d-49d9-4f0b-8fcd-b54fb0e22f62"], Cell[TextData[{ StyleBox["maxSteps", FontWeight->"Bold"], " is a limit on the number of deduction steps." }], "Text",ExpressionUUID->"3273e9d8-812d-4dd3-bcec-67a66c29c3a4"], Cell[TextData[{ StyleBox["verbose", FontWeight->"Bold"], " can be ", Cell[BoxData[ FormBox["False", TraditionalForm]],ExpressionUUID-> "4f374102-0d22-4601-a4e8-4f555fe957b1"], ", ", Cell[BoxData[ FormBox["Counts", TraditionalForm]],ExpressionUUID-> "76084dfb-2cdd-4f1c-99fc-e0dd761cdf2b"], ", ", Cell[BoxData[ FormBox["True", TraditionalForm]],ExpressionUUID-> "9ae1c98b-b32f-4e3f-9330-774c2c62e88f"], " or ", Cell[BoxData[ FormBox["Automatic", TraditionalForm]],ExpressionUUID-> "d633ed45-7042-4280-926e-4e4c7bdd10cb"], " to select various levels of verbosity." }], "Text",ExpressionUUID->"15c4d1dd-e2a1-4671-a53d-7ddaf6f29b83"] }, Closed]], Cell[CellGroupData[{ Cell["showSteps", "Subsubsection",ExpressionUUID->"19df8c7d-4cd5-4594-87e5-d1fedd138176"], Cell[BoxData[ RowBox[{ RowBox[{"showSteps", "[", RowBox[{"result_", ",", "rules_", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{"prune", "\[Rule]", "True"}], "}"}], "]"}]}], "]"}], ":=", "..."}]], "Input",ExpressionUUID->"5a8c315d-b3e8-444a-a4fa-0499bbec305e"], Cell[TextData[{ "This function pretty-prints the deduction trace obtained from ", Cell[BoxData[ FormBox["deduce", TraditionalForm]],ExpressionUUID-> "81575b93-3e29-4a5e-8eb1-e6da963f73cc"], "." }], "Text",ExpressionUUID->"62d746aa-ac49-4e40-80fa-2084ef38f8b6"], Cell[TextData[{ StyleBox["result", FontWeight->"Bold"], " is the output from ", Cell[BoxData[ FormBox["deduce", TraditionalForm]],ExpressionUUID-> "67419069-f8a2-413e-9ce6-e534f3bcc4d0"], " (if called using ", Cell[BoxData[ FormBox[ RowBox[{"withTrace", "\[Rule]", "True"}], TraditionalForm]],ExpressionUUID-> "68b3ec38-ffb2-4e53-a95f-ff10bf518fea"], ")." }], "Text",ExpressionUUID->"e2a5ca4a-017d-4bd2-87f7-9ebb39ffb74d"], Cell[TextData[{ StyleBox["rules", FontWeight->"Bold"], " should be the same set of rules that was used with ", Cell[BoxData[ FormBox["deduce", TraditionalForm]],ExpressionUUID-> "d8ed3178-9462-4f2c-8da2-c8e5fcd2d72c"], "." }], "Text",ExpressionUUID->"983a7dbb-6242-4f93-80a0-ddba0dd39f4a"], Cell[TextData[{ StyleBox["prune", FontWeight->"Bold"], " clears the list of results from entries that are not on paths that reached \ final ", Cell[BoxData[ FormBox["True", TraditionalForm]],ExpressionUUID-> "02d8febf-639c-46e0-bf4f-3868abf10015"], " or ", Cell[BoxData[ FormBox["False", TraditionalForm]],ExpressionUUID-> "92d80dec-c460-41c1-a57a-20260639300b"], " values." }], "Text", CellChangeTimes->{ 3.9721155143158207`*^9},ExpressionUUID->"e87a9373-fd30-4f37-bf7e-\ 4af7e411b1bb"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Validators (Level 2)", "Subsection",ExpressionUUID->"9ac8df9b-5aad-4273-a15a-49554907af48"], Cell[CellGroupData[{ Cell["validate", "Subsubsection",ExpressionUUID->"18f3f333-93c3-4a9c-b7c8-f8b2f7219476"], Cell[BoxData[ RowBox[{ RowBox[{"validate", "[", RowBox[{"knowns_", ",", "question_", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"theorems", "\[Rule]", RowBox[{"{", "}"}]}], ",", RowBox[{"maxSteps", "\[Rule]", "3"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", "..."}]], "Input",ExpressionUUID->"15f4e08c-adc3-4789-a0d5-5f1a1e7c2ddc"], Cell[TextData[{ "This function performs the test for implication ", Cell[BoxData[ FormBox[ RowBox[{"knowns", "\[Implies]", "question"}], TraditionalForm]], ExpressionUUID->"8e3bdbe9-cb32-43f5-9769-d346f3785b6e"], " and returns ", Cell[BoxData[ FormBox["False", TraditionalForm]],ExpressionUUID-> "b1b422cb-1908-4c3d-a54b-cb7a2236a7ab"], ", ", Cell[BoxData[ FormBox["True", TraditionalForm]],ExpressionUUID-> "b2e026cb-7c93-4598-996c-7b5d93be95e2"], " or ", Cell[BoxData[ FormBox["Indeterminate", TraditionalForm]],ExpressionUUID-> "6fe853f8-5c49-4526-81c8-7d90ffb0a681"], " (if the result cannot be computed or confirmed either way using available \ methods)." }], "Text",ExpressionUUID->"16eae217-3d00-4558-9348-2113c2dc8352"], Cell[TextData[{ StyleBox["knowns", FontWeight->"Bold"], " is a conjunction (", Cell[BoxData[ FormBox[ RowBox[{"And", "[", "...", "]"}], TraditionalForm]],ExpressionUUID-> "ccaf1500-c1bb-455d-806e-6739eae19751"], ") of terms or a single term.\nThe term can be:\n- equation (like ", Cell[BoxData[ FormBox[ RowBox[{"x", "==", "0"}], TraditionalForm]],ExpressionUUID-> "280f86b5-a89c-4275-a493-bcf9186ff8f5"], ", ", Cell[BoxData[ FormBox[ RowBox[{"y", "==", RowBox[{"x", "+", "1"}]}], TraditionalForm]],ExpressionUUID-> "538bca47-5da5-476d-bc92-8406f34c5161"], ", ", Cell[BoxData[ FormBox[ RowBox[{"z", "==", "True"}], TraditionalForm]],ExpressionUUID-> "8f1862f2-6a35-476e-a675-fec58193c0bf"], ", etc.),\n- inequality (like ", Cell[BoxData[ FormBox[ RowBox[{"x", ">", "0"}], TraditionalForm]],ExpressionUUID-> "10238aae-4e3f-4ddb-9c5d-0f4d2da827f1"], ", ", Cell[BoxData[ FormBox[ RowBox[{"0", "\[LessEqual]", "x", "\[LessEqual]", RowBox[{"y", "+", "7"}]}], TraditionalForm]],ExpressionUUID-> "4b8710c7-7f08-4622-8763-d66dc0e1073c"], ", etc.),\n- declaration of domain or set membership (like ", Cell[BoxData[ FormBox[ RowBox[{"x", "\[Element]", "Integers"}], TraditionalForm]],ExpressionUUID-> "c0c43894-3fb5-4c5d-b565-93a7675fbc8a"], ", ", Cell[BoxData[ FormBox[ RowBox[{"y", "\[Element]", "Booleans"}], TraditionalForm]],ExpressionUUID-> "f3d7a34f-030d-4ea8-abc8-d0b744caf635"], ", ", Cell[BoxData[ FormBox[ RowBox[{"z", "\[Element]", RowBox[{"{", RowBox[{"1", ",", "2", ",", "3", ",", "4"}], "}"}]}], TraditionalForm]], ExpressionUUID->"0a0fe28d-b6f3-44be-a9dc-b11178d184ee"], ", etc.),\n- free n-ary predicate (like ", Cell[BoxData[ FormBox[ RowBox[{"P", "[", RowBox[{"x", ",", "y"}], "]"}], TraditionalForm]],ExpressionUUID-> "3e3e0a3c-a3e1-45a3-8e45-95ceffce43e4"], ", but it is expected that the same predicate is used somewhere in knowns or \ question within a quantifier), negation of such predicate (like ", Cell[BoxData[ FormBox[ RowBox[{"\[Not]", RowBox[{"P", "[", RowBox[{"x", ",", "y"}], "]"}]}], TraditionalForm]],ExpressionUUID-> "7fadf1f0-dc8e-4567-bc86-0f0941385d2c"], ") or\n- quantified expression (", Cell[BoxData[ FormBox["ForAll", TraditionalForm]],ExpressionUUID-> "ed0a5b07-5312-4956-b726-630ff6f75f3b"], " or ", Cell[BoxData[ FormBox["Exists", TraditionalForm]],ExpressionUUID-> "2e7a05f7-daf9-447c-be9c-460b85bc1ace"], ") over a single variable with (possibly negated) n-ary predicate as the \ only quantified expression (like ", Cell[BoxData[ FormBox[ RowBox[{"ForAll", "[", RowBox[{"x", ",", RowBox[{"0", "\[LessEqual]", "x", "\[LessEqual]", "10"}], ",", RowBox[{"P", "[", "x", "]"}]}], "]"}], TraditionalForm]],ExpressionUUID-> "59280288-a51d-4043-9819-4e17e3bc0c02"], ").\nNote that predicates, on their own, should be undefined symbols - it is \ their interaction with quantifiers and other instances of the same (or \ negated) predicates that allows them to be replaced with ultimate logic \ values. In this sense predicates are always \[OpenCurlyDoubleQuote]ghost\ \[CloseCurlyDoubleQuote] predicates.\nFor convenience, ", Cell[BoxData[ FormBox[ RowBox[{"Span", "[", RowBox[{"a", ",", "b"}], "]"}], TraditionalForm]],ExpressionUUID-> "ec33bdbc-1653-49d2-b51f-70c516568b2a"], " is recognized as well and resolves to appropriate inequality, depending on \ the way it is used.\nMany of the standard Wolfram functions can be also used \ as parts of these expressions - in principle, all the functions that can be \ used within ", ButtonBox["FullSimplify", BaseStyle->"Hyperlink", ButtonData->{ URL["https://reference.wolfram.com/language/ref/FullSimplify.html"], None}, ButtonNote-> "https://reference.wolfram.com/language/ref/FullSimplify.html"], ", ", ButtonBox["Reduce", BaseStyle->"Hyperlink", ButtonData->{ URL["https://reference.wolfram.com/language/ref/Reduce.html"], None}, ButtonNote->"https://reference.wolfram.com/language/ref/Reduce.html"], " and ", ButtonBox["FindInstance", BaseStyle->"Hyperlink", ButtonData->{ URL["https://reference.wolfram.com/language/ref/FindInstance.html"], None}, ButtonNote-> "https://reference.wolfram.com/language/ref/FindInstance.html"], "." }], "Text",ExpressionUUID->"22ef0d0a-509f-42f5-a00f-3b466468b41b"], Cell[TextData[{ StyleBox["question", FontWeight->"Bold"], " is a conjunction of terms or a single term (as in knowns)." }], "Text",ExpressionUUID->"14af27ce-4d54-408b-b55a-4d23cdd8b9eb"], Cell[TextData[{ StyleBox["theorems", FontWeight->"Bold"], " is a list of ", Cell[BoxData[ FormBox[ RowBox[{"\"\\"", "\[Rule]", "theorem"}], TraditionalForm]], ExpressionUUID->"a230b074-d061-4033-8828-d6efd37def3a"], ", where theorem is one of:\n- implication of the form ", Cell[BoxData[ FormBox[ RowBox[{"A", "\[Implies]", "B"}], TraditionalForm]],ExpressionUUID-> "42885104-4b7c-4cf1-aa5a-7e85aa97128d"], " or ", Cell[BoxData[ FormBox[ RowBox[{ RowBox[{ RowBox[{ SubscriptBox["A", "1"], "\[And]", SubscriptBox["A", "2"], "\[And]"}], "..."}], "\[Implies]", "C"}], TraditionalForm]],ExpressionUUID->"7945f82f-e009-4beb-9278-b1d800de5955"], " - in this case, if A is found among top-level terms in knowns, C is \ automatically added to knowns as well,\n- replacement of the form ", Cell[BoxData[ FormBox[ RowBox[{"A", "\[Rule]", "B"}], TraditionalForm]],ExpressionUUID-> "41e4d12f-7e9b-4bd6-b0d9-52efa8cc3796"], " - such rules are applied to both knowns and question with the use of \ standard ", ButtonBox["ReplaceAll", BaseStyle->"Hyperlink", ButtonData->{ URL["https://reference.wolfram.com/language/ref/ReplaceAll.html"], None}, ButtonNote->"https://reference.wolfram.com/language/ref/ReplaceAll.html"], " function.\n- ", Cell[BoxData[ FormBox[ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", RowBox[{"knowns", ",", "question"}], "}"}], ",", " ", "..."}], "]"}], TraditionalForm]],ExpressionUUID->"bc583414-277e-4cf2-afb3-067eeedc3ae1"], " or separately defined function of the same profile, which can rewrite the \ whole set in arbitrary way." }], "Text",ExpressionUUID->"3adccaa8-02da-45b8-bac0-21e1ffdecc7a"], Cell[TextData[{ StyleBox["maxSteps", FontWeight->"Bold"], " is a limit on the number of deduction steps." }], "Text",ExpressionUUID->"be5e9870-61c7-4605-82af-65fd9d209e5b"], Cell[TextData[{ StyleBox["verbose", FontWeight->"Bold"], " can be ", Cell[BoxData[ FormBox["False", TraditionalForm]],ExpressionUUID-> "efce7647-39fb-4308-b0cf-6406eec56dfd"], ", ", Cell[BoxData[ FormBox["Monitor", TraditionalForm]],ExpressionUUID-> "b0093a54-55c7-456a-8222-2141544fe287"], ", ", Cell[BoxData[ FormBox["Counts", TraditionalForm]],ExpressionUUID-> "a8e64155-f4cb-434e-a587-f99bb76f6be0"], ", ", Cell[BoxData[ FormBox["True", TraditionalForm]],ExpressionUUID-> "4f90f853-a892-4f8f-b59e-dae52d10a877"], " or ", Cell[BoxData[ FormBox["Automatic", TraditionalForm]],ExpressionUUID-> "f274047e-8604-492f-b122-3e77cf1e54b2"], " to select various levels of verbosity." }], "Text",ExpressionUUID->"569d3a10-c2b6-4648-addc-05babef62ec4"] }, Closed]], Cell[CellGroupData[{ Cell["validatePiecewise", "Subsubsection",ExpressionUUID->"c30e0023-0e7e-496f-b7d1-9481d14088f8"], Cell[BoxData[ RowBox[{ RowBox[{"validatePiecewise", "[", RowBox[{"knowns_", ",", "question_", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"theorems", "\[Rule]", RowBox[{"{", "}"}]}], ",", RowBox[{"parallel", "\[Rule]", "False"}], ",", RowBox[{"maxSteps", "\[Rule]", "3"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", "..."}]], "Input",ExpressionUUID->"537bff3f-45b9-4649-a141-54112cd1e641"], Cell[TextData[{ "This function has the same purpose and arguments as validate, but \ identifies variables of finite domains (", Cell[BoxData[ FormBox["Booleans", TraditionalForm]],ExpressionUUID-> "0e815a26-0b6f-46c4-ab6a-ba47cd09b6cf"], " and simple sets) and validates the given problem separately for each \ possible value assignments for all such variables. As such, it offers a \ trade-off:\n- it replaces a single problem with multiple (possibly large \ number) other problems, but\n- each of them can be a lot simpler to solve \ than the original." }], "Text",ExpressionUUID->"db1d1477-7775-41bc-8f01-8eeb728c79c5"], Cell["\<\ This function should be treated as a backup solution if validate takes too \ long or fails to solve the given problem. On the other hand, the possibility \ to solve those smaller problems in multiple parallel kernels (if the target \ platform allows that) might offer performance improvements.\ \>", "Text",ExpressionUUID->"20003995-1eba-46a8-9eb1-824864fa9b75"], Cell["All arguments have the same meaning as in validate, except:", "Text",ExpressionUUID->"95347e60-c69c-40ec-8f15-f34a20113199"], Cell[TextData[{ StyleBox["parallel", FontWeight->"Bold"], " attempts to launch individual validations in separate kernels." }], "Text",ExpressionUUID->"016244fd-eded-4694-98df-dd3ac09d3133"] }, Closed]], Cell[CellGroupData[{ Cell["satisfy", "Subsubsection",ExpressionUUID->"b0685d02-98f4-4c6c-8a96-261de66b2903"], Cell[BoxData[ RowBox[{ RowBox[{"satisfy", "[", RowBox[{"problem_", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"theorems", "\[Rule]", RowBox[{"{", "}"}]}], ",", RowBox[{"maxSteps", "\[Rule]", "3"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", "..."}]], "Input",ExpressionUUID->"d2465f80-164c-46d3-894b-4427d75333ac"], Cell[TextData[{ "This function checks if the given problem has at least one solution and \ returns ", Cell[BoxData[ FormBox["False", TraditionalForm]],ExpressionUUID-> "5ed305cd-698c-4c41-a5df-250a96599276"], ", ", Cell[BoxData[ FormBox["True", TraditionalForm]],ExpressionUUID-> "1d3c6c4e-aa5c-4da5-975e-4c770faf9b84"], " or ", Cell[BoxData[ FormBox["Indeterminate", TraditionalForm]],ExpressionUUID-> "f6400adc-28f8-439d-9cda-cc2efc1c17a6"], " (if the result cannot be computed or confirmed either way using available \ methods)." }], "Text",ExpressionUUID->"d7dd9afa-6c0c-4207-9a02-4958db6a6c46"], Cell[TextData[{ StyleBox["problem", FontWeight->"Bold"], " is a conjunction of terms, interpreted as knowns in validate." }], "Text",ExpressionUUID->"7ddad528-0bed-44d2-be71-3b22e8e7375f"], Cell["The remaining options are treated as in validate.", "Text",ExpressionUUID->"09a4a870-a4a7-4144-9137-2000f05f37b1"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Event-B modeling (Level 3)", "Subsection",ExpressionUUID->"1d9f9266-219e-4ec9-99a2-ac1d74e6fa2f"], Cell[CellGroupData[{ Cell["validateModel", "Subsubsection",ExpressionUUID->"70e7242e-3e6b-497b-bf05-b5dac925bbd1"], Cell[BoxData[ RowBox[{ RowBox[{"validateModel", "[", RowBox[{"m_model", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"onlyPhase", "\[Rule]", "\"\<*\>\""}], ",", RowBox[{"onlyEvents", "\[Rule]", "\"\<*\>\""}], ",", RowBox[{"onlyInvariants", "\[Rule]", "\"\<*\>\""}], ",", RowBox[{"method", "\[Rule]", "Full"}], ",", RowBox[{"parallel", "\[Rule]", "False"}], ",", RowBox[{"showProofs", "\[Rule]", "False"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", "..."}]], "Input",ExpressionUUID->"16f61d5e-f7f3-4167-b3a4-18b5eed50358"], Cell["\<\ This function validates the given model by generating appropriate \ verification checks, evaluating them and printing results.\ \>", "Text",ExpressionUUID->"774f3f9b-9ff8-4342-8e7d-4f23f84f68da"], Cell[TextData[{ StyleBox["m", FontWeight->"Bold"], " is a model to be checked. The model can contain axioms, theorems, \ invariants, variants, initialization conditions and events with guards and \ actions. It can also refine one more abstract model. See the list of special \ symbols that can be used to define models below." }], "Text",ExpressionUUID->"657fc7c5-9dbd-426b-8417-3d9645d586db"], Cell[TextData[{ StyleBox["onlyPhase", FontWeight->"Bold"], " is a string pattern that selects the particular verification phases to be \ executed. Possible phase names are:\n- init,\n- events,\n- guards,\n- \ invariants,\n- superposition,\n- convergence,\n- deadlock." }], "Text",ExpressionUUID->"d6d4ffcb-d5d0-44d0-a64f-00bf9a798b05"], Cell[TextData[{ StyleBox["onlyEvents", FontWeight->"Bold"], " is a string pattern that selects the names of events to be verified." }], "Text",ExpressionUUID->"f263156c-f010-472f-ba33-07e64f551783"], Cell[TextData[{ StyleBox["onlyInvariants", FontWeight->"Bold"], " is a string pattern that selects the names of invariants to be verified." }], "Text",ExpressionUUID->"7ae5e6f8-bd27-4670-bb95-476dc1fa024e"], Cell[TextData[{ StyleBox["method", FontWeight->"Bold"], " is one of:\n- Full, which tries to solve every generated model check at \ once, or\n- Piecewise, which detects Boolean variables and simple set \ membership declarations and tries to solve the given problem with all \ possible replacements of those variables with their domains\[CloseCurlyQuote] \ values.\nFor each check generated for the model, Piecewise execution \ transforms a (possibly large) single problem into many simpler problems, \ which might help in cases where underlying methods cannot cope with original \ statements. Piecewise execution might be slower (because there are many \ invocations of underlying Wolfram functions instead of one) or faster \ (because after replacing some of the variables with constant values the \ problem can be significantly simpler to solve). When combined with ", Cell[BoxData[ FormBox[ RowBox[{"parallel", "\[Rule]", "True"}], TraditionalForm]],ExpressionUUID-> "ef8302df-fa13-485e-8ebb-4688aab1860a"], ", Piecewise execution of those simplified problems in every model check is \ parallelized, but individual model checks are processed in sequence." }], "Text",ExpressionUUID->"87dd86f3-3ebe-4f74-8765-eca40593c1eb"], Cell[TextData[{ StyleBox["parallel", FontWeight->"Bold"], " indicates whether parallel execution of model checks is intended. If \ method is Full (see above), then model checks are parallelized across \ multiple invariants; if method is Piecewise, individual model checks are \ processed in sequence, but they are potentially parallelized across Boolean \ and set membership replacements." }], "Text",ExpressionUUID->"b58e2707-0327-4293-bd5b-a33e558875de"], Cell[TextData[{ StyleBox["showProofs", FontWeight->"Bold"], " allows to print, in tabular form, the knowns and questions for each \ generated model check. This option helps in debugging failing checks." }], "Text",ExpressionUUID->"c2f1fdf4-0d39-4e90-b626-05e98ce3621e"], Cell[TextData[{ StyleBox["verbose", FontWeight->"Bold"], " can be ", Cell[BoxData[ FormBox["Total", TraditionalForm]],ExpressionUUID-> "d62d0a23-a2f5-4069-a51b-fd98e0ff1ff9"], ", ", Cell[BoxData[ FormBox["Less", TraditionalForm]],ExpressionUUID-> "88c60f91-4162-4213-9152-47b123446e2e"], ", ", Cell[BoxData[ FormBox["False", TraditionalForm]],ExpressionUUID-> "5abaa94f-220d-462e-ab5d-659c47bd15d4"], ", ", Cell[BoxData[ FormBox["Monitor", TraditionalForm]],ExpressionUUID-> "0c2386a8-bf5c-466a-98f8-e7949329c77b"], ", ", Cell[BoxData[ FormBox["Counts", TraditionalForm]],ExpressionUUID-> "01a2435a-342c-4476-95b8-4136235fb4ad"], ", ", Cell[BoxData[ FormBox["True", TraditionalForm]],ExpressionUUID-> "a12acc35-1a36-4f83-abe0-3f03d1747c0d"], " or ", Cell[BoxData[ FormBox["Automatic", TraditionalForm]],ExpressionUUID-> "01360101-5538-4586-884c-f5025221510a"], " to select various levels of verbosity." }], "Text",ExpressionUUID->"bc82dcef-d402-4de9-94ad-16039eb4dc51"] }, Closed]], Cell[CellGroupData[{ Cell["Model checks", "Subsubsection",ExpressionUUID->"97c9bfa7-af97-4efa-b2c9-84b408ea4de3"], Cell["\<\ See \[OpenCurlyDoubleQuote]Event-B verification \ checks\[CloseCurlyDoubleQuote] subsection in examples (below) for a \ demonstration of possible model checks.\ \>", "Text",ExpressionUUID->"4732efae-18c2-4639-8ad5-3756a4a0f193"] }, Closed]], Cell[CellGroupData[{ Cell["Symbols with special meaning in models", "Subsubsection",ExpressionUUID->"17d41d22-2a75-4e33-ae8b-58eac1fdfb15"], Cell["\<\ The Event-B modeling layer is built on top of regular Wolfram syntax and is \ governed by all Wolfram grammar and operator precedence rules. Still, some \ symbols have special meaning that contribute to the model structure and its \ expressive power (the actual strategies of using these elements in modeling \ activities are beyond the scope of this documentation):\ \>", "Text",ExpressionUUID->"d4070909-48a1-4c29-a8c9-cfc77af25f46"], Cell[TextData[{ StyleBox["model", FontWeight->"Bold"], " is a main wrapper for the model description:" }], "Text",ExpressionUUID->"df57e262-46d6-4f46-ba2c-fc6fc856ba62"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "...", "]"}]}], ";"}]], "Input",ExpressionUUID->\ "9023bd44-baf7-4cc1-a1a4-6c20dc935215"], Cell[TextData[{ StyleBox["refines", FontWeight->"Bold"], " can appear once at top level in the model and indicates the base \ (abstract) model, which is refined by the given model." }], "Text",ExpressionUUID->"1e234441-ff8f-4ecd-8497-b82b6145b314"], Cell[BoxData[{ RowBox[{ RowBox[{"myBaseModel", "=", RowBox[{"model", "[", "...", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myBaseModel", "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"myModel", " ", "refines", " ", "myBaseModel"}], " ", "*)"}], "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input",ExpressionUUID->"22f6d11b-186c-4b08-813f-e3e6935f3d2c"], Cell[TextData[{ StyleBox["axiom", FontWeight->"Bold"], " can appear at top level in the model and introduces an axiom to the set of \ knowns in all generated checks:" }], "Text",ExpressionUUID->"35d2a99d-72c7-471b-918d-cfc9a3dd009b"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", ">", RowBox[{ "0", " ", "is", " ", "present", " ", "in", " ", "knowns", " ", "of", " ", "all", " ", "checks"}]}], " ", "*)"}], "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->\ "0320efc7-0356-4f9d-aea1-9bb190c5b5ba"], Cell[TextData[{ StyleBox["invariant", FontWeight->"Bold"], " can appear at top level in the model and introduces an invariant that is \ verified and used as a known depending on the particular model check:" }], "Text",ExpressionUUID->"168e37bd-5825-43ed-8a15-1374020e3aa1"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", ">", RowBox[{ "0", " ", "is", " ", "verified", " ", "and", " ", "used", " ", "in", " ", "knowns", " ", "of", " ", "some", " ", "checks"}]}], " ", "*)"}], "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"c2fc3a15-fa42-44d7-ab6f-33fa4e162aaa"], Cell[TextData[{ StyleBox["variant", FontWeight->"Bold"], " can appear at top level in the model and introduces a variant for \ convergent events:" }], "Text",ExpressionUUID->"60a67650-0d01-4643-aee8-c431f39c3ace"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "-", "a"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"n", "-", RowBox[{ "a", " ", "is", " ", "verified", " ", "to", " ", "be", " ", "non"}], "-", RowBox[{ "negative", " ", "and", " ", "decreasing", " ", "in", " ", "each", " ", "convergent", " ", "event"}]}], " ", "*)"}], "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->\ "92735e22-1dfe-4644-ae5f-9d5bf02cbaa8"], Cell[TextData[{ StyleBox["theorem", FontWeight->"Bold"], " can appear at top level in the model and introduces a transformation step \ that is applied to knowns and questions before the attempt to solve a given \ problem (theorems are applied in order):" }], "Text",ExpressionUUID->"c77c25eb-2d99-4136-8d38-7b774ef893d9"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", RowBox[{"A", "\[Implies]", "B"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ "if", " ", "A", " ", "is", " ", "present", " ", "at", " ", "top"}], "-", RowBox[{"level", " ", "in", " ", "knowns"}]}], ",", " ", RowBox[{ "B", " ", "will", " ", "be", " ", "added", " ", "to", " ", "knowns", " ", "as", " ", "well"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", RowBox[{"A", "\[Rule]", "B"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"A", "\[Rule]", RowBox[{ "B", " ", "replacement", " ", "is", " ", "applied", " ", "across", " ", "the", " ", "whole", " ", "problem"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", "myTheorem"}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "myTheorem", " ", "is", " ", "a", " ", "function", " ", "that", " ", "can", " ", "arbitrarily", " ", "process", " ", "and", " ", "transform", " ", "both", " ", "knowns", " ", "and", " ", "question", " ", "for", " ", "all", " ", "generated", " ", "checks"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"8a8152d4-\ 66a2-424c-a165-2071df0fe49e"], Cell[TextData[{ StyleBox["init", FontWeight->"Bold"], " can appear at top level in the model and introduces initial conditions for \ invariants:" }], "Text",ExpressionUUID->"935c6fe0-2af8-4338-94be-ee3ef95b2560"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", "7"}], ",", RowBox[{"b", "\[Rule]", "42"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "initial", " ", "values", " ", "for", " ", "variables", " ", "a", " ", "and", " ", "b"}], " ", "*)"}], "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"71790b16-\ b2bc-4d90-aef3-b1cae4d83fe0"], Cell[TextData[{ StyleBox["event", FontWeight->"Bold"], " can appear at top level in the model:" }], "Text",ExpressionUUID->"f5f5efbf-bef0-4205-89f4-f78ca0209981"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"event", "[", RowBox[{"\"\\"", ",", "..."}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"(", "optional", ")"}], " ", "guards", " ", "and", " ", "actions"}], " ", "*)"}], "]"}], ",", "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"a93e8c2c-\ 24c6-447e-ab5a-9b6a8e0b3c07"], Cell[TextData[{ StyleBox["when", FontWeight->"Bold"], " is an optional guard for the event:" }], "Text",ExpressionUUID->"1cbb3c67-bc2b-4525-8706-0c7d2310e51b"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", ">", "b"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", ">", RowBox[{ "b", " ", "is", " ", "a", " ", "condition", " ", "for", " ", "the", " ", "event", " ", "to", " ", "be", " ", "activated"}]}], " ", "*)"}], "\[IndentingNewLine]", "..."}], " ", RowBox[{"(*", " ", "actions", " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->\ "133b19c2-c0eb-4aad-b3d6-890a117828f7"], Cell[TextData[{ StyleBox["convergent", FontWeight->"Bold"], " or ", StyleBox["convergent[]", FontWeight->"Bold"], " is an explicit declaration (or suppression, if negated) of convergence for \ the event (new non-refining events in refined models are convergent by \ default) - the given event is supposed to strictly decrease the model\ \[CloseCurlyQuote]s variant.\n", StyleBox["anticipated", FontWeight->"Bold"], " or ", StyleBox["anticipated[]", FontWeight->"Bold"], " is a declaration of \[OpenCurlyDoubleQuote]weak\[CloseCurlyDoubleQuote] \ convergence - the given event is supposed not to increase the model\ \[CloseCurlyQuote]s variant:" }], "Text", CellChangeTimes->{{3.97211601679582*^9, 3.9721160977727146`*^9}, { 3.972116197550228*^9, 3.9721162087775593`*^9}},ExpressionUUID->"e0d004f9-1196-4b1e-89fb-\ b23afd85842a"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"variant", "[", RowBox[{"(*", " ", "...", " ", "*)"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", "convergent", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"this", " ", "event", " ", "is", " ", "convergent"}], " ", "-", " ", RowBox[{"variant", " ", "should", " ", "decrease"}]}], " ", "*)"}], "\[IndentingNewLine]", "..."}], " ", RowBox[{"(*", " ", RowBox[{"guards", " ", "and", " ", "actions"}], " ", "*)"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"this", " ", "event", " ", "is", " ", "anticipated"}], " ", "-", " ", RowBox[{"variant", " ", "should", " ", "not", " ", "increase"}]}], " ", "*)"}], "\[IndentingNewLine]", "anticipated", ",", "\[IndentingNewLine]", "..."}], " ", RowBox[{"(*", " ", RowBox[{"guards", " ", "and", " ", "actions"}], " ", "*)"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"\[Not]", "convergent"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "this", " ", "event", " ", "is", " ", "NOT", " ", "convergent"}], " ", "-", " ", RowBox[{"variant", " ", "is", " ", "not", " ", "checked"}]}], " ", "*)"}], "\[IndentingNewLine]", "..."}], " ", RowBox[{"(*", " ", RowBox[{"guards", " ", "and", " ", "actions"}], " ", "*)"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.9721161116613464`*^9, 3.972116186534523*^9}},ExpressionUUID->"0382534b-bbbd-496b-bdf5-\ 9c652a66eaa7"], Cell[TextData[{ StyleBox["Rule", FontWeight->"Bold"], " expresses initialization and event actions, it looks like (and in fact is, \ internally) a replacement rule:" }], "Text",ExpressionUUID->"ab3ba26a-ee92-4a84-9078-8a60bd571f5f"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "\[Rule]", "7"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "initial", " ", "value", " ", "for", " ", "variable", " ", "a"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}]}], " ", RowBox[{"(*", " ", RowBox[{ "a", " ", "is", " ", "incremented", " ", "by", " ", "this", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"415f198c-e7af-4519-a0b5-f6178a4adbb3"], Cell[TextData[{ StyleBox["Rule", FontWeight->"Bold"], " also allows to explicitly name a base event for refining event (be default \ events refine base events of the same name):" }], "Text",ExpressionUUID->"8230cf9a-80a6-42dd-9826-233c0f6b8d92"], Cell[BoxData[{ RowBox[{ RowBox[{"myBaseModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "..."}], "]"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myBaseModel", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{"\"\\"", " ", "refines", " ", "\"\\""}], " ", "*)"}], "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input",ExpressionUUID\ ->"36e33723-deda-4ed5-aed4-724b3149aa1f"], Cell[TextData[{ StyleBox["List", FontWeight->"Bold"], " allows to group initialization and event actions, guard conditions and \ multiple base events in the event refinement declaration:" }], "Text",ExpressionUUID->"deee0c5b-0724-4ed4-a152-ffd258b3577e"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "...", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", "7"}], ",", RowBox[{"b", "\[Rule]", "42"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"multiple", " ", "initializations"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"multiple", " ", "base", " ", "events"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", ">", "b"}], ",", RowBox[{"c", ">", "d"}]}], "}"}], ",", " ", RowBox[{"(*", " ", RowBox[{"multiple", " ", "guards", " ", RowBox[{"(", RowBox[{"same", " ", "as", " ", "AND"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}], ",", RowBox[{"b", "\[Rule]", "0"}]}], "}"}]}], " ", RowBox[{"(*", " ", RowBox[{"multiple", " ", "actions"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"1425aacc-9a0c-470f-9218-0b07a7499681"], Cell[TextData[{ StyleBox["Null", FontWeight->"Bold"], " is equivalent to an empty list:" }], "Text",ExpressionUUID->"cb4dfd62-eeae-47ff-987c-769ff5f0b8c4"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", ">", "b"}], ",", "\[IndentingNewLine]", "Null"}], " ", RowBox[{"(*", " ", RowBox[{"no", " ", "action", " ", RowBox[{"(", RowBox[{ "useful", " ", "to", " ", "mark", " ", "a", " ", "terminating", " ", "event", " ", "in", " ", "a", " ", "state", " ", "machine"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"2a1d9101-\ f353-4b06-a2b1-390eb9d132b9"], Cell[TextData[{ StyleBox["Element", FontWeight->"Bold"], " defines domain and simple set membership:" }], "Text",ExpressionUUID->"2c63ec20-c4fd-4c8f-8c48-ee7c28dcbb81"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"k", "\[Element]", TemplateBox[{}, "Integers"]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "k", " ", "is", " ", "expected", " ", "to", " ", "be", " ", "an", " ", "Integer"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"m", "\[Element]", RowBox[{"{", RowBox[{"7", ",", "42", ",", "101"}], "}"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "m", " ", "is", " ", "one", " ", "of", " ", "these", " ", "values"}], " ", "*)"}], "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"fc80f5a6-1926-4434-bb91-\ 936ec9a29d88"], Cell[TextData[{ StyleBox["Span", FontWeight->"Bold"], " defines a range:" }], "Text",ExpressionUUID->"2666b3be-bfaa-468a-8437-5b416c5fe63f"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"r", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"equivalent", " ", "to", " ", "1"}], " ", "\[LessEqual]", " ", "r", " ", "\[LessEqual]", " ", "n"}], " ", "*)"}], "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"552bd01c-4b89-44fb-8d3a-b84c96c17b25"], Cell[TextData[{ StyleBox["Exists", FontWeight->"Bold"], " and ", StyleBox["ForAll", FontWeight->"Bold"], " can be used with predicates:" }], "Text",ExpressionUUID->"fa2c17b5-c382-42e9-b9f6-17257612df7d"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ForAll", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", RowBox[{"r", "-", "1"}]}], "]"}]}], ",", RowBox[{"\[Not]", RowBox[{"good", "[", "x", "]"}]}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"Exists", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"r", ",", "n"}], "]"}]}], ",", RowBox[{"good", "[", "x", "]"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"098c5786-ded7-439f-8df2-8fd96e97262e"], Cell[TextData[{ StyleBox["deadlockFree", FontWeight->"Bold"], " or ", StyleBox["deadlockFree[]", FontWeight->"Bold"], " can appear at top level of the model and switches on checks for deadlock \ freedom (that disjunction of all event guards covers the whole space defined \ by invariants):" }], "Text", CellChangeTimes->{{3.9721162457117023`*^9, 3.972116249226904*^9}},ExpressionUUID->"a38e9407-8406-4be3-8d12-\ 5e151a718405"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"deadlockFree", "[", "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "myModel", " ", "will", " ", "be", " ", "checked", " ", "for", " ", "deadlock", " ", "freedom"}], " ", "*)"}], "\[IndentingNewLine]", "..."}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.9721162569164944`*^9, 3.9721162653517036`*^9}},ExpressionUUID->"586eb9f9-480a-42e6-9968-\ 3984989f13a6"], Cell["Otherwise, everything is just plain Wolfram.", "Text",ExpressionUUID->"6961ff7f-9810-4529-8f2b-cabcd990f5ae"] }, Closed]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Code (do not remove)", "Section",ExpressionUUID->"b03e2ae5-2147-4f39-838e-e30e50646408"], Cell[CellGroupData[{ Cell["Core Proof Assistant", "Subsection",ExpressionUUID->"19d63da2-233d-48e4-ac3d-6a55653d13e3"], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{ "ensures", " ", "the", " ", "value", " ", "is", " ", "a", " ", "list"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"ensureList", "[", "v_", "]"}], ":=", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"ListQ", "[", "v", "]"}], ",", "\[IndentingNewLine]", "v", ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"v", "===", "Null"}], ",", "\[IndentingNewLine]", RowBox[{"{", "}"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "treat", " ", "direct", " ", "Null", " ", "as", " ", "empty", " ", "list"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"List", "[", "v", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"helper", " ", "for", " ", "pretty"}], "-", RowBox[{"printing", " ", "results"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"prettyResult", "[", "res_", "]"}], ":=", RowBox[{"Switch", "[", RowBox[{"res", ",", "\[IndentingNewLine]", "True", ",", RowBox[{"Style", "[", RowBox[{"res", ",", "Bold", ",", "Green"}], "]"}], ",", "\[IndentingNewLine]", "False", ",", RowBox[{"Style", "[", RowBox[{"res", ",", "Bold", ",", "Red"}], "]"}], ",", "\[IndentingNewLine]", "_", ",", RowBox[{"Style", "[", RowBox[{"res", ",", "Bold", ",", "Black"}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{ "checks", " ", "if", " ", "the", " ", "term", " ", "is", " ", "considered", " ", "final"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"isFinalTerm", "[", RowBox[{"t_", ",", "finalTermsOpt_"}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"ListQ", "[", "finalTermsOpt", "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"final", " ", "terms", " ", "is", " ", "a", " ", "list"}], " ", "-", " ", RowBox[{"check", " ", "membership"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"MemberQ", "[", RowBox[{"finalTermsOpt", ",", "t"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "otherwise", " ", "treat", " ", "finalTerms", " ", "as", " ", "a", " ", "function", " ", "that", " ", "checks", " ", "for", " ", "termination"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"finalTermsOpt", "[", "t", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", "\[IndentingNewLine]", RowBox[{ RowBox[{ "Returns", " ", "a", " ", "list", " ", "of", " ", "new", " ", "knowns"}], ",", " ", RowBox[{ "deduced", " ", "from", " ", "knowns", " ", "and", " ", "rules"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ "or", " ", "an", " ", "empty", " ", "list", " ", "if", " ", "nothing", " ", "new", " ", "can", " ", "be", " ", "deduced"}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"knownIndexThreshold", " ", "is", " ", "the", " ", "cut"}], "-", RowBox[{"off", " ", "index", " ", "in", " ", "knowns"}]}]}], ",", " ", RowBox[{ "so", " ", "that", " ", "only", " ", "rules", " ", "that", " ", "apply", " ", "to", " ", "premises", " ", "from", " ", "this", " ", "index", " ", "and", " ", "above", " ", "are", " ", "processed", " ", RowBox[{"(", RowBox[{ RowBox[{ "this", " ", "is", " ", "to", " ", "avoid", " ", "processing", " ", "old", " ", "premises", " ", "over", " ", "and", " ", "over", " ", "again", " ", "in", " ", "subsequent", " ", "steps"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ "each", " ", "result", " ", "in", " ", "the", " ", "returned", " ", "list", " ", "has", " ", RowBox[{"form", ":", " ", RowBox[{"{", RowBox[{"term", ",", "ruleIndex", ",", RowBox[{"{", RowBox[{"premiseIndex1", ",", "..."}], "}"}]}], "}"}]}]}]}], "\[IndentingNewLine]"}]}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"deduceStep", "[", RowBox[{"knowns_", ",", "rules_", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"finalTerms", "\[Rule]", RowBox[{"{", "}"}]}], ",", RowBox[{"knownIndexThreshold", "\[Rule]", "1"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"newKnowns", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "ruleIndex", ",", "\[IndentingNewLine]", "candidatePositions", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "list", " ", "of", " ", "lists", " ", "of", " ", "term", " ", "positions"}], ",", " ", RowBox[{"for", " ", "the", " ", "given", " ", "rule"}]}], " ", "*)"}], "\[IndentingNewLine]", "candidatePremises", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "lists", " ", "of", " ", "terms", " ", "from", " ", "knowns", " ", "that", " ", "match", " ", "rule", " ", "premises"}], ",", " ", RowBox[{ "for", " ", "each", " ", "separate", " ", "rule", " ", "application"}]}], " ", "*)"}], "\[IndentingNewLine]", "result", ",", " ", RowBox[{"(*", " ", RowBox[{ "result", " ", "from", " ", "the", " ", "application", " ", "of", " ", "each", " ", "rule"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"finalTermsOpt", "=", RowBox[{"OptionValue", "[", "finalTerms", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"knownIndexThresholdOpt", "=", RowBox[{"OptionValue", "[", "knownIndexThreshold", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"verboseOpt", "=", RowBox[{"OptionValue", "[", "verbose", "]"}]}], ",", "\[IndentingNewLine]", "ruleLoggedOnce", ",", "\[IndentingNewLine]", "applicationCount"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "===", "Automatic"}], ",", "\[IndentingNewLine]", RowBox[{"verboseOpt", "=", "False"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "===", "Counts"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< terms: \>\"", ",", RowBox[{"Length", "[", "knowns", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"applicationCount", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"Catch", "[", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "process", " ", "each", " ", "rule", " ", "in", " ", "the", " ", "list"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"ruleIndex", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"rule", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"rule", " ", "is", " ", RowBox[{"{", RowBox[{"premise", ",", "..."}], "}"}]}], "\[Implies]", "conclusion"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"++", "ruleIndex"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"verboseOpt", ",", "\[IndentingNewLine]", RowBox[{"ruleLoggedOnce", "=", "False"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"premises", "=", RowBox[{"rule", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"conclusion", "=", RowBox[{"rule", "[", RowBox[{"[", "2", "]"}], "]"}]}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "for", " ", "each", " ", "premise", " ", "in", " ", "the", " ", "rule"}], ",", RowBox[{ "collect", " ", "positions", " ", "of", " ", "terms", " ", "from", " ", "knowns", " ", "that", " ", "can", " ", "be", " ", "used", " ", "for", " ", "that", " ", "premise"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{" ", RowBox[{ RowBox[{ "candidatePositions", " ", "is", " ", "the", " ", "list", " ", "of", " ", RowBox[{"lists", ":", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"pos1ForPremise1", ",", RowBox[{"pos2ForPremise1", "..."}]}], "}"}], ",", RowBox[{"{", RowBox[{"pos1ForPremise2", ",", "..."}], "}"}]}], "}"}]}]}], ",", "..."}], "}"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"candidatePositions", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"prem", ",", " ", RowBox[{"(*", " ", RowBox[{ "each", " ", "premise", " ", "from", " ", "the", " ", "current", " ", "rule"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"candidatePositions", ",", RowBox[{"Position", "[", RowBox[{"knowns", ",", "prem", ",", RowBox[{"{", "1", "}"}], ",", RowBox[{"Heads", "\[Rule]", "False"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "premises"}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ "apply", " ", "index", " ", "threshold", " ", "to", " ", "avoid", " ", "processing", " ", "rules", " ", "on", " ", "old", " ", "knowns", " ", "repeatedly"}], ";", "\[IndentingNewLine]", RowBox[{"that", " ", "is"}]}], ",", " ", RowBox[{ "if", " ", "the", " ", "candidates", " ", "are", " ", "all", " ", "from", " ", "below", " ", "the", " ", "threashold"}], ",", " ", RowBox[{ "it", " ", "means", " ", "that", " ", "they", " ", "were", " ", "already", " ", "processed", " ", "in", " ", "previous", " ", "deduction", " ", "steps", " ", "and", " ", "there", " ", "is", " ", "no", " ", "need", " ", "to", " ", "repeat", " ", "that", " ", "processing", " ", RowBox[{"(", RowBox[{ "because", " ", "it", " ", "would", " ", "give", " ", "the", " ", "same", " ", "results", " ", "that", " ", "were", " ", "already", " ", "added", " ", "to", " ", "knowns"}], ")"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Max", "[", RowBox[{"Flatten", "[", "candidatePositions", "]"}], "]"}], ">", "knownIndexThresholdOpt"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "apply", " ", "rule", " ", "to", " ", "each", " ", "combination", " ", "of", " ", "candidates", " ", "found", " ", "above"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"candidates", ",", " ", RowBox[{"(*", " ", RowBox[{ "positions", " ", "for", " ", "each", " ", "set", " ", "of", " ", "candidates"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"again", ",", " ", RowBox[{ RowBox[{ "prune", " ", "selections", " ", "that", " ", "were", " ", "already", " ", "processed", " ", RowBox[{"(", RowBox[{ "those", " ", "below", " ", "the", " ", "index", " ", "threshold"}], ")"}]}], ";", RowBox[{"in", " ", "addition"}]}], ",", " ", RowBox[{ "if", " ", "the", " ", "candidates", " ", "positions", " ", "have", " ", "duplicates"}], ",", " ", RowBox[{ RowBox[{ "it", " ", "means", " ", "that", " ", "the", " ", "same", " ", "premise", " ", "was", " ", "selected", " ", "more", " ", "than", " ", "once", " ", "for", " ", "the", " ", "given", " ", "rule", " ", RowBox[{"(", RowBox[{ "this", " ", "can", " ", "happen", " ", "with", " ", "patterns", " ", "in", " ", "rules"}], ")"}]}], " ", "-", " ", RowBox[{"omit", " ", "this", " ", "selection"}]}], ",", " ", RowBox[{ "process", " ", "only", " ", "selections", " ", "of", " ", "unique", " ", "premises"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Max", "[", RowBox[{"Flatten", "[", "candidates", "]"}], "]"}], ">", "knownIndexThresholdOpt"}], "&&", RowBox[{"DuplicateFreeQ", "[", "candidates", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"candidatePremises", "=", RowBox[{ RowBox[{ RowBox[{"Extract", "[", RowBox[{"knowns", ",", "#"}], "]"}], "&"}], "/@", "candidates"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"re", "-", RowBox[{ "check", " ", "the", " ", "candidate", " ", "premises", " ", "by", " ", "treating", " ", "them", " ", "as", " ", "a", " ", "whole"}]}], ",", " ", RowBox[{ RowBox[{ "against", " ", "the", " ", "premises", " ", "treated", " ", "as", " ", "a", " ", "single", " ", "list"}], "-", RowBox[{"based", " ", "pattern"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"candidatePremises", ",", "premises"}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{"verboseOpt", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"Not", "[", "ruleLoggedOnce", "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "ruleIndex", ",", "\"\<: \>\"", ",", "rule"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"ruleLoggedOnce", "=", "True"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< on: \>\"", ",", RowBox[{"StringJoin", "@", RowBox[{"Riffle", "[", RowBox[{ RowBox[{"ToString", "/@", "candidatePremises"}], ",", "\"\<, \>\""}], "]"}]}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Head", "[", "conclusion", "]"}], "===", "Function"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"functional", " ", "rule"}], " ", "-", " ", RowBox[{ "supply", " ", "candidate", " ", "premises", " ", "and", " ", "produce", " ", "new", " ", "term"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"conclusion", "@@", "candidatePremises"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"literal", " ", "rule"}], " ", "-", " ", RowBox[{ "the", " ", "rule", " ", "provides", " ", "the", " ", "result", " ", "and", " ", "is", " ", "not", " ", "parameterized", " ", "by", " ", "premises"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", "conclusion"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"ensureList", "[", "result", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"++", "applicationCount"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"verboseOpt", ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< gives: \>\"", ",", RowBox[{"StringJoin", "@", RowBox[{"Riffle", "[", RowBox[{ RowBox[{"ToString", "/@", "result"}], ",", "\"\<, \>\""}], "]"}]}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "the", " ", "candidate", " ", "premises", " ", "do", " ", "not", " ", "match", " ", "the", " ", "whole", " ", "sequence", " ", "of", " ", "premises", " ", RowBox[{"(", RowBox[{ RowBox[{"that", " ", "is"}], ",", " ", RowBox[{ "treated", " ", "together", " ", "as", " ", "a", " ", "single", " ", "pattern"}]}], ")"}]}], ",", " ", RowBox[{ "even", " ", "though", " ", "they", " ", "were", " ", "found", " ", "and", " ", "collected", " ", "by", " ", "matching", " ", "each", " ", "premise", " ", "pattern", " ", "separately"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"{", "}"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"res", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"isFinalTerm", "[", RowBox[{"res", ",", "finalTermsOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ "this", " ", "step", " ", "produced", " ", "conclusive", " ", "final", " ", "term"}], " ", "-", " ", RowBox[{ "no", " ", "need", " ", "to", " ", "continue", " ", "processing"}]}], ",", " ", RowBox[{ "but", " ", "ensure", " ", "this", " ", "is", " ", "still", " ", "added", " ", "to", " ", "the", " ", "known", " ", "list"}], ",", " ", RowBox[{ "even", " ", "if", " ", "it", " ", "would", " ", "repeat", " ", "the", " ", "existing", " ", "known", " ", RowBox[{"(", RowBox[{ RowBox[{"for", " ", "example"}], ",", " ", RowBox[{ "it", " ", "might", " ", "happen", " ", "that", " ", "True", " ", "or", " ", "False", " ", "was", " ", "in", " ", "the", " ", "knowns", " ", "from", " ", "the", " ", "beginning"}], ",", " ", RowBox[{ "but", " ", "we", " ", "still", " ", "need", " ", "proper", " ", "deduction", " ", "trace", " ", "for", " ", RowBox[{"deduce", "[", "]"}], " ", "to", " ", "recognize", " ", "that", " ", "there", " ", "will", " ", "be", " ", "no", " ", "more", " ", "steps", " ", "to", " ", "execute"}]}], " "}]}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendTo", "[", RowBox[{"newKnowns", ",", RowBox[{"{", RowBox[{"res", ",", "ruleIndex", ",", RowBox[{"Flatten", "[", "candidates", "]"}]}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Throw", "[", "Null", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Not", "[", RowBox[{"MemberQ", "[", RowBox[{"knowns", ",", "res"}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"newKnowns", ",", RowBox[{"{", RowBox[{"res", ",", "ruleIndex", ",", RowBox[{"Flatten", "[", "candidates", "]"}]}], "}"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "result"}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "assume", " ", "that", " ", "all", " ", "rules", " ", "are", " ", RowBox[{"orderless", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Union", "[", RowBox[{"Sort", "/@", RowBox[{"Tuples", "[", "candidatePositions", "]"}]}], "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "if", " ", "ordering", " ", "of", " ", "premises", " ", "is", " ", "important", " ", "this", " ", "is", " ", "more", " ", "appropriate", " ", "instead", " ", "of", " ", "the", " ", "above"}], ",", " ", RowBox[{"optimized", " ", RowBox[{"version", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"Tuples", "[", "candidatePositions", "]"}], "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "rules"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "===", "Counts"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< rule applications: \>\"", ",", "applicationCount"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"DeleteDuplicatesBy", "[", RowBox[{"newKnowns", ",", "First"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\n", RowBox[{ RowBox[{"deduce", "[", RowBox[{"knowns_List", ",", "rules_List", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"finalTerms", "\[Rule]", RowBox[{"{", "}"}]}], ",", RowBox[{"withTrace", "\[Rule]", "False"}], ",", RowBox[{"maxSteps", "\[Rule]", "10"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"trace", ",", "\[IndentingNewLine]", RowBox[{"oldKnownsLength", "=", "0"}], ",", "\[IndentingNewLine]", RowBox[{"currentKnowns", "=", "knowns"}], ",", "\[IndentingNewLine]", "stepResult", ",", "\[IndentingNewLine]", "newKnowns", ",", "newTrace", ",", "\[IndentingNewLine]", RowBox[{"finalTermsOpt", "=", RowBox[{"OptionValue", "[", "finalTerms", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"withTraceOpt", "=", RowBox[{"OptionValue", "[", "withTrace", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"maxStepsOpt", "=", RowBox[{"OptionValue", "[", "maxSteps", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"stepCount", "=", "0"}], ",", "\[IndentingNewLine]", RowBox[{"keepWork", "=", "True"}], ",", "\[IndentingNewLine]", RowBox[{"verboseOpt", "=", RowBox[{"OptionValue", "[", "verbose", "]"}]}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "===", "Automatic"}], ",", "\[IndentingNewLine]", RowBox[{"verboseOpt", "=", "False"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"trace", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{"0", ",", RowBox[{"{", "}"}]}], "}"}], ",", RowBox[{"Length", "[", "knowns", "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{"keepWork", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"++", "stepCount"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"verboseOpt", "===", "Counts"}], "||", RowBox[{"verboseOpt", "===", "True"}]}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "stepCount"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"stepResult", "=", RowBox[{"deduceStep", "[", RowBox[{"currentKnowns", ",", "rules", ",", RowBox[{"finalTerms", "\[Rule]", "finalTermsOpt"}], ",", RowBox[{"knownIndexThreshold", "\[Rule]", "oldKnownsLength"}], ",", RowBox[{"verbose", "\[Rule]", "verboseOpt"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"stepResult", "===", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{"verboseOpt", ",", "\[IndentingNewLine]", RowBox[{ "Print", "[", "\"\\"", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"keepWork", "=", "False"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"newKnowns", "=", RowBox[{"stepResult", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"newTrace", "=", RowBox[{"stepResult", "[", RowBox[{"[", RowBox[{"All", ",", RowBox[{"2", ";;"}]}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"oldKnownsLength", "=", RowBox[{"Length", "[", "currentKnowns", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"currentKnowns", "=", RowBox[{"Join", "[", RowBox[{"currentKnowns", ",", "newKnowns"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"trace", "=", RowBox[{"Join", "[", RowBox[{"trace", ",", "newTrace"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"lastKnown", "=", RowBox[{"Last", "[", "newKnowns", "]"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"isFinalTerm", "[", RowBox[{"lastKnown", ",", "finalTermsOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"keepWork", "=", "False"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"stepCount", "\[Equal]", "maxStepsOpt"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{"verboseOpt", ",", "\[IndentingNewLine]", RowBox[{ "Print", "[", "\"\\"", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"keepWork", "=", "False"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"withTraceOpt", ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"currentKnowns", ",", "trace"}], "}"}], ",", "\[IndentingNewLine]", "currentKnowns"}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\n", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "gives", " ", "a", " ", "short", " ", "summary", " ", "of", " ", "the", " ", "result"}], ",", " ", RowBox[{"as", " ", "True"}], ",", " ", RowBox[{"False", " ", "or", " ", "Indeterminate"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"finalResult", "[", "result_", "]"}], ":=", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"last", "=", RowBox[{"result", "[", RowBox[{"[", RowBox[{"-", "1"}], "]"}], "]"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Switch", "[", RowBox[{"last", ",", "\[IndentingNewLine]", RowBox[{"True", "|", "False"}], ",", "last", ",", "\[IndentingNewLine]", "_", ",", "Indeterminate"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "prints", " ", "the", " ", "list", " ", "of", " ", "deductions"}], ",", " ", RowBox[{ RowBox[{"from", " ", "the", " ", "beginning"}], ";", "\[IndentingNewLine]", RowBox[{ "if", " ", "the", " ", "deduction", " ", "finishes", " ", "with", " ", "True", " ", "or", " ", "False"}]}], ",", " ", RowBox[{ "the", " ", "list", " ", "is", " ", "pruned", " ", "to", " ", "show", " ", "only", " ", "those", " ", "deductions", " ", "that", " ", "trace", " ", "to", " ", "that", " ", "final", " ", "result"}]}], " ", "*)"}], "\n", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"helper", " ", "for", " ", "recursive", " ", "back"}], "-", "tracing"}], ",", " ", RowBox[{ "collects", " ", "indices", " ", "of", " ", "those", " ", "terms", " ", "that", " ", "are", " ", "reachable", " ", "from", " ", "the", " ", "end"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"collectReachableIndices", "[", RowBox[{"zipped_", ",", "index_"}], "]"}], ":=", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"entry", "=", RowBox[{"zipped", "[", RowBox[{"[", "index", "]"}], "]"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Join", "[", RowBox[{ RowBox[{"{", "index", "}"}], ",", RowBox[{"Catenate", "[", RowBox[{ RowBox[{ RowBox[{"collectReachableIndices", "[", RowBox[{"zipped", ",", "#"}], "]"}], "&"}], "/@", RowBox[{"entry", "[", RowBox[{"[", "3", "]"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"showSteps", "[", RowBox[{"result_", ",", "rules_", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{"prune", "\[Rule]", "True"}], "}"}], "]"}]}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"terms", "=", RowBox[{"result", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"trace", "=", RowBox[{"result", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", "resultLen", ",", "\[IndentingNewLine]", "zipped", ",", "\[IndentingNewLine]", RowBox[{"pruneOpt", "=", RowBox[{"OptionValue", "[", "prune", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"pruned", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "prunedIndices", ",", "\[IndentingNewLine]", "prunedLen"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"zipped", "=", RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{"terms", ",", RowBox[{"trace", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}], ",", RowBox[{"trace", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}]}], "}"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"resultLen", "=", RowBox[{"Length", "[", "zipped", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "prune", " ", "the", " ", "list", " ", "if", " ", "the", " ", "deduction", " ", "finishes", " ", "with", " ", "True", " ", "or", " ", "False"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"pruneOpt", "&&", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"Last", "[", "terms", "]"}], "===", "True"}], "||", RowBox[{ RowBox[{"Last", "[", "terms", "]"}], "===", "False"}]}], ")"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "prepend", " ", "recursively", " ", "those", " ", "deductions", " ", "that", " ", "are", " ", "reachable", " ", "from", " ", "the", " ", "end"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"prunedIndices", "=", RowBox[{"Union", "[", RowBox[{"collectReachableIndices", "[", RowBox[{"zipped", ",", "resultLen"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"pruned", "=", RowBox[{"zipped", "[", RowBox[{"[", "prunedIndices", "]"}], "]"}]}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"otherwise", ",", " ", RowBox[{ "do", " ", "not", " ", "prune", " ", "and", " ", "show", " ", "the", " ", "whole", " ", "list"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"pruned", "=", "zipped"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"prunedLen", "=", RowBox[{"Length", "[", "pruned", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"prunedLen", "\[Equal]", "resultLen"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", "\"\\"", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"resultLen", "-", "prunedLen"}], ",", "\"\< irrelevant entries.\>\""}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"d", ",", " ", RowBox[{"(*", " ", RowBox[{"d", " ", "is", " ", RowBox[{"{", RowBox[{"term", ",", "ruleIndex", ",", RowBox[{"{", RowBox[{"premiseIndex1", ",", "..."}], "}"}]}], "}"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"term", "=", RowBox[{"d", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"ruleIndex", "=", RowBox[{"d", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "rule", " ", "index", " ", "points", " ", "to", " ", "the", " ", "rule", " ", "that", " ", "is", " ", "a", " ", "source", " ", "for", " ", "the", " ", "given", " ", "term", " ", "and", " ", "is", " ", "0", " ", "for", " ", "any", " ", "of", " ", "the", " ", "terms", " ", "in", " ", "initial", " ", "set", " ", RowBox[{"(", "knowns", ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"rule", "=", RowBox[{"rules", "[", RowBox[{"[", RowBox[{"d", "[", RowBox[{"[", "2", "]"}], "]"}], "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"premises", "=", RowBox[{"terms", "[", RowBox[{"[", RowBox[{"d", "[", RowBox[{"[", "3", "]"}], "]"}], "]"}], "]"}]}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{" ", RowBox[{ "show", " ", "only", " ", "deductions", " ", "for", " ", "terms", " ", "that", " ", "did", " ", "not", " ", "exist", " ", "in", " ", "knowns"}], ")"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"ruleIndex", "\[NotEqual]", "0"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"StandardForm", "[", "rule", "]"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< with: \>\"", ",", RowBox[{"StringJoin", "@", RowBox[{"Riffle", "[", RowBox[{ RowBox[{"ToString", "/@", "premises"}], ",", "\"\<, \>\""}], "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< gives: \>\"", ",", "term"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "pruned"}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "simple", " ", "wrapper", " ", "for", " ", "use", " ", "with", " ", "standard", " ", "rules"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"showSteps", "[", "result_", "]"}], ":=", RowBox[{"showSteps", "[", RowBox[{"result", ",", "standardRules"}], "]"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "helper", " ", "for", " ", "handling", " ", "Span", " ", "variables", " ", "expressions"}], ",", " ", RowBox[{ RowBox[{ "extracts", " ", "Span", " ", "\"\\"", " ", "of", " ", "the", " ", "form", " ", "a"}], " ", "\[Element]", " ", RowBox[{ "Span", " ", "and", " ", "prepares", " ", "list", " ", "of", " ", "replacements"}]}], ",", " ", RowBox[{ RowBox[{ "so", " ", "that", " ", "span", " ", "variables", " ", "can", " ", "be", " ", "replaced", " ", "with", " ", "expanded", " ", "forms", " ", RowBox[{"Span", "[", RowBox[{"aMin", ",", "aMax"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ "returns", " ", "both", " ", "the", " ", "list", " ", "of", " ", "replacements", " ", "and", " ", "the", " ", "term", " ", "with", " ", "declarations", " ", "removed"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"extractSpanDeclarations", "[", "term_", "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "spanVariables", ",", "\[IndentingNewLine]", "spanVarReplacements", ",", "\[IndentingNewLine]", "result"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "gather", " ", "and", " ", "remove", " ", "direct", " ", "span", " ", "variable", " ", "declarations"}], ",", " ", RowBox[{ RowBox[{ "they", " ", "are", " ", "\"\\"", " ", "as", " ", "a"}], " ", "\[Element]", " ", "Span"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"spanVariables", "=", RowBox[{"Cases", "[", RowBox[{"term", ",", RowBox[{ RowBox[{"Element", "[", RowBox[{"v_Symbol", ",", "Span"}], "]"}], ":>", "v"}], ",", RowBox[{"{", RowBox[{"0", ",", "Infinity"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"DeleteCases", "[", RowBox[{"term", ",", RowBox[{"Element", "[", RowBox[{"_Symbol", ",", "Span"}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "replace", " ", "all", " ", "span", " ", "variables", " ", "with", " ", "span", " ", "expressions", " ", "like", " ", RowBox[{"Span", "[", RowBox[{"xMin", ",", "xMax"}], "]"}]}], " ", "*)"}], RowBox[{"spanVarReplacements", "=", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"v", ",", "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"vStr", "=", RowBox[{"ToString", "[", "v", "]"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"v", "->", RowBox[{"Span", "[", RowBox[{ RowBox[{"Unique", "[", RowBox[{"vStr", "<>", "\"\\""}], "]"}], ",", RowBox[{"Unique", "[", RowBox[{"vStr", "<>", "\"\\""}], "]"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "spanVariables"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"spanVarReplacements", ",", "result"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{ RowBox[{ "replaces", " ", "expressions", " ", "of", " ", "the", " ", "form", " ", "a"}], " ", "\[Element]", " ", "SomeSet"}], ",", " ", RowBox[{"where", " ", "SomeSet", " ", "can", " ", RowBox[{"be", ":", "\[IndentingNewLine]", RowBox[{ RowBox[{"-", " ", "Span"}], " ", RowBox[{"(", RowBox[{"for", " ", "span", " ", "declarations"}], ")"}]}]}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"-", " ", RowBox[{"{", RowBox[{"a", ",", "b", ",", "c", ",", "..."}], "}"}]}], " ", "for", " ", "explicit", " ", "set", " ", "definitions"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"-", " ", "Booleans"}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"Set", " ", "memberships", " ", "like", " ", "a"}], "\[Element]", RowBox[{"Integers", " ", "and", " ", "a"}], "\[Element]", RowBox[{"Reals", " ", "are", " ", "preserved"}]}]}], ",", " ", RowBox[{ RowBox[{ RowBox[{ "because", " ", "they", " ", "are", " ", "hints", " ", "for", " ", "further", " ", RowBox[{"computations", ".", "\[IndentingNewLine]", "Set"}], " ", "membership", " ", "a"}], "\[Element]", RowBox[{ "Booleans", " ", "can", " ", "be", " ", "preserved", " ", "with", " ", "leaveBooleans"}]}], "\[Rule]", RowBox[{"True", " ", RowBox[{"option", "."}]}]}]}], "\[IndentingNewLine]", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"rewriteSets", "[", RowBox[{"term_", ",", "spanVarReplacements_", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{"leaveBooleans", "\[Rule]", "False"}], "}"}], "]"}]}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"leaveBooleansOpt", "=", RowBox[{"OptionValue", "[", "leaveBooleans", "]"}]}], ",", "\[IndentingNewLine]", "result"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"replace", " ", "span", " ", "variables"}], ",", " ", RowBox[{ "according", " ", "to", " ", "earlier", " ", "declarations"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"result", "=", RowBox[{"term", "/.", "spanVarReplacements"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"leaveBooleansOpt", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"expand", " ", "a"}], " ", "\[Element]", " ", "Booleans"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Element", "[", RowBox[{"name_Symbol", ",", "Booleans"}], "]"}], "\[RuleDelayed]", RowBox[{"(", RowBox[{ RowBox[{"name", "\[Equal]", "False"}], "||", RowBox[{"name", "\[Equal]", "True"}]}], ")"}]}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"expand", " ", "a"}], " ", "\[Element]", " ", RowBox[{"{", "...", "}"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Element", "[", RowBox[{"el_", ",", "set_List"}], "]"}], "\[RuleDelayed]", RowBox[{"Or", "@@", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"el", "\[Equal]", "#"}], "&"}], "/@", "set"}], ")"}]}]}]}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "type", " ", "preservation", " ", "for", " ", "Span", " ", "operations"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"\[EmptySet]", " ", "\[Element]", " ", "Span"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Element", "[", RowBox[{"\[EmptySet]", ",", "Span"}], "]"}], "->", "True"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"Span", "[", RowBox[{"a", ",", "b"}], "]"}], " ", "\[Element]", " ", "Span"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Element", "[", RowBox[{ RowBox[{"Span", "[", RowBox[{"_", ",", "_"}], "]"}], ",", "Span"}], "]"}], "\[Rule]", "True"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"Span", "[", RowBox[{"a", ",", "b"}], "]"}], "+", RowBox[{"Span", "[", RowBox[{"b", ",", "c"}], "]"}]}], " ", "\[Element]", " ", "Span"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Element", "[", RowBox[{ RowBox[{ RowBox[{"Span", "[", RowBox[{"a_", ",", "b_"}], "]"}], "+", RowBox[{"Span", "[", RowBox[{"c_", ",", "d_"}], "]"}]}], ",", "Span"}], "]"}], "\[RuleDelayed]", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"b", "+", "1"}], "\[Equal]", "c"}], "||", RowBox[{ RowBox[{"d", "+", "1"}], "==", "a"}]}], ")"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"Span", "[", RowBox[{"a", ",", "b"}], "]"}], "+", "c"}], " ", "\[Element]", " ", "Span"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Element", "[", RowBox[{ RowBox[{"Plus", "[", RowBox[{ RowBox[{"Span", "[", RowBox[{"a_", ",", "b_"}], "]"}], ",", "c_"}], "]"}], ",", "Span"}], "]"}], "\[RuleDelayed]", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"c", "+", "1"}], "==", "a"}], "||", RowBox[{ RowBox[{"b", "+", "1"}], "\[Equal]", "c"}]}], ")"}]}]}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"arithmetic", " ", "and", " ", "equalities"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"Span", "[", RowBox[{"a", ",", "b"}], "]"}], "\[Equal]", "\[EmptySet]"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Equal", "[", RowBox[{ RowBox[{"Span", "[", RowBox[{"a_", ",", "b_"}], "]"}], ",", "\[EmptySet]"}], "]"}], "\[RuleDelayed]", RowBox[{"(", RowBox[{"a", ">", "b"}], ")"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"Span", "[", RowBox[{"a", ",", "b"}], "]"}], "\[Equal]", RowBox[{"Span", "[", RowBox[{"c", ",", "d"}], "]"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Equal", "[", RowBox[{ RowBox[{"Span", "[", RowBox[{"a_", ",", "b_"}], "]"}], ",", RowBox[{"Span", "[", RowBox[{"c_", ",", "d_"}], "]"}]}], "]"}], "\[RuleDelayed]", RowBox[{"(", RowBox[{ RowBox[{"a", "\[Equal]", "c"}], "&&", RowBox[{"b", "\[Equal]", "d"}]}], ")"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"Span", "[", RowBox[{"a", ",", "b"}], "]"}], "+", "c"}], " ", "==", " ", RowBox[{"Span", "[", RowBox[{"d", ",", "e"}], "]"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Equal", "[", RowBox[{ RowBox[{ RowBox[{"Span", "[", RowBox[{"a_", ",", "b_"}], "]"}], "+", "c_"}], ",", RowBox[{"Span", "[", RowBox[{"d_", ",", "e_"}], "]"}]}], "]"}], "\[RuleDelayed]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"a", "==", "d"}], "&&", RowBox[{ RowBox[{"b", "+", "1"}], "==", "c"}], "&&", RowBox[{"c", "==", "e"}]}], ")"}], "||", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"c", "+", "1"}], "==", "a"}], "&&", RowBox[{"c", "==", "d"}], "&&", RowBox[{"b", "==", "e"}]}], ")"}]}], ")"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"Span", "[", RowBox[{"a", ",", "b"}], "]"}], "+", RowBox[{"Span", "[", RowBox[{"c", ",", "d"}], "]"}]}], " ", "==", " ", RowBox[{"Span", "[", RowBox[{"e", ",", "f"}], "]"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"TODO", ":", " ", RowBox[{"uncomment", " ", "if", " ", "needed"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Equal", "[", RowBox[{ RowBox[{ RowBox[{"Span", "[", RowBox[{"a_", ",", "b_"}], "]"}], "+", RowBox[{"Span", "[", RowBox[{"c_", ",", "d_"}], "]"}]}], ",", RowBox[{"Span", "[", RowBox[{"e_", ",", "f_"}], "]"}]}], "]"}], ":>", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"a", "==", "e"}], "&&", RowBox[{ RowBox[{"b", "+", "1"}], "==", "c"}], "&&", RowBox[{"d", "==", "f"}]}], ")"}], "||", RowBox[{"(", RowBox[{ RowBox[{"c", "==", "e"}], "&&", RowBox[{ RowBox[{"d", "+", "1"}], "==", "a"}], "&&", RowBox[{"b", "==", "f"}]}], ")"}]}], ")"}]}]}]}], ";"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"handle", " ", "x"}], " ", "\[Element]", " ", RowBox[{"Span", "[", RowBox[{"a", ",", "b"}], "]"}]}], ",", " ", RowBox[{ RowBox[{"inject", " ", "x"}], " ", "\[Element]", " ", RowBox[{ "Integers", " ", "if", " ", "x", " ", "is", " ", "a", " ", "symbol"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Element", "[", RowBox[{"expr_", ",", RowBox[{"Span", "[", RowBox[{"a_", ",", "b_"}], "]"}]}], "]"}], "\[RuleDelayed]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Head", "[", "expr", "]"}], "===", "Symbol"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Element", "[", RowBox[{"expr", ",", "Integers"}], "]"}], "&&", RowBox[{"(", RowBox[{"a", "\[LessEqual]", "expr", "\[LessEqual]", "b"}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"(", RowBox[{"a", "\[LessEqual]", "expr", "\[LessEqual]", "b"}], ")"}]}], "\[IndentingNewLine]", "]"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"handle", " ", "x"}], " ", "\[NotElement]", " ", RowBox[{"Span", "[", RowBox[{"a", ",", "b"}], "]"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"NotElement", "[", RowBox[{"expr_", ",", RowBox[{"Span", "[", RowBox[{"a_", ",", "b_"}], "]"}]}], "]"}], "\[RuleDelayed]", RowBox[{"Not", "[", RowBox[{"(", RowBox[{"a", "\[LessEqual]", "expr", "\[LessEqual]", "b"}], ")"}], "]"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Element", "[", RowBox[{"v_Integer", ",", RowBox[{"Span", "[", RowBox[{"a_", ",", "b_"}], "]"}]}], "]"}], "\[RuleDelayed]", RowBox[{"(", RowBox[{"a", "\[LessEqual]", "v", "\[LessEqual]", "b"}], ")"}]}]}]}], ";"}], "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"result", "=", RowBox[{"result", "/.", RowBox[{ RowBox[{"Element", "[", RowBox[{"el_Symbol", ",", RowBox[{"Span", "[", RowBox[{"a_", ",", "b_"}], "]"}]}], "]"}], "\[RuleDelayed]", RowBox[{"(", RowBox[{"a", "\[LessEqual]", "el", "\[LessEqual]", "b"}], ")"}]}]}]}], ";"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"handle", " ", "a"}], " ", "\[Element]", " ", "\[EmptySet]"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"TODO", ":", " ", RowBox[{"uncomment", " ", "if", " ", "needed"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"result", " ", "=", " ", RowBox[{"result", "/.", RowBox[{ RowBox[{"Element", "[", RowBox[{"_", ",", "\[EmptySet]"}], "]"}], "\[Rule]", "False"}]}]}], ";"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", "result"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helpers", ",", " ", RowBox[{ RowBox[{ "used", " ", "to", " ", "structurally", " ", "match", " ", "n"}], "-", RowBox[{"ary", " ", "predicates"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"regionMatchPrerequisite", "[", RowBox[{ "uv_Symbol", ",", "quantSet1_", ",", "quantSet2_", ",", "failingResult_"}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"region1", "=", RowBox[{"quantSet1", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params1", "=", RowBox[{"quantSet1", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"region2", "=", RowBox[{"quantSet2", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params2", "=", RowBox[{"quantSet2", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"lastUVMatch", "=", RowBox[{"{", "}"}]}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "params1", "]"}], "\[Equal]", RowBox[{"Length", "[", "params2", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"And", "@@", RowBox[{"MapThread", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", RowBox[{"p1", ",", "p2"}], "}"}], ",", " ", RowBox[{"(*", " ", RowBox[{"p1", ",", RowBox[{ "p2", " ", "are", " ", "respective", " ", "parameters"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"p1", "===", "uv"}], "&&", RowBox[{"p2", "===", "uv"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "both", " ", "params", " ", "refer", " ", "to", " ", "bound", " ", "variable", " ", "uv"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"lastUVMatch", "\[Equal]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"first", "-", RowBox[{"time", " ", "match", " ", "with", " ", "uv"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"lastUVMatch", "=", RowBox[{"{", RowBox[{"p1", ",", "p2"}], "}"}]}], " ", ";", "\[IndentingNewLine]", "True"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"lastUVMatch", "===", RowBox[{"{", RowBox[{"p1", ",", "p2"}], "}"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"p1", "===", "uv"}], "&&", RowBox[{"p2", "=!=", "uv"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "left", " ", "param", " ", "refers", " ", "to", " ", "uv"}], ",", " ", RowBox[{"fail", " ", "this", " ", "match"}]}], " ", "*)"}], "\[IndentingNewLine]", "failingResult", ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"p1", "=!=", "uv"}], "&&", RowBox[{"p2", "===", "uv"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "right", " ", "param", " ", "refers", " ", "to", " ", "uv"}], ",", " ", RowBox[{"add", " ", "condition"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"lastUVMatch", "\[Equal]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"first", "-", RowBox[{"time", " ", "match", " ", "with", " ", "uv"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"lastUVMatch", "=", RowBox[{"{", RowBox[{"p1", ",", "p2"}], "}"}]}], " ", ";", "\[IndentingNewLine]", RowBox[{"p1", "\[Equal]", "uv"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"lastUVMatch", "===", RowBox[{"{", RowBox[{"p1", ",", "p2"}], "}"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"p1", "===", "p2"}]}], " ", RowBox[{"(*", " ", RowBox[{ "require", " ", "exact", " ", "structural", " ", "match", " ", "for", " ", "free", " ", "parameters"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"params1", ",", "params2"}], "}"}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", "failingResult"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"regionMatchCondition", "[", RowBox[{ "uv_Symbol", ",", "quantSet1_", ",", "quantSet2_", ",", "failingResult_"}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"region1", "=", RowBox[{"quantSet1", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params1", "=", RowBox[{"quantSet1", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"region2", "=", RowBox[{"quantSet2", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params2", "=", RowBox[{"quantSet2", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"lastUVMatch", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "match"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"match", "=", RowBox[{"regionMatchPrerequisite", "[", RowBox[{ "uv", ",", "quantSet1", ",", "quantSet2", ",", "failingResult"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"match", "===", "True"}], ",", "\[IndentingNewLine]", RowBox[{"region1", "\[Implies]", "region2"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"match", "===", "failingResult"}], ",", "\[IndentingNewLine]", "match", ",", "\[IndentingNewLine]", RowBox[{"match", "\[Implies]", "region2"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{"replaces", " ", "expressions", " ", "of", " ", "the", " ", RowBox[{"forms", ":", "\[IndentingNewLine]", RowBox[{"-", " ", RowBox[{"ForAll", "[", RowBox[{"var", ",", "varSet", ",", RowBox[{"P", "[", "var", "]"}]}], "]"}]}]}]}], ",", " ", RowBox[{ "where", " ", "varSet", " ", "is", " ", "some", " ", "constraining", " ", "condition", " ", "on", " ", "var", " ", "and", " ", "P", " ", "is", " ", "a", " ", "symbol", " ", "denoting", " ", "some", " ", "arbitrary", " ", "unary", " ", "predicate"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"-", " ", RowBox[{"P", "[", "var", "]"}]}], "\[IndentingNewLine]", "These", " ", "expressions", " ", "do", " ", "not", " ", "need", " ", "to", " ", "use", " ", "the", " ", "same", " ", "var"}], ",", " ", RowBox[{ RowBox[{ "which", " ", "is", " ", "replaced", " ", "with", " ", "unified", " ", "and", " ", "unique", " ", "name", " ", "anyway"}], ";", " ", RowBox[{ "expressions", " ", "are", " ", "matched", " ", "by", " ", "the", " ", "predicate", " ", "name"}], ";", "\[IndentingNewLine]", RowBox[{ "predicates", " ", "can", " ", "be", " ", "used", " ", "directly", " ", "or", " ", RowBox[{"negated", ".", "\[IndentingNewLine]", "These"}], " ", "expressions", " ", "are", " ", "deleted", " ", "from", " ", "knowns", " ", "and", " ", "in", " ", "question", " ", "replaced", " ", "with", " ", "conditions", " ", "that", " ", "make", " ", "them", " ", "True", " ", "if", " ", "appropriate", " ", "set", " ", "dependencies", " ", "are", " ", RowBox[{"met", "."}]}]}]}], "\[IndentingNewLine]", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"rewriteQuantifiers", "[", RowBox[{"knowns_", ",", "question_"}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"knowns2", ",", " ", RowBox[{"(*", " ", RowBox[{"after", " ", "preprocessing"}], " ", "*)"}], "\[IndentingNewLine]", "knownsFAPos", ",", " ", RowBox[{"(*", " ", RowBox[{"positions", " ", "of", " ", "ForAll", " ", "expressions"}], " ", "*)"}], "\[IndentingNewLine]", "knownsEXPos", ",", " ", RowBox[{"(*", " ", RowBox[{"positions", " ", "of", " ", "Exists", " ", "expressions"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"knownsPredPos", "=", RowBox[{"{", "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "positions", " ", "of", " ", "free", " ", "predicates", " ", "in", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", "questionFAPos", ",", "\[IndentingNewLine]", "questionEXPos", ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsFASets", "=", RowBox[{"<|", "|>"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"combined", " ", "FA", " ", "variable", " ", "sets"}], ",", " ", RowBox[{"keyed", " ", "by", " ", "predicate", " ", "head"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"combinedKnownsFANSets", "=", RowBox[{"<|", "|>"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "combined", " ", "variable", " ", "sets", " ", "for", " ", "negated", " ", "predicates"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"combinedKnownsEXSets", "=", RowBox[{"<|", "|>"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"combined", " ", "EX", " ", "variable", " ", "sets"}], ",", " ", RowBox[{"keyed", " ", "by", " ", "predicate", " ", "head"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"combinedKnownsEXNSets", "=", RowBox[{"<|", "|>"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "combined", " ", "variable", " ", "sets", " ", "for", " ", "negated", " ", "predicates"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"unifiedVars", "=", RowBox[{"<|", "|>"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "unified", " ", "variable", " ", "names", " ", "for", " ", "FA", " ", "and", " ", "EX", " ", "regions"}], " ", "*)"}], "\[IndentingNewLine]", "kfa", ",", "kfaVar", ",", "kfaCond", ",", "kfaPred", ",", "kfaPredHead", ",", "\[IndentingNewLine]", "kex", ",", "kexVar", ",", "kexCond", ",", "kexPred", ",", "kexPredHead", ",", "\[IndentingNewLine]", "quantSet", ",", " ", RowBox[{"(*", " ", RowBox[{ "condition", " ", "set", " ", "for", " ", "the", " ", "given", " ", "quantifier"}], " ", "*)"}], "\[IndentingNewLine]", "kPredPos", ",", "kPred", ",", "\[IndentingNewLine]", "uv", ",", " ", RowBox[{"(*", " ", RowBox[{ "unique", " ", "variable", " ", "name", " ", "to", " ", "replace", " ", "bound", " ", "variable"}], " ", "*)"}], "\[IndentingNewLine]", "merged", ",", "newQS", ",", "keepTrying", ",", " ", RowBox[{"(*", " ", RowBox[{ "temporary", " ", "object", " ", "for", " ", "merging", " ", "sets"}], " ", "*)"}], "\[IndentingNewLine]", "qfa", ",", "qfaVar", ",", "qfaCond", ",", "qfaPred", ",", "qfaPredHead", ",", "qPreds", ",", "qPr", ",", "\[IndentingNewLine]", "qex", ",", "qexVar", ",", "qexCond", ",", "qexPred", ",", "qexPredHead", ",", "\[IndentingNewLine]", "cond", ",", "ncond", ",", "qRep", ",", "\[IndentingNewLine]", RowBox[{"questionReplacements", "=", RowBox[{"{", "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"transformations", " ", "in", " ", "question"}], " ", "*)"}], "\[IndentingNewLine]", "injectedKnowns"}], " ", RowBox[{"(*", " ", RowBox[{ "new", " ", "knowns", " ", "deduced", " ", "from", " ", "quantifier", " ", "sets"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "0.", " ", "perform", " ", "some", " ", "obvious", " ", "transformations"}], ",", " ", RowBox[{ RowBox[{"like", ":", "\[IndentingNewLine]", RowBox[{"ForAll", "[", RowBox[{"P", "&&", "Q"}], "]"}]}], " ", "\[Rule]", " ", RowBox[{ RowBox[{"ForAll", "[", "P", "]"}], " ", "&&", " ", RowBox[{"ForAll", "[", "Q", "]"}]}]}]}], "\[IndentingNewLine]", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"knowns2", "=", RowBox[{"Replace", "[", RowBox[{"knowns", ",", "\[IndentingNewLine]", RowBox[{"fa_ForAll", "\[RuleDelayed]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"var", "=", RowBox[{"fa", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"cnd", "=", RowBox[{"fa", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"pred", "=", RowBox[{"fa", "[", RowBox[{"[", "3", "]"}], "]"}]}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Head", "[", "pred", "]"}], "===", "And"}], ",", "\[IndentingNewLine]", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"p", ",", "\[IndentingNewLine]", RowBox[{"ForAll", "[", RowBox[{"var", ",", "cnd", ",", "p"}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "pred"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "fa"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"knowns2", ",", RowBox[{"ForAll", "[", RowBox[{"_", ",", "_", ",", "_"}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"knownsFAPos", "=", RowBox[{"{", RowBox[{"{", "}"}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"knownsFAPos", "=", RowBox[{"Position", "[", RowBox[{"knowns2", ",", RowBox[{"ForAll", "[", RowBox[{"_", ",", "_", ",", "_"}], "]"}], ",", RowBox[{"{", "1", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"knowns2", ",", RowBox[{"Exists", "[", RowBox[{"_", ",", "_", ",", "_"}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"knownsEXPos", "=", RowBox[{"{", RowBox[{"{", "}"}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"knownsEXPos", "=", RowBox[{"Position", "[", RowBox[{"knowns2", ",", RowBox[{"Exists", "[", RowBox[{"_", ",", "_", ",", "_"}], "]"}], ",", RowBox[{"{", "1", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"question", ",", RowBox[{"ForAll", "[", RowBox[{"_", ",", "_", ",", "_"}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"questionFAPos", "=", RowBox[{"{", RowBox[{"{", "}"}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"questionFAPos", "=", RowBox[{"Position", "[", RowBox[{"question", ",", RowBox[{"ForAll", "[", RowBox[{"_", ",", "_", ",", "_"}], "]"}], ",", RowBox[{"{", "1", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"question", ",", RowBox[{"Exists", "[", RowBox[{"_", ",", "_", ",", "_"}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"questionEXPos", "=", RowBox[{"{", RowBox[{"{", "}"}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"questionEXPos", "=", RowBox[{"Position", "[", RowBox[{"question", ",", RowBox[{"Exists", "[", RowBox[{"_", ",", "_", ",", "_"}], "]"}], ",", RowBox[{"{", "1", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"1.", " ", "find", " ", "and", " ", "merge", " ", "FA"}], ",", " ", RowBox[{ "EX", " ", "and", " ", "free", " ", "predicates", " ", "from", " ", "knowns"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"1", RowBox[{"a", ".", " ", "find"}], " ", "all", " ", "FA", " ", "quantifiers", " ", "and", " ", "store", " ", "their", " ", "ranges", " ", "and", " ", "parameters", " ", "with", " ", "the", " ", "use", " ", "of", " ", "unified", " ", "variables"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"Note", ":", " ", RowBox[{"for", " ", "P", " ", RowBox[{"and", " ", "!"}], "P", " ", "predicates", " ", "variables", " ", "are", " ", "the", " ", "same"}]}], ",", " ", RowBox[{ "but", " ", "their", " ", "sets", " ", "are", " ", "collected", " ", "separately"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"kpos", ",", " ", RowBox[{"(*", " ", RowBox[{ "kpos", " ", "is", " ", "position", " ", "of", " ", "FA", " ", "quantifier", " ", "in", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"kfa", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"kpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", "knowns2", ",", RowBox[{"Extract", "[", RowBox[{"knowns2", ",", "kpos"}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"kfaVar", "=", RowBox[{"kfa", "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", "variable", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"kfaCond", "=", RowBox[{"kfa", "[", RowBox[{"[", "2", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"constraining", " ", "condition"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"kfaPred", "=", RowBox[{"kfa", "[", RowBox[{"[", "3", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", "predicate", " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Head", "[", "kfaVar", "]"}], "===", "Symbol"}], "&&", "\[IndentingNewLine]", RowBox[{ RowBox[{"Max", "@@", RowBox[{"Length", "/@", RowBox[{"Position", "[", RowBox[{"kfaPred", ",", "kfaVar"}], "]"}]}]}], "\[Equal]", "1"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"n", "-", RowBox[{ "ary", " ", "predicates", " ", "over", " ", "one", " ", "variable", " ", "are", " ", "supported"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"kfaPredHead", "=", RowBox[{"Head", "[", "kfaPred", "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"unifiedVars", ",", "kfaPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "kfaPredHead", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"uv", "=", RowBox[{"Unique", "[", RowBox[{"ToString", "[", "kfaPredHead", "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"unifiedVars", "[", "kfaPredHead", "]"}], "=", "uv"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{"kfaCond", "/.", RowBox[{"kfaVar", "\[Rule]", "uv"}]}], ")"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "region", " ", "of", " ", "the", " ", "quantifier"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"List", "@@", "kfaPred"}], "/.", RowBox[{"kfaVar", "\[Rule]", "uv"}]}], ")"}]}], " ", RowBox[{"(*", " ", RowBox[{"predicate", " ", "parameters"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFASets", ",", "kfaPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"note", ":", " ", RowBox[{ "sets", " ", "are", " ", "kept", " ", "separate"}]}], ",", " ", RowBox[{"in", " ", "a", " ", "list"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{ RowBox[{"combinedKnownsFASets", "[", "kfaPredHead", "]"}], ",", "quantSet"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"combinedKnownsFASets", "[", "kfaPredHead", "]"}], "=", RowBox[{"{", "quantSet", "}"}]}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Head", "[", "kfaPred", "]"}], "===", "Not"}], "&&", "\[IndentingNewLine]", RowBox[{ RowBox[{"Head", "[", "kfaVar", "]"}], "===", "Symbol"}], "&&", "\[IndentingNewLine]", RowBox[{ RowBox[{"Max", "@@", RowBox[{"Length", "/@", RowBox[{"Position", "[", RowBox[{ RowBox[{"kfaPred", "[", RowBox[{"[", "1", "]"}], "]"}], ",", "kfaVar"}], "]"}]}]}], "\[Equal]", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"negation", " ", "of", " ", "predicate"}], ",", " ", RowBox[{ "accumulate", " ", "separate", " ", "set", " ", "for", " ", "that", " ", "name"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"kfaPredHead", "=", RowBox[{"Head", "[", RowBox[{"kfaPred", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"unifiedVars", ",", "kfaPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "kfaPredHead", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"uv", "=", RowBox[{"Unique", "[", RowBox[{"ToString", "[", "kfaPredHead", "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"unifiedVars", "[", "kfaPredHead", "]"}], "=", "uv"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{"kfaCond", "/.", RowBox[{"kfaVar", "\[Rule]", "uv"}]}], ")"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "region", " ", "of", " ", "the", " ", "quantifier"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"List", "@@", RowBox[{"kfaPred", "[", RowBox[{"[", "1", "]"}], "]"}]}], "/.", RowBox[{"kfaVar", "\[Rule]", "uv"}]}], ")"}]}], " ", RowBox[{"(*", " ", RowBox[{"predicate", " ", "parameters"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFANSets", ",", "kfaPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"note", ":", " ", RowBox[{ "sets", " ", "are", " ", "kept", " ", "separate"}]}], ",", " ", RowBox[{"in", " ", "a", " ", "list"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{ RowBox[{ "combinedKnownsFANSets", "[", "kfaPredHead", "]"}], ",", "quantSet"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ "combinedKnownsFANSets", "[", "kfaPredHead", "]"}], "=", RowBox[{"{", "quantSet", "}"}]}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "kfa", ",", "\"\< is not supported (wrong predicate)\>\""}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "knownsFAPos"}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"1", RowBox[{"b", ".", " ", "find"}], " ", "all", " ", "EX", " ", "quantifiers", " ", "and", " ", "store", " ", "their", " ", "ranges", " ", "and", " ", "parameters", " ", "with", " ", "the", " ", "use", " ", "of", " ", "unified", " ", "variables"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"Note", ":", " ", RowBox[{ "the", " ", "EX", " ", "sets", " ", "cannot", " ", "be", " ", "merged", " ", "the", " ", "way", " ", "FA", " ", "sets", " ", "are"}]}], ",", " ", RowBox[{ RowBox[{ "they", " ", "need", " ", "to", " ", "preserve", " ", "their", " ", "separate", " ", "meaning", " ", "and", " ", "impact", " ", "on", " ", "further", " ", "deductions"}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"that", "'"}], "s", " ", "why", " ", "combinedKnownsEXSets", " ", "keeps", " ", "lists", " ", "of", " ", "separate", " ", "sets", " ", "instead", " ", "of", " ", "merging", " ", "them", " ", "into", " ", "a", " ", "single", " ", "set"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"kpos", ",", " ", RowBox[{"(*", " ", RowBox[{ "kpos", " ", "is", " ", "position", " ", "of", " ", "EX", " ", "quantifier", " ", "in", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"kex", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"kpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", "knowns2", ",", RowBox[{"Extract", "[", RowBox[{"knowns2", ",", "kpos"}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"kexVar", "=", RowBox[{"kex", "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", "variable", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"kexCond", "=", RowBox[{"kex", "[", RowBox[{"[", "2", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"constraining", " ", "condition"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"kexPred", "=", RowBox[{"kex", "[", RowBox[{"[", "3", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", "predicate", " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Head", "[", "kexVar", "]"}], "===", "Symbol"}], "&&", "\[IndentingNewLine]", RowBox[{ RowBox[{"Max", "@@", RowBox[{"Length", "/@", RowBox[{"Position", "[", RowBox[{"kexPred", ",", "kexVar"}], "]"}]}]}], "\[Equal]", "1"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"n", "-", RowBox[{ "ary", " ", "predicates", " ", "over", " ", "one", " ", "variable", " ", "are", " ", "supported"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"kexPredHead", "=", RowBox[{"Head", "[", "kexPred", "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"unifiedVars", ",", "kexPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "kexPredHead", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"uv", "=", RowBox[{"Unique", "[", RowBox[{"ToString", "[", "kexPredHead", "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"unifiedVars", "[", "kexPredHead", "]"}], "=", "uv"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{"kexCond", "/.", RowBox[{"kexVar", "\[Rule]", "uv"}]}], ")"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "region", " ", "of", " ", "the", " ", "quantifier"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"List", "@@", "kexPred"}], "/.", RowBox[{"kexVar", "\[Rule]", "uv"}]}], ")"}]}], " ", RowBox[{"(*", " ", RowBox[{"predicate", " ", "parameters"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsEXSets", ",", "kexPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"note", ":", " ", RowBox[{ "sets", " ", "are", " ", "kept", " ", "separate"}]}], ",", " ", RowBox[{"in", " ", "a", " ", "list"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{ RowBox[{"combinedKnownsEXSets", "[", "kexPredHead", "]"}], ",", "quantSet"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"combinedKnownsEXSets", "[", "kexPredHead", "]"}], "=", RowBox[{"{", "quantSet", "}"}]}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Head", "[", "kexPred", "]"}], "===", "Not"}], "&&", "\[IndentingNewLine]", RowBox[{ RowBox[{"Head", "[", "kexVar", "]"}], "===", "Symbol"}], "&&", "\[IndentingNewLine]", RowBox[{ RowBox[{"Max", "@@", RowBox[{"Length", "/@", RowBox[{"Position", "[", RowBox[{ RowBox[{"kexPred", "[", RowBox[{"[", "1", "]"}], "]"}], ",", "kexVar"}], "]"}]}]}], "\[Equal]", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"negation", " ", "of", " ", "predicate"}], ",", " ", RowBox[{ "accumulate", " ", "separate", " ", "set", " ", "for", " ", "that", " ", "name"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"kexPredHead", "=", RowBox[{"Head", "[", RowBox[{"kexPred", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"unifiedVars", ",", "kexPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "kexPredHead", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"uv", "=", RowBox[{"Unique", "[", RowBox[{"ToString", "[", "kexPredHead", "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"unifiedVars", "[", "kexPredHead", "]"}], "=", "uv"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{"kexCond", "/.", RowBox[{"kexVar", "\[Rule]", "uv"}]}], ")"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "region", " ", "of", " ", "the", " ", "quantifier"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"List", "@@", RowBox[{"kexPred", "[", RowBox[{"[", "1", "]"}], "]"}]}], "/.", RowBox[{"kexVar", "\[Rule]", "uv"}]}], ")"}]}], " ", RowBox[{"(*", " ", RowBox[{"predicate", " ", "parameters"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsEXNSets", ",", "kexPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"note", ":", " ", RowBox[{ "sets", " ", "are", " ", "kept", " ", "separate"}]}], ",", " ", RowBox[{"in", " ", "a", " ", "list"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{ RowBox[{ "combinedKnownsEXNSets", "[", "kexPredHead", "]"}], ",", "quantSet"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ "combinedKnownsEXNSets", "[", "kexPredHead", "]"}], "=", RowBox[{"{", "quantSet", "}"}]}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "kex", ",", "\"\< is not supported (wrong predicate)\>\""}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "knownsEXPos"}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"1", RowBox[{"c", ".", " ", "find"}], " ", "FA", " ", "and", " ", "EX", " ", "quantifiers", " ", "in", " ", "question", " ", "as", " ", "well", " ", "and", " ", "collect", " ", "their", " ", "predicate", " ", "names"}], ",", " ", RowBox[{ "so", " ", "that", " ", "they", " ", "can", " ", "be", " ", "recognized", " ", "in", " ", "knowns", " ", "even", " ", "if", " ", "they", " ", "exist", " ", "there", " ", "in", " ", "free", " ", "form", " ", "only"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qpos", ",", " ", RowBox[{"(*", " ", RowBox[{ "qpos", " ", "is", " ", "position", " ", "of", " ", "FA", " ", "or", " ", "EX", " ", "quantifier", " ", "in", " ", "question"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"qfa", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"qpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", "question", ",", RowBox[{"Extract", "[", RowBox[{"question", ",", "qpos"}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"qfaVar", "=", RowBox[{"qfa", "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", "variable", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qfaPred", "=", RowBox[{"qfa", "[", RowBox[{"[", "3", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", "predicate", " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Head", "[", "qfaVar", "]"}], "===", "Symbol"}], "&&", "\[IndentingNewLine]", RowBox[{ RowBox[{"Max", "@@", RowBox[{"Length", "/@", RowBox[{"Position", "[", RowBox[{"qfaPred", ",", "qfaVar"}], "]"}]}]}], "\[Equal]", "1"}]}], ",", " ", " ", RowBox[{"(*", " ", RowBox[{"n", "-", RowBox[{ "ary", " ", "predicates", " ", "over", " ", "one", " ", "variable", " ", "are", " ", "supported"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"qfaPredHead", "=", RowBox[{"Head", "[", "qfaPred", "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Not", "[", RowBox[{"KeyExistsQ", "[", RowBox[{"unifiedVars", ",", "qfaPredHead"}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"uv", "=", RowBox[{"Unique", "[", RowBox[{"ToString", "[", "qfaPredHead", "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"unifiedVars", "[", "qfaPredHead", "]"}], "=", "uv"}]}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Head", "[", "qfaPred", "]"}], "===", "Not"}], "&&", "\[IndentingNewLine]", RowBox[{ RowBox[{"Head", "[", "qfaVar", "]"}], "===", "Symbol"}], "&&", "\[IndentingNewLine]", RowBox[{ RowBox[{"Max", "@@", RowBox[{"Length", "/@", RowBox[{"Position", "[", RowBox[{ RowBox[{"qfaPred", "[", RowBox[{"[", "1", "]"}], "]"}], ",", "qfaVar"}], "]"}]}]}], "\[Equal]", "1"}]}], ",", " ", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"negation", " ", "of", " ", "predicate"}], ",", " ", RowBox[{ "accumulate", " ", "separate", " ", "set", " ", "for", " ", "that", " ", "name"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"qfaPredHead", "=", RowBox[{"Head", "[", RowBox[{"qfaPred", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Not", "[", RowBox[{"KeyExistsQ", "[", RowBox[{"unifiedVars", ",", "qfaPredHead"}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"uv", "=", RowBox[{"Unique", "[", RowBox[{"ToString", "[", "qfaPredHead", "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"unifiedVars", "[", "qfaPredHead", "]"}], "=", "uv"}]}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "qfa", ",", "\"\< is not supported (wrong predicate)\>\""}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Union", "[", RowBox[{"questionFAPos", ",", "questionEXPos"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"1", RowBox[{"d", ".", " ", "find"}], " ", "all", " ", "free", " ", "predicates", " ", "in", " ", "knowns", " ", "or", " ", "their", " ", "negations", " ", RowBox[{"(", RowBox[{ "those", " ", "that", " ", "were", " ", "used", " ", "in", " ", "quantifiers"}], ")"}], " ", "and", " ", "add", " ", "them", " ", "to", " ", "combinedKnownsFASets"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ph", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"ph", " ", "is", " ", "predicate", " ", "head"}], ",", " ", RowBox[{ "one", " ", "of", " ", "those", " ", "found", " ", "in", " ", "quantifiers"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "ph", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "find", " ", "predicates", " ", "used", " ", "directly", " ", RowBox[{"(", RowBox[{"without", " ", "negation"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"knowns2", ",", RowBox[{"_ForAll", "|", "_Exists"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"kPredPos", "=", RowBox[{"{", "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "ignore", " ", "predicate", " ", "if", " ", "ForAll", " ", "or", " ", "Exists", " ", "is", " ", "the", " ", "whole", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"kPredPos", "=", RowBox[{"Position", "[", RowBox[{"knowns2", ",", "_ph", ",", RowBox[{"{", "1", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"kpos", ",", " ", RowBox[{"(*", " ", RowBox[{ "kpos", " ", "is", " ", "position", " ", "of", " ", "free", " ", "predicate", " ", "in", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"kPred", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"kpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", "knowns2", ",", RowBox[{"Extract", "[", RowBox[{"knowns2", ",", "kpos"}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"knownsPredPos", ",", "kpos"}], "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "kPred", "]"}], "==", "1"}], ",", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"uv", "==", RowBox[{"kPred", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "implicit", " ", "region", " ", "for", " ", "unary", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", "uv", "}"}]}], " ", RowBox[{"(*", " ", RowBox[{ "implicit", " ", "parameter", " ", "for", " ", "unary", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"True", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"implicit", " ", "region", " ", "for", " ", "n"}], "-", RowBox[{"ary", " ", "predicate"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"List", "@@", "kPred"}]}], " ", RowBox[{"(*", " ", "parameters", " ", "*)"}], "\[IndentingNewLine]", "}"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFASets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{ RowBox[{"combinedKnownsFASets", "[", "ph", "]"}], ",", "quantSet"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"combinedKnownsFASets", "[", "ph", "]"}], "=", RowBox[{"{", "quantSet", "}"}]}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", RowBox[{"(*", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsEXSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{ RowBox[{"combinedKnownsEXSets", "[", "ph", "]"}], ",", "quantSet"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"combinedKnownsEXSets", "[", "ph", "]"}], "=", RowBox[{"{", "quantSet", "}"}]}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "*)"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "kPredPos"}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "find", " ", "negated", " ", "predicates", " ", "as", " ", "well"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"knowns2", ",", RowBox[{"_ForAll", "|", "_Exists"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"kPredPos", "=", RowBox[{"{", "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "ignore", " ", "predicate", " ", "if", " ", "ForAll", " ", "or", " ", "Exists", " ", "is", " ", "the", " ", "whole", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"kPredPos", "=", RowBox[{"Position", "[", RowBox[{"knowns2", ",", RowBox[{"Not", "[", "_ph", "]"}], ",", RowBox[{"{", "1", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"kpos", ",", " ", RowBox[{"(*", " ", RowBox[{ "kpos", " ", "is", " ", "position", " ", "of", " ", "free", " ", "negated", " ", "predicate", " ", "in", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"kPred", "=", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"kpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", "knowns2", ",", RowBox[{"Extract", "[", RowBox[{"knowns2", ",", "kpos"}], "]"}]}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"knownsPredPos", ",", "kpos"}], "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "kPred", "]"}], "==", "1"}], ",", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"uv", "==", RowBox[{"kPred", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "implicit", " ", "region", " ", "for", " ", "unary", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", "uv", "}"}]}], " ", RowBox[{"(*", " ", RowBox[{ "implicit", " ", "parameter", " ", "for", " ", "unary", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"True", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"implicit", " ", "region", " ", "for", " ", "n"}], "-", RowBox[{"ary", " ", "predicate"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"List", "@@", "kPred"}]}], " ", RowBox[{"(*", " ", "parameters", " ", "*)"}], "\[IndentingNewLine]", "}"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFANSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{ RowBox[{"combinedKnownsFANSets", "[", "ph", "]"}], ",", "quantSet"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"combinedKnownsFANSets", "[", "ph", "]"}], "=", RowBox[{"{", "quantSet", "}"}]}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", RowBox[{"(*", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsEXNSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{ RowBox[{"combinedKnownsEXNSets", "[", "ph", "]"}], ",", "quantSet"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"combinedKnownsEXNSets", "[", "ph", "]"}], "=", RowBox[{"{", "quantSet", "}"}]}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "*)"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "kPredPos"}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Keys", "[", "unifiedVars", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"1", RowBox[{"e", ".", " ", "merge"}], " ", "regions", " ", "of", " ", "FA", " ", "and", " ", "FAN", " ", "quantifiers"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"keepTrying", "=", "True"}], ";", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{"keepTrying", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"keepTrying", "=", "False"}], ";", "\[IndentingNewLine]", RowBox[{"merged", "=", RowBox[{"<|", "|>"}]}], ";", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ph", ",", " ", RowBox[{"(*", " ", RowBox[{ "ph", " ", "is", " ", "predicate", " ", "name", " ", "that", " ", "has", " ", "some", " ", "FA", " ", "sets"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"merged", "[", "ph", "]"}], "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "ph", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qss", ",", " ", RowBox[{"(*", " ", RowBox[{ "qss", " ", "are", " ", "two", " ", "of", " ", "FA", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "sets", " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"region1", "=", RowBox[{"qss", "[", RowBox[{"[", RowBox[{"1", ",", "1"}], "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params1", "=", RowBox[{"qss", "[", RowBox[{"[", RowBox[{"1", ",", "2"}], "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"region2", "=", RowBox[{"qss", "[", RowBox[{"[", RowBox[{"2", ",", "1"}], "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params2", "=", RowBox[{"qss", "[", RowBox[{"[", RowBox[{"2", ",", "2"}], "]"}], "]"}]}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"newQS", "=", "None"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"params1", "===", "params2"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"region1", ",", "region2"}], "]"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"region2", ",", "region1"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"newQS", "=", RowBox[{"{", RowBox[{ RowBox[{"Or", "@@", RowBox[{"Union", "[", RowBox[{"List", "@@", RowBox[{"(", RowBox[{"region1", "||", "region2"}], ")"}]}], "]"}]}], ",", "params1"}], "}"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"cond", "=", RowBox[{"regionMatchPrerequisite", "[", RowBox[{"uv", ",", RowBox[{"qss", "[", RowBox[{"[", "1", "]"}], "]"}], ",", RowBox[{"qss", "[", RowBox[{"[", "2", "]"}], "]"}], ",", "False"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"cond", "=!=", "False"}], "&&", RowBox[{"cond", "=!=", "True"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"region2", ",", "cond"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"newQS", "=", RowBox[{"{", RowBox[{ RowBox[{"cond", "||", "region2"}], ",", "params2"}], "}"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"cond", "=", RowBox[{"regionMatchPrerequisite", "[", RowBox[{"uv", ",", RowBox[{"qss", "[", RowBox[{"[", "2", "]"}], "]"}], ",", RowBox[{"qss", "[", RowBox[{"[", "1", "]"}], "]"}], ",", "False"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"cond", "=!=", "False"}], "&&", RowBox[{"cond", "=!=", "True"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"region1", ",", "cond"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"newQS", "=", RowBox[{"{", RowBox[{ RowBox[{"region1", "||", "cond"}], ",", "params1"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"newQS", "=!=", "None"}], "&&", RowBox[{"FreeQ", "[", RowBox[{ RowBox[{"combinedKnownsFASets", "[", "ph", "]"}], ",", "newQS"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"keepTrying", "=", "True"}], ";", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{ RowBox[{"merged", "[", "ph", "]"}], ",", "newQS"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Subsets", "[", RowBox[{ RowBox[{"combinedKnownsFASets", "[", "ph", "]"}], ",", RowBox[{"{", "2", "}"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Keys", "[", "combinedKnownsFASets", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ph", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"combinedKnownsFASets", "[", "ph", "]"}], "=", RowBox[{"Union", "[", RowBox[{"Join", "[", RowBox[{ RowBox[{"combinedKnownsFASets", "[", "ph", "]"}], ",", RowBox[{"merged", "[", "ph", "]"}]}], "]"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Keys", "[", "merged", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"and", " ", "FAN", " ", "sets", " ", "as", " ", RowBox[{"well", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"keepTrying", "=", "True"}], ";", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{"keepTrying", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"keepTrying", "=", "False"}], ";", "\[IndentingNewLine]", RowBox[{"merged", "=", RowBox[{"<|", "|>"}]}], ";", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ph", ",", " ", RowBox[{"(*", " ", RowBox[{ "ph", " ", "is", " ", "predicate", " ", "name", " ", "that", " ", "has", " ", "some", " ", "FAN", " ", "sets"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"merged", "[", "ph", "]"}], "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "ph", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qss", ",", " ", RowBox[{"(*", " ", RowBox[{ "qss", " ", "are", " ", "two", " ", "of", " ", "FAN", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "sets", " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"region1", "=", RowBox[{"qss", "[", RowBox[{"[", RowBox[{"1", ",", "1"}], "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params1", "=", RowBox[{"qss", "[", RowBox[{"[", RowBox[{"1", ",", "2"}], "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"region2", "=", RowBox[{"qss", "[", RowBox[{"[", RowBox[{"2", ",", "1"}], "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params2", "=", RowBox[{"qss", "[", RowBox[{"[", RowBox[{"2", ",", "2"}], "]"}], "]"}]}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"newQS", "=", "None"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"params1", "===", "params2"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"region1", ",", "region2"}], "]"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"region2", ",", "region1"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"newQS", "=", RowBox[{"{", RowBox[{ RowBox[{"Or", "@@", RowBox[{"Union", "[", RowBox[{"List", "@@", RowBox[{"(", RowBox[{"region1", "||", "region2"}], ")"}]}], "]"}]}], ",", "params1"}], "}"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"cond", "=", RowBox[{"regionMatchPrerequisite", "[", RowBox[{"uv", ",", RowBox[{"qss", "[", RowBox[{"[", "1", "]"}], "]"}], ",", RowBox[{"qss", "[", RowBox[{"[", "2", "]"}], "]"}], ",", "False"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"cond", "=!=", "False"}], "&&", RowBox[{"cond", "=!=", "True"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"region2", ",", "cond"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"newQS", "=", RowBox[{"{", RowBox[{ RowBox[{"cond", "||", "region2"}], ",", "params2"}], "}"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"cond", "=", RowBox[{"regionMatchPrerequisite", "[", RowBox[{"uv", ",", RowBox[{"qss", "[", RowBox[{"[", "2", "]"}], "]"}], ",", RowBox[{"qss", "[", RowBox[{"[", "1", "]"}], "]"}], ",", "False"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"cond", "=!=", "False"}], "&&", RowBox[{"cond", "=!=", "True"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"region1", ",", "cond"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"newQS", "=", RowBox[{"{", RowBox[{ RowBox[{"region1", "||", "cond"}], ",", "params1"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"newQS", "=!=", "None"}], "&&", RowBox[{"FreeQ", "[", RowBox[{ RowBox[{"combinedKnownsFANSets", "[", "ph", "]"}], ",", "newQS"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"keepTrying", "=", "True"}], ";", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{ RowBox[{"merged", "[", "ph", "]"}], ",", "newQS"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Subsets", "[", RowBox[{ RowBox[{"combinedKnownsFANSets", "[", "ph", "]"}], ",", RowBox[{"{", "2", "}"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Keys", "[", "combinedKnownsFANSets", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ph", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"combinedKnownsFANSets", "[", "ph", "]"}], "=", RowBox[{"Union", "[", RowBox[{"Join", "[", RowBox[{ RowBox[{"combinedKnownsFANSets", "[", "ph", "]"}], ",", RowBox[{"merged", "[", "ph", "]"}]}], "]"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Keys", "[", "merged", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "2.", " ", "find", " ", "quantifiers", " ", "and", " ", "free", " ", "predicates", " ", "in", " ", "question", " ", "and", " ", "prepare", " ", "replacement", " ", "rules", " ", "for", " ", "them"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"2", RowBox[{"a", ".", " ", "find"}], " ", "FA", " ", "quantifiers"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qpos", ",", " ", RowBox[{"(*", " ", RowBox[{ "qpos", " ", "is", " ", "position", " ", "of", " ", "FA", " ", "quantifier", " ", "in", " ", "question"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"qfa", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"qpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", "question", ",", RowBox[{"Extract", "[", RowBox[{"question", ",", "qpos"}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"qfaVar", "=", RowBox[{"qfa", "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", "variable", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qfaCond", "=", RowBox[{"qfa", "[", RowBox[{"[", "2", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"constraining", " ", "condition"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qfaPred", "=", RowBox[{"qfa", "[", RowBox[{"[", "3", "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Head", "[", "qfaVar", "]"}], "===", "Symbol"}], "&&", "\[IndentingNewLine]", RowBox[{ RowBox[{"Max", "@@", RowBox[{"Length", "/@", RowBox[{"Position", "[", RowBox[{"qfaPred", ",", "qfaVar"}], "]"}]}]}], "\[Equal]", "1"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"quantifier", " ", "with", " ", "direct", " ", RowBox[{"(", RowBox[{"non", "-", "negated"}], ")"}], " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"qfaPredHead", "=", RowBox[{"Head", "[", "qfaPred", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "qfaPredHead", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{"qfaCond", "/.", RowBox[{"qfaVar", "\[Rule]", "uv"}]}], ")"}], ",", " ", RowBox[{"(*", " ", "region", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"List", "@@", "qfaPred"}], "/.", RowBox[{"qfaVar", "\[Rule]", "uv"}]}], ")"}]}], " ", RowBox[{"(*", " ", "parameters", " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFASets", ",", "qfaPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"qRep", "=", "False"}], ";", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FA", " ", RowBox[{"{", RowBox[{"region", ",", "parameters"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{"qRep", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "quantSet", ",", "qs", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{ "combinedKnownsFASets", "[", "qfaPredHead", "]"}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "no", " ", "such", " ", "predicate", " ", "was", " ", "used", " ", "in", " ", "knowns"}], ",", " ", RowBox[{ "so", " ", "this", " ", "FA", " ", "in", " ", "question", " ", "resolves", " ", "against", " ", "empty", " ", "known", " ", "set"}], ",", " ", RowBox[{ "irrespective", " ", "of", " ", "its", " ", "parameters"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{ RowBox[{"quantSet", "[", RowBox[{"[", "1", "]"}], "]"}], "\[Implies]", "False"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"questionReplacements", ",", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"qpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"{", RowBox[{"{", "}"}], "}"}], ",", "qpos"}], "]"}], "\[Rule]", "qRep"}]}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"qfaPred", ",", RowBox[{"Not", "[", "_", "]"}]}], "]"}], "&&", RowBox[{"MemberQ", "[", RowBox[{ RowBox[{"qfaPred", "[", RowBox[{"[", "1", "]"}], "]"}], ",", "qfaVar"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "quantifier", " ", "with", " ", "negated", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"qfaPredHead", "=", RowBox[{"Head", "[", RowBox[{"qfaPred", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "qfaPredHead", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{"qfaCond", "/.", RowBox[{"qfaVar", "\[Rule]", "uv"}]}], ")"}], ",", " ", RowBox[{"(*", " ", "region", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"List", "@@", RowBox[{"qfaPred", "[", RowBox[{"[", "1", "]"}], "]"}]}], "/.", RowBox[{"qfaVar", "\[Rule]", "uv"}]}], ")"}]}], " ", RowBox[{"(*", " ", "parameters", " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFANSets", ",", "qfaPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"qRep", "=", "False"}], ";", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FAN", " ", RowBox[{"{", RowBox[{"region", ",", "parameters"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{"qRep", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "quantSet", ",", "qs", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{ "combinedKnownsFANSets", "[", "qfaPredHead", "]"}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "no", " ", "such", " ", "predicate", " ", "was", " ", "used", " ", "in", " ", "knowns"}], ",", " ", RowBox[{ "so", " ", "this", " ", "FAN", " ", "in", " ", "question", " ", "resolves", " ", "against", " ", "empty", " ", "known", " ", "set"}], ",", " ", RowBox[{ "irrespective", " ", "of", " ", "its", " ", "parameters"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{ RowBox[{"quantSet", "[", RowBox[{"[", "1", "]"}], "]"}], "\[Implies]", "False"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"questionReplacements", ",", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"qpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"{", RowBox[{"{", "}"}], "}"}], ",", "qpos"}], "]"}], "\[Rule]", "qRep"}]}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "qfa", ",", "\"\< is not supported (wrong predicate)\>\""}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "questionFAPos"}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"2", RowBox[{"b", ".", " ", "find"}], " ", "EX", " ", "quantifiers"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qpos", ",", " ", RowBox[{"(*", " ", RowBox[{ "qpos", " ", "is", " ", "position", " ", "of", " ", "EX", " ", "quantifier", " ", "in", " ", "question"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"qex", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"qpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", "question", ",", RowBox[{"Extract", "[", RowBox[{"question", ",", "qpos"}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"qexVar", "=", RowBox[{"qex", "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", "variable", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qexCond", "=", RowBox[{"qex", "[", RowBox[{"[", "2", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"constraining", " ", "condition"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qexPred", "=", RowBox[{"qex", "[", RowBox[{"[", "3", "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Head", "[", "qexVar", "]"}], "===", "Symbol"}], "&&", "\[IndentingNewLine]", RowBox[{ RowBox[{"Max", "@@", RowBox[{"Length", "/@", RowBox[{"Position", "[", RowBox[{"qexPred", ",", "qfaVar"}], "]"}]}]}], "\[Equal]", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"quantifier", " ", "with", " ", "direct", " ", RowBox[{"(", RowBox[{"non", "-", "negated"}], ")"}], " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"qexPredHead", "=", RowBox[{"Head", "[", "qexPred", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "qexPredHead", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{"qexCond", "/.", RowBox[{"qexVar", "\[Rule]", "uv"}]}], ")"}], ",", " ", RowBox[{"(*", " ", "region", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"List", "@@", "qexPred"}], "/.", RowBox[{"qexVar", "\[Rule]", "uv"}]}], ")"}]}], " ", RowBox[{"(*", " ", "parameters", " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"qRep", "=", "False"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsEXSets", ",", "qexPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "EX", " ", RowBox[{"{", RowBox[{"region", ",", "parameters"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{"qRep", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "qs", ",", "quantSet", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{ "combinedKnownsEXSets", "[", "qexPredHead", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "no", " ", "such", " ", "predicate", " ", "was", " ", "used", " ", "in", " ", "knowns"}], ",", " ", RowBox[{ "so", " ", "this", " ", "EX", " ", "in", " ", "question", " ", "resolves", " ", "against", " ", "empty", " ", "known", " ", "set"}], ",", " ", RowBox[{ "irrespective", " ", "of", " ", "its", " ", "parameters"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{ RowBox[{"quantSet", "[", RowBox[{"[", "1", "]"}], "]"}], "\[Implies]", "False"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFANSets", ",", "qexPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FAN", " ", RowBox[{"{", RowBox[{"region", ",", "parameters"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{"qRep", "&&", RowBox[{"!", RowBox[{"regionMatchCondition", "[", RowBox[{ "uv", ",", "quantSet", ",", "qs", ",", "Indeterminate"}], "]"}]}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{ "combinedKnownsFANSets", "[", "qexPredHead", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFASets", ",", "qexPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FA", " ", RowBox[{"{", RowBox[{"region", ",", "parameters"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{"qRep", "||", RowBox[{"satisfy", "[", RowBox[{"regionMatchCondition", "[", RowBox[{ "uv", ",", "quantSet", ",", "qs", ",", "Indeterminate"}], "]"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{ "combinedKnownsFASets", "[", "qexPredHead", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"questionReplacements", ",", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"qpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"{", RowBox[{"{", "}"}], "}"}], ",", "qpos"}], "]"}], "\[Rule]", "qRep"}]}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"qexPred", ",", RowBox[{"Not", "[", "_", "]"}]}], "]"}], "&&", RowBox[{"MemberQ", "[", RowBox[{ RowBox[{"qexPred", "[", RowBox[{"[", "1", "]"}], "]"}], ",", "qexVar"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "quantifier", " ", "with", " ", "negated", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"qexPredHead", "=", RowBox[{"Head", "[", RowBox[{"qexPred", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "qexPredHead", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{"qexCond", "/.", RowBox[{"qexVar", "\[Rule]", "uv"}]}], ")"}], ",", " ", RowBox[{"(*", " ", "region", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"List", "@@", RowBox[{"qexPred", "[", RowBox[{"[", "1", "]"}], "]"}]}], "/.", RowBox[{"qexVar", "\[Rule]", "uv"}]}], ")"}]}], " ", RowBox[{"(*", " ", "parameters", " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"qRep", "=", "False"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsEXNSets", ",", "qexPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "EXN", " ", RowBox[{"{", RowBox[{"region", ",", "parameters"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{"qRep", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "qs", ",", "quantSet", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{ "combinedKnownsEXNSets", "[", "qexPredHead", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "no", " ", "such", " ", "predicate", " ", "was", " ", "used", " ", "in", " ", "knowns"}], ",", " ", RowBox[{ "so", " ", "this", " ", "EXN", " ", "in", " ", "question", " ", "resolves", " ", "against", " ", "empty", " ", "known", " ", "set"}], ",", " ", RowBox[{ "irrespective", " ", "of", " ", "its", " ", "parameters"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{ RowBox[{"quantSet", "[", RowBox[{"[", "1", "]"}], "]"}], "\[Implies]", "False"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFASets", ",", "qexPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FAN", " ", RowBox[{"{", RowBox[{"region", ",", "parameters"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{"qRep", "&&", RowBox[{"!", RowBox[{"regionMatchCondition", "[", RowBox[{ "uv", ",", "quantSet", ",", "qs", ",", "Indeterminate"}], "]"}]}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{ "combinedKnownsFASets", "[", "qexPredHead", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFANSets", ",", "qexPredHead"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FA", " ", RowBox[{"{", RowBox[{"region", ",", "parameters"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{"qRep", "||", RowBox[{"satisfy", "[", RowBox[{"regionMatchCondition", "[", RowBox[{ "uv", ",", "quantSet", ",", "qs", ",", "Indeterminate"}], "]"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{ "combinedKnownsFANSets", "[", "qexPredHead", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"questionReplacements", ",", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"qpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"{", RowBox[{"{", "}"}], "}"}], ",", "qpos"}], "]"}], "\[Rule]", "qRep"}]}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "qex", ",", "\"\< is not supported (wrong predicate)\>\""}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "questionEXPos"}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"2", RowBox[{"c", ".", " ", "find"}], " ", "also", " ", "free", " ", "uses", " ", "of", " ", "predicates", " ", "in", " ", "question"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"direct", " ", RowBox[{"(", RowBox[{"non", "-", "negated"}], ")"}], " ", RowBox[{"predicates", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ph", ",", " ", RowBox[{"(*", " ", RowBox[{"ph", " ", "is", " ", "predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"question", ",", "_ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"qPreds", "=", RowBox[{"{", RowBox[{"{", "}"}], "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"whole", " ", "question", " ", "is", " ", RowBox[{"ph", "[", "...", "]"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"question", ",", RowBox[{"Not", "[", "_ph", "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"qPreds", "=", RowBox[{"{", "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"whole", " ", "question", " ", "is", " ", RowBox[{"Not", "[", RowBox[{"ph", "[", "...", "]"}], "]"}]}], " ", "-", " ", "ignore"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"question", ",", RowBox[{"_ForAll", "|", "_Exists"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"qPreds", "=", RowBox[{"{", "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "whole", " ", "question", " ", "is", " ", "ForAll", " ", "or", " ", "Exists"}], " ", "-", " ", "ignore"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qPreds", "=", RowBox[{"Position", "[", RowBox[{"question", ",", "_ph", ",", RowBox[{"{", "1", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "ph", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qpos", ",", " ", RowBox[{"(*", " ", RowBox[{ "qpos", " ", "is", " ", "position", " ", "of", " ", "free", " ", "predicate", " ", "in", " ", "question"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"qPr", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"qpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", "question", ",", RowBox[{"Extract", "[", RowBox[{"question", ",", "qpos"}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"True", ",", " ", RowBox[{"(*", " ", RowBox[{ "implicit", " ", "region", " ", "for", " ", "free", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"List", "@@", "qPr"}]}], " ", RowBox[{"(*", " ", "parameters", " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"cond", "=", "False"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFASets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FA", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"cond", "=", RowBox[{"cond", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "quantSet", ",", "qs", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsFASets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsEXSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "EX", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"cond", "=", RowBox[{"cond", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "qs", ",", "quantSet", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsEXSets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"additionally", ",", " ", RowBox[{ "match", " ", "based", " ", "on", " ", "value", " ", "equality", " ", "with", " ", "free", " ", "predicates", " ", "in", " ", "knowns"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "free", " ", "predicates", " ", "in", " ", "knowns", " ", "were", " ", "added", " ", "to", " ", "both", " ", "FA", " ", "and", " ", "EX", " ", "sets", " ", "with", " ", "True", " ", "regions", " ", RowBox[{"(", RowBox[{ "and", " ", "with", " ", "no", " ", "reference", " ", "to", " ", "univied", " ", "var"}], ")"}]}], ",", " ", RowBox[{ "so", " ", "it", " ", "is", " ", "enough", " ", "to", " ", "match", " ", "only", " ", "one", " ", "of", " ", "them", " ", RowBox[{"(", RowBox[{ RowBox[{"let", "'"}], "s", " ", "say", " ", "FA"}], ")"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFASets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FA", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"region", "=", RowBox[{"qs", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params", "=", RowBox[{"qs", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"qP", "=", RowBox[{"quantSet", "[", RowBox[{"[", "2", "]"}], "]"}]}]}], " ", RowBox[{"(*", " ", RowBox[{ "parameters", " ", "of", " ", "the", " ", "processed", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"region", "===", "True"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"params", ",", "uv"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"cond", "=", RowBox[{"cond", "||", RowBox[{"And", "@@", RowBox[{"Thread", "[", RowBox[{"qP", "\[Equal]", "params"}], "]"}]}]}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsFASets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"ncond", "=", "False"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFANSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FAN", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"ncond", "=", RowBox[{"ncond", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "quantSet", ",", "qs", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsFANSets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsEXNSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "EXN", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"ncond", "=", RowBox[{"ncond", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "qs", ",", "quantSet", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsEXNSets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"additionally", ",", " ", RowBox[{ "match", " ", "based", " ", "on", " ", "value", " ", "equality", " ", "with", " ", "free", " ", "predicates", " ", "in", " ", "knowns"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFANSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FAN", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"region", "=", RowBox[{"qs", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params", "=", RowBox[{"qs", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"qP", "=", RowBox[{"quantSet", "[", RowBox[{"[", "2", "]"}], "]"}]}]}], " ", RowBox[{"(*", " ", RowBox[{ "parameters", " ", "of", " ", "the", " ", "processed", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"region", "===", "True"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"params", ",", "uv"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"ncond", "=", RowBox[{"ncond", "||", RowBox[{"And", "@@", RowBox[{"Thread", "[", RowBox[{"qP", "\[Equal]", "params"}], "]"}]}]}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsFANSets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{"cond", "&&", RowBox[{"!", "ncond"}]}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"questionReplacements", ",", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"qpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"{", RowBox[{"{", "}"}], "}"}], ",", "qpos"}], "]"}], "\[Rule]", "qRep"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "qPreds"}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Keys", "[", "unifiedVars", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"2", "c"}], ",", " ", RowBox[{"negated", " ", RowBox[{"predicates", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ph", ",", " ", RowBox[{"(*", " ", RowBox[{"ph", " ", "is", " ", "predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"question", ",", RowBox[{"Not", "[", "_ph", "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"qPreds", "=", RowBox[{"{", RowBox[{"{", "}"}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MatchQ", "[", RowBox[{"question", ",", RowBox[{"_ForAll", "|", "_Exists"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"qPreds", "=", RowBox[{"{", "}"}]}], ",", " ", RowBox[{"(*", " ", "ignore", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"qPreds", "=", RowBox[{"Position", "[", RowBox[{"question", ",", RowBox[{"Not", "[", "_ph", "]"}], ",", RowBox[{"{", "1", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"uv", "=", RowBox[{"unifiedVars", "[", "ph", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qpos", ",", " ", RowBox[{"(*", " ", RowBox[{ "qpos", " ", "is", " ", "position", " ", "of", " ", "free", " ", "predicate", " ", "in", " ", "question"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"qPr", "=", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"qpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", "question", ",", RowBox[{"Extract", "[", RowBox[{"question", ",", "qpos"}], "]"}]}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"quantSet", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"True", ",", " ", RowBox[{"(*", " ", RowBox[{ "implicit", " ", "region", " ", "for", " ", "free", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"List", "@@", "qPr"}]}], " ", RowBox[{"(*", " ", "parameters", " ", "*)"}], "\[IndentingNewLine]", "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"cond", "=", "False"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFANSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FAN", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"cond", "=", RowBox[{"cond", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "quantSet", ",", "qs", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsFANSets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsEXNSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "EXN", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"cond", "=", RowBox[{"cond", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "qs", ",", "quantSet", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsEXNSets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"additionally", ",", " ", RowBox[{ "match", " ", "based", " ", "on", " ", "value", " ", "equality", " ", "with", " ", "free", " ", "predicates", " ", "in", " ", "knowns"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "free", " ", "predicates", " ", "in", " ", "knowns", " ", "were", " ", "added", " ", "to", " ", "both", " ", "FA", " ", "and", " ", "EX", " ", "sets", " ", "with", " ", "True", " ", "regions", " ", RowBox[{"(", RowBox[{ "and", " ", "with", " ", "no", " ", "reference", " ", "to", " ", "univied", " ", "var"}], ")"}]}], ",", " ", RowBox[{ "so", " ", "it", " ", "is", " ", "enough", " ", "to", " ", "match", " ", "only", " ", "one", " ", "of", " ", "them", " ", RowBox[{"(", RowBox[{ RowBox[{"let", "'"}], "s", " ", "say", " ", "FA"}], ")"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFANSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FAN", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"region", "=", RowBox[{"qs", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params", "=", RowBox[{"qs", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"qP", "=", RowBox[{"quantSet", "[", RowBox[{"[", "2", "]"}], "]"}]}]}], " ", RowBox[{"(*", " ", RowBox[{ "parameters", " ", "of", " ", "the", " ", "processed", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"region", "===", "True"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"params", ",", "uv"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"cond", "=", RowBox[{"cond", "||", RowBox[{"And", "@@", RowBox[{"Thread", "[", RowBox[{"qP", "\[Equal]", "params"}], "]"}]}]}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsFANSets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"ncond", "=", "False"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFASets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FA", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"ncond", "=", RowBox[{"ncond", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "quantSet", ",", "qs", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsFASets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsEXSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "EX", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"ncond", "=", RowBox[{"ncond", "||", RowBox[{"regionMatchCondition", "[", RowBox[{"uv", ",", "qs", ",", "quantSet", ",", "False"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsEXSets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"additionally", ",", " ", RowBox[{ "match", " ", "based", " ", "on", " ", "value", " ", "equality", " ", "with", " ", "free", " ", "predicates", " ", "in", " ", "knowns"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFASets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qs", ",", " ", RowBox[{"(*", " ", RowBox[{ "qs", " ", "is", " ", "one", " ", "of", " ", "FA", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "from", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"region", "=", RowBox[{"qs", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"params", "=", RowBox[{"qs", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"qP", "=", RowBox[{"quantSet", "[", RowBox[{"[", "2", "]"}], "]"}]}]}], " ", RowBox[{"(*", " ", RowBox[{ "parameters", " ", "of", " ", "the", " ", "processed", " ", "predicate"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"region", "===", "True"}], "&&", RowBox[{"FreeQ", "[", RowBox[{"params", ",", "uv"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"ncond", "=", RowBox[{"ncond", "||", RowBox[{"And", "@@", RowBox[{"Thread", "[", RowBox[{"qP", "\[Equal]", "params"}], "]"}]}]}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsFASets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"qRep", "=", RowBox[{"cond", "&&", RowBox[{"!", "ncond"}]}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"questionReplacements", ",", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"qpos", "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"{", RowBox[{"{", "}"}], "}"}], ",", "qpos"}], "]"}], "\[Rule]", "qRep"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "qPreds"}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Keys", "[", "unifiedVars", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"3.", " ", "deduce", " ", "injected", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"3", RowBox[{"a", ".", " ", "collect"}], " ", "knowns", " ", "from", " ", "EX", " ", "and", " ", "EXN", " ", "sets", " ", RowBox[{"(", RowBox[{ RowBox[{ "pruned", " ", "by", " ", "FAN", " ", "and", " ", "FA", " ", "sets"}], ",", " ", "respectively"}], ")"}], " ", "as", " ", "they", " ", "can", " ", "be", " ", "interpreted", " ", "as", " ", "\"\\"", " ", "that", " ", "something"}], ",", " ", RowBox[{"somewhere", " ", "is", " ", "true"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"injectedKnowns", "=", "True"}], ";", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ph", ",", " ", RowBox[{"(*", " ", RowBox[{ "ph", " ", "is", " ", "predicate", " ", "name", " ", "in", " ", "any", " ", "of", " ", "combined", " ", "EX", " ", "set"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ex", ",", " ", RowBox[{"(*", " ", RowBox[{"ex", " ", "is", " ", "one", " ", "of", " ", "EX", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "for", " ", "the", " ", "given", " ", "predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"injectedKnowns", "=", RowBox[{"injectedKnowns", "&&", RowBox[{"ex", "[", RowBox[{"[", "1", "]"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsEXSets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFANSets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"fan", ",", " ", RowBox[{"(*", " ", RowBox[{ "fan", " ", "is", " ", "one", " ", "of", " ", "FAN", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "for", " ", "the", " ", "given", " ", "predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"injectedKnowns", "=", RowBox[{"injectedKnowns", "&&", RowBox[{"!", RowBox[{"fan", "[", RowBox[{"[", "1", "]"}], "]"}]}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsFANSets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Keys", "[", "combinedKnownsEXSets", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ph", ",", " ", RowBox[{"(*", " ", RowBox[{ "ph", " ", "is", " ", "predicate", " ", "name", " ", "in", " ", "any", " ", "of", " ", "combined", " ", "EXN", " ", "set"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"exn", ",", " ", RowBox[{"(*", " ", RowBox[{ "exn", " ", "is", " ", "one", " ", "of", " ", "EXN", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "for", " ", "the", " ", "given", " ", "predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"injectedKnowns", "=", RowBox[{"injectedKnowns", "&&", RowBox[{"exn", "[", RowBox[{"[", "1", "]"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsEXNSets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"KeyExistsQ", "[", RowBox[{"combinedKnownsFASets", ",", "ph"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"fa", ",", " ", RowBox[{"(*", " ", RowBox[{ "fa", " ", "is", " ", "one", " ", "of", " ", "FA", " ", RowBox[{"{", RowBox[{"region", ",", "params"}], "}"}], " ", "for", " ", "the", " ", "given", " ", "predicate", " ", "name"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"injectedKnowns", "=", RowBox[{"injectedKnowns", "&&", RowBox[{"!", RowBox[{"fa", "[", RowBox[{"[", "1", "]"}], "]"}]}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"combinedKnownsFASets", "[", "ph", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Keys", "[", "combinedKnownsEXNSets", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", "\"\\"", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "combinedKnownsEXSets"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "combinedKnownsEXNSets"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "combinedKnownsFASets"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "combinedKnownsFANSets"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "unifiedVars"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "questionReplacements"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "injectedKnowns"}], "]"}], ";"}], "\[IndentingNewLine]", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"posToDelete", "=", RowBox[{"Union", "[", RowBox[{"knownsFAPos", ",", "knownsEXPos", ",", "knownsPredPos"}], "]"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"rewritten", " ", "knowns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"posToDelete", "==", RowBox[{"{", RowBox[{"{", "}"}], "}"}]}], ",", "\[IndentingNewLine]", "injectedKnowns", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Delete", "[", RowBox[{"knowns2", ",", "posToDelete"}], "]"}], "&&", "injectedKnowns"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"rewritten", " ", "question"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"ReplacePart", "[", RowBox[{"question", ",", "questionReplacements"}], "]"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{"flips", " ", "the", " ", "result"}], ",", " ", RowBox[{"if", " ", "determinate"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"flipResult", "[", "res_", "]"}], ":=", "\[IndentingNewLine]", RowBox[{"Switch", "[", RowBox[{ "res", ",", "\[IndentingNewLine]", "True", ",", "False", ",", "\[IndentingNewLine]", "False", ",", "True", ",", "\[IndentingNewLine]", "_", ",", "res"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{ "applies", " ", "theorem", " ", "to", " ", "knowns", " ", "and", " ", "question"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"th", " ", "is", " ", "\"\\""}], "\[Rule]", RowBox[{ RowBox[{ RowBox[{"Function", "[", "...", "]"}], " ", "or", " ", "\"\\""}], "\[Rule]", RowBox[{ RowBox[{ RowBox[{"Implies", "[", RowBox[{"a", ",", "b"}], "]"}], " ", "or", " ", "\"\\""}], "\[Rule]", RowBox[{"Rule", "[", RowBox[{"a", ",", "b"}], "]"}]}]}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"applyTheorem", "[", RowBox[{"knowns_", ",", "question_", ",", "th_"}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Head", "[", RowBox[{"th", "[", RowBox[{"[", "2", "]"}], "]"}], "]"}], "===", "Implies"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"use", " ", "the", " ", "implication", " ", "a"}], "\[Implies]", RowBox[{"b", " ", "to", " ", "add", " ", "b"}]}], ",", " ", RowBox[{ "if", " ", "a", " ", "is", " ", "present", " ", "in", " ", "knowns"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "=", RowBox[{"th", "[", RowBox[{"[", RowBox[{"2", ",", "1"}], "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"b", "=", RowBox[{"th", "[", RowBox[{"[", RowBox[{"2", ",", "2"}], "]"}], "]"}]}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Head", "[", "a", "]"}], "===", "And"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"find", " ", "all", " ", "elements", " ", "separately"}], ",", " ", RowBox[{ "they", " ", "are", " ", "not", " ", "matched", " ", "properly", " ", "by", " ", "Cases"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Map", "[", RowBox[{ RowBox[{ RowBox[{"MemberQ", "[", RowBox[{"knowns", ",", "#"}], "]"}], "&"}], ",", "a"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"And", "[", RowBox[{"knowns", ",", "b"}], "]"}], ",", "question"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"knowns", ",", "question"}], "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Cases", "[", RowBox[{"knowns", ",", "a", ",", RowBox[{"{", "1", "}"}]}], "]"}], "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"And", "[", RowBox[{"knowns", ",", "b"}], "]"}], ",", "question"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"knowns", ",", "question"}], "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Head", "[", RowBox[{"th", "[", RowBox[{"[", "2", "]"}], "]"}], "]"}], "===", "Rule"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"use", " ", "the", " ", "rule", " ", "a"}], "\[Rule]", RowBox[{ "b", " ", "to", " ", "replace", " ", "a", " ", "with", " ", "b", " ", "in", " ", "both", " ", "knowns", " ", "and", " ", "question"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"knowns", ",", "question"}], "}"}], "/.", RowBox[{"th", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"otherwise", ",", " ", RowBox[{ "treat", " ", "the", " ", "theorem", " ", "as", " ", "executable", " ", "function", " ", "that", " ", "rewrites", " ", "both", " ", "knowns", " ", "and", " ", "question"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"th", "[", RowBox[{"[", "2", "]"}], "]"}], "[", RowBox[{"knowns", ",", "question"}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"applyTheorems", "[", RowBox[{"knowns_", ",", "question_", ",", "ths_List"}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"knowns2", "=", "knowns"}], ",", "\[IndentingNewLine]", RowBox[{"question2", "=", "question"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"th", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"th", " ", "is", " ", "\"\\""}], "\[Rule]", RowBox[{ RowBox[{"Function", " ", "or", " ", "\"\\""}], "\[Rule]", RowBox[{ RowBox[{"Implies", " ", "or", " ", "\"\\""}], "\[Rule]", "Rule"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"knowns2", ",", "question2"}], "}"}], "=", RowBox[{"applyTheorem", "[", RowBox[{"knowns2", ",", "question2", ",", "th"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "ths"}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"knowns2", ",", "question2"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{ RowBox[{"replaces", " ", "instances", " ", RowBox[{"of", " ", "!"}], "x", " ", "with", " ", "x"}], "==", RowBox[{"False", " ", "expressions"}]}], ",", "\[IndentingNewLine]", RowBox[{ "this", " ", "helps", " ", "internal", " ", "solver", " ", "engines"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"rewriteNots", "[", "expr_", "]"}], ":=", RowBox[{"expr", "/.", RowBox[{ RowBox[{"Not", "[", "e_", "]"}], "->", RowBox[{"(", RowBox[{"e", "==", "False"}], ")"}]}]}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"validation", " ", "driver"}], ",", " ", RowBox[{ RowBox[{ "facilitates", " ", "use", " ", "with", " ", "single", " ", "term", " ", "as", " ", "first", " ", "argument"}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"this", " ", "driver", " ", "also", " ", "handles", " ", "x"}], "\[Element]", RowBox[{"set", " ", "entries", " ", "other", " ", "than", " ", "x"}], "\[Element]", RowBox[{"Reals", " ", "and", " ", "x"}], "\[Element]", "Integers"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"validate", "[", RowBox[{"knowns_", ",", "question_", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"theorems", "\[Rule]", RowBox[{"{", "}"}]}], ",", RowBox[{"maxSteps", "\[Rule]", "3"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"theoremsOpt", "=", RowBox[{"OptionValue", "[", "theorems", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"maxStepsOpt", "=", RowBox[{"OptionValue", "[", "maxSteps", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"verboseOpt", "=", RowBox[{"OptionValue", "[", "verbose", "]"}]}], ",", "\[IndentingNewLine]", "knowns2", ",", "question2", ",", " ", RowBox[{"(*", " ", RowBox[{ "knowns", " ", "and", " ", "question", " ", "after", " ", "application", " ", "of", " ", "theorems"}], " ", "*)"}], "\[IndentingNewLine]", "spanVarReplacements", ",", "\[IndentingNewLine]", "prunedKnowns", ",", "\[IndentingNewLine]", "simpleQuestion", ",", "\[IndentingNewLine]", "res"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"sanity", " ", "check"}], ",", " ", RowBox[{"higher", "-", RowBox[{ "level", " ", "code", " ", "uses", " ", "lists", " ", "to", " ", "group", " ", "terms"}]}], ",", " ", RowBox[{ "the", " ", "knowns", " ", "and", " ", "question", " ", "should", " ", "come", " ", "here", " ", "already", " ", "combined", " ", "with", " ", "And"}], ",", " ", "Or", ",", " ", RowBox[{"etc", "."}], ",", " ", RowBox[{"not", " ", "as", " ", "raw", " ", RowBox[{"list", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"ListQ", "[", "knowns", "]"}], "||", RowBox[{"ListQ", "[", "question", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "question"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "=!=", "Skip"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"apply", " ", "optional", " ", "theorems"}], ",", " ", RowBox[{"in", " ", "order"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"knowns2", ",", "question2"}], "}"}], "=", RowBox[{"applyTheorems", "[", RowBox[{"knowns", ",", "question", ",", "theoremsOpt"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"handle", " ", "Spans", " ", "and", " ", "sets"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"spanVarReplacements", ",", "prunedKnowns"}], "}"}], "=", RowBox[{"extractSpanDeclarations", "[", "knowns2", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"prunedKnowns", "=", RowBox[{"rewriteSets", "[", RowBox[{"prunedKnowns", ",", "spanVarReplacements"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "attempt", " ", "to", " ", "simplify", " ", "the", " ", "question"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"simpleQuestion", "=", RowBox[{"FullSimplify", "[", RowBox[{"rewriteSets", "[", RowBox[{"question2", ",", "spanVarReplacements"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "handle", " ", "ForAll", " ", "quantifiers", " ", "and", " ", "their", " ", "matching", " ", "free", " ", "predicates"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"prunedKnowns", ",", "simpleQuestion"}], "}"}], "=", RowBox[{"rewriteQuantifiers", "[", RowBox[{"prunedKnowns", ",", "simpleQuestion"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{"rewrite", " ", "!"}], "x", " ", "into", " ", "x"}], "==", "False"}], ",", " ", RowBox[{"to", " ", "help", " ", "internal", " ", "solvers"}]}], " ", "*)"}], RowBox[{"prunedKnowns", "=", RowBox[{"rewriteNots", "[", "prunedKnowns", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "===", "Monitor"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "knowns", ",", "\"\<,\\n\>\"", ",", "question"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "===", "True"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "knowns", ",", "\"\<,\\n\>\"", ",", "question"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"theoremsOpt", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "knowns2", ",", "\"\<,\\n\>\"", ",", "question2"}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "prunedKnowns", ",", "\"\<,\\n\>\"", ",", "simpleQuestion"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"finalResult", "[", "\[IndentingNewLine]", RowBox[{"deduce", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"List", "[", RowBox[{"And", "[", RowBox[{"prunedKnowns", ",", RowBox[{"Not", "[", "simpleQuestion", "]"}]}], "]"}], "]"}], ",", "\[IndentingNewLine]", "standardRules", ",", RowBox[{"finalTerms", "\[Rule]", RowBox[{"{", "False", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"maxSteps", "\[Rule]", "maxStepsOpt"}], ",", RowBox[{"verbose", "\[Rule]", "verboseOpt"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}]}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", "Indeterminate"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"flipResult", "[", "res", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", "res"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ "driver", " ", "for", " ", "piecewise", " ", "computation", " ", "of", " ", "larger", " ", "proofs", " ", "that", " ", "contain", " ", "x"}], "\[Element]", RowBox[{ RowBox[{"{", "...", "}"}], " ", "entries"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"this", " ", "driver", " ", "also", " ", "handles", " ", "x"}], "\[Element]", RowBox[{"set", " ", "entries", " ", "other", " ", "than", " ", "x"}], "\[Element]", RowBox[{"Reals", " ", "and", " ", "x"}], "\[Element]", "Integers"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"validatePiecewise", "[", RowBox[{"knowns_", ",", "question_", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"theorems", "\[Rule]", RowBox[{"{", "}"}]}], ",", RowBox[{"parallel", "\[Rule]", "False"}], ",", RowBox[{"maxSteps", "\[Rule]", "3"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"theoremsOpt", "=", RowBox[{"OptionValue", "[", "theorems", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"maxStepsOpt", "=", RowBox[{"OptionValue", "[", "maxSteps", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"parallelOpt", "=", RowBox[{"OptionValue", "[", "parallel", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"verboseOpt", "=", RowBox[{"OptionValue", "[", "verbose", "]"}]}], ",", "\[IndentingNewLine]", "knowns2", ",", "question2", ",", " ", RowBox[{"(*", " ", RowBox[{ "knowns", " ", "and", " ", "question", " ", "after", " ", "application", " ", "of", " ", "theorems"}], " ", "*)"}], "\[IndentingNewLine]", "spanVarReplacements", ",", "\[IndentingNewLine]", "parallelWrapper", ",", "\[IndentingNewLine]", "sets", ",", "\[IndentingNewLine]", "prunedKnowns", ",", "\[IndentingNewLine]", "valueAssignments", ",", "\[IndentingNewLine]", "assignmentLength", ",", "\[IndentingNewLine]", "counter", ",", " ", RowBox[{"(*", " ", RowBox[{ "only", " ", "for", " ", "sequential", " ", "progress", " ", "tracking"}], " ", "*)"}], "\[IndentingNewLine]", "simpleQuestion", ",", "\[IndentingNewLine]", "totalRes"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"sanity", " ", "checks"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"ListQ", "[", "question", "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "question"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "=!=", "Skip"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{"parallelOpt", ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "process", " ", "using", " ", "parallel", " ", "kernels"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"parallelWrapper", "=", "Parallelize"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"process", " ", "sequentially"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"parallelWrapper", "=", "Identity"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"apply", " ", "optional", " ", "theorems"}], ",", " ", RowBox[{"in", " ", "order"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"knowns2", ",", "question2"}], "}"}], "=", RowBox[{"applyTheorems", "[", RowBox[{"knowns", ",", "question", ",", "theoremsOpt"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"handle", " ", "Spans", " ", "and", " ", "sets"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"spanVarReplacements", ",", "prunedKnowns"}], "}"}], "=", RowBox[{"extractSpanDeclarations", "[", "knowns2", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "attempt", " ", "to", " ", "simplify", " ", "the", " ", "question"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"simpleQuestion", "=", RowBox[{"FullSimplify", "[", RowBox[{"rewriteSets", "[", RowBox[{"question2", ",", "spanVarReplacements"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "prunedKnowns", " ", "does", " ", "not", " ", "have", " ", "to", " ", "contain", " ", "the", " ", "entries", " ", "that", " ", "are", " ", "gathered", " ", "anyway", " ", "at", " ", "level", " ", "1", " ", "in", " ", "sets", " ", "and", " ", "valueAssignments", " ", "below"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"prunedKnowns", "=", RowBox[{"DeleteCases", "[", RowBox[{"prunedKnowns", ",", RowBox[{"Element", "[", RowBox[{"_Symbol", ",", "_List"}], "]"}], ",", "1"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"prunedKnowns", "=", RowBox[{"DeleteCases", "[", RowBox[{"prunedKnowns", ",", RowBox[{"Element", "[", RowBox[{"_Symbol", ",", "Booleans"}], "]"}], ",", "1"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"prunedKnowns", "=", RowBox[{"rewriteSets", "[", RowBox[{"prunedKnowns", ",", "spanVarReplacements"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "handle", " ", "ForAll", " ", "quantifiers", " ", "and", " ", "their", " ", "matching", " ", "free", " ", "predicates"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"prunedKnowns", ",", "simpleQuestion"}], "}"}], "=", RowBox[{"rewriteQuantifiers", "[", RowBox[{"prunedKnowns", ",", "simpleQuestion"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "===", "Monitor"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "knowns", ",", "\"\<,\\n\>\"", ",", "question"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "===", "True"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "knowns", ",", "\"\<,\\n\>\"", ",", "question"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"theoremsOpt", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "knowns2", ",", "\"\<,\\n\>\"", ",", "question2"}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "prunedKnowns", ",", "\"\<,\\n\>\"", ",", "simpleQuestion"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"sets", "=", RowBox[{"Join", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Cases", "[", RowBox[{"knowns2", ",", RowBox[{"Element", "[", RowBox[{"name_Symbol", ",", "s_List"}], "]"}], ",", "1"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Cases", "[", RowBox[{"knowns2", ",", RowBox[{ RowBox[{"Element", "[", RowBox[{"name_Symbol", ",", "Booleans"}], "]"}], "\[RuleDelayed]", RowBox[{"Element", "[", RowBox[{"name", ",", RowBox[{"{", RowBox[{"True", ",", "False"}], "}"}]}], "]"}]}], ",", "1"}], "]"}]}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"valueAssignments", "=", RowBox[{ RowBox[{ RowBox[{"Thread", "[", RowBox[{ RowBox[{"sets", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}], "\[Rule]", "#"}], "]"}], "&"}], "/@", RowBox[{"Tuples", "[", RowBox[{"sets", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"assignmentLength", "=", RowBox[{"Length", "[", "valueAssignments", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"parallelOpt", "===", "False"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"counter", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"PrintTemporary", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"ProgressIndicator", "[", RowBox[{ RowBox[{"Dynamic", "[", "counter", "]"}], ",", RowBox[{"{", RowBox[{"0", ",", "assignmentLength"}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\"\< \>\"", ",", RowBox[{"Dynamic", "[", "counter", "]"}], ",", "\"\\"", ",", "assignmentLength"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"totalRes", "=", RowBox[{"And", "@@", RowBox[{"parallelWrapper", "[", "\[IndentingNewLine]", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"assignment", ",", "\[IndentingNewLine]", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ "{", "\[IndentingNewLine]", "res", "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"res", "=", RowBox[{"finalResult", "[", "\[IndentingNewLine]", RowBox[{"deduce", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"List", "[", RowBox[{ RowBox[{"And", "[", RowBox[{"prunedKnowns", ",", RowBox[{"Not", "[", "simpleQuestion", "]"}]}], "]"}], "/.", "assignment"}], "]"}], ",", "\[IndentingNewLine]", "standardRules", ",", RowBox[{"finalTerms", "\[Rule]", RowBox[{"{", "False", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"maxSteps", "\[Rule]", "maxStepsOpt"}], ",", RowBox[{"verbose", "\[Rule]", "verboseOpt"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"flipResult", "[", "res", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"parallelOpt", "===", "False"}], ",", "\[IndentingNewLine]", RowBox[{"++", "counter"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MemberQ", "[", RowBox[{ RowBox[{"{", RowBox[{"Monitor", ",", "True"}], "}"}], ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"res", "=!=", "True"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{ RowBox[{"prettyResult", "[", "res", "]"}], ",", "\"\< with \>\"", ",", "assignment"}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", "res"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "valueAssignments"}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}]}]}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"totalRes", "=", "Indeterminate"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Head", "[", "totalRes", "]"}], "===", "And"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "the", " ", "result", " ", "contains", " ", "at", " ", "least", " ", "one", " ", "Indeterminate", " ", "and", " ", "cannot", " ", "be", " ", "And"}], "-", "ed"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"totalRes", "=", "Indeterminate"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", "totalRes"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"satisfiability", " ", "driver"}], ",", " ", RowBox[{ RowBox[{ "facilitates", " ", "use", " ", "with", " ", "single", " ", "term", " ", "as", " ", "its", " ", "argument"}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"this", " ", "driver", " ", "also", " ", "handles", " ", "x"}], "\[Element]", RowBox[{"set", " ", "entries", " ", "other", " ", "than", " ", "x"}], "\[Element]", RowBox[{"Reals", " ", "and", " ", "x"}], "\[Element]", RowBox[{"Integers", "."}]}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"satisfy", "[", RowBox[{"problem_", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"theorems", "\[Rule]", RowBox[{"{", "}"}]}], ",", RowBox[{"maxSteps", "\[Rule]", "3"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"theoremsOpt", "=", RowBox[{"OptionValue", "[", "theorems", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"maxStepsOpt", "=", RowBox[{"OptionValue", "[", "maxSteps", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"verboseOpt", "=", RowBox[{"OptionValue", "[", "verbose", "]"}]}], ",", "\[IndentingNewLine]", "problem2", ",", "dummyQuestion2", ",", " ", RowBox[{"(*", " ", RowBox[{ "problem", " ", "after", " ", "application", " ", "of", " ", "theorems"}], " ", "*)"}], "\[IndentingNewLine]", "dummyQuestion3", ",", " ", RowBox[{"(*", " ", RowBox[{ "question", " ", "placeholder", " ", "for", " ", "rewriting", " ", "quantifiers"}], " ", "*)"}], "\[IndentingNewLine]", "spanVarReplacements", ",", "\[IndentingNewLine]", "prunedProblem", ",", "\[IndentingNewLine]", "res"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"sanity", " ", "check"}], ",", " ", RowBox[{"higher", "-", RowBox[{ "level", " ", "code", " ", "uses", " ", "lists", " ", "to", " ", "group", " ", "terms"}]}], ",", " ", RowBox[{ "the", " ", "problem", " ", "should", " ", "come", " ", "here", " ", "already", " ", "combined", " ", "with", " ", "And"}], ",", " ", "Or", ",", " ", RowBox[{"etc", "."}], ",", " ", RowBox[{"not", " ", "as", " ", "raw", " ", RowBox[{"list", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"ListQ", "[", "problem", "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "problem"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "=!=", "Skip"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"apply", " ", "optional", " ", "theorems"}], ",", " ", RowBox[{"in", " ", "order"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"problem2", ",", "dummyQuestion2"}], "}"}], "=", RowBox[{"applyTheorems", "[", RowBox[{"problem", ",", "True", ",", "theoremsOpt"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"handle", " ", "Spans", " ", "and", " ", "sets"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"spanVarReplacements", ",", "prunedProblem"}], "}"}], "=", RowBox[{"extractSpanDeclarations", "[", "problem2", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"prunedProblem", "=", RowBox[{"rewriteSets", "[", RowBox[{"prunedProblem", ",", "spanVarReplacements", ",", RowBox[{"leaveBooleans", "\[Rule]", "True"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "handle", " ", "ForAll", " ", "quantifiers", " ", "and", " ", "their", " ", "matching", " ", "free", " ", "predicates"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"prunedProblem", ",", "dummyQuestion3"}], "}"}], "=", RowBox[{"rewriteQuantifiers", "[", RowBox[{"prunedProblem", ",", "True"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "===", "Monitor"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "problem"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "===", "True"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "problem"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"theoremsOpt", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "problem2"}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "prunedProblem"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"finalResult", "[", "\[IndentingNewLine]", RowBox[{"deduce", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"List", "[", "prunedProblem", "]"}], ",", "\[IndentingNewLine]", "standardInstanceRules", ",", RowBox[{"finalTerms", "\[Rule]", RowBox[{"{", RowBox[{"True", ",", "False", ",", "Indeterminate"}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"maxSteps", "\[Rule]", "maxStepsOpt"}], ",", RowBox[{"verbose", "\[Rule]", "verboseOpt"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}]}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", "Indeterminate"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", "res"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"TODO", ":", " ", RowBox[{"satisfyPiecewise", "?"}]}], " ", "*)"}]}]}]], "Input", InitializationCell->True, CellChangeTimes->{{3.9706483407166634`*^9, 3.9706483871331406`*^9}}, CellLabel-> "In[244]:=",ExpressionUUID->"37df5e6c-a9ed-43d2-87a9-fb59215bdc0e"] }, Closed]], Cell[CellGroupData[{ Cell["Standard rules", "Subsection",ExpressionUUID->"8c430146-9b22-4eac-b2b9-c2103c5ad660"], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ RowBox[{ "sometimes", " ", "Reduce", " ", "and", " ", "FullSimplify", " ", "produce", " ", "different", " ", "results", " ", RowBox[{"(", RowBox[{ "or", " ", "only", " ", "one", " ", "of", " ", "them", " ", "can", " ", "solve", " ", "the", " ", "problem"}], ")"}]}], ";", " ", RowBox[{"try", " ", "both"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"trySolve", "[", "t_", "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "vars", ",", "\[IndentingNewLine]", "r", ",", "\[IndentingNewLine]", "fs"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"vars", "=", RowBox[{"Complement", "[", RowBox[{ RowBox[{"Union", "@", RowBox[{"Cases", "[", RowBox[{"t", ",", "_Symbol", ",", RowBox[{"-", "1"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{"Integers", ",", "Reals", ",", "True", ",", "False"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "try", " ", "to", " ", "resolve", " ", "for", " ", "each", " ", "variable", " ", "in", " ", "turn"}], ",", " ", RowBox[{ "until", " ", "conclusive", " ", "result", " ", "is", " ", "reached"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"vars", "!=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"Catch", "[", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"v", ",", " ", RowBox[{"(*", " ", RowBox[{ "v", " ", "is", " ", "one", " ", "of", " ", "vars", " ", "used", " ", "in", " ", "t"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"r", "=", RowBox[{"FullSimplify", "@", RowBox[{"Quiet", "[", RowBox[{"Reduce", "[", RowBox[{"t", ",", "v"}], "]"}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"r", "===", "True"}], "||", RowBox[{"r", "===", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"Throw", "[", "r", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "vars"}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"r", "=", "t"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"r", "===", "True"}], "||", RowBox[{"r", "===", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"conclusive", " ", "result"}], ",", " ", RowBox[{ "no", " ", "need", " ", "to", " ", "try", " ", "FullSimplify", " ", "separately"}]}], " ", "*)"}], "\[IndentingNewLine]", "r", ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"fs", "=", RowBox[{"FullSimplify", "[", "t", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"r", "===", "fs"}], ",", "\[IndentingNewLine]", "r", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "if", " ", "results", " ", "are", " ", "the", " ", "same"}], ",", " ", RowBox[{ "use", " ", "only", " ", "one", " ", "of", " ", "them"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Head", "[", "r", "]"}], "=!=", "Reduce"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"r", ",", "fs"}], "}"}], ",", " ", RowBox[{"(*", " ", RowBox[{"results", " ", "are", " ", "different"}], " ", "*)"}], "\[IndentingNewLine]", "fs"}], " ", RowBox[{"(*", " ", RowBox[{ "Reduce", " ", "failed", " ", "and", " ", "remained", " ", "unevaluated"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "standard", " ", "deduction", " ", "rules", " ", "for", " ", "formula", " ", "simplification"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"standardRules", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "attempt", " ", "to", " ", "reduce", " ", "and", " ", "simplify", " ", "the", " ", "terms", " ", "individually"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", "_", "}"}], "\[Rule]", RowBox[{"(", RowBox[{ RowBox[{"{", "x", "}"}], "\[Function]", RowBox[{"trySolve", "[", "x", "]"}]}], ")"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"attempt", " ", "to", " ", "combine", " ", "terms"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"x_", ",", "y_"}], "}"}], "\[Rule]", RowBox[{"(", RowBox[{ RowBox[{"{", RowBox[{"x", ",", "y"}], "}"}], "\[Function]", RowBox[{"trySolve", "[", RowBox[{"And", "[", RowBox[{"x", ",", "y"}], "]"}], "]"}]}], ")"}]}]}], "\[IndentingNewLine]", "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"returns", " ", RowBox[{"(", RowBox[{"possibly", " ", "empty"}], ")"}], " ", "list", " ", "of", " ", "instances", " ", "or", " ", "Indeterminate"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tryFindInstance", "[", "t_", "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "fs", ",", "\[IndentingNewLine]", "vars", ",", "\[IndentingNewLine]", "instances"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"vars", "=", RowBox[{"Complement", "[", RowBox[{ RowBox[{"Union", "@", RowBox[{"Cases", "[", RowBox[{"t", ",", "_Symbol", ",", RowBox[{"-", "1"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{ "Booleans", ",", "Integers", ",", "Reals", ",", "True", ",", "False"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"vars", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"instances", "=", RowBox[{"Quiet", "@", RowBox[{"FindInstance", "[", RowBox[{"t", ",", "vars"}], "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"instances", "=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"trySolve", "[", "t", "]"}], "\[Equal]", "True"}], ",", RowBox[{"{", "True", "}"}], ",", RowBox[{"{", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"ListQ", "[", "instances", "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Length", "[", "instances", "]"}], ">", "0"}], ",", "\[IndentingNewLine]", "Indeterminate"}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "standard", " ", "deduction", " ", "rules", " ", "for", " ", "finding", " ", "solution", " ", "instances"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"standardInstanceRules", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "_", "}"}], "\[Rule]", RowBox[{"(", RowBox[{ RowBox[{"{", "x", "}"}], "\[Function]", RowBox[{"tryFindInstance", "[", "x", "]"}]}], ")"}]}], "\[IndentingNewLine]", "}"}]}], ";"}]}]}]], "Input", InitializationCell->True, CellLabel-> "In[265]:=",ExpressionUUID->"262882c7-ac46-45b7-8a9f-273373359862"] }, Closed]], Cell[CellGroupData[{ Cell["Event-B modeling", "Subsection",ExpressionUUID->"dea91a47-5b97-4032-b76f-416cd675f4c9"], Cell["\<\ Current limitations: - More abstract set operations and functions expressed as set products are \ not supported. - Event parameters are not supported. - Witness predicates are not supported.\ \>", "Text",ExpressionUUID->"8cb87485-7208-4800-8efd-b87216394e8d"], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{"Event", "-", RowBox[{"B", " ", "style", " ", "of", " ", "modeling"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helpers", " ", "for", " ", "displaying", " ", "proofs"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"prettyProof", "[", RowBox[{"caption_String", ",", "knowns_List", ",", "question_List"}], "]"}], ":=", RowBox[{"Print", "[", "\[IndentingNewLine]", RowBox[{"Grid", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"caption", ",", "SpanFromLeft"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"Column", "@", "knowns"}], ",", RowBox[{"Column", "@", "question"}]}], "}"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"Alignment", "\[Rule]", "Left"}], ",", RowBox[{"Frame", "\[Rule]", "All"}], ",", RowBox[{"Spacings", "->", RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}]}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"prettyReachabilityProof", "[", RowBox[{"caption_String", ",", "knowns_List"}], "]"}], ":=", RowBox[{"Print", "[", "\[IndentingNewLine]", RowBox[{"Grid", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "caption", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"Column", "@", "knowns"}], "}"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"Alignment", "\[Rule]", "Left"}], ",", RowBox[{"Frame", "\[Rule]", "All"}], ",", RowBox[{"Spacings", "->", RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}]}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"prettyPath", "[", "names_List", "]"}], ":=", RowBox[{"StringJoin", "[", RowBox[{"Riffle", "[", RowBox[{"names", ",", "\"\< -> \>\""}], "]"}], "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "helpers", " ", "for", " ", "decomposing", " ", "event", " ", "names", " ", "\"\\""}], "\[Rule]", "\"\\""}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"properName", "[", "fullName_", "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"StringQ", "[", "fullName", "]"}], ",", "fullName", ",", RowBox[{"fullName", "[", RowBox[{"[", "1", "]"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"separateNames", "[", "fullName_", "]"}], ":=", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"StringQ", "[", "fullName", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"fullName", ",", RowBox[{"{", "fullName", "}"}]}], "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"note", ":", " ", RowBox[{ RowBox[{"fullName", "[", RowBox[{"[", "2", "]"}], "]"}], " ", "can", " ", "be", " ", "a", " ", "list", " ", "of", " ", "strings"}]}], ",", " ", RowBox[{"if", " ", "the", " ", "event", " ", "is", " ", "merging"}], ",", "\[IndentingNewLine]", RowBox[{ "so", " ", "the", " ", "list", " ", "is", " ", "always", " ", "returned", " ", "for", " ", "unification"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"fullName", "[", RowBox[{"[", "1", "]"}], "]"}], ",", RowBox[{"ensureList", "[", RowBox[{"fullName", "[", RowBox[{"[", "2", "]"}], "]"}], "]"}]}], "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"helper", " ", "for", " ", "dividing", " ", "actions", " ", RowBox[{"(", RowBox[{"including", " ", "init", " ", "actions"}], ")"}], " ", "into", " ", "deterministic", " ", "assignments", " ", "and", " ", "non"}], "-", RowBox[{"deterministic", " ", "promises"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"splitActionsPromises", "[", "acts_", "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "groups", ",", "\[IndentingNewLine]", "actions", ",", "\[IndentingNewLine]", "promises"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"groups", "=", RowBox[{"GroupBy", "[", RowBox[{"acts", ",", RowBox[{ RowBox[{ RowBox[{"Head", "[", "#", "]"}], "===", "Rule"}], "&"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"actions", "=", RowBox[{"Lookup", "[", RowBox[{"groups", ",", "True", ",", RowBox[{"{", "}"}]}], "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"actions", " ", "or", " ", "empty", " ", "list"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"promises", "=", RowBox[{"Lookup", "[", RowBox[{"groups", ",", "False", ",", RowBox[{"{", "}"}]}], "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"promises", " ", "or", " ", "empty", " ", "list"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"actions", ",", "promises"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", " ", "for", " ", "extracting", " ", "guards", " ", RowBox[{"(", RowBox[{"if", " ", "present"}], ")"}], " ", "and", " ", "actions", " ", RowBox[{"(", RowBox[{"and", " ", "promises"}], ")"}], " ", "from", " ", "events"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"guardsAndActions", "[", "e_event", "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"pruned", "=", RowBox[{"DeleteCases", "[", RowBox[{"e", ",", "\[IndentingNewLine]", RowBox[{"_convergent", "|", "convergent", "|", RowBox[{"Not", "[", "_convergent", "]"}], "|", RowBox[{"Not", "[", "convergent", "]"}], "|", "\[IndentingNewLine]", "_anticipated", "|", "anticipated"}], ",", "\[IndentingNewLine]", "1"}], "]"}]}], ",", "\[IndentingNewLine]", "guards", ",", "\[IndentingNewLine]", "actions", ",", "\[IndentingNewLine]", "promises"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Head", "[", RowBox[{"pruned", "[", RowBox[{"[", "2", "]"}], "]"}], "]"}], "===", "when"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "the", " ", "event", " ", "has", " ", "guards", " ", "and", " ", "actions"}], ",", " ", RowBox[{"in", " ", RowBox[{"when", "[", RowBox[{"guards", ",", "actions"}], "]"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"guards", "=", RowBox[{"ensureList", "[", RowBox[{"pruned", "[", RowBox[{"[", RowBox[{"2", ",", "1"}], "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"actions", ",", "promises"}], "}"}], "=", RowBox[{"splitActionsPromises", "[", RowBox[{"ensureList", "[", RowBox[{"pruned", "[", RowBox[{"[", RowBox[{"2", ",", "2"}], "]"}], "]"}], "]"}], "]"}]}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"there", " ", "is", " ", "no", " ", "guard"}], ",", " ", RowBox[{"only", " ", "actions"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"guards", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"actions", ",", "promises"}], "}"}], "=", RowBox[{"splitActionsPromises", "[", RowBox[{"ensureList", "[", RowBox[{"pruned", "[", RowBox[{"[", "2", "]"}], "]"}], "]"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"guards", ",", "actions", ",", "promises"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{"collects", " ", "all", " ", "guards", " ", RowBox[{"(", RowBox[{ "ORed", " ", "at", " ", "first", " ", "level", " ", "and", " ", "ANDed", " ", "at", " ", "second"}], ")"}], " ", "from", " ", "the", " ", "list", " ", "of", " ", "events"}], ",", " ", RowBox[{ "used", " ", "for", " ", "deadlock", " ", "freedom", " ", "check"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"allGuards", "[", "events_List", "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"events", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"Or", "@@", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ev", ",", "\[IndentingNewLine]", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "guards", ",", "\[IndentingNewLine]", "dummyActions", ",", "\[IndentingNewLine]", "dummyPromises"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"guards", ",", "dummyActions", ",", "dummyPromises"}], "}"}], "=", RowBox[{"guardsAndActions", "[", "ev", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"And", "@@", "guards"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "events"}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "True"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"convergent", " ", "/", " ", "anticipated"}], " ", "/", " ", "not"}], " ", "convergent", " ", RowBox[{"events", ":", "\[IndentingNewLine]", RowBox[{"-", " ", "convergent"}], ":", " ", RowBox[{ "the", " ", "variant", " ", "is", " ", "checked", " ", "to", " ", "be", " ", "limited", " ", "and", " ", "lowering", " ", "when", " ", "action", " ", "takes", " ", "place", " ", RowBox[{"(", RowBox[{ RowBox[{"if", " ", "this", " ", "is", " ", "selected"}], ",", " ", RowBox[{ "the", " ", "variant", " ", "is", " ", "not", " ", "checked", " ", "for", " ", "anticipation"}]}], ")"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{"-", " ", RowBox[{"anticipated", ":", " ", RowBox[{ "the", " ", "variant", " ", "is", " ", "checked", " ", "to", " ", "be", " ", "limited", " ", "and", " ", "not", " ", "growing", " ", "when", " ", "action", " ", "takes", " ", "place", " ", RowBox[{"(", RowBox[{ RowBox[{"if", " ", "this", " ", "is", " ", "selected"}], ",", " ", RowBox[{ "the", " ", "variant", " ", "is", " ", "not", " ", "checked", " ", "for", " ", "convergence"}]}], ")"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"-", " ", "not"}], " ", RowBox[{"convergent", ":", " ", RowBox[{ "the", " ", "variant", " ", "is", " ", "not", " ", "checked", " ", "at", " ", "all", " ", "for", " ", "this", " ", "event"}]}]}]}], ",", "\[IndentingNewLine]", RowBox[{ "this", " ", "setting", " ", "overrides", " ", "all", " ", "other", " ", "flags", " ", "and", " ", "implicit", " ", "defaults"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{ "helper", " ", "for", " ", "detecting", " ", "convergence", " ", "and", " ", "non"}], "-", RowBox[{ "convergence", " ", "option", " ", "of", " ", "the", " ", "event"}]}], ";", "\[IndentingNewLine]", RowBox[{ "the", " ", "default", " ", "flag", " ", "is", " ", "True", " ", "for", " ", "new", " ", "events", " ", "in", " ", "refining", " ", "models"}]}], ",", " ", RowBox[{"otherwise", " ", "False"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"isConvergent", "[", RowBox[{"e_event", ",", "default_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{"default", ",", "\[IndentingNewLine]", RowBox[{"FreeQ", "[", RowBox[{"e", ",", RowBox[{"_anticipated", "|", "anticipated", "|", RowBox[{"Not", "[", "_convergent", "]"}], "|", RowBox[{"Not", "[", "convergent", "]"}]}], ",", "1"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"MemberQ", "[", RowBox[{"e", ",", RowBox[{"_convergent", "|", "convergent"}], ",", "1"}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ "helper", " ", "for", " ", "detecting", " ", "whether", " ", "event", " ", "is", " ", "anticipated"}], ";", "\[IndentingNewLine]", RowBox[{ "convergence", " ", "flags", " ", "are", " ", "stronger", " ", "than", " ", "anticipated", " ", "flag"}]}], ",", " ", RowBox[{ "so", " ", "if", " ", "there", " ", "is", " ", "any", " ", "explicit", " ", "setting", " ", "related", " ", "to", " ", "convergence"}], ",", " ", RowBox[{ "the", " ", "anticipation", " ", "flag", " ", "is", " ", "not", " ", "taken", " ", "into", " ", "account"}], ",", "\[IndentingNewLine]", RowBox[{ "and", " ", "the", " ", "hypothetical", " ", "\"\\"", " ", "setting", " ", "is", " ", "covered", " ", "by", " ", RowBox[{"Not", "[", "convergent", "]"}], " ", "anyway"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"isAnticipated", "[", "e_event", "]"}], ":=", RowBox[{ RowBox[{"MemberQ", "[", RowBox[{"e", ",", RowBox[{"_anticipated", "|", "anticipated"}], ",", "1"}], "]"}], "&&", "\[IndentingNewLine]", RowBox[{"FreeQ", "[", RowBox[{"e", ",", RowBox[{"_convergent", "|", "convergent", "|", RowBox[{"Not", "[", "_convergent", "]"}], "|", RowBox[{"Not", "[", "convergent", "]"}]}], ",", "1"}], "]"}]}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{ "leaf", " ", "events", " ", "are", " ", "those", " ", "events", " ", "that", " ", "can", " ", "be", " ", "further", " ", "refined", " ", RowBox[{"(", RowBox[{ RowBox[{"that", " ", "is"}], ",", " ", RowBox[{ "they", " ", "were", " ", "not", " ", "yet", " ", "hidden", " ", "by", " ", "their", " ", "own", " ", "refinements"}]}], ")"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"leafEvents", "[", "m_model", "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "base", ",", "\[IndentingNewLine]", "baseLeafs", ",", "\[IndentingNewLine]", "theseEvents", ",", " ", RowBox[{"(*", " ", RowBox[{ "events", " ", "from", " ", "this", " ", "model", " ", "only", " ", RowBox[{"(", RowBox[{"no", " ", "base"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", "thisName", ",", "baseName", ",", "\[IndentingNewLine]", "explicitlyRefinedNames", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "names", " ", "mentioned", " ", "explicitly", " ", "like", " ", "in", " ", "\"\\""}], "\[Rule]", "\"\\""}], " ", "*)"}], "\[IndentingNewLine]", "missedNames", ",", "\[IndentingNewLine]", "baseNamesThatAreRefined", ",", " ", RowBox[{"(*", " ", RowBox[{ "names", " ", "that", " ", "are", " ", "to", " ", "be", " ", "hidden", " ", "by", " ", "these", " ", "events"}], " ", "*)"}], "\[IndentingNewLine]", "stillVisibleBaseEvents"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"theseEvents", "=", RowBox[{"Cases", "[", RowBox[{"m", ",", "_event"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"base", "=", RowBox[{"Cases", "[", RowBox[{"m", ",", RowBox[{"b_refines", "\[RuleDelayed]", RowBox[{"b", "[", RowBox[{"[", "1", "]"}], "]"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"base", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"there", " ", "is", " ", "a", " ", "base", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"base", "=", RowBox[{"First", "[", "base", "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"Cases", " ", "returns", " ", "a", " ", "list"}], ",", " ", RowBox[{ RowBox[{"even", " ", "if", " ", "single"}], "-", "element"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"baseLeafs", "=", RowBox[{"leafEvents", "[", "base", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"explicitlyRefinedNames", "=", RowBox[{"Flatten", "@", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ev", ",", " ", RowBox[{"(*", " ", RowBox[{"ev", " ", "is", " ", RowBox[{"event", "[", "...", "]"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Head", "[", RowBox[{"ev", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}], "===", "Rule"}], ",", "\[IndentingNewLine]", RowBox[{"ensureList", "[", RowBox[{"ev", "[", RowBox[{"[", RowBox[{"1", ",", "2"}], "]"}], "]"}], "]"}], ",", "\[IndentingNewLine]", "Nothing"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "theseEvents"}], "\[IndentingNewLine]", "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"missedNames", "=", RowBox[{"Complement", "[", RowBox[{"explicitlyRefinedNames", ",", RowBox[{"properName", "/@", RowBox[{"baseLeafs", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"missedNames", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"StringJoin", "@", RowBox[{"Riffle", "[", RowBox[{"missedNames", ",", "\"\<, \>\""}], "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"baseNamesThatAreRefined", "=", RowBox[{"Flatten", "@", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ev", ",", " ", RowBox[{"(*", " ", RowBox[{"ev", " ", "is", " ", RowBox[{"event", "[", "...", "]"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"thisName", ",", "baseName"}], "}"}], "=", RowBox[{"separateNames", "[", RowBox[{"ev", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", "baseName"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "theseEvents"}], "\[IndentingNewLine]", "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"stillVisibleBaseEvents", "=", RowBox[{"Select", "[", RowBox[{"baseLeafs", ",", RowBox[{ RowBox[{"FreeQ", "[", RowBox[{"baseNamesThatAreRefined", ",", RowBox[{"properName", "[", RowBox[{"#", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], "]"}], "&"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Join", "[", RowBox[{"theseEvents", ",", "stillVisibleBaseEvents"}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "m", " ", "is", " ", "the", " ", "most", " ", "base", " ", "model"}], ",", " ", RowBox[{ "all", " ", "its", " ", "events", " ", "are", " ", "leafs"}]}], " ", "*)"}], "\[IndentingNewLine]", "theseEvents"}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{ "turns", " ", "the", " ", "argument", " ", "into", " ", "a", " ", "Rule", " ", RowBox[{"(", RowBox[{ "provided", " ", "it", " ", "has", " ", "proper", " ", "structure"}], ")"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"toRule", "[", "t_", "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Length", "[", "t", "]"}], "\[Equal]", "2"}], "&&", RowBox[{"StringQ", "[", RowBox[{"t", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"Rule", "@@", "t"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "t"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{ "collects", " ", "guards", " ", "and", " ", "actions", " ", "on", " ", "a", " ", "path", " ", "that", " ", "leads", " ", "from", " ", "the", " ", "given", " ", "named", " ", "event", " ", "in", " ", "the", " ", "model", " ", "down", " ", "via", " ", "the", " ", "refinement", " ", "relation"}], ",", " ", RowBox[{ RowBox[{ "returning", " ", "potentially", " ", "multiple", " ", "paths", " ", "if", " ", "there", " ", "are", " ", "merging", " ", "events", " ", "on", " ", "the", " ", "way"}], ";", "\[IndentingNewLine]", RowBox[{ "input", " ", "is", " ", "a", " ", "currently", " ", "collected", " ", "single", " ", "path", " ", RowBox[{"{", RowBox[{"names", ",", "guards", ",", "actions", ",", "promises"}], "}"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"returns", " ", "list", " ", "of", " ", "paths"}], ",", " ", RowBox[{ "each", " ", "path", " ", "is", " ", "a", " ", "quadruple", " ", RowBox[{"{", RowBox[{"names", ",", "guards", ",", "actions", ",", "promises"}], "}"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"collectGuardPaths", "[", RowBox[{ "currentPath_", ",", "\[IndentingNewLine]", "m_model", ",", "eventName_String", ",", "appendGuard_"}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"base", ",", "\[IndentingNewLine]", "thisEvent", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"event", " ", "from", " ", "m"}], ",", " ", RowBox[{"named", " ", "by", " ", "eventName"}]}], " ", "*)"}], "\[IndentingNewLine]", "thisGuards", ",", "thisActions", ",", "thisPromises", ",", "\[IndentingNewLine]", "name", ",", "refinedNames", ",", "\[IndentingNewLine]", "furtherPath", ",", " ", RowBox[{"(*", " ", RowBox[{ "currentPath", " ", "extended", " ", "by", " ", "further", " ", "elements"}], " ", "*)"}], "\[IndentingNewLine]", "mergedResults"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"thisEvent", "=", RowBox[{"Select", "[", RowBox[{ RowBox[{"leafEvents", "[", "m", "]"}], ",", RowBox[{ RowBox[{"eventName", "==", RowBox[{"properName", "[", RowBox[{"#", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], "&"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"thisEvent", "\[Equal]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"event", " ", "not", " ", "found"}], ",", " ", RowBox[{ "return", " ", "the", " ", "input", " ", "values", " ", "without", " ", "change"}], ",", " ", RowBox[{"on", " ", "one", " ", "path"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", "currentPath", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "collect", " ", "actions", " ", "and", " ", "guards", " ", "from", " ", "this", " ", "event", " ", "and", " ", "its", " ", "bases", " ", RowBox[{"(", RowBox[{"if", " ", "any"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"thisEvent", "=", RowBox[{"First", "[", "thisEvent", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"thisGuards", ",", "thisActions", ",", "thisPromises"}], "}"}], "=", RowBox[{"guardsAndActions", "[", "thisEvent", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "append", " ", "these", " ", "values", " ", "to", " ", "the", " ", "current", " ", "path"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"appendGuard", ",", "\[IndentingNewLine]", RowBox[{"furtherPath", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"DeleteDuplicates", "@", RowBox[{"Append", "[", RowBox[{ RowBox[{"currentPath", "[", RowBox[{"[", "1", "]"}], "]"}], ",", "eventName"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"DeleteDuplicates", "@", RowBox[{"Join", "[", RowBox[{ RowBox[{"currentPath", "[", RowBox[{"[", "2", "]"}], "]"}], ",", "thisGuards"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"DeleteDuplicates", "@", RowBox[{"Join", "[", RowBox[{ RowBox[{"currentPath", "[", RowBox[{"[", "3", "]"}], "]"}], ",", "thisActions"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"DeleteDuplicates", "@", RowBox[{"Join", "[", RowBox[{ RowBox[{"currentPath", "[", RowBox[{"[", "4", "]"}], "]"}], ",", "thisPromises"}], "]"}]}]}], "\[IndentingNewLine]", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"furtherPath", "=", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"DeleteDuplicates", "@", RowBox[{"Append", "[", RowBox[{ RowBox[{"currentPath", "[", RowBox[{"[", "1", "]"}], "]"}], ",", "eventName"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"currentPath", "[", RowBox[{"[", "2", "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"DeleteDuplicates", "@", RowBox[{"Join", "[", RowBox[{ RowBox[{"currentPath", "[", RowBox[{"[", "3", "]"}], "]"}], ",", "thisActions"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"DeleteDuplicates", "@", RowBox[{"Join", "[", RowBox[{ RowBox[{"currentPath", "[", RowBox[{"[", "4", "]"}], "]"}], ",", "thisPromises"}], "]"}]}]}], "\[IndentingNewLine]", "}"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"base", "=", RowBox[{"Cases", "[", RowBox[{"m", ",", RowBox[{"b_refines", "\[RuleDelayed]", RowBox[{"b", "[", RowBox[{"[", "1", "]"}], "]"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"base", "=!=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"base", "=", RowBox[{"First", "[", "base", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "this", " ", "is", " ", "a", " ", "refining", " ", "model"}], ",", " ", "descend"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"name", ",", "refinedNames"}], "}"}], "=", RowBox[{"separateNames", "[", RowBox[{"thisEvent", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "refinedNames", "]"}], "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "this", " ", "event", " ", "refines", " ", "only", " ", "one", " ", RowBox[{"(", RowBox[{"or", " ", "none"}], ")"}], " ", "event", " ", "from", " ", "base", " ", "model"}], ",", " ", RowBox[{ RowBox[{ "the", " ", "result", " ", "is", " ", "an", " ", "extension", " ", "of", " ", "a", " ", "single", " ", "path"}], ";", "\[IndentingNewLine]", RowBox[{ "do", " ", "not", " ", "collect", " ", "the", " ", "guard", " ", "from", " ", "this", " ", "single", " ", "base"}]}], ",", " ", RowBox[{ "as", " ", "it", " ", "is", " ", "a", " ", "superset", " ", "of", " ", "the", " ", "current", " ", "guard", " ", "anyway"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"mergedResults", "=", RowBox[{"collectGuardPaths", "[", RowBox[{"furtherPath", ",", "base", ",", RowBox[{"First", "[", "refinedNames", "]"}], ",", "False"}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "this", " ", "event", " ", "is", " ", "a", " ", "merging", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "each", " ", "merged", " ", "base", " ", "event", " ", "creates", " ", "a", " ", "separate", " ", "path", " ", "in", " ", "the", " ", "refinement", " ", "graph"}], ",", "\[IndentingNewLine]", RowBox[{ "so", " ", "the", " ", "existing", " ", "furtherPath", " ", "list", " ", "needs", " ", "to", " ", "be", " ", "cloned"}], ",", " ", RowBox[{ "once", " ", "for", " ", "each", " ", "refining", " ", "path"}], ",", " ", RowBox[{ RowBox[{ "with", " ", "guard", " ", "specific", " ", "for", " ", "each", " ", "merged", " ", "event"}], ";", "\[IndentingNewLine]", RowBox[{ "collect", " ", "guards", " ", "from", " ", "each", " ", RowBox[{"(", "direct", ")"}], " ", "merged", " ", "event"}]}], ",", " ", RowBox[{ "because", " ", "they", " ", "are", " ", "likely", " ", "subsets", " ", "of", " ", "the", " ", "current", " ", "guard"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"mergedResults", "=", RowBox[{"Flatten", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"rn", ",", " ", RowBox[{"(*", " ", RowBox[{ "rn", " ", "is", " ", "a", " ", "name", " ", "of", " ", "each", " ", "merged", " ", "base", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"collectGuardPaths", "[", RowBox[{ "furtherPath", ",", "base", ",", "rn", ",", "True"}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "refinedNames"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "1"}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "this", " ", "model", " ", "has", " ", "no", " ", "base"}], ",", " ", RowBox[{ RowBox[{"return", " ", "single"}], "-", RowBox[{"path", " ", "result"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"mergedResults", "=", RowBox[{"{", "furtherPath", "}"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", "mergedResults"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "helper", " ", "for", " ", "managing", " ", "parallel", " ", "and", " ", "piecewise", " ", "executions"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"doValidate", "[", RowBox[{ "knowns_", ",", "question_", ",", "theoremsOpt_", ",", "methodOpt_", ",", "parallelOpt_", ",", "verboseOpt_"}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"methodOpt", "===", "Piecewise"}], ",", "\[IndentingNewLine]", RowBox[{"validatePiecewise", "[", RowBox[{"knowns", ",", "question", ",", RowBox[{"theorems", "\[Rule]", "theoremsOpt"}], ",", "\[IndentingNewLine]", RowBox[{"parallel", "\[Rule]", "parallelOpt"}], ",", RowBox[{"verbose", "\[Rule]", "verboseOpt"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"validate", "[", RowBox[{"knowns", ",", "question", ",", RowBox[{"theorems", "\[Rule]", "theoremsOpt"}], ",", RowBox[{"verbose", "\[Rule]", "verboseOpt"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"helper", ",", " ", RowBox[{ "decide", " ", "whether", " ", "to", " ", "print", " ", "the", " ", "result"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"showResult", "[", RowBox[{"res_", ",", "verboseOpt_"}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"res", "===", "True"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "show", " ", "success", " ", "only", " ", "above", " ", "verbose"}], "\[Rule]", "Less"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"verboseOpt", "=!=", "Total"}], "&&", RowBox[{"verboseOpt", "=!=", "Less"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"show", " ", "failures", " ", "above", " ", "verbose"}], "\[Rule]", "Total"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"verboseOpt", "=!=", "Total"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"validates", " ", "the", " ", "complete", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"validateModel", "[", RowBox[{"m_model", ",", RowBox[{"OptionsPattern", "[", RowBox[{"{", RowBox[{ RowBox[{"onlyPhase", "\[Rule]", "\"\<*\>\""}], ",", RowBox[{"onlyEvents", "\[Rule]", "\"\<*\>\""}], ",", RowBox[{"onlyInvariants", "\[Rule]", "\"\<*\>\""}], ",", RowBox[{"method", "\[Rule]", "Full"}], ",", RowBox[{"parallel", "\[Rule]", "False"}], ",", RowBox[{"showProofs", "\[Rule]", "False"}], ",", RowBox[{"verbose", "\[Rule]", "Automatic"}]}], "}"}], "]"}]}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"base", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"base", " ", "model"}], ",", " ", RowBox[{"if", " ", "m", " ", "is", " ", "a", " ", "refinement"}]}], " ", "*)"}], "\[IndentingNewLine]", "theoremsOpt", ",", "\[IndentingNewLine]", "baseTheoremsOpt", ",", "\[IndentingNewLine]", "axioms", ",", "\[IndentingNewLine]", RowBox[{"baseAxioms", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "inits", ",", "\[IndentingNewLine]", RowBox[{"baseInits", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "invariants", ",", "\[IndentingNewLine]", RowBox[{"baseInvariants", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "variants", ",", "\[IndentingNewLine]", "variantExprs", ",", "\[IndentingNewLine]", "axiomExprs", ",", " ", RowBox[{"(*", " ", RowBox[{"expressions", " ", "from", " ", "all", " ", "axioms"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"baseAxiomExprs", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "invariantExprs", ",", " ", RowBox[{"(*", " ", RowBox[{"expressions", " ", "from", " ", "all", " ", "invariants"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"baseInvariantExprs", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "thisModelEvents", ",", " ", RowBox[{"(*", " ", RowBox[{"events", " ", "from", " ", "this", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", "events", ",", " ", RowBox[{"(*", " ", RowBox[{"all", " ", "leaf", " ", "events"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"baseEvents", "=", RowBox[{"{", "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "leaf", " ", "events", " ", "of", " ", "the", " ", "base", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"onlyPhaseOpt", "=", RowBox[{"OptionValue", "[", "onlyPhase", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"onlyEventsOpt", "=", RowBox[{"OptionValue", "[", "onlyEvents", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"onlyInvariantsOpt", "=", RowBox[{"OptionValue", "[", "onlyInvariants", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"methodOpt", "=", RowBox[{"OptionValue", "[", "method", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"parallelOpt", "=", RowBox[{"OptionValue", "[", "parallel", "]"}]}], ",", "\[IndentingNewLine]", "parallelWrapper", ",", "\[IndentingNewLine]", RowBox[{"showProofsOpt", "=", RowBox[{"OptionValue", "[", "showProofs", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"verboseOpt", "=", RowBox[{"OptionValue", "[", "verbose", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", "partialResults", ",", "\[IndentingNewLine]", RowBox[{"results", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "counts"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"parallelOpt", "===", "True"}], "&&", RowBox[{"methodOpt", "=!=", "Piecewise"}]}], ",", "\[IndentingNewLine]", RowBox[{"parallelWrapper", "=", "Parallelize"}], ",", " ", RowBox[{"(*", " ", RowBox[{"parallelize", " ", "some", " ", "Scan", " ", "calls"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"parallelWrapper", "=", "Identity"}]}], " ", RowBox[{"(*", " ", RowBox[{"do", " ", "not", " ", "parallelize"}], " ", "*)"}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"base", "=", RowBox[{"Cases", "[", RowBox[{"m", ",", RowBox[{"b_refines", "\[RuleDelayed]", RowBox[{"b", "[", RowBox[{"[", "1", "]"}], "]"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"theoremsOpt", "=", RowBox[{"Cases", "[", RowBox[{"m", ",", RowBox[{"th_theorem", "\[RuleDelayed]", RowBox[{"toRule", "[", "th", "]"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"axioms", "=", RowBox[{"Cases", "[", RowBox[{"m", ",", RowBox[{"ax_axiom", "\[RuleDelayed]", RowBox[{"toRule", "[", "ax", "]"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"inits", "=", RowBox[{"Cases", "[", RowBox[{"m", ",", RowBox[{"i_init", "\[RuleDelayed]", RowBox[{"toRule", "[", "i", "]"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"invariants", "=", RowBox[{"Cases", "[", RowBox[{"m", ",", RowBox[{"inv_invariant", "\[RuleDelayed]", RowBox[{"toRule", "[", "inv", "]"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"variants", "=", RowBox[{"Cases", "[", RowBox[{"m", ",", RowBox[{"v_variant", "\[RuleDelayed]", RowBox[{"toRule", "[", "v", "]"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"thisModelEvents", "=", RowBox[{"Cases", "[", RowBox[{"m", ",", "e_event"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"events", "=", RowBox[{"leafEvents", "[", "m", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"axiomExprs", "=", RowBox[{"Flatten", "[", RowBox[{"axioms", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"invariantExprs", "=", RowBox[{"Flatten", "[", RowBox[{"invariants", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"variantExprs", "=", RowBox[{"Flatten", "[", RowBox[{"variants", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"base", "=!=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "this", " ", "model", " ", "is", " ", "a", " ", "refinement", " ", "of", " ", "some", " ", "base", " ", "model"}], ",", " ", RowBox[{ "check", " ", "if", " ", "the", " ", "refinement", " ", "is", " ", "correct"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "base", "]"}], "=!=", "1"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ "Print", "[", "\"\\"", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"base", "=", RowBox[{"First", "[", "base", "]"}]}], ";", " ", RowBox[{"(*", " ", "simplify", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Head", "[", "base", "]"}], "=!=", "model"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ "Print", "[", "\"\\"", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "=!=", "Total"}], ",", "\[IndentingNewLine]", RowBox[{ "Print", "[", "\"\\"", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "collect", " ", "theorems", " ", "from", " ", "all", " ", "bases", " ", "and", " ", "inject", " ", "them", " ", "into", " ", "this", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"baseTheoremsOpt", "=", RowBox[{"Cases", "[", RowBox[{"base", ",", RowBox[{"th_theorem", "\[RuleDelayed]", RowBox[{"toRule", "[", "th", "]"}]}], ",", "Infinity"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"theoremsOpt", "=", RowBox[{"Join", "[", RowBox[{"baseTheoremsOpt", ",", "theoremsOpt"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"collect", " ", "axioms"}], ",", " ", RowBox[{ "inits", " ", "and", " ", "invariants", " ", "from", " ", "all", " ", "bases", " ", RowBox[{"(", "deep", ")"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"baseAxioms", "=", RowBox[{"Cases", "[", RowBox[{"base", ",", RowBox[{"ax_axiom", "\[RuleDelayed]", RowBox[{"Rule", "@@", "ax"}]}], ",", "Infinity"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"baseInits", "=", RowBox[{"Cases", "[", RowBox[{"base", ",", RowBox[{"i_init", "\[RuleDelayed]", RowBox[{"Rule", "@@", "i"}]}], ",", "Infinity"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"baseInvariants", "=", RowBox[{"Cases", "[", RowBox[{"base", ",", RowBox[{"inv_invariant", "\[RuleDelayed]", RowBox[{"Rule", "@@", "inv"}]}], ",", "Infinity"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"baseEvents", "=", RowBox[{"leafEvents", "[", "base", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"baseAxiomExprs", "=", RowBox[{"Flatten", "[", RowBox[{"baseAxioms", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"baseInvariantExprs", "=", RowBox[{"Flatten", "[", RowBox[{"baseInvariants", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "=!=", "Total"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", "\"\\"", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"base", "=", "Null"}]}]}], " ", RowBox[{"(*", " ", "simplify", " ", "*)"}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "check", " ", "if", " ", "all", " ", "names", " ", "are", " ", "unique", " ", RowBox[{"(", RowBox[{ "except", " ", "event", " ", "names", " ", "in", " ", "base", " ", "model"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"allNames", "=", RowBox[{"Join", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"baseAxioms", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"baseInits", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"baseInvariants", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"theoremsOpt", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"axioms", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"inits", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariants", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"variants", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"properName", "/@", RowBox[{"events", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"n", ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Not", "[", RowBox[{"StringQ", "[", "n", "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "n"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "allNames"}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Not", "[", RowBox[{"DuplicateFreeQ", "[", "allNames", "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"StringJoin", "@", RowBox[{"Riffle", "[", RowBox[{ RowBox[{"Commonest", "[", "allNames", "]"}], ",", "\"\<, \>\""}], "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Abort", "[", "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "validate", " ", "all", " ", "axioms", " ", "and", " ", "inits", " ", "against", " ", "invariants"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "=!=", "Total"}], ",", "\[IndentingNewLine]", RowBox[{ "Print", "[", "\"\\"", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "baseInitActions", ",", "baseInitPromises", ",", "\[IndentingNewLine]", "initActions", ",", "initPromises", ",", "\[IndentingNewLine]", "combinedInitRules"}], " ", RowBox[{"(*", " ", RowBox[{"only", " ", "actions"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"baseInitActions", ",", "baseInitPromises"}], "}"}], "=", RowBox[{"splitActionsPromises", "[", RowBox[{"Flatten", "[", RowBox[{"baseInits", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"initActions", ",", "initPromises"}], "}"}], "=", RowBox[{"splitActionsPromises", "[", RowBox[{"Flatten", "[", RowBox[{"inits", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"combinedInitRules", "=", RowBox[{"Join", "[", RowBox[{"baseInitActions", ",", "initActions"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "initKnowns", ",", "\[IndentingNewLine]", "baseInitQuestion", ",", "\[IndentingNewLine]", "res1", ",", "res2", ",", "res"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"initKnowns", "=", RowBox[{"Join", "[", "\[IndentingNewLine]", RowBox[{ "baseAxiomExprs", ",", "axiomExprs", ",", "\[IndentingNewLine]", RowBox[{"baseInitActions", "/.", RowBox[{"Rule", "\[Rule]", "Equal"}]}], ",", "\[IndentingNewLine]", "baseInitPromises", ",", "\[IndentingNewLine]", RowBox[{"initActions", "/.", RowBox[{"Rule", "\[Rule]", "Equal"}]}], ",", "\[IndentingNewLine]", "initPromises"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"baseInitQuestion", "=", RowBox[{"Join", "[", RowBox[{ RowBox[{"baseInitActions", "/.", RowBox[{"Rule", "\[Rule]", "Equal"}]}], ",", "baseInitPromises"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{"prettyProof", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", "initKnowns", ",", "baseInitQuestion"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res1", "=", RowBox[{"satisfy", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", "initKnowns"}], ",", "\[IndentingNewLine]", RowBox[{"theorems", "->", "theoremsOpt"}], ",", "\[IndentingNewLine]", RowBox[{"verbose", "->", "verboseOpt"}]}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res2", "=", RowBox[{"doValidate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", "initKnowns"}], ",", "\[IndentingNewLine]", RowBox[{"And", "@@", "baseInitQuestion"}], ",", "\[IndentingNewLine]", "theoremsOpt", ",", "\[IndentingNewLine]", "methodOpt", ",", "parallelOpt", ",", "verboseOpt"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"res1", "=!=", "True"}], ",", "res1", ",", "res2"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"res", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< init consistency: \>\"", ",", RowBox[{"prettyResult", "[", "res", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"results", ",", "res"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "check", " ", "each", " ", "concrete", " ", "invariant"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"partialResults", "=", RowBox[{"parallelWrapper", "@", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"inv", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"inv", " ", "is", " ", "name"}], "->", "expression"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"invName", "=", RowBox[{"inv", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"invExpr", "=", RowBox[{"ensureList", "[", RowBox[{"inv", "[", RowBox[{"[", "2", "]"}], "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"invExprModified", "=", RowBox[{ RowBox[{"ensureList", "[", RowBox[{"inv", "[", RowBox[{"[", "2", "]"}], "]"}], "]"}], "/.", "combinedInitRules"}]}], ",", "\[IndentingNewLine]", "knowns", ",", "\[IndentingNewLine]", "res"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"StringMatchQ", "[", RowBox[{"invName", ",", "onlyInvariantsOpt"}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"knowns", "=", RowBox[{"Join", "[", RowBox[{ "baseAxiomExprs", ",", "axiomExprs", ",", "\[IndentingNewLine]", "baseInitPromises", ",", "initPromises"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{"prettyProof", "[", RowBox[{ RowBox[{"\"\\"", "<>", "invName"}], ",", "\[IndentingNewLine]", "knowns", ",", RowBox[{"Join", "[", RowBox[{"invExpr", ",", RowBox[{"{", "\"\<\\nwith\\n\>\"", "}"}], ",", "combinedInitRules"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"doValidate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", "knowns"}], ",", "\[IndentingNewLine]", RowBox[{"And", "@@", "invExprModified"}], ",", "\[IndentingNewLine]", "theoremsOpt", ",", "\[IndentingNewLine]", "methodOpt", ",", "parallelOpt", ",", "verboseOpt"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"res", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< \>\"", ",", "invName", ",", "\"\<: \>\"", ",", RowBox[{"prettyResult", "[", "res", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", "res"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", "Nothing"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "invariants"}], "\[IndentingNewLine]", "]"}]}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"partialResults", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"results", "=", RowBox[{"Join", "[", RowBox[{"results", ",", "partialResults"}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"Indeterminate", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ "Print", "[", "\"\< No invariants to check.\>\"", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"for", " ", "each", " ", "event"}], ",", " ", RowBox[{ "validate", " ", "strengthening", " ", "of", " ", "its", " ", "guards", " ", "and", " ", "preservation", " ", "of", " ", "invariants", " ", "of", " ", "its", " ", "actions"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}], "||", "\[IndentingNewLine]", RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}], "||", "\[IndentingNewLine]", RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}], "||", "\[IndentingNewLine]", RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}], "||", "\[IndentingNewLine]", RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"ev", ",", " ", RowBox[{"(*", " ", RowBox[{"ev", " ", "is", " ", RowBox[{"event", "[", "...", "]"}], " ", "from", " ", "events", " ", RowBox[{"(", RowBox[{"leafs", " ", "of", " ", "this", " ", "model"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"fullName", "=", RowBox[{"ev", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", "name", ",", "\[IndentingNewLine]", "refinedNames", ",", "\[IndentingNewLine]", "guards", ",", "\[IndentingNewLine]", "actions", ",", "\[IndentingNewLine]", "promises", ",", "\[IndentingNewLine]", RowBox[{"thisModelEventNames", "=", RowBox[{"properName", "/@", RowBox[{"thisModelEvents", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"directlyRefinedEvents", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"baseGuards", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"basePromises", "=", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"refinedEventsDeep", ","}], "*)"}], " ", RowBox[{"(*", " ", RowBox[{ "recursively", " ", "across", " ", "model", " ", "hierarchy"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"baseActionsDeep", "=", RowBox[{"{", "}"}]}], ","}], "*)"}], " ", RowBox[{"(*", " ", RowBox[{ "recursively", " ", "across", " ", "model", " ", "hierarchy"}], " ", "*)"}], "\[IndentingNewLine]", "guardsActionPaths", ",", " ", RowBox[{"(*", " ", RowBox[{ "collected", " ", "guards", " ", "and", " ", "actions", " ", "on", " ", "all", " ", "refinement", " ", "paths"}], " ", "*)"}], "\[IndentingNewLine]", "variantsAreNatural", ",", " ", RowBox[{"(*", " ", RowBox[{ "for", " ", "both", " ", "convergent", " ", "and", " ", "anticipated", " ", "events"}], " ", "*)"}], "\[IndentingNewLine]", "variantsAreMonotonic", ",", " ", RowBox[{"(*", " ", RowBox[{"for", " ", "convergent", " ", "events"}], " ", "*)"}], "\[IndentingNewLine]", "variantsAreNonGrowing", ",", " ", RowBox[{"(*", " ", RowBox[{"for", " ", "anticipated", " ", "events"}], " ", "*)"}], "\[IndentingNewLine]", "knowns", ",", "\[IndentingNewLine]", "res"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"name", ",", "refinedNames"}], "}"}], "=", RowBox[{"separateNames", "[", "fullName", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"StringMatchQ", "[", RowBox[{"name", ",", "onlyEventsOpt"}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "=!=", "Total"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "name"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"guards", ",", "actions", ",", "promises"}], "}"}], "=", RowBox[{"guardsAndActions", "[", "ev", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"knowns", "=", RowBox[{"Join", "[", "\[IndentingNewLine]", RowBox[{ "baseAxiomExprs", ",", "axiomExprs", ",", "\[IndentingNewLine]", "baseInvariantExprs", ",", "invariantExprs", ",", "\[IndentingNewLine]", "guards"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "find", " ", "base", " ", "events", " ", "that", " ", "are", " ", "refined", " ", "by", " ", "ev"}], ",", " ", RowBox[{ "only", " ", "for", " ", "events", " ", "that", " ", "exist", " ", "in", " ", "this", " ", "model"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"MemberQ", "[", RowBox[{"thisModelEventNames", ",", "name"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"directlyRefinedEvents", "=", RowBox[{"Select", "[", RowBox[{"baseEvents", ",", "\[IndentingNewLine]", RowBox[{"Function", "[", RowBox[{"bev", ",", RowBox[{"MemberQ", "[", RowBox[{"refinedNames", ",", RowBox[{"properName", "[", RowBox[{"bev", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"collect", " ", "base", " ", "guards"}], ",", " ", RowBox[{ "only", " ", "for", " ", "directly", " ", "refined", " ", "base", " ", "events"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"directlyRefinedEvents", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"baseGuards", ",", "basePromises"}], "}"}], "=", RowBox[{"Transpose", "@", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"bev", ",", " ", RowBox[{"(*", " ", RowBox[{"bev", " ", "is", " ", RowBox[{"event", "[", "...", "]"}], " ", "from", " ", "refinedEvents"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "bevGuards", ",", "\[IndentingNewLine]", "dummyBevActions", ",", "\[IndentingNewLine]", "bevPromises"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ "bevGuards", ",", "dummyBevActions", ",", "bevPromises"}], "}"}], "=", RowBox[{"guardsAndActions", "[", "bev", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"bevGuards", ",", "bevPromises"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "directlyRefinedEvents"}], "\[IndentingNewLine]", "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "collect", " ", "all", " ", "guards", " ", "and", " ", "actions", " ", "for", " ", "this", " ", "event", " ", "and", " ", "its", " ", "bases"}], ",", " ", RowBox[{ "across", " ", "the", " ", "whole", " ", "hierarchy"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"guardsActionPaths", "=", RowBox[{"collectGuardPaths", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"{", "}"}], ",", RowBox[{"{", "}"}], ",", RowBox[{"{", "}"}], ",", RowBox[{"{", "}"}]}], "}"}], ",", "m", ",", "name", ",", "False"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}], "||", "\[IndentingNewLine]", RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"guards", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"check", " ", "guard", " ", "reachability"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{ "prettyReachabilityProof", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "<>", "name"}], ",", "knowns"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"satisfy", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", "knowns"}], ",", "\[IndentingNewLine]", RowBox[{"theorems", "->", "theoremsOpt"}], ",", "\[IndentingNewLine]", RowBox[{"verbose", "->", "verboseOpt"}]}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"res", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< guard reachable: \>\"", ",", RowBox[{"prettyResult", "[", "res", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"results", ",", "res"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"directlyRefinedEvents", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "=!=", "Total"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "directlyRefinedEvents", "]"}], ">", "1"}], ",", "\[IndentingNewLine]", RowBox[{ "Print", "[", "\"\< This is a merging event.\>\"", "]"}], ",", "\[IndentingNewLine]", RowBox[{ "Print", "[", "\"\< This is a refining event.\>\"", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "check", " ", "guard", " ", "and", " ", "promise", " ", "strengthening"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Flatten", "[", "baseGuards", "]"}], "\[NotEqual]", RowBox[{"{", "}"}]}], "||", RowBox[{"(", RowBox[{ RowBox[{"promises", "\[NotEqual]", RowBox[{"{", "}"}]}], "&&", RowBox[{"basePromises", "\[NotEqual]", RowBox[{"{", "}"}]}]}], ")"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"allKnowns", ",", " ", RowBox[{"(*", " ", RowBox[{ "combined", " ", "these", " ", "guards", " ", "and", " ", "promises"}], " ", "*)"}], "\[IndentingNewLine]", "allQuestions"}], " ", RowBox[{"(*", " ", RowBox[{ "combined", " ", "base", " ", "guards", " ", "and", " ", "base", " ", "promises"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"promises", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "there", " ", "are", " ", "promises", " ", "in", " ", "this", " ", "event"}], ",", " ", RowBox[{ "check", " ", "them", " ", "against", " ", "base", " ", "ones"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"allKnowns", "=", RowBox[{"Join", "[", RowBox[{"knowns", ",", "promises"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"allQuestions", "=", RowBox[{"Join", "@@@", RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{"baseGuards", ",", "basePromises"}], "}"}], "]"}]}]}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"there", " ", "are", " ", "no", " ", "promises"}], ",", " ", RowBox[{ "do", " ", "not", " ", "involve", " ", "base", " ", "promises", " ", "either"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"allKnowns", "=", "knowns"}], ";", "\[IndentingNewLine]", RowBox[{"allQuestions", "=", "baseGuards"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{"prettyProof", "[", RowBox[{ RowBox[{"\"\\ \"", "<>", "name"}], ",", "\[IndentingNewLine]", "allKnowns", ",", RowBox[{"Riffle", "[", RowBox[{ RowBox[{"And", "@@@", "allQuestions"}], ",", "\"\\""}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"doValidate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", "allKnowns"}], ",", "\[IndentingNewLine]", RowBox[{"Or", "@@", RowBox[{"(", RowBox[{"And", "@@@", "allQuestions"}], ")"}]}], ",", "\[IndentingNewLine]", "theoremsOpt", ",", "\[IndentingNewLine]", "methodOpt", ",", "parallelOpt", ",", "verboseOpt"}], "\[IndentingNewLine]", "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"res", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< guard and promise strengthening: \>\"", ",", RowBox[{"prettyResult", "[", "res", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"results", ",", "res"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], " ", "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"check", " ", "invariant", " ", "compatibility"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}], "||", "\[IndentingNewLine]", RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"partialResults", "=", RowBox[{"parallelWrapper", "@", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"inv", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"inv", " ", "is", " ", "name"}], "->", "expression"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"invName", "=", RowBox[{"inv", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"invExpr", "=", RowBox[{"ensureList", "[", RowBox[{"inv", "[", RowBox[{"[", "2", "]"}], "]"}], "]"}]}], ",", "\[IndentingNewLine]", "invExprModified", ",", "\[IndentingNewLine]", "invRes"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"StringMatchQ", "[", RowBox[{"invName", ",", "onlyInvariantsOpt"}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "there", " ", "are", " ", "possibly", " ", "multiple", " ", "refinement", " ", "paths"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"invRes", "=", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"path", ",", " ", RowBox[{"(*", " ", RowBox[{"path", " ", "is", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"names", "..."}], "}"}], ",", RowBox[{"{", RowBox[{"guards", "..."}], "}"}], ",", RowBox[{"{", RowBox[{"actions", "..."}], "}"}]}], "}"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"eventNames", "=", RowBox[{"path", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"inheritedGuards", "=", RowBox[{"path", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"combinedActions", "=", RowBox[{"DeleteDuplicatesBy", "[", RowBox[{ RowBox[{"path", "[", RowBox[{"[", "3", "]"}], "]"}], ",", "First"}], "]"}]}], ",", "\[IndentingNewLine]", "pathKnowns", ",", "\[IndentingNewLine]", "pathRes"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"pathKnowns", "=", RowBox[{"Join", "[", RowBox[{ "knowns", ",", "inheritedGuards", ",", "promises"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ "for", " ", "combined", " ", "actions", " ", "only", " ", "the", " ", "first", " ", RowBox[{"(", RowBox[{ "sooner", " ", "on", " ", "the", " ", "refinement", " ", "path"}], ")"}], " ", "modification", " ", "of", " ", "the", " ", "given", " ", "variable", " ", "is", " ", "taken", " ", "into", " ", "account", " ", "to", " ", "avoid", " ", "replacement", " ", "problems", " ", "later", " ", "on"}], ";", "\[IndentingNewLine]", RowBox[{ "even", " ", "if", " ", "there", " ", "are", " ", "multiple", " ", "modifications", " ", "on", " ", "a", " ", "given", " ", "path"}]}], ",", " ", RowBox[{ "they", " ", "are", " ", "verified", " ", "by", " ", "state", " ", "superposition", " ", "check", " ", "anyway"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"combinedActions", "=", RowBox[{"DeleteDuplicatesBy", "[", RowBox[{ RowBox[{"path", "[", RowBox[{"[", "3", "]"}], "]"}], ",", "First"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invExprModified", "=", RowBox[{"invExpr", "/.", "combinedActions"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{"prettyProof", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "guardsActionPaths", "]"}], "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "title", " ", "for", " ", "single", " ", "refinement", " ", "path"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"\"\\"", "<>", "name", "<>", "\"\< and \>\"", "<>", "invName"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "title", " ", "for", " ", "multiple", " ", "refinement", " ", "paths"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"\"\\"", "<>", RowBox[{"prettyPath", "[", "eventNames", "]"}], "<>", "\"\< and \>\"", "<>", "invName"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "pathKnowns", ",", RowBox[{"Join", "[", RowBox[{"invExpr", ",", RowBox[{"{", "\"\<\\nwith\\n\>\"", "}"}], ",", "combinedActions"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"pathRes", "=", RowBox[{"doValidate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", "pathKnowns"}], ",", "\[IndentingNewLine]", RowBox[{"And", "@@", "invExprModified"}], ",", "\[IndentingNewLine]", "theoremsOpt", ",", "\[IndentingNewLine]", "methodOpt", ",", "parallelOpt", ",", "verboseOpt"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"pathRes", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "guardsActionPaths", "]"}], "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "report", " ", "for", " ", "single", " ", "refinement", " ", "path"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< \>\"", ",", "invName", ",", "\"\<: \>\"", ",", RowBox[{"prettyResult", "[", "pathRes", "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "report", " ", "for", " ", "multiple", " ", "refinement", " ", "paths"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< \>\"", ",", "invName", ",", "\"\< via \>\"", ",", RowBox[{"prettyPath", "[", "eventNames", "]"}], ",", "\"\<: \>\"", ",", RowBox[{"prettyResult", "[", "pathRes", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", "pathRes"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "guardsActionPaths"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "invRes", " ", "can", " ", "be", " ", "a", " ", "single", " ", "truth", " ", "value", " ", "or", " ", "a", " ", "list", " ", "here"}], " ", "*)"}], "\[IndentingNewLine]", "invRes"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", "Nothing"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"refined", " ", "events"}], ",", " ", RowBox[{ "with", " ", "their", " ", "combined", " ", "actions"}], ",", " ", RowBox[{ "have", " ", "to", " ", "be", " ", "checked", " ", "against", " ", "both", " ", "base", " ", "and", " ", "concrete", " ", "invariants"}], ",", "\[IndentingNewLine]", RowBox[{ "otherwise", " ", "it", " ", "would", " ", "be", " ", "possible", " ", "for", " ", "the", " ", "refined", " ", "action", " ", "to", " ", "break", " ", "some", " ", "base", " ", "invariant", " ", "that", " ", "was", " ", "respected", " ", "by", " ", "the", " ", "given", " ", "event", " ", "in", " ", "base", " ", "model"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Join", "[", RowBox[{"baseInvariants", ",", "invariants"}], "]"}]}], "\[IndentingNewLine]", "]"}]}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"results", "=", RowBox[{"Join", "[", RowBox[{"results", ",", RowBox[{"Flatten", "[", "partialResults", "]"}]}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "check", " ", "superposition", " ", "of", " ", "states"}], ",", " ", RowBox[{ "if", " ", "the", " ", "event", " ", "is", " ", "refining"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}], "||", "\[IndentingNewLine]", RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}]}], ")"}], "&&", "\[IndentingNewLine]", RowBox[{"directlyRefinedEvents", "\[NotEqual]", RowBox[{"{", "}"}]}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "only", " ", "if", " ", "there", " ", "are", " ", "base", " ", "events"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"Note", ":", " ", RowBox[{ "on", " ", "any", " ", "refinement", " ", "path", " ", "collected", " ", "by", " ", RowBox[{"collectGuardPaths", "[", "]"}]}]}], ",", " ", RowBox[{ RowBox[{ "duplicates", " ", "are", " ", "already", " ", "removed"}], " ", "-", " ", RowBox[{ "this", " ", "means", " ", "that", " ", "only", " ", "syntactically", " ", "different", " ", "actions", " ", "have", " ", "their", " ", "keys", " ", RowBox[{"(", RowBox[{ "left", " ", "of", " ", "rule", " ", "assignment"}], ")"}], " ", "listed", " ", "multiple", " ", "times"}]}], ",", " ", RowBox[{ "so", " ", "it", " ", "is", " ", "enough", " ", "to", " ", "check", " ", "only", " ", "those", " ", "cases"}], ",", " ", RowBox[{ "where", " ", "the", " ", "given", " ", "variable", " ", "is", " ", "present", " ", "many", " ", "times", " ", "on", " ", "the", " ", "whole", " ", "path"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "there", " ", "are", " ", "possibly", " ", "multiple", " ", "refinement", " ", "paths"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Scan", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"path", ",", " ", RowBox[{"(*", RowBox[{"path", " ", "is", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"names", "..."}], "}"}], ",", RowBox[{"{", RowBox[{"guards", "..."}], "}"}], ",", RowBox[{"{", RowBox[{"actions", "..."}], "}"}]}], "}"}]}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"eventNames", "=", RowBox[{"path", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"inheritedGuards", "=", RowBox[{"path", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"combinedActions", "=", RowBox[{"path", "[", RowBox[{"[", "3", "]"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"combinedPromises", "=", RowBox[{"path", "[", RowBox[{"[", "4", "]"}], "]"}]}], ",", "\[IndentingNewLine]", "pathKnowns", ",", "\[IndentingNewLine]", "suspectedVariables", ",", " ", RowBox[{"(*", " ", RowBox[{ "variables", " ", "modified", " ", "differently", " ", "on", " ", "the", " ", "refinement", " ", "path"}], " ", "*)"}], "\[IndentingNewLine]", "superposition"}], " ", RowBox[{"(*", " ", RowBox[{"correctness", " ", RowBox[{"condition", ":", " ", RowBox[{ "base", " ", "actions", " ", "are", " ", "equivalent", " ", "to", " ", "these", " ", "actions"}]}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"pathKnowns", "=", RowBox[{"Join", "[", RowBox[{"knowns", ",", "inheritedGuards"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"suspectedVariables", "=", RowBox[{"Keys", "[", RowBox[{"Select", "[", RowBox[{ RowBox[{"CountsBy", "[", RowBox[{"combinedActions", ",", "First"}], "]"}], ",", RowBox[{ RowBox[{"#", ">", "1"}], "&"}]}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"suspectedVariables", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"superposition", "=", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"varName", ",", "\[IndentingNewLine]", RowBox[{"Equal", "@@", RowBox[{"(", RowBox[{ RowBox[{"Select", "[", RowBox[{"combinedActions", ",", RowBox[{ RowBox[{ RowBox[{"First", "[", "#", "]"}], "===", "varName"}], "&"}]}], "]"}], "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], ")"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "suspectedVariables"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"combinedPromises", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "there", " ", "are", " ", "promises", " ", "in", " ", "the", " ", "refinement", " ", "paths"}], ",", " ", RowBox[{ "check", " ", "if", " ", "they", " ", "are", " ", "fulfilled"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{"prettyProof", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "guardsActionPaths", "]"}], "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "title", " ", "for", " ", "single", " ", "refinement", " ", "path"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"\"\\"", "<>", "name"}], ",", RowBox[{"(*", " ", RowBox[{"title", " ", "for", " ", "multiple", " ", "refinement", " ", "paths"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"\"\\"", "<>", RowBox[{"prettyPath", "[", "eventNames", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Join", "[", RowBox[{"pathKnowns", ",", "superposition"}], "]"}], ",", "combinedPromises"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"doValidate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", RowBox[{"Join", "[", RowBox[{"pathKnowns", ",", "superposition"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"And", "@@", "combinedPromises"}], ",", "\[IndentingNewLine]", "theoremsOpt", ",", "\[IndentingNewLine]", "methodOpt", ",", "parallelOpt", ",", "verboseOpt"}], "\[IndentingNewLine]", "]"}]}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"there", " ", "are", " ", "no", " ", "promises"}], ",", " ", RowBox[{ "check", " ", "only", " ", "the", " ", "satisfiability", " ", "of", " ", "superposition"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{ "prettyReachabilityProof", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "guardsActionPaths", "]"}], "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "title", " ", "for", " ", "single", " ", "refinement", " ", "path"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"\"\\"", "<>", "name"}], ",", RowBox[{"(*", " ", RowBox[{ "title", " ", "for", " ", "multiple", " ", "refinement", " ", "paths"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"\"\\"", "<>", RowBox[{"prettyPath", "[", "eventNames", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Join", "[", RowBox[{"pathKnowns", ",", "superposition"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"satisfy", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", RowBox[{"Join", "[", RowBox[{"pathKnowns", ",", "superposition"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"theorems", "->", "theoremsOpt"}], ",", "\[IndentingNewLine]", RowBox[{"verbose", "->", "verboseOpt"}]}], "\[IndentingNewLine]", "]"}]}]}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ "there", " ", "are", " ", "no", " ", "suspected", " ", "variables"}], " ", "-", " ", RowBox[{"that", " ", "is"}]}], ",", " ", RowBox[{ "either", " ", "there", " ", "are", " ", "no", " ", "references", " ", "to", " ", "common", " ", "variables", " ", "across", " ", "the", " ", "refinement", " ", "path"}], ",", " ", RowBox[{ RowBox[{ "or", " ", "modifications", " ", "of", " ", "such", " ", "variables", " ", "are", " ", "syntactically", " ", "identical", " ", "and", " ", "were", " ", "thus", " ", "omitted", " ", "as", " ", "duplicates", " ", "already"}], "\[IndentingNewLine]", "\[Rule]", " ", RowBox[{ "if", " ", "there", " ", "are", " ", "no", " ", "promises", " ", "at", " ", "this", " ", "level"}]}], ",", " ", RowBox[{ "but", " ", "there", " ", "are", " ", "some", " ", "in", " ", "base", " ", "model"}], ",", " ", RowBox[{ "check", " ", "the", " ", "feasibility", " ", "of", " ", "actions", " ", "with", " ", "regard", " ", "to", " ", "base", " ", "promises"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"promises", "\[Equal]", RowBox[{"{", "}"}]}], "&&", RowBox[{"combinedPromises", "\[NotEqual]", RowBox[{"{", "}"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"basePromisesUpdated", "=", RowBox[{"combinedPromises", "/.", "actions"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{ "prettyReachabilityProof", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "guardsActionPaths", "]"}], "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "title", " ", "for", " ", "single", " ", "refinement", " ", "path"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"\"\\"", "<>", "name"}], ",", RowBox[{"(*", " ", RowBox[{ "title", " ", "for", " ", "multiple", " ", "refinement", " ", "paths"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"\"\\"", "<>", RowBox[{"prettyPath", "[", "eventNames", "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Join", "[", RowBox[{"pathKnowns", ",", "basePromisesUpdated"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"satisfy", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", RowBox[{"Join", "[", RowBox[{"pathKnowns", ",", "basePromisesUpdated"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"theorems", "->", "theoremsOpt"}], ",", "\[IndentingNewLine]", RowBox[{"verbose", "->", "verboseOpt"}]}], "\[IndentingNewLine]", "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"nothing", " ", "to", " ", "check"}], ",", " ", RowBox[{ "consider", " ", "superposition", " ", "to", " ", "pass"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"res", "=", "True"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"res", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "guardsActionPaths", "]"}], "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "report", " ", "for", " ", "single", " ", "refinement", " ", "path"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< state superposition: \>\"", ",", RowBox[{"prettyResult", "[", "res", "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "report", " ", "for", " ", "multiple", " ", "refinement", " ", "paths"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< state superposition via \>\"", ",", RowBox[{"prettyPath", "[", "eventNames", "]"}], ",", "\"\<: \>\"", ",", RowBox[{"prettyResult", "[", "res", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"results", ",", "res"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "guardsActionPaths"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "check", " ", "convergence", " ", "if", " ", "this", " ", "is", " ", "a", " ", "new", " ", "event", " ", "in", " ", "a", " ", "refining", " ", "model"}], ",", "\[IndentingNewLine]", RowBox[{ "or", " ", "if", " ", "the", " ", "convergence", " ", "was", " ", "ordered", " ", "explicitly"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}], "||", "\[IndentingNewLine]", RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}]}], ")"}], "&&", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "do", " ", "not", " ", "check", " ", "if", " ", "the", " ", "model", " ", "is", " ", "not", " ", "refining"}], ",", " ", RowBox[{ "unless", " ", "it", " ", "is", " ", "explicitly", " ", RowBox[{"on", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"base", "=!=", "Null"}], "||", RowBox[{"isConvergent", "[", RowBox[{"ev", ",", "False"}], "]"}]}], ")"}], "&&", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "check", " ", "only", " ", "if", " ", "event", " ", "is", " ", "from", " ", "this", " ", "model", " ", RowBox[{"(", RowBox[{ "not", " ", "implicit", " ", "from", " ", "base"}], ")"}]}], ":"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"MemberQ", "[", RowBox[{"thisModelEventNames", ",", "name"}], "]"}], "&&", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "do", " ", "not", " ", "check", " ", "if", " ", "event", " ", "is", " ", "refining"}], ",", " ", RowBox[{ "unless", " ", "it", " ", "is", " ", "explicitly", " ", RowBox[{"on", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"isConvergent", "[", RowBox[{"ev", ",", RowBox[{"directlyRefinedEvents", "==", RowBox[{"{", "}"}]}]}], "]"}], "&&", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "and", " ", "do", " ", "not", " ", "if", " ", "the", " ", "check", " ", "is", " ", "explicitly", " ", RowBox[{"suppressed", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"isConvergent", "[", RowBox[{"ev", ",", "True"}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"variants", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"variantsAreNatural", "=", RowBox[{ RowBox[{"Function", "[", RowBox[{"v", ",", RowBox[{ RowBox[{"Element", "[", RowBox[{"v", ",", "Integers"}], "]"}], "&&", RowBox[{"v", "\[GreaterEqual]", "0"}]}]}], "]"}], "/@", RowBox[{"variants", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}]}]}], ";", "\n", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{"prettyProof", "[", RowBox[{ RowBox[{"\"\\"", "<>", "name"}], ",", "\[IndentingNewLine]", "knowns", ",", "variantsAreNatural"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"doValidate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", "knowns"}], ",", "\[IndentingNewLine]", RowBox[{"And", "@@", "variantsAreNatural"}], ",", "\[IndentingNewLine]", "theoremsOpt", ",", "\[IndentingNewLine]", "methodOpt", ",", "parallelOpt", ",", "verboseOpt"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"res", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< variant limited: \>\"", ",", RowBox[{"prettyResult", "[", "res", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"results", ",", "res"}], "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"variantsAreMonotonic", "=", RowBox[{ RowBox[{"Function", "[", RowBox[{"v", ",", RowBox[{ RowBox[{"(", RowBox[{"v", "/.", "actions"}], ")"}], "<", "v"}]}], "]"}], "/@", RowBox[{"variants", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}]}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{"prettyProof", "[", RowBox[{ RowBox[{"\"\\"", "<>", "name"}], ",", "\[IndentingNewLine]", "knowns", ",", RowBox[{"Join", "[", RowBox[{ RowBox[{"variants", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], ",", RowBox[{"{", "\"\<\\ndecreases with\\n\>\"", "}"}], ",", "actions"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"doValidate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", "knowns"}], ",", "\[IndentingNewLine]", RowBox[{"And", "@@", "variantsAreMonotonic"}], ",", "\[IndentingNewLine]", "theoremsOpt", ",", "\[IndentingNewLine]", "methodOpt", ",", "parallelOpt", ",", "verboseOpt"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"res", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< variant monotonic: \>\"", ",", RowBox[{"prettyResult", "[", "res", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"results", ",", "res"}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"there", " ", "are", " ", "no", " ", "variants"}], ",", RowBox[{ "treat", " ", "it", " ", "as", " ", "an", " ", "incomplete", " ", "model"}]}], "*)"}], RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"Indeterminate", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< no variants defined: \>\"", ",", RowBox[{"prettyResult", "[", "Indeterminate", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"results", ",", "Indeterminate"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "check", " ", "anticipation", " ", "only", " ", "if", " ", "ordered", " ", "explicitly"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}], "||", "\[IndentingNewLine]", RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}]}], ")"}], "&&", "\[IndentingNewLine]", RowBox[{"isAnticipated", "[", "ev", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"variants", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"variantsAreNatural", "=", RowBox[{ RowBox[{"Function", "[", RowBox[{"v", ",", RowBox[{ RowBox[{"Element", "[", RowBox[{"v", ",", "Integers"}], "]"}], "&&", RowBox[{"v", "\[GreaterEqual]", "0"}]}]}], "]"}], "/@", RowBox[{"variants", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}]}]}], ";", "\n", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{"prettyProof", "[", RowBox[{ RowBox[{"\"\\"", "<>", "name"}], ",", "\[IndentingNewLine]", "knowns", ",", "variantsAreNatural"}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"doValidate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", "knowns"}], ",", "\[IndentingNewLine]", RowBox[{"And", "@@", "variantsAreNatural"}], ",", "\[IndentingNewLine]", "theoremsOpt", ",", "\[IndentingNewLine]", "methodOpt", ",", "parallelOpt", ",", "verboseOpt"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"res", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< variant limited: \>\"", ",", RowBox[{"prettyResult", "[", "res", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"results", ",", "res"}], "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"variantsAreNonGrowing", "=", RowBox[{ RowBox[{"Function", "[", RowBox[{"v", ",", RowBox[{ RowBox[{"(", RowBox[{"v", "/.", "actions"}], ")"}], "<=", "v"}]}], "]"}], "/@", RowBox[{"variants", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}]}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{"prettyProof", "[", RowBox[{ RowBox[{"\"\\"", "<>", "name"}], ",", "\[IndentingNewLine]", "knowns", ",", RowBox[{"Join", "[", RowBox[{ RowBox[{"variants", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}], ",", RowBox[{"{", "\"\<\\ndecreases with\\n\>\"", "}"}], ",", "actions"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"doValidate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", "knowns"}], ",", "\[IndentingNewLine]", RowBox[{"And", "@@", "variantsAreNonGrowing"}], ",", "\[IndentingNewLine]", "theoremsOpt", ",", "\[IndentingNewLine]", "methodOpt", ",", "parallelOpt", ",", "verboseOpt"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"res", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< variant non-growing: \>\"", ",", RowBox[{"prettyResult", "[", "res", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"results", ",", "res"}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"there", " ", "are", " ", "no", " ", "variants"}], ",", " ", RowBox[{ "treat", " ", "it", " ", "as", " ", "an", " ", "incomplete", " ", "model"}]}], " ", "*)"}], RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"Indeterminate", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< no variants defined: \>\"", ",", RowBox[{"prettyResult", "[", "Indeterminate", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"results", ",", "Indeterminate"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "events"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"validate", " ", "deaclock", " ", "freedom"}], ",", " ", RowBox[{"if", " ", "requested"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"both", " ", "deadlockFree", " ", "and", " ", RowBox[{"deadlockFree", "[", "]"}], " ", "forms", " ", "are", " ", "accepted"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"MemberQ", "[", RowBox[{"m", ",", RowBox[{"_deadlockFree", "|", "deadlockFree"}]}], "]"}], "&&", "\[IndentingNewLine]", RowBox[{"StringMatchQ", "[", RowBox[{"\"\\"", ",", "onlyPhaseOpt"}], "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"verboseOpt", "=!=", "Total"}], ",", "\[IndentingNewLine]", RowBox[{ "Print", "[", "\"\\"", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "base", " ", "guards", " ", "are", " ", "collected", " ", "from", " ", "all", " ", "leaf", " ", "events", " ", "of", " ", "the", " ", "base", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"allBaseGuards", "=", RowBox[{"allGuards", "[", "baseEvents", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"\"\\"", " ", "guards", " ", "are", " ", "collected", " ", "from", " ", "all", " ", "leaf", " ", "events", " ", "of", " ", "this", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"allThisGuards", "=", RowBox[{"allGuards", "[", "events", "]"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", "knowns", ",", "\[IndentingNewLine]", "res"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"knowns", "=", RowBox[{"Join", "[", "\[IndentingNewLine]", RowBox[{ "baseAxiomExprs", ",", "axiomExprs", ",", "\[IndentingNewLine]", "baseInvariantExprs", ",", "invariantExprs", ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"allBaseGuards", "===", "True"}], ",", RowBox[{"{", "}"}], ",", RowBox[{"{", "allBaseGuards", "}"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"showProofsOpt", ",", "\[IndentingNewLine]", RowBox[{"prettyProof", "[", RowBox[{"\"\\"", ",", "knowns", ",", RowBox[{"{", "allThisGuards", "}"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"res", "=", RowBox[{"doValidate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"And", "@@", "knowns"}], ",", "\[IndentingNewLine]", "allThisGuards", ",", "\[IndentingNewLine]", "theoremsOpt", ",", "\[IndentingNewLine]", "methodOpt", ",", "parallelOpt", ",", "verboseOpt"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"showResult", "[", RowBox[{"res", ",", "verboseOpt"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< deadlock freedom: \>\"", ",", RowBox[{"prettyResult", "[", "res", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"results", ",", "res"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "print", " ", "summary", " ", "of", " ", "final", " ", "results"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"counts", "=", RowBox[{"Counts", "[", "results", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", "\"\\"", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "counts", "]"}], "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", "\"\\"", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "counts", "]"}], "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"Length", "[", "results", "]"}], ",", "\"\< \>\"", ",", RowBox[{"prettyResult", "[", RowBox[{"First", "[", "results", "]"}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"r", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"r", " ", "is", " ", "result"}], "\[Rule]", "count"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\< \>\"", ",", RowBox[{"prettyResult", "[", RowBox[{"r", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}], ",", "\"\< \>\"", ",", RowBox[{"r", "[", RowBox[{"[", "2", "]"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Normal", "[", RowBox[{"Counts", "[", "results", "]"}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}]}]}]], "Input", InitializationCell->True, CellChangeTimes->{{3.9707290814043064`*^9, 3.97072908744866*^9}, { 3.9713209680655384`*^9, 3.971320972092352*^9}, {3.971321036924923*^9, 3.971321050859783*^9}, 3.9713210833614426`*^9, 3.9713280543953133`*^9, { 3.9713281938776894`*^9, 3.9713282213114185`*^9}}, CellLabel-> "In[269]:=",ExpressionUUID->"63df2883-0635-49e0-962b-ee77b801240c"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Examples", "Section",ExpressionUUID->"e487a85f-a6bd-475d-b5a1-bef200539c8d"], Cell[CellGroupData[{ Cell["Basic examples", "Subsection",ExpressionUUID->"07e2d479-a86a-4b3a-836c-19001e9d244c"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"deduceStep", "[", RowBox[{ RowBox[{"{", RowBox[{"A", ",", "B", ",", "C"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"A", ",", "B"}], "}"}], "\[Rule]", "X"}], ",", RowBox[{ RowBox[{"{", RowBox[{"B", ",", "C"}], "}"}], "\[Rule]", "Y"}]}], "}"}], ",", RowBox[{"verbose", "\[Rule]", "True"}]}], "]"}]], "Input", CellLabel-> "In[124]:=",ExpressionUUID->"15657f24-b994-4a16-af99-b085cecfddfe"], Cell[CellGroupData[{ Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"processing rule \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", RowBox[{ RowBox[{"{", RowBox[{"A", ",", "B"}], "}"}], "\[Rule]", "X"}]}], SequenceForm[ "processing rule ", 1, ": ", {$CellContext`A, $CellContext`B} -> $CellContext`X], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[124]:=",ExpressionUUID->"ebf5200b-c440-433c-8b68-d355f1577754"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" on: \"\>", "\[InvisibleSpace]", "\<\"A, B\"\>"}], SequenceForm[" on: ", "A, B"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[124]:=",ExpressionUUID->"4552edcc-18c9-4aef-b1f7-969f2af05338"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" gives: \"\>", "\[InvisibleSpace]", "\<\"X\"\>"}], SequenceForm[" gives: ", "X"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[124]:=",ExpressionUUID->"39656bd4-84f3-4f77-bad8-1f6fbfe6a639"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"processing rule \"\>", "\[InvisibleSpace]", "2", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", RowBox[{ RowBox[{"{", RowBox[{"B", ",", "C"}], "}"}], "\[Rule]", "Y"}]}], SequenceForm[ "processing rule ", 2, ": ", {$CellContext`B, C} -> $CellContext`Y], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[124]:=",ExpressionUUID->"117d183d-93ba-4c94-baaf-b4f321bdde82"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" on: \"\>", "\[InvisibleSpace]", "\<\"B, C\"\>"}], SequenceForm[" on: ", "B, C"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[124]:=",ExpressionUUID->"53d42212-5441-456c-909f-cc0e381f1177"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" gives: \"\>", "\[InvisibleSpace]", "\<\"Y\"\>"}], SequenceForm[" gives: ", "Y"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[124]:=",ExpressionUUID->"8119b2c2-f085-4223-8207-eb0b50c8529e"] }, Open ]], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"X", ",", "1", ",", RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}]}], "}"}], ",", RowBox[{"{", RowBox[{"Y", ",", "2", ",", RowBox[{"{", RowBox[{"2", ",", "3"}], "}"}]}], "}"}]}], "}"}]], "Output", CellLabel-> "Out[124]=",ExpressionUUID->"d87c7249-5682-41d5-93f6-ba127bfba68e"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"deduce", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"\[Not]", "A"}], "\[And]", "B"}], ",", RowBox[{"A", "\[Or]", RowBox[{"\[Not]", "B"}]}]}], "}"}], ",", "\[IndentingNewLine]", "standardRules", ",", "\[IndentingNewLine]", RowBox[{"finalTerms", "\[Rule]", RowBox[{"{", RowBox[{"True", ",", "False"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[125]:=",ExpressionUUID->"4d9c2189-b05a-468a-834c-fb3439a880c5"], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"!", "A"}], "&&", "B"}], ",", RowBox[{"A", "||", RowBox[{"!", "B"}]}], ",", "False"}], "}"}]], "Output", CellLabel-> "Out[125]=",ExpressionUUID->"1fd6fad9-7fac-4f72-abef-57612a23f312"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"deduce", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "1", "}"}], ",", " ", RowBox[{"(*", " ", RowBox[{"start", " ", "with", " ", "1"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"{", "_", "}"}], "\[Rule]", RowBox[{"(", RowBox[{"a", "\[Function]", RowBox[{"2", "a"}]}], ")"}]}], "}"}], ",", " ", RowBox[{"(*", " ", RowBox[{"double", " ", "everything"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"finalTerms", "\[Rule]", RowBox[{"(", RowBox[{"x", "\[Function]", RowBox[{"x", ">", "20"}]}], ")"}]}]}], " ", RowBox[{"(*", " ", RowBox[{"until", " ", "above", " ", "20"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[126]:=",ExpressionUUID->"7c9813a6-d43f-4213-b51b-1fad236d94cc"], Cell[BoxData[ RowBox[{"{", RowBox[{"1", ",", "2", ",", "4", ",", "8", ",", "16", ",", "32"}], "}"}]], "Output", CellLabel-> "Out[126]=",ExpressionUUID->"48a41df1-e3da-4292-88a2-5acfbff349c7"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"deduce", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"2", ",", "3"}], "}"}], ",", " ", RowBox[{"(*", " ", RowBox[{"start", " ", "with", " ", "2", " ", "and", " ", "3"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"_", ",", "_"}], "}"}], "\[Rule]", RowBox[{"(", RowBox[{ RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}], "\[Function]", RowBox[{"a", "*", "b"}]}], ")"}]}], "}"}], ",", " ", RowBox[{"(*", " ", RowBox[{"multiply", " ", "any", " ", "two", " ", "values"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"finalTerms", "\[Rule]", RowBox[{"(", RowBox[{"x", "\[Function]", RowBox[{"x", ">", "20"}]}], ")"}]}]}], " ", RowBox[{"(*", " ", RowBox[{"until", " ", "above", " ", "20"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[127]:=",ExpressionUUID->"7da1b539-462c-4673-82dc-4f8e85c23dc5"], Cell[BoxData[ RowBox[{"{", RowBox[{"2", ",", "3", ",", "6", ",", "12", ",", "18", ",", "24"}], "}"}]], "Output", CellLabel-> "Out[127]=",ExpressionUUID->"4dfde821-52ba-4f5c-99e7-2ed4beee8c35"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"rules", "=", RowBox[{"{", RowBox[{ RowBox[{"{", "_", "}"}], "\[Rule]", RowBox[{"(", RowBox[{"x", "\[Function]", RowBox[{"Mod", "[", RowBox[{ RowBox[{"3", "x"}], ",", "10"}], "]"}]}], ")"}]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"result", "=", RowBox[{"deduce", "[", RowBox[{ RowBox[{"{", "1", "}"}], ",", "rules", ",", RowBox[{"withTrace", "\[Rule]", "True"}]}], "]"}]}], ";", RowBox[{"Grid", "[", "result", "]"}]}]}], "Input", CellLabel-> "In[128]:=",ExpressionUUID->"05173cf9-4435-4a75-bedc-cce7fbf370b8"], Cell[BoxData[ TagBox[GridBox[{ {"1", "3", "9", "7"}, { RowBox[{"{", RowBox[{"0", ",", RowBox[{"{", "}"}]}], "}"}], RowBox[{"{", RowBox[{"1", ",", RowBox[{"{", "1", "}"}]}], "}"}], RowBox[{"{", RowBox[{"1", ",", RowBox[{"{", "2", "}"}]}], "}"}], RowBox[{"{", RowBox[{"1", ",", RowBox[{"{", "3", "}"}]}], "}"}]} }, AutoDelete->False, GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}], "Grid"]], "Output", CellLabel-> "Out[129]=",ExpressionUUID->"b332c477-32df-494c-9d5a-a4dd82e6ad4f"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"showSteps", "[", RowBox[{"result", ",", "rules"}], "]"}]], "Input", CellLabel-> "In[130]:=",ExpressionUUID->"f1018f07-4306-418a-88cc-37696bb59c3a"], Cell[CellGroupData[{ Cell[BoxData["\<\"Showing all entries.\"\>"], "Print", CellLabel-> "During evaluation of \ In[130]:=",ExpressionUUID->"be7319b4-f06e-4392-8104-34cedd7ad7ee"], Cell[BoxData[ TagBox[ FormBox[ RowBox[{ RowBox[{"{", "_", "}"}], "\[Rule]", RowBox[{"Function", "[", RowBox[{"x", ",", RowBox[{"Mod", "[", RowBox[{ RowBox[{"3", " ", "x"}], ",", "10"}], "]"}]}], "]"}]}], StandardForm], StandardForm, Editable->True]], "Print", CellLabel-> "During evaluation of \ In[130]:=",ExpressionUUID->"9fa49043-8fbd-4c6e-b445-4a140dd27c63"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" with: \"\>", "\[InvisibleSpace]", "\<\"1\"\>"}], SequenceForm[" with: ", "1"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[130]:=",ExpressionUUID->"3d44d92d-8603-459d-acb2-9c82099aca4d"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" gives: \"\>", "\[InvisibleSpace]", "3"}], SequenceForm[" gives: ", 3], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[130]:=",ExpressionUUID->"fa7aa7cd-e865-4ff2-b450-8961f379483c"], Cell[BoxData[ TagBox[ FormBox[ RowBox[{ RowBox[{"{", "_", "}"}], "\[Rule]", RowBox[{"Function", "[", RowBox[{"x", ",", RowBox[{"Mod", "[", RowBox[{ RowBox[{"3", " ", "x"}], ",", "10"}], "]"}]}], "]"}]}], StandardForm], StandardForm, Editable->True]], "Print", CellLabel-> "During evaluation of \ In[130]:=",ExpressionUUID->"c582ec33-0821-4563-bd5f-40b2fd6bf436"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" with: \"\>", "\[InvisibleSpace]", "\<\"3\"\>"}], SequenceForm[" with: ", "3"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[130]:=",ExpressionUUID->"577f2da9-8d62-4372-9ff3-a45d075f8752"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" gives: \"\>", "\[InvisibleSpace]", "9"}], SequenceForm[" gives: ", 9], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[130]:=",ExpressionUUID->"797280b9-071d-4b19-9814-03e424c2bcad"], Cell[BoxData[ TagBox[ FormBox[ RowBox[{ RowBox[{"{", "_", "}"}], "\[Rule]", RowBox[{"Function", "[", RowBox[{"x", ",", RowBox[{"Mod", "[", RowBox[{ RowBox[{"3", " ", "x"}], ",", "10"}], "]"}]}], "]"}]}], StandardForm], StandardForm, Editable->True]], "Print", CellLabel-> "During evaluation of \ In[130]:=",ExpressionUUID->"c520d309-f52d-453a-bf67-34909ac3ba7c"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" with: \"\>", "\[InvisibleSpace]", "\<\"9\"\>"}], SequenceForm[" with: ", "9"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[130]:=",ExpressionUUID->"f2a0a3ec-c98d-47c9-8e39-225352907675"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" gives: \"\>", "\[InvisibleSpace]", "7"}], SequenceForm[" gives: ", 7], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[130]:=",ExpressionUUID->"8f138ce3-5644-43d6-ac73-f588eaa41cb0"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ RowBox[{ "is", " ", "the", " ", "sum", " ", "of", " ", "two", " ", "positive", " ", "values", " ", "also", " ", RowBox[{"positive", "?", " ", "yes"}]}], ",", " ", "always"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"a", ">", "0"}], "\[And]", RowBox[{"b", ">", "0"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "+", "b"}], ">", "0"}]}], "\[IndentingNewLine]", "]"}]}]], "Input", CellLabel-> "In[131]:=",ExpressionUUID->"8c550027-df3b-4553-964a-26bb4bc149b3"], Cell[BoxData["True"], "Output", CellLabel-> "Out[131]=",ExpressionUUID->"e6a9133c-35b0-428c-8dc2-c0989bc61087"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ "is", " ", "the", " ", "sum", " ", "of", " ", "two", " ", "positive", " ", "values", " ", "less", " ", "than", " ", RowBox[{"100", "?", " ", "not"}], " ", "necessarily"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"a", ">", "0"}], "\[And]", RowBox[{"b", ">", "0"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "+", "b"}], "<", "100"}]}], "\[IndentingNewLine]", "]"}]}]], "Input", CellLabel-> "In[132]:=",ExpressionUUID->"a0a6056e-47d7-4791-9017-16adc0c38e19"], Cell[BoxData["Indeterminate"], "Output", CellLabel-> "Out[132]=",ExpressionUUID->"2037f2a6-cfb5-449c-859c-1cd9222772f6"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ "is", " ", "it", " ", "possible", " ", "for", " ", "the", " ", "sum", " ", "of", " ", "two", " ", "positive", " ", "values", " ", "to", " ", "be", " ", "less", " ", "than", " ", RowBox[{"100", "?", " ", "yes"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"satisfy", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", ">", "0"}], "\[And]", RowBox[{"b", ">", "0"}], "\[And]", RowBox[{ RowBox[{"a", "+", "b"}], "<", "100"}]}], "\[IndentingNewLine]", "]"}]}]], "Input", CellLabel-> "In[133]:=",ExpressionUUID->"0e47a2e7-6865-4294-966c-39f19c389535"], Cell[BoxData["True"], "Output", CellLabel-> "Out[133]=",ExpressionUUID->"d6a04c4a-377c-4dac-b05c-d23aba286955"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ "is", " ", "it", " ", "possible", " ", "for", " ", "the", " ", "sum", " ", "of", " ", "two", " ", "positive", " ", "values", " ", "to", " ", "be", " ", RowBox[{"negative", "?", " ", "no"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"satisfy", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", ">", "0"}], "\[And]", RowBox[{"b", ">", "0"}], "\[And]", RowBox[{ RowBox[{"a", "+", "b"}], "<", "0"}]}], "\[IndentingNewLine]", "]"}]}]], "Input", CellLabel-> "In[134]:=",ExpressionUUID->"b3b7a9c2-7f65-49f4-89e2-a9f16768f385"], Cell[BoxData["False"], "Output", CellLabel-> "Out[134]=",ExpressionUUID->"af3d53ea-951c-4674-b829-80bebfe1cca7"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Known issues", "Subsection",ExpressionUUID->"1df4db60-4e57-4de6-9654-8b5d2758e53a"], Cell["This fails to answer the question:", "Text",ExpressionUUID->"35fb4960-afbb-4fb0-9ee0-94003df06fe9"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"r", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"a", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"b", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"a", "\[Equal]", "b"}]}], "\[InvisibleSpace]", ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"r", "\[Equal]", "a"}], "\[Implies]", RowBox[{ RowBox[{"(", RowBox[{"r", "\[NotEqual]", "b"}], ")"}], "\[Equal]", "False"}]}], ")"}], "&&", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"r", "\[NotEqual]", "b"}], ")"}], "\[Equal]", "False"}], "\[Implies]", RowBox[{"r", "\[Equal]", "a"}]}], ")"}]}]}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[135]:=",ExpressionUUID->"4bdbc5c2-d913-4414-bb83-41491f6e753e"], Cell[BoxData["Indeterminate"], "Output", CellLabel-> "Out[135]=",ExpressionUUID->"f89449c5-aace-4b01-ac0e-5a7e3c9e2040"] }, Open ]], Cell["\<\ ... even though it can solve each part of the question separately:\ \>", "Text",ExpressionUUID->"37d1cb66-adf7-4798-99cd-b10f99c77661"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"r", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"a", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"b", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"a", "\[Equal]", "b"}]}], "\[InvisibleSpace]", ",", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"r", "\[Equal]", "a"}], "\[Implies]", RowBox[{ RowBox[{"(", RowBox[{"r", "\[NotEqual]", "b"}], ")"}], "\[Equal]", "False"}]}], ")"}]}], RowBox[{"(*", " ", RowBox[{"&&", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"r", "\[NotEqual]", "b"}], ")"}], "\[Equal]", "False"}], "\[Implies]", RowBox[{"r", "\[Equal]", "a"}]}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[136]:=",ExpressionUUID->"e251d7f5-9c02-4a5c-990b-ccbe2c09bbdf"], Cell[BoxData["True"], "Output", CellLabel-> "Out[136]=",ExpressionUUID->"cb6e98cd-9a99-4abe-903b-3dae23e5481d"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"r", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"a", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"b", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"a", "\[Equal]", "b"}]}], "\[InvisibleSpace]", ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"r", "\[Equal]", "a"}], "\[Implies]", RowBox[{ RowBox[{"(", RowBox[{"r", "\[NotEqual]", "b"}], ")"}], "\[Equal]", "False"}]}], ")"}], "&&"}], " ", "*)"}], RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"r", "\[NotEqual]", "b"}], ")"}], "\[Equal]", "False"}], "\[Implies]", RowBox[{"r", "\[Equal]", "a"}]}], ")"}]}], " ", "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[137]:=",ExpressionUUID->"53be9cc5-95e2-412c-a419-29aca8caaeac"], Cell[BoxData["True"], "Output", CellLabel-> "Out[137]=",ExpressionUUID->"c2264b9a-05b0-4ba7-8c6b-757a5d3227ca"] }, Open ]], Cell["This fails to answer the question:", "Text",ExpressionUUID->"b2ef4389-20a9-4371-9fd5-c9575a84cf10"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"i", "\[Element]", "Booleans"}], "&&", RowBox[{"r", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"b", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"i", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r", "\[Equal]", "b"}]}], ")"}], "&&", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"r", "\[Equal]", "b"}], "\[Implies]", RowBox[{"i", "\[Equal]", "False"}]}], ")"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"i", "\[Equal]", RowBox[{"(", RowBox[{"r", "\[NotEqual]", "b"}], ")"}]}]}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[138]:=",ExpressionUUID->"e80f9d2f-ab14-4518-bdf1-e776a845a16b"], Cell[BoxData["Indeterminate"], "Output", CellLabel-> "Out[138]=",ExpressionUUID->"0c4b9bc1-7d92-4e24-8c78-d12431ebaeaf"] }, Open ]], Cell["... even though it can do so in the piecewise mode:", "Text",ExpressionUUID->"91420703-810f-4008-a492-94dcd22218f3"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validatePiecewise", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"i", "\[Element]", "Booleans"}], "&&", RowBox[{"r", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"b", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"i", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r", "\[Equal]", "b"}]}], ")"}], "&&", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"r", "\[Equal]", "b"}], "\[Implies]", RowBox[{"i", "\[Equal]", "False"}]}], ")"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"i", "\[Equal]", RowBox[{"(", RowBox[{"r", "\[NotEqual]", "b"}], ")"}]}]}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[139]:=",ExpressionUUID->"932a6baf-0470-43cf-893c-77319f82a5dd"], Cell[BoxData["True"], "Output", CellLabel-> "Out[139]=",ExpressionUUID->"0c75d592-a923-49b2-9e38-4b63e5563bd8"] }, Open ]], Cell["\<\ This fails to answer the question (rounded average of two integer numbers is \ within their range):\ \>", "Text",ExpressionUUID->"9c80b8b6-cdfc-47df-9a77-4b41a4c64e5b"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"a", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"b", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"a", "<", "b"}]}], ",", "\[IndentingNewLine]", RowBox[{"a", "\[LessEqual]", RowBox[{"IntegerPart", "[", RowBox[{ RowBox[{"(", RowBox[{"a", "+", "b"}], ")"}], "/", "2"}], "]"}], "\[LessEqual]", "b"}]}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[140]:=",ExpressionUUID->"beb0359a-29f8-44bd-a2da-3f3186dec1d2"], Cell[BoxData["Indeterminate"], "Output", CellLabel-> "Out[140]=",ExpressionUUID->"fa328d5d-423f-4013-bee6-dcbe7f7e90cb"] }, Open ]], Cell["\<\ However, small restructuring of the question allows it to prove correctly:\ \>", "Text",ExpressionUUID->"3f11e9eb-8d7a-4e6e-bb5e-1c32f433cef3"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"a", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"b", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"a", "<", "b"}]}], ",", "\[IndentingNewLine]", RowBox[{"a", "\[LessEqual]", RowBox[{"a", "+", RowBox[{"IntegerPart", "[", RowBox[{ RowBox[{"(", RowBox[{"b", "-", "a"}], ")"}], "/", "2"}], "]"}]}], "\[LessEqual]", "b"}]}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel->"In[59]:=",ExpressionUUID->"d5082e42-40b3-4c9e-aa3d-ca058a133d45"], Cell[BoxData["True"], "Output", CellLabel->"Out[59]=",ExpressionUUID->"fe5edc19-9512-4395-a6d4-f60d023faba9"] }, Open ]], Cell["\<\ Some real problems can lead to expressions that are too difficult for the \ underlying functions to solve. For example (see theorem \[OpenCurlyDoubleQuote]th1\[CloseCurlyDoubleQuote] \ in \[OpenCurlyDoubleQuote]Model - digital circuit: arbiter\ \[CloseCurlyDoubleQuote] example below):\ \>", "Text",ExpressionUUID->"a9a61ff4-5073-4966-b0bf-d7104d9c9f2d"], Cell[BoxData[{ RowBox[{ RowBox[{"expr1", "=", RowBox[{ RowBox[{"(", RowBox[{"r2", "\[NotEqual]", "b2"}], ")"}], "\[Equal]", RowBox[{"(", RowBox[{"r2", "\[NotEqual]", "a2"}], ")"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"expr2", "=", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"r2", "==", "b2"}], "&&", RowBox[{"r2", "==", "a2"}]}], ")"}], "||", RowBox[{"(", RowBox[{ RowBox[{"r2", "!=", "b2"}], "&&", RowBox[{"r2", "!=", "a2"}]}], ")"}]}], ")"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"FindInstance", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"env", "\[NotEqual]", "cir"}], "&&", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "||", RowBox[{"mode", "\[Equal]", "cir"}]}], ")"}], "&&", "\[IndentingNewLine]", RowBox[{"r1", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"r1", "\[GreaterEqual]", "0"}], "&&", "\[IndentingNewLine]", RowBox[{"r2", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"r2", "\[GreaterEqual]", "0"}], "&&", "\[IndentingNewLine]", RowBox[{"a1", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"a1", "\[GreaterEqual]", "0"}], "&&", "\[IndentingNewLine]", RowBox[{"a2", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"a2", "\[GreaterEqual]", "0"}], "&&", "\[IndentingNewLine]", RowBox[{"a1", "\[LessEqual]", "r1"}], "&&", RowBox[{"r1", "\[LessEqual]", RowBox[{"1", "+", "a1"}]}], "&&", RowBox[{"a2", "\[LessEqual]", "r2"}], "&&", RowBox[{"r2", "\[LessEqual]", RowBox[{"1", "+", "a2"}]}], "&&", "\[IndentingNewLine]", RowBox[{"p1", "\[Element]", "Booleans"}], "&&", "\[IndentingNewLine]", RowBox[{"p2", "\[Element]", "Booleans"}], "&&", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"p1", "\[Equal]", "False"}], "||", RowBox[{"p2", "\[Equal]", "False"}]}], ")"}], "&&", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"p1", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r1", "\[Equal]", "a1"}]}], ")"}]}], ")"}], "&&", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"p2", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r2", "\[Equal]", "a2"}]}], ")"}]}], ")"}], "&&", "\[IndentingNewLine]", RowBox[{"b1", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"b1", "\[GreaterEqual]", "0"}], "&&", "\[IndentingNewLine]", RowBox[{"o1", "\[Element]", "Booleans"}], "&&", "\[IndentingNewLine]", RowBox[{"b2", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"b2", "\[GreaterEqual]", "0"}], "&&", "\[IndentingNewLine]", RowBox[{"o2", "\[Element]", "Booleans"}], "&&", "\[IndentingNewLine]", RowBox[{"mode", "\[Equal]", "cir"}], "&&", "\[IndentingNewLine]", "\[IndentingNewLine]", "expr1"}], " ", RowBox[{"(*", " ", RowBox[{"replace", " ", "with", " ", "equivalent", " ", "expr2"}], " ", "*)"}], "\[IndentingNewLine]", ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ "a1", ",", "a2", ",", "b1", ",", "b2", ",", "cir", ",", "env", ",", "mode", ",", "o1", ",", "o2", ",", "p1", ",", "p2", ",", "r1", ",", "r2"}], "}"}]}], "\[IndentingNewLine]", "]"}]}], "Input", CellLabel->"In[79]:=",ExpressionUUID->"14a89d1b-0ae6-431a-8974-b9911e5fd360"] }, Closed]], Cell[CellGroupData[{ Cell["Source Code Verification", "Subsection",ExpressionUUID->"cb176461-f0f4-4477-ad48-cc8ab660242c"], Cell[CellGroupData[{ Cell["Mean value - naive version", "Subsubsection",ExpressionUUID->"e8bddd05-5249-4f2b-9d3d-4ca6a2bfc408"], Cell["\<\ This example demonstrates basic verification for a function that computes the \ mean of two integers.\ \>", "Text", CellChangeTimes->{{3.972116385479925*^9, 3.972116385984783*^9}},ExpressionUUID->"ddfb6c37-57c0-4d2a-a55a-\ cef96f5e7c1a"], Cell["\<\ int mean(int a, int b) { int res = (a + b) / 2; return res; }\ \>", "CodeText",ExpressionUUID->"9208b080-001f-4af2-b6b6-1d7c9007386a"], Cell["\<\ The only \[OpenCurlyDoubleQuote]dangerous\[CloseCurlyDoubleQuote] operation \ is addition a+b, which can potentially overflow.\ \>", "Text",ExpressionUUID->"709bc880-58e3-4732-86cb-ea72bd739584"], Cell["Initial assumptions (on a system with 32-bit integers):", "Text",ExpressionUUID->"3ee4fc54-b721-41e5-aed9-f675a28c8188"], Cell[BoxData[{ RowBox[{ RowBox[{"intMin", "=", RowBox[{"-", SuperscriptBox["2", "31"]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"intMax", "=", RowBox[{ SuperscriptBox["2", "31"], "-", "1"}]}], ";"}]}], "Input", CellLabel-> "In[142]:=",ExpressionUUID->"ad274347-3836-493f-9061-e2a42887033f"], Cell["Validate the lack of integer overflow in the addition:", "Text",ExpressionUUID->"8b45cf43-83b7-426a-b230-3bed44eaccfc"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"intMin", "\[LessEqual]", "a", "\[LessEqual]", "intMax"}], "\[And]", RowBox[{"intMin", "\[LessEqual]", "b", "\[LessEqual]", "intMax"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"intMin", "\[LessEqual]", RowBox[{"a", "+", "b"}], "\[LessEqual]", "intMax"}]}], " ", RowBox[{"(*", " ", RowBox[{"is", " ", "it", " ", "always", " ", "the", " ", RowBox[{"case", "?"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[144]:=",ExpressionUUID->"bcff7911-8ddb-4d72-8070-f2a6617513c5"], Cell[BoxData["Indeterminate"], "Output", CellLabel-> "Out[144]=",ExpressionUUID->"5951e39e-dd60-4f71-9aae-4801314f6261"] }, Open ]], Cell["This result shows that safe execution is not guaranteed.", "Text",ExpressionUUID->"205012c6-c550-42fa-bd39-c14f88d87c35"], Cell["\<\ We can assume that input values are limited by the caller, for example in the \ range 0..100. Then, the naive way to compute the mean value is safe:\ \>", "Text",ExpressionUUID->"69baaa27-1893-4e26-aecd-9ec9e09ec991"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"0", "\[LessEqual]", "a", "\[LessEqual]", "100"}], "\[And]", RowBox[{"0", "\[LessEqual]", "b", "\[LessEqual]", "100"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "+", "b"}], "\[LessEqual]", "intMax"}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"and", " ", "now"}], ",", " ", RowBox[{"is", " ", "it", " ", RowBox[{"safe", "?"}]}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[145]:=",ExpressionUUID->"220aaa22-0cec-416b-95fa-238a26afd1a7"], Cell[BoxData["True"], "Output", CellLabel-> "Out[145]=",ExpressionUUID->"7f404702-6e57-4731-b171-b891d7cf9766"] }, Open ]], Cell["\<\ This result shows that if input values are in the range 0..100, then the mean \ value can be safely computed with this method - but for unconstrained inputs \ this method is not appropriate.\ \>", "Text",ExpressionUUID->"938db21d-bd14-474b-b735-dbb3934043ee"] }, Closed]], Cell[CellGroupData[{ Cell["Mean value - corrected", "Subsubsection",ExpressionUUID->"d99d7658-e0b9-42ac-9a57-a1a506efb733"], Cell["\<\ We can notice that a+b does not lead to overflow if a and b have different \ signs - their sum is always somewhere between them. The overflow is avoided \ in that case. We can also notice that instead of using the original formula, we can take \ one of two values and add to it half of their difference:\ \>", "Text",ExpressionUUID->"a321b378-10de-4427-bf0d-429bd7c2f814"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"FullSimplify", "[", RowBox[{ FractionBox[ RowBox[{"a", "+", "b"}], "2"], "\[Equal]", RowBox[{"a", "+", FractionBox[ RowBox[{"b", "-", "a"}], "2"]}]}], "]"}]], "Input", CellLabel-> "In[146]:=",ExpressionUUID->"03e26fa6-a59c-41c1-83cf-9e1c8cba0d71"], Cell[BoxData["True"], "Output", CellLabel-> "Out[146]=",ExpressionUUID->"df812860-e895-43df-8766-310c3125db0d"] }, Open ]], Cell["\<\ If a and b have the same sign, this method also avoids the overflow.\ \>", "Text",ExpressionUUID->"98576154-b20c-43ba-bfc7-c6dc234e112f"], Cell["\<\ These observations suggest the following correct implementation:\ \>", "Text",ExpressionUUID->"c667905f-54ca-475c-98b7-86c065567ea4"], Cell["\<\ int mean(int a, int b) { \tint res; \t \tif ((a >= 0 && b >= 0) || (a < 0 && b < 0)) \t{ \t\t// a and b have the same sign \t\t \t\tres = a + (b - a) / 2; \t} \telse \t{ \t\t// a and b have different signs \t\t \t\tres = (a + b) / 2; \t} \t \treturn res; }\ \>", "CodeText",ExpressionUUID->"7c9d141d-4d01-4a4b-99a8-ee2b5eae1227"], Cell["\<\ The first branch has two potentially dangerous (leading to overflow) \ operations - subtraction and addition. The second branch has only one \ addition to check.\ \>", "Text",ExpressionUUID->"2dcca28d-cc3f-4322-82de-5a7345187726"], Cell["In the first branch, subtraction is safe:", "Text",ExpressionUUID->"6e711fa8-bd00-48ec-90d2-0bfea2e12ba9"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"what", " ", "we", " ", "know", " ", "about", " ", "variable", " ", RowBox[{"a", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"a", "\[Element]", "Integers"}], "\[And]", RowBox[{"intMin", "\[LessEqual]", "a", "\[LessEqual]", "intMax"}], "\[And]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"what", " ", "we", " ", "know", " ", "about", " ", "variable", " ", RowBox[{"b", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"b", "\[Element]", "Integers"}], "\[And]", RowBox[{"intMin", "\[LessEqual]", "b", "\[LessEqual]", "intMax"}], "\[And]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"condition", " ", "of", " ", "the", " ", "first", " ", RowBox[{"branch", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"a", "\[GreaterEqual]", "0"}], "\[And]", RowBox[{"b", "\[GreaterEqual]", "0"}]}], ")"}], "\[Or]", RowBox[{"(", RowBox[{ RowBox[{"a", "<", "0"}], "\[And]", RowBox[{"b", "<", "0"}]}], ")"}]}], ")"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"our", " ", "verification", " ", RowBox[{"condition", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"intMin", "\[LessEqual]", RowBox[{"b", "-", "a"}], "\[LessEqual]", "intMax"}]}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[147]:=",ExpressionUUID->"20c2d379-bca8-4609-9e39-376fff80dced"], Cell[BoxData["True"], "Output", CellLabel-> "Out[147]=",ExpressionUUID->"68b5d63d-e302-4cbd-8348-227b3c2d3b3c"] }, Open ]], Cell["Addition in the first branch is also safe:", "Text",ExpressionUUID->"9bd0f988-bc9c-482f-b967-ad9d78c4da1e"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"what", " ", "we", " ", "know", " ", "about", " ", "variable", " ", RowBox[{"a", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"a", "\[Element]", "Integers"}], "\[And]", RowBox[{"intMin", "\[LessEqual]", "a", "\[LessEqual]", "intMax"}], "\[And]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"what", " ", "we", " ", "know", " ", "about", " ", "variable", " ", RowBox[{"b", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"b", "\[Element]", "Integers"}], "\[And]", RowBox[{"intMin", "\[LessEqual]", "b", "\[LessEqual]", "intMax"}], "\[And]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"condition", " ", "of", " ", "the", " ", "first", " ", RowBox[{"branch", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"a", "\[GreaterEqual]", "0"}], "\[And]", RowBox[{"b", "\[GreaterEqual]", "0"}]}], ")"}], "\[Or]", RowBox[{"(", RowBox[{ RowBox[{"a", "<", "0"}], "\[And]", RowBox[{"b", "<", "0"}]}], ")"}]}], ")"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"our", " ", "verification", " ", RowBox[{"condition", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"intMin", "\[LessEqual]", RowBox[{"a", "+", FractionBox[ RowBox[{"b", "-", "a"}], "2"]}], "\[LessEqual]", "intMax"}]}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[148]:=",ExpressionUUID->"7323eaff-4f97-4ff8-ab7f-20fb774801fb"], Cell[BoxData["True"], "Output", CellLabel-> "Out[148]=",ExpressionUUID->"85591b8f-1551-4406-97d9-1f74995f18f0"] }, Open ]], Cell["\<\ Finally, addition in the second branch (before dividing by half) is also fine:\ \>", "Text",ExpressionUUID->"a6471a07-1323-4c69-9240-8491945a0d03"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validate", "[", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"what", " ", "we", " ", "know", " ", "about", " ", "variable", " ", RowBox[{"a", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"a", "\[Element]", "Integers"}], "\[And]", RowBox[{"intMin", "\[LessEqual]", "a", "\[LessEqual]", "intMax"}], "\[And]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"what", " ", "we", " ", "know", " ", "about", " ", "variable", " ", RowBox[{"b", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"b", "\[Element]", "Integers"}], "\[And]", RowBox[{"intMin", "\[LessEqual]", "b", "\[LessEqual]", "intMax"}], "\[And]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"condition", " ", "of", " ", "the", " ", "second", " ", RowBox[{"branch", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"\[Not]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"a", "\[GreaterEqual]", "0"}], "\[And]", RowBox[{"b", "\[GreaterEqual]", "0"}]}], ")"}], "\[Or]", RowBox[{"(", RowBox[{ RowBox[{"a", "<", "0"}], "\[And]", RowBox[{"b", "<", "0"}]}], ")"}]}], ")"}]}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"our", " ", "verification", " ", RowBox[{"condition", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"intMin", "\[LessEqual]", RowBox[{"a", "+", "b"}], "\[LessEqual]", "intMax"}]}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[149]:=",ExpressionUUID->"c1a8332b-c95b-4daa-bb28-32f7423dcbb0"], Cell[BoxData["True"], "Output", CellLabel-> "Out[149]=",ExpressionUUID->"57c0e4e4-26d3-4338-81f4-d585c961be1d"] }, Open ]], Cell["\<\ Last but not least - the conditional statement (with two branches) was \ introduced in this version and it is prudent to check whether those branches \ are reachable - that is, whether it is possible to have the input values such \ that those branches are executed.\ \>", "Text",ExpressionUUID->"6c628b5e-2357-4208-bf3c-7be52aebb7dd"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"satisfy", "[", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"what", " ", "we", " ", "know", " ", "about", " ", "variable", " ", RowBox[{"a", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Element]", "Integers"}], "\[And]", RowBox[{"intMin", "\[LessEqual]", "a", "\[LessEqual]", "intMax"}], "\[And]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"what", " ", "we", " ", "know", " ", "about", " ", "variable", " ", RowBox[{"b", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"b", "\[Element]", "Integers"}], "\[And]", RowBox[{"intMin", "\[LessEqual]", "b", "\[LessEqual]", "intMax"}], "\[And]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"condition", " ", "of", " ", "the", " ", "first", " ", RowBox[{"branch", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"a", "\[GreaterEqual]", "0"}], "\[And]", RowBox[{"b", "\[GreaterEqual]", "0"}]}], ")"}], "\[Or]", RowBox[{"(", RowBox[{ RowBox[{"a", "<", "0"}], "\[And]", RowBox[{"b", "<", "0"}]}], ")"}]}], ")"}]}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[150]:=",ExpressionUUID->"c912bd5a-f47d-429c-8f21-32c3a067c786"], Cell[BoxData["True"], "Output", CellLabel-> "Out[150]=",ExpressionUUID->"3611f345-6ea6-44fa-82e7-9f9a43677a40"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"satisfy", "[", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"what", " ", "we", " ", "know", " ", "about", " ", "variable", " ", RowBox[{"a", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Element]", "Integers"}], "\[And]", RowBox[{"intMin", "\[LessEqual]", "a", "\[LessEqual]", "intMax"}], "\[And]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"what", " ", "we", " ", "know", " ", "about", " ", "variable", " ", RowBox[{"b", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"b", "\[Element]", "Integers"}], "\[And]", RowBox[{"intMin", "\[LessEqual]", "b", "\[LessEqual]", "intMax"}], "\[And]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"condition", " ", "of", " ", "the", " ", "second", " ", RowBox[{"branch", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"\[Not]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"a", "\[GreaterEqual]", "0"}], "\[And]", RowBox[{"b", "\[GreaterEqual]", "0"}]}], ")"}], "\[Or]", RowBox[{"(", RowBox[{ RowBox[{"a", "<", "0"}], "\[And]", RowBox[{"b", "<", "0"}]}], ")"}]}], ")"}]}]}], "\[IndentingNewLine]", "]"}]], "Input", CellLabel-> "In[151]:=",ExpressionUUID->"2b2bd2eb-3d8d-4035-b36d-c4b279690fc8"], Cell[BoxData["True"], "Output", CellLabel-> "Out[151]=",ExpressionUUID->"59afc716-7a7a-44c6-89b3-9af0cb4611cb"] }, Open ]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Event-B verification checks", "Subsection",ExpressionUUID->"e3185c71-3c80-43ec-8282-576e403e7ec1"], Cell["\<\ All verification checks are demonstrated here in isolation. Realistic models (see below) undergo (and sometimes fail) multiple checks at \ a time.\ \>", "Text",ExpressionUUID->"5c610100-a5ad-476b-b6c6-2d024c34a127"], Cell[CellGroupData[{ Cell["Initialization", "Subsubsection",ExpressionUUID->"e4b28e9a-c4d3-4e96-bcc1-224bfcb00bdf"], Cell["\<\ Check the initial values against invariants - is the initial state legal?\ \>", "Text",ExpressionUUID->"537f7691-096c-4772-9c19-c7e263362af1"], Cell[BoxData[{ RowBox[{ RowBox[{"good", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", " ", "must", " ", "be", " ", "positive"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "\[Rule]", "42"}]}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"and", " ", "it", " ", "is"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"bad", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", " ", "must", " ", "be", " ", "positive"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "\[Rule]", RowBox[{"-", "42"}]}]}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"but", " ", "it", " ", "is", " ", "not"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellChangeTimes->{{3.9083493736622496`*^9, 3.908349453244486*^9}, { 3.908349508005143*^9, 3.9083495124619703`*^9}}, CellLabel-> "In[494]:=",ExpressionUUID->"4e3002aa-ae6a-4e80-bfac-ef23a3a5c369"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", "good", "]"}]], "Input", CellChangeTimes->{{3.9083494577768946`*^9, 3.9083494602129297`*^9}}, CellLabel-> "In[496]:=",ExpressionUUID->"ca5dcad7-f3de-4c77-b4ba-6610d9c278bb"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a base model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[496]:=",ExpressionUUID->"c7a76e85-b60b-4596-ba19-304a919b7b77"], Cell[BoxData["\<\"Validating initial conditions.\"\>"], "Print", CellLabel-> "During evaluation of \ In[496]:=",ExpressionUUID->"b60a6d8f-d719-4e39-9e47-bc77bfa78cb0"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" init consistency: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" init consistency: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[496]:=",ExpressionUUID->"3fd80e57-ba76-48ef-998f-6ee1a219a260"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" ", "inv", ": ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[496]:=",ExpressionUUID->"59e76b65-acb0-486e-bcab-32a5d3fa352e"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[496]:=",ExpressionUUID->"66c9be03-fe77-4f7f-b1b0-f0459b7fee9d"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "2", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 2, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[496]:=",ExpressionUUID->"c791ba7c-8d52-44b4-9412-51babad39c89"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", "bad", "]"}]], "Input", CellLabel-> "In[497]:=",ExpressionUUID->"1ffbb5fa-6992-4c98-a641-40c6537c7e72"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a base model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[497]:=",ExpressionUUID->"395ea023-bf3e-4233-91f0-77d427334b88"], Cell[BoxData["\<\"Validating initial conditions.\"\>"], "Print", CellLabel-> "During evaluation of \ In[497]:=",ExpressionUUID->"f6026619-82e6-42ee-9daf-35dde36dfa30"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" init consistency: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" init consistency: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[497]:=",ExpressionUUID->"0c045ae7-f153-4a43-816b-c762bbc0a299"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]]}], SequenceForm[" ", "inv", ": ", Style[False, Bold, RGBColor[1, 0, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[497]:=",ExpressionUUID->"a4baeb3f-7c0e-456d-8273-1843b35538fd"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[497]:=",ExpressionUUID->"d9889d5b-edfe-46c4-8c05-175eda829e01"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[True, Bold, RGBColor[0, 1, 0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[497]:=",ExpressionUUID->"56d202a1-ea1d-4fcb-b767-4697b750293e"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[False, Bold, RGBColor[1, 0, 0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[497]:=",ExpressionUUID->"a5473c0a-ed18-4194-a574-62dcf8a8edbb"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Guard reachability", "Subsubsection",ExpressionUUID->"ce17ea8c-c24a-4524-8ceb-ed50e68efa7a"], Cell["\<\ Check if the event can be executed at all - that is, if the conditions needed \ by the event guard are possible, even potentially.\ \>", "Text",ExpressionUUID->"2933c507-841d-4b4f-97b1-ed51a07b21ac"], Cell[BoxData[{ RowBox[{ RowBox[{"good", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", " ", "must", " ", "be", " ", "positive"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "<", "42"}], ",", " ", RowBox[{"(*", " ", RowBox[{"it", " ", "might", " ", "happen", " ", "one", " ", "day"}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"bad", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", " ", "must", " ", "be", " ", "positive"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "<", RowBox[{"-", "42"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"it", " ", "can", " ", "never", " ", "happen"}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[498]:=",ExpressionUUID->"f3501a25-c1e5-4d87-bbec-8f1f88f45d9e"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"good", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[500]:=",ExpressionUUID->"60cf9adf-96cf-4502-9152-f7b180734af2"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a base model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[500]:=",ExpressionUUID->"fb98943b-81b9-45c6-9610-17c5015e37bf"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[500]:=",ExpressionUUID->"9d003457-15a3-4179-bdba-550aea228c3c"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard reachable: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" guard reachable: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[500]:=",ExpressionUUID->"596726ec-5636-4b73-8f9d-84ab41cc0853"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[500]:=",ExpressionUUID->"066ea741-4c58-450e-8964-f464c6a4dc4c"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 1, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[500]:=",ExpressionUUID->"5c25e392-df90-4564-bf6c-acb676e61ec6"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"bad", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[501]:=",ExpressionUUID->"8e2afda7-efcf-45bd-b47a-ec094a99b8c2"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a base model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[501]:=",ExpressionUUID->"57ea5a00-98e6-48ae-8047-1aa7daf5b083"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[501]:=",ExpressionUUID->"58736f9c-47c6-4d3a-9fd2-46270f53cc6f"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard reachable: \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]]}], SequenceForm[" guard reachable: ", Style[False, Bold, RGBColor[1, 0, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[501]:=",ExpressionUUID->"c6163b65-d58f-4bcb-b16e-34f6563deedf"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[501]:=",ExpressionUUID->"2bed497c-2279-43c3-a460-3151616adf4b"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]]}], SequenceForm["All ", 1, " ", Style[False, Bold, RGBColor[1, 0, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[501]:=",ExpressionUUID->"4e189417-b993-4e95-88a6-b67c94204e68"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Invariant preservation", "Subsubsection",ExpressionUUID->"f608dfde-22bd-4ca8-b113-741225ede866"], Cell["\<\ Check if the event actions leave the system in a state that is still legal \ with regard to invariants.\ \>", "Text",ExpressionUUID->"acbf0686-afe9-41a5-96cf-fba50c23ec7d"], Cell[BoxData[{ RowBox[{ RowBox[{"good", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", " ", "must", " ", "be", " ", "positive"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", "42"}]}], " ", RowBox[{"(*", " ", RowBox[{"still", " ", "OK"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"bad", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", " ", "must", " ", "be", " ", "positive"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", RowBox[{"-", "42"}]}]}], " ", RowBox[{"(*", " ", RowBox[{"not", " ", "OK"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellChangeTimes->{{3.90834972856168*^9, 3.908349867341135*^9}, { 3.9083499055535917`*^9, 3.908349906502142*^9}, {3.9083502522696075`*^9, 3.9083502753487253`*^9}, {3.9083521277312098`*^9, 3.908352145342888*^9}, { 3.9083521994248595`*^9, 3.908352205570177*^9}}, CellLabel-> "In[502]:=",ExpressionUUID->"790efd7c-778b-4d14-aba5-904be5c33dac"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"good", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellChangeTimes->{{3.908350288693997*^9, 3.9083503120685573`*^9}}, CellLabel-> "In[504]:=",ExpressionUUID->"0c1a8fb3-65da-4626-8357-97977e566f5f"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a base model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[504]:=",ExpressionUUID->"35deb9ab-a6bb-4f60-965a-77b5dac91647"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[504]:=",ExpressionUUID->"5d78e770-b552-4c25-afed-33acb2109154"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" ", "inv", ": ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[504]:=",ExpressionUUID->"a16b5674-345f-4b0e-9bb9-040fc90f381e"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[504]:=",ExpressionUUID->"759f0bc2-0174-4ca0-9daf-8b200603b3e9"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 1, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[504]:=",ExpressionUUID->"0fb5f512-3859-4399-967a-e304d5ee7aaf"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"bad", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellChangeTimes->{{3.908350323097201*^9, 3.9083503232526665`*^9}, { 3.908351932013039*^9, 3.908351934550606*^9}, 3.908352119132809*^9}, CellLabel-> "In[505]:=",ExpressionUUID->"67fe0d93-6aa7-40af-8d0e-ee08e1fd611e"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a base model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[505]:=",ExpressionUUID->"33314caa-8f0d-4134-b503-d866aa6dfc60"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[505]:=",ExpressionUUID->"f69aa904-cde5-4e45-a773-676998e8d5b8"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm[" ", "inv", ": ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[505]:=",ExpressionUUID->"506a82c9-cfd1-49f1-947a-6f0ddd914c8e"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[505]:=",ExpressionUUID->"7817875c-1c58-4ae5-98e6-75f46696d8fe"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm["All ", 1, " ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[505]:=",ExpressionUUID->"f70589e6-dc70-46be-af1a-ac9185343d40"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Deadlock freedom", "Subsubsection",ExpressionUUID->"41bac25f-9322-4917-b6e4-1028ed01a6cf"], Cell["\<\ Check if, assuming invariants, any of the events can take place. This is \ similar to guard reachability, but considers all events at once, not each of \ them in isolation.\[LineSeparator]The deadlock freedom check is optional \ (because it does not make sense in all systems) and has to be requested in \ the model by a separate flag.\ \>", "Text", CellChangeTimes->{ 3.972116501391281*^9},ExpressionUUID->"9a9f874a-231f-4f69-a635-\ a48f916ac82c"], Cell[BoxData[{ RowBox[{ RowBox[{"good", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "<", "42"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", ">=", "42"}], ",", " ", RowBox[{"(*", " ", RowBox[{"OK", ",", " ", RowBox[{ "together", " ", "with", " ", "ev1", " ", "all", " ", "possible", " ", "states", " ", "are", " ", "covered"}]}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], " ", RowBox[{"(*", " ", RowBox[{ "this", " ", "is", " ", "how", " ", "the", " ", "deadlock", " ", "check", " ", "is", " ", "switched", " ", "on"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"bad", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "<", "42"}], ",", " ", RowBox[{"(*", " ", RowBox[{"oops", "..."}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", ">", "42"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"...", "oops"}], ",", " ", RowBox[{ RowBox[{"what", " ", "if", " ", "a"}], "\[Equal]", RowBox[{"42", "?"}]}]}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], " ", RowBox[{"(*", " ", RowBox[{ "this", " ", "is", " ", "how", " ", "the", " ", "deadlock", " ", "check", " ", "is", " ", "switched", " ", "on"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[506]:=",ExpressionUUID->"bf70dc8a-02e8-40a4-aa2b-4fd5fb34cd44"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"good", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[508]:=",ExpressionUUID->"e94cab11-835d-4012-91e4-31b4a7057f65"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a base model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[508]:=",ExpressionUUID->"c6d7a57d-172b-492e-bee6-3ea9639749a7"], Cell[BoxData["\<\"Validating deadlock freedom.\"\>"], "Print", CellLabel-> "During evaluation of \ In[508]:=",ExpressionUUID->"2fa32dd1-55e9-41cc-964f-317948a37d0e"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" deadlock freedom: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" deadlock freedom: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[508]:=",ExpressionUUID->"4e8eefd3-f28e-4156-b75b-963192f7831e"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[508]:=",ExpressionUUID->"820b9d98-b702-4b93-b134-0ac12dca3be7"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 1, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[508]:=",ExpressionUUID->"cb099fd7-6cb1-495f-8b6d-df4dff821228"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"bad", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[509]:=",ExpressionUUID->"c708d7e9-27e6-4880-993f-4f86f9c93dac"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a base model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[509]:=",ExpressionUUID->"4406416d-be1c-406c-8d05-c7ffdcb931ed"], Cell[BoxData["\<\"Validating deadlock freedom.\"\>"], "Print", CellLabel-> "During evaluation of \ In[509]:=",ExpressionUUID->"60493b1f-667e-4968-b15c-5c6d38c2ba52"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" deadlock freedom: \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm[" deadlock freedom: ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[509]:=",ExpressionUUID->"77cb453a-e55f-4816-a27f-ddcc3955f559"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[509]:=",ExpressionUUID->"b541a10f-b503-4e95-a0b9-93ef7a64dc54"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm["All ", 1, " ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[509]:=",ExpressionUUID->"f3b6da20-bfe1-4ac6-9879-1f06cf64061a"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Initialization refinement", "Subsubsection",ExpressionUUID->"e7e7119f-7183-4fcf-803a-8f276fbaf81e"], Cell["\<\ This applies to refined models.\[LineSeparator]New initializations cannot \ conflict with base model. Base initializations cannot conflict with new \ invariants, even if they were correct in the base model.\ \>", "Text",ExpressionUUID->"a571d115-ca99-4bba-8b09-12c163ed72d2"], Cell[BoxData[{ RowBox[{ RowBox[{"base", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", " ", "must", " ", "be", " ", "positive"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "\[Rule]", "42"}]}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"and", " ", "it", " ", "is"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"goodRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "10"}]}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"OK", ",", " ", RowBox[{"more", " ", "constrained"}], ",", " ", RowBox[{ "but", " ", "base", " ", "inits", " ", "are", " ", "still", " ", "OK"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"badRefinement1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "100"}]}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"oops", ",", " ", RowBox[{ "the", " ", "base", " ", "initial", " ", "state", " ", "does", " ", "not", " ", "fit", " ", "any", " ", "more"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"badRefinement2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "\[Rule]", "7"}]}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"oops", ",", " ", RowBox[{ "incompatible", " ", "with", " ", "base", " ", "initialization"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[510]:=",ExpressionUUID->"1d90028c-248a-461f-8961-8a6d658ff301"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"goodRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[514]:=",ExpressionUUID->"d7a8f476-5851-4504-b2a0-4e2e3e07713a"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[514]:=",ExpressionUUID->"1733a05f-8b5e-417d-a44d-30b829401123"], Cell[BoxData["\<\"Validating initial conditions.\"\>"], "Print", CellLabel-> "During evaluation of \ In[514]:=",ExpressionUUID->"61695b9f-db1e-4de8-8585-37d293852b1f"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" init consistency: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" init consistency: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[514]:=",ExpressionUUID->"80c639b0-07b5-48a4-bcd5-f1f9d0e214c8"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv1\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" ", "inv1", ": ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[514]:=",ExpressionUUID->"5b87005b-c508-4963-95a9-d14d0c4d89e6"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[514]:=",ExpressionUUID->"3c4c33b1-df60-4f3e-ab56-9efe5f3a85c3"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "2", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 2, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[514]:=",ExpressionUUID->"df8bcb28-e6e0-4de9-9591-71a3a93e4dcd"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"badRefinement1", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[515]:=",ExpressionUUID->"7a27433a-5672-4048-9c41-4d018601ca46"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[515]:=",ExpressionUUID->"8979ad7f-71a3-4de3-9a76-c955a12721e1"], Cell[BoxData["\<\"Validating initial conditions.\"\>"], "Print", CellLabel-> "During evaluation of \ In[515]:=",ExpressionUUID->"dfb74c63-ee12-4f01-ae5f-95741883bed8"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" init consistency: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" init consistency: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[515]:=",ExpressionUUID->"42d24845-3626-4f1a-9c4d-d77f2d229b25"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv1\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]]}], SequenceForm[" ", "inv1", ": ", Style[False, Bold, RGBColor[1, 0, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[515]:=",ExpressionUUID->"920c98da-9a81-4da5-b57a-f71044853b48"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[515]:=",ExpressionUUID->"191877f5-aa30-4b23-b3b5-0eae9a272eee"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[True, Bold, RGBColor[0, 1, 0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[515]:=",ExpressionUUID->"07b6803f-df28-4a19-bfc2-401d21e6ad62"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[False, Bold, RGBColor[1, 0, 0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[515]:=",ExpressionUUID->"24f901b7-9ccc-4a51-9511-91108cafabf9"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"badRefinement2", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[516]:=",ExpressionUUID->"4015d46f-cb0c-44ba-aefb-d693da9cdda4"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[516]:=",ExpressionUUID->"a2fe01c8-f89f-444c-87b6-32a6ce32d8e9"], Cell[BoxData["\<\"Validating initial conditions.\"\>"], "Print", CellLabel-> "During evaluation of \ In[516]:=",ExpressionUUID->"c3e859f0-3945-446f-a733-c6701b9ec960"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" init consistency: \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]]}], SequenceForm[" init consistency: ", Style[False, Bold, RGBColor[1, 0, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[516]:=",ExpressionUUID->"c4f4fba0-1af1-4071-be2f-4de1945ba8c3"], Cell[BoxData["\<\" No invariants to check.\"\>"], "Print", CellLabel-> "During evaluation of \ In[516]:=",ExpressionUUID->"5851a134-42e4-434c-ac75-038360561ad7"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[516]:=",ExpressionUUID->"abd8824a-762f-44a0-9a35-14938c072691"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]]}], SequenceForm["All ", 1, " ", Style[False, Bold, RGBColor[1, 0, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[516]:=",ExpressionUUID->"bdf1ca9c-6742-4aa3-b4cf-d1dcacc0ce34"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Refined guard reachability", "Subsubsection",ExpressionUUID->"6c9538f5-957f-474f-8d19-02a4b3f35ade"], Cell["\<\ This applies to refined models.\[LineSeparator]The refined guard can be \ stronger than the base one, but it still needs to be potentially reachable.\ \>", "Text",ExpressionUUID->"39b3e9a5-f520-46ba-9949-b51d08a3e86a"], Cell[BoxData[{ RowBox[{ RowBox[{"base", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", " ", "must", " ", "be", " ", "positive"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "<", "42"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"goodRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "<", "10"}], ",", " ", RowBox[{"(*", " ", RowBox[{"OK", ",", " ", RowBox[{ "stronger", " ", "than", " ", "in", " ", "base", " ", "model"}], ",", " ", RowBox[{"but", " ", "still", " ", "possible"}]}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"badRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "<", RowBox[{"-", "10"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"oops", ",", " ", RowBox[{ "stronger", " ", "than", " ", "in", " ", "base", " ", "model", " ", "and", " ", "impossible", " ", "to", " ", "satisfy"}]}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[517]:=",ExpressionUUID->"fe1c8b0d-2952-4916-b270-d046fcf54fcb"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"goodRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[520]:=",ExpressionUUID->"8a5ddf52-967b-47a7-aac7-5b52aa7fed40"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[520]:=",ExpressionUUID->"d78e6812-8cf8-41ad-ba19-79d73bea5c62"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[520]:=",ExpressionUUID->"bbdb5c74-2176-4e56-92a6-bb3ac539e4ee"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard reachable: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" guard reachable: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[520]:=",ExpressionUUID->"cf92463f-5bb9-4c9f-bddf-412a9f6f8800"], Cell[BoxData["\<\" This is a refining event.\"\>"], "Print", CellLabel-> "During evaluation of \ In[520]:=",ExpressionUUID->"a5ee3be5-0b3d-4cbd-95b2-997556226ca0"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard and promise strengthening: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" guard and promise strengthening: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[520]:=",ExpressionUUID->"957dae37-f0c1-4edf-84a6-4f81307db271"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[520]:=",ExpressionUUID->"22cd4d35-50f8-4c34-b456-0b954c4fffed"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "2", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 2, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[520]:=",ExpressionUUID->"2b110ad0-4c57-4e4d-9d0c-d8d996254970"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"badRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[521]:=",ExpressionUUID->"f50acbc6-2447-4dd0-858e-7f286cbe6116"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[521]:=",ExpressionUUID->"a998d982-217a-43e7-85a7-1ee4b1bb1bea"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[521]:=",ExpressionUUID->"28c82e39-3905-4b3c-a1c7-ce86e34ed437"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard reachable: \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]]}], SequenceForm[" guard reachable: ", Style[False, Bold, RGBColor[1, 0, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[521]:=",ExpressionUUID->"f208917d-fbd6-4722-b09d-b94881390fc5"], Cell[BoxData["\<\" This is a refining event.\"\>"], "Print", CellLabel-> "During evaluation of \ In[521]:=",ExpressionUUID->"2f9624e8-605b-48af-90fc-a1ac81a86ba9"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard and promise strengthening: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" guard and promise strengthening: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[521]:=",ExpressionUUID->"45c3047d-0bb8-451c-b09d-0035d7d424d2"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[521]:=",ExpressionUUID->"0885abf0-1e0c-49a0-85c5-d5857dc522a9"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[False, Bold, RGBColor[1, 0, 0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[521]:=",ExpressionUUID->"8c880c88-4585-43e9-9e26-3df83f78f5c0"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[True, Bold, RGBColor[0, 1, 0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[521]:=",ExpressionUUID->"3e11dcc9-5bbc-43e3-ad8b-ef813a40e66e"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Refined guard strengthening", "Subsubsection",ExpressionUUID->"31e43d5d-f815-4c8e-a5e6-d1486c425e08"], Cell["\<\ This check applies to refined models.\[LineSeparator]The refined guard can be \ stronger than the base one, but not looser.\ \>", "Text",ExpressionUUID->"90399a13-3b01-4a29-a0c7-7669012d47f7"], Cell[BoxData[{ RowBox[{ RowBox[{"base", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "<", "42"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"goodRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "<", "10"}], ",", " ", RowBox[{"(*", " ", RowBox[{"OK", ",", " ", RowBox[{ "stronger", " ", "than", " ", "in", " ", "base", " ", "model"}]}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"badRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "<", "100"}], ",", " ", RowBox[{"(*", " ", RowBox[{"oops", ",", " ", RowBox[{ "looser", " ", "than", " ", "in", " ", "base", " ", "model"}]}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[522]:=",ExpressionUUID->"c0aeb3c8-cf2e-46f3-abe0-b6d45d2310c6"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"goodRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[525]:=",ExpressionUUID->"5b01e5c1-8603-4cba-a973-6e7495538560"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[525]:=",ExpressionUUID->"43d8c48c-3ca5-417d-a91a-bb64313b2a5a"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[525]:=",ExpressionUUID->"3e70ee1c-eb5b-4d52-bfa1-3bd52f29f727"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard reachable: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" guard reachable: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[525]:=",ExpressionUUID->"c09e9f8f-3739-49c1-af5c-56ccc21e241d"], Cell[BoxData["\<\" This is a refining event.\"\>"], "Print", CellLabel-> "During evaluation of \ In[525]:=",ExpressionUUID->"cffa81bf-3b15-41f6-b55e-f2c0eb2bdd1b"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard and promise strengthening: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" guard and promise strengthening: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[525]:=",ExpressionUUID->"39d78a05-380c-4ea5-a9b0-93c59da8b728"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[525]:=",ExpressionUUID->"b67e3d1e-0aad-498e-a106-206151f82a48"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "2", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 2, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[525]:=",ExpressionUUID->"5ab1bff2-5298-4359-9131-4f4b2dce7ebd"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"badRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[526]:=",ExpressionUUID->"c95b019c-0302-4818-ba59-d6f0ea69d7ba"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[526]:=",ExpressionUUID->"4b446d7e-6478-49f8-bee0-9356a3b1edb9"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[526]:=",ExpressionUUID->"fab4c39d-41c6-49fc-868d-e0ca9a2347e5"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard reachable: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" guard reachable: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[526]:=",ExpressionUUID->"e7e3b5b9-9456-4148-97f1-eecdeb4ff478"], Cell[BoxData["\<\" This is a refining event.\"\>"], "Print", CellLabel-> "During evaluation of \ In[526]:=",ExpressionUUID->"cfb57f27-019c-4619-917e-1d10c9362a92"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard and promise strengthening: \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm[" guard and promise strengthening: ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[526]:=",ExpressionUUID->"583827fe-18f4-4ae9-8482-58e2b1c05555"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[526]:=",ExpressionUUID->"a503c163-bc06-49da-9549-46033aa307a2"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[True, Bold, RGBColor[0, 1, 0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[526]:=",ExpressionUUID->"464aa877-3cb6-4790-95f0-d1dd1fbed9a7"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[Indeterminate, Bold, GrayLevel[0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[526]:=",ExpressionUUID->"894d7c46-a6dd-435f-a7ae-1b22fc3ea31a"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Refined promise strengthening", "Subsubsection",ExpressionUUID->"b0c0a588-5c05-4b1b-80b3-70f9192ddf13"], Cell["\<\ This check applies to refined models and is done together with guard check.\ \[LineSeparator]The refined promise can be stronger than the base one, but \ not looser.\ \>", "Text",ExpressionUUID->"273d518b-3a66-499c-a960-7c8eb7494236"], Cell[BoxData[{ RowBox[{ RowBox[{"base", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "42"}]}], "]"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"goodRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "100"}]}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"OK", ",", " ", RowBox[{"stronger", " ", "promise"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"badRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "10"}]}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"oops", ",", " ", RowBox[{"looser", " ", "promise"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[527]:=",ExpressionUUID->"ccd4d57b-acae-4d40-929a-44c3db9287a6"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"goodRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[530]:=",ExpressionUUID->"a15c1a40-662c-4456-a52d-7004d52ea12d"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[530]:=",ExpressionUUID->"a95bf436-38a8-4519-94eb-8f4d8fbcf47b"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[530]:=",ExpressionUUID->"94e26808-66fe-404a-9f5c-cdb8e3481f64"], Cell[BoxData["\<\" This is a refining event.\"\>"], "Print", CellLabel-> "During evaluation of \ In[530]:=",ExpressionUUID->"7a8d2e41-9fb7-41ca-acd3-90670431fea8"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard and promise strengthening: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" guard and promise strengthening: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[530]:=",ExpressionUUID->"c7755f88-e629-431e-9ebe-ea63cdf4a780"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[530]:=",ExpressionUUID->"a87b84af-b9c4-4513-9a79-26932ac93565"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 1, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[530]:=",ExpressionUUID->"c630e224-b130-4563-b7fe-8cbdc56c41f4"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"badRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[531]:=",ExpressionUUID->"c96e3c38-0cdb-4184-9bbc-b63fa60e955d"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[531]:=",ExpressionUUID->"12426133-e0da-4ca4-9c90-64cfb7b45cb9"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[531]:=",ExpressionUUID->"3ec3d4aa-796e-41b6-95f3-22288c35630a"], Cell[BoxData["\<\" This is a refining event.\"\>"], "Print", CellLabel-> "During evaluation of \ In[531]:=",ExpressionUUID->"b441d1b3-73ab-454f-ae20-b8f1bc092fd5"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard and promise strengthening: \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm[" guard and promise strengthening: ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[531]:=",ExpressionUUID->"06ea4e7e-5ed7-4e8f-9e33-aa883a4c745f"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[531]:=",ExpressionUUID->"71c37899-3906-4144-8906-6024e9afea4d"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm["All ", 1, " ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[531]:=",ExpressionUUID->"7bdeadef-a18d-4fab-8ccc-c113ef021ce4"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Merging guard strengthening", "Subsubsection",ExpressionUUID->"3d2ff949-e9a5-457e-9428-77983f68d963"], Cell["\<\ This check applies to refined models, where new event refines multiple events \ from the base model.\[LineSeparator]The refined guard can be stronger than \ the disjunction of base ones, but not looser.\ \>", "Text",ExpressionUUID->"c8197584-dc64-46ba-b96c-ee2d00cf4b38"], Cell[BoxData[{ RowBox[{ RowBox[{"base", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "a", "<", "42"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"42", "<=", "a", "<", "100"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"goodRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "merges", " ", "two", " ", "events", " ", "from", " ", "base", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "a", "<", "100"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "same", " ", "or", " ", "stronger", " ", "than", " ", "both", " ", "bases", " ", "together"}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"badRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "merges", " ", "two", " ", "events", " ", "from", " ", "base", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "a", "<=", "100"}], ",", " ", RowBox[{"(*", " ", RowBox[{"oops", ",", " ", RowBox[{ "100", " ", "is", " ", "not", " ", "covered", " ", "by", " ", "any", " ", "of", " ", "the", " ", "base", " ", "events"}]}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[532]:=",ExpressionUUID->"71bc1ac2-f451-4b27-a6bb-17facf095cd3"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"goodRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[535]:=",ExpressionUUID->"89af1eb4-a5af-4daf-a45d-4faa306910e4"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[535]:=",ExpressionUUID->"6b3091b1-aa5e-4935-97dc-06a0fe6c064d"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev3\"\>"}], SequenceForm["Validating event ", "ev3"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[535]:=",ExpressionUUID->"66bf1f20-0021-42e8-aed7-0a22d36f8896"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard reachable: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" guard reachable: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[535]:=",ExpressionUUID->"f9ebf6bb-ed65-4363-8bd5-a4c6c1266429"], Cell[BoxData["\<\" This is a merging event.\"\>"], "Print", CellLabel-> "During evaluation of \ In[535]:=",ExpressionUUID->"f3688e67-976c-4b17-a8f7-00b1b67fb794"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard and promise strengthening: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" guard and promise strengthening: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[535]:=",ExpressionUUID->"74615dbd-6129-4214-a69c-c11e036a3303"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[535]:=",ExpressionUUID->"51e19a13-86e8-43cd-8be6-2c37ab5e7573"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "2", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 2, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[535]:=",ExpressionUUID->"c2a59d18-1f88-4d6f-b453-42c70db67b44"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"badRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[536]:=",ExpressionUUID->"933bd681-7ec5-4557-99a6-fafb66f3b8b3"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[536]:=",ExpressionUUID->"7f8c2b45-68d5-429d-93b2-040423af1a28"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev3\"\>"}], SequenceForm["Validating event ", "ev3"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[536]:=",ExpressionUUID->"613c9524-bb87-4155-94b5-cb897f7efe16"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard reachable: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" guard reachable: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[536]:=",ExpressionUUID->"706c50fb-0ff6-43b9-8cbb-94592c05df14"], Cell[BoxData["\<\" This is a merging event.\"\>"], "Print", CellLabel-> "During evaluation of \ In[536]:=",ExpressionUUID->"521c2170-4c7e-4a9a-969f-0320c2e7d2c4"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" guard and promise strengthening: \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm[" guard and promise strengthening: ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[536]:=",ExpressionUUID->"65c640cb-fd20-458a-b3d2-dd535aee5e7d"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[536]:=",ExpressionUUID->"0a01baeb-4b90-40cd-9d24-8d0b289299a0"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[True, Bold, RGBColor[0, 1, 0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[536]:=",ExpressionUUID->"26323ee6-ef4c-42ac-8f0e-7bc5851c9ce2"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[Indeterminate, Bold, GrayLevel[0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[536]:=",ExpressionUUID->"79c8af29-6d82-4978-9ae4-1a14246b17ac"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Invariant compatibility", "Subsubsection",ExpressionUUID->"a8b9dcc6-4916-4360-a5ab-a7a6ad3f8014"], Cell["\<\ This applies to refined models.\[LineSeparator]Actions from base events have \ to be compatible with new invariants and actions from refined events have to \ be compatible with both base and new invariants.\ \>", "Text",ExpressionUUID->"679d7406-4c26-4b2b-be34-79b8e952c373"], Cell[BoxData[{ RowBox[{ RowBox[{"base", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"a", " ", "must", " ", "be", " ", "positive"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"b", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"b", " ", "must", " ", "be", " ", "positive"}], ",", " ", "too"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", "42"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"goodRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "<", "100"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"together", " ", "with", " ", "inv1"}], ",", " ", RowBox[{"0", " ", "<", " ", "a", " ", "<", " ", "100"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"b", "\[Rule]", "42"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"badRefinement1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "<", "10"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"oops", ",", " ", RowBox[{"together", " ", "with", " ", "inv1"}], ",", " ", RowBox[{"0", " ", "<", " ", "a", " ", "<", " ", "10"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"b", "\[Rule]", "42"}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"this", " ", "is", " ", "OK"}], ",", " ", RowBox[{ "but", " ", "base", " ", "action", " ", "now", " ", "does", " ", "not", " ", "fit", " ", "inv3"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"badRefinement2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"b", "\[Rule]", RowBox[{"-", "42"}]}]}], " ", RowBox[{"(*", " ", RowBox[{"oops", ",", " ", RowBox[{ "conflicts", " ", "with", " ", "inv2", " ", "in", " ", "base"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[537]:=",ExpressionUUID->"460b9c74-57df-408e-9e57-71ee7a42a67a"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"goodRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[541]:=",ExpressionUUID->"685dc07e-f967-4b1e-8cb2-80dc3490156f"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[541]:=",ExpressionUUID->"2f88f48e-bcfa-4cf4-802f-770beef274dc"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[541]:=",ExpressionUUID->"dd83a3fa-30e4-4016-a404-3cf84ca2d399"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv1\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" ", "inv1", ": ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[541]:=",ExpressionUUID->"24356ccb-1c41-4b0b-97ec-257da86b74d5"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv2\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" ", "inv2", ": ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[541]:=",ExpressionUUID->"71127bf1-5c52-4e11-aee7-73e23dc942a8"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv3\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" ", "inv3", ": ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[541]:=",ExpressionUUID->"96c4f91d-58f2-413e-a7c2-336292cd43d7"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[541]:=",ExpressionUUID->"88df8b0f-27ac-473a-a048-2a8a0b9775c8"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "3", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 3, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[541]:=",ExpressionUUID->"602fec27-1485-4bbc-9850-e6cd8bcebcd3"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"badRefinement1", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[542]:=",ExpressionUUID->"e81de24e-c3a1-4021-b55c-3163de906027"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[542]:=",ExpressionUUID->"d7ea675c-5bff-4160-8442-e784ac0daa61"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[542]:=",ExpressionUUID->"014bc722-4304-491b-aa05-2dedeff24527"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv1\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" ", "inv1", ": ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[542]:=",ExpressionUUID->"bb536e75-8687-4620-a820-48108fb2548d"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv2\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" ", "inv2", ": ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[542]:=",ExpressionUUID->"61b0a728-e2db-4ef1-8766-370648e09ecb"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv3\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm[" ", "inv3", ": ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[542]:=",ExpressionUUID->"5025128f-1aa0-43da-a163-a714c0d67e9a"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[542]:=",ExpressionUUID->"3ac42fc8-288d-484b-91f4-1ae636982ec4"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "2"}], SequenceForm[" ", Style[True, Bold, RGBColor[0, 1, 0]], " ", 2], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[542]:=",ExpressionUUID->"7a9f90ac-4793-4868-885a-9137a3a87d0c"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[Indeterminate, Bold, GrayLevel[0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[542]:=",ExpressionUUID->"9c8b5507-ea05-4a9d-a9fc-90c416672245"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"badRefinement2", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[543]:=",ExpressionUUID->"661f6a34-026f-4472-945c-48b3ec370382"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[543]:=",ExpressionUUID->"b9e69641-fb48-44b2-86f6-d8a45b5a828d"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[543]:=",ExpressionUUID->"2dc7ec82-f578-4717-a029-fc20b1e9ab1b"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv1\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" ", "inv1", ": ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[543]:=",ExpressionUUID->"c36bf53a-b965-4175-a378-a0daa513f703"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", "\<\"inv2\"\>", "\[InvisibleSpace]", "\<\": \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm[" ", "inv2", ": ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[543]:=",ExpressionUUID->"620db8d9-c728-4060-8f92-8595e442fafd"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[543]:=",ExpressionUUID->"0fb0e4d9-596d-49f1-b827-584318996a7f"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[True, Bold, RGBColor[0, 1, 0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[543]:=",ExpressionUUID->"e8a2e1e2-ff4d-44e9-b5db-54ac04f5a105"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]], "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", "1"}], SequenceForm[" ", Style[Indeterminate, Bold, GrayLevel[0]], " ", 1], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[543]:=",ExpressionUUID->"ba2d75b7-b745-4914-b07c-f62e4c71d8ce"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["State superposition", "Subsubsection",ExpressionUUID->"cfd24bf3-f40f-435a-9985-7c167df9be86"], Cell["\<\ This applies to refined models.\[LineSeparator]Actions from base and refining \ events have to be compatible with regard to modifications of the same \ variables.\ \>", "Text",ExpressionUUID->"b3e8e07c-6089-4c82-9daf-1eebac743e06"], Cell[BoxData[{ RowBox[{ RowBox[{"base", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Rule]", "42"}], ",", "\[IndentingNewLine]", RowBox[{"b", "\[Rule]", "10"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"goodRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "\[Rule]", "10"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "modification", " ", "that", " ", "is", " ", "common", " ", "for", " ", "both", " ", "base", " ", "and", " ", "refining", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"c", "\[Rule]", "100"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"badRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "\[Rule]", "12"}], ",", " ", RowBox[{"(*", " ", RowBox[{"oops", ",", " ", RowBox[{"incompatible", " ", "modification"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"c", "\[Rule]", "100"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[544]:=",ExpressionUUID->"9727de61-18c7-4fb9-8602-4d4558b362f2"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"goodRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[547]:=",ExpressionUUID->"96a46f1d-d37f-4574-afc0-8b3a9daaaa64"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[547]:=",ExpressionUUID->"09168521-a380-4aa4-aa3d-08c1a19baa4e"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[547]:=",ExpressionUUID->"0d3cdecd-e97f-4c05-83c6-564508635ee2"], Cell[BoxData["\<\" This is a refining event.\"\>"], "Print", CellLabel-> "During evaluation of \ In[547]:=",ExpressionUUID->"16ab25a9-14ca-4bc5-bcd4-783f6de4e24c"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" state superposition: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" state superposition: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[547]:=",ExpressionUUID->"f77e33b1-049d-4114-b8e9-ca02fc22e5a0"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[547]:=",ExpressionUUID->"cd66f6de-a00a-474a-afef-986d37e1ad42"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 1, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[547]:=",ExpressionUUID->"86b8eec2-4e3d-471b-ba17-4004cf218eee"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"badRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[548]:=",ExpressionUUID->"39a8a5e7-2606-4cb6-93ea-12a2caf0e325"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[548]:=",ExpressionUUID->"98fa90e0-6d10-49a8-9cfa-919f72cbfbb0"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[548]:=",ExpressionUUID->"7c59b313-bc41-4dd4-b8c1-6c34ff86ee41"], Cell[BoxData["\<\" This is a refining event.\"\>"], "Print", CellLabel-> "During evaluation of \ In[548]:=",ExpressionUUID->"dd66754d-8eb0-40be-9ee6-3d37c136d5ea"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" state superposition: \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]]}], SequenceForm[" state superposition: ", Style[False, Bold, RGBColor[1, 0, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[548]:=",ExpressionUUID->"cf2d6960-94bb-4007-98e9-caa3763a4cbc"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[548]:=",ExpressionUUID->"3d863e58-3a76-4a08-b6f5-1977b59fb821"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]]}], SequenceForm["All ", 1, " ", Style[False, Bold, RGBColor[1, 0, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[548]:=",ExpressionUUID->"a08df440-b455-469d-83fc-e81023ef5706"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["State superposition over base promise", "Subsubsection",ExpressionUUID->"ff141f26-7c58-4df9-8f23-92dbee95269b"], Cell["\<\ This applies to refined models.\[LineSeparator]Actions have to be compatible \ also with promises from base model, if the promise disappears in concrete \ event.\ \>", "Text",ExpressionUUID->"f349766d-96ec-41af-91ae-4e38b2fd0968"], Cell[BoxData[{ RowBox[{ RowBox[{"base", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"a", ">", "42"}]}], "]"}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"abstract", " ", "promise", " ", "that", " ", "a"}], " ", ">", " ", "42"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"goodRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "\[Rule]", "100"}]}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"OK", ",", " ", RowBox[{ "concrete", " ", "action", " ", "fits", " ", "the", " ", "base", " ", "promise"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"badRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "\[Rule]", "10"}]}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"oops", ",", " ", RowBox[{ "concrete", " ", "action", " ", "does", " ", "not", " ", "fit", " ", "the", " ", "base", " ", "promise"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[549]:=",ExpressionUUID->"bcf17464-4d85-4800-8ade-ea23c0c981ab"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"goodRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[552]:=",ExpressionUUID->"dd3b3476-6785-4223-a715-2bd5bd46a9e5"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[552]:=",ExpressionUUID->"5795adfc-ebac-44dc-9db0-5a62886426d4"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[552]:=",ExpressionUUID->"54b7ee33-c5e6-4782-b344-938cb642cbc4"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" state superposition: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" state superposition: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[552]:=",ExpressionUUID->"d9baf557-f71e-46a1-adcc-06af06a8d6e5"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[552]:=",ExpressionUUID->"50eb465a-76d9-4c4c-94b0-05d756b3eb2a"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 1, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[552]:=",ExpressionUUID->"130db781-699e-4d6a-8f24-51877ed716e6"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"badRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellLabel-> "In[553]:=",ExpressionUUID->"09f3053d-4298-48d7-9682-2cb9f39133e2"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[553]:=",ExpressionUUID->"ebb3867e-adfa-433e-b1eb-92ef2d6cba85"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[553]:=",ExpressionUUID->"0575806d-2952-4a94-a963-4c7e8a686134"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" state superposition: \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]]}], SequenceForm[" state superposition: ", Style[False, Bold, RGBColor[1, 0, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[553]:=",ExpressionUUID->"7b981bd5-52df-4bfc-9a62-b69db8afe133"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[553]:=",ExpressionUUID->"d36d8d13-925f-4c30-a166-915d17e70791"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["False", StripOnInput->False, LineColor->RGBColor[1, 0, 0], FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontWeight->Bold, FontColor->RGBColor[1, 0, 0]]}], SequenceForm["All ", 1, " ", Style[False, Bold, RGBColor[1, 0, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[553]:=",ExpressionUUID->"d41f0497-0ffd-4647-a716-ccf4b77ff31d"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Event convergence", "Subsubsection",ExpressionUUID->"9f1eb617-e027-4c28-afba-99b1ec0e449a"], Cell["\<\ This applies to refined models.\[LineSeparator]New events that do not refine \ events from base model, should not starve existing events by \ \[OpenCurlyDoubleQuote]executing\[CloseCurlyDoubleQuote] forever - variants \ need to be used to demonstrate that the execution sequence of new events is \ limited.\ \>", "Text",ExpressionUUID->"4906f172-01d8-4b39-b0a3-fe561417177f"], Cell[BoxData[{ RowBox[{ RowBox[{"base", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "Null"}], "]"}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"goodRefinement1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Element]", "Integers"}], ",", RowBox[{"a", "<=", "10"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"b", "\[Element]", "Integers"}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"10", "-", "a"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "this", " ", "expression", " ", "decreases", " ", "when", " ", "ev1", " ", "executes"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ "this", " ", "new", " ", "event", " ", "is", " ", "implicitly", " ", "convergent"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "<", "10"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ "this", " ", "new", " ", "event", " ", "has", " ", "no", " ", "impact", " ", "on", " ", "\"\\"", " ", RowBox[{"(", RowBox[{"and", " ", "on", " ", "variant"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", "anticipated", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"b", "<", "100"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"b", "->", RowBox[{"b", "+", "1"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"badRefinement", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", ">", "10"}], ",", " ", RowBox[{"(*", " ", RowBox[{"oops", ",", " ", RowBox[{"this", " ", "might", " ", "run", " ", "forever"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"goodRefinement2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "base", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "we", " ", "explicitly", " ", "say", " ", "it", " ", "is", " ", "acceptable"}], " ", "..."}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", ">", "10"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "...", " ", "for", " ", "this", " ", "to", " ", "run", " ", "forever"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellChangeTimes->{{3.971328328189562*^9, 3.9713283569098415`*^9}},ExpressionUUID->"a2174f78-55e6-4649-913e-\ be8c800b2450"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"goodRefinement1", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input",\ CellLabel-> "In[558]:=",ExpressionUUID->"caaa0c16-719d-4c12-be10-6d077dc225ea"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[558]:=",ExpressionUUID->"1dc47704-eaac-4040-9966-fc2342396268"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev1\"\>"}], SequenceForm["Validating event ", "ev1"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[558]:=",ExpressionUUID->"01360058-00e7-42fd-9cf8-3bd21c4125ae"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" variant limited: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" variant limited: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[558]:=",ExpressionUUID->"337275cc-007b-4045-b882-2bfebbbe398b"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" variant monotonic: \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm[" variant monotonic: ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[558]:=",ExpressionUUID->"6b2d9e39-bc6f-42d0-ba34-b7a629349ae7"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[558]:=",ExpressionUUID->"0b52856b-c783-474a-9ea6-150320a8119c"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[558]:=",ExpressionUUID->"61def6bf-77a3-47a1-bfbe-0e2ac1d04ceb"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "2", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["True", StripOnInput->False, LineColor->RGBColor[0, 1, 0], FrontFaceColor->RGBColor[0, 1, 0], BackFaceColor->RGBColor[0, 1, 0], GraphicsColor->RGBColor[0, 1, 0], FontWeight->Bold, FontColor->RGBColor[0, 1, 0]]}], SequenceForm["All ", 2, " ", Style[True, Bold, RGBColor[0, 1, 0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[558]:=",ExpressionUUID->"f9aa8d19-4838-4973-8bd2-d325b68da2d9"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"badRefinement", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input",\ CellLabel-> "In[559]:=",ExpressionUUID->"bbd9ef00-2e17-45dc-b369-dbdbe8107200"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[559]:=",ExpressionUUID->"939630fd-878d-4dc0-89f5-54354943c4c9"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev1\"\>"}], SequenceForm["Validating event ", "ev1"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[559]:=",ExpressionUUID->"9fc94b8d-82cb-4992-88c0-ee7c76a1a4ea"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\" no variants defined: \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm[" no variants defined: ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[559]:=",ExpressionUUID->"5a4b588a-eb07-44f6-893f-df353d64869c"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[559]:=",ExpressionUUID->"c0c65e7c-dd21-4013-9274-2af9d5c0c44d"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[559]:=",ExpressionUUID->"9d620783-f390-4fca-b386-436de46093a3"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"All \"\>", "\[InvisibleSpace]", "1", "\[InvisibleSpace]", "\<\" \"\>", "\[InvisibleSpace]", StyleBox["Indeterminate", StripOnInput->False, LineColor->GrayLevel[0], FrontFaceColor->GrayLevel[0], BackFaceColor->GrayLevel[0], GraphicsColor->GrayLevel[0], FontWeight->Bold, FontColor->GrayLevel[0]]}], SequenceForm["All ", 1, " ", Style[Indeterminate, Bold, GrayLevel[0]]], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[559]:=",ExpressionUUID->"78b4e605-5f03-4a94-9bd1-8aa07cd3818b"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"goodRefinement2", ",", RowBox[{"onlyPhase", "\[Rule]", "\"\\""}]}], "]"}]], "Input",\ CellLabel-> "In[560]:=",ExpressionUUID->"acd10369-7594-49cb-b6eb-985059ec3ff6"], Cell[CellGroupData[{ Cell[BoxData["\<\"This is a refining model.\"\>"], "Print", CellLabel-> "During evaluation of \ In[560]:=",ExpressionUUID->"b160cb2c-7656-4f27-addd-19c7d6419ac0"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev1\"\>"}], SequenceForm["Validating event ", "ev1"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[560]:=",ExpressionUUID->"1e58eac2-377f-4d81-af16-0c5eda01167f"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"Validating event \"\>", "\[InvisibleSpace]", "\<\"ev\"\>"}], SequenceForm["Validating event ", "ev"], Editable->False]], "Print", CellLabel-> "During evaluation of \ In[560]:=",ExpressionUUID->"dfbbe41b-f170-4ee5-abf5-7b20802d2c7b"], Cell[BoxData["\<\"Summary:\"\>"], "Print", CellLabel-> "During evaluation of \ In[560]:=",ExpressionUUID->"ff372f19-3b7a-4ce3-8837-524a635710c9"], Cell[BoxData["\<\"Nothing was checked.\"\>"], "Print", CellLabel-> "During evaluation of \ In[560]:=",ExpressionUUID->"3fd5e5cc-454f-467e-a45c-c0a20251ec29"] }, Open ]] }, Open ]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Model - cars on a bridge", "Subsection",ExpressionUUID->"c526e747-686f-42e4-949f-044e0670c6b1"], Cell["\<\ This example is based on chapter 2 of the \[OpenCurlyDoubleQuote]Modeling in \ Event-B\[CloseCurlyDoubleQuote] book by Jean-Raymond Abrial.\ \>", "Text",ExpressionUUID->"6a9f2aec-7eca-4f40-977f-5fe43725630d"], Cell[CellGroupData[{ Cell["Requirements", "Subsubsection",ExpressionUUID->"688bd1ef-cdc4-4d77-b495-b3a4225d2e18"], Cell[BoxData[ RowBox[{ RowBox[{"reqs", "=", RowBox[{"<|", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}]}], "\[IndentingNewLine]", "|>"}]}], ";"}]], "Input", CellLabel-> "In[320]:=",ExpressionUUID->"b7c90550-6177-455c-9300-3b9d2c274498"] }, Closed]], Cell[CellGroupData[{ Cell["Initial attempt", "Subsubsection",ExpressionUUID->"99155fb1-007b-472a-8ba6-261630a31e43"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"d", "\[Element]", "Integers"}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "what", " ", "we", " ", "know", " ", "about", " ", "bridge", " ", "and", " ", "island", " ", "capacity"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"n", "\[Element]", "Integers"}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "number", " ", "of", " ", "cars", " ", "is", " ", "always", " ", "int"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "\[LessEqual]", "d"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"cars", " ", "on", " ", "the", " ", RowBox[{"bridge", "/", "island"}], " ", "do", " ", "not", " ", "exceed", " ", "capacity"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ "event", " ", "for", " ", "a", " ", "car", " ", "moving", " ", "out", " ", "to", " ", "the", " ", "bridge", " ", "and", " ", "island"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"n", "\[Rule]", RowBox[{"n", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ "event", " ", "for", " ", "a", " ", "car", " ", "moving", " ", "back", " ", "from", " ", "the", " ", "bridge", " ", "and", " ", "island"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"n", "\[Rule]", RowBox[{"n", "-", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[321]:=",ExpressionUUID->"43f9748c-2271-4178-8247-e5210ec93197"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellLabel-> "In[322]:=",ExpressionUUID->"0ede6c93-a6b7-4615-8145-950a9f300efa"], Cell["\<\ The init and ML_out events cannot be validated, because there are not enough \ details in the model.\ \>", "Text",ExpressionUUID->"1be967a7-801d-4158-aaf1-578966723c89"] }, Closed]], Cell[CellGroupData[{ Cell["Adding event guards", "Subsubsection",ExpressionUUID->"91c7f39a-a55c-4be2-979f-b38444e60bc2"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"d", "\[Element]", "Integers"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "\[Element]", "Integers"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "\[LessEqual]", "d"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"n", "<", "d"}], ",", " ", RowBox[{"(*", " ", RowBox[{"guard", ":", " ", RowBox[{ "there", " ", "is", " ", "space", " ", "left", " ", "on", " ", "the", " ", "bridge", " ", "and", " ", "island"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"n", "\[Rule]", RowBox[{"n", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "n"}], ",", " ", RowBox[{"(*", " ", RowBox[{"guard", ":", " ", RowBox[{ "there", " ", "is", " ", "at", " ", "least", " ", "one", " ", "car", " ", "on", " ", "the", " ", "bridge", " ", "and", " ", "island"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"n", "\[Rule]", RowBox[{"n", "-", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[323]:=",ExpressionUUID->"0439324c-aa23-4176-960b-ac862bb11bbf"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellLabel-> "In[325]:=",ExpressionUUID->"f3d7a5fd-d5b8-4f3c-9e8a-28ea3cc6f9aa"], Cell["\<\ Still, axioms cannot be validated, there is not enough data related to \ constant d, which expresses the capacity of the bridge and island.\ \>", "Text", CellChangeTimes->{{3.9058559862911434`*^9, 3.9058559966893315`*^9}, { 3.905856087820291*^9, 3.9058561053207273`*^9}, {3.9059111705407157`*^9, 3.905911171601857*^9}, {3.905912336221181*^9, 3.9059123377671857`*^9}, { 3.90593001497136*^9, 3.905930040830184*^9}},ExpressionUUID->"e1f8dfff-6ad3-4181-ba47-\ 202001737d18"] }, Closed]], Cell[CellGroupData[{ Cell["Adding more axioms and init event", "Subsubsection",ExpressionUUID->"2508316b-b3b2-4f0f-a282-59a5ee82a668"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"d", "\[Element]", "Integers"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"d", ">", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "new", " ", "axiom", " ", "that", " ", "allows", " ", "the", " ", "traffic", " ", "to", " ", "exist"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "\[Rule]", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"initial", " ", "state"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "\[Element]", "Integers"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "\[LessEqual]", "d"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"n", "<", "d"}], ",", RowBox[{"n", "\[Rule]", RowBox[{"n", "+", "1"}]}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "n"}], ",", RowBox[{"n", "\[Rule]", RowBox[{"n", "-", "1"}]}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[326]:=",ExpressionUUID->"5f52a638-bde3-4d01-a7d3-f32d0e80b3f2"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input",ExpressionUUID->"3ef187d4-342a-4f57-acc2-1af7b5a5dafd"] }, Closed]], Cell[CellGroupData[{ Cell["Adding deadlock freedom requirement", "Subsubsection",ExpressionUUID->"44def3ed-f0c1-4f12-929b-4c4216382a01"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"reqs", "[", "\"\\"", "]"}], "=", "\"\\""}], ";"}]], "Input", CellLabel-> "In[328]:=",ExpressionUUID->"eb137cee-c023-46ac-bed8-9029c2fe1f76"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"d", "\[Element]", "Integers"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"d", ">", "0"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "\[Rule]", "0"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "\[Element]", "Integers"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "\[LessEqual]", "d"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"n", "<", "d"}], ",", RowBox[{"n", "\[Rule]", RowBox[{"n", "+", "1"}]}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "n"}], ",", RowBox[{"n", "\[Rule]", RowBox[{"n", "-", "1"}]}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"deadlock", "-", RowBox[{"freedom", " ", "validation", " ", "request"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[329]:=",ExpressionUUID->"8b906477-f8b3-4be4-a6cd-7fcb7383d0a7"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellChangeTimes->{{3.9059160315798845`*^9, 3.905916079807065*^9}, { 3.9060884211656685`*^9, 3.9060884245799026`*^9}, {3.90608885996437*^9, 3.906088862427227*^9}, {3.906458693796014*^9, 3.9064586943674593`*^9}, { 3.9065130983270864`*^9, 3.906513102082329*^9}, {3.9065138624624205`*^9, 3.906513917398452*^9}, 3.9071306214448547`*^9}, CellLabel-> "In[330]:=",ExpressionUUID->"4ac35a2e-8389-4e1c-a652-b8f1f4faf32e"] }, Closed]], Cell[CellGroupData[{ Cell["First refinement", "Subsubsection",ExpressionUUID->"dc228291-157d-4f15-994b-ce6f1d91f2b8"], Cell["\<\ The refinement means that new, more precise model is based on (and is \ compatible with) a previous, more abstract model.\ \>", "Text",ExpressionUUID->"f1cb8bd5-dbf3-4207-a5a0-60d9301dbcad"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"refinement", " ", "relation"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "a", " ", "is", " ", "cars", " ", "on", " ", "the", " ", "bridge", " ", "moving", " ", "to", " ", "island"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"b", " ", "is", " ", "cars", " ", "on", " ", "island"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "c", " ", "is", " ", "cars", " ", "on", " ", "the", " ", "bridge", " ", "coming", " ", "back", " ", "from", " ", "island"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", "0"}], ",", RowBox[{"b", "\[Rule]", "0"}], ",", RowBox[{"c", "\[Rule]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Element]", "Integers"}], ",", RowBox[{"a", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"b", "\[Element]", "Integers"}], ",", RowBox[{"b", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"c", "\[Element]", "Integers"}], ",", RowBox[{"c", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"a", "+", "b", "+", "c"}], "\[Equal]", "n"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"n", " ", "exists", " ", "in", " ", "base", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"a", "\[Equal]", "0"}], "||", RowBox[{"c", "\[Equal]", "0"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"bridge", " ", "is", " ", "one"}], "-", "way"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "always", " ", "decreasing", " ", "variant", " ", "for", " ", "new", " ", "events", " ", "ensures", " ", "that", " ", "new", " ", "events", " ", "do", " ", "not", " ", "starve", " ", "the", " ", "events", " ", "from", " ", "base", " ", "model", " ", RowBox[{"(", RowBox[{ RowBox[{"that", " ", "is"}], ",", " ", RowBox[{ "new", " ", "events", " ", "cannot", " ", "form", " ", "infinite", " ", "chains"}]}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"2", "a"}], "+", "b"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "c"}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "-", "1"}]}]}], "]"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"refined", " ", "base", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"a", "+", "b"}], "<", "d"}], ",", RowBox[{"c", "\[Equal]", "0"}]}], "}"}], ",", RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}]}], "]"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"refined", " ", "base", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "a"}], ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "-", "1"}]}], ",", RowBox[{"b", "\[Rule]", RowBox[{"b", "+", "1"}]}]}], "}"}]}], "]"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"new", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"b", ">", "0"}], ",", RowBox[{"a", "\[Equal]", "0"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"b", "\[Rule]", RowBox[{"b", "-", "1"}]}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "+", "1"}]}]}], "}"}]}], "]"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"new", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"deadlock", "-", RowBox[{"freedom", " ", "validation", " ", "request"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[331]:=",ExpressionUUID->"1db9e59a-6837-4211-a775-baffda6ebaf4"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel-> "In[386]:=",ExpressionUUID->"90d1d80f-d264-4d6d-b7c3-5ac85c421a9c"] }, Closed]], Cell[CellGroupData[{ Cell["Second refinement, adding traffic lights", "Subsubsection",ExpressionUUID->"03d659d0-78ff-40bf-87f6-3437f53d8c49"], Cell["\<\ This refinement introduces traffic lights to control the way cars move \ between zones mainland-bridge-island.\ \>", "Text",ExpressionUUID->"e8fd08a4-672c-435b-ab7d-56523d902c64"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"color", "=", RowBox[{"{", RowBox[{"green", ",", "red"}], "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "helper", " ", "function", " ", "for", " ", "generating", " ", "statements", " ", "of", " ", "unique", " ", "elements", " ", "in", " ", "a", " ", "set"}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"uniqueElements", "[", "s_List", "]"}], ":=", RowBox[{"Unequal", "@@@", RowBox[{"Subsets", "[", RowBox[{"s", ",", RowBox[{"{", "2", "}"}]}], "]"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"uniqueElements", "[", "color", "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"mlTl", "\[Rule]", "red"}], ",", RowBox[{"ilTl", "\[Rule]", "red"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "not", " ", "present", " ", "in", " ", "the", " ", "book", " ", RowBox[{"(", "!", ")"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "new", " ", "invariants", " ", "for", " ", "traffic", " ", "lights"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"mlTl", "\[Element]", "color"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"mainland", " ", "traffic", " ", "light"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ilTl", "\[Element]", "color"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"island", " ", "traffic", " ", "light"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mlTl", "\[Equal]", "green"}], "\[Implies]", RowBox[{ RowBox[{ RowBox[{"a", "+", "b"}], "<", "d"}], "&&", RowBox[{"c", "\[Equal]", "0"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"ilTl", "\[Equal]", "green"}], "\[Implies]", RowBox[{ RowBox[{"b", ">", "0"}], "&&", RowBox[{"a", "\[Equal]", "0"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refinement", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"mlTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refinement", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"ilTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"b", "\[Rule]", RowBox[{"b", "-", "1"}]}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "+", "1"}]}]}], "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "event"}], " ", "-", " ", RowBox[{ "turn", " ", "green", " ", "for", " ", "cars", " ", "moving", " ", "to", " ", "island"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"mlTl", "\[Equal]", "red"}], ",", RowBox[{ RowBox[{"a", "+", "b"}], "<", "d"}], ",", RowBox[{"c", "\[Equal]", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"mlTl", "\[Rule]", "green"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "event"}], " ", "-", " ", RowBox[{ "turn", " ", "green", " ", "for", " ", "cars", " ", "moving", " ", "from", " ", "islan"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"ilTl", "\[Equal]", "red"}], ",", RowBox[{"b", ">", "0"}], ",", RowBox[{"a", "\[Equal]", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"ilTl", "\[Rule]", "green"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"as", " ", "in", " ", "base", " ", "model"}], ",", " ", RowBox[{ "but", " ", "still", " ", "needed", " ", "here", " ", "for", " ", "completeness"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "c"}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "-", "1"}]}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "a"}], ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "-", "1"}]}], ",", RowBox[{"b", "\[Rule]", RowBox[{"b", "+", "1"}]}]}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[381]:=",ExpressionUUID->"fc50867d-5147-4a7e-bd16-c2e2823636b6"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel-> "In[385]:=",ExpressionUUID->"39775b79-5a2a-4d28-90ac-f49b7179274e"], Cell["\<\ The above model cannot be validated, because it misses invariants...\ \>", "Text",ExpressionUUID->"20c03a26-2d27-41f6-a892-7173864bd0f3"] }, Closed]], Cell[CellGroupData[{ Cell["Second refinement, adding invariants", "Subsubsection",ExpressionUUID->"0f4b9336-c50d-415e-b6b9-815732bc8688"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"color", "=", RowBox[{"{", RowBox[{"green", ",", "red"}], "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "helper", " ", "function", " ", "for", " ", "generating", " ", "statements", " ", "of", " ", "unique", " ", "elements", " ", "in", " ", "a", " ", "set"}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"uniqueElements", "[", "s_List", "]"}], ":=", RowBox[{"Unequal", "@@@", RowBox[{"Subsets", "[", RowBox[{"s", ",", RowBox[{"{", "2", "}"}]}], "]"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"uniqueElements", "[", "color", "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"mlTl", "\[Rule]", "red"}], ",", RowBox[{"ilTl", "\[Rule]", "red"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "new", " ", "invariants", " ", "for", " ", "traffic", " ", "lights"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"mlTl", "\[Element]", "color"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"mainland", " ", "traffic", " ", "light"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ilTl", "\[Element]", "color"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"island", " ", "traffic", " ", "light"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mlTl", "\[Equal]", "green"}], "\[Implies]", RowBox[{ RowBox[{ RowBox[{"a", "+", "b"}], "<", "d"}], "&&", RowBox[{"c", "\[Equal]", "0"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"ilTl", "\[Equal]", "green"}], "\[Implies]", RowBox[{ RowBox[{"b", ">", "0"}], "&&", RowBox[{"a", "\[Equal]", "0"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "invariant"}], ",", " ", RowBox[{ "both", " ", "lights", " ", "cannot", " ", "be", " ", "green", " ", "at", " ", "the", " ", "same", " ", RowBox[{"time", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mlTl", "\[Equal]", "red"}], "||", RowBox[{"ilTl", "\[Equal]", "red"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refinement", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"mlTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refinement", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"ilTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"b", "\[Rule]", RowBox[{"b", "-", "1"}]}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "+", "1"}]}]}], "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "event"}], " ", "-", " ", RowBox[{ "turn", " ", "green", " ", "for", " ", "cars", " ", "moving", " ", "to", " ", "island"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"mlTl", "\[Equal]", "red"}], ",", RowBox[{ RowBox[{"a", "+", "b"}], "<", "d"}], ",", RowBox[{"c", "\[Equal]", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlTl", "\[Rule]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"ilTl", "\[Rule]", "red"}]}], " ", RowBox[{"(*", " ", RowBox[{ "corrected", " ", "action", " ", "for", " ", "inv2_", "5"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "event"}], " ", "-", " ", RowBox[{ "turn", " ", "green", " ", "for", " ", "cars", " ", "moving", " ", "from", " ", "islan"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"ilTl", "\[Equal]", "red"}], ",", RowBox[{"b", ">", "0"}], ",", RowBox[{"a", "\[Equal]", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilTl", "\[Rule]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"mlTl", "\[Rule]", "red"}]}], " ", RowBox[{"(*", " ", RowBox[{ "corrected", " ", "action", " ", "for", " ", "inv2_", "5"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"as", " ", "in", " ", "base", " ", "model"}], ",", " ", RowBox[{ "but", " ", "still", " ", "needed", " ", "here", " ", "for", " ", "completeness"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "c"}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "-", "1"}]}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "a"}], ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "-", "1"}]}], ",", RowBox[{"b", "\[Rule]", RowBox[{"b", "+", "1"}]}]}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[387]:=",ExpressionUUID->"a2c5cfe6-d084-41a3-a27e-3ab1b572b517"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel-> "In[390]:=",ExpressionUUID->"e20b287b-b8f1-4b66-8de1-bb64bc5a42a5"], Cell["\<\ This model is still not complete, because ML_out and Il_out have to be split \ to conditionally turn their respective lights to red. This means that the \ split event will have disjoint guards...\ \>", "Text",ExpressionUUID->"c696aa0d-ce49-4125-918d-5089405ef988"] }, Closed]], Cell[CellGroupData[{ Cell["Second refinement, splitting events", "Subsubsection",ExpressionUUID->"869308bc-3cbd-40f9-9c7c-792fd27528ec"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"color", "=", RowBox[{"{", RowBox[{"green", ",", "red"}], "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "helper", " ", "function", " ", "for", " ", "generating", " ", "statements", " ", "of", " ", "unique", " ", "elements", " ", "in", " ", "a", " ", "set"}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"uniqueElements", "[", "s_List", "]"}], ":=", RowBox[{"Unequal", "@@@", RowBox[{"Subsets", "[", RowBox[{"s", ",", RowBox[{"{", "2", "}"}]}], "]"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"uniqueElements", "[", "color", "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"mlTl", "\[Rule]", "red"}], ",", RowBox[{"ilTl", "\[Rule]", "red"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "new", " ", "invariants", " ", "for", " ", "traffic", " ", "lights"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"mlTl", "\[Element]", "color"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"mainland", " ", "traffic", " ", "light"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ilTl", "\[Element]", "color"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"island", " ", "traffic", " ", "light"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mlTl", "\[Equal]", "green"}], "\[Implies]", RowBox[{ RowBox[{ RowBox[{"a", "+", "b"}], "<", "d"}], "&&", RowBox[{"c", "\[Equal]", "0"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"ilTl", "\[Equal]", "green"}], "\[Implies]", RowBox[{ RowBox[{"b", ">", "0"}], "&&", RowBox[{"a", "\[Equal]", "0"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mlTl", "\[Equal]", "red"}], "||", RowBox[{"ilTl", "\[Equal]", "red"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "no", " ", "two", " ", "greens", " ", "at", " ", "the", " ", "same", " ", "time"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{"split", ",", " ", RowBox[{"but", " ", "still", " ", "refinement"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "+", "b", "+", "1"}], "\[NotEqual]", "d"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "condition", " ", "in", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{"split", ",", " ", RowBox[{"but", " ", "still", " ", "refinement"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "+", "b", "+", "1"}], "==", "d"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "condition", " ", "in", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"mlTl", "\[Rule]", "red"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{"split", ",", " ", RowBox[{"but", " ", "still", " ", "refinement"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"b", "\[NotEqual]", "1"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "condition", " ", "in", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"b", "\[Rule]", RowBox[{"b", "-", "1"}]}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "+", "1"}]}]}], "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{"split", ",", " ", RowBox[{"but", " ", "still", " ", "refinement"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"b", "\[Equal]", "1"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "condition", " ", "in", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "\[Rule]", RowBox[{"b", "-", "1"}]}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"ilTl", "\[Rule]", "red"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "event"}], " ", "-", " ", RowBox[{ "turn", " ", "green", " ", "for", " ", "cars", " ", "moving", " ", "to", " ", "island"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"mlTl", "\[Equal]", "red"}], ",", RowBox[{ RowBox[{"a", "+", "b"}], "<", "d"}], ",", RowBox[{"c", "\[Equal]", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlTl", "\[Rule]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"ilTl", "\[Rule]", "red"}]}], " ", RowBox[{"(*", " ", RowBox[{ "corrected", " ", "action", " ", "for", " ", "inv2_", "5"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "event"}], " ", "-", " ", RowBox[{ "turn", " ", "green", " ", "for", " ", "cars", " ", "moving", " ", "from", " ", "islan"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"ilTl", "\[Equal]", "red"}], ",", RowBox[{"b", ">", "0"}], ",", RowBox[{"a", "\[Equal]", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilTl", "\[Rule]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"mlTl", "\[Rule]", "red"}]}], " ", RowBox[{"(*", " ", RowBox[{ "corrected", " ", "action", " ", "for", " ", "inv2_", "5"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"as", " ", "in", " ", "base", " ", "model"}], ",", " ", RowBox[{ "but", " ", "still", " ", "needed", " ", "here", " ", "for", " ", "completeness"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "c"}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "-", "1"}]}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "a"}], ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "-", "1"}]}], ",", RowBox[{"b", "\[Rule]", RowBox[{"b", "+", "1"}]}]}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[391]:=",ExpressionUUID->"818f3d99-6ade-4e09-900d-d89399d47f7b"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel-> "In[394]:=",ExpressionUUID->"f6206825-2ff2-4607-81b2-6675ed6e006e"], Cell["\<\ This model still needs to be completed with variants, to ensure that new \ events (those that are not refinements of events from base model) do not \ starve the old ones...\ \>", "Text",ExpressionUUID->"eb1b7da6-ed8c-4833-90a0-60681a97ee9f"] }, Closed]], Cell[CellGroupData[{ Cell["Second refinement, adding boolean variants", "Subsubsection",ExpressionUUID->"bf8c7482-1b2e-4d9d-9e09-997bfafffa70"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"color", "=", RowBox[{"{", RowBox[{"green", ",", "red"}], "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "helper", " ", "function", " ", "for", " ", "generating", " ", "statements", " ", "of", " ", "unique", " ", "elements", " ", "in", " ", "a", " ", "set"}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"uniqueElements", "[", "s_List", "]"}], ":=", RowBox[{"Unequal", "@@@", RowBox[{"Subsets", "[", RowBox[{"s", ",", RowBox[{"{", "2", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "helper", " ", "function", " ", "for", " ", "counting", " ", "boolean", " ", "values"}], ",", " ", RowBox[{"for", " ", "proving", " ", "bool", " ", "variants"}]}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"boolCount", "[", "a_", "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"a", "\[Equal]", "True"}], ",", "1", ",", "0"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"boolCount", "[", RowBox[{"a_", ",", "b_"}], "]"}], ":=", RowBox[{ RowBox[{"boolCount", "[", "a", "]"}], "+", RowBox[{"boolCount", "[", "b", "]"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"uniqueElements", "[", "color", "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlTl", "\[Rule]", "red"}], ",", RowBox[{"ilTl", "\[Rule]", "red"}], ",", "\[IndentingNewLine]", RowBox[{"mlPass", "\[Element]", "Booleans"}], ",", RowBox[{"mlPass", "\[Rule]", "True"}], ",", RowBox[{"ilPass", "\[Element]", "Booleans"}], ",", RowBox[{"ilPass", "\[Rule]", "True"}]}], " ", " ", RowBox[{"(*", " ", RowBox[{ "new", " ", "initial", " ", "values", " ", "for", " ", "variants"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "new", " ", "invariants", " ", "for", " ", "traffic", " ", "lights"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"mlTl", "\[Element]", "color"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"mainland", " ", "traffic", " ", "light"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ilTl", "\[Element]", "color"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"island", " ", "traffic", " ", "light"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mlTl", "\[Equal]", "green"}], "\[Implies]", RowBox[{ RowBox[{ RowBox[{"a", "+", "b"}], "<", "d"}], "&&", RowBox[{"c", "\[Equal]", "0"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"ilTl", "\[Equal]", "green"}], "\[Implies]", RowBox[{ RowBox[{"b", ">", "0"}], "&&", RowBox[{"a", "\[Equal]", "0"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mlTl", "\[Equal]", "red"}], "||", RowBox[{"ilTl", "\[Equal]", "red"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "no", " ", "two", " ", "greens", " ", "at", " ", "the", " ", "same", " ", "time"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"mlPass", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ilPass", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mlTl", "\[Equal]", "red"}], "\[Implies]", RowBox[{"mlPass", "\[Equal]", "True"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"ilTl", "\[Equal]", "red"}], "\[Implies]", RowBox[{"ilPass", "\[Equal]", "True"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"variant", " ", "for", " ", "new", " ", "events"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"boolCount", "[", RowBox[{"mlPass", ",", "ilPass"}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{"split", ",", " ", RowBox[{"but", " ", "still", " ", "refinement"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "+", "b", "+", "1"}], "\[NotEqual]", "d"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "condition", " ", "in", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"mlPass", "\[Rule]", "True"}]}], " ", RowBox[{"(*", " ", RowBox[{"new", " ", "variant", " ", "change"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{"split", ",", " ", RowBox[{"but", " ", "still", " ", "refinement"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "+", "b", "+", "1"}], "==", "d"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "condition", " ", "in", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"mlTl", "\[Rule]", "red"}], ",", "\[IndentingNewLine]", RowBox[{"mlPass", "\[Rule]", "True"}]}], RowBox[{"(*", " ", RowBox[{"new", " ", "variant", " ", "change"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{"split", ",", " ", RowBox[{"but", " ", "still", " ", "refinement"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"b", "\[NotEqual]", "1"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "condition", " ", "in", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "\[Rule]", RowBox[{"b", "-", "1"}]}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"ilPass", "\[Rule]", "True"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{"split", ",", " ", RowBox[{"but", " ", "still", " ", "refinement"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilTl", "\[Equal]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"b", "\[Equal]", "1"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "condition", " ", "in", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "\[Rule]", RowBox[{"b", "-", "1"}]}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"ilTl", "\[Rule]", "red"}], ",", "\[IndentingNewLine]", RowBox[{"ilPass", "\[Rule]", "True"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "event"}], " ", "-", " ", RowBox[{ "turn", " ", "green", " ", "for", " ", "cars", " ", "moving", " ", "to", " ", "island"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlTl", "\[Equal]", "red"}], ",", RowBox[{ RowBox[{"a", "+", "b"}], "<", "d"}], ",", RowBox[{"c", "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{"ilPass", "\[Equal]", "True"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlTl", "\[Rule]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"ilTl", "\[Rule]", "red"}], " ", ",", "\[IndentingNewLine]", RowBox[{"mlPass", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "event"}], " ", "-", " ", RowBox[{ "turn", " ", "green", " ", "for", " ", "cars", " ", "moving", " ", "from", " ", "island"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilTl", "\[Equal]", "red"}], ",", RowBox[{"b", ">", "0"}], ",", RowBox[{"a", "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{"mlPass", "\[Equal]", "True"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilTl", "\[Rule]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"mlTl", "\[Rule]", "red"}], ",", "\[IndentingNewLine]", RowBox[{"ilPass", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"as", " ", "in", " ", "base", " ", "model"}], ",", " ", RowBox[{ "but", " ", "still", " ", "needed", " ", "here", " ", "for", " ", "completeness"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "c"}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "-", "1"}]}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"0", "<", "a"}], ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "-", "1"}]}], ",", RowBox[{"b", "\[Rule]", RowBox[{"b", "+", "1"}]}]}], "}"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"deadlock", "-", RowBox[{"freedom", " ", "validation", " ", "request"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input",ExpressionUUID->\ "80bdfe3f-bd9a-4fe3-bbbd-97aed6d75a3f"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel-> "In[484]:=",ExpressionUUID->"2f2dce00-f022-47bd-a63a-ca8db3bfe71d"] }, Closed]], Cell[CellGroupData[{ Cell["Third refinement, adding car sensors", "Subsubsection",ExpressionUUID->"264d7941-21bf-44f8-86eb-956db30ddb61"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"reqs", "[", "\"\\"", "]"}], "=", "\"\\""}], ";"}]], "Input", CellLabel-> "In[351]:=",ExpressionUUID->"71e16781-5945-47a2-884f-889a0f90d32d"], Cell[BoxData[{ RowBox[{ RowBox[{"color", "=", RowBox[{"{", RowBox[{"green", ",", "red"}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"sensor", "=", RowBox[{"{", RowBox[{"On", ",", "Off"}], "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "helper", " ", "function", " ", "for", " ", "generating", " ", "statements", " ", "of", " ", "unique", " ", "elements", " ", "in", " ", "a", " ", "set"}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"uniqueElements", "[", "s_List", "]"}], ":=", RowBox[{"Unequal", "@@@", RowBox[{"Subsets", "[", RowBox[{"s", ",", RowBox[{"{", "2", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "helper", " ", "function", " ", "for", " ", "counting", " ", "boolean", " ", "values"}], ",", " ", RowBox[{"for", " ", "proving", " ", "bool", " ", "variants"}]}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"boolCount", "[", "a_", "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"a", "\[Equal]", "True"}], ",", "1", ",", "0"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"boolCount", "[", RowBox[{"a_", ",", "b_", ",", "c_", ",", "d_"}], "]"}], ":=", RowBox[{ RowBox[{"boolCount", "[", "a", "]"}], "+", RowBox[{"boolCount", "[", "b", "]"}], "+", RowBox[{"boolCount", "[", "c", "]"}], "+", RowBox[{"boolCount", "[", "d", "]"}]}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"sensorCount", "[", "a_", "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"a", "==", "On"}], ",", "1", ",", "0"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"sensorCount", "[", RowBox[{"a_", ",", "b_", ",", "c_", ",", "d_"}], "]"}], ":=", RowBox[{ RowBox[{"sensorCount", "[", "a", "]"}], "+", RowBox[{"sensorCount", "[", "b", "]"}], "+", RowBox[{"sensorCount", "[", "c", "]"}], "+", RowBox[{"sensorCount", "[", "d", "]"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel3", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel2", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"uniqueElements", "[", "sensor", "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "initial", " ", "values", " ", "for", " ", "new", " ", "invariants"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlOutSr", "\[Rule]", "Off"}], ",", RowBox[{"mlInSr", "\[Rule]", "Off"}], ",", RowBox[{"ilOutSr", "\[Rule]", "Off"}], ",", RowBox[{"ilInSr", "\[Rule]", "Off"}], ",", "\[IndentingNewLine]", RowBox[{"mlOut10", "\[Element]", "Booleans"}], ",", RowBox[{"mlOut10", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"mlIn10", "\[Element]", "Booleans"}], ",", RowBox[{"mlIn10", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"ilOut10", "\[Element]", "Booleans"}], ",", RowBox[{"ilOut10", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"ilIn10", "\[Element]", "Booleans"}], ",", RowBox[{"ilIn10", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"A", "\[Rule]", "0"}], ",", RowBox[{"B", "\[Rule]", "0"}], ",", RowBox[{"C", "\[Rule]", "0"}]}], "\[IndentingNewLine]", "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "new", " ", "invariants", " ", "for", " ", "car", " ", "sensors"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"mlOutSr", "\[Element]", "sensor"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"mainland", "-", "to", "-", RowBox[{"bridge", " ", "car", " ", "sensor"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"mlInSr", "\[Element]", "sensor"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"bridge", "-", "to", "-", RowBox[{"mainland", " ", "car", " ", "sensor"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ilOutSr", "\[Element]", "sensor"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"island", "-", "to", "-", RowBox[{"bridge", " ", "car", " ", "sensor"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ilInSr", "\[Element]", "sensor"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"bridge", "-", "to", "-", RowBox[{"island", " ", "car", " ", "sensor"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"A", "\[Element]", "Integers"}], ",", RowBox[{"A", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "physical", " ", "num", " ", "of", " ", "cars", " ", "going", " ", "to", " ", "island"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"B", "\[Element]", "Integers"}], ",", RowBox[{"B", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "physical", " ", "num", " ", "of", " ", "cars", " ", "on", " ", "island"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"C", "\[Element]", "Integers"}], ",", RowBox[{"C", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "phys", " ", "num", " ", "of", " ", "cars", " ", "going", " ", "to", " ", "mainland"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"mlOut10", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"mlIn10", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ilOut10", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ilIn10", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "if", " ", "the", " ", "car", " ", "is", " ", "on", " ", "sensor"}], ",", " ", RowBox[{ "then", " ", "the", " ", "physical", " ", "num", " ", "of", " ", "cars", " ", "in", " ", "that", " ", "group", " ", "is", " ", RowBox[{"positive", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", " ", RowBox[{ RowBox[{"ilInSr", "\[Equal]", "On"}], "\[Implies]", RowBox[{"A", ">", "0"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", " ", RowBox[{ RowBox[{"ilOutSr", "\[Equal]", "On"}], "\[Implies]", RowBox[{"B", ">", "0"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", " ", RowBox[{ RowBox[{"mlInSr", "\[Equal]", "On"}], "\[Implies]", RowBox[{"C", ">", "0"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"cars", " ", "leave", " ", "sensors", " ", RowBox[{"(", RowBox[{ "the", " ", "sensor", " ", "switches", " ", "from", " ", "1", " ", "to", " ", "0"}], ")"}], " ", "only", " ", "when", " ", "they", " ", "have", " ", "green", " ", "light", " ", RowBox[{"(", RowBox[{"they", " ", "obey", " ", "trafficl", " ", "rules"}], ")"}]}], ":"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mlOut10", "\[Equal]", "True"}], "\[Implies]", RowBox[{"mlTl", "\[Equal]", "green"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"ilOut10", "\[Equal]", "True"}], "\[Implies]", RowBox[{"ilTl", "\[Equal]", "green"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "there", " ", "are", " ", "no", " ", "messages", " ", "from", " ", "sensor", " ", "as", " ", "long", " ", "as", " ", "the", " ", "car", " ", "is", " ", "above", " ", RowBox[{"it", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"ilInSr", "\[Equal]", "On"}], "\[Implies]", RowBox[{"ilIn10", "\[Equal]", "False"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"ilOutSr", "\[Equal]", "On"}], "\[Implies]", RowBox[{"ilOut10", "\[Equal]", "False"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mlInSr", "\[Equal]", "On"}], "\[Implies]", RowBox[{"mlIn10", "\[Equal]", "False"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mlOutSr", "\[Equal]", "On"}], "\[Implies]", RowBox[{"mlOut10", "\[Equal]", "False"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"controller", "'"}], "s", " ", "knowledge", " ", RowBox[{"(", RowBox[{"a", ",", "b", ",", "c"}], ")"}], " ", "is", " ", "related", " ", "to", " ", "physical", " ", "number", " ", "of", " ", "cars", " ", RowBox[{"(", RowBox[{"A", ",", "B", ",", "C"}], ")"}]}], ":"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilIn10", "\[Equal]", "True"}], "&&", RowBox[{"mlOut10", "\[Equal]", "True"}]}], "\[Implies]", RowBox[{"A", "\[Equal]", "a"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilIn10", "\[Equal]", "False"}], "&&", RowBox[{"mlOut10", "\[Equal]", "True"}]}], "\[Implies]", RowBox[{"A", "\[Equal]", RowBox[{"a", "+", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilIn10", "\[Equal]", "True"}], "&&", RowBox[{"mlOut10", "\[Equal]", "False"}]}], "\[Implies]", RowBox[{"A", "\[Equal]", RowBox[{"a", "-", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilIn10", "\[Equal]", "False"}], "&&", RowBox[{"mlOut10", "\[Equal]", "False"}]}], "\[Implies]", RowBox[{"A", "\[Equal]", "a"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilIn10", "\[Equal]", "True"}], "&&", RowBox[{"ilOut10", "\[Equal]", "True"}]}], "\[Implies]", RowBox[{"B", "\[Equal]", "b"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilIn10", "\[Equal]", "True"}], "&&", RowBox[{"ilOut10", "\[Equal]", "False"}]}], "\[Implies]", RowBox[{"B", "\[Equal]", RowBox[{"b", "+", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilIn10", "\[Equal]", "False"}], "&&", RowBox[{"ilOut10", "\[Equal]", "True"}]}], "\[Implies]", RowBox[{"B", "\[Equal]", RowBox[{"b", "-", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilIn10", "\[Equal]", "False"}], "&&", RowBox[{"ilOut10", "\[Equal]", "False"}]}], "\[Implies]", RowBox[{"B", "\[Equal]", "b"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilOut10", "\[Equal]", "True"}], "&&", RowBox[{"mlIn10", "\[Equal]", "True"}]}], "\[Implies]", RowBox[{"C", "\[Equal]", "c"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilOut10", "\[Equal]", "True"}], "&&", RowBox[{"mlIn10", "\[Equal]", "False"}]}], "\[Implies]", RowBox[{"C", "\[Equal]", RowBox[{"c", "+", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilOut10", "\[Equal]", "False"}], "&&", RowBox[{"mlIn10", "\[Equal]", "True"}]}], "\[Implies]", RowBox[{"C", "\[Equal]", RowBox[{"c", "-", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"ilOut10", "\[Equal]", "False"}], "&&", RowBox[{"mlIn10", "\[Equal]", "False"}]}], "\[Implies]", RowBox[{"C", "\[Equal]", "c"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"one", "-", RowBox[{ "way", " ", "bridge", " ", "and", " ", "limited", " ", "number", " ", "of", " ", "cars", " ", "on", " ", "island", " ", "hold", " ", "for", " ", "physical", " ", "number"}]}], ",", " ", RowBox[{"too", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"A", "\[Equal]", "0"}], "||", RowBox[{"C", "\[Equal]", "0"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"A", "+", "B", "+", "C"}], "\[LessEqual]", "d"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"variant", " ", "for", " ", "new", " ", "events"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"12", "-", RowBox[{"(", RowBox[{ RowBox[{"sensorCount", "[", RowBox[{"mlOutSr", ",", "mlInSr", ",", "ilOutSr", ",", "ilInSr"}], "]"}], "+", RowBox[{"2", "*", RowBox[{"boolCount", "[", RowBox[{"mlOut10", ",", "mlIn10", ",", "ilOut10", ",", "ilIn10"}], "]"}]}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlOut10", "\[Equal]", "True"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "guard"}], ",", " ", RowBox[{ "wait", " ", "for", " ", "message", " ", "from", " ", "the", " ", "sensor"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "+", "b", "+", "1"}], "\[NotEqual]", "d"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"mlPass", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"mlOut10", "\[Rule]", "False"}]}], " ", RowBox[{"(*", " ", RowBox[{ "message", " ", "from", " ", "the", " ", "sensor", " ", "is", " ", "considered", " ", "to", " ", "be", " ", "consumed"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlOut10", "\[Equal]", "True"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "guard"}], ",", " ", RowBox[{ "wait", " ", "for", " ", "message", " ", "from", " ", "the", " ", "sensor"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "+", "b", "+", "1"}], "==", "d"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"mlTl", "\[Rule]", "red"}], ",", "\[IndentingNewLine]", RowBox[{"mlPass", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"mlOut10", "\[Rule]", "False"}]}], " ", RowBox[{"(*", " ", RowBox[{ "message", " ", "from", " ", "the", " ", "sensor", " ", "is", " ", "considered", " ", "to", " ", "be", " ", "consumed"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilOut10", "\[Equal]", "True"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "guard"}], ",", " ", RowBox[{ "wait", " ", "for", " ", "message", " ", "from", " ", "the", " ", "sensor"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"b", "\[NotEqual]", "1"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "\[Rule]", RowBox[{"b", "-", "1"}]}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"ilPass", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"ilOut10", "\[Rule]", "False"}]}], " ", RowBox[{"(*", " ", RowBox[{ "message", " ", "from", " ", "the", " ", "sensor", " ", "is", " ", "considered", " ", "to", " ", "be", " ", "consumed"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilOut10", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"b", "\[Equal]", "1"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "\[Rule]", RowBox[{"b", "-", "1"}]}], ",", RowBox[{"c", "\[Rule]", RowBox[{"c", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"ilTl", "\[Rule]", "red"}], ",", "\[IndentingNewLine]", RowBox[{"ilPass", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"ilOut10", "\[Rule]", "False"}]}], " ", RowBox[{"(*", " ", RowBox[{ "message", " ", "from", " ", "the", " ", "sensor", " ", "is", " ", "considered", " ", "to", " ", "be", " ", "consumed"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ "refinement", " ", "with", " ", "the", " ", "use", " ", "of", " ", "sensor", " ", "message"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlIn10", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"0", "<", "c"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"c", "\[Rule]", RowBox[{"c", "-", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"mlIn10", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ "refinement", " ", "with", " ", "the", " ", "use", " ", "of", " ", "sensor", " ", "message"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilIn10", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"0", "<", "a"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Rule]", RowBox[{"a", "-", "1"}]}], ",", RowBox[{"b", "\[Rule]", RowBox[{"b", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"ilIn10", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ "refinement", " ", "with", " ", "the", " ", "use", " ", "of", " ", "sensor", " ", "message"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlTl", "\[Equal]", "red"}], ",", RowBox[{ RowBox[{"a", "+", "b"}], "<", "d"}], ",", RowBox[{"c", "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{"ilPass", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"ilOut10", "\[Equal]", "False"}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "guard"}], ",", " ", RowBox[{"to", " ", "ensure", " ", "inv3_", "16"}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlTl", "\[Rule]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"ilTl", "\[Rule]", "red"}], " ", ",", "\[IndentingNewLine]", RowBox[{"mlPass", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ "refinement", " ", "with", " ", "the", " ", "use", " ", "of", " ", "sensor", " ", "message"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilTl", "\[Equal]", "red"}], ",", RowBox[{"b", ">", "0"}], ",", RowBox[{"a", "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{"mlPass", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"mlOut10", "\[Equal]", "False"}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"new", " ", "guard"}], ",", " ", RowBox[{"to", " ", "ensure", " ", "inv3_", "15"}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilTl", "\[Rule]", "green"}], ",", "\[IndentingNewLine]", RowBox[{"mlTl", "\[Rule]", "red"}], ",", "\[IndentingNewLine]", RowBox[{"ilPass", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "new", " ", "events", " ", "representing", " ", "cars", " ", "arriving", " ", "on", " ", RowBox[{"sensors", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlOutSr", "\[Equal]", "Off"}], ",", "\[IndentingNewLine]", RowBox[{"mlOut10", "\[Equal]", "False"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"mlOutSr", "\[Rule]", "On"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlInSr", "\[Equal]", "Off"}], ",", "\[IndentingNewLine]", RowBox[{"mlIn10", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"C", ">", "0"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"mlInSr", "\[Rule]", "On"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilOutSr", "\[Equal]", "Off"}], ",", "\[IndentingNewLine]", RowBox[{"ilOut10", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"B", ">", "0"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"ilOutSr", "\[Rule]", "On"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilInSr", "\[Equal]", "Off"}], ",", "\[IndentingNewLine]", RowBox[{"ilIn10", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"A", ">", "0"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"ilInSr", "\[Rule]", "On"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "new", " ", "events", " ", "representing", " ", "cars", " ", "leaving", " ", RowBox[{"sensors", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlOutSr", "\[Equal]", "On"}], ",", "\[IndentingNewLine]", RowBox[{"mlTl", "\[Equal]", "green"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlOutSr", "\[Rule]", "Off"}], ",", "\[IndentingNewLine]", RowBox[{"mlOut10", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"A", "\[Rule]", RowBox[{"A", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlInSr", "\[Equal]", "On"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mlInSr", "\[Rule]", "Off"}], ",", "\[IndentingNewLine]", RowBox[{"mlIn10", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"C", "\[Rule]", RowBox[{"C", "-", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilOutSr", "\[Equal]", "On"}], ",", "\[IndentingNewLine]", RowBox[{"ilTl", "\[Equal]", "green"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilOutSr", "\[Rule]", "Off"}], ",", "\[IndentingNewLine]", RowBox[{"ilOut10", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"B", "\[Rule]", RowBox[{"B", "-", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"C", "\[Rule]", RowBox[{"C", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilInSr", "\[Equal]", "On"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"ilInSr", "\[Rule]", "Off"}], ",", "\[IndentingNewLine]", RowBox[{"ilIn10", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"A", "\[Rule]", RowBox[{"A", "-", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"B", "\[Rule]", RowBox[{"B", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"deadlock", "-", RowBox[{"freedom", " ", "validation", " ", "request"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input",ExpressionUUID->\ "0a1e41f8-e78b-42e2-abec-2ce0dc79063a"], Cell[BoxData[ RowBox[{ RowBox[{"(*", RowBox[{" ", RowBox[{ RowBox[{"Note", ":", " ", RowBox[{ "invariants", " ", "\"\\"", " ", "are", " ", "troublemakers"}]}], ",", " ", RowBox[{ RowBox[{ "which", " ", "apparently", " ", "cannot", " ", "be", " ", "solved", " ", "with", " ", "default", " ", "Whole", " ", RowBox[{"method", ".", "\[IndentingNewLine]", "The"}], " ", "Piecewise", " ", "method", " ", "allows", " ", "to", " ", "solve", " ", "the", " ", "whole", " ", "model"}], ";", " ", RowBox[{"it", " ", "\"\\""}]}], ",", " ", RowBox[{ "but", " ", "can", " ", "take", " ", "several", " ", "hours", " ", "to", " ", RowBox[{"complete", ".", " ", "The"}], " ", "parallel", " ", "option", " ", "helps"}], ",", " ", RowBox[{ RowBox[{ RowBox[{ "too", ".", "\[IndentingNewLine]", "\[IndentingNewLine]", "An"}], " ", "alternative", " ", "strategy", " ", "is", " ", "to", " ", "divide", " ", "the", " ", "validation", " ", "of", " ", "invariants", " ", "into", " ", "two", " ", "groups", " ", "and", " ", "use", " ", "appropriate", " ", "methods", " ", "for", " ", "most", " ", "efficient", " ", RowBox[{"solution", ".", "\[IndentingNewLine]", "This"}], " ", "is", " ", "left", " ", "as", " ", "an", " ", "exercise", " ", "to", " ", "the", " ", RowBox[{"user", "."}]}], " ", ":", "-"}]}], ")"}], "\[IndentingNewLine]", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"validateModel", "[", RowBox[{"myModel3", ",", RowBox[{"method", "->", "Piecewise"}], ",", RowBox[{"parallel", "\[Rule]", "True"}]}], "]"}]}]], "Input",ExpressionUUI\ D->"ed3d08c7-54bb-4478-b178-11f92cdbc6f0"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Model - mechanical press controller", "Subsection",ExpressionUUID->"8de5077c-1e9c-4e26-ae6c-4f41aaecc2b7"], Cell["\<\ This example is based on chapter 3 of the \[OpenCurlyDoubleQuote]Modeling in \ Event-B\[CloseCurlyDoubleQuote] book by Jean-Raymond Abrial.\ \>", "Text",ExpressionUUID->"1105cb25-9451-4b40-9cf2-70df3e1946c2"], Cell[CellGroupData[{ Cell["Action and reaction pattern (weak)", "Subsubsection",ExpressionUUID->"e2c6d784-b6eb-4610-b06e-0aa026e106cd"], Cell["\<\ This model has a weak synchronization guarantee, so that reactions do not \ have to follow all actions (that is, some actions can be missed).\ \>", "Text",ExpressionUUID->"63ae0022-9917-4a80-b029-1a0aaa63db1d"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"myPattern0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "\[Element]", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", "action", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"r", "\[Element]", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", "reaction", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"ca", "\[Element]", "Integers"}], ",", RowBox[{"ca", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"action", " ", "counter", " ", "is", " ", "Natural"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"cr", "\[Element]", "Integers"}], ",", RowBox[{"cr", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"reaction", " ", "counter", " ", "is", " ", "Natural"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"cr", "\[LessEqual]", "ca"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "there", " ", "are", " ", "at", " ", "most", " ", "ca", " ", "reactions"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"try", " ", "with", " ", "and", " ", "without", " ", RowBox[{"this", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"a", "\[Equal]", "1"}], "&&", RowBox[{"r", "\[Equal]", "0"}]}], "\[Implies]", RowBox[{"cr", "<", "ca"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", "0"}], ",", RowBox[{"r", "\[Rule]", "0"}], ",", RowBox[{"ca", "\[Rule]", "0"}], ",", RowBox[{"cr", "\[Rule]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"initially", " ", "nothing", " ", "happened"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{"action", " ", "happened"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Rule]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"ca", "\[Rule]", RowBox[{"ca", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{"action", " ", "dismissed"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", "0"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{"reaction", " ", "happened"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"r", "\[Equal]", "0"}], ",", RowBox[{"a", "\[Equal]", "1"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"r", "\[Rule]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"cr", "\[Rule]", RowBox[{"cr", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{"reaction", " ", "dismissed"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"r", "\[Equal]", "1"}], ",", RowBox[{"a", "\[Equal]", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"r", "\[Rule]", "0"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]"}]], "Input", CellLabel-> "In[561]:=",ExpressionUUID->"47989326-24b5-42a7-8a83-89dd908bf40e"], Cell[BoxData[ RowBox[{"validateModel", "[", "myPattern0", "]"}]], "Input", CellLabel-> "In[562]:=",ExpressionUUID->"e3a9531b-0f27-4fc1-b219-1aa0518eeae0"] }, Closed]], Cell[CellGroupData[{ Cell["Refinement with retro-acting reaction (strong)", "Subsubsection",ExpressionUUID->"66b5e3bc-6e5f-411e-9e4b-cc577e8b80d0"], Cell["\<\ This refinement adds strong synchronization, so all actions are followed by \ reactions.\ \>", "Text",ExpressionUUID->"43dc0d5e-25cf-48d5-8c53-e9d4cf797f5c"], Cell[BoxData[ RowBox[{ RowBox[{"myPattern1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myPattern0", "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"refinement", " ", "of", " ", "previous", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ca", "\[LessEqual]", RowBox[{"cr", "+", "1"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "actions", " ", "can", " ", "be", " ", "at", " ", "most", " ", "one", " ", "step", " ", "ahead"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"a", "\[Equal]", "0"}], "\[Implies]", RowBox[{"ca", "\[Equal]", "cr"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "reactions", " ", "follow", " ", "up", " ", "before", " ", "action", " ", "is", " ", "off"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"a", "\[Equal]", "1"}], "&&", RowBox[{"r", "\[Equal]", "1"}]}], "\[Implies]", RowBox[{"ca", "\[Equal]", "cr"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", "\[Equal]", "0"}], ",", RowBox[{"r", "\[Equal]", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Rule]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"ca", "\[Rule]", RowBox[{"ca", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", "\[Equal]", "1"}], ",", RowBox[{"r", "\[Equal]", "1"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", "0"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.907122189360712*^9, 3.9071222163926067`*^9}, { 3.9071223875230303`*^9, 3.907122451690057*^9}, {3.9071238096983986`*^9, 3.907123890636093*^9}, {3.9071239384807367`*^9, 3.9071239598451786`*^9}, { 3.907124000236956*^9, 3.9071240212072153`*^9}, {3.9071240759570227`*^9, 3.9071241108977203`*^9}, 3.9071306719481554`*^9, {3.9071405743339157`*^9, 3.9071405817024417`*^9}}, CellLabel-> "In[563]:=",ExpressionUUID->"8ca66f91-c76f-43fe-84e4-13e02511c1f8"], Cell[BoxData[ RowBox[{"validateModel", "[", "myPattern1", "]"}]], "Input", CellLabel-> "In[564]:=",ExpressionUUID->"7d57b9b2-a862-4e60-a677-00e78e7f068c"], Cell["\<\ Now the counters ca and cr can be removed from the model, because they were \ used only to guide the refinement. The a and r variables are sufficient (with \ proper guards) to maintain strong synchronization.\ \>", "Text",ExpressionUUID->"b0b4768f-1c39-4fb4-a96d-b3029fe949cc"] }, Closed]], Cell[CellGroupData[{ Cell["Requirements of the mechanical press", "Subsubsection",ExpressionUUID->"3cdda322-8524-4e33-88cb-eb80fbf34fed"], Cell[BoxData[ RowBox[{ RowBox[{"reqs", "=", RowBox[{"<|", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}]}], "\[IndentingNewLine]", "|>"}]}], ";"}]], "Input", CellLabel-> "In[565]:=",ExpressionUUID->"15fcc515-b283-4d43-b049-4f6bd111363e"] }, Closed]], Cell[CellGroupData[{ Cell["Initial model: connecting the controller to the motor", "Subsubsection",ExpressionUUID->"ab382c5d-789c-4ad2-a681-d31ce0bdf748"], Cell["\<\ The connections between components follow the action-reaction patterns above.\ \ \>", "Text",ExpressionUUID->"2b5da748-8f8e-4dcf-8d98-587f5ba2ec1f"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"status", "=", RowBox[{"{", RowBox[{"stopped", ",", "working"}], "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "helper", " ", "function", " ", "for", " ", "generating", " ", "statements", " ", "of", " ", "unique", " ", "elements", " ", "in", " ", "a", " ", "set"}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"uniqueElements", "[", "s_List", "]"}], ":=", RowBox[{"Unequal", "@@@", RowBox[{"Subsets", "[", RowBox[{"s", ",", RowBox[{"{", "2", "}"}]}], "]"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"uniqueElements", "[", "status", "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"motorSensor", "\[Element]", "status"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"motorActuator", "\[Element]", "status"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"motorSensor", "\[Rule]", "stopped"}], ",", RowBox[{"motorActuator", "\[Rule]", "stopped"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"controller", " ", RowBox[{"events", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"motorActuator", "\[Equal]", "stopped"}], ",", RowBox[{"motorSensor", "\[Equal]", "stopped"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"motorActuator", "\[Rule]", "working"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"motorActuator", "\[Equal]", "working"}], ",", RowBox[{"motorSensor", "\[Equal]", "working"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"motorActuator", "\[Rule]", "stopped"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"physical", " ", "reaction", " ", "of", " ", "the", " ", RowBox[{"motor", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"motorSensor", "\[Equal]", "stopped"}], ",", RowBox[{"motorActuator", "\[Equal]", "working"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"motorSensor", "\[Rule]", "working"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"motorSensor", "\[Equal]", "working"}], ",", RowBox[{"motorActuator", "\[Equal]", "stopped"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"motorSensor", "\[Rule]", "stopped"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[566]:=",ExpressionUUID->"fb32c732-0fe1-481f-ac83-8500629d0585"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellLabel-> "In[569]:=",ExpressionUUID->"4a7c4b8f-c227-4d47-9417-887aa027a00b"] }, Closed]], Cell[CellGroupData[{ Cell["\<\ First refinement: connecting the motor buttons to the controller\ \>", "Subsubsection",ExpressionUUID->"f3d13488-a114-42ac-ab03-5e9856aab605"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"physical", " ", "buttons", " ", RowBox[{"(", RowBox[{ "they", " ", "motivate", " ", "changes", " ", "in", " ", "controller", " ", "variables"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"stopMotorButton", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"startMotorButton", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "knowledge", " ", "of", " ", "physical", " ", "status", " ", "of", " ", "the", " ", "buttons"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"stopMotorImpulse", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"startMotorImpulse", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"stopMotorButton", "\[Element]", "Booleans"}], ",", RowBox[{"stopMotorButton", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"startMotorButton", "\[Element]", "Booleans"}], ",", RowBox[{"startMotorButton", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"stopMotorImpulse", "\[Element]", "Booleans"}], ",", RowBox[{"stopMotorImpulse", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"startMotorImpulse", "\[Element]", "Booleans"}], ",", RowBox[{"startMotorImpulse", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "events", " ", "representing", " ", "operations", " ", "on", " ", "physical", " ", "buttons"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"startMotorButton", "\[Equal]", "False"}], ",", RowBox[{"startMotorButton", "\[Rule]", "True"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"startMotorButton", "\[Equal]", "True"}], ",", RowBox[{"startMotorButton", "\[Rule]", "False"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "events", " ", "representing", " ", "the", " ", "influence", " ", "of", " ", "buttons", " ", "on", " ", "what", " ", "the", " ", "controller", " ", "knows"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "synchronization", " ", "between", " ", "physical", " ", "button", " ", "and", " ", "the", " ", "controller", " ", "knowledge", " ", "is", " ", "weak"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startMotorImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"startMotorButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"motorActuator", "\[Equal]", "stopped"}], ",", " ", RowBox[{"(*", " ", RowBox[{"old", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"motorSensor", "\[Equal]", "stopped"}]}], " ", RowBox[{"(*", " ", RowBox[{"old", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startMotorImpulse", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"motorActuator", "\[Rule]", "working"}]}], " ", RowBox[{"(*", " ", RowBox[{"old", " ", "action"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startMotorImpulse", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"startMotorButton", "\[Equal]", "False"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"startMotorImpulse", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "additional", " ", "\"\\"", " ", "event", " ", "to", " ", "deal", " ", "with", " ", "superposition", " ", "of", " ", RowBox[{"patterns", ":", "\[IndentingNewLine]", RowBox[{ "treat_push", "_start", "_motor", "_button", " ", "was", " ", "created", " ", "on", " ", "top", " ", "of", " ", "treat_start", "_motor", " ", "and", " ", "even", " ", "though", " ", "it", " ", "properly", " ", "strengthens", " ", "the", " ", "base", " ", "guard"}]}]}], ",", " ", RowBox[{ RowBox[{ "it", " ", "is", " ", "itself", " ", "not", " ", "completely", " ", "covered", " ", "if", " ", "the", " ", "base", " ", "guard", " ", "of", " ", "treat_start", "_motor", " ", "is", " ", "false"}], ";", " ", RowBox[{ "the", " ", "\"\\"", " ", "event", " ", "extends", " ", "the", " ", "overage", " ", "of", " ", "the", " ", "higher", " ", "pattern"}]}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startMotorImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"startMotorButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"Not", "[", RowBox[{ RowBox[{"motorActuator", "\[Equal]", "stopped"}], "&&", " ", RowBox[{"(*", " ", RowBox[{ "false", " ", "part", " ", "of", " ", "base", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"motorSensor", "\[Equal]", "stopped"}]}], " ", "]"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"startMotorImpulse", "\[Rule]", "True"}]}], " ", RowBox[{"(*", " ", RowBox[{"only", " ", "\"\\"", " ", "action"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "similarly", " ", "for", " ", "stopping", " ", "buttons", " ", "and", " ", "controls"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"stopMotorButton", "\[Equal]", "False"}], ",", RowBox[{"stopMotorButton", "\[Rule]", "True"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"stopMotorButton", "\[Equal]", "True"}], ",", RowBox[{"stopMotorButton", "\[Rule]", "False"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"stopMotorImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"stopMotorButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"motorSensor", "\[Equal]", "working"}], ",", "\[IndentingNewLine]", RowBox[{"motorActuator", "\[Equal]", "working"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"stopMotorImpulse", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"motorActuator", "\[Rule]", "stopped"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"stopMotorImpulse", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"stopMotorButton", "\[Equal]", "False"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"stopMotorImpulse", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"stopMotorImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"stopMotorButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"Not", "[", RowBox[{ RowBox[{"motorActuator", "\[Equal]", "working"}], "&&", "\[IndentingNewLine]", RowBox[{"motorSensor", "\[Equal]", "working"}]}], " ", "]"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"stopMotorImpulse", "\[Rule]", "True"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"0f436db3-4c8e-4ae4-a4ca-14e36b778268"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel-> "In[571]:=",ExpressionUUID->"08c37424-9c3a-40bb-9b06-0b54c4136aee"] }, Closed]], Cell[CellGroupData[{ Cell["Second refinement: connecting the controller to the clutch", \ "Subsubsection",ExpressionUUID->"bb46dac7-503d-49a9-8617-0883b8e498d0"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"clstatus", "=", RowBox[{"{", RowBox[{"engaged", ",", "disengaged"}], "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"uniqueElements", "[", "clstatus", "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"clutch", " ", "controller", " ", "variables"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"clutchSensor", "\[Element]", "clstatus"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"clutchActuator", "\[Element]", "clstatus"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"physical", " ", "buttons", " ", RowBox[{"(", RowBox[{ "they", " ", "motivate", " ", "changes", " ", "in", " ", "controller", " ", "variables"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"stopClutchButton", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"startClutchButton", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "knowledge", " ", "of", " ", "physical", " ", "status", " ", "of", " ", "the", " ", "buttons"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"stopClutchImpulse", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"startClutchImpulse", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"clutchSensor", "\[Element]", "clstatus"}], ",", RowBox[{"clutchSensor", "\[Rule]", "disengaged"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "\[Element]", "clstatus"}], ",", RowBox[{"clutchActuator", "\[Rule]", "disengaged"}], ",", "\[IndentingNewLine]", RowBox[{"stopClutchButton", "\[Element]", "Booleans"}], ",", RowBox[{"stopClutchButton", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"startClutchButton", "\[Element]", "Booleans"}], ",", RowBox[{"startClutchButton", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"stopClutchImpulse", "\[Element]", "Booleans"}], ",", RowBox[{"stopClutchImpulse", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"startClutchImpulse", "\[Element]", "Booleans"}], ",", RowBox[{"startClutchImpulse", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "events", " ", "representing", " ", "operations", " ", "on", " ", "physical", " ", "buttons"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"startClutchButton", "\[Equal]", "False"}], ",", RowBox[{"startClutchButton", "\[Rule]", "True"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"startClutchButton", "\[Equal]", "True"}], ",", RowBox[{"startClutchButton", "\[Rule]", "False"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "events", " ", "representing", " ", "the", " ", "influence", " ", "of", " ", "buttons", " ", "on", " ", "what", " ", "the", " ", "controller", " ", "knows"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"Note", ":", " ", RowBox[{ "this", " ", "event", " ", "does", " ", "not", " ", "refine", " ", "any", " ", "base", " ", "event", " ", RowBox[{"(", RowBox[{ "as", " ", "was", " ", "the", " ", "case", " ", "with", " ", "the", " ", "motor", " ", "in", " ", "myModel1"}], ")"}]}]}], ",", " ", RowBox[{ "because", " ", "both", " ", "physical", " ", "and", " ", "control", " ", "aspects", " ", "are", " ", "added", " ", "in", " ", "a", " ", "single", " ", "step"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startClutchImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"startClutchButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "\[Equal]", "disengaged"}], ",", "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Equal]", "disengaged"}]}], " ", "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startClutchImpulse", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "\[Rule]", "engaged"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startClutchImpulse", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"startClutchButton", "\[Equal]", "False"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"startClutchImpulse", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "additional", " ", "\"\\"", " ", "event", " ", "to", " ", "deal", " ", "with", " ", "superposition", " ", "of", " ", "patterns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startClutchImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"startClutchButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"Not", "[", RowBox[{ RowBox[{"clutchActuator", "\[Equal]", "disengaged"}], "&&", " ", RowBox[{"(*", " ", RowBox[{ "false", " ", "part", " ", "of", " ", "base", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Equal]", "disengaged"}]}], " ", "]"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"startClutchImpulse", "\[Rule]", "True"}]}], " ", RowBox[{"(*", " ", RowBox[{"only", " ", "\"\\"", " ", "action"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "similarly", " ", "for", " ", "stopping", " ", "buttons", " ", "and", " ", "controls"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"stopClutchButton", "\[Equal]", "False"}], ",", RowBox[{"stopClutchButton", "\[Rule]", "True"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"stopClutchButton", "\[Equal]", "True"}], ",", RowBox[{"stopClutchButton", "\[Rule]", "False"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"stopClutchImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"stopClutchButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Equal]", "working"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "\[Equal]", "working"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"stopClutchImpulse", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "\[Rule]", "disengaged"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"stopClutchImpulse", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"stopClutchButton", "\[Equal]", "False"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"stopClutchImpulse", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"stopClutchImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"stopClutchButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"Not", "[", RowBox[{ RowBox[{"clutchActuator", "\[Equal]", "engaged"}], "&&", "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Equal]", "engaged"}]}], " ", "]"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"stopClutchImpulse", "\[Rule]", "True"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"physical", " ", "reaction", " ", "of", " ", "the", " ", RowBox[{"clutch", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"clutchSensor", "\[Equal]", "disengaged"}], ",", RowBox[{"clutchActuator", "\[Equal]", "engaged"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Rule]", "engaged"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"clutchSensor", "\[Equal]", "engaged"}], ",", RowBox[{"clutchActuator", "\[Equal]", "disengaged"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Rule]", "disengaged"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input",ExpressionUUID->"61fd9636-0c2e-4529-8965-e64952259434"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel-> "In[574]:=",ExpressionUUID->"fa3b8872-ca4c-4054-beea-fa97e3f51dbd"] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Another pattern: weak synchronization of two strong reactions\ \>", "Subsubsection",ExpressionUUID->"692de66f-c32b-4fee-86dc-045dd6f814ee"], Cell["\<\ This pattern ensures that two reactions are strictly one-within-another in \ terms of time - that is, one (B) starts after the other (A) starts and it (B) \ finishes before the other (A) finishes. The coupling is weak in that the A \ \[OpenCurlyDoubleQuote]thing\[CloseCurlyDoubleQuote] can bounce up before the \ B \[OpenCurlyDoubleQuote]thing\[CloseCurlyDoubleQuote] starts and B can \ bounce down before A finishes.\ \>", "Text",ExpressionUUID->"eabc76e1-ff39-466d-9580-4113d25fde46"], Cell["\<\ The \[OpenCurlyDoubleQuote]outer thing\[CloseCurlyDoubleQuote] A has action a \ and reaction r, whereas the \[OpenCurlyDoubleQuote]inner thing\ \[CloseCurlyDoubleQuote] B has action b and reaction s.\ \>", "Text",ExpressionUUID->"de7a3129-1ded-41b6-8616-a16871b896ef"], Cell["\<\ The challenge is to couple these two patterns without modifying their \ reactive parts (r and s).\ \>", "Text",ExpressionUUID->"7819961b-f148-49e1-a91e-e77459e91c28"], Cell[BoxData[ RowBox[{ RowBox[{"myPattern2", "=", RowBox[{"model", "[", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "this", " ", "model", " ", "contains", " ", "both", " ", "patterns"}], ",", " ", RowBox[{"but", " ", "independent", " ", RowBox[{"(", RowBox[{"not", " ", "coupled"}], ")"}]}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "\[Element]", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"r", "\[Element]", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"ca", "\[Element]", "Integers"}], ",", RowBox[{"ca", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"cr", "\[Element]", "Integers"}], ",", RowBox[{"cr", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"a", "\[Equal]", "1"}], "&&", RowBox[{"r", "\[Equal]", "0"}]}], "\[Implies]", RowBox[{"ca", "\[Equal]", RowBox[{"cr", "+", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"a", "\[Equal]", "0"}], "||", RowBox[{"r", "\[Equal]", "1"}]}], "\[Implies]", RowBox[{"ca", "==", "cr"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"b", "\[Element]", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"s", "\[Element]", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"cb", "\[Element]", "Integers"}], ",", RowBox[{"cb", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"cs", "\[Element]", "Integers"}], ",", RowBox[{"cs", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"b", "\[Equal]", "1"}], "&&", RowBox[{"s", "\[Equal]", "0"}]}], "\[Implies]", RowBox[{"cb", "\[Equal]", RowBox[{"cs", "+", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"b", "\[Equal]", "0"}], "||", RowBox[{"s", "\[Equal]", "1"}]}], "\[Implies]", RowBox[{"cb", "==", "cs"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", "0"}], ",", RowBox[{"r", "\[Rule]", "0"}], ",", RowBox[{"ca", "\[Rule]", "0"}], ",", RowBox[{"cr", "\[Rule]", "0"}], ",", RowBox[{"b", "\[Rule]", "0"}], ",", RowBox[{"s", "\[Rule]", "0"}], ",", RowBox[{"cb", "\[Rule]", "0"}], ",", RowBox[{"cs", "\[Rule]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"separate", " ", "patterns", " ", "for", " ", "A", " ", RowBox[{"(", RowBox[{"a", "/", "r"}], ")"}], " ", "and", " ", "B", " ", RowBox[{"(", RowBox[{"b", "/", "s"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", "\[Equal]", "0"}], ",", RowBox[{"r", "\[Equal]", "0"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"a", "\[Rule]", "1"}], ",", RowBox[{"ca", "\[Rule]", RowBox[{"ca", "+", "1"}]}]}], "}"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", "\[Equal]", "1"}], ",", RowBox[{"r", "\[Equal]", "1"}]}], "}"}], ",", RowBox[{"a", "\[Rule]", "0"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"r", "\[Equal]", "0"}], ",", RowBox[{"a", "\[Equal]", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"r", "\[Rule]", "1"}], ",", RowBox[{"cr", "\[Rule]", RowBox[{"cr", "+", "1"}]}]}], "}"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"r", "\[Equal]", "1"}], ",", RowBox[{"a", "\[Equal]", "0"}]}], "}"}], ",", RowBox[{"r", "\[Rule]", "0"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"b", "\[Equal]", "0"}], ",", RowBox[{"s", "\[Equal]", "0"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"b", "\[Rule]", "1"}], ",", RowBox[{"cb", "\[Rule]", RowBox[{"cb", "+", "1"}]}]}], "}"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"b", "\[Equal]", "1"}], ",", RowBox[{"s", "\[Equal]", "1"}]}], "}"}], ",", RowBox[{"b", "\[Rule]", "0"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"s", "\[Equal]", "0"}], ",", RowBox[{"b", "\[Equal]", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"s", "\[Rule]", "1"}], ",", RowBox[{"cs", "\[Rule]", RowBox[{"cs", "+", "1"}]}]}], "}"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"s", "\[Equal]", "1"}], ",", RowBox[{"b", "\[Equal]", "0"}]}], "}"}], ",", RowBox[{"s", "\[Rule]", "0"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[575]:=",ExpressionUUID->"3f1d3dcc-50c2-4ca3-a1ca-6af7bfc78f8d"], Cell[BoxData[ RowBox[{"validateModel", "[", "myPattern2", "]"}]], "Input", CellLabel-> "In[576]:=",ExpressionUUID->"cb079c4d-d0d9-49f1-a47d-74216e5d2b74"], Cell[BoxData[ RowBox[{ RowBox[{"myPattern3", "=", RowBox[{"model", "[", " ", RowBox[{"(*", " ", RowBox[{ "this", " ", "model", " ", "couples", " ", "two", " ", "patterns"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myPattern2", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "the", " ", "constraint", " ", "that", " ", "weakly", " ", "couples", " ", "both", " ", "patterns", " ", "from", " ", "myPattern2"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"s", "\[Equal]", "1"}], "\[Implies]", RowBox[{"r", "\[Equal]", "1"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "the", " ", "following", " ", "refinements", " ", "for", " ", "the", " ", "coupling", " ", "invariant", " ", "above", " ", "are", " ", "sufficient", " ", "for", " ", "proper", " ", "operation"}], ",", " ", RowBox[{ RowBox[{ "but", " ", "the", " ", "challenge", " ", "here", " ", "is", " ", "not", " ", "to", " ", "modify", " ", "the", " ", "events"}], "..."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", "\[IndentingNewLine]", RowBox[{ RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"s", "\[Equal]", "0"}], ",", RowBox[{"b", "\[Equal]", "1"}], ",", RowBox[{"r", "\[Equal]", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"s", "\[Rule]", "1"}], ",", RowBox[{"cs", "\[Rule]", RowBox[{"cs", "+", "1"}]}]}], "}"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"r", "\[Equal]", "1"}], ",", RowBox[{"a", "\[Equal]", "0"}], ",", RowBox[{"s", "\[Equal]", "0"}]}], "}"}], ",", RowBox[{"r", "\[Rule]", "0"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "...", " ", "so", " ", "we", " ", "can", " ", "modify", " ", "the", " ", "action", " ", "events", " ", RowBox[{"instead", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"b", "\[Equal]", "1"}], "\[Implies]", RowBox[{"r", "\[Equal]", "1"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"B", "'"}], "s", " ", "action", " ", "happens", " ", "after", " ", RowBox[{"A", "'"}], "s", " ", "reaction"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"a", "\[Equal]", "0"}], "\[Implies]", RowBox[{"s", "\[Equal]", "0"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"A", "'"}], "s", " ", "action", " ", "goes", " ", "down", " ", "after", " ", RowBox[{"B", "'"}], "s", " ", "reaction"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{"s", "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{"r", "\[Equal]", "1"}], " ", ",", RowBox[{"a", "\[Equal]", "1"}]}], RowBox[{"(*", " ", RowBox[{"additional", " ", RowBox[{"(", "constraining", ")"}], " ", "guards"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"b", "\[Rule]", "1"}], ",", RowBox[{"cb", "\[Rule]", RowBox[{"cb", "+", "1"}]}]}], "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"a", "\[Equal]", "0"}], "\[Implies]", RowBox[{"s", "\[Equal]", "0"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"A", "'"}], "s", " ", "action", " ", "goes", " ", "down", " ", "after", " ", RowBox[{"B", "'"}], "s", " ", "reaction"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"a", "\[Equal]", "0"}], "\[Implies]", RowBox[{"b", "\[Equal]", "0"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"to", " ", "support", " ", "dbl1_", "3"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"r", "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"s", "\[Equal]", "0"}], " ", ",", RowBox[{"b", "\[Equal]", "0"}]}], RowBox[{"(*", " ", RowBox[{"additional", " ", RowBox[{"(", "constraining", ")"}], " ", "guards"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", "0"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[579]:=",ExpressionUUID->"32c2e8eb-587d-4b76-9c50-439da1b832d8"], Cell[BoxData[ RowBox[{"validateModel", "[", "myPattern3", "]"}]], "Input", CellLabel-> "In[580]:=",ExpressionUUID->"e6541e95-0e5d-465e-b2be-a444148ab23a"] }, Closed]], Cell[CellGroupData[{ Cell["Third refinement: constraining the clutch and the motor", \ "Subsubsection",ExpressionUUID->"9bc4d197-f4d4-4500-be8b-cc3bf118a021"], Cell["\<\ The application of the pattern above in the model is needed, because:\ \>", "Text",ExpressionUUID->"8fa3d95c-16de-427f-a1f0-afb830e5ee44"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"reqs", "[", "\"\\"", "]"}]], "Input", CellLabel-> "In[581]:=",ExpressionUUID->"a65865e1-88a3-4fa4-ad4e-884648d1ee3e"], Cell[BoxData["\<\"When the clutch is engaged, the motor must work.\"\>"], \ "Output", CellLabel-> "Out[581]=",ExpressionUUID->"f7cef664-63e3-4499-90fc-727c4da3a4c1"] }, Open ]], Cell[BoxData[ RowBox[{ RowBox[{"myModel3", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel2", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"clutchSensor", "\[Equal]", "engaged"}], "\[Implies]", RowBox[{"motorSensor", "\[Equal]", "working"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"clutchActuator", "\[Equal]", "engaged"}], "\[Implies]", RowBox[{"motorSensor", "\[Equal]", "working"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"motorActuator", "\[Equal]", "stopped"}], "\[Implies]", RowBox[{"clutchSensor", "\[Equal]", "disengaged"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"motorActuator", "\[Equal]", "stopped"}], "\[Implies]", RowBox[{"clutchActuator", "\[Equal]", "disengaged"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refinement", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startClutchImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"startClutchButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "\[Equal]", "disengaged"}], ",", "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Equal]", "disengaged"}], ",", "\[IndentingNewLine]", RowBox[{"motorSensor", "\[Equal]", "working"}], ",", RowBox[{"(*", " ", RowBox[{"additional", " ", RowBox[{"(", "constraining", ")"}], " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"motorActuator", "\[Equal]", "working"}]}], " ", RowBox[{"(*", " ", "ditto", " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startClutchImpulse", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "->", "engaged"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refinement", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"stopMotorImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"stopMotorButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"motorActuator", "\[Equal]", "working"}], ",", "\[IndentingNewLine]", RowBox[{"motorSensor", "\[Equal]", "working"}], ",", "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Equal]", "disengaged"}], ",", RowBox[{"(*", " ", RowBox[{"additional", " ", RowBox[{"(", "constraining", ")"}], " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"clutchActuator", "\[Equal]", "disengaged"}]}], " ", RowBox[{"(*", " ", "ditto", " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"motorActuator", "\[Rule]", "stopped"}], ",", "\[IndentingNewLine]", RowBox[{"stopMotorImpulse", "\[Rule]", "True"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[582]:=",ExpressionUUID->"62b4cf68-8cb9-4222-8a70-247c87cf3910"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel3", "]"}]], "Input", CellLabel-> "In[583]:=",ExpressionUUID->"b67ddfd2-8029-4e81-938c-891c63775f95"] }, Closed]], Cell[CellGroupData[{ Cell["Fourth refinement: connecting the controller to the door", \ "Subsubsection",ExpressionUUID->"40796ccd-efe1-4503-99f3-8b0967d21990"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"dstatus", "=", RowBox[{"{", RowBox[{"open", ",", "closed"}], "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "helper", " ", "function", " ", "for", " ", "generating", " ", "statements", " ", "of", " ", "unique", " ", "elements", " ", "in", " ", "a", " ", "set"}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"uniqueElements", "[", "s_List", "]"}], ":=", RowBox[{"Unequal", "@@@", RowBox[{"Subsets", "[", RowBox[{"s", ",", RowBox[{"{", "2", "}"}]}], "]"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel4", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel3", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"uniqueElements", "[", "dstatus", "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"doorSensor", "\[Element]", "dstatus"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"doorActuator", "\[Element]", "dstatus"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"doorSensor", "\[Rule]", "closed"}], ",", RowBox[{"doorActuator", "\[Rule]", "closed"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"controller", " ", RowBox[{"events", ":"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"doorActuator", "\[Equal]", "closed"}], ",", RowBox[{"doorSensor", "\[Equal]", "closed"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"doorActuator", "\[Rule]", "open"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"doorActuator", "\[Equal]", "open"}], ",", RowBox[{"doorSensor", "\[Equal]", "open"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"doorActuator", "\[Rule]", "closed"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"physical", " ", "reaction", " ", "of", " ", "the", " ", RowBox[{"door", ":"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"doorSensor", "\[Equal]", "closed"}], ",", RowBox[{"doorActuator", "\[Equal]", "open"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"doorSensor", "\[Rule]", "open"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"doorSensor", "\[Equal]", "open"}], ",", RowBox[{"doorActuator", "\[Equal]", "closed"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"doorSensor", "\[Rule]", "closed"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[584]:=",ExpressionUUID->"7354b233-06bf-4ac1-8682-816fe2fd7cb3"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel4", "]"}]], "Input",ExpressionUUID->"b975566e-ee49-4acb-81de-9a7ad16b1bd1"] }, Closed]], Cell[CellGroupData[{ Cell["Fifth refinement: constraining the clutch and the door", "Subsubsection",ExpressionUUID->"f7c62710-4451-4bf1-b95a-b7582bbac10c"], Cell["\<\ Additional constraints due to the following existing requirement:\ \>", "Text",ExpressionUUID->"c876ae1f-f397-487c-ac20-9078d9efc762"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"reqs", "[", "\"\\"", "]"}]], "Input", CellLabel-> "In[588]:=",ExpressionUUID->"ce04df1b-e09b-40af-8b65-b06494342fdf"], Cell[BoxData["\<\"When the clutch is engaged, the door must be closed.\"\>"], \ "Output", CellLabel-> "Out[588]=",ExpressionUUID->"954cd670-2985-4d1a-8bc9-a7ec2837e3db"] }, Open ]], Cell["This has to be complemented with additional requirement:", "Text",ExpressionUUID->"c00908cb-639d-4a3e-ba39-85c307e7093f"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"reqs", "[", "\"\\"", "]"}], "=", "\"\\""}], ";"}]], "Input", CellLabel-> "In[589]:=",ExpressionUUID->"303fbf6f-2056-46df-af63-7a79264d4b70"], Cell["\<\ Then the pattern from 3rd refinement can be repeated for clutch and door:\ \>", "Text",ExpressionUUID->"e06d1b20-4648-412a-a5c6-09fdc9c159c3"], Cell[BoxData[ RowBox[{ RowBox[{"myModel5", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel4", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"clutchSensor", "\[Equal]", "engaged"}], "\[Implies]", RowBox[{"doorSensor", "\[Equal]", "closed"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"clutchActuator", "\[Equal]", "engaged"}], "\[Implies]", RowBox[{"doorSensor", "\[Equal]", "closed"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"doorActuator", "\[Equal]", "open"}], "\[Implies]", RowBox[{"clutchSensor", "\[Equal]", "disengaged"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"doorActuator", "\[Equal]", "open"}], "\[Implies]", RowBox[{"clutchActuator", "\[Equal]", "disengaged"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refinement", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startClutchImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"startClutchButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "\[Equal]", "disengaged"}], ",", "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Equal]", "disengaged"}], ",", "\[IndentingNewLine]", RowBox[{"motorSensor", "\[Equal]", "working"}], ",", "\[IndentingNewLine]", RowBox[{"motorActuator", "\[Equal]", "working"}], " ", ",", "\[IndentingNewLine]", RowBox[{"doorSensor", "\[Equal]", "closed"}], ",", RowBox[{"(*", " ", RowBox[{"additional", " ", RowBox[{"(", "constraining", ")"}], " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"doorActuator", "\[Equal]", "closed"}]}], " ", RowBox[{"(*", " ", "ditto", " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startClutchImpulse", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "->", "engaged"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refinement", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"doorActuator", "\[Equal]", "closed"}], ",", "\[IndentingNewLine]", RowBox[{"doorSensor", "\[Equal]", "closed"}], ",", "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Equal]", "disengaged"}], ",", RowBox[{"(*", " ", RowBox[{"additional", " ", RowBox[{"(", "constraining", ")"}], " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"clutchActuator", "\[Equal]", "disengaged"}]}], " ", RowBox[{"(*", " ", "ditto", " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"doorActuator", "\[Rule]", "open"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[590]:=",ExpressionUUID->"0028406f-7b94-4021-9d22-01de61e46862"], Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"myModel5", "\[InvisibleSpace]", ",", RowBox[{"parallel", "->", "True"}]}], "]"}]], "Input",ExpressionUUID->\ "23f4b42d-05bd-43f9-aadb-ec91468ab25f"] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Another pattern: strong synchronization of two strong reactions\ \>", "Subsubsection",ExpressionUUID->"63aca57a-3701-4df1-87aa-ba667a1b93fe"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"reqs", "[", "\"\\"", "]"}]], "Input", CellLabel-> "In[592]:=",ExpressionUUID->"5d9da396-18af-4e8d-9a34-356abbeabd57"], Cell[BoxData["\<\"When the door is closed, the clutch cannot be disengaged \ several times, ONLY ONCE.\"\>"], "Output", CellLabel-> "Out[592]=",ExpressionUUID->"7f968fec-08ca-4a91-9ea8-7a334d2f3f08"] }, Open ]], Cell["\<\ This pattern ensures that two reactions are strictly one-within-another in \ terms of time - that is, one (B) starts after the other (A) starts and it (B) \ finishes before the other (A) finishes. The coupling is strong in that the A \ and B \[OpenCurlyDoubleQuote]things\[CloseCurlyDoubleQuote] can switch only \ once between each other.\ \>", "Text",ExpressionUUID->"9f3fc4be-01a1-4a6a-bf8e-937a51ac3129"], Cell["\<\ The A \[OpenCurlyDoubleQuote]thing\[CloseCurlyDoubleQuote] has action a and \ reaction r, whereas the \[OpenCurlyDoubleQuote]thing\[CloseCurlyDoubleQuote] \ B has action b and reaction s.\ \>", "Text",ExpressionUUID->"f6600f80-b74d-450f-b0b3-8d5ad6276b32"], Cell["\<\ The challenge is to couple these two patterns without modifying their \ reactive parts (r and s).\ \>", "Text",ExpressionUUID->"6a33adc7-22b9-42b2-b80a-b041b21a8fef"], Cell[BoxData[ RowBox[{ RowBox[{"myPattern4", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myPattern3", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "m", " ", "handles", " ", "the", " ", "\"\\"", " ", "of", " ", "the", " ", "cycle", " ", "between", " ", "A", " ", "and", " ", "B"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"m", "\[Element]", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"m", "\[Equal]", "1"}], "\[Implies]", RowBox[{"ca", "\[Equal]", RowBox[{"cb", "+", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"m", "\[Equal]", "0"}], "\[Implies]", RowBox[{"ca", "\[Equal]", "cb"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"r", "\[Equal]", "1"}], "&&", RowBox[{"s", "\[Equal]", "0"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"m", "\[Equal]", "1"}], "||", RowBox[{"b", "\[Equal]", "1"}]}], ")"}]}], "\[Implies]", RowBox[{"cr", "\[Equal]", RowBox[{"cs", "+", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"r", "\[Equal]", "0"}], "||", RowBox[{"s", "\[Equal]", "1"}], "||", RowBox[{"(", RowBox[{ RowBox[{"m", "\[Equal]", "0"}], "&&", RowBox[{"b", "\[Equal]", "0"}]}], ")"}]}], "\[Implies]", RowBox[{"cr", "\[Equal]", "cs"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"m", "\[Equal]", "0"}], "\[Implies]", RowBox[{ RowBox[{"a", "\[Equal]", "0"}], "||", RowBox[{"r", "\[Equal]", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"m", "\[Equal]", "1"}], "\[Implies]", RowBox[{ RowBox[{"b", "\[Equal]", "0"}], "&&", RowBox[{"s", "\[Equal]", "0"}], "&&", RowBox[{"a", "\[Equal]", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"m", "\[Rule]", "0"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refining", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", "\[Equal]", "0"}], ",", RowBox[{"r", "\[Equal]", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Rule]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"ca", "\[Rule]", RowBox[{"ca", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"m", "\[Rule]", "1"}]}], " ", RowBox[{"(*", " ", RowBox[{"new", " ", "action"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refining", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "\[Equal]", "0"}], ",", RowBox[{"s", "\[Equal]", "0"}], ",", RowBox[{"r", "\[Equal]", "1"}], " ", ",", RowBox[{"a", "\[Equal]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"m", "\[Equal]", "1"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "\[Rule]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"cb", "\[Rule]", RowBox[{"cb", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"m", "\[Rule]", "0"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "action"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refining", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "\[Equal]", "1"}], ",", RowBox[{"r", "\[Equal]", "1"}], ",", RowBox[{"s", "\[Equal]", "0"}], " ", ",", RowBox[{"b", "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{"m", "\[Equal]", "0"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", "0"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[593]:=",ExpressionUUID->"ee5c85f0-fc41-44bb-9d1a-80f95a201095"], Cell[BoxData[ RowBox[{"validateModel", "[", "myPattern4", "]"}]], "Input", CellLabel-> "In[594]:=",ExpressionUUID->"b74a6fdd-61cc-4ef1-b422-111a0b561fdc"] }, Closed]], Cell[CellGroupData[{ Cell["Sixth refinement: more constraints between clutch and door", \ "Subsubsection",ExpressionUUID->"77fc041e-fb4c-4f87-83d7-d463b839f296"], Cell["\<\ This refinement applies strong-strong pattern over the 5th refinement.\ \>", "Text",ExpressionUUID->"e9e373bf-19c1-411d-95f2-7fadd74bec3b"], Cell[BoxData[ RowBox[{ RowBox[{"myModel6", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel5", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "this", " ", "invariant", " ", "is", " ", "copied", " ", "from", " ", "base", " ", "models", " ", "to", " ", "support", " ", "piecewise", " ", "computation", " ", "of", " ", "deadlock", " ", "freedom", " ", RowBox[{"(", RowBox[{ "it", " ", "takes", " ", "infinitely", " ", "long", " ", "without", " ", "it"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"startClutchButton", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"again", ",", " ", RowBox[{ "variable", " ", "m", " ", "controls", " ", "the", " ", "\"\\"", " ", "of", " ", "interaction"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refinement", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"doorActuator", "\[Equal]", "open"}], ",", "\[IndentingNewLine]", RowBox[{"doorSensor", "\[Equal]", "open"}], ",", "\[IndentingNewLine]", RowBox[{"motorActuator", "\[Equal]", "working"}], ",", "\[IndentingNewLine]", RowBox[{"motorSensor", "\[Equal]", "working"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"doorActuator", "\[Rule]", "closed"}], ",", "\[IndentingNewLine]", RowBox[{"m", "\[Rule]", "1"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "action"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refinement", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startClutchImpulse", "\[Equal]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"startClutchButton", "\[Equal]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "\[Equal]", "disengaged"}], ",", "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Equal]", "disengaged"}], ",", "\[IndentingNewLine]", RowBox[{"motorSensor", "\[Equal]", "working"}], ",", "\[IndentingNewLine]", RowBox[{"motorActuator", "\[Equal]", "working"}], " ", ",", "\[IndentingNewLine]", RowBox[{"doorSensor", "\[Equal]", "closed"}], ",", "\[IndentingNewLine]", RowBox[{"doorActuator", "\[Equal]", "closed"}], ",", "\[IndentingNewLine]", RowBox[{"m", "\[Equal]", "1"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"startClutchImpulse", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "->", "engaged"}], ",", "\[IndentingNewLine]", RowBox[{"m", "\[Rule]", "0"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "action"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refinement", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"doorActuator", "\[Equal]", "closed"}], ",", "\[IndentingNewLine]", RowBox[{"doorSensor", "\[Equal]", "closed"}], ",", "\[IndentingNewLine]", RowBox[{"clutchSensor", "\[Equal]", "disengaged"}], ",", "\[IndentingNewLine]", RowBox[{"clutchActuator", "\[Equal]", "disengaged"}], ",", "\[IndentingNewLine]", RowBox[{"m", "\[Equal]", "0"}]}], " ", RowBox[{"(*", " ", RowBox[{"additional", " ", "guard"}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"doorActuator", "\[Rule]", "open"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[597]:=",ExpressionUUID->"429ee9c3-fc20-4a14-87f7-5cdae997ca63"], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ "this", " ", "validates", " ", "everything", " ", "except", " ", "the", " ", "deadlock", " ", "freedom"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"validateModel", "[", RowBox[{"myModel6", ",", RowBox[{"onlyPhase", "->", RowBox[{"\"\\"", "|", "\"\\"", "|", "\"\\"", "|", "\"\\"", "|", "\"\\"", "|", "\"\\""}]}]}], "]"}]}]], "Input",ExpressionUUID->\ "f327440a-00f4-4b19-b28c-c24ee7ed2a91"], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ "this", " ", "efficiently", " ", "validates", " ", "the", " ", "deadlock", " ", "freedom", " ", RowBox[{"(", RowBox[{ RowBox[{ "which", " ", "takes", " ", "infinitely", " ", "long", " ", "with", " ", "default", " ", "method"}], "\[Rule]", "Whole"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"validateModel", "[", RowBox[{"myModel6", ",", RowBox[{"onlyPhase", "->", "\"\\""}], ",", RowBox[{"method", "\[Rule]", "Piecewise"}]}], "]"}]}]], "Input", CellLabel-> "In[607]:=",ExpressionUUID->"0ee37682-e3c4-44fd-b1da-ec96bf9e07af"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Template for simple inductive theorems", "Subsection",ExpressionUUID->"563624ef-c592-495a-b9fe-fa7380145cf1"], Cell["\<\ This template demonstrates how a simple theorem can be injected in the model \ validator.\ \>", "Text",ExpressionUUID->"5466e09e-7549-4a8c-82f0-110232b480b3"], Cell["\<\ Example: - 0 is considered an even number - any number that is +2 some other even number is also even\ \>", "Text",ExpressionUUID->"e3841b17-91c3-45f9-99f3-342b795c5e55"], Cell["\<\ More formally, let even[x] be a statement about x being even, then:\ \>", "Text",ExpressionUUID->"1a3e2a2a-ddfa-45ca-b788-61d060d14b46"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Column", "[", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"even", "[", "0", "]"}], "==", "True"}], ",", RowBox[{"ForAll", "[", RowBox[{"x", ",", RowBox[{"x", ">", "0"}], ",", RowBox[{ RowBox[{"even", "[", "x", "]"}], "\[Implies]", RowBox[{"even", "[", RowBox[{"x", "+", "2"}], "]"}]}]}], "]"}]}], "}"}], "]"}]], "Input", CellLabel-> "In[610]:=",ExpressionUUID->"6be5ae13-3a4d-4f3b-a31a-1e1078451286"], Cell[BoxData[ TagBox[GridBox[{ { RowBox[{ RowBox[{"even", "[", "0", "]"}], "\[Equal]", "True"}]}, { RowBox[{ SubscriptBox["\[ForAll]", RowBox[{"x", ",", RowBox[{"x", ">", "0"}]}]], RowBox[{"(", RowBox[{ RowBox[{"even", "[", "x", "]"}], "\[Implies]", RowBox[{"even", "[", RowBox[{"2", "+", "x"}], "]"}]}], ")"}]}]} }, DefaultBaseStyle->"Column", GridBoxAlignment->{"Columns" -> {{Left}}}, GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}], "Column"]], "Output", CellLabel-> "Out[610]=",ExpressionUUID->"4a3d773f-bd3d-4606-b88d-d9a086616508"] }, {2}]], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{"template", " ", "for", " ", "simple", " ", RowBox[{"(", RowBox[{"one", "-", "variable"}], ")"}], " ", "inductive", " ", "theorems"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"evenTheorem", "[", RowBox[{"knowns_", ",", "question_"}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "knownEvens", ",", "\[IndentingNewLine]", "newKnowns", ",", "\[IndentingNewLine]", "newQuestion"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"knownEvens", "=", RowBox[{"Cases", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"even", "[", "0", "]"}], ",", "knowns"}], "}"}], ",", RowBox[{ RowBox[{"even", "[", "v_", "]"}], "\[RuleDelayed]", "v"}], ",", RowBox[{"{", RowBox[{"0", ",", "Infinity"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"newKnowns", "=", RowBox[{"DeleteCases", "[", RowBox[{"knowns", ",", "_even", ",", RowBox[{"{", RowBox[{"0", ",", "Infinity"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"newQuestion", "=", RowBox[{"question", "/.", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qe", ",", " ", RowBox[{"(*", " ", RowBox[{"qe", " ", "is", " ", RowBox[{"even", "[", "...", "]"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{"v", "=", RowBox[{"qe", "[", RowBox[{"[", "1", "]"}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"value", " ", "tested"}], ",", " ", RowBox[{"like", " ", "in", " ", RowBox[{"even", "[", "v", "]"}]}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"qe", "\[Rule]", RowBox[{"Or", "@@", RowBox[{"Map", "[", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "qe", " ", "is", " ", "replaced", " ", "with", " ", "Or"}], "-", RowBox[{ "ed", " ", "test", " ", "against", " ", "all", " ", "known", " ", "evens"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"e", ",", " ", RowBox[{"(*", " ", RowBox[{ "e", " ", "is", " ", "some", " ", "known", " ", "even", " ", "value", " ", RowBox[{"(", RowBox[{"including", " ", "starting", " ", "0"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"v", "\[Equal]", "e"}], "||", RowBox[{"v", "\[Equal]", RowBox[{"e", "+", "2"}]}]}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"v", " ", "is", " ", "even"}], ",", " ", RowBox[{ RowBox[{ "if", " ", "equal", " ", "to", " ", "some", " ", "known", " ", "even", " ", "or"}], " ", "+", "2"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "knownEvens"}], "\[IndentingNewLine]", "]"}]}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Cases", "[", RowBox[{"question", ",", "_even", ",", RowBox[{"{", RowBox[{"0", ",", "Infinity"}], "}"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"newKnowns", ",", "newQuestion"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}]}]], "Input", CellLabel-> "In[611]:=",ExpressionUUID->"208c53cc-262f-4094-9f97-3f5f156472d5"], Cell["\<\ Such a function can be provided as a hint to the model and will be used to \ pre-process the knowns and the question before the actual deduction.\ \>", "Text",ExpressionUUID->"cba54afc-a22a-4880-b38c-ce007d73cb2c"], Cell["\<\ The following model with invariant that a counter remains even based on the \ above inductive theorem can validate properly:\ \>", "Text",ExpressionUUID->"dcb87c02-e98d-46ef-87c6-37f485b54462"], Cell[BoxData[ RowBox[{ RowBox[{"m", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", "evenTheorem"}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "the", " ", "evenTheorem", " ", "applied", " ", "to", " ", "the", " ", "model"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "\[Element]", "Integers"}], ",", RowBox[{"n", "\[GreaterEqual]", "0"}], ",", " ", RowBox[{"(*", " ", "counter", " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"even", "[", "n", "]"}], "\[Equal]", "True"}]}], " ", RowBox[{"(*", " ", RowBox[{ "we", " ", "want", " ", "the", " ", "counter", " ", "to", " ", "always", " ", "remain", " ", "even"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"n", "\[Rule]", "0"}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "counter", " ", "is", " ", "even", " ", "at", " ", "the", " ", "beginning"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"n", "<", "1000"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"n", "\[Rule]", RowBox[{"n", "+", "2"}]}], RowBox[{"(*", " ", RowBox[{ "does", " ", "the", " ", "counter", " ", "remain", " ", "even", " ", "all", " ", "the", " ", RowBox[{"time", "?"}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[612]:=",ExpressionUUID->"6871c2e9-0ec3-4451-9e06-9bbafef7240c"], Cell[BoxData[ RowBox[{"validateModel", "[", "m", "]"}]], "Input", CellLabel-> "In[613]:=",ExpressionUUID->"6fe77fee-47dd-4d45-ad71-48c98ddfcbec"] }, Closed]], Cell[CellGroupData[{ Cell["Model - simple file transfer protocol", "Subsection",ExpressionUUID->"8a7af492-c322-44b5-9faa-ad3787ac9ee6"], Cell["\<\ This example is based on chapter 4 of the \[OpenCurlyDoubleQuote]Modeling in \ Event-B\[CloseCurlyDoubleQuote] book by Jean-Raymond Abrial.\ \>", "Text",ExpressionUUID->"5ccff6a7-ec82-47c9-8053-e847f397ff13"], Cell[CellGroupData[{ Cell["Requirements", "Subsubsection",ExpressionUUID->"1d6f5e20-5460-4d11-890c-779e9c730e8a"], Cell[BoxData[ RowBox[{ RowBox[{"reqs", "=", RowBox[{"<|", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "->", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "->", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "->", "\"\\""}]}], "\[IndentingNewLine]", "|>"}]}], ";"}]], "Input", CellLabel-> "In[614]:=",ExpressionUUID->"68a38dac-8a76-4c3e-b4a3-484cc829320a"] }, Closed]], Cell[CellGroupData[{ Cell["Initial model", "Subsubsection",ExpressionUUID->"a0aee41f-a7e8-4b32-82de-90f880496337"], Cell["\<\ The model assumes that file elements are transmitted sequentially, from the \ beginning to the end - it is not based on the notion of \ \[OpenCurlyDoubleQuote]partial function\[CloseCurlyDoubleQuote] on a given \ interval. Constant f represents a file to be copied, variable g is a copied file that \ in this high-level view just transitions from \[OpenCurlyDoubleQuote]not \ copied\[CloseCurlyDoubleQuote] to \[OpenCurlyDoubleQuote]copied\ \[CloseCurlyDoubleQuote].\ \>", "Text",ExpressionUUID->"6c65192d-b334-477b-bcb6-853b3a8ca96d"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"n", "\[Element]", "Integers"}], ",", RowBox[{"n", ">", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"f", "\[Element]", "Span"}], ",", RowBox[{"f", "==", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"b", "\[Element]", "Booleans"}], ",", RowBox[{"g", "\[Element]", "Span"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"b", "==", "False"}], "\[Implies]", RowBox[{"g", "==", "\[EmptySet]"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"b", "==", "True"}], "\[Implies]", RowBox[{"g", "==", "f"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"g", "->", "\[EmptySet]"}], ",", "\[IndentingNewLine]", RowBox[{"b", "\[Element]", "Booleans"}], ",", RowBox[{"b", "->", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "this", " ", "is", " ", "\"\\"", " ", "event", " ", "that", " ", "allows", " ", "to", " ", "observe", " ", "that", " ", "the", " ", "file", " ", "was", " ", "copied"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"b", "==", "False"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"g", "->", "f"}], ",", "\[IndentingNewLine]", RowBox[{"b", "->", "True"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"911910ab-\ a4b4-4bf4-9a25-f864917f2504"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellLabel-> "In[624]:=",ExpressionUUID->"b0aa1fd6-8650-4958-a0f7-4d3a0356f0ff"] }, Closed]], Cell[CellGroupData[{ Cell["First refinement", "Subsubsection",ExpressionUUID->"98b77193-4284-4f61-8c38-2be3d91f813a"], Cell["\<\ This refinement introduces variable h that represents the part of file that \ was already copied; the index r is one-past-the-end for that copied part. New \ event receive allows to \ \[OpenCurlyDoubleQuote]observe\[CloseCurlyDoubleQuote] the process of file \ transfer in more granularity.\ \>", "Text",ExpressionUUID->"b767efd0-80b6-4223-a619-a3da035685e8"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"r", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", RowBox[{"n", "+", "1"}]}], "]"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"file", " ", "index"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"h", "\[Element]", "Span"}], ",", RowBox[{"h", "==", RowBox[{"Span", "[", RowBox[{"1", ",", RowBox[{"r", "-", "1"}]}], "]"}]}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"h", " ", "\[SubsetEqual]", " ", "f"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"b", "==", "True"}], "\[Implies]", RowBox[{"r", "==", RowBox[{"n", "+", "1"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"h", "\[Element]", "Span"}], ",", " ", RowBox[{"(*", " ", RowBox[{"note", ":", " ", RowBox[{ "necessary", " ", "for", " ", "proper", " ", "processing", " ", "of", " ", "the", " ", "following"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"h", "->", RowBox[{"Span", "[", RowBox[{"1", ",", "0"}], "]"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"\[EmptySet]", ",", " ", RowBox[{ "but", " ", "with", " ", "lower", " ", "bound", " ", "already", " ", "established"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"r", "->", "1"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"for", " ", "event", " ", "receive"}], ",", " ", RowBox[{ "which", " ", "is", " ", "limited", " ", "by", " ", "file", " ", "size"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "+", "1", "-", "r"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"r", "<=", "n"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"h", "->", RowBox[{"h", "+", "r"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "span", " ", "h", " ", "extends", " ", "one", " ", "element", " ", "up"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"r", "->", RowBox[{"r", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refining", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"r", "==", RowBox[{"n", "+", "1"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"all", " ", "elements", " ", "copied"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"b", "==", "False"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"b", "->", "True"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[636]:=",ExpressionUUID->"820c5a4d-cdbd-4595-9858-933e19827f2e"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel-> "In[637]:=",ExpressionUUID->"1f07e70f-19dd-42a9-ad8a-e5105494fd8a"] }, Closed]], Cell[CellGroupData[{ Cell["Second refinement", "Subsubsection",ExpressionUUID->"91d408af-c1e4-493a-a3c9-af1fea426570"], Cell["\<\ This refinement introduces even more granularity with new event send. The \ index s points to the element that was just sent. This model does not take \ into account the actual values of \[OpenCurlyDoubleQuote]transmitted\ \[CloseCurlyDoubleQuote] elements.\ \>", "Text",ExpressionUUID->"a49a5b62-140b-465b-81bf-03f30b02096e"], Cell[BoxData[ RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"s", "\[Element]", "Integers"}], ",", RowBox[{"s", ">", "0"}], ",", RowBox[{"s", "<=", RowBox[{"n", "+", "1"}]}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"s", "\[Element]", RowBox[{"Span", "[", RowBox[{"r", ",", RowBox[{"r", "+", "1"}]}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"inv2_", "3", " ", "not", " ", "used", " ", "here"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"s", "->", "1"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"for", " ", "event", " ", "send"}], ",", " ", RowBox[{ "which", " ", "is", " ", "limited", " ", "by", " ", "file", " ", "size"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "+", "1", "-", "s"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"s", "==", "r"}], ",", "\[IndentingNewLine]", RowBox[{"r", "!=", RowBox[{"n", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"s", "->", RowBox[{"s", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", "refining", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"s", "==", RowBox[{"r", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"h", "->", RowBox[{"h", "+", "r"}]}], ",", "\[IndentingNewLine]", RowBox[{"r", "->", RowBox[{"r", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[638]:=",ExpressionUUID->"6ef28272-9441-4421-a4e5-756645c5c1a0"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel-> "In[639]:=",ExpressionUUID->"e6022c58-0ed9-42ae-9792-83ab2917ecc1"] }, Closed]], Cell[CellGroupData[{ Cell["Third refinement", "Subsubsection",ExpressionUUID->"40fb2c02-eaa1-48d9-9b9f-882bdc20740d"], Cell["\<\ This refinement introduces parity counters and relies on two different \ theorems about parity to validate properly.\ \>", "Text",ExpressionUUID->"444e7ab2-3b18-44b6-b708-6b831ba85440"], Cell["\<\ In the first theorem, parity[n,p] is a statement that p is a parity value (0 \ or 1) for number n. The inductive nature of this theorem is that:\ \>", "Text",ExpressionUUID->"d3a82566-d856-4862-ad7a-163d53e3e3d4"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Column", "[", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"parity", "[", RowBox[{"0", ",", "0"}], "]"}], "\[Equal]", "True"}], ",", RowBox[{"ForAll", "[", RowBox[{"x", ",", RowBox[{"x", ">", "0"}], ",", RowBox[{ RowBox[{"parity", "[", RowBox[{"x", ",", "p"}], "]"}], "\[Implies]", RowBox[{"parity", "[", RowBox[{ RowBox[{"x", "+", "1"}], ",", RowBox[{"1", "-", "p"}]}], "]"}]}]}], "]"}]}], "}"}], "]"}]], "Input",\ CellLabel-> "In[640]:=",ExpressionUUID->"e31b7c82-f7ce-48e5-aa6f-e845b20edc8b"], Cell[BoxData[ TagBox[GridBox[{ { RowBox[{ RowBox[{"parity", "[", RowBox[{"0", ",", "0"}], "]"}], "\[Equal]", "True"}]}, { RowBox[{ SubscriptBox["\[ForAll]", RowBox[{"x", ",", RowBox[{"x", ">", "0"}]}]], RowBox[{"(", RowBox[{ RowBox[{"parity", "[", RowBox[{"x", ",", "p"}], "]"}], "\[Implies]", RowBox[{"parity", "[", RowBox[{ RowBox[{"1", "+", "x"}], ",", RowBox[{"1", "-", "p"}]}], "]"}]}], ")"}]}]} }, DefaultBaseStyle->"Column", GridBoxAlignment->{"Columns" -> {{Left}}}, GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}], "Column"]], "Output", CellLabel-> "Out[640]=",ExpressionUUID->"1b26a21c-3040-4e53-96ae-dafcffb39e07"] }, {2}]], Cell[BoxData[ RowBox[{ RowBox[{"parityTheorem", "[", RowBox[{"knowns_", ",", "question_"}], "]"}], ":=", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "knownParities", ",", "\[IndentingNewLine]", "newKnowns", ",", "\[IndentingNewLine]", "newQuestion"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"knownParities", "=", RowBox[{"Cases", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"parity", "[", RowBox[{"0", ",", "0"}], "]"}], ",", "knowns"}], "}"}], ",", RowBox[{ RowBox[{"parity", "[", RowBox[{"n_", ",", "p_"}], "]"}], "\[RuleDelayed]", RowBox[{"{", RowBox[{"n", ",", "p"}], "}"}]}], ",", RowBox[{"{", RowBox[{"0", ",", "Infinity"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"newKnowns", "=", RowBox[{"DeleteCases", "[", RowBox[{"knowns", ",", "_parity", ",", RowBox[{"{", RowBox[{"0", ",", "Infinity"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"newQuestion", "=", RowBox[{"question", "/.", RowBox[{"Map", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"qp", ",", " ", RowBox[{"(*", " ", RowBox[{"qp", " ", "is", " ", RowBox[{"parity", "[", "...", "]"}], " ", "in", " ", "question"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"qp", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", " ", RowBox[{"(*", " ", "number", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"p", "=", RowBox[{"qp", "[", RowBox[{"[", "2", "]"}], "]"}]}]}], " ", RowBox[{"(*", " ", "parity", " ", "*)"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"qp", "\[Rule]", RowBox[{"Or", "@@", RowBox[{"Map", "[", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "qp", " ", "is", " ", "replaced", " ", "with", " ", "Or"}], "-", RowBox[{ "ed", " ", "test", " ", "against", " ", "all", " ", "known", " ", "parities"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Function", "[", RowBox[{"knp", ",", " ", RowBox[{"(*", " ", RowBox[{ "knp", " ", "is", " ", "some", " ", "known", " ", RowBox[{"{", RowBox[{"n", ",", "p"}], "}"}], " ", "pair", " ", RowBox[{"(", RowBox[{"including", " ", "starting", " ", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "p", " ", "is", " ", "a", " ", "parity", " ", "value", " ", "of", " ", "number", " ", "n"}], ",", " ", RowBox[{"if", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"n", "==", RowBox[{"knp", "[", RowBox[{"[", "1", "]"}], "]"}]}], "&&", RowBox[{"p", "==", RowBox[{"knp", "[", RowBox[{"[", "2", "]"}], "]"}]}]}], ")"}], "||", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"we", " ", "know", " ", "it", " ", "already"}], ",", " ", RowBox[{"or", " ", "..."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"n", "==", RowBox[{ RowBox[{"knp", "[", RowBox[{"[", "1", "]"}], "]"}], "+", "1"}]}], "&&", RowBox[{"p", "\[Equal]", RowBox[{"1", "-", RowBox[{"knp", "[", RowBox[{"[", "2", "]"}], "]"}]}]}]}], ")"}]}]}], " ", RowBox[{"(*", " ", RowBox[{ "...", " ", "we", " ", "can", " ", "induce", " ", "it"}], " ", "*)"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "knownParities"}], "\[IndentingNewLine]", "]"}]}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Cases", "[", RowBox[{"question", ",", "_parity", ",", RowBox[{"{", RowBox[{"0", ",", "Infinity"}], "}"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"newKnowns", ",", "newQuestion"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input", CellLabel-> "In[641]:=",ExpressionUUID->"e6f16111-613d-469d-9bd5-d0a9dc8b9c4a"], Cell["\<\ The other theorem states that if two numbers differ from each other by at \ most 1, then if their parities are equal, the numbers are equal, too. This \ theorem applies to the send and receive counters and is injected directly in \ the model, without defining it as a separate function.\ \>", "Text",ExpressionUUID->"42a919af-8118-49ec-9a55-1097f4b13b22"], Cell[BoxData[ RowBox[{ RowBox[{"myModel3", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel2", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "theorems", " ", "can", " ", "be", " ", "defined", " ", "elsewhere", " ", "and", " ", "referred", " ", "by", " ", RowBox[{"name", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", "parityTheorem"}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "very", " ", "simple", " ", "theorems", " ", "can", " ", "be", " ", "injected", " ", "directly"}], ",", " ", RowBox[{"using", " ", "the", " ", "axiom", " ", RowBox[{"mechanism", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"p", "\[Equal]", "q"}], "\[Implies]", RowBox[{"s", "\[Equal]", "r"}]}], ")"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"p", "\[NotEqual]", "q"}], "\[Implies]", RowBox[{"s", "\[NotEqual]", "r"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{"parity", " ", "of", " ", "send", " ", "counter"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"p", "\[Element]", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"parity", "[", RowBox[{"s", ",", "p"}], "]"}], "\[Equal]", "True"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{"parity", " ", "of", " ", "receive", " ", "counter"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"q", "\[Element]", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"parity", "[", RowBox[{"r", ",", "q"}], "]"}], "\[Equal]", "True"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"p", "->", "1"}], ",", RowBox[{"q", "->", "1"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"because", " ", "r"}], "->", RowBox[{ RowBox[{"1", " ", "in", " ", "myModel1", " ", "and", " ", "s"}], "->", RowBox[{"1", " ", "in", " ", "myModel2"}]}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"p", "==", "q"}], ",", " ", RowBox[{"(*", " ", RowBox[{"base", " ", "guard", " ", RowBox[{"(", RowBox[{"s", "\[Equal]", "r"}], ")"}], " ", "is", " ", "strengthened"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"s", "!=", RowBox[{"n", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"s", "->", RowBox[{"s", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"p", "->", RowBox[{"1", "-", "p"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"p", "!=", "q"}], ",", " ", RowBox[{"(*", " ", RowBox[{"base", " ", "guard", " ", RowBox[{"(", RowBox[{"s", "\[NotEqual]", "r"}], ")"}], " ", "is", " ", "strengthened"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"r", "->", RowBox[{"r", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"q", "->", RowBox[{"1", "-", "q"}]}]}], " ", "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[642]:=",ExpressionUUID->"68082f1d-2073-4faa-9e98-54820f9f8e9e"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel3", "]"}]], "Input", CellLabel-> "In[643]:=",ExpressionUUID->"16103f8f-03be-4be5-8f70-f3605c6b91bd"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Model - digital circuit: pulser", "Subsection",ExpressionUUID->"72c98d55-d0e5-4cf3-8e75-5fe04d3e9731"], Cell["\<\ This example is based on chapter 8 of the \[OpenCurlyDoubleQuote]Modeling in \ Event-B\[CloseCurlyDoubleQuote] book by Jean-Raymond Abrial. The model describes a digital circuit that generates one short pulse when a \ button is pressed.\ \>", "Text",ExpressionUUID->"12a27c5d-c77b-4914-a2a8-0890adce16dd"], Cell[CellGroupData[{ Cell["Initial model", "Subsubsection",ExpressionUUID->"3f2c7407-9a9f-4490-9025-eb720ca58eea"], Cell["\<\ The initial model uses counters to decide when the pulse should be generated, \ they will disappear in later refinement.\ \>", "Text",ExpressionUUID->"af6f8b81-4ec4-4003-ba01-d69b7c591453"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"systemMode", "=", RowBox[{"{", RowBox[{"env", ",", "cir"}], "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "helper", " ", "function", " ", "for", " ", "generating", " ", "statements", " ", "of", " ", "unique", " ", "elements", " ", "in", " ", "a", " ", "set"}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"uniqueElements", "[", "s_List", "]"}], ":=", RowBox[{"Unequal", "@@@", RowBox[{"Subsets", "[", RowBox[{"s", ",", RowBox[{"{", "2", "}"}]}], "]"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"uniqueElements", "[", "systemMode", "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"mode", "\[Element]", "systemMode"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"push", "\[Element]", "Integers"}], ",", RowBox[{"push", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"pop", "\[Element]", "Integers"}], ",", RowBox[{"pop", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"pop", "\[LessEqual]", "push"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"push", "\[LessEqual]", RowBox[{"pop", "+", "1"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"flash", "\[Element]", "Integers"}], ",", RowBox[{"flash", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"flash", "\[LessEqual]", "push"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"push", "\[LessEqual]", RowBox[{"flash", "+", "1"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"flash", "\[Equal]", "push"}], "||", RowBox[{"flash", "\[Equal]", "pop"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"interesting", ":", " ", RowBox[{"without", " ", "inv0_", "9"}]}], ",", " ", RowBox[{"inv0_", "8", " ", "cannot", " ", "be", " ", "resolved"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", RowBox[{"push", "\[Rule]", "0"}], ",", RowBox[{"pop", "\[Rule]", "0"}], ",", RowBox[{"flash", "\[Rule]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "events", " ", "describing", " ", "abstract", " ", "environment"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"pop", "\[Equal]", "push"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"push", "\[Rule]", RowBox[{"push", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"pop", "\[NotEqual]", "push"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"pop", "\[Rule]", RowBox[{"pop", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], ",", RowBox[{"mode", "\[Rule]", "cir"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"events", " ", "describing", " ", "abstract", " ", "circuit"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"push", "\[NotEqual]", "flash"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"flash", "\[Rule]", RowBox[{"flash", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"push", "\[NotEqual]", "pop"}], "||", RowBox[{"push", "\[Equal]", "flash"}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"mode", "\[Rule]", "env"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[696]:=",ExpressionUUID->"c09fc0d9-2d75-480e-8c24-39732f95753c"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellLabel-> "In[699]:=",ExpressionUUID->"abb09a58-9d0e-43d3-a9ab-6af2eb08653a"] }, Closed]], Cell[CellGroupData[{ Cell["First refinement - reducing non-determinism", "Subsubsection",ExpressionUUID->"c10d1ded-cd0b-4a5a-8063-2fff453f2149"], Cell["\<\ This refinement reduces non-determinism of the initial model, it follows the \ first option described in the book (flash the pulse as soon as possible).\ \>", "Text",ExpressionUUID->"0a763dd5-d27d-471e-ad9e-b8af079abb7e"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"pop", "\[NotEqual]", "push"}], "&&", RowBox[{"mode", "\[Equal]", "env"}]}], ")"}], "\[Implies]", RowBox[{"flash", "\[NotEqual]", "pop"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"in", " ", "fact"}], ",", " ", RowBox[{ "identical", " ", "to", " ", "cir1", " ", "in", " ", "base", " ", "model"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"push", "\[NotEqual]", "flash"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"flash", "\[Rule]", RowBox[{"flash", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"push", "\[Equal]", "flash"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"stronger", " ", "than", " ", "cir2"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"mode", "\[Rule]", "env"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[700]:=",ExpressionUUID->"3c5994c2-9313-45bc-9739-60e7429d49ea"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel-> "In[701]:=",ExpressionUUID->"6379b1ef-4dff-4770-b2ef-9c1ba95e216e"] }, Closed]], Cell[CellGroupData[{ Cell["Second refinement - change the data space", "Subsubsection",ExpressionUUID->"5e65f049-e55e-448f-89c4-94efb338e3c5"], Cell["\<\ This refinement drops the use of integer counters (push, pop, flash) and \ replaces them with simpler boolean variables (input, output, reg). The \ challenge is to demonstrate that it is still the same system.\ \>", "Text",ExpressionUUID->"1e091f0a-6ed0-4a58-a197-3a655d5f1812"], Cell[BoxData[ RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"input", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"output", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "this", " ", "invariant", " ", "binds", " ", "together", " ", "variables", " ", "between", " ", "this", " ", "and", " ", "base", " ", "model"}], ",", " ", RowBox[{ "and", " ", "thus", " ", "allows", " ", "to", " ", "switch", " ", "data", " ", RowBox[{"spaces", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", " ", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"input", "\[Equal]", "True"}], "\[Implies]", RowBox[{"pop", "\[NotEqual]", "push"}]}], ")"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"pop", "\[NotEqual]", "push"}], "\[Implies]", RowBox[{"input", "\[Equal]", "True"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"reg", "\[Element]", "Booleans"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"single", " ", "memory", " ", "register"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"reg", "\[Equal]", "input"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "\[Implies]", RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"input", "\[Equal]", "True"}], "&&", RowBox[{"reg", "\[Equal]", "False"}]}], ")"}], "\[Implies]", RowBox[{"push", "\[NotEqual]", "flash"}]}], ")"}], "&&", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"push", "\[NotEqual]", "flash"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"input", "\[Equal]", "True"}], "&&", RowBox[{"reg", "\[Equal]", "False"}]}], ")"}]}], ")"}]}], "\[IndentingNewLine]", ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"input", "\[Element]", "Booleans"}], ",", RowBox[{"output", "\[Element]", "Booleans"}], ",", RowBox[{"reg", "\[Element]", "Booleans"}], ",", "\[IndentingNewLine]", RowBox[{"input", "\[Rule]", "False"}], ",", RowBox[{"output", "\[Rule]", "False"}], ",", RowBox[{"reg", "\[Rule]", "False"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"input", "\[Equal]", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"input", "\[Rule]", "True"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"input", "\[Equal]", "True"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"input", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"in", " ", "fact"}], ",", " ", RowBox[{ "identical", " ", "to", " ", "env3", " ", "in", " ", "base", " ", "model"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], ",", RowBox[{"mode", "\[Rule]", "cir"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"input", "\[Equal]", "True"}], "&&", RowBox[{"reg", "\[Equal]", "False"}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"output", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"reg", "\[Rule]", "input"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"input", "\[Equal]", "False"}], "||", RowBox[{"reg", "\[Equal]", "True"}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"output", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"reg", "\[Rule]", "input"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[707]:=",ExpressionUUID->"724f6b62-46c2-4a27-8ae1-4a66c009125e"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel-> "In[708]:=",ExpressionUUID->"3fd3a2da-5e8b-44de-bda1-282ca872dd87"] }, Closed]], Cell[CellGroupData[{ Cell["Final circuit", "Subsubsection",ExpressionUUID->"73b3a0a1-9575-4da5-9aa4-c1a275f8086d"], Cell["\<\ The final refinement merges events that deal with circuit operation (which \ already use only boolean variables) into a single event that directly defines \ signal changes as its actions.\ \>", "Text",ExpressionUUID->"d6912cb2-812b-491b-baf1-0783a32db1d7"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"myModel3", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel2", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"output", "\[Rule]", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"input", "\[Equal]", "True"}], "&&", RowBox[{"reg", "\[Equal]", "False"}]}], ")"}], "&&", RowBox[{"True", "\[Equal]", "True"}]}], ")"}], "||", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"input", "\[Equal]", "False"}], "||", RowBox[{"reg", "\[Equal]", "True"}]}], ")"}], "&&", RowBox[{"False", "\[Equal]", "True"}]}], ")"}]}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"reg", "\[Rule]", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"input", "\[Equal]", "True"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"input", "\[Equal]", "True"}], "&&", RowBox[{"reg", "\[Equal]", "False"}]}], ")"}]}], ")"}], "||", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"input", "\[Equal]", "True"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"input", "\[Equal]", "False"}], "||", RowBox[{"reg", "\[Equal]", "True"}]}], ")"}]}], ")"}]}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"which", " ", "is", " ", "the", " ", "same", " ", RowBox[{"as", ":"}]}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel3", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel2", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"output", "\[Rule]", RowBox[{ RowBox[{"input", "\[Equal]", "True"}], "&&", RowBox[{"reg", "\[Equal]", "False"}]}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"reg", "\[Rule]", "input"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel-> "In[709]:=",ExpressionUUID->"6b0f4c34-d712-4c56-8b58-8b547b6c5cfe"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel3", "]"}]], "Input", CellLabel-> "In[711]:=",ExpressionUUID->"ae5315d6-5aa4-47b6-acc3-f6b900d3cb57"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Model - digital circuit: arbiter", "Subsection",ExpressionUUID->"812f1fd6-1ccf-4938-a3a3-9456439997b1"], Cell["\<\ This example is based on chapter 8 of the \[OpenCurlyDoubleQuote]Modeling in \ Event-B\[CloseCurlyDoubleQuote] book by Jean-Raymond Abrial. The model describes a digital circuit that arbitrates access to resource that \ is requested by two competing users.\ \>", "Text",ExpressionUUID->"3f7962fc-9cfe-4015-a9f8-f70e2a707537"], Cell[CellGroupData[{ Cell["Requirements", "Subsubsection",ExpressionUUID->"f2cca57a-aab2-486d-b912-a8a342953fad"], Cell[BoxData[ RowBox[{ RowBox[{"reqs", "=", RowBox[{"<|", "\[IndentingNewLine]", RowBox[{"\"\\"", ",", "\"\\"", ",", "\[IndentingNewLine]", "\"\\"", ",", "\"\\"", ",", "\[IndentingNewLine]", "\"\\"", ",", "\"\\"", ",", "\[IndentingNewLine]", "\"\\"", ",", "\"\\"", ",", "\[IndentingNewLine]", "\"\\"", ",", "\"\\"", ",", "\[IndentingNewLine]", "\"\\"", ",", "\"\\"", ",", "\[IndentingNewLine]", "\"\\"", ",", "\"\\"", ",", "\[IndentingNewLine]", "\"\\"", ",", "\"\\ \""}], "\[IndentingNewLine]", "|>"}]}], ";"}]], "Input", CellLabel-> "In[712]:=",ExpressionUUID->"f3ded21b-d3a8-4905-a3c5-997f31448817"] }, Closed]], Cell[CellGroupData[{ Cell["Initial model", "Subsubsection",ExpressionUUID->"f85126a4-d7d8-411d-903a-fdce01a243bd"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"systemMode", "=", RowBox[{"{", RowBox[{"env", ",", "cir"}], "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "helper", " ", "function", " ", "for", " ", "generating", " ", "statements", " ", "of", " ", "unique", " ", "elements", " ", "in", " ", "a", " ", "set"}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"uniqueElements", "[", "s_List", "]"}], ":=", RowBox[{"Unequal", "@@@", RowBox[{"Subsets", "[", RowBox[{"s", ",", RowBox[{"{", "2", "}"}]}], "]"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"uniqueElements", "[", "systemMode", "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"mode", "\[Element]", "systemMode"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"r1", "\[Element]", "Integers"}], ",", RowBox[{"r1", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"request", " ", "counter", " ", "for", " ", "user", " ", "1"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"r2", "\[Element]", "Integers"}], ",", RowBox[{"r2", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "allocation", " ", "counter", " ", "for", " ", "user", " ", "1"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"a1", "\[Element]", "Integers"}], ",", RowBox[{"a1", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"request", " ", "counter", " ", "2"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"a2", "\[Element]", "Integers"}], ",", RowBox[{"a2", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"allocation", " ", "counter", " ", "2"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a1", "\[LessEqual]", "r1"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "allocated", " ", "no", " ", "more", " ", "than", " ", "requested"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"r1", "\[LessEqual]", RowBox[{"a1", "+", "1"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"requested", " ", "until", " ", "allocated"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a2", "\[LessEqual]", "r2"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"r2", "\[LessEqual]", RowBox[{"a2", "+", "1"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"p1", "\[Element]", "Booleans"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "p1", " ", "is", " ", "True", " ", "if", " ", "user", " ", "1", " ", "now", " ", "waits", " ", "for", " ", "resource"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"p2", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"p1", "\[Equal]", "False"}], "||", RowBox[{"p2", "\[Equal]", "False"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"users", " ", "do", " ", "not", " ", "wait", " ", "together"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"glue", " ", "user", " ", "actions", " ", RowBox[{"(", RowBox[{"r1", ",", "a1", ",", "r2", ",", "a2"}], ")"}], " ", "with", " ", "internal", " ", "knowledge", " ", RowBox[{"(", RowBox[{"p1", ",", "p2"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"r1", "\[Equal]", "a1"}], "\[Implies]", RowBox[{"p1", "\[Equal]", "False"}]}], ")"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"p1", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r1", "\[Equal]", "a1"}]}], ")"}]}], ")"}]}]}], "]"}], ","}], "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"r1", "\[Equal]", "a1"}], "\[Implies]", RowBox[{"p1", "\[Equal]", "False"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"p1", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r1", "\[Equal]", "a1"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"r2", "\[Equal]", "a2"}], "\[Implies]", RowBox[{"p2", "\[Equal]", "False"}]}], ")"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"p2", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r2", "\[Equal]", "a2"}]}], ")"}]}], ")"}]}]}], "]"}], ","}], "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"r2", "\[Equal]", "a2"}], "\[Implies]", RowBox[{"p2", "\[Equal]", "False"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"p2", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r2", "\[Equal]", "a2"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"r1", "\[Equal]", "a1"}], "\[Implies]", RowBox[{"p1", "\[Equal]", "False"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"r2", "\[Equal]", "a2"}], "\[Implies]", RowBox[{"p2", "\[Equal]", "False"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"r1", "\[Rule]", "0"}], ",", RowBox[{"a1", "\[Rule]", "0"}], ",", "\[IndentingNewLine]", RowBox[{"r2", "\[Rule]", "0"}], ",", RowBox[{"a2", "\[Rule]", "0"}], ",", "\[IndentingNewLine]", RowBox[{"p1", "\[Element]", "Booleans"}], ",", RowBox[{"p1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Element]", "Booleans"}], ",", RowBox[{"p2", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"mode", "\[Rule]", "env"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"environment", " ", RowBox[{"perspective", ":", " ", RowBox[{ "user", " ", "1", " ", "can", " ", "ask", " ", "for", " ", "resource"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"r1", "\[Equal]", "a1"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"r1", "\[Rule]", RowBox[{"r1", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"environment", " ", RowBox[{"perspective", ":", " ", RowBox[{ "user", " ", "2", " ", "can", " ", "ask", " ", "for", " ", "resource"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"r2", "\[Equal]", "a2"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"r2", "\[Rule]", RowBox[{"r2", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"environment", " ", RowBox[{"perspective", ":", " ", RowBox[{ "both", " ", "user", " ", "can", " ", "ask", " ", "for", " ", "resource"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"r1", "\[Equal]", "a1"}], "&&", RowBox[{"r2", "\[Equal]", "a2"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"r1", "\[Rule]", RowBox[{"r1", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"r2", "\[Rule]", RowBox[{"r2", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"environment", " ", RowBox[{"perspective", ":", " ", RowBox[{"nothing", " ", "happens"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"mode", "\[Rule]", "cir"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"circuit", " ", RowBox[{"perspective", ":", " ", RowBox[{ "user", " ", "1", " ", "is", " ", "waiting", " ", "for", " ", "resource", " ", RowBox[{"(", RowBox[{"but", " ", "user", " ", "2", " ", "is", " ", "not"}], ")"}]}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"r1", "\[NotEqual]", "a1"}], "&&", RowBox[{"p2", "\[Equal]", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"a1", "\[Rule]", RowBox[{"a1", "+", "1"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"allocate", " ", "to", " ", "user", " ", "1"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"p1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", RowBox[{"r2", "\[NotEqual]", "a2"}]}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "mark", " ", "user", " ", "2", " ", "as", " ", "waiting"}], ",", " ", RowBox[{"if", " ", "needed"}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"circuit", " ", RowBox[{"perspective", ":", " ", RowBox[{ "user", " ", "2", " ", "is", " ", "waiting", " ", "for", " ", "resource", " ", RowBox[{"(", RowBox[{"but", " ", "user", " ", "1", " ", "is", " ", "not"}], ")"}]}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"r2", "\[NotEqual]", "a2"}], "&&", RowBox[{"p1", "\[Equal]", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"a2", "\[Rule]", RowBox[{"a2", "+", "1"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"allocate", " ", "to", " ", "user", " ", "2"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p1", "\[Rule]", RowBox[{"r1", "\[NotEqual]", "a1"}]}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "mark", " ", "user", " ", "1", " ", "as", " ", "waiting"}], ",", " ", RowBox[{"if", " ", "needed"}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"circuit", " ", RowBox[{"perspective", ":", " ", RowBox[{"neither", " ", "user", " ", "is", " ", "waiting"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"r1", "\[Equal]", "a1"}], "&&", RowBox[{"r2", "\[Equal]", "a2"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"p1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellLabel->"In[41]:=",ExpressionUUID->"8e05c522-5791-4a5e-8fbd-5f4efc93784e"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellLabel->"In[44]:=",ExpressionUUID->"51821de8-7e6f-4ccc-b8bb-5e7f0c191ebd"] }, Closed]], Cell[CellGroupData[{ Cell["First refinement", "Subsubsection",ExpressionUUID->"61be26dd-873e-4ac0-8571-ac867fd73121"], Cell["\<\ The initial model used integer counters to represent both input actions and \ to influence outputs. This refinement replaces allocation counters with \ boolean variables, which brings the model closer to the expected boolean \ system (it is a data space transformation).\ \>", "Text",ExpressionUUID->"5c3a1c23-9153-4879-a210-51129451700f"], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ RowBox[{ "helper", " ", "function", " ", "for", " ", "counting", " ", "boolean", " ", "values"}], ",", " ", RowBox[{"for", " ", "proving", " ", "bool", " ", "variants"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"boolCount", "[", "a_", "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"a", "\[Equal]", "True"}], ",", "1", ",", "0"}], "]"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"b1", "\[Element]", "Integers"}], ",", RowBox[{"b1", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"\"\\"", " ", "allocations", " ", "for", " ", "user", " ", "1"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"o1", "\[Element]", "Booleans"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"output", " ", "1"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"b2", "\[Element]", "Integers"}], ",", RowBox[{"b2", "\[GreaterEqual]", "0"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"\"\\"", " ", "allocations", " ", "for", " ", "user", " ", "2"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"o2", "\[Element]", "Booleans"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"output", " ", "2"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"in", " ", "the", " ", "circuit", " ", "perspective"}], ",", " ", RowBox[{ "counters", " ", "ai", " ", "and", " ", "bi", " ", "are", " ", "\"\\""}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "\[Implies]", RowBox[{"a1", "==", "b1"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "\[Implies]", RowBox[{"a2", "==", "b2"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"in", " ", "the", " ", "environment", " ", "perspective"}], ",", " ", RowBox[{ "ai", " ", "and", " ", "bi", " ", "are", " ", "possibly", " ", "shifted", " ", "by", " ", "oi"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"a1", "\[Equal]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "\[Implies]", RowBox[{"a2", "\[Equal]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "theorem", " ", "to", " ", "help", " ", "FindInstance", " ", "solve", " ", "satisfiability", " ", "of", " ", "superposition", " ", "in", " ", "events", " ", "cir1", " ", "and", " ", "cir2"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"a_", "!=", "b_"}], ")"}], "==", RowBox[{"(", RowBox[{"a_", "!=", "c_"}], ")"}]}], "->", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"a", "==", "b"}], "&&", RowBox[{"a", "==", "c"}]}], ")"}], "||", RowBox[{"(", RowBox[{ RowBox[{"a", "!=", "b"}], "&&", RowBox[{"a", "!=", "c"}]}], ")"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"b1", "\[Rule]", "0"}], ",", RowBox[{"o1", "\[Element]", "Booleans"}], ",", RowBox[{"o1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"b2", "\[Rule]", "0"}], ",", RowBox[{"o2", "\[Element]", "Booleans"}], ",", RowBox[{"o2", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"r1", "\[Equal]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"r1", "\[Rule]", RowBox[{"r1", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"b1", "\[Rule]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"b2", "\[Rule]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"r2", "\[Equal]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"r2", "\[Rule]", RowBox[{"r2", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"b1", "\[Rule]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"b2", "\[Rule]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"r1", "\[Equal]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], "&&", RowBox[{"r2", "\[Equal]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"r1", "\[Rule]", RowBox[{"r1", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"r2", "\[Rule]", RowBox[{"r2", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"b1", "\[Rule]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"b2", "\[Rule]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ "this", " ", "event", " ", "just", " ", "maintains", " ", "the", " ", "shifted", " ", "counters"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"b1", "\[Rule]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"b2", "\[Rule]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"r1", "\[NotEqual]", "b1"}], "&&", RowBox[{"p2", "\[Equal]", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"o1", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"o2", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", RowBox[{"r2", "\[NotEqual]", "b2"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"r2", "\[NotEqual]", "b2"}], "&&", RowBox[{"p1", "\[Equal]", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"o1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"o2", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"p1", "\[Rule]", RowBox[{"r1", "\[NotEqual]", "b1"}]}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"r1", "\[Equal]", "b1"}], "&&", RowBox[{"r2", "\[Equal]", "b2"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"o1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"o2", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}]}]], "Input",Expressio\ nUUID->"6f90e019-99fd-4c93-9d05-622d24b19fcc"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel->"In[82]:=",ExpressionUUID->"fb4d9506-ee98-4b64-8c49-98ababe5137f"] }, Closed]], Cell[CellGroupData[{ Cell["Second refinement", "Subsubsection",ExpressionUUID->"655e4168-701c-418a-8056-d1e3e9fb4a73"], Cell["\<\ In the first refinement, \[OpenCurlyDoubleQuote]circuit\ \[CloseCurlyDoubleQuote] events still accessed \ \[OpenCurlyDoubleQuote]environment\[CloseCurlyDoubleQuote] state (r1, r2, b1, \ b2). This refinement introduces boolean variables i1, i2 representing inputs \ to break this dependency.\ \>", "Text",ExpressionUUID->"705091c1-d1ef-4985-9827-0ec6f16f6580"], Cell[BoxData[ RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"i1", "\[Element]", "Booleans"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"input", " ", "for", " ", "user", " ", "1"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"i2", "\[Element]", "Booleans"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"input", " ", "for", " ", "user", " ", "2"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", "glue", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"i1", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r1", "\[Equal]", "b1"}]}], ")"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"r1", "\[Equal]", "b1"}], "\[Implies]", RowBox[{"i1", "\[Equal]", "False"}]}], ")"}]}], ")"}]}]}], "]"}], ","}], "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"i1", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r1", "\[Equal]", "b1"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"r1", "\[Equal]", "b1"}], "\[Implies]", RowBox[{"i1", "\[Equal]", "False"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"i2", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r2", "\[Equal]", "b2"}]}], ")"}], "&&", RowBox[{"(", RowBox[{ RowBox[{"r2", "\[Equal]", "b2"}], "\[Implies]", RowBox[{"i2", "\[Equal]", "False"}]}], ")"}]}], ")"}]}]}], "]"}], ","}], "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"i2", "\[Equal]", "False"}], "\[Implies]", RowBox[{"r2", "\[Equal]", "b2"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "\[Implies]", RowBox[{"(", RowBox[{ RowBox[{"r2", "\[Equal]", "b2"}], "\[Implies]", RowBox[{"i2", "\[Equal]", "False"}]}], ")"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "theorem", " ", "to", " ", "help", " ", "FindInstance", " ", "solve", " ", "satisfiability", " ", "of", " ", "superposition", " ", "in", " ", "events", " ", "cir1", " ", "and", " ", "cir2"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"a_", "==", "b_", "==", "c_"}], "->", RowBox[{ RowBox[{"(", RowBox[{"a", "&&", "b", "&&", "c"}], ")"}], "||", RowBox[{"(", RowBox[{ RowBox[{"!", "a"}], "&&", RowBox[{"!", "b"}], "&&", RowBox[{"!", "c"}]}], ")"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"i1", "\[Element]", "Booleans"}], ",", RowBox[{"i1", "\[Rule]", "False"}], ",", RowBox[{"i2", "\[Element]", "Booleans"}], ",", RowBox[{"i2", "\[Rule]", "False"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"r1", "\[Equal]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"r1", "\[Rule]", RowBox[{"r1", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"b1", "\[Rule]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"b2", "\[Rule]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"i1", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"i2", "\[Rule]", RowBox[{"(", RowBox[{"r2", "\[NotEqual]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}], ")"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"r2", "\[Equal]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"r2", "\[Rule]", RowBox[{"r2", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"b1", "\[Rule]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"b2", "\[Rule]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"i1", "\[Rule]", RowBox[{"(", RowBox[{"r1", "\[NotEqual]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"i2", "\[Rule]", "True"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], "&&", RowBox[{"r1", "\[Equal]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], "&&", RowBox[{"r2", "\[Equal]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"r1", "\[Rule]", RowBox[{"r1", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"r2", "\[Rule]", RowBox[{"r2", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"b1", "\[Rule]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"b2", "\[Rule]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"i1", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"i2", "\[Rule]", "True"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{"again", ",", " ", RowBox[{"just", " ", "maintain", " ", "the", " ", "counters"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"mode", "\[Equal]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"b1", "\[Rule]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"b2", "\[Rule]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"i1", "\[Rule]", RowBox[{"(", RowBox[{"r1", "\[NotEqual]", RowBox[{"b1", "+", RowBox[{"boolCount", "[", "o1", "]"}]}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"i2", "\[Rule]", RowBox[{"(", RowBox[{"r2", "\[NotEqual]", RowBox[{"b2", "+", RowBox[{"boolCount", "[", "o2", "]"}]}]}], ")"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"i1", "\[Equal]", "True"}], "&&", RowBox[{"p2", "\[Equal]", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"o1", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"o2", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", RowBox[{"i2", "==", "True"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"i2", "\[Equal]", "True"}], "&&", RowBox[{"p1", "\[Equal]", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"o1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"o2", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"p1", "\[Rule]", RowBox[{"i1", "==", "True"}]}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], "&&", RowBox[{"i1", "\[Equal]", "False"}], "&&", RowBox[{"i2", "\[Equal]", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"o1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"o2", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[194]:=",ExpressionUUID->"b3a23a2d-88ce-4b85-b6a4-5415fae25c5e"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel-> "In[195]:=",ExpressionUUID->"0738d3c7-cc75-4614-a8e3-c45518fb3c15"] }, Closed]], Cell[CellGroupData[{ Cell["Third refinement", "Subsubsection",ExpressionUUID->"541c03a2-884f-4b30-8fa8-485492541ca3"], Cell["\<\ This refinement reduces non-determinacy that allowed both inputs to be set to \ True and thus allowed both circuit events cir1 and cir2 to be enabled. This \ refinement gives first user the priority in such case.\ \>", "Text",ExpressionUUID->"7628fc4f-5b87-4c30-b051-c68d846d422a"], Cell[BoxData[ RowBox[{ RowBox[{"myModel3", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel2", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "==", "cir"}], "&&", RowBox[{"i1", "\[Equal]", "True"}], "&&", RowBox[{"p2", "\[Equal]", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"o1", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"o2", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", RowBox[{"i2", "==", "True"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "==", "cir"}], "&&", RowBox[{"i2", "\[Equal]", "True"}], "&&", RowBox[{"!", RowBox[{"(", RowBox[{ RowBox[{"i1", "\[Equal]", "True"}], "&&", RowBox[{"p2", "\[Equal]", "False"}]}], ")"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"o1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"o2", "\[Rule]", "True"}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"mode", "==", "cir"}], "&&", RowBox[{"i1", "\[Equal]", "False"}], "&&", RowBox[{"i2", "\[Equal]", "False"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", RowBox[{"o1", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"o2", "\[Rule]", "False"}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[200]:=",ExpressionUUID->"38a566a3-21c6-4ee2-a0ef-71897b08b594"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel3", "]"}]], "Input", CellLabel-> "In[202]:=",ExpressionUUID->"a0f5cd5e-8199-468f-b3fe-b32a780c47c6"] }, Closed]], Cell[CellGroupData[{ Cell["Final refinement", "Subsubsection",ExpressionUUID->"d492dc51-4657-494a-8f83-c93491aae68d"], Cell["\<\ In this refinement, the \ \[OpenCurlyDoubleQuote]arbiter\[CloseCurlyDoubleQuote] event merges together \ all circuit events from previous model defines the final circuit for both \ outputs and a single memory register p2.\ \>", "Text",ExpressionUUID->"2b6c7dec-1121-446f-87d5-bc9be6896cbd"], Cell[BoxData[ RowBox[{ RowBox[{"myModel4", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel3", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "theorem", " ", "to", " ", "help", " ", "FindInstance", " ", "solve", " ", "satisfiability", " ", "of", " ", "superposition", " ", "in", " ", "event", " ", "arbiter", " ", "on", " ", "refinement", " ", "via", " ", "cir1", " ", "and", " ", "cir2"}], ";", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ "theorem", " ", "th2", " ", "from", " ", "myModel2", " ", "still", " ", "holds", " ", "and", " ", "is", " ", "used", " ", "here"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"a_", "==", "b_", "==", "c_", "==", "d_"}], "->", RowBox[{ RowBox[{"(", RowBox[{"a", "&&", "b", "&&", "c", "&&", "d"}], ")"}], "||", RowBox[{"(", RowBox[{ RowBox[{"!", "a"}], "&&", RowBox[{"!", "b"}], "&&", RowBox[{"!", "c"}], "&&", RowBox[{"!", "d"}]}], ")"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\"", ",", "\"\\""}], "}"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{"refines", " ", "all", " ", "circuit", " ", "events"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"mode", "\[Equal]", "cir"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"mode", "\[Rule]", "env"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"o1", "\[Rule]", RowBox[{ RowBox[{"i1", "\[Equal]", "True"}], "&&", RowBox[{"p2", "\[Equal]", "False"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"o2", "\[Rule]", RowBox[{ RowBox[{"i2", "\[Equal]", "True"}], "&&", RowBox[{"!", RowBox[{"(", RowBox[{ RowBox[{"i1", "\[Equal]", "True"}], "&&", RowBox[{"p2", "\[Equal]", "False"}]}], ")"}]}]}]}], ",", "\[IndentingNewLine]", RowBox[{"p2", "\[Rule]", RowBox[{ RowBox[{"i1", "\[Equal]", "True"}], "&&", RowBox[{"i2", "\[Equal]", "True"}], "&&", RowBox[{"p2", "\[Equal]", "False"}]}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[242]:=",ExpressionUUID->"9e2b9b53-0762-4c2d-ab06-afd8485fe474"], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ RowBox[{"with", " ", "default", " ", "method"}], "->", RowBox[{ "Full", " ", "the", " ", "invariant", " ", "inv1_", "8", " ", "takes", " ", "forever", " ", "to", " ", "prove"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"validateModel", "[", RowBox[{"myModel4", ",", RowBox[{"method", "->", "Piecewise"}]}], "]"}]}]], "Input",ExpressionUUID->\ "0f7bee00-3d86-4830-b497-b598aa040956"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Model with non-deterministic actions", "Subsection",ExpressionUUID->"d1d3fe04-bab6-47bc-b597-f2325079c0ed"], Cell["\<\ This example demonstrates how non-deterministic actions can be refined to \ become deterministic at the final, concrete level.\ \>", "Text",ExpressionUUID->"107d54e3-65a5-4880-bde6-e6ced0864a90"], Cell["\<\ The model deals with \[OpenCurlyDoubleQuote]earning\[CloseCurlyDoubleQuote] \ and \[OpenCurlyDoubleQuote]spending\[CloseCurlyDoubleQuote] and the relevant \ modifications of account state.\ \>", "Text",ExpressionUUID->"6c3b4c26-cbfe-4a59-bb29-dd2fbf3b7d47"], Cell[CellGroupData[{ Cell["Initial model", "Subsubsection",ExpressionUUID->"39e187d5-1dee-4426-a06f-0370a9afa0b2"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"account", "\[GreaterEqual]", "0"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"account", " ", "state"}], ",", " ", RowBox[{"no", " ", "debts"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"account", "\[Rule]", "0"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"at", " ", "high", " ", "abstraction", " ", "level"}], ",", " ", RowBox[{ "earning", " ", "increases", " ", "the", " ", "account", " ", "state"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"account", "\[Rule]", "newAccount"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"non", "-", "deterministic"}], "..."}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"newAccount", ">", "account"}]}], " ", RowBox[{"(*", " ", RowBox[{ "...", "but", " ", "we", " ", "know", " ", "that", " ", "account", " ", "increases"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"at", " ", "high", " ", "abstraction", " ", "level"}], ",", " ", RowBox[{ "spending", " ", "decreases", " ", "the", " ", "account", " ", "state"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"account", ">", "0"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"account", "\[Rule]", "newAccount"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"non", "-", "deterministic"}], "..."}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"0", "\[LessEqual]", "newAccount", "<", "account"}]}], " ", RowBox[{"(*", " ", RowBox[{ "but", " ", "we", " ", "know", " ", "that", " ", "account", " ", "decreases", " ", RowBox[{"(", RowBox[{"but", " ", "no", " ", "debts"}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[244]:=",ExpressionUUID->"43509910-87c1-4c38-8b85-6d9a2948e943"], Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"myModel0", ",", RowBox[{"verbose", "\[Rule]", "Total"}]}], "]"}]], "Input", CellLabel-> "In[245]:=",ExpressionUUID->"79db81ae-b009-4340-b746-e1f0ddf012ae"] }, Closed]], Cell[CellGroupData[{ Cell["First refinement", "Subsubsection",ExpressionUUID->"50b12d43-07a7-49b5-9add-7ae40fb60100"], Cell["\<\ In this refinement, earning is constrained to \[OpenCurlyDoubleQuote]small\ \[CloseCurlyDoubleQuote] amounts only. This demonstrates strengthening of promises.\ \>", "Text",ExpressionUUID->"ae64c10d-6dc3-439d-929f-7a72263bb514"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{ "earning", " ", "a", " ", "bit", " ", "is", " ", "still", " ", "earning"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"account", "\[Rule]", "newAccount"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"still", " ", "non"}], "-", "deterministic"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"account", "<", "newAccount", "\[LessEqual]", RowBox[{"account", "+", "1000"}]}]}], " ", RowBox[{"(*", " ", RowBox[{"only", " ", "small", " ", "amounts", " ", "allowed"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[246]:=",ExpressionUUID->"655de7ce-d07f-4890-aba1-785562178e0b"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel-> "In[247]:=",ExpressionUUID->"29668ad4-f3a8-4cbc-805d-eadd1b8fbc00"] }, Closed]], Cell[CellGroupData[{ Cell["Final version", "Subsubsection",ExpressionUUID->"25074e76-088e-420b-8930-c71e997f2642"], Cell["\<\ The final refinement uses only deterministic actions. This demonstrates superposition of state over base promises.\ \>", "Text",ExpressionUUID->"3546e041-0a78-451f-9882-a95da5ed21fd"], Cell[BoxData[ RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{"cutting", " ", "grass", " ", "earns", " ", "a", " ", RowBox[{"bit", "!"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"account", "\[Rule]", RowBox[{"account", "+", "100"}]}]}], " ", RowBox[{"(*", " ", RowBox[{"deterministic", ",", " ", RowBox[{"concrete", " ", "action"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"(*", " ", RowBox[{"buying", " ", "chips", " ", "is", " ", "spending"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"account", ">=", "10"}], ",", "\[IndentingNewLine]", RowBox[{"account", "\[Rule]", RowBox[{"account", "-", "10"}]}]}], " ", RowBox[{"(*", " ", RowBox[{"deterministic", ",", " ", RowBox[{"concrete", " ", "action"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[248]:=",ExpressionUUID->"4c3d5464-8eba-4cbb-ab02-d64ce7c58086"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel-> "In[249]:=",ExpressionUUID->"cc69f105-6cdb-4ff5-9645-7cab4769ec39"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Model - sequential program - linear search", "Subsection",ExpressionUUID->"db449e30-3a15-4651-836b-4374053658aa"], Cell["\<\ This example is based on chapter 15 of the \"Modeling in Event-B\" book by \ Jean-Raymond Abrial. The model describes a linear search algorithm (finding an element in array, \ for example). Originally, the problem referred to the concept of array and \ array element explicitly, like in:\ \>", "Text",ExpressionUUID->"4d96b3b7-b558-418e-9f75-cfd7293eb903"], Cell[BoxData[{ RowBox[{ RowBox[{"r", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"f", "[", RowBox[{"[", "r", "]"}], "]"}], "\[Equal]", "v"}], ";"}]}], "Input",Expres\ sionUUID->"45f37892-00c5-4ca1-9424-b113a1b2bd32"], Cell["\<\ where r is an array index, f is an array of size n and v is an element to be \ found. However, these details are irrelevant for the algorithm itself, so the notion \ that r is the interesting index value can be expressed with abstract \ predicate like this:\ \>", "Text",ExpressionUUID->"fdc64ac0-fcdb-4291-828c-15067eacdcf5"], Cell[BoxData[ RowBox[{"good", "[", "r", "]"}]], "Input",ExpressionUUID->"7b4b1653-8805-4416-b2d2-057ea1ce4f0c"], Cell["\<\ where \[OpenCurlyDoubleQuote]good\[CloseCurlyDoubleQuote] has no special \ meaning from the algorithm point of view. This allows to simplify the \ deduction engine.\ \>", "Text",ExpressionUUID->"e7a0a2c6-7b24-41a5-a3d9-a34d041acef6"], Cell["\<\ Considering the fact that \[OpenCurlyDoubleQuote]good\[CloseCurlyDoubleQuote] \ is not itself defined anywhere, it is a ghost predicate.\ \>", "Text",ExpressionUUID->"33a8086d-26a7-4136-8a55-f187d32c7b4d"], Cell[CellGroupData[{ Cell["Initial version", "Subsubsection",ExpressionUUID->"4f91ea36-78ea-496f-a939-3b9e353f11f5"], Cell["\<\ The initial version just provides structure for the algorithm development - \ the machine has \[OpenCurlyDoubleQuote]progress\[CloseCurlyDoubleQuote] and \ \[OpenCurlyDoubleQuote]final\[CloseCurlyDoubleQuote] events that will be \ developed in later refinements.\ \>", "Text",ExpressionUUID->"23ec6047-18c8-4ed8-a45c-fe2d2becc5d9"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"n", "\[Element]", "Integers"}], ",", RowBox[{"n", "\[GreaterEqual]", "1"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"array", " ", "size"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"r", "\[Element]", "Integers"}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"array", " ", "index"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"\"\\"", " ", "event", " ", "to", " ", "mark", " ", "the", " ", "end", " ", "of", " ", "algorithm"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"good", "[", "r", "]"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"abstract", " ", "and", " ", "non"}], "-", RowBox[{ "deterministic", " ", "progress", " ", "that", " ", "\"\\"", " ", "establishes", " ", "new", " ", "index", " ", "value"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"r", ">", "0"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[250]:=",ExpressionUUID->"bd2bd181-ec0c-4aff-a48b-27cefa5680af"], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ RowBox[{"Note", ":", " ", RowBox[{ "this", " ", "model", " ", "will", " ", "NOT", " ", "validate"}]}], ",", " ", RowBox[{ "because", " ", "there", " ", "is", " ", "no", " ", "reasonable", " ", "initial", " ", "value", " ", "and", " ", "also", " ", "\"\\"", " ", "guard", " ", "has", " ", "no", " ", "meaning", " ", "and", " ", "is", " ", "therefore", " ", "not", " ", "reachable"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"validateModel", "[", "myModel0", "]"}]}]], "Input", CellLabel-> "In[251]:=",ExpressionUUID->"1fd06fa0-672b-458d-a48d-2d3362275e85"] }, Closed]], Cell[CellGroupData[{ Cell["Refinement", "Subsubsection",ExpressionUUID->"c8060933-912c-4822-b3f3-b7993efe1d7f"], Cell["\<\ This refinement makes the progress action more concrete (it moves the index \ forward) and introduces an invariant that adds meaning to the \ \[OpenCurlyDoubleQuote]good\[CloseCurlyDoubleQuote] predicate.\ \>", "Text",ExpressionUUID->"b4eb18de-d5fc-4690-bf86-df75628fe412"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1a", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"algorithm", " ", "starts", " ", "at", " ", "index", " ", "1"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"r", "\[Rule]", "1"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "index", " ", "is", " ", "always", " ", "within", " ", "array"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"r", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "there", " ", "is", " ", "no", " ", "interesting", " ", "element", " ", "in", " ", "the", " ", "range", " ", "that", " ", "was", " ", "checked", " ", "so", " ", "far"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"ForAll", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", RowBox[{"r", "-", "1"}]}], "]"}]}], ",", RowBox[{"\[Not]", RowBox[{"good", "[", "x", "]"}]}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"variant", " ", "for", " ", "event", " ", "\"\\""}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "-", "r"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"concrete", " ", "algorithm", " ", "step"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"r", "<", "n"}], "\[And]", RowBox[{"\[Not]", RowBox[{"good", "[", "r", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"r", "\[Rule]", RowBox[{"r", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"\"\\"", " ", "termination", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"r", "\[Equal]", "n"}], "\[And]", RowBox[{"\[Not]", RowBox[{"good", "[", "r", "]"}]}]}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[459]:=",ExpressionUUID->"f6fbd9cf-6a2a-485d-ab45-b9b5f20238b1"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1a", "]"}]], "Input", CellLabel-> "In[460]:=",ExpressionUUID->"1b1dec94-88d0-4b86-9cd2-61afee660317"] }, Closed]], Cell[CellGroupData[{ Cell["Alternative Refinement (with guaranteed success)", "Subsubsection",ExpressionUUID->"001f6132-3b85-4422-886f-f159b1689a4a"], Cell["\<\ This refinement offers a different solution with the assumption that the \ element searched for is guaranteed to exist somewhere in the array. Thanks to \ this assumption the \[OpenCurlyDoubleQuote]failed\[CloseCurlyDoubleQuote] \ event is not needed and the \[OpenCurlyDoubleQuote]progress\ \[CloseCurlyDoubleQuote] event is guaranteed to find the right index without \ falling out of array. Axiom \[OpenCurlyDoubleQuote]axiom1_1\[CloseCurlyDoubleQuote] ensures that \ the element will be found, ultimately, and invariant \ \[OpenCurlyDoubleQuote]inv1_3\[CloseCurlyDoubleQuote] keeps that promise \ along the process.\ \>", "Text",ExpressionUUID->"967b7f52-7f88-41ba-beaa-4cad2e775e73"], Cell["In order to prove \[OpenCurlyDoubleQuote]inv1_1\[CloseCurlyDoubleQuote] \ here, it is useful to note that:", "Text",ExpressionUUID->"6e8d7e08-2576-4b6e-\ b13c-69ae8a140283"], Cell["IF:", "Text",ExpressionUUID->"46a91303-e108-4c40-b1b4-e68c9a0a2f6a"], Cell[BoxData[ RowBox[{ RowBox[{"n", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"r", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{ SubscriptBox["\[Exists]", RowBox[{"x", ",", RowBox[{ RowBox[{"x", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"x", "\[Element]", RowBox[{"r", ";;", "n"}]}]}]}]], RowBox[{"good", "[", "x", "]"}]}]}]], "Input",ExpressionUUID->"4276e9c0-\ b43e-467b-a7da-36f550875e5e"], Cell["THEN:", "Text",ExpressionUUID->"133f0752-6d5a-4595-9bdd-a69feecd647a"], Cell[BoxData[ RowBox[{ RowBox[{"r", "\[Equal]", "n"}], "\[Implies]", RowBox[{"good", "[", "r", "]"}]}]], "Input",ExpressionUUID->"fc890e08-2ca3-\ 4444-baf6-82f2fbdad0bd"], Cell["In other words:", "Text", CellChangeTimes->{{3.9100904395969896`*^9, 3.910090443080231*^9}},ExpressionUUID->"da50d09d-9624-406d-b136-\ 3dc5a84999b5"], Cell["IF:", "Text",ExpressionUUID->"fae7e6c8-e774-4afe-b157-4fbb65aeaacf"], Cell[BoxData[ RowBox[{ RowBox[{"n", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"r", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{ SubscriptBox["\[Exists]", RowBox[{"x", ",", RowBox[{ RowBox[{"x", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"x", "\[Element]", RowBox[{"r", ";;", "n"}]}]}]}]], RowBox[{"good", "[", "x", "]"}]}]}]], "Input",ExpressionUUID->"e9776f6a-\ a151-472a-831a-b91ca08e2f2a"], Cell["THEN:", "Text",ExpressionUUID->"576bd27f-477e-4369-b214-d62c9cf1d827"], Cell[BoxData[ RowBox[{ RowBox[{"\[Not]", RowBox[{"good", "[", "r", "]"}]}], "\[Implies]", RowBox[{"r", "\[NotEqual]", "n"}]}]], "Input",ExpressionUUID->"c8954b35-\ 0c39-4323-b346-f1ae4decf986"], Cell["\<\ This means that the guard of event \[OpenCurlyDoubleQuote]progress\ \[CloseCurlyDoubleQuote] implies that r!=n, but this has to be injected in \ terms of a theorem hint.\ \>", "Text",ExpressionUUID->"321db477-9051-4cd8-9b69-655358aaa74b"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1b", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "this", " ", "algorithm", " ", "assumes", " ", "that", " ", "the", " ", "interesting", " ", "element", " ", "is", " ", "somewhere", " ", "in", " ", "the", " ", "array"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"Exists", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}], ",", RowBox[{"good", "[", "x", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"algorithm", " ", "starts", " ", "at", " ", "index", " ", "1"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"r", "\[Rule]", "1"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "index", " ", "is", " ", "always", " ", "within", " ", "array"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"r", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "there", " ", "is", " ", "no", " ", "interesting", " ", "element", " ", "in", " ", "the", " ", "range", " ", "that", " ", "was", " ", "checked", " ", "so", " ", "far"}], "..."}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"ForAll", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", RowBox[{"r", "-", "1"}]}], "]"}]}], ",", RowBox[{"\[Not]", RowBox[{"good", "[", "x", "]"}]}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "...", " ", "the", " ", "interesting", " ", "element", " ", "must", " ", "be", " ", "in", " ", "the", " ", "remaining", " ", "part"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"Exists", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"r", ",", "n"}], "]"}]}], ",", RowBox[{"good", "[", "x", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"theorem", " ", "hint", " ", "for", " ", "inv1_", "1"}], ",", " ", RowBox[{"as", " ", "explained", " ", "above"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"\[Not]", RowBox[{"good", "[", "r", "]"}]}], "\[Implies]", RowBox[{"r", "\[NotEqual]", "n"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"variant", " ", "for", " ", "event", " ", "\"\\""}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "-", "r"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"concrete", " ", "algorithm", " ", "step"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"\[Not]", RowBox[{"good", "[", "r", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"r", "\[Rule]", RowBox[{"r", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.9100819267151394`*^9, 3.9100819861898165`*^9}, { 3.9100823445213785`*^9, 3.9100823813652053`*^9}, {3.910082422412839*^9, 3.9100824550709553`*^9}, {3.910082508083146*^9, 3.910082519711175*^9}, { 3.910083502057701*^9, 3.910083519328993*^9}, {3.910083615912239*^9, 3.9100836351534967`*^9}, {3.910088134242342*^9, 3.910088152746313*^9}, { 3.910088256239577*^9, 3.9100882587729516`*^9}, 3.9100885577491755`*^9, { 3.9100885916912107`*^9, 3.910088591887946*^9}, {3.910088672686555*^9, 3.9100886771499033`*^9}, {3.9100896280379925`*^9, 3.910089628777809*^9}, { 3.910090378496068*^9, 3.910090380181554*^9}, {3.91009052273209*^9, 3.9100906995978155`*^9}, {3.9100912958116703`*^9, 3.9100913072660575`*^9}, {3.910091398420065*^9, 3.9100913996803656`*^9}, { 3.910091664302694*^9, 3.910091684313448*^9}, {3.910091724388686*^9, 3.910091725409337*^9}, {3.9101554588930397`*^9, 3.9101554686523004`*^9}, { 3.9101557702215977`*^9, 3.910155794328472*^9}, {3.9101559416996703`*^9, 3.9101559428391967`*^9}, 3.9101564881969137`*^9, {3.910168783091488*^9, 3.9101688059410486`*^9}}, CellLabel-> "In[255]:=",ExpressionUUID->"b523f71b-57eb-4fce-a881-29429703e13b"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1b", "]"}]], "Input", CellLabel-> "In[458]:=",ExpressionUUID->"5b8b82f2-d26c-44c1-b0ee-10a3b0e19ba2"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Model - sequential program - binary search in sorted array", \ "Subsection",ExpressionUUID->"80bac012-f39f-4759-b1ed-f59b85255241"], Cell["\<\ This example is based on chapter 15 of the \"Modeling in Event-B\" book by \ Jean-Raymond Abrial. The model describes a binary search algorithm (presumably in a sorted array), \ and uses ghost predicates to hide the concept of array altogether. \ \>", "Text",ExpressionUUID->"65965991-7edf-4104-af2c-659b6be13a9e"], Cell[CellGroupData[{ Cell["Initial version", "Subsubsection",ExpressionUUID->"d8e97376-3c4a-4f57-adcc-b7d2e472ace4"], Cell["\<\ As in the linear search example, the initial version is the same and just \ provides structure for the algorithm development.\ \>", "Text",ExpressionUUID->"8c9c3f0c-f508-4685-a0f8-3518fe52b108"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"n", "\[Element]", "Integers"}], ",", RowBox[{"n", "\[GreaterEqual]", "1"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"array", " ", "size"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"r", "\[Element]", "Integers"}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"array", " ", "index"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"\"\\"", " ", "event", " ", "to", " ", "mark", " ", "the", " ", "end", " ", "of", " ", "algorithm"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"good", "[", "r", "]"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"abstract", " ", "and", " ", "non"}], "-", RowBox[{ "deterministic", " ", "progress", " ", "that", " ", "\"\\"", " ", "establishes", " ", "new", " ", "index", " ", "value"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"r", ">", "0"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel->"In[40]:=",ExpressionUUID->"e8c07a06-ddcd-4d62-b2f9-150cb45d5f2c"], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ RowBox[{"Note", ":", " ", RowBox[{ "this", " ", "model", " ", "will", " ", "NOT", " ", "validate", " ", "completely"}]}], ",", " ", RowBox[{ "because", " ", "there", " ", "is", " ", "no", " ", "initialization", " ", "and", " ", "the", " ", "ghost", " ", "predicate", " ", RowBox[{"good", "[", "]"}], " ", "is", " ", "not", " ", "glued", " ", "with", " ", "anything", " ", "else", " ", "in", " ", "the", " ", "model"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"validateModel", "[", "myModel0", "]"}]}]], "Input", CellLabel-> "In[462]:=",ExpressionUUID->"21d9fe5f-54cc-46a8-adf3-bdad93ec3dbf"] }, Closed]], Cell[CellGroupData[{ Cell["First refinement", "Subsubsection",ExpressionUUID->"972f3d72-b134-4f19-b042-0131ec38bc51"], Cell["\<\ In the first refinement we assume that the array contains the interesting \ element and we introduce two index variable p and q, which will denote the \ array range where the given element can be found. The events \[OpenCurlyDoubleQuote]inc\[CloseCurlyDoubleQuote] and \ \[OpenCurlyDoubleQuote]dec\[CloseCurlyDoubleQuote] are partial refinements of \ base event \[OpenCurlyDoubleQuote]progress\[CloseCurlyDoubleQuote] and they \ move p and q in such a way that range p..q inevitably converges. The r index \ is kept in a non-deterministic way anywhere in p..q.\ \>", "Text",ExpressionUUID->"a0f2b17d-1e86-4dd6-9f97-fe3dbc704c08"], Cell["\<\ The ghost predicate \[OpenCurlyDoubleQuote]below\[CloseCurlyDoubleQuote] \ indicates that the given index is below the interesting value in the sorted \ array and predicate \[OpenCurlyDoubleQuote]above\[CloseCurlyDoubleQuote] \ indicates that the index is above the final one; as in the previous example, \ predicate \[OpenCurlyDoubleQuote]good\[CloseCurlyDoubleQuote] means that the \ element was found.\ \>", "Text",ExpressionUUID->"ccb28ec1-f6b7-411f-b10b-16d3c7a2b6ca"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "the", " ", "element", " ", "is", " ", "somewhere", " ", "in", " ", "the", " ", "array"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"Exists", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}], ",", RowBox[{"good", "[", "x", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"index", " ", "variables", " ", "p"}], ",", " ", "q", ",", " ", RowBox[{ "and", " ", "r", " ", "are", " ", "always", " ", "within", " ", "array"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"p", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"q", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"r", "\[Element]", RowBox[{"Span", "[", RowBox[{"p", ",", "q"}], "]"}]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"r", " ", "is", " ", "within", " ", "p"}], ".."}], "q"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"starting", " ", "values"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"p", "\[Rule]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"q", "\[Rule]", "n"}], ",", "\[IndentingNewLine]", RowBox[{"r", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"non", "-", "deterministic"}], ",", " ", RowBox[{"but", " ", "within", " ", "inv1_", "3"}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "the", " ", "given", " ", "element", " ", "is", " ", "always", " ", "within", " ", "range", " ", "denoted", " ", "by", " ", "indices", " ", "p", " ", "and", " ", "q"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"Exists", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"p", ",", "q"}], "]"}]}], ",", RowBox[{"good", "[", "x", "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "these", " ", "theorems", " ", "bind", " ", "the", " ", "\"\\""}], ",", " ", RowBox[{"\"\\"", " ", "and", " ", "\"\\"", " ", "concepts"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"below", "[", "r", "]"}], "\[Implies]", RowBox[{"ForAll", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "r"}], "]"}]}], ",", RowBox[{ RowBox[{"below", "[", "x", "]"}], "\[And]", RowBox[{"\[Not]", RowBox[{"good", "[", "x", "]"}]}]}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"above", "[", "r", "]"}], "\[Implies]", RowBox[{"ForAll", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"r", ",", "n"}], "]"}]}], ",", RowBox[{ RowBox[{"above", "[", "x", "]"}], "\[And]", RowBox[{"\[Not]", RowBox[{"good", "[", "x", "]"}]}]}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "variant", " ", "for", " ", "both", " ", "\"\\"", " ", "and", " ", "\"\\""}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"q", "-", "p"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"below", "[", "r", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "increase", " ", "the", " ", "lower", " ", "border", " ", "of", " ", "the", " ", "search", " ", "region"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"p", "\[Rule]", RowBox[{"r", "+", "1"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "set", " ", "r", " ", "anywhere", " ", "in", " ", "the", " ", "new", " ", RowBox[{"region", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"r", "\[Rule]", "newR"}], ",", "\[IndentingNewLine]", RowBox[{"newR", "\[Element]", RowBox[{"Span", "[", RowBox[{ RowBox[{"r", "+", "1"}], ",", "q"}], "]"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"above", "[", "r", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "decrease", " ", "the", " ", "upper", " ", "border", " ", "of", " ", "the", " ", "search", " ", "region"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"q", "\[Rule]", RowBox[{"r", "-", "1"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "set", " ", "r", " ", "anywhere", " ", "in", " ", "the", " ", "new", " ", RowBox[{"region", ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"r", "\[Rule]", "newR"}], ",", "\[IndentingNewLine]", RowBox[{"newR", "\[Element]", RowBox[{"Span", "[", RowBox[{"p", ",", RowBox[{"r", "-", "1"}]}], "]"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel->"In[41]:=",ExpressionUUID->"c4bab121-f2c1-4eda-ba87-b0f3467c5aae"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel-> "In[464]:=",ExpressionUUID->"a6a5e309-87d9-4fe1-8ba3-b7ff4bee0738"] }, Closed]], Cell[CellGroupData[{ Cell["Second refinement", "Subsubsection",ExpressionUUID->"2a6b7759-5648-44ba-bdbd-7eab7536f2e9"], Cell["\<\ This (final) refinement reduces the non-determinism of actions by assigning \ concrete \[OpenCurlyDoubleQuote]middle\[CloseCurlyDoubleQuote] value for new \ index.\ \>", "Text",ExpressionUUID->"d3df5906-1d21-42df-8c22-efab3ac7f80d"], Cell[BoxData[ RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"r", "\[Element]", "Integers"}], ",", RowBox[{"r", "\[Rule]", RowBox[{ RowBox[{"(", RowBox[{"1", "+", "n"}], ")"}], "/", "2"}]}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"Note", ":", "\[IndentingNewLine]", RowBox[{"the", " ", "underlying", " ", "engine", " ", RowBox[{"(", RowBox[{"ver", ".", " ", "13.3"}], ")"}], " ", "cannot", " ", "prove", " ", "that", " ", RowBox[{"(", RowBox[{"for", " ", "event", " ", "\"\\""}], ")"}]}], ":", "\[IndentingNewLine]", RowBox[{ RowBox[{"1", "+", "r"}], " ", "<=", " ", RowBox[{"1", "+", "r", "+", RowBox[{"IntegerPart", "[", RowBox[{ FractionBox["1", "2"], " ", RowBox[{"(", RowBox[{ RowBox[{"-", "1"}], "+", "q", "-", "r"}], ")"}]}], "]"}]}], " ", "<=", " ", RowBox[{ "q", "\[IndentingNewLine]", "and", " ", "that", " ", "the", " ", "middle", " ", "value", " ", "is", " ", "Integer"}]}]}], ";", "\[IndentingNewLine]", RowBox[{ "we", " ", "assume", " ", "that", " ", "the", " ", "above", " ", "can", " ", "be", " ", "proven", " ", "by", " ", "\"\\"", " ", "and", " ", "we", " ", "replace", " ", "the", " ", "problem", " ", "in", " ", "place", " ", "by", " ", "means", " ", "of", " ", RowBox[{"theorem", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"1", "+", "r", "+", RowBox[{"IntegerPart", "[", RowBox[{ FractionBox["1", "2"], " ", RowBox[{"(", RowBox[{ RowBox[{"-", "1"}], "+", "q", "-", "r"}], ")"}]}], "]"}]}], "\[Equal]", "newR"}], "\[IndentingNewLine]", "->", "\[IndentingNewLine]", RowBox[{"newR", "\[Element]", RowBox[{ RowBox[{"1", "+", "r"}], ";;", "q"}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Similarly", ",", " ", RowBox[{ RowBox[{"for", " ", "event", " ", "\"\\""}], ":"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"p", "+", RowBox[{"IntegerPart", "[", RowBox[{ FractionBox["1", "2"], " ", RowBox[{"(", RowBox[{ RowBox[{"-", "1"}], "-", "p", "+", "r"}], ")"}]}], "]"}]}], "\[Equal]", "newR"}], "\[IndentingNewLine]", "->", "\[IndentingNewLine]", RowBox[{"newR", "\[Element]", RowBox[{"p", ";;", RowBox[{"r", "-", "1"}]}]}]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"below", "[", "r", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"p", "\[Rule]", RowBox[{"r", "+", "1"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"deterministic", " ", "middle", " ", "point"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"r", "\[Rule]", RowBox[{"IntegerPart", "[", RowBox[{ RowBox[{"(", RowBox[{"r", "+", "1", "+", "q"}], ")"}], "/", "2"}], "]"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"r", "\[Rule]", RowBox[{"r", "+", "1", "+", RowBox[{"IntegerPart", "[", RowBox[{ RowBox[{"(", RowBox[{"q", "-", "r", "-", "1"}], ")"}], "/", "2"}], "]"}]}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"above", "[", "r", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"q", "\[Rule]", RowBox[{"r", "-", "1"}]}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"deterministic", " ", "middle", " ", "point"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"r", "\[Rule]", RowBox[{"IntegerPart", "[", RowBox[{ RowBox[{"(", RowBox[{"p", "+", "r", "-", "1"}], ")"}], "/", "2"}], "]"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"r", "\[Rule]", RowBox[{"p", "+", RowBox[{"IntegerPart", "[", RowBox[{ RowBox[{"(", RowBox[{"r", "-", "1", "-", "p"}], ")"}], "/", "2"}], "]"}]}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input",ExpressionUUID->"fb02cd6d-\ c0b0-4ccf-af38-7a8bfe9f7f73"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel->"In[87]:=",ExpressionUUID->"1a32ebd5-f6bc-410b-931c-3baacf23a0ec"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Model - sequential program - minimum of an array of natural numbers\ \>", "Subsection",ExpressionUUID->"85496e65-e53c-4299-8d3a-d8c1eeee23b1"], Cell["\<\ This example is based on chapter 15 of the \"Modeling in Event-B\" book by \ Jean-Raymond Abrial.\[LineSeparator]The model uses similar techniques to \ examples above.\ \>", "Text",ExpressionUUID->"9aa0bc05-7923-4e88-a78b-9938861326e0"], Cell[CellGroupData[{ Cell["Initial model", "Subsubsection",ExpressionUUID->"96bf2f07-f185-4e56-b001-0bd9fef6cad1"], Cell["\<\ The initial model introduces only the array size and states that the array \ surely contains some \[OpenCurlyDoubleQuote]minimal\[CloseCurlyDoubleQuote] \ value.\ \>", "Text",ExpressionUUID->"0b006c9b-5a5d-4d81-9a9d-38ea084dff74"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"n", "\[Element]", "Integers"}], ",", RowBox[{"n", "\[GreaterEqual]", "1"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"array", " ", "size"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"Exists", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}], ",", RowBox[{"minimal", "[", "x", "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel->"In[88]:=",ExpressionUUID->"01854bd6-7e93-4271-b413-032fc75df3a1"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellLabel->"In[89]:=",ExpressionUUID->"0927f1b8-57db-4e65-a73a-81a966146336"] }, Closed]], Cell[CellGroupData[{ Cell["First refinement", "Subsubsection",ExpressionUUID->"e49956c7-40fa-420a-b4f9-32417bb54721"], Cell["\<\ This refinement introduces an index range p..q, which presumably contains the \ minimum array value. It also introduces events \[OpenCurlyDoubleQuote]inc\ \[CloseCurlyDoubleQuote] and \[OpenCurlyDoubleQuote]dec\ \[CloseCurlyDoubleQuote], which work towards systematic narrowing of this \ index range. The \[OpenCurlyDoubleQuote]minimalOrGreater\ \[CloseCurlyDoubleQuote] predicate indicates that value at the given index is \ not lower than the minimal of the whole array. The theorem binds together \ this concept with comparisons of array values.\ \>", "Text",ExpressionUUID->"86be1d28-f70a-44eb-8161-9ecaaeddff99"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"p", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"q", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"p", "\[LessEqual]", "q"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"Exists", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"p", ",", "q"}], "]"}]}], ",", RowBox[{"minimal", "[", "x", "]"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"p", "\[Rule]", "1"}], ",", RowBox[{"q", "\[Rule]", "n"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", RowBox[{"Function", "[", RowBox[{ RowBox[{"{", RowBox[{"knowns", ",", "question"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"knowns", "/.", RowBox[{ RowBox[{ RowBox[{"array", "[", "p", "]"}], ">", RowBox[{"array", "[", "q", "]"}]}], "\[Rule]", RowBox[{"!", RowBox[{"minimal", "[", "p", "]"}]}]}]}], ",", "question"}], "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", RowBox[{"Function", "[", RowBox[{ RowBox[{"{", RowBox[{"knowns", ",", "question"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"knowns", "/.", RowBox[{ RowBox[{ RowBox[{"array", "[", "p", "]"}], "\[LessEqual]", RowBox[{"array", "[", "q", "]"}]}], "\[Rule]", RowBox[{"!", RowBox[{"minimal", "[", "q", "]"}]}]}]}], ",", "question"}], "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "variant", " ", "for", " ", "\"\\"", " ", "and", " ", "\"\\""}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"q", "-", "p"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"p", "<", "q"}], "&&", RowBox[{ RowBox[{"array", "[", "p", "]"}], ">", RowBox[{"array", "[", "q", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"p", "\[Rule]", RowBox[{"p", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"p", "<", "q"}], "&&", RowBox[{ RowBox[{"array", "[", "p", "]"}], "\[LessEqual]", RowBox[{"array", "[", "q", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"q", "\[Rule]", RowBox[{"q", "-", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"!", "convergent"}], ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"minimal", "[", "p", "]"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel->"In[90]:=",ExpressionUUID->"cee61e21-95a6-495f-ac0a-1483c9527c16"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel->"In[91]:=",ExpressionUUID->"a9a1dd2e-67ec-4f94-9d09-26a392553130"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Model - sequential program - pattern for systematic array modification\ \>", "Subsection",ExpressionUUID->"b958e583-43ad-4e23-9afe-fc52593359cc"], Cell["\<\ This model demonstrates the way to describe algorithms that \ \[OpenCurlyDoubleQuote]modify an array\[CloseCurlyDoubleQuote], where neither \ the modification nor array is directly supported by the syntax. Instead, \ ghost predicates are used in non-deterministic actions (promises) to guide \ the proofs. The assumption is that the actual model implementation in some \ imperative programming language will fulfill those promises.\ \>", "Text",ExpressionUUID->"d24f5ffb-9333-4cb7-84ff-e613cf6c92ce"], Cell["\<\ The model sets all array elements to zero. The \ \[OpenCurlyDoubleQuote]isSetToZero\[CloseCurlyDoubleQuote] is a ghost \ predicate.\ \>", "Text", CellChangeTimes->{{3.972117378243902*^9, 3.9721173786516857`*^9}},ExpressionUUID->"32402770-f928-48ad-b5ae-\ 5bf9e33426bf"], Cell[BoxData[ RowBox[{ RowBox[{"myModel", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"n", "\[Element]", TemplateBox[{}, "Integers"]}], ",", RowBox[{"n", "\[GreaterEqual]", "1"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"array", " ", "size"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"1", ".."}], "i", " ", "indicates", " ", "the", " ", "range", " ", "of", " ", "array", " ", "that", " ", "was", " ", "already", " ", "processed"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"i", "\[Element]", TemplateBox[{}, "Integers"]}], "\[And]", RowBox[{"ForAll", "[", RowBox[{"x", ",", RowBox[{"x", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "i"}], "]"}]}], ",", RowBox[{"isSetToZero", "[", "x", "]"}]}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"i", "\[Rule]", "0"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "-", "i"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "ensures", " ", "that", " ", "progress", " ", "ultimately", " ", "finishes"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"i", "<", "n"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"i", "\[Rule]", RowBox[{"i", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"isSetToZero", "[", RowBox[{"i", "+", "1"}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{"non", "-", RowBox[{"deterministic", " ", "promise"}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ "marks", " ", "the", " ", "end", " ", "of", " ", "algorithm"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"i", "\[Equal]", "n"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "invariant", " ", "inv", " ", "guarantess", " ", "that", " ", "the", " ", "whole", " ", "array", " ", "\"\\""}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel->"In[92]:=",ExpressionUUID->"77026a82-6801-434c-a3d1-32d17d59d68f"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel", "]"}]], "Input", CellLabel->"In[93]:=",ExpressionUUID->"e1dfd714-8e96-4f0b-baeb-ef539d171e6b"] }, Closed]], Cell[CellGroupData[{ Cell["Model - sequential program - array partitioning", "Subsection",ExpressionUUID->"f38c7f5e-7ab9-4742-b0ca-edea15c0ca40"], Cell["\<\ This example is based on chapter 15 of the \[OpenCurlyDoubleQuote]Modeling in \ Event-B\[CloseCurlyDoubleQuote] book by Jean-Raymond Abrial. The model describes partitioning of array into two parts, where one part \ (from the beginning) contains elements smaller than the given threshold and \ the rest (to the end) contains larger elements.\ \>", "Text",ExpressionUUID->"40024dfe-8662-45c8-8634-e90fde112f79"], Cell["\<\ The model does not use the notion of array or element modification directly, \ but hides them behind ghost predicate, like in previous examples.\ \>", "Text",ExpressionUUID->"bd278449-91ca-4389-ab81-55c0aeef8b3a"], Cell[CellGroupData[{ Cell["Initial model", "Subsubsection",ExpressionUUID->"c3218f46-1f72-4847-8966-a71d5f2b1ef2"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"n", "\[Element]", TemplateBox[{}, "Integers"]}], ",", RowBox[{"n", "\[GreaterEqual]", "1"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"array", " ", "size"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "k", " ", "is", " ", "an", " ", "index", " ", "indicating", " ", "partitioning", " ", "point"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"k", "\[Element]", TemplateBox[{}, "Integers"]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"k", "\[Element]", TemplateBox[{}, "Integers"]}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"non", "-", "deterministic"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"k", "\[Element]", TemplateBox[{}, "Integers"]}]}], " ", RowBox[{"(*", " ", RowBox[{"non", "-", RowBox[{"deterministic", " ", "promise"}]}], " ", "*)"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"ForAll", "[", RowBox[{"m", ",", RowBox[{"m", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "k"}], "]"}]}], ",", RowBox[{"\[Not]", RowBox[{"isGreater", "[", "m", "]"}]}]}], "]"}], "\[And]", "\[IndentingNewLine]", RowBox[{"ForAll", "[", RowBox[{"m", ",", RowBox[{"m", "\[Element]", RowBox[{"Span", "[", RowBox[{ RowBox[{"k", "+", "1"}], ",", "n"}], "]"}]}], ",", RowBox[{"isGreater", "[", "m", "]"}]}], "]"}]}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel->"In[94]:=",ExpressionUUID->"7d6f9a1e-00b1-4dde-897a-cc1df5530575"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellLabel->"In[95]:=",ExpressionUUID->"7dd8708a-7a7b-4d67-bed9-d41562e9832a"] }, Closed]], Cell[CellGroupData[{ Cell["First refinement", "Subsubsection",ExpressionUUID->"b289c5a7-d32f-4ff9-9acb-dd3407191f48"], Cell["\<\ This refinement introduces variable j that divides the portion of array above \ k into part that was already processed (k+1..j, where elements are greater \ than threshold) and part that was not yet processed (j+1..n). As such, there \ are three ranges that are managed by the model: - 1..k, where elements are not greater than threshold (see invariant \ inv1_5), - k+1..j, where elements are greater than threshold (see invariant inv1_6), - j+1..n, which was not yet processed. Variable j is also a \[OpenCurlyDoubleQuote]loop control variable\ \[CloseCurlyDoubleQuote] in the sense that it starts from 0 and walks up to \ the end of array.\ \>", "Text",ExpressionUUID->"84c758b6-7723-47e1-af12-2576bba8eee2"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"j", "\[Element]", RowBox[{"Span", "[", RowBox[{"0", ",", "n"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"k", "\[Element]", RowBox[{"Span", "[", RowBox[{"0", ",", "j"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "these", " ", "invariants", " ", "describe", " ", "the", " ", "already", " ", "processed", " ", "part", " ", "of", " ", "array"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ForAll", "[", RowBox[{"m", ",", RowBox[{"m", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "k"}], "]"}]}], ",", RowBox[{"\[Not]", RowBox[{"isGreater", "[", "m", "]"}]}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ForAll", "[", RowBox[{"m", ",", RowBox[{"m", "\[Element]", RowBox[{"Span", "[", RowBox[{ RowBox[{"k", "+", "1"}], ",", "j"}], "]"}]}], ",", RowBox[{"isGreater", "[", "m", "]"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"j", "\[Rule]", "0"}], ",", RowBox[{"k", "\[Rule]", "0"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "-", "j"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "variant", " ", "for", " ", "all", " ", "progress", " ", "sub"}], "-", "events"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"j", "\[NotEqual]", "n"}], "\[And]", RowBox[{"isGreater", "[", RowBox[{"j", "+", "1"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"j", "\[Rule]", RowBox[{"j", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"j", "\[NotEqual]", "n"}], "\[And]", RowBox[{"\[Not]", RowBox[{"isGreater", "[", RowBox[{"j", "+", "1"}], "]"}]}], "\[And]", RowBox[{"k", "\[Equal]", "j"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"k", "\[Rule]", RowBox[{"k", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"j", "\[Rule]", RowBox[{"j", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"j", "\[NotEqual]", "n"}], "\[And]", RowBox[{"\[Not]", RowBox[{"isGreater", "[", RowBox[{"j", "+", "1"}], "]"}]}], "\[And]", RowBox[{"k", "\[NotEqual]", "j"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"k", "\[Rule]", RowBox[{"k", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"j", "\[Rule]", RowBox[{"j", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Not]", RowBox[{"isGreater", "[", RowBox[{"k", "+", "1"}], "]"}]}], "\[And]", RowBox[{"isGreater", "[", RowBox[{"j", "+", "1"}], "]"}]}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"non", "-", RowBox[{"deterministic", " ", "promise"}]}], ",", " ", RowBox[{ RowBox[{ "presumably", " ", "implemented", " ", "as", " ", "swap", " ", "of", " ", "elements", " ", "at", " ", "k"}], "+", RowBox[{"1", " ", "and", " ", "j"}], "+", "1"}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"j", "\[Equal]", "n"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"key", " ", "point"}], ",", " ", RowBox[{ "this", " ", "is", " ", "properly", " ", "matched", " ", "with", " ", "condition", " ", "in", " ", "base", " ", "model"}]}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel->"In[96]:=",ExpressionUUID->"c7dddc32-7a00-421d-b14c-1ed40cf0a35c"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel->"In[97]:=",ExpressionUUID->"b3692ccf-f4f2-436a-9ba5-62c37b606972"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Model - sequential program - simple sorting", "Subsection",ExpressionUUID->"be4a7148-8f4c-46ad-8000-e2fb8c0c8ae2"], Cell["\<\ This example is based on chapter 15 of the \[OpenCurlyDoubleQuote]Modeling in \ Event-B\[CloseCurlyDoubleQuote] book by Jean-Raymond Abrial. The model uses techniques from earlier examples.\ \>", "Text",ExpressionUUID->"61c5e85d-6b53-49ae-a60f-c6d15a264141"], Cell[CellGroupData[{ Cell["Initial model", "Subsubsection",ExpressionUUID->"24410418-54c8-4941-bf1b-94a89c65fec3"], Cell["\<\ In this model, isMinimum[a,b,c] is a (ghost) statement that element at index \ a is the minimal element from the index range range b..c.\ \>", "Text",ExpressionUUID->"3056e246-7509-434a-b840-c0b449bcaacf"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"n", "\[Element]", TemplateBox[{}, "Integers"]}], ",", RowBox[{"n", "\[GreaterEqual]", "1"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"array", " ", "size"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"ForAll", "[", RowBox[{"i", ",", RowBox[{"i", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", RowBox[{"n", "-", "1"}]}], "]"}]}], ",", RowBox[{"isMinimum", "[", RowBox[{"i", ",", "i", ",", "n"}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel->"In[98]:=",ExpressionUUID->"28e488c1-e9ea-49f1-9bb5-d41f3bc53b02"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellLabel->"In[99]:=",ExpressionUUID->"09a785ea-4a07-40ce-bd4f-ed837e02d53d"] }, Closed]], Cell[CellGroupData[{ Cell["First refinement", "Subsubsection",ExpressionUUID->"abf472cd-7ce7-462d-baac-778ee478b3dd"], Cell["\<\ This refinement introduces index k and promises to keep the invariant that \ all elements in range 1..k-1 are sorted and not greater than elements in \ remaining (k..n) part. There is also variable l, which is supposed (but not \ yet implemented at this level) to point to the minimum element in k..n.\ \>", "Text",ExpressionUUID->"e2e316bb-ecfa-43cb-afc1-81f324a1695a"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"k", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ForAll", "[", RowBox[{"i", ",", RowBox[{"i", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", RowBox[{"k", "-", "1"}]}], "]"}]}], ",", RowBox[{"isMinimum", "[", RowBox[{"i", ",", "i", ",", "n"}], "]"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"l", "\[Element]", TemplateBox[{}, "Integers"]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"k", "\[Rule]", "1"}], ",", RowBox[{"l", "\[Element]", TemplateBox[{}, "Integers"]}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "-", "k"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"variant", " ", "for", " ", "progress"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"k", "\[NotEqual]", "n"}], "\[And]", RowBox[{"l", "\[Element]", RowBox[{"Span", "[", RowBox[{"k", ",", "n"}], "]"}]}], "\[And]", RowBox[{"isMinimum", "[", RowBox[{"l", ",", "k", ",", "n"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"k", "\[Rule]", RowBox[{"k", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"l", "\[Element]", TemplateBox[{}, "Integers"]}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"still", " ", "non"}], "-", "deterministic"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"isMinimum", "[", RowBox[{"k", ",", "k", ",", "n"}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"non", "-", "deterministic"}], ",", " ", RowBox[{ "presumably", " ", "implemented", " ", "by", " ", "swapping", " ", "elements", " ", "at", " ", "k", " ", "and", " ", "l"}]}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ "prototype", " ", "for", " ", "\"\\"", " ", "that", " ", "finds", " ", "minimum", " ", "in", " ", "k"}], ".."}], "n"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"\[Not]", "convergent"}], ",", " ", RowBox[{"(*", " ", RowBox[{"we", " ", RowBox[{"don", "'"}], "t", " ", "promise", " ", "convergence", " ", "yet"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"l", "\[Element]", TemplateBox[{}, "Integers"]}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"k", "\[Equal]", "n"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "with", " ", "inv1_", "4", " ", "this", " ", "means", " ", "that", " ", "the", " ", "whole", " ", "array", " ", "is", " ", "sorted"}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[100]:=",ExpressionUUID->"1c67af7a-0d68-4f51-82e2-b81b71e122dc"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel-> "In[101]:=",ExpressionUUID->"a2a715db-5e85-46d9-a753-b0c773483ab3"] }, Closed]], Cell[CellGroupData[{ Cell["Second refinement", "Subsubsection",ExpressionUUID->"108e4a14-52e7-4fb3-a285-88fa126e0901"], Cell["\<\ This refinement develops the \[OpenCurlyDoubleQuote]nested loop\ \[CloseCurlyDoubleQuote] of event \[OpenCurlyDoubleQuote]prog\ \[CloseCurlyDoubleQuote] that finds the minimum element in range k..n. For \ this, variable j in this range separates the part that was tested from the \ part that was not yet tested with l maintained so that it is always at the \ minimum from k..j.\[LineSeparator]The whole model maintains the following \ ranges: - 1..k-1, which is already sorted with elements less than the rest of array, - k..j, with l pointing to the minimum in this range (and j walking towards \ to end), - j+1..n, which is not yet tested in the given run of the inner loop.\ \[LineSeparator]The helper (ghost) predicate isSmaller[a,b] is a statement \ that element at index a is smaller than element at index b. The relation of \ this predicate with isMinimum is provided in the form of explicit theorems.\ \>", "Text",ExpressionUUID->"00beec26-d942-4927-a8e4-10f724af3ac4"], Cell[BoxData[ RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"j", "\[Element]", RowBox[{"Span", "[", RowBox[{"k", ",", "n"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"l", "\[Element]", RowBox[{"Span", "[", RowBox[{"k", ",", "j"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"isMinimum", "[", RowBox[{"l", ",", "k", ",", "j"}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "a", " ", "couple", " ", "of", " ", "theorems", " ", "that", " ", "inductively", " ", "explain", " ", "the", " ", "meaning", " ", "of", " ", "isMinimum"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"isMinimum", "[", RowBox[{"l_", ",", "l_", ",", "l_"}], "]"}], "\[Rule]", "True"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"isMinimum", "[", RowBox[{"l", ",", "k", ",", "j"}], "]"}], "\[And]", RowBox[{"\[Not]", RowBox[{"isSmaller", "[", RowBox[{ RowBox[{"j", "+", "1"}], ",", "l"}], "]"}]}]}], ")"}], "\[Implies]", RowBox[{"isMinimum", "[", RowBox[{"l", ",", "k", ",", RowBox[{"j", "+", "1"}]}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"isMinimum", "[", RowBox[{"l", ",", "k", ",", "j"}], "]"}], "\[And]", RowBox[{"isSmaller", "[", RowBox[{ RowBox[{"j", "+", "1"}], ",", "l"}], "]"}]}], ")"}], "\[Implies]", RowBox[{"isMinimum", "[", RowBox[{ RowBox[{"j", "+", "1"}], ",", "k", ",", RowBox[{"j", "+", "1"}]}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "this", " ", "theorem", " ", "allows", " ", "to", " ", "discharge", " ", "reachability", " ", "of", " ", "isSmaller", " ", "predicate"}], ",", "\[IndentingNewLine]", RowBox[{ "and", " ", "also", " ", "cleans", " ", "up", " ", "that", " ", "predicate", " ", "after", " ", "it", " ", "was", " ", "used", " ", "in", " ", "previous", " ", "theorems"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", RowBox[{"_isSmaller", "\[Rule]", RowBox[{ RowBox[{"sm", "\[Equal]", "True"}], "&&", RowBox[{"sm", "\[Element]", "Booleans"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"k", "\[Rule]", "1"}], ",", RowBox[{"l", "\[Rule]", "1"}], ",", RowBox[{"j", "\[Rule]", "1"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "-", "j"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"variant", " ", "for", " ", "prog1", " ", "and", " ", "prog2"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"k", "\[NotEqual]", "n"}], "\[And]", "\[IndentingNewLine]", RowBox[{"j", "\[Equal]", "n"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "inv2_", "3", " ", "binds", " ", "this", " ", "with", " ", "the", " ", "guard", " ", "of", " ", "base", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"k", "\[Rule]", RowBox[{"k", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"j", "\[Rule]", RowBox[{"k", "+", "1"}]}], ",", " ", RowBox[{"(*", " ", RowBox[{ "this", " ", "restarts", " ", "the", " ", "inner", " ", "loop"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"l", "\[Rule]", RowBox[{"k", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"isMinimum", "[", RowBox[{"k", ",", "k", ",", "n"}], "]"}]}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"still", " ", "non"}], "-", "deterministic"}], " ", "*)"}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"k", "\[NotEqual]", "n"}], "\[And]", RowBox[{"j", "\[NotEqual]", "n"}], "\[And]", RowBox[{"\[Not]", RowBox[{"isSmaller", "[", RowBox[{ RowBox[{"j", "+", "1"}], ",", "l"}], "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"j", "\[Rule]", RowBox[{"j", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"k", "\[NotEqual]", "n"}], "\[And]", RowBox[{"j", "\[NotEqual]", "n"}], "\[And]", RowBox[{"isSmaller", "[", RowBox[{ RowBox[{"j", "+", "1"}], ",", "l"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"j", "\[Rule]", RowBox[{"j", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"l", "\[Rule]", RowBox[{"j", "+", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[102]:=",ExpressionUUID->"02ba8cce-1df2-4e37-bccf-e10a013a49b8"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel-> "In[103]:=",ExpressionUUID->"32db4d59-3ecd-42da-9dfb-64641752fa1e"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Model - sequential program - array reversing", "Subsection",ExpressionUUID->"a2718367-9c44-4219-b0f7-322c29578e7d"], Cell["\<\ This example is based on chapter 15 of the \[OpenCurlyDoubleQuote]Modeling in \ Event-B\[CloseCurlyDoubleQuote] book by Jean-Raymond Abrial. The model uses techniques from earlier examples.\ \>", "Text",ExpressionUUID->"c11c207d-4315-4819-a76e-f5c37fe98555"], Cell[CellGroupData[{ Cell["Initial model", "Subsubsection",ExpressionUUID->"06fd2ea4-e504-4462-9c51-1989c9e0918e"], Cell["\<\ In this model, isSwapped[a] is a (ghost) statement that element at index a \ and its respective pair from the other end of array (that is, at index n-a+1) \ are already swapped; it allows to isolate the notion of array from the \ algorithm itself.\ \>", "Text",ExpressionUUID->"5904ec18-4bec-4475-af99-946cf71a8ec5"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"n", "\[Element]", TemplateBox[{}, "Integers"]}], ",", RowBox[{"n", "\[GreaterEqual]", "1"}]}], "}"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"array", " ", "size"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"ForAll", "[", RowBox[{"k", ",", RowBox[{"k", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}], ",", RowBox[{"isSwapped", "[", "k", "]"}]}], "]"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[104]:=",ExpressionUUID->"6a7c23db-2a9b-43c6-99f9-b6bed64b842d"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellLabel-> "In[105]:=",ExpressionUUID->"9bec37ee-f2f2-4c8f-960c-3c41df5d363e"] }, Closed]], Cell[CellGroupData[{ Cell["First refinement", "Subsubsection",ExpressionUUID->"e07aa4d8-ca6f-4cc0-9194-f3a49c94c02d"], Cell["\<\ This refinement introduces indices i and j that move from both sides of array \ towards each other.\ \>", "Text",ExpressionUUID->"a4a97bf7-1a1d-4c72-83bd-6e4db756cde7"], Cell["\<\ The model maintains three ranges within the array: - 1..i-1, which is already reversed (with regard to j+1..n), - i..j, which is still unchanged, - j+1..n, which is already reversed (with regard to 1..i-1).\ \>", "Text",ExpressionUUID->"ded2fc3c-31df-4da6-964b-ba0f1f164a36"], Cell["\<\ Since both i and j traverse towards each other, they maintain the condition i \ + j == n + 1.\ \>", "Text",ExpressionUUID->"1a75a61b-aea1-421b-9323-32e457858d2f"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"i", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"j", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", "n"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"i", "+", "j"}], "\[Equal]", RowBox[{"n", "+", "1"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"i", "\[LessEqual]", RowBox[{"j", "+", "1"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ForAll", "[", RowBox[{"k", ",", RowBox[{"k", "\[Element]", RowBox[{"Span", "[", RowBox[{"1", ",", RowBox[{"i", "-", "1"}]}], "]"}]}], ",", RowBox[{"isSwapped", "[", "k", "]"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"ForAll", "[", RowBox[{"k", ",", RowBox[{"k", "\[Element]", RowBox[{"Span", "[", RowBox[{ RowBox[{"j", "+", "1"}], ",", "n"}], "]"}]}], ",", RowBox[{"isSwapped", "[", "k", "]"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "this", " ", "theorem", " ", "expresses", " ", "the", " ", "fact", " ", "that", " ", "swapping", " ", "always", " ", "affects", " ", "two", " ", "elements", " ", "at", " ", "the", " ", "same", " ", "time"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"theorem", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"isSwapped", "[", "i", "]"}], "\[Implies]", RowBox[{"isSwapped", "[", RowBox[{"n", "-", "i", "+", "1"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "this", " ", "theorem", " ", "states", " ", "that", " ", "middle", " ", "element", " ", "can", " ", "be", " ", "considered", " ", "already", " ", "swapped"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"ForAll", "[", RowBox[{"k", ",", RowBox[{ RowBox[{"k", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"k", "==", "i"}], "&&", RowBox[{"k", "\[Equal]", "j"}]}], ",", RowBox[{"isSwapped", "[", "k", "]"}]}], "]"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"i", "\[Rule]", "1"}], ",", RowBox[{"j", "\[Rule]", "n"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"j", "-", "i"}]}], "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{"obiously", ",", " ", RowBox[{ "shrinking", " ", "of", " ", "the", " ", "middle", " ", "region"}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"j", "\[LessEqual]", "i"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"i", "<", "j"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"isSwapped", "[", "i", "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ "presumably", " ", "implemented", " ", "as", " ", "swap", RowBox[{"(", RowBox[{ RowBox[{"A", "[", "i", "]"}], ",", " ", RowBox[{"A", "[", RowBox[{"n", "-", "i", "+", "1"}], "]"}]}], ")"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"i", "\[Rule]", RowBox[{"i", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"j", "\[Rule]", RowBox[{"j", "-", "1"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[106]:=",ExpressionUUID->"769dec76-8614-4679-9904-c07cd35444a0"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel-> "In[107]:=",ExpressionUUID->"50843857-9957-48ed-b5d6-6b108b1aa87c"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Model - sequential program - square root", "Subsection",ExpressionUUID->"ca96bb64-4a9f-4dbc-94f3-422f2675c925"], Cell["\<\ This example is based on chapter 15 of the \[OpenCurlyDoubleQuote]Modeling in \ Event-B\[CloseCurlyDoubleQuote] book by Jean-Raymond Abrial.\ \>", "Text",ExpressionUUID->"70d9fa9c-a69c-41e1-a4ac-777aa8dd698f"], Cell["\<\ The goal of this model is, given input number n, to compute r such that:\ \>", "Text",ExpressionUUID->"8071992b-2bbe-4e3d-8cc8-50373922d01b"], Cell[BoxData[ RowBox[{ SuperscriptBox["r", "2"], "\[LessEqual]", "n", "<", SuperscriptBox[ RowBox[{"(", RowBox[{"r", "+", "1"}], ")"}], "2"]}]], "Input",ExpressionUUID->\ "62eaa9d2-e865-48df-a0f7-2c52bfce9240"], Cell["\<\ Computing this value is achieved without actual computation of squares - the \ model is used to verify that the alternative method produces correct results.\ \ \>", "Text",ExpressionUUID->"d52804aa-e6d1-4cd6-858f-8c01ceb96e06"], Cell[CellGroupData[{ Cell["Initial model", "Subsubsection",ExpressionUUID->"169a017b-7348-419f-aef0-f59ad254d4af"], Cell["\<\ Initial model just states the expectation with regard to the result.\ \>", "Text",ExpressionUUID->"0bc14b16-0c4a-4e1a-8811-c5c395c716a8"], Cell[BoxData[ RowBox[{ RowBox[{"myModel0", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{ RowBox[{"n", "\[Element]", TemplateBox[{}, "Integers"]}], "&&", RowBox[{"n", ">", "0"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"r", "\[Element]", TemplateBox[{}, "Integers"]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"r", "\[Element]", TemplateBox[{}, "Integers"]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ SuperscriptBox["r", "2"], "\[LessEqual]", "n", "<", SuperscriptBox[ RowBox[{"(", RowBox[{"r", "+", "1"}], ")"}], "2"]}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[108]:=",ExpressionUUID->"ea9f4030-aa15-4ecd-b3b1-8678fdbe2f2f"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel0", "]"}]], "Input", CellLabel-> "In[109]:=",ExpressionUUID->"32153ff3-8d7f-4e2d-9170-9a194c60373a"] }, Closed]], Cell[CellGroupData[{ Cell["First refinement", "Subsubsection",ExpressionUUID->"90cc9aee-98d9-4ba3-a809-d06b110918bb"], Cell["\<\ This refinement introduces a loop (event \[OpenCurlyDoubleQuote]progress\ \[CloseCurlyDoubleQuote]) that finds the result upper bound by brute force.\ \>", "Text",ExpressionUUID->"5457109a-bde4-4759-bcef-9da597772590"], Cell[BoxData[ RowBox[{ RowBox[{"myModel1", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel0", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{ SuperscriptBox["r", "2"], "\[LessEqual]", "n"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"r", "\[Rule]", "0"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"n", "-", "r"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"n", "<", SuperscriptBox[ RowBox[{"(", RowBox[{"r", "+", "1"}], ")"}], "2"]}], ",", " ", RowBox[{"(*", " ", RowBox[{"note", ":", " ", RowBox[{ "inv1_", "1", " ", "implicitly", " ", "supports", " ", "guard", " ", "compatibility"}]}], " ", "*)"}], "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{"r", "+", "1"}], ")"}], "2"], "\[LessEqual]", "n"}], ",", "\[IndentingNewLine]", RowBox[{"r", "\[Rule]", RowBox[{"r", "+", "1"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[110]:=",ExpressionUUID->"a82f84d0-b4a7-4a41-ae65-f5a51ee421af"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel1", "]"}]], "Input", CellLabel-> "In[111]:=",ExpressionUUID->"8228ff51-7dfa-4e50-b535-d0ef98e5303b"] }, Closed]], Cell[CellGroupData[{ Cell["Second refinement", "Subsubsection",ExpressionUUID->"f1e30cc8-2421-4dcd-8c71-314f9397dd1c"], Cell["\<\ This refinement avoids presumably expensive multiplication (square of r+1) at \ each step by noticing that:\ \>", "Text",ExpressionUUID->"32b69b81-face-46f1-bdcc-598f519507ee"], Cell[BoxData[ RowBox[{ RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{"r", "+", "1"}], ")"}], "+", "1"}], ")"}], "2"], "\[Equal]", RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{"r", "+", "1"}], ")"}], "2"], "+", RowBox[{"(", RowBox[{ RowBox[{"2", "r"}], "+", "3"}], ")"}]}]}], "\[And]", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"2", RowBox[{"(", RowBox[{"r", "+", "1"}], ")"}]}], "+", "3"}], "\[Equal]", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"2", "r"}], "+", "3"}], ")"}], "+", "2"}]}]}]], "Input",Expressi\ onUUID->"f1249a9c-2ed3-438f-922c-b6fd25eef03b"], Cell[TextData[{ "Two more variables a and b maintain the crucial values ", Cell[BoxData[ FormBox[ SuperscriptBox[ RowBox[{"(", RowBox[{"r", "+", "1"}], ")"}], "2"], TraditionalForm]],ExpressionUUID-> "e1a03d5e-c2e3-446e-8c6c-f15a596168b2"], " and 2r + 3. The model verifies (by means of refinement) that the result is \ correct and fulfills the expectations stated in higher models." }], "Text",ExpressionUUID->"8d51eeae-9b13-44b1-8fa6-bb20827af83f"], Cell[BoxData[ RowBox[{ RowBox[{"myModel2", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "myModel1", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"a", "\[Equal]", SuperscriptBox[ RowBox[{"(", RowBox[{"r", "+", "1"}], ")"}], "2"]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"b", "\[Equal]", RowBox[{ RowBox[{"2", "r"}], "+", "3"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"r", "\[Rule]", "0"}], ",", RowBox[{"a", "\[Rule]", "1"}], ",", RowBox[{"b", "\[Rule]", "3"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"n", "<", "a"}], ",", "\[IndentingNewLine]", "Null"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"a", "\[LessEqual]", "n"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"r", "\[Rule]", RowBox[{"r", "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{"a", "\[Rule]", RowBox[{"a", "+", "b"}]}], ",", "\[IndentingNewLine]", RowBox[{"b", "\[Rule]", RowBox[{"b", "+", "2"}]}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellLabel-> "In[112]:=",ExpressionUUID->"e5785ef9-f0da-42e0-a05b-2f177246e773"], Cell[BoxData[ RowBox[{"validateModel", "[", "myModel2", "]"}]], "Input", CellLabel-> "In[113]:=",ExpressionUUID->"161ea543-8fe7-4619-80de-55c8f5cf97f3"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Model - coffee machine", "Subsection", CellChangeTimes->{{3.971328659217222*^9, 3.971328676515871*^9}},ExpressionUUID->"7b17f6c1-2837-524e-be33-\ 0c6bad21c394"], Cell["\<\ The coffee machine model demonstrates the use of refinements and convergent \ events that add details to the \[OpenCurlyDoubleQuote]big-picture\ \[CloseCurlyDoubleQuote] concept defined in base mode.\ \>", "Text", CellChangeTimes->{{3.9713286971840744`*^9, 3.9713287106317444`*^9}, { 3.971328848165018*^9, 3.9713289744397945`*^9}, {3.9713291037827168`*^9, 3.971329200689457*^9}},ExpressionUUID->"f1b0335c-4577-494a-86e0-\ 608b2d2850c1"], Cell[CellGroupData[{ Cell["Base model", "Subsubsection", CellChangeTimes->{{3.971329203673235*^9, 3.9713292086212807`*^9}},ExpressionUUID->"e23f584d-8800-1446-be10-\ ad038553ab38"], Cell["\<\ The \[OpenCurlyDoubleQuote]big-picture\[CloseCurlyDoubleQuote] view is that \ the coffee machine has a single button that can be pressed or released and \ that button causes the machine to do some work that can be finished and where \ the machine is idle waiting for another request.\ \>", "Text", CellChangeTimes->{{3.9713286971840744`*^9, 3.9713287106317444`*^9}, { 3.971328848165018*^9, 3.9713289744397945`*^9}, {3.9713291037827168`*^9, 3.97132918122159*^9}},ExpressionUUID->"4ea201ff-48f4-4a44-b3d2-\ 19f2750ddfd9"], Cell[BoxData[ RowBox[{ RowBox[{"coffeeMachineBase", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"requestButton", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"inProgress", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"requestButton", "->", "False"}], ",", RowBox[{"inProgress", "->", "False"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"\[Not]", "requestButton"}], ",", "\[IndentingNewLine]", RowBox[{"requestButton", "->", "True"}], ",", "\[IndentingNewLine]", RowBox[{"inProgress", "->", "True"}]}], " ", RowBox[{"(*", " ", RowBox[{ "the", " ", "machine", " ", "is", " ", "doing", " ", "something"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{"requestButton", ",", "\[IndentingNewLine]", RowBox[{"requestButton", "->", "False"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{"inProgress", ",", "\[IndentingNewLine]", RowBox[{"inProgress", "->", "False"}]}], " ", RowBox[{"(*", " ", RowBox[{ "the", " ", "work", " ", "finishes", " ", "at", " ", "some", " ", "point", " ", "in", " ", "time"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"\[Not]", "inProgress"}], ",", "\[IndentingNewLine]", "Null"}], " ", RowBox[{"(*", " ", RowBox[{ "the", " ", "machine", " ", "just", " ", "waits", " ", "for", " ", "other", " ", "requests"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.970288282371237*^9, 3.9702885092127724`*^9}, { 3.970288556378927*^9, 3.970288566949997*^9}, {3.9702887060925446`*^9, 3.970288733707039*^9}, 3.9702959361900597`*^9, {3.97029612829755*^9, 3.9702961339715023`*^9}, {3.9702965017463913`*^9, 3.9702965025967464`*^9}, {3.970633082587902*^9, 3.9706332210242977`*^9}, { 3.9706360755390015`*^9, 3.9706361161646194`*^9}, {3.970636263274393*^9, 3.970636279119295*^9}, {3.9706363745126495`*^9, 3.9706364006205845`*^9}, { 3.970636479385908*^9, 3.9706365014579678`*^9}, {3.9706372587129345`*^9, 3.970637335652317*^9}, {3.97072923484247*^9, 3.970729234999216*^9}, { 3.971329004666113*^9, 3.9713290087579346`*^9}, {3.9713292717848167`*^9, 3.971329313909956*^9}, {3.972117565025669*^9, 3.972117565072708*^9}}, CellLabel-> "In[295]:=",ExpressionUUID->"633820a0-ab5a-d54c-9da2-96419f0eb146"], Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"coffeeMachineBase", ",", RowBox[{"verbose", "->", "Total"}]}], "]"}]], "Input", CellChangeTimes->{{3.9702883080465603`*^9, 3.970288315360504*^9}, 3.970288737356447*^9, {3.9702961525624866`*^9, 3.97029615622801*^9}, { 3.970296200836817*^9, 3.9702962138290462`*^9}}, CellLabel-> "In[296]:=",ExpressionUUID->"bfa89b66-2092-274e-924b-f85daf0b9494"] }, Closed]], Cell[CellGroupData[{ Cell["Detailed model", "Subsubsection", CellChangeTimes->{{3.971329321965412*^9, 3.9713293260102215`*^9}},ExpressionUUID->"de82d39b-cd1b-a140-a23e-\ 709c8ed9d048"], Cell["\<\ The detailed model adds the concept of \[OpenCurlyDoubleQuote]making coffee\ \[CloseCurlyDoubleQuote] and specifies that after some number of coffees (10) \ it will automatically move to the cleaning task. Here, making coffee and cleaning are conceptually sub-states of general \ \[OpenCurlyDoubleQuote]work in progress\[CloseCurlyDoubleQuote] state that \ was defined in base model in terms of inProgress flag - but formally these \ states are defined as new events instead of refinements. This means that they \ should be convergent, to ensure that they do not starve base events. The convergence of new events is demonstrated with the help of variant that \ counts coffees and cleanings together.\ \>", "Text", CellChangeTimes->{{3.971329340139744*^9, 3.9713294234604645`*^9}, { 3.971329466885954*^9, 3.971329511974346*^9}, {3.971335225760071*^9, 3.9713354004696484`*^9}, {3.971335451781172*^9, 3.971335482634798*^9}},ExpressionUUID->"e18d3675-3658-b648-bcea-\ 51f3c609b394"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"boolCount", "[", "b_", "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"b", "==", "True"}], ",", "1", ",", "0"}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"coffeeMachine", "=", RowBox[{"model", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"refines", "[", "coffeeMachineBase", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"coffeeCount", "\[Element]", TemplateBox[{}, "Integers"]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"axiom", "[", RowBox[{"\"\\"", ",", RowBox[{"cleaned", "\[Element]", "Booleans"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"invariant", "[", RowBox[{"\"\\"", ",", RowBox[{"coffeeCount", ">=", "0"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"init", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"coffeeCount", "->", "0"}], ",", RowBox[{"cleaned", "->", "False"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "this", " ", "variant", " ", "limits", " ", "the", " ", "coffee", " ", "making", " ", "and", " ", "cleaning", " ", "activities"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"variant", "[", RowBox[{"\"\\"", ",", RowBox[{"11", "-", "coffeeCount", "-", RowBox[{"boolCount", "[", "cleaned", "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{"new", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"requestButton", "\[And]", RowBox[{"coffeeCount", "<", "10"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{"coffeeCount", "->", RowBox[{"coffeeCount", "+", "1"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{"\"\\"", ",", " ", RowBox[{"(*", " ", RowBox[{"new", " ", "event"}], " ", "*)"}], "\[IndentingNewLine]", "convergent", ",", "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{ RowBox[{"coffeeCount", "==", "10"}], "\[And]", RowBox[{"\[Not]", "cleaned"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"inProgress", "->", "True"}], ",", "\[IndentingNewLine]", RowBox[{"cleaned", "->", "True"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"event", "[", RowBox[{ RowBox[{"\"\\"", "->", "\"\\""}], ",", " ", RowBox[{"(*", " ", "refining", " ", "*)"}], "\[IndentingNewLine]", RowBox[{"when", "[", RowBox[{ RowBox[{"inProgress", "\[And]", "cleaned"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"inProgress", "->", "False"}], ",", "\[IndentingNewLine]", RowBox[{"coffeeCount", "->", "0"}], ",", "\[IndentingNewLine]", RowBox[{"cleaned", "->", "False"}]}], "\[IndentingNewLine]", "}"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"deadlockFree", "[", "]"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}], "Input", CellChangeTimes->{{3.970288727968334*^9, 3.970288767145294*^9}, { 3.970288827963257*^9, 3.9702888880270023`*^9}, {3.970288952429888*^9, 3.9702889876452045`*^9}, {3.97028902882703*^9, 3.9702890939316254`*^9}, { 3.970289132187702*^9, 3.9702891338719063`*^9}, {3.970295544486126*^9, 3.9702955465242023`*^9}, {3.970295707615658*^9, 3.9702957400945187`*^9}, { 3.970295780413433*^9, 3.970295838294588*^9}, {3.970296243777149*^9, 3.9702963436546*^9}, {3.970296427446413*^9, 3.9702964289071884`*^9}, { 3.9702965117282486`*^9, 3.970296535473503*^9}, {3.970296626395567*^9, 3.9702966471748066`*^9}, {3.970299446356964*^9, 3.9702994802354984`*^9}, 3.9702995754972763`*^9, {3.9706364830277596`*^9, 3.970636628592394*^9}, { 3.9706368306559944`*^9, 3.970636845733799*^9}, {3.970636877738796*^9, 3.9706369030344067`*^9}, {3.970636972330845*^9, 3.9706370124329815`*^9}, { 3.9706370670337486`*^9, 3.9706370999536343`*^9}, {3.970637255898159*^9, 3.970637285820078*^9}, {3.970637350857092*^9, 3.970637488974457*^9}, { 3.970637529559967*^9, 3.970637629443165*^9}, {3.970637669186289*^9, 3.9706376761054134`*^9}, {3.970637751236809*^9, 3.9706377848094406`*^9}, { 3.970637826079912*^9, 3.9706379110585785`*^9}, 3.9706380332575684`*^9, { 3.970638361252125*^9, 3.970638383471895*^9}, {3.970638427508938*^9, 3.970638429541258*^9}, {3.970646018074238*^9, 3.970646020191551*^9}, { 3.9706476150767727`*^9, 3.9706476174297123`*^9}, {3.970648148899391*^9, 3.970648200344591*^9}, {3.9706484571298466`*^9, 3.970648494467663*^9}, { 3.970728780070986*^9, 3.9707287963840885`*^9}, 3.9707292454397736`*^9, 3.97132904903034*^9, 3.9713354396128864`*^9, {3.971335494715231*^9, 3.9713355497358665`*^9}, {3.9721176217985287`*^9, 3.972117621955557*^9}}, CellLabel-> "In[297]:=",ExpressionUUID->"555889a0-345c-684b-b078-654976290a46"], Cell[BoxData[ RowBox[{"validateModel", "[", RowBox[{"coffeeMachineMaking", ",", RowBox[{"verbose", "->", "Total"}]}], "]"}]], "Input", CellChangeTimes->{{3.9702887565921955`*^9, 3.970288760160303*^9}, { 3.9702958500118294`*^9, 3.9702958656993866`*^9}, {3.9702963123201847`*^9, 3.970296318214634*^9}, {3.9702963487205505`*^9, 3.970296350815428*^9}, 3.9702966392004433`*^9, 3.9702966893093586`*^9, {3.9702994664730206`*^9, 3.9702994855403767`*^9}, {3.9706370407711735`*^9, 3.970637043045912*^9}, { 3.9706377662990913`*^9, 3.9706377680422115`*^9}, {3.970637918875412*^9, 3.970637921334814*^9}, {3.9706380428396835`*^9, 3.9706380578758354`*^9}, { 3.9706384384682655`*^9, 3.970638446931099*^9}, {3.970638484769169*^9, 3.9706384977753677`*^9}, {3.97063856232955*^9, 3.9706385660314445`*^9}, { 3.9706460275982666`*^9, 3.9706460514637947`*^9}, {3.9706476259310703`*^9, 3.970647639975073*^9}, {3.9706481914015503`*^9, 3.970648194930149*^9}}, CellLabel-> "In[299]:=",ExpressionUUID->"c943d131-07c5-af42-8b42-47f983062804"] }, Closed]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Your code here", "Section", CellChangeTimes->{{3.909222008733883*^9, 3.909222013180233*^9}},ExpressionUUID->"5861d877-bbe8-4b6b-8bf6-\ d46f0e28619e"], Cell["Good luck!", "Text", CellChangeTimes->{{3.9092221466439342`*^9, 3.9092221485167875`*^9}},ExpressionUUID->"bccb800d-a7cd-4fc6-a286-\ d05ffb71ddfe"] }, Open ]] }, WindowSize->{707.25, 639.75}, WindowMargins->{{Automatic, -2466.75}, {Automatic, 3}}, FrontEndVersion->"14.3 for Microsoft Windows (64-bit) (July 8, 2025)", StyleDefinitions->"Default.nb", ExpressionUUID->"fd603278-4804-354f-9b16-884ea604b469" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[576, 22, 113, 0, 66, "Section",ExpressionUUID->"48e737c5-1928-47b4-8664-7a92815820d3"], Cell[692, 24, 303, 8, 33, "Text",ExpressionUUID->"1e3d6943-9081-4c68-af40-f9421d9cf082"], Cell[998, 34, 316, 8, 33, "Text",ExpressionUUID->"f7a311bf-bcb5-49d8-836e-a2e554fe6ab6"], Cell[1317, 44, 350, 6, 77, "Text",ExpressionUUID->"049f7ac9-6712-4e36-977d-a604d6895794"], Cell[1670, 52, 110, 0, 33, "Text",ExpressionUUID->"4fcb9f02-aad4-4d19-aab4-d353015c9e2f"], Cell[CellGroupData[{ Cell[1805, 56, 117, 2, 28, "Input",ExpressionUUID->"9f040ab0-b22b-4d23-9489-b3072a310b6c"], Cell[1925, 60, 216, 4, 32, "Output",ExpressionUUID->"0887015f-e6b0-3c44-b9ab-3bd6bccaf458"] }, {2}]], Cell[2153, 67, 215, 5, 33, "Text",ExpressionUUID->"00b76dfe-9af7-4f91-b113-652697a60046"], Cell[2371, 74, 325, 5, 77, "Text",ExpressionUUID->"991429fe-ba16-406d-94f9-5f4c603403ee"] }, Closed]], Cell[CellGroupData[{ Cell[2733, 84, 87, 0, 52, "Section",ExpressionUUID->"fc5bdc44-316c-4303-9749-9246a7e75626"], Cell[CellGroupData[{ Cell[2845, 88, 101, 0, 53, "Subsection",ExpressionUUID->"35fe5105-53c0-406b-b030-909aeb2fd1d5"], Cell[2949, 90, 303, 6, 55, "Text",ExpressionUUID->"ec07c978-81d4-47d4-8aa5-95eb808aec80"], Cell[3255, 98, 471, 9, 99, "Text",ExpressionUUID->"5e52fe1d-eca1-4776-90f2-a4567cdd1973"], Cell[3729, 109, 362, 5, 77, "Text",ExpressionUUID->"5d7b8895-14c8-43db-b33c-793b5bcd9de5"], Cell[4094, 116, 398, 8, 77, "Text",ExpressionUUID->"4cc3b4cf-b9dd-4e99-b131-e906f57d208b"], Cell[4495, 126, 582, 8, 143, "Text",ExpressionUUID->"dba0a6af-8599-45cc-a76d-2584dd3653c4"] }, Closed]], Cell[CellGroupData[{ Cell[5114, 139, 91, 0, 37, "Subsection",ExpressionUUID->"4befac73-5c29-4bae-892d-70d5adec30e9"], Cell[5208, 141, 418, 6, 99, "Text",ExpressionUUID->"22597b90-eb53-45ea-ae15-3354fe721e07"], Cell[5629, 149, 534, 8, 121, "Text",ExpressionUUID->"4383d9d3-f6ae-4b35-accc-74a4c122c022"], Cell[6166, 159, 520, 7, 121, "Text",ExpressionUUID->"32dfe053-d573-478c-b23a-5ab70f67707a"], Cell[6689, 168, 422, 6, 99, "Text",ExpressionUUID->"ca107bd2-7a5a-46a6-96bc-a424beda6dc8"], Cell[7114, 176, 625, 9, 121, "Text",ExpressionUUID->"8cda5970-09a9-4c68-8673-6890ac9d94cd"], Cell[7742, 187, 402, 6, 77, "Text",ExpressionUUID->"cb6dc8f2-93da-4882-8ea4-7fe555f96e31"], Cell[8147, 195, 341, 5, 77, "Text",ExpressionUUID->"38273fd8-5a01-43e2-b562-220dd0c377ad"] }, Closed]], Cell[CellGroupData[{ Cell[8525, 205, 101, 0, 37, "Subsection",ExpressionUUID->"8cd3b6ad-bda8-4d95-934d-40a0bc8aaece"], Cell[CellGroupData[{ Cell[8651, 209, 90, 0, 43, "Subsubsection",ExpressionUUID->"49f884cf-1c21-408f-9486-5e0cfeaaf82d"], Cell[8744, 211, 465, 11, 66, "Input",ExpressionUUID->"3463075c-7605-440a-bd7b-262e4b0370cd"], Cell[9212, 224, 835, 21, 77, "Text",ExpressionUUID->"6fdb8fca-9807-4614-9ce9-c5b538110ef7"], Cell[10050, 247, 343, 8, 33, "Text",ExpressionUUID->"bd7f75cc-36c9-4758-8914-f20ba43eb7af"], Cell[10396, 257, 1039, 23, 164, "Text",ExpressionUUID->"5179017f-9d04-4aa3-aa2a-6fed1b267595"], Cell[11438, 282, 326, 8, 33, "Text",ExpressionUUID->"25c57995-5f58-4d8a-8e7a-0b43e302bb7f"], Cell[11767, 292, 257, 5, 55, "Text",ExpressionUUID->"6ea69bbe-3a9f-4082-bb62-fcc63a827319"], Cell[12027, 299, 657, 20, 33, "Text",ExpressionUUID->"12224095-bd44-42ba-a33b-d6ab7c071a8a"] }, Closed]], Cell[CellGroupData[{ Cell[12721, 324, 86, 0, 35, "Subsubsection",ExpressionUUID->"03b970cb-42b6-47eb-a9dd-824d893de0c6"], Cell[12810, 326, 515, 12, 66, "Input",ExpressionUUID->"9f2f2f74-d588-4fec-9eb7-cefe4257c040"], Cell[13328, 340, 251, 4, 55, "Text",ExpressionUUID->"8c8579c2-1ad5-4962-a2d5-2531cc0c64f5"], Cell[13582, 346, 420, 17, 33, "Text",ExpressionUUID->"2c435960-58ea-49d6-8727-b6d675914b46"], Cell[14005, 365, 558, 15, 55, "Text",ExpressionUUID->"c59d830d-49d9-4f0b-8fcd-b54fb0e22f62"], Cell[14566, 382, 176, 4, 33, "Text",ExpressionUUID->"3273e9d8-812d-4dd3-bcec-67a66c29c3a4"], Cell[14745, 388, 657, 20, 33, "Text",ExpressionUUID->"15c4d1dd-e2a1-4671-a53d-7ddaf6f29b83"] }, Closed]], Cell[CellGroupData[{ Cell[15439, 413, 89, 0, 35, "Subsubsection",ExpressionUUID->"19df8c7d-4cd5-4594-87e5-d1fedd138176"], Cell[15531, 415, 300, 7, 28, "Input",ExpressionUUID->"5a8c315d-b3e8-444a-a4fa-0499bbec305e"], Cell[15834, 424, 267, 6, 33, "Text",ExpressionUUID->"62d746aa-ac49-4e40-80fa-2084ef38f8b6"], Cell[16104, 432, 441, 13, 33, "Text",ExpressionUUID->"e2a5ca4a-017d-4bd2-87f7-9ebb39ffb74d"], Cell[16548, 447, 299, 8, 33, "Text",ExpressionUUID->"983a7dbb-6242-4f93-80a0-ddba0dd39f4a"], Cell[16850, 457, 506, 16, 55, "Text",ExpressionUUID->"e87a9373-fd30-4f37-bf7e-4af7e411b1bb"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[17405, 479, 97, 0, 37, "Subsection",ExpressionUUID->"9ac8df9b-5aad-4273-a15a-49554907af48"], Cell[CellGroupData[{ Cell[17527, 483, 88, 0, 43, "Subsubsection",ExpressionUUID->"18f3f333-93c3-4a9c-b7c8-f8b2f7219476"], Cell[17618, 485, 453, 11, 47, "Input",ExpressionUUID->"15f4e08c-adc3-4789-a0d5-5f1a1e7c2ddc"], Cell[18074, 498, 755, 20, 77, "Text",ExpressionUUID->"16eae217-3d00-4558-9348-2113c2dc8352"], Cell[18832, 520, 4411, 117, 383, "Text",ExpressionUUID->"22ef0d0a-509f-42f5-a00f-3b466468b41b"], Cell[23246, 639, 190, 4, 33, "Text",ExpressionUUID->"14af27ce-4d54-408b-b55a-4d23cdd8b9eb"], Cell[23439, 645, 1724, 45, 164, "Text",ExpressionUUID->"3adccaa8-02da-45b8-bac0-21e1ffdecc7a"], Cell[25166, 692, 176, 4, 33, "Text",ExpressionUUID->"be5e9870-61c7-4605-82af-65fd9d209e5b"], Cell[25345, 698, 778, 24, 33, "Text",ExpressionUUID->"569d3a10-c2b6-4648-addc-05babef62ec4"] }, Closed]], Cell[CellGroupData[{ Cell[26160, 727, 97, 0, 35, "Subsubsection",ExpressionUUID->"c30e0023-0e7e-496f-b7d1-9481d14088f8"], Cell[26260, 729, 517, 12, 66, "Input",ExpressionUUID->"537bff3f-45b9-4649-a141-54112cd1e641"], Cell[26780, 743, 629, 11, 121, "Text",ExpressionUUID->"db1d1477-7775-41bc-8f01-8eeb728c79c5"], Cell[27412, 756, 372, 5, 99, "Text",ExpressionUUID->"20003995-1eba-46a8-9eb1-824864fa9b75"], Cell[27787, 763, 130, 0, 33, "Text",ExpressionUUID->"95347e60-c69c-40ec-8f15-f34a20113199"], Cell[27920, 765, 194, 4, 33, "Text",ExpressionUUID->"016244fd-eded-4694-98df-dd3ac09d3133"] }, Closed]], Cell[CellGroupData[{ Cell[28151, 774, 87, 0, 35, "Subsubsection",ExpressionUUID->"b0685d02-98f4-4c6c-8a96-261de66b2903"], Cell[28241, 776, 435, 11, 47, "Input",ExpressionUUID->"d2465f80-164c-46d3-894b-4427d75333ac"], Cell[28679, 789, 618, 16, 77, "Text",ExpressionUUID->"d7dd9afa-6c0c-4207-9a02-4958db6a6c46"], Cell[29300, 807, 192, 4, 33, "Text",ExpressionUUID->"7ddad528-0bed-44d2-be71-3b22e8e7375f"], Cell[29495, 813, 120, 0, 33, "Text",ExpressionUUID->"09a4a870-a4a7-4144-9137-2000f05f37b1"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[29664, 819, 103, 0, 37, "Subsection",ExpressionUUID->"1d9f9266-219e-4ec9-99a2-ac1d74e6fa2f"], Cell[CellGroupData[{ Cell[29792, 823, 93, 0, 43, "Subsubsection",ExpressionUUID->"70e7242e-3e6b-497b-bf05-b5dac925bbd1"], Cell[29888, 825, 664, 14, 85, "Input",ExpressionUUID->"16f61d5e-f7f3-4167-b3a4-18b5eed50358"], Cell[30555, 841, 205, 3, 55, "Text",ExpressionUUID->"774f3f9b-9ff8-4342-8e7d-4f23f84f68da"], Cell[30763, 846, 397, 7, 77, "Text",ExpressionUUID->"657fc7c5-9dbd-426b-8417-3d9645d586db"], Cell[31163, 855, 339, 6, 208, "Text",ExpressionUUID->"d6d4ffcb-d5d0-44d0-a64f-00bf9a798b05"], Cell[31505, 863, 202, 4, 33, "Text",ExpressionUUID->"f263156c-f010-472f-ba33-07e64f551783"], Cell[31710, 869, 210, 4, 33, "Text",ExpressionUUID->"7ae5e6f8-bd27-4670-bb95-476dc1fa024e"], Cell[31923, 875, 1238, 20, 296, "Text",ExpressionUUID->"87dd86f3-3ebe-4f74-8765-eca40593c1eb"], Cell[33164, 897, 460, 8, 99, "Text",ExpressionUUID->"b58e2707-0327-4293-bd5b-a33e558875de"], Cell[33627, 907, 273, 5, 55, "Text",ExpressionUUID->"c2f1fdf4-0d39-4e90-b626-05e98ce3621e"], Cell[33903, 914, 1015, 32, 55, "Text",ExpressionUUID->"bc82dcef-d402-4de9-94ad-16039eb4dc51"] }, Closed]], Cell[CellGroupData[{ Cell[34955, 951, 92, 0, 35, "Subsubsection",ExpressionUUID->"97c9bfa7-af97-4efa-b2c9-84b408ea4de3"], Cell[35050, 953, 238, 4, 55, "Text",ExpressionUUID->"4732efae-18c2-4639-8ad5-3756a4a0f193"] }, Closed]], Cell[CellGroupData[{ Cell[35325, 962, 118, 0, 35, "Subsubsection",ExpressionUUID->"17d41d22-2a75-4e33-ae8b-58eac1fdfb15"], Cell[35446, 964, 445, 6, 99, "Text",ExpressionUUID->"d4070909-48a1-4c29-a8c9-cfc77af25f46"], Cell[35894, 972, 173, 4, 33, "Text",ExpressionUUID->"df57e262-46d6-4f46-ba2c-fc6fc856ba62"], Cell[36070, 978, 165, 4, 28, "Input",ExpressionUUID->"9023bd44-baf7-4cc1-a1a4-6c20dc935215"], Cell[36238, 984, 252, 5, 55, "Text",ExpressionUUID->"1e234441-ff8f-4ecd-8497-b82b6145b314"], Cell[36493, 991, 535, 12, 104, "Input",ExpressionUUID->"22f6d11b-186c-4b08-813f-e3e6935f3d2c"], Cell[37031, 1005, 237, 5, 55, "Text",ExpressionUUID->"35d2a99d-72c7-471b-918d-cfc9a3dd009b"], Cell[37271, 1012, 569, 14, 85, "Input",ExpressionUUID->"0320efc7-0356-4f9d-aea1-9bb190c5b5ba"], Cell[37843, 1028, 277, 5, 55, "Text",ExpressionUUID->"168e37bd-5825-43ed-8a15-1374020e3aa1"], Cell[38123, 1035, 599, 14, 104, "Input",ExpressionUUID->"c2fc3a15-fa42-44d7-ab6f-33fa4e162aaa"], Cell[38725, 1051, 217, 5, 33, "Text",ExpressionUUID->"60a67650-0d01-4643-aee8-c431f39c3ace"], Cell[38945, 1058, 671, 16, 104, "Input",ExpressionUUID->"92735e22-1dfe-4644-ae5f-9d5bf02cbaa8"], Cell[39619, 1076, 325, 6, 77, "Text",ExpressionUUID->"c77c25eb-2d99-4136-8d38-7b774ef893d9"], Cell[39947, 1084, 1654, 37, 256, "Input",ExpressionUUID->"8a8152d4-66a2-424c-a165-2071df0fe49e"], Cell[41604, 1123, 216, 5, 33, "Text",ExpressionUUID->"935c6fe0-2af8-4338-94be-ee3ef95b2560"], Cell[41823, 1130, 630, 16, 85, "Input",ExpressionUUID->"71790b16-b2bc-4d90-aef3-b1cae4d83fe0"], Cell[42456, 1148, 166, 4, 33, "Text",ExpressionUUID->"f5f5efbf-bef0-4205-89f4-f78ca0209981"], Cell[42625, 1154, 493, 12, 85, "Input",ExpressionUUID->"a93e8c2c-24c6-447e-ab5a-9b6a8e0b3c07"], Cell[43121, 1168, 163, 4, 33, "Text",ExpressionUUID->"1cbb3c67-bc2b-4525-8706-0c7d2310e51b"], Cell[43287, 1174, 850, 19, 161, "Input",ExpressionUUID->"133b19c2-c0eb-4aad-b3d6-890a117828f7"], Cell[44140, 1195, 850, 22, 121, "Text",ExpressionUUID->"e0d004f9-1196-4b1e-89fb-b23afd85842a"], Cell[44993, 1219, 2110, 48, 313, "Input",ExpressionUUID->"0382534b-bbbd-496b-bdf5-9c652a66eaa7"], Cell[47106, 1269, 236, 5, 55, "Text",ExpressionUUID->"ab3ba26a-ee92-4a84-9078-8a60bd571f5f"], Cell[47345, 1276, 878, 21, 142, "Input",ExpressionUUID->"415f198c-e7af-4519-a0b5-f6178a4adbb3"], Cell[48226, 1299, 249, 5, 55, "Text",ExpressionUUID->"8230cf9a-80a6-42dd-9826-233c0f6b8d92"], Cell[48478, 1306, 833, 19, 180, "Input",ExpressionUUID->"36e33723-deda-4ed5-aed4-724b3149aa1f"], Cell[49314, 1327, 258, 5, 55, "Text",ExpressionUUID->"deee0c5b-0724-4ed4-a152-ffd258b3577e"], Cell[49575, 1334, 1775, 44, 237, "Input",ExpressionUUID->"1425aacc-9a0c-470f-9218-0b07a7499681"], Cell[51353, 1380, 159, 4, 33, "Text",ExpressionUUID->"cb4dfd62-eeae-47ff-987c-769ff5f0b8c4"], Cell[51515, 1386, 843, 19, 161, "Input",ExpressionUUID->"2a1d9101-f353-4b06-a2b1-390eb9d132b9"], Cell[52361, 1407, 172, 4, 33, "Text",ExpressionUUID->"2c63ec20-c4fd-4c8f-8c48-ee7c28dcbb81"], Cell[52536, 1413, 938, 24, 104, "Input",ExpressionUUID->"fc80f5a6-1926-4434-bb91-936ec9a29d88"], Cell[53477, 1439, 144, 4, 33, "Text",ExpressionUUID->"2666b3be-bfaa-468a-8437-5b416c5fe63f"], Cell[53624, 1445, 630, 15, 85, "Input",ExpressionUUID->"552bd01c-4b89-44fb-8d3a-b84c96c17b25"], Cell[54257, 1462, 211, 7, 33, "Text",ExpressionUUID->"fa2c17b5-c382-42e9-b9f6-17257612df7d"], Cell[54471, 1471, 973, 25, 104, "Input",ExpressionUUID->"098c5786-ded7-439f-8df2-8fd96e97262e"], Cell[55447, 1498, 438, 12, 77, "Text",ExpressionUUID->"a38e9407-8406-4be3-8d12-5e151a718405"], Cell[55888, 1512, 546, 13, 85, "Input",ExpressionUUID->"586eb9f9-480a-42e6-9968-3984989f13a6"], Cell[56437, 1527, 115, 0, 33, "Text",ExpressionUUID->"6961ff7f-9810-4529-8f2b-cabcd990f5ae"] }, Closed]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[56613, 1534, 94, 0, 52, "Section",ExpressionUUID->"b03e2ae5-2147-4f39-838e-e30e50646408"], Cell[CellGroupData[{ Cell[56732, 1538, 97, 0, 53, "Subsection",ExpressionUUID->"19d63da2-233d-48e4-ac3d-6a55653d13e3"], Cell[56832, 1540, 258180, 5390, 34540, "Input",ExpressionUUID->"37df5e6c-a9ed-43d2-87a9-fb59215bdc0e", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell[315049, 6935, 91, 0, 37, "Subsection",ExpressionUUID->"8c430146-9b22-4eac-b2b9-c2103c5ad660"], Cell[315143, 6937, 9263, 220, 1490, "Input",ExpressionUUID->"262882c7-ac46-45b7-8a9f-273373359862", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell[324443, 7162, 93, 0, 37, "Subsection",ExpressionUUID->"dea91a47-5b97-4032-b76f-416cd675f4c9"], Cell[324539, 7164, 269, 6, 99, "Text",ExpressionUUID->"8cb87485-7208-4800-8efd-b87216394e8d"], Cell[324811, 7172, 149465, 3034, 21487, "Input",ExpressionUUID->"63df2883-0635-49e0-962b-ee77b801240c", InitializationCell->True] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[474325, 10212, 82, 0, 52, "Section",ExpressionUUID->"e487a85f-a6bd-475d-b5a1-bef200539c8d"], Cell[CellGroupData[{ Cell[474432, 10216, 91, 0, 53, "Subsection",ExpressionUUID->"07e2d479-a86a-4b3a-836c-19001e9d244c"], Cell[CellGroupData[{ Cell[474548, 10220, 500, 15, 28, "Input",ExpressionUUID->"15657f24-b994-4a16-af99-b085cecfddfe"], Cell[CellGroupData[{ Cell[475073, 10239, 485, 13, 22, "Print",ExpressionUUID->"ebf5200b-c440-433c-8b68-d355f1577754"], Cell[475561, 10254, 282, 7, 22, "Print",ExpressionUUID->"4552edcc-18c9-4aef-b1f7-969f2af05338"], Cell[475846, 10263, 276, 7, 22, "Print",ExpressionUUID->"39656bd4-84f3-4f77-bad8-1f6fbfe6a639"], Cell[476125, 10272, 468, 12, 22, "Print",ExpressionUUID->"117d183d-93ba-4c94-baaf-b4f321bdde82"], Cell[476596, 10286, 282, 7, 22, "Print",ExpressionUUID->"53d42212-5441-456c-909f-cc0e381f1177"], Cell[476881, 10295, 276, 7, 22, "Print",ExpressionUUID->"8119b2c2-f085-4223-8207-eb0b50c8529e"] }, Open ]], Cell[477172, 10305, 380, 12, 32, "Output",ExpressionUUID->"d87c7249-5682-41d5-93f6-ba127bfba68e"] }, Open ]], Cell[CellGroupData[{ Cell[477589, 10322, 547, 15, 104, "Input",ExpressionUUID->"4d9c2189-b05a-468a-834c-fb3439a880c5"], Cell[478139, 10339, 260, 8, 32, "Output",ExpressionUUID->"1fd6fad9-7fac-4f72-abef-57612a23f312"] }, Open ]], Cell[CellGroupData[{ Cell[478436, 10352, 854, 23, 104, "Input",ExpressionUUID->"7c9813a6-d43f-4213-b51b-1fad236d94cc"], Cell[479293, 10377, 201, 5, 32, "Output",ExpressionUUID->"48a41df1-e3da-4292-88a2-5acfbff349c7"] }, Open ]], Cell[CellGroupData[{ Cell[479531, 10387, 1017, 28, 104, "Input",ExpressionUUID->"7da1b539-462c-4673-82dc-4f8e85c23dc5"], Cell[480551, 10417, 202, 5, 32, "Output",ExpressionUUID->"4dfde821-52ba-4f5c-99e7-2ed4beee8c35"] }, Open ]], Cell[CellGroupData[{ Cell[480790, 10427, 646, 19, 66, "Input",ExpressionUUID->"05173cf9-4435-4a75-bedc-cce7fbf370b8"], Cell[481439, 10448, 610, 21, 45, "Output",ExpressionUUID->"b332c477-32df-494c-9d5a-a4dd82e6ad4f"] }, Open ]], Cell[CellGroupData[{ Cell[482086, 10474, 177, 4, 28, "Input",ExpressionUUID->"f1018f07-4306-418a-88cc-37696bb59c3a"], Cell[CellGroupData[{ Cell[482288, 10482, 160, 3, 22, "Print",ExpressionUUID->"be7319b4-f06e-4392-8104-34cedd7ad7ee"], Cell[482451, 10487, 416, 15, 22, "Print",ExpressionUUID->"9fa49043-8fbd-4c6e-b445-4a140dd27c63"], Cell[482870, 10504, 272, 7, 22, "Print",ExpressionUUID->"3d44d92d-8603-459d-acb2-9c82099aca4d"], Cell[483145, 10513, 262, 7, 22, "Print",ExpressionUUID->"fa7aa7cd-e865-4ff2-b450-8961f379483c"], Cell[483410, 10522, 416, 15, 22, "Print",ExpressionUUID->"c582ec33-0821-4563-bd5f-40b2fd6bf436"], Cell[483829, 10539, 272, 7, 22, "Print",ExpressionUUID->"577f2da9-8d62-4372-9ff3-a45d075f8752"], Cell[484104, 10548, 262, 7, 22, "Print",ExpressionUUID->"797280b9-071d-4b19-9814-03e424c2bcad"], Cell[484369, 10557, 416, 15, 22, "Print",ExpressionUUID->"c520d309-f52d-453a-bf67-34909ac3ba7c"], Cell[484788, 10574, 272, 7, 22, "Print",ExpressionUUID->"f2a0a3ec-c98d-47c9-8e39-225352907675"], Cell[485063, 10583, 262, 7, 22, "Print",ExpressionUUID->"8f138ce3-5644-43d6-ac73-f588eaa41cb0"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[485374, 10596, 657, 18, 104, "Input",ExpressionUUID->"8c550027-df3b-4553-964a-26bb4bc149b3"], Cell[486034, 10616, 114, 2, 32, "Output",ExpressionUUID->"e6a9133c-35b0-428c-8dc2-c0989bc61087"] }, Open ]], Cell[CellGroupData[{ Cell[486185, 10623, 648, 17, 104, "Input",ExpressionUUID->"a0a6056e-47d7-4791-9017-16adc0c38e19"], Cell[486836, 10642, 123, 2, 32, "Output",ExpressionUUID->"2037f2a6-cfb5-449c-859c-1cd9222772f6"] }, Open ]], Cell[CellGroupData[{ Cell[486996, 10649, 656, 16, 85, "Input",ExpressionUUID->"0e47a2e7-6865-4294-966c-39f19c389535"], Cell[487655, 10667, 114, 2, 32, "Output",ExpressionUUID->"d6a04c4a-377c-4dac-b05c-d23aba286955"] }, Open ]], Cell[CellGroupData[{ Cell[487806, 10674, 630, 16, 85, "Input",ExpressionUUID->"b3b7a9c2-7f65-49f4-89e2-a9f16768f385"], Cell[488439, 10692, 115, 2, 32, "Output",ExpressionUUID->"af3d53ea-951c-4674-b829-80bebfe1cca7"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[488603, 10700, 89, 0, 37, "Subsection",ExpressionUUID->"1df4db60-4e57-4de6-9654-8b5d2758e53a"], Cell[488695, 10702, 105, 0, 33, "Text",ExpressionUUID->"35fb4960-afbb-4fb0-9ee0-94003df06fe9"], Cell[CellGroupData[{ Cell[488825, 10706, 1005, 31, 104, "Input",ExpressionUUID->"4bdbc5c2-d913-4414-bb83-41491f6e753e"], Cell[489833, 10739, 123, 2, 32, "Output",ExpressionUUID->"f89449c5-aace-4b01-ac0e-5a7e3c9e2040"] }, Open ]], Cell[489971, 10744, 145, 2, 33, "Text",ExpressionUUID->"37d1cb66-adf7-4798-99cd-b10f99c77661"], Cell[CellGroupData[{ Cell[490141, 10750, 1010, 32, 85, "Input",ExpressionUUID->"e251d7f5-9c02-4a5c-990b-ccbe2c09bbdf"], Cell[491154, 10784, 114, 2, 32, "Output",ExpressionUUID->"cb6e98cd-9a99-4abe-903b-3dae23e5481d"] }, Open ]], Cell[CellGroupData[{ Cell[491305, 10791, 1025, 32, 85, "Input",ExpressionUUID->"53be9cc5-95e2-412c-a419-29aca8caaeac"], Cell[492333, 10825, 114, 2, 32, "Output",ExpressionUUID->"c2264b9a-05b0-4ba7-8c6b-757a5d3227ca"] }, Open ]], Cell[492462, 10830, 105, 0, 33, "Text",ExpressionUUID->"b2ef4389-20a9-4371-9fd5-c9575a84cf10"], Cell[CellGroupData[{ Cell[492592, 10834, 907, 25, 142, "Input",ExpressionUUID->"e80f9d2f-ab14-4518-bdf1-e776a845a16b"], Cell[493502, 10861, 123, 2, 32, "Output",ExpressionUUID->"0c4b9bc1-7d92-4e24-8c78-d12431ebaeaf"] }, Open ]], Cell[493640, 10866, 122, 0, 33, "Text",ExpressionUUID->"91420703-810f-4008-a492-94dcd22218f3"], Cell[CellGroupData[{ Cell[493787, 10870, 916, 25, 142, "Input",ExpressionUUID->"932a6baf-0470-43cf-893c-77319f82a5dd"], Cell[494706, 10897, 114, 2, 32, "Output",ExpressionUUID->"0c75d592-a923-49b2-9e38-4b63e5563bd8"] }, Open ]], Cell[494835, 10902, 178, 3, 55, "Text",ExpressionUUID->"9c80b8b6-cdfc-47df-9a77-4b41a4c64e5b"], Cell[CellGroupData[{ Cell[495038, 10909, 619, 18, 85, "Input",ExpressionUUID->"beb0359a-29f8-44bd-a2da-3f3186dec1d2"], Cell[495660, 10929, 123, 2, 32, "Output",ExpressionUUID->"fa328d5d-423f-4013-bee6-dcbe7f7e90cb"] }, Open ]], Cell[495798, 10934, 153, 2, 33, "Text",ExpressionUUID->"3f11e9eb-8d7a-4e6e-bb5e-1c32f433cef3"], Cell[CellGroupData[{ Cell[495976, 10940, 644, 18, 85, "Input",ExpressionUUID->"d5082e42-40b3-4c9e-aa3d-ca058a133d45"], Cell[496623, 10960, 110, 1, 32, "Output",ExpressionUUID->"fe5edc19-9512-4395-a6d4-f60d023faba9"] }, Open ]], Cell[496748, 10964, 364, 6, 77, "Text",ExpressionUUID->"a9a61ff4-5073-4966-b0bf-d7104d9c9f2d"], Cell[497115, 10972, 3756, 94, 484, "Input",ExpressionUUID->"14a89d1b-0ae6-431a-8974-b9911e5fd360"] }, Closed]], Cell[CellGroupData[{ Cell[500908, 11071, 101, 0, 37, "Subsection",ExpressionUUID->"cb176461-f0f4-4477-ad48-cc8ab660242c"], Cell[CellGroupData[{ Cell[501034, 11075, 106, 0, 43, "Subsubsection",ExpressionUUID->"e8bddd05-5249-4f2b-9d3d-4ca6a2bfc408"], Cell[501143, 11077, 251, 6, 55, "Text",ExpressionUUID->"ddfb6c37-57c0-4d2a-a55a-cef96f5e7c1a"], Cell[501397, 11085, 160, 7, 136, "CodeText",ExpressionUUID->"9208b080-001f-4af2-b6b6-1d7c9007386a"], Cell[501560, 11094, 205, 3, 33, "Text",ExpressionUUID->"709bc880-58e3-4732-86cb-ea72bd739584"], Cell[501768, 11099, 126, 0, 33, "Text",ExpressionUUID->"3ee4fc54-b721-41e5-aed9-f675a28c8188"], Cell[501897, 11101, 327, 10, 47, "Input",ExpressionUUID->"ad274347-3836-493f-9061-e2a42887033f"], Cell[502227, 11113, 125, 0, 33, "Text",ExpressionUUID->"8b45cf43-83b7-426a-b230-3bed44eaccfc"], Cell[CellGroupData[{ Cell[502377, 11117, 651, 14, 104, "Input",ExpressionUUID->"bcff7911-8ddb-4d72-8070-f2a6617513c5"], Cell[503031, 11133, 123, 2, 32, "Output",ExpressionUUID->"5951e39e-dd60-4f71-9aae-4801314f6261"] }, Open ]], Cell[503169, 11138, 127, 0, 33, "Text",ExpressionUUID->"205012c6-c550-42fa-bd39-c14f88d87c35"], Cell[503299, 11140, 227, 3, 55, "Text",ExpressionUUID->"69baaa27-1893-4e26-aecd-9ec9e09ec991"], Cell[CellGroupData[{ Cell[503551, 11147, 642, 16, 104, "Input",ExpressionUUID->"220aaa22-0cec-416b-95fa-238a26afd1a7"], Cell[504196, 11165, 114, 2, 32, "Output",ExpressionUUID->"7f404702-6e57-4731-b171-b891d7cf9766"] }, Open ]], Cell[504325, 11170, 269, 4, 55, "Text",ExpressionUUID->"938db21d-bd14-474b-b735-dbb3934043ee"] }, Closed]], Cell[CellGroupData[{ Cell[504631, 11179, 102, 0, 35, "Subsubsection",ExpressionUUID->"d99d7658-e0b9-42ac-9a57-a1a506efb733"], Cell[504736, 11181, 382, 6, 99, "Text",ExpressionUUID->"a321b378-10de-4427-bf0d-429bd7c2f814"], Cell[CellGroupData[{ Cell[505143, 11191, 298, 9, 43, "Input",ExpressionUUID->"03e26fa6-a59c-41c1-83cf-9e1c8cba0d71"], Cell[505444, 11202, 114, 2, 32, "Output",ExpressionUUID->"df812860-e895-43df-8766-310c3125db0d"] }, Open ]], Cell[505573, 11207, 147, 2, 33, "Text",ExpressionUUID->"98576154-b20c-43ba-bfc7-c6dc234e112f"], Cell[505723, 11211, 143, 2, 33, "Text",ExpressionUUID->"c667905f-54ca-475c-98b7-86c065567ea4"], Cell[505869, 11215, 339, 20, 394, "CodeText",ExpressionUUID->"7c9d141d-4d01-4a4b-99a8-ee2b5eae1227"], Cell[506211, 11237, 240, 4, 55, "Text",ExpressionUUID->"2dcca28d-cc3f-4322-82de-5a7345187726"], Cell[506454, 11243, 112, 0, 33, "Text",ExpressionUUID->"6e711fa8-bd00-48ec-90d2-0bfea2e12ba9"], Cell[CellGroupData[{ Cell[506591, 11247, 1708, 37, 256, "Input",ExpressionUUID->"20c2d379-bca8-4609-9e39-376fff80dced"], Cell[508302, 11286, 114, 2, 32, "Output",ExpressionUUID->"68b5d63d-e302-4cbd-8348-227b3c2d3b3c"] }, Open ]], Cell[508431, 11291, 113, 0, 33, "Text",ExpressionUUID->"9bd0f988-bc9c-482f-b967-ad9d78c4da1e"], Cell[CellGroupData[{ Cell[508569, 11295, 1759, 39, 291, "Input",ExpressionUUID->"7323eaff-4f97-4ff8-ab7f-20fb774801fb"], Cell[510331, 11336, 114, 2, 32, "Output",ExpressionUUID->"85591b8f-1551-4406-97d9-1f74995f18f0"] }, Open ]], Cell[510460, 11341, 157, 2, 33, "Text",ExpressionUUID->"a6471a07-1323-4c69-9240-8491945a0d03"], Cell[CellGroupData[{ Cell[510642, 11347, 1744, 38, 256, "Input",ExpressionUUID->"c1a8332b-c95b-4daa-bb28-32f7423dcbb0"], Cell[512389, 11387, 114, 2, 32, "Output",ExpressionUUID->"57c0e4e4-26d3-4338-81f4-d585c961be1d"] }, Open ]], Cell[512518, 11392, 344, 5, 77, "Text",ExpressionUUID->"6c628b5e-2357-4208-bf3c-7be52aebb7dd"], Cell[CellGroupData[{ Cell[512887, 11401, 1379, 30, 199, "Input",ExpressionUUID->"c912bd5a-f47d-429c-8f21-32c3a067c786"], Cell[514269, 11433, 114, 2, 32, "Output",ExpressionUUID->"3611f345-6ea6-44fa-82e7-9f9a43677a40"] }, Open ]], Cell[CellGroupData[{ Cell[514420, 11440, 1414, 31, 199, "Input",ExpressionUUID->"2b2bd2eb-3d8d-4035-b36d-c4b279690fc8"], Cell[515837, 11473, 114, 2, 32, "Output",ExpressionUUID->"59afc716-7a7a-44c6-89b3-9af0cb4611cb"] }, Open ]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[516012, 11482, 104, 0, 37, "Subsection",ExpressionUUID->"e3185c71-3c80-43ec-8282-576e403e7ec1"], Cell[516119, 11484, 225, 4, 55, "Text",ExpressionUUID->"5c610100-a5ad-476b-b6c6-2d024c34a127"], Cell[CellGroupData[{ Cell[516369, 11492, 94, 0, 43, "Subsubsection",ExpressionUUID->"e4b28e9a-c4d3-4e96-bcc1-224bfcb00bdf"], Cell[516466, 11494, 152, 2, 33, "Text",ExpressionUUID->"537f7691-096c-4772-9c19-c7e263362af1"], Cell[516621, 11498, 1464, 37, 161, "Input",ExpressionUUID->"4e3002aa-ae6a-4e80-bfac-ef23a3a5c369"], Cell[CellGroupData[{ Cell[518110, 11539, 222, 4, 28, "Input",ExpressionUUID->"ca5dcad7-f3de-4c77-b4ba-6610d9c278bb"], Cell[CellGroupData[{ Cell[518357, 11547, 161, 3, 22, "Print",ExpressionUUID->"c7a76e85-b60b-4596-ba19-304a919b7b77"], Cell[518521, 11552, 170, 3, 22, "Print",ExpressionUUID->"b60a6d8f-d719-4e39-9e47-bc77bfa78cb0"], Cell[518694, 11557, 577, 17, 22, "Print",ExpressionUUID->"3fd80e57-ba76-48ef-998f-6ee1a219a260"], Cell[519274, 11576, 629, 18, 22, "Print",ExpressionUUID->"59e76b65-acb0-486e-bcab-32a5d3fa352e"], Cell[519906, 11596, 148, 3, 22, "Print",ExpressionUUID->"66c9be03-fe77-4f7f-b1b0-f0459b7fee9d"], Cell[520057, 11601, 613, 18, 22, "Print",ExpressionUUID->"c791ba7c-8d52-44b4-9412-51babad39c89"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[520719, 11625, 151, 3, 28, "Input",ExpressionUUID->"1ffbb5fa-6992-4c98-a641-40c6537c7e72"], Cell[CellGroupData[{ Cell[520895, 11632, 161, 3, 22, "Print",ExpressionUUID->"395ea023-bf3e-4233-91f0-77d427334b88"], Cell[521059, 11637, 170, 3, 22, "Print",ExpressionUUID->"f6026619-82e6-42ee-9daf-35dde36dfa30"], Cell[521232, 11642, 577, 17, 22, "Print",ExpressionUUID->"0c045ae7-f153-4a43-816b-c762bbc0a299"], Cell[521812, 11661, 631, 18, 22, "Print",ExpressionUUID->"a4baeb3f-7c0e-456d-8273-1843b35538fd"], Cell[522446, 11681, 148, 3, 22, "Print",ExpressionUUID->"d9889d5b-edfe-46c4-8c05-175eda829e01"], Cell[522597, 11686, 613, 18, 22, "Print",ExpressionUUID->"56d202a1-ea1d-4fcb-b767-4697b750293e"], Cell[523213, 11706, 615, 18, 22, "Print",ExpressionUUID->"a5473c0a-ed18-4194-a574-62dcf8a8edbb"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[523889, 11731, 98, 0, 35, "Subsubsection",ExpressionUUID->"ce17ea8c-c24a-4524-8ceb-ed50e68efa7a"], Cell[523990, 11733, 209, 3, 55, "Text",ExpressionUUID->"2933c507-841d-4b4f-97b1-ed51a07b21ac"], Cell[524202, 11738, 1753, 43, 313, "Input",ExpressionUUID->"f3501a25-c1e5-4d87-bbec-8f1f88f45d9e"], Cell[CellGroupData[{ Cell[525980, 11785, 226, 5, 28, "Input",ExpressionUUID->"60cf9adf-96cf-4502-9152-f7b180734af2"], Cell[CellGroupData[{ Cell[526231, 11794, 161, 3, 22, "Print",ExpressionUUID->"fb98943b-81b9-45c6-9610-17c5015e37bf"], Cell[526395, 11799, 288, 7, 22, "Print",ExpressionUUID->"9d003457-15a3-4179-bdba-550aea228c3c"], Cell[526686, 11808, 575, 17, 22, "Print",ExpressionUUID->"596726ec-5636-4b73-8f9d-84ab41cc0853"], Cell[527264, 11827, 148, 3, 22, "Print",ExpressionUUID->"066ea741-4c58-450e-8964-f464c6a4dc4c"], Cell[527415, 11832, 613, 18, 22, "Print",ExpressionUUID->"5c25e392-df90-4564-bf6c-acb676e61ec6"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[528077, 11856, 225, 5, 28, "Input",ExpressionUUID->"8e2afda7-efcf-45bd-b47a-ec094a99b8c2"], Cell[CellGroupData[{ Cell[528327, 11865, 161, 3, 22, "Print",ExpressionUUID->"57ea5a00-98e6-48ae-8047-1aa7daf5b083"], Cell[528491, 11870, 288, 7, 22, "Print",ExpressionUUID->"58736f9c-47c6-4d3a-9fd2-46270f53cc6f"], Cell[528782, 11879, 577, 17, 22, "Print",ExpressionUUID->"c6163b65-d58f-4bcb-b16e-34f6563deedf"], Cell[529362, 11898, 148, 3, 22, "Print",ExpressionUUID->"2bed497c-2279-43c3-a460-3151616adf4b"], Cell[529513, 11903, 615, 18, 22, "Print",ExpressionUUID->"4e189417-b993-4e95-88a6-b67c94204e68"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[530189, 11928, 102, 0, 35, "Subsubsection",ExpressionUUID->"f608dfde-22bd-4ca8-b113-741225ede866"], Cell[530294, 11930, 182, 3, 33, "Text",ExpressionUUID->"acbf0686-afe9-41a5-96cf-fba50c23ec7d"], Cell[530479, 11935, 1683, 39, 237, "Input",ExpressionUUID->"790efd7c-778b-4d14-aba5-904be5c33dac"], Cell[CellGroupData[{ Cell[532187, 11978, 298, 6, 28, "Input",ExpressionUUID->"0c1a8fb3-65da-4626-8357-97977e566f5f"], Cell[CellGroupData[{ Cell[532510, 11988, 161, 3, 22, "Print",ExpressionUUID->"35deb9ab-a6bb-4f60-965a-77b5dac91647"], Cell[532674, 11993, 288, 7, 22, "Print",ExpressionUUID->"5d78e770-b552-4c25-afed-33acb2109154"], Cell[532965, 12002, 629, 18, 22, "Print",ExpressionUUID->"a16b5674-345f-4b0e-9bb9-040fc90f381e"], Cell[533597, 12022, 148, 3, 22, "Print",ExpressionUUID->"759f0bc2-0174-4ca0-9daf-8b200603b3e9"], Cell[533748, 12027, 613, 18, 22, "Print",ExpressionUUID->"0fb5f512-3859-4399-967a-e304d5ee7aaf"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[534410, 12051, 369, 7, 28, "Input",ExpressionUUID->"67fe0d93-6aa7-40af-8d0e-ee08e1fd611e"], Cell[CellGroupData[{ Cell[534804, 12062, 161, 3, 22, "Print",ExpressionUUID->"33314caa-8f0d-4134-b503-d866aa6dfc60"], Cell[534968, 12067, 288, 7, 22, "Print",ExpressionUUID->"f69aa904-cde5-4e45-a773-676998e8d5b8"], Cell[535259, 12076, 617, 18, 22, "Print",ExpressionUUID->"506a82c9-cfd1-49f1-947a-6f0ddd914c8e"], Cell[535879, 12096, 148, 3, 22, "Print",ExpressionUUID->"7817875c-1c58-4ae5-98e6-75f46696d8fe"], Cell[536030, 12101, 601, 18, 22, "Print",ExpressionUUID->"f70589e6-dc70-46be-af1a-ac9185343d40"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[536692, 12126, 96, 0, 35, "Subsubsection",ExpressionUUID->"41bac25f-9322-4917-b6e4-1028ed01a6cf"], Cell[536791, 12128, 461, 9, 99, "Text",ExpressionUUID->"9a9f874a-231f-4f69-a635-a48f916ac82c"], Cell[537255, 12139, 2674, 63, 503, "Input",ExpressionUUID->"bf70dc8a-02e8-40a4-aa2b-4fd5fb34cd44"], Cell[CellGroupData[{ Cell[539954, 12206, 228, 5, 28, "Input",ExpressionUUID->"e94cab11-835d-4012-91e4-31b4a7057f65"], Cell[CellGroupData[{ Cell[540207, 12215, 161, 3, 22, "Print",ExpressionUUID->"c6d7a57d-172b-492e-bee6-3ea9639749a7"], Cell[540371, 12220, 168, 3, 22, "Print",ExpressionUUID->"2fa32dd1-55e9-41cc-964f-317948a37d0e"], Cell[540542, 12225, 577, 17, 22, "Print",ExpressionUUID->"4e8eefd3-f28e-4156-b75b-963192f7831e"], Cell[541122, 12244, 148, 3, 22, "Print",ExpressionUUID->"820b9d98-b702-4b93-b134-0ac12dca3be7"], Cell[541273, 12249, 613, 18, 22, "Print",ExpressionUUID->"cb099fd7-6cb1-495f-8b6d-df4dff821228"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[541935, 12273, 227, 5, 28, "Input",ExpressionUUID->"c708d7e9-27e6-4880-993f-4f86f9c93dac"], Cell[CellGroupData[{ Cell[542187, 12282, 161, 3, 22, "Print",ExpressionUUID->"4406416d-be1c-406c-8d05-c7ffdcb931ed"], Cell[542351, 12287, 168, 3, 22, "Print",ExpressionUUID->"60493b1f-667e-4968-b15c-5c6d38c2ba52"], Cell[542522, 12292, 565, 17, 22, "Print",ExpressionUUID->"77cb453a-e55f-4816-a27f-ddcc3955f559"], Cell[543090, 12311, 148, 3, 22, "Print",ExpressionUUID->"b541a10f-b503-4e95-a0b9-93ef7a64dc54"], Cell[543241, 12316, 601, 18, 22, "Print",ExpressionUUID->"f3b6da20-bfe1-4ac6-9879-1f06cf64061a"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[543903, 12341, 105, 0, 35, "Subsubsection",ExpressionUUID->"e7e7119f-7183-4fcf-803a-8f276fbaf81e"], Cell[544011, 12343, 285, 4, 77, "Text",ExpressionUUID->"a571d115-ca99-4bba-8b09-12c163ed72d2"], Cell[544299, 12349, 2389, 59, 351, "Input",ExpressionUUID->"1d90028c-248a-461f-8961-8a6d658ff301"], Cell[CellGroupData[{ Cell[546713, 12412, 234, 5, 28, "Input",ExpressionUUID->"d7a8f476-5851-4504-b2a0-4e2e3e07713a"], Cell[CellGroupData[{ Cell[546972, 12421, 165, 3, 22, "Print",ExpressionUUID->"1733a05f-8b5e-417d-a44d-30b829401123"], Cell[547140, 12426, 170, 3, 22, "Print",ExpressionUUID->"61695b9f-db1e-4de8-8585-37d293852b1f"], Cell[547313, 12431, 577, 17, 22, "Print",ExpressionUUID->"80c639b0-07b5-48a4-bcd5-f1f9d0e214c8"], Cell[547893, 12450, 631, 18, 22, "Print",ExpressionUUID->"5b87005b-c508-4963-95a9-d14d0c4d89e6"], Cell[548527, 12470, 148, 3, 22, "Print",ExpressionUUID->"3c4c33b1-df60-4f3e-ab56-9efe5f3a85c3"], Cell[548678, 12475, 613, 18, 22, "Print",ExpressionUUID->"df8bcb28-e6e0-4de9-9591-71a3a93e4dcd"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[549340, 12499, 234, 5, 28, "Input",ExpressionUUID->"7a27433a-5672-4048-9c41-4d018601ca46"], Cell[CellGroupData[{ Cell[549599, 12508, 165, 3, 22, "Print",ExpressionUUID->"8979ad7f-71a3-4de3-9a76-c955a12721e1"], Cell[549767, 12513, 170, 3, 22, "Print",ExpressionUUID->"dfb74c63-ee12-4f01-ae5f-95741883bed8"], Cell[549940, 12518, 577, 17, 22, "Print",ExpressionUUID->"42d24845-3626-4f1a-9c4d-d77f2d229b25"], Cell[550520, 12537, 633, 18, 22, "Print",ExpressionUUID->"920c98da-9a81-4da5-b57a-f71044853b48"], Cell[551156, 12557, 148, 3, 22, "Print",ExpressionUUID->"191877f5-aa30-4b23-b3b5-0eae9a272eee"], Cell[551307, 12562, 613, 18, 22, "Print",ExpressionUUID->"07b6803f-df28-4a19-bfc2-401d21e6ad62"], Cell[551923, 12582, 615, 18, 22, "Print",ExpressionUUID->"24f901b7-9ccc-4a51-9511-91108cafabf9"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[552587, 12606, 234, 5, 28, "Input",ExpressionUUID->"4015d46f-cb0c-44ba-aefb-d693da9cdda4"], Cell[CellGroupData[{ Cell[552846, 12615, 165, 3, 22, "Print",ExpressionUUID->"a2fe01c8-f89f-444c-87b6-32a6ce32d8e9"], Cell[553014, 12620, 170, 3, 22, "Print",ExpressionUUID->"c3e859f0-3945-446f-a733-c6701b9ec960"], Cell[553187, 12625, 579, 17, 22, "Print",ExpressionUUID->"c4f4fba0-1af1-4071-be2f-4de1945ba8c3"], Cell[553769, 12644, 167, 3, 22, "Print",ExpressionUUID->"5851a134-42e4-434c-ac75-038360561ad7"], Cell[553939, 12649, 148, 3, 22, "Print",ExpressionUUID->"abd8824a-762f-44a0-9a35-14938c072691"], Cell[554090, 12654, 615, 18, 22, "Print",ExpressionUUID->"bdf1ca9c-6742-4aa3-b4cf-d1dcacc0ce34"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[554766, 12679, 106, 0, 35, "Subsubsection",ExpressionUUID->"6c9538f5-957f-474f-8d19-02a4b3f35ade"], Cell[554875, 12681, 228, 3, 77, "Text",ExpressionUUID->"39b3e9a5-f520-46ba-9949-b51d08a3e86a"], Cell[555106, 12686, 2378, 56, 484, "Input",ExpressionUUID->"fe1c8b0d-2952-4916-b270-d046fcf54fcb"], Cell[CellGroupData[{ Cell[557509, 12746, 236, 5, 28, "Input",ExpressionUUID->"8a5ddf52-967b-47a7-aac7-5b52aa7fed40"], Cell[CellGroupData[{ Cell[557770, 12755, 165, 3, 22, "Print",ExpressionUUID->"d78e6812-8cf8-41ad-ba19-79d73bea5c62"], Cell[557938, 12760, 288, 7, 22, "Print",ExpressionUUID->"bbdb5c74-2176-4e56-92a6-bb3ac539e4ee"], Cell[558229, 12769, 575, 17, 22, "Print",ExpressionUUID->"cf92463f-5bb9-4c9f-bddf-412a9f6f8800"], Cell[558807, 12788, 169, 3, 22, "Print",ExpressionUUID->"a5ee3be5-0b3d-4cbd-95b2-997556226ca0"], Cell[558979, 12793, 607, 17, 22, "Print",ExpressionUUID->"957dae37-f0c1-4edf-84a6-4f81307db271"], Cell[559589, 12812, 148, 3, 22, "Print",ExpressionUUID->"22cd4d35-50f8-4c34-b456-0b954c4fffed"], Cell[559740, 12817, 613, 18, 22, "Print",ExpressionUUID->"2b110ad0-4c57-4e4d-9d0c-d8d996254970"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[560402, 12841, 235, 5, 28, "Input",ExpressionUUID->"f50acbc6-2447-4dd0-858e-7f286cbe6116"], Cell[CellGroupData[{ Cell[560662, 12850, 165, 3, 22, "Print",ExpressionUUID->"a998d982-217a-43e7-85a7-1ee4b1bb1bea"], Cell[560830, 12855, 288, 7, 22, "Print",ExpressionUUID->"28c82e39-3905-4b3c-a1c7-ce86e34ed437"], Cell[561121, 12864, 577, 17, 22, "Print",ExpressionUUID->"f208917d-fbd6-4722-b09d-b94881390fc5"], Cell[561701, 12883, 169, 3, 22, "Print",ExpressionUUID->"2f9624e8-605b-48af-90fc-a1ac81a86ba9"], Cell[561873, 12888, 607, 17, 22, "Print",ExpressionUUID->"45c3047d-0bb8-451c-b09d-0035d7d424d2"], Cell[562483, 12907, 148, 3, 22, "Print",ExpressionUUID->"0885abf0-1e0c-49a0-85c5-d5857dc522a9"], Cell[562634, 12912, 615, 18, 22, "Print",ExpressionUUID->"8c880c88-4585-43e9-9e26-3df83f78f5c0"], Cell[563252, 12932, 613, 18, 22, "Print",ExpressionUUID->"3e11dcc9-5bbc-43e3-ad8b-ef813a40e66e"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[563926, 12957, 107, 0, 35, "Subsubsection",ExpressionUUID->"31e43d5d-f815-4c8e-a5e6-d1486c425e08"], Cell[564036, 12959, 202, 3, 55, "Text",ExpressionUUID->"90399a13-3b01-4a29-a0c7-7669012d47f7"], Cell[564241, 12964, 1936, 46, 446, "Input",ExpressionUUID->"c0aeb3c8-cf2e-46f3-abe0-b6d45d2310c6"], Cell[CellGroupData[{ Cell[566202, 13014, 236, 5, 28, "Input",ExpressionUUID->"5b01e5c1-8603-4cba-a973-6e7495538560"], Cell[CellGroupData[{ Cell[566463, 13023, 165, 3, 22, "Print",ExpressionUUID->"43d8c48c-3ca5-417d-a91a-bb64313b2a5a"], Cell[566631, 13028, 288, 7, 22, "Print",ExpressionUUID->"3e70ee1c-eb5b-4d52-bfa1-3bd52f29f727"], Cell[566922, 13037, 575, 17, 22, "Print",ExpressionUUID->"c09e9f8f-3739-49c1-af5c-56ccc21e241d"], Cell[567500, 13056, 169, 3, 22, "Print",ExpressionUUID->"cffa81bf-3b15-41f6-b55e-f2c0eb2bdd1b"], Cell[567672, 13061, 607, 17, 22, "Print",ExpressionUUID->"39d78a05-380c-4ea5-a9b0-93c59da8b728"], Cell[568282, 13080, 148, 3, 22, "Print",ExpressionUUID->"b67e3d1e-0aad-498e-a106-206151f82a48"], Cell[568433, 13085, 613, 18, 22, "Print",ExpressionUUID->"5ab1bff2-5298-4359-9131-4f4b2dce7ebd"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[569095, 13109, 235, 5, 28, "Input",ExpressionUUID->"c95b019c-0302-4818-ba59-d6f0ea69d7ba"], Cell[CellGroupData[{ Cell[569355, 13118, 165, 3, 22, "Print",ExpressionUUID->"4b446d7e-6478-49f8-bee0-9356a3b1edb9"], Cell[569523, 13123, 288, 7, 22, "Print",ExpressionUUID->"fab4c39d-41c6-49fc-868d-e0ca9a2347e5"], Cell[569814, 13132, 575, 17, 22, "Print",ExpressionUUID->"e7e3b5b9-9456-4148-97f1-eecdeb4ff478"], Cell[570392, 13151, 169, 3, 22, "Print",ExpressionUUID->"cfb57f27-019c-4619-917e-1d10c9362a92"], Cell[570564, 13156, 595, 17, 22, "Print",ExpressionUUID->"583827fe-18f4-4ae9-8482-58e2b1c05555"], Cell[571162, 13175, 148, 3, 22, "Print",ExpressionUUID->"a503c163-bc06-49da-9549-46033aa307a2"], Cell[571313, 13180, 613, 18, 22, "Print",ExpressionUUID->"464aa877-3cb6-4790-95f0-d1dd1fbed9a7"], Cell[571929, 13200, 601, 18, 22, "Print",ExpressionUUID->"894d7c46-a6dd-435f-a7ae-1b22fc3ea31a"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[572591, 13225, 109, 0, 35, "Subsubsection",ExpressionUUID->"b0c0a588-5c05-4b1b-80b3-70f9192ddf13"], Cell[572703, 13227, 244, 4, 55, "Text",ExpressionUUID->"273d518b-3a66-499c-a960-7c8eb7494236"], Cell[572950, 13233, 1278, 33, 218, "Input",ExpressionUUID->"ccd4d57b-acae-4d40-929a-44c3db9287a6"], Cell[CellGroupData[{ Cell[574253, 13270, 236, 5, 28, "Input",ExpressionUUID->"a15c1a40-662c-4456-a52d-7004d52ea12d"], Cell[CellGroupData[{ Cell[574514, 13279, 165, 3, 22, "Print",ExpressionUUID->"a95bf436-38a8-4519-94eb-8f4d8fbcf47b"], Cell[574682, 13284, 288, 7, 22, "Print",ExpressionUUID->"94e26808-66fe-404a-9f5c-cdb8e3481f64"], Cell[574973, 13293, 169, 3, 22, "Print",ExpressionUUID->"7a8d2e41-9fb7-41ca-acd3-90670431fea8"], Cell[575145, 13298, 607, 17, 22, "Print",ExpressionUUID->"c7755f88-e629-431e-9ebe-ea63cdf4a780"], Cell[575755, 13317, 148, 3, 22, "Print",ExpressionUUID->"a87b84af-b9c4-4513-9a79-26932ac93565"], Cell[575906, 13322, 613, 18, 22, "Print",ExpressionUUID->"c630e224-b130-4563-b7fe-8cbdc56c41f4"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[576568, 13346, 235, 5, 28, "Input",ExpressionUUID->"c96e3c38-0cdb-4184-9bbc-b63fa60e955d"], Cell[CellGroupData[{ Cell[576828, 13355, 165, 3, 22, "Print",ExpressionUUID->"12426133-e0da-4ca4-9c90-64cfb7b45cb9"], Cell[576996, 13360, 288, 7, 22, "Print",ExpressionUUID->"3ec3d4aa-796e-41b6-95f3-22288c35630a"], Cell[577287, 13369, 169, 3, 22, "Print",ExpressionUUID->"b441d1b3-73ab-454f-ae20-b8f1bc092fd5"], Cell[577459, 13374, 595, 17, 22, "Print",ExpressionUUID->"06ea4e7e-5ed7-4e8f-9e33-aa883a4c745f"], Cell[578057, 13393, 148, 3, 22, "Print",ExpressionUUID->"71c37899-3906-4144-8906-6024e9afea4d"], Cell[578208, 13398, 601, 18, 22, "Print",ExpressionUUID->"7bdeadef-a18d-4fab-8ccc-c113ef021ce4"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[578870, 13423, 107, 0, 35, "Subsubsection",ExpressionUUID->"3d2ff949-e9a5-457e-9428-77983f68d963"], Cell[578980, 13425, 281, 4, 77, "Text",ExpressionUUID->"c8197584-dc64-46ba-b96c-ee2d00cf4b38"], Cell[579264, 13431, 2934, 68, 541, "Input",ExpressionUUID->"71bc1ac2-f451-4b27-a6bb-17facf095cd3"], Cell[CellGroupData[{ Cell[582223, 13503, 236, 5, 28, "Input",ExpressionUUID->"89af1eb4-a5af-4daf-a45d-4faa306910e4"], Cell[CellGroupData[{ Cell[582484, 13512, 165, 3, 22, "Print",ExpressionUUID->"6b3091b1-aa5e-4935-97dc-06a0fe6c064d"], Cell[582652, 13517, 290, 7, 22, "Print",ExpressionUUID->"66bf1f20-0021-42e8-aed7-0a22d36f8896"], Cell[582945, 13526, 575, 17, 22, "Print",ExpressionUUID->"f9ebf6bb-ed65-4363-8bd5-a4c6c1266429"], Cell[583523, 13545, 168, 3, 22, "Print",ExpressionUUID->"f3688e67-976c-4b17-a8f7-00b1b67fb794"], Cell[583694, 13550, 607, 17, 22, "Print",ExpressionUUID->"74615dbd-6129-4214-a69c-c11e036a3303"], Cell[584304, 13569, 148, 3, 22, "Print",ExpressionUUID->"51e19a13-86e8-43cd-8be6-2c37ab5e7573"], Cell[584455, 13574, 613, 18, 22, "Print",ExpressionUUID->"c2a59d18-1f88-4d6f-b453-42c70db67b44"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[585117, 13598, 235, 5, 28, "Input",ExpressionUUID->"933bd681-7ec5-4557-99a6-fafb66f3b8b3"], Cell[CellGroupData[{ Cell[585377, 13607, 165, 3, 22, "Print",ExpressionUUID->"7f8c2b45-68d5-429d-93b2-040423af1a28"], Cell[585545, 13612, 290, 7, 22, "Print",ExpressionUUID->"613c9524-bb87-4155-94b5-cb897f7efe16"], Cell[585838, 13621, 575, 17, 22, "Print",ExpressionUUID->"706c50fb-0ff6-43b9-8cbb-94592c05df14"], Cell[586416, 13640, 168, 3, 22, "Print",ExpressionUUID->"521c2170-4c7e-4a9a-969f-0320c2e7d2c4"], Cell[586587, 13645, 595, 17, 22, "Print",ExpressionUUID->"65c640cb-fd20-458a-b3d2-dd535aee5e7d"], Cell[587185, 13664, 148, 3, 22, "Print",ExpressionUUID->"0a01baeb-4b90-40cd-9d24-8d0b289299a0"], Cell[587336, 13669, 613, 18, 22, "Print",ExpressionUUID->"26323ee6-ef4c-42ac-8f0e-7bc5851c9ce2"], Cell[587952, 13689, 601, 18, 22, "Print",ExpressionUUID->"79c8af29-6d82-4978-9ae4-1a14246b17ac"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[588614, 13714, 103, 0, 35, "Subsubsection",ExpressionUUID->"a8b9dcc6-4916-4360-a5ab-a7a6ad3f8014"], Cell[588720, 13716, 285, 4, 77, "Text",ExpressionUUID->"679d7406-4c26-4b2b-be34-79b8e952c373"], Cell[589008, 13722, 3309, 78, 522, "Input",ExpressionUUID->"460b9c74-57df-408e-9e57-71ee7a42a67a"], Cell[CellGroupData[{ Cell[592342, 13804, 240, 5, 28, "Input",ExpressionUUID->"685dc07e-f967-4b1e-8cb2-80dc3490156f"], Cell[CellGroupData[{ Cell[592607, 13813, 165, 3, 22, "Print",ExpressionUUID->"2f88f48e-bcfa-4cf4-802f-770beef274dc"], Cell[592775, 13818, 288, 7, 22, "Print",ExpressionUUID->"dd83a3fa-30e4-4016-a404-3cf84ca2d399"], Cell[593066, 13827, 631, 18, 22, "Print",ExpressionUUID->"24356ccb-1c41-4b0b-97ec-257da86b74d5"], Cell[593700, 13847, 631, 18, 22, "Print",ExpressionUUID->"71127bf1-5c52-4e11-aee7-73e23dc942a8"], Cell[594334, 13867, 631, 18, 22, "Print",ExpressionUUID->"96c4f91d-58f2-413e-a7c2-336292cd43d7"], Cell[594968, 13887, 148, 3, 22, "Print",ExpressionUUID->"88df8b0f-27ac-473a-a048-2a8a0b9775c8"], Cell[595119, 13892, 613, 18, 22, "Print",ExpressionUUID->"602fec27-1485-4bbc-9850-e6cd8bcebcd3"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[595781, 13916, 240, 5, 28, "Input",ExpressionUUID->"e81de24e-c3a1-4021-b55c-3163de906027"], Cell[CellGroupData[{ Cell[596046, 13925, 165, 3, 22, "Print",ExpressionUUID->"d7ea675c-5bff-4160-8442-e784ac0daa61"], Cell[596214, 13930, 288, 7, 22, "Print",ExpressionUUID->"014bc722-4304-491b-aa05-2dedeff24527"], Cell[596505, 13939, 631, 18, 22, "Print",ExpressionUUID->"bb536e75-8687-4620-a820-48108fb2548d"], Cell[597139, 13959, 631, 18, 22, "Print",ExpressionUUID->"61b0a728-e2db-4ef1-8766-370648e09ecb"], Cell[597773, 13979, 619, 18, 22, "Print",ExpressionUUID->"5025128f-1aa0-43da-a163-a714c0d67e9a"], Cell[598395, 13999, 148, 3, 22, "Print",ExpressionUUID->"3ac42fc8-288d-484b-91f4-1ae636982ec4"], Cell[598546, 14004, 613, 18, 22, "Print",ExpressionUUID->"7a9f90ac-4793-4868-885a-9137a3a87d0c"], Cell[599162, 14024, 601, 18, 22, "Print",ExpressionUUID->"9c8b5507-ea05-4a9d-a9fc-90c416672245"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[599812, 14048, 240, 5, 28, "Input",ExpressionUUID->"661f6a34-026f-4472-945c-48b3ec370382"], Cell[CellGroupData[{ Cell[600077, 14057, 165, 3, 22, "Print",ExpressionUUID->"b9e69641-fb48-44b2-86f6-d8a45b5a828d"], Cell[600245, 14062, 288, 7, 22, "Print",ExpressionUUID->"2dc7ec82-f578-4717-a029-fc20b1e9ab1b"], Cell[600536, 14071, 631, 18, 22, "Print",ExpressionUUID->"c36bf53a-b965-4175-a378-a0daa513f703"], Cell[601170, 14091, 619, 18, 22, "Print",ExpressionUUID->"620db8d9-c728-4060-8f92-8595e442fafd"], Cell[601792, 14111, 148, 3, 22, "Print",ExpressionUUID->"0fb0e4d9-596d-49f1-b827-584318996a7f"], Cell[601943, 14116, 613, 18, 22, "Print",ExpressionUUID->"e8a2e1e2-ff4d-44e9-b5db-54ac04f5a105"], Cell[602559, 14136, 601, 18, 22, "Print",ExpressionUUID->"ba2d75b7-b745-4914-b07c-f62e4c71d8ce"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[603221, 14161, 99, 0, 35, "Subsubsection",ExpressionUUID->"cfd24bf3-f40f-435a-9985-7c167df9be86"], Cell[603323, 14163, 241, 4, 77, "Text",ExpressionUUID->"b3e8e07c-6089-4c82-9daf-1eebac743e06"], Cell[603567, 14169, 2092, 46, 503, "Input",ExpressionUUID->"9727de61-18c7-4fb9-8602-4d4558b362f2"], Cell[CellGroupData[{ Cell[605684, 14219, 236, 5, 28, "Input",ExpressionUUID->"96a46f1d-d37f-4574-afc0-8b3a9daaaa64"], Cell[CellGroupData[{ Cell[605945, 14228, 165, 3, 22, "Print",ExpressionUUID->"09168521-a380-4aa4-aa3d-08c1a19baa4e"], Cell[606113, 14233, 288, 7, 22, "Print",ExpressionUUID->"0d3cdecd-e97f-4c05-83c6-564508635ee2"], Cell[606404, 14242, 169, 3, 22, "Print",ExpressionUUID->"16ab25a9-14ca-4bc5-bcd4-783f6de4e24c"], Cell[606576, 14247, 583, 17, 22, "Print",ExpressionUUID->"f77e33b1-049d-4114-b8e9-ca02fc22e5a0"], Cell[607162, 14266, 148, 3, 22, "Print",ExpressionUUID->"cd66f6de-a00a-474a-afef-986d37e1ad42"], Cell[607313, 14271, 613, 18, 22, "Print",ExpressionUUID->"86b8eec2-4e3d-471b-ba17-4004cf218eee"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[607975, 14295, 235, 5, 28, "Input",ExpressionUUID->"39a8a5e7-2606-4cb6-93ea-12a2caf0e325"], Cell[CellGroupData[{ Cell[608235, 14304, 165, 3, 22, "Print",ExpressionUUID->"98fa90e0-6d10-49a8-9cfa-919f72cbfbb0"], Cell[608403, 14309, 288, 7, 22, "Print",ExpressionUUID->"7c59b313-bc41-4dd4-b8c1-6c34ff86ee41"], Cell[608694, 14318, 169, 3, 22, "Print",ExpressionUUID->"dd66754d-8eb0-40be-9ee6-3d37c136d5ea"], Cell[608866, 14323, 585, 17, 22, "Print",ExpressionUUID->"cf2d6960-94bb-4007-98e9-caa3763a4cbc"], Cell[609454, 14342, 148, 3, 22, "Print",ExpressionUUID->"3d863e58-3a76-4a08-b6f5-1977b59fb821"], Cell[609605, 14347, 615, 18, 22, "Print",ExpressionUUID->"a08df440-b455-469d-83fc-e81023ef5706"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[610281, 14372, 117, 0, 35, "Subsubsection",ExpressionUUID->"ff141f26-7c58-4df9-8f23-92dbee95269b"], Cell[610401, 14374, 240, 4, 77, "Text",ExpressionUUID->"f349766d-96ec-41af-91ae-4e38b2fd0968"], Cell[610644, 14380, 1598, 39, 218, "Input",ExpressionUUID->"bcf17464-4d85-4800-8ade-ea23c0c981ab"], Cell[CellGroupData[{ Cell[612267, 14423, 246, 6, 28, "Input",ExpressionUUID->"dd3b3476-6785-4223-a715-2bd5bd46a9e5"], Cell[CellGroupData[{ Cell[612538, 14433, 165, 3, 22, "Print",ExpressionUUID->"5795adfc-ebac-44dc-9db0-5a62886426d4"], Cell[612706, 14438, 288, 7, 22, "Print",ExpressionUUID->"54b7ee33-c5e6-4782-b344-938cb642cbc4"], Cell[612997, 14447, 583, 17, 22, "Print",ExpressionUUID->"d9baf557-f71e-46a1-adcc-06af06a8d6e5"], Cell[613583, 14466, 148, 3, 22, "Print",ExpressionUUID->"50eb465a-76d9-4c4c-94b0-05d756b3eb2a"], Cell[613734, 14471, 613, 18, 22, "Print",ExpressionUUID->"130db781-699e-4d6a-8f24-51877ed716e6"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[614396, 14495, 245, 6, 28, "Input",ExpressionUUID->"09f3053d-4298-48d7-9682-2cb9f39133e2"], Cell[CellGroupData[{ Cell[614666, 14505, 165, 3, 22, "Print",ExpressionUUID->"ebb3867e-adfa-433e-b1eb-92ef2d6cba85"], Cell[614834, 14510, 288, 7, 22, "Print",ExpressionUUID->"0575806d-2952-4a94-a963-4c7e8a686134"], Cell[615125, 14519, 585, 17, 22, "Print",ExpressionUUID->"7b981bd5-52df-4bfc-9a62-b69db8afe133"], Cell[615713, 14538, 148, 3, 22, "Print",ExpressionUUID->"d36d8d13-925f-4c30-a166-915d17e70791"], Cell[615864, 14543, 615, 18, 22, "Print",ExpressionUUID->"d41f0497-0ffd-4647-a716-ccf4b77ff31d"] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[616540, 14568, 97, 0, 35, "Subsubsection",ExpressionUUID->"9f1eb617-e027-4c28-afba-99b1ec0e449a"], Cell[616640, 14570, 385, 6, 99, "Text",ExpressionUUID->"4906f172-01d8-4b39-b0a3-fe561417177f"], Cell[617028, 14578, 4657, 109, 884, "Input",ExpressionUUID->"a2174f78-55e6-4649-913e-be8c800b2450"], Cell[CellGroupData[{ Cell[621710, 14691, 244, 6, 28, "Input",ExpressionUUID->"caaa0c16-719d-4c12-be10-6d077dc225ea"], Cell[CellGroupData[{ Cell[621979, 14701, 165, 3, 22, "Print",ExpressionUUID->"1dc47704-eaac-4040-9966-fc2342396268"], Cell[622147, 14706, 290, 7, 22, "Print",ExpressionUUID->"01360058-00e7-42fd-9cf8-3bd21c4125ae"], Cell[622440, 14715, 575, 17, 22, "Print",ExpressionUUID->"337275cc-007b-4045-b882-2bfebbbe398b"], Cell[623018, 14734, 579, 17, 22, "Print",ExpressionUUID->"6b2d9e39-bc6f-42d0-ba34-b7a629349ae7"], Cell[623600, 14753, 288, 7, 22, "Print",ExpressionUUID->"0b52856b-c783-474a-9ea6-150320a8119c"], Cell[623891, 14762, 148, 3, 22, "Print",ExpressionUUID->"61def6bf-77a3-47a1-bfbe-0e2ac1d04ceb"], Cell[624042, 14767, 613, 18, 22, "Print",ExpressionUUID->"f9aa8d19-4838-4973-8bd2-d325b68da2d9"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[624704, 14791, 242, 6, 28, "Input",ExpressionUUID->"bbd9ef00-2e17-45dc-b369-dbdbe8107200"], Cell[CellGroupData[{ Cell[624971, 14801, 165, 3, 22, "Print",ExpressionUUID->"939630fd-878d-4dc0-89f5-54354943c4c9"], Cell[625139, 14806, 290, 7, 22, "Print",ExpressionUUID->"9fc94b8d-82cb-4992-88c0-ee7c76a1a4ea"], Cell[625432, 14815, 571, 17, 22, "Print",ExpressionUUID->"5a4b588a-eb07-44f6-893f-df353d64869c"], Cell[626006, 14834, 288, 7, 22, "Print",ExpressionUUID->"c0c65e7c-dd21-4013-9274-2af9d5c0c44d"], Cell[626297, 14843, 148, 3, 22, "Print",ExpressionUUID->"9d620783-f390-4fca-b386-436de46093a3"], Cell[626448, 14848, 601, 18, 22, "Print",ExpressionUUID->"78b4e605-5f03-4a94-9bd1-8aa07cd3818b"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[627098, 14872, 244, 6, 28, "Input",ExpressionUUID->"acd10369-7594-49cb-b6eb-985059ec3ff6"], Cell[CellGroupData[{ Cell[627367, 14882, 165, 3, 22, "Print",ExpressionUUID->"b160cb2c-7656-4f27-addd-19c7d6419ac0"], Cell[627535, 14887, 290, 7, 22, "Print",ExpressionUUID->"1e58eac2-377f-4d81-af16-0c5eda01167f"], Cell[627828, 14896, 288, 7, 22, "Print",ExpressionUUID->"dfbbe41b-f170-4ee5-abf5-7b20802d2c7b"], Cell[628119, 14905, 148, 3, 22, "Print",ExpressionUUID->"ff372f19-3b7a-4ce3-8837-524a635710c9"], Cell[628270, 14910, 160, 3, 22, "Print",ExpressionUUID->"3fd5e5cc-454f-467e-a45c-c0a20251ec29"] }, Open ]] }, Open ]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[628503, 14921, 101, 0, 37, "Subsection",ExpressionUUID->"c526e747-686f-42e4-949f-044e0670c6b1"], Cell[628607, 14923, 218, 3, 33, "Text",ExpressionUUID->"6a9f2aec-7eca-4f40-977f-5fe43725630d"], Cell[CellGroupData[{ Cell[628850, 14930, 92, 0, 43, "Subsubsection",ExpressionUUID->"688bd1ef-cdc4-4d77-b495-b3a4225d2e18"], Cell[628945, 14932, 1598, 31, 408, "Input",ExpressionUUID->"b7c90550-6177-455c-9300-3b9d2c274498"] }, Closed]], Cell[CellGroupData[{ Cell[630580, 14968, 95, 0, 35, "Subsubsection",ExpressionUUID->"99155fb1-007b-472a-8ba6-261630a31e43"], Cell[630678, 14970, 2246, 51, 313, "Input",ExpressionUUID->"43f9748c-2271-4178-8247-e5210ec93197"], Cell[632927, 15023, 156, 3, 28, "Input",ExpressionUUID->"0ede6c93-a6b7-4615-8145-950a9f300efa"], Cell[633086, 15028, 179, 3, 55, "Text",ExpressionUUID->"1be967a7-801d-4158-aaf1-578966723c89"] }, Closed]], Cell[CellGroupData[{ Cell[633302, 15036, 99, 0, 35, "Subsubsection",ExpressionUUID->"91c7f39a-a55c-4be2-979f-b38444e60bc2"], Cell[633404, 15038, 2024, 48, 332, "Input",ExpressionUUID->"0439324c-aa23-4176-960b-ac862bb11bbf"], Cell[635431, 15088, 156, 3, 28, "Input",ExpressionUUID->"f3d7a5fd-d5b8-4f3c-9e8a-28ea3cc6f9aa"], Cell[635590, 15093, 491, 9, 55, "Text",ExpressionUUID->"e1f8dfff-6ad3-4181-ba47-202001737d18"] }, Closed]], Cell[CellGroupData[{ Cell[636118, 15107, 113, 0, 35, "Subsubsection",ExpressionUUID->"2508316b-b3b2-4f0f-a282-59a5ee82a668"], Cell[636234, 15109, 1869, 48, 237, "Input",ExpressionUUID->"5f52a638-bde3-4d01-a7d3-f32d0e80b3f2"], Cell[638106, 15159, 128, 1, 28, "Input",ExpressionUUID->"3ef187d4-342a-4f57-acc2-1af7b5a5dafd"] }, Closed]], Cell[CellGroupData[{ Cell[638271, 15165, 115, 0, 35, "Subsubsection",ExpressionUUID->"44def3ed-f0c1-4f12-929b-4c4216382a01"], Cell[638389, 15167, 254, 7, 28, "Input",ExpressionUUID->"eb137cee-c023-46ac-bed8-9029c2fe1f76"], Cell[638646, 15176, 1844, 47, 275, "Input",ExpressionUUID->"8b906477-f8b3-4be4-a6cd-7fcb7383d0a7"], Cell[640493, 15225, 503, 8, 28, "Input",ExpressionUUID->"4ac35a2e-8389-4e1c-a652-b8f1f4faf32e"] }, Closed]], Cell[CellGroupData[{ Cell[641033, 15238, 96, 0, 35, "Subsubsection",ExpressionUUID->"dc228291-157d-4f15-994b-ce6f1d91f2b8"], Cell[641132, 15240, 200, 3, 55, "Text",ExpressionUUID->"f1cb8bd5-dbf3-4207-a5a0-60d9301dbcad"], Cell[641335, 15245, 5741, 145, 503, "Input",ExpressionUUID->"1db9e59a-6837-4211-a775-baffda6ebaf4"], Cell[647079, 15392, 156, 3, 28, "Input",ExpressionUUID->"90d1d80f-d264-4d6d-b7c3-5ac85c421a9c"] }, Closed]], Cell[CellGroupData[{ Cell[647272, 15400, 120, 0, 35, "Subsubsection",ExpressionUUID->"03d659d0-78ff-40bf-87f6-3437f53d8c49"], Cell[647395, 15402, 189, 3, 55, "Text",ExpressionUUID->"e8fd08a4-672c-435b-ab7d-56523d902c64"], Cell[647587, 15407, 6518, 160, 827, "Input",ExpressionUUID->"fc50867d-5147-4a7e-bd16-c2e2823636b6"], Cell[654108, 15569, 156, 3, 28, "Input",ExpressionUUID->"39775b79-5a2a-4d28-90ac-f49b7179274e"], Cell[654267, 15574, 147, 2, 33, "Text",ExpressionUUID->"20c03a26-2d27-41f6-a892-7173864bd0f3"] }, Closed]], Cell[CellGroupData[{ Cell[654451, 15581, 116, 0, 35, "Subsubsection",ExpressionUUID->"0f4b9336-c50d-415e-b6b9-815732bc8688"], Cell[654570, 15583, 7564, 183, 998, "Input",ExpressionUUID->"a2c5cfe6-d084-41a3-a27e-3ab1b572b517"], Cell[662137, 15768, 156, 3, 28, "Input",ExpressionUUID->"e20b287b-b8f1-4b66-8de1-bb64bc5a42a5"], Cell[662296, 15773, 274, 4, 55, "Text",ExpressionUUID->"c696aa0d-ce49-4125-918d-5089405ef988"] }, Closed]], Cell[CellGroupData[{ Cell[662607, 15782, 115, 0, 35, "Subsubsection",ExpressionUUID->"869308bc-3cbd-40f9-9c7c-792fd27528ec"], Cell[662725, 15784, 10709, 257, 1512, "Input",ExpressionUUID->"818f3d99-6ade-4e09-900d-d89399d47f7b"], Cell[673437, 16043, 156, 3, 28, "Input",ExpressionUUID->"f6206825-2ff2-4607-81b2-6675ed6e006e"], Cell[673596, 16048, 251, 4, 55, "Text",ExpressionUUID->"eb1b7da6-ed8c-4833-90a0-60681a97ee9f"] }, Closed]], Cell[CellGroupData[{ Cell[673884, 16057, 122, 0, 35, "Subsubsection",ExpressionUUID->"bf8c7482-1b2e-4d9d-9e09-997bfafffa70"], Cell[674009, 16059, 14178, 327, 2216, "Input",ExpressionUUID->"80bdfe3f-bd9a-4fe3-bbbd-97aed6d75a3f"], Cell[688190, 16388, 156, 3, 28, "Input",ExpressionUUID->"2f2dce00-f022-47bd-a63a-ca8db3bfe71d"] }, Closed]], Cell[CellGroupData[{ Cell[688383, 16396, 116, 0, 35, "Subsubsection",ExpressionUUID->"264d7941-21bf-44f8-86eb-956db30ddb61"], Cell[688502, 16398, 316, 7, 66, "Input",ExpressionUUID->"71e16781-5945-47a2-884f-889a0f90d32d"], Cell[688821, 16407, 33450, 738, 5431, "Input",ExpressionUUID->"0a1e41f8-e78b-42e2-abec-2ce0dc79063a"], Cell[722274, 17147, 1823, 39, 199, "Input",ExpressionUUID->"ed3d08c7-54bb-4478-b178-11f92cdbc6f0"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[724146, 17192, 112, 0, 37, "Subsection",ExpressionUUID->"8de5077c-1e9c-4e26-ae6c-4f41aaecc2b7"], Cell[724261, 17194, 218, 3, 33, "Text",ExpressionUUID->"1105cb25-9451-4b40-9cf2-70df3e1946c2"], Cell[CellGroupData[{ Cell[724504, 17201, 114, 0, 43, "Subsubsection",ExpressionUUID->"e2c6d784-b6eb-4610-b06e-0aa026e106cd"], Cell[724621, 17203, 220, 3, 55, "Text",ExpressionUUID->"63ae0022-9917-4a80-b029-1a0aaa63db1d"], Cell[724844, 17208, 5378, 128, 770, "Input",ExpressionUUID->"47989326-24b5-42a7-8a83-89dd908bf40e"], Cell[730225, 17338, 158, 3, 28, "Input",ExpressionUUID->"e3a9531b-0f27-4fc1-b219-1aa0518eeae0"] }, Closed]], Cell[CellGroupData[{ Cell[730420, 17346, 126, 0, 35, "Subsubsection",ExpressionUUID->"66b5e3bc-6e5f-411e-9e4b-cc577e8b80d0"], Cell[730549, 17348, 167, 3, 33, "Text",ExpressionUUID->"43dc0d5e-25cf-48d5-8c53-e9d4cf797f5c"], Cell[730719, 17353, 3042, 69, 427, "Input",ExpressionUUID->"8ca66f91-c76f-43fe-84e4-13e02511c1f8"], Cell[733764, 17424, 158, 3, 28, "Input",ExpressionUUID->"7d57b9b2-a862-4e60-a677-00e78e7f068c"], Cell[733925, 17429, 287, 4, 77, "Text",ExpressionUUID->"b0b4768f-1c39-4fb4-a96d-b3029fe949cc"] }, Closed]], Cell[CellGroupData[{ Cell[734249, 17438, 116, 0, 35, "Subsubsection",ExpressionUUID->"3cdda322-8524-4e33-88cb-eb80fbf34fed"], Cell[734368, 17440, 1848, 37, 427, "Input",ExpressionUUID->"15fcc515-b283-4d43-b049-4f6bd111363e"] }, Closed]], Cell[CellGroupData[{ Cell[736253, 17482, 133, 0, 35, "Subsubsection",ExpressionUUID->"ab382c5d-789c-4ad2-a681-d31ce0bdf748"], Cell[736389, 17484, 158, 3, 33, "Text",ExpressionUUID->"2b5da748-8f8e-4dcf-8d98-587f5ba2ec1f"], Cell[736550, 17489, 4251, 99, 751, "Input",ExpressionUUID->"fb32c732-0fe1-481f-ac83-8500629d0585"], Cell[740804, 17590, 156, 3, 28, "Input",ExpressionUUID->"4a7c4b8f-c227-4d47-9417-887aa027a00b"] }, Closed]], Cell[CellGroupData[{ Cell[740997, 17598, 152, 2, 35, "Subsubsection",ExpressionUUID->"f3d13488-a114-42ac-ab03-5e9856aab605"], Cell[741152, 17602, 12676, 257, 2482, "Input",ExpressionUUID->"0f436db3-4c8e-4ae4-a4ca-14e36b778268"], Cell[753831, 17861, 156, 3, 28, "Input",ExpressionUUID->"08c37424-9c3a-40bb-9b06-0b54c4136aee"] }, Closed]], Cell[CellGroupData[{ Cell[754024, 17869, 140, 1, 35, "Subsubsection",ExpressionUUID->"bb46dac7-503d-49a9-8617-0883b8e498d0"], Cell[754167, 17872, 14483, 299, 2844, "Input",ExpressionUUID->"61fd9636-0c2e-4529-8965-e64952259434"], Cell[768653, 18173, 156, 3, 28, "Input",ExpressionUUID->"fa3b8872-ca4c-4054-beea-fa97e3f51dbd"] }, Closed]], Cell[CellGroupData[{ Cell[768846, 18181, 149, 2, 35, "Subsubsection",ExpressionUUID->"692de66f-c32b-4fee-86dc-045dd6f814ee"], Cell[768998, 18185, 497, 7, 99, "Text",ExpressionUUID->"eabc76e1-ff39-466d-9580-4113d25fde46"], Cell[769498, 18194, 278, 4, 55, "Text",ExpressionUUID->"de7a3129-1ded-41b6-8616-a16871b896ef"], Cell[769779, 18200, 176, 3, 33, "Text",ExpressionUUID->"7819961b-f148-49e1-a91e-e77459e91c28"], Cell[769958, 18205, 8050, 217, 618, "Input",ExpressionUUID->"3f1d3dcc-50c2-4ca3-a1ca-6af7bfc78f8d"], Cell[778011, 18424, 158, 3, 28, "Input",ExpressionUUID->"cb079c4d-d0d9-49f1-a47d-74216e5d2b74"], Cell[778172, 18429, 6216, 145, 827, "Input",ExpressionUUID->"32c2e8eb-587d-4b76-9c50-439da1b832d8"], Cell[784391, 18576, 158, 3, 28, "Input",ExpressionUUID->"e6541e95-0e5d-465e-b2be-a444148ab23a"] }, Closed]], Cell[CellGroupData[{ Cell[784586, 18584, 137, 1, 35, "Subsubsection",ExpressionUUID->"9bc4d197-f4d4-4500-be8b-cc3bf118a021"], Cell[784726, 18587, 148, 2, 33, "Text",ExpressionUUID->"8fa3d95c-16de-427f-a1f0-afb830e5ee44"], Cell[CellGroupData[{ Cell[784899, 18593, 152, 3, 28, "Input",ExpressionUUID->"a65865e1-88a3-4fa4-ad4e-884648d1ee3e"], Cell[785054, 18598, 168, 3, 32, "Output",ExpressionUUID->"f7cef664-63e3-4499-90fc-727c4da3a4c1"] }, Open ]], Cell[785237, 18604, 4592, 95, 827, "Input",ExpressionUUID->"62b4cf68-8cb9-4222-8a70-247c87cf3910"], Cell[789832, 18701, 156, 3, 28, "Input",ExpressionUUID->"b67ddfd2-8029-4e81-938c-891c63775f95"] }, Closed]], Cell[CellGroupData[{ Cell[790025, 18709, 138, 1, 35, "Subsubsection",ExpressionUUID->"40796ccd-efe1-4503-99f3-8b0967d21990"], Cell[790166, 18712, 4418, 101, 808, "Input",ExpressionUUID->"7354b233-06bf-4ac1-8682-816fe2fd7cb3"], Cell[794587, 18815, 128, 1, 28, "Input",ExpressionUUID->"b975566e-ee49-4acb-81de-9a7ad16b1bd1"] }, Closed]], Cell[CellGroupData[{ Cell[794752, 18821, 134, 0, 35, "Subsubsection",ExpressionUUID->"f7c62710-4451-4bf1-b95a-b7582bbac10c"], Cell[794889, 18823, 144, 2, 33, "Text",ExpressionUUID->"c876ae1f-f397-487c-ac20-9078d9efc762"], Cell[CellGroupData[{ Cell[795058, 18829, 152, 3, 28, "Input",ExpressionUUID->"ce04df1b-e09b-40af-8b65-b06494342fdf"], Cell[795213, 18834, 172, 3, 32, "Output",ExpressionUUID->"954cd670-2985-4d1a-8bc9-a7ec2837e3db"] }, Open ]], Cell[795400, 18840, 127, 0, 33, "Text",ExpressionUUID->"c00908cb-639d-4a3e-ba39-85c307e7093f"], Cell[795530, 18842, 257, 7, 28, "Input",ExpressionUUID->"303fbf6f-2056-46df-af63-7a79264d4b70"], Cell[795790, 18851, 152, 2, 33, "Text",ExpressionUUID->"e06d1b20-4648-412a-a5c6-09fdc9c159c3"], Cell[795945, 18855, 4432, 91, 808, "Input",ExpressionUUID->"0028406f-7b94-4021-9d22-01de61e46862"], Cell[800380, 18948, 209, 4, 28, "Input",ExpressionUUID->"23f4b42d-05bd-43f9-aadb-ec91468ab25f"] }, Closed]], Cell[CellGroupData[{ Cell[800626, 18957, 151, 2, 35, "Subsubsection",ExpressionUUID->"63aca57a-3701-4df1-87aa-ba667a1b93fe"], Cell[CellGroupData[{ Cell[800802, 18963, 152, 3, 28, "Input",ExpressionUUID->"5d9da396-18af-4e8d-9a34-356abbeabd57"], Cell[800957, 18968, 202, 3, 51, "Output",ExpressionUUID->"7f968fec-08ca-4a91-9ea8-7a334d2f3f08"] }, Open ]], Cell[801174, 18974, 417, 6, 77, "Text",ExpressionUUID->"9f3fc4be-01a1-4a6a-bf8e-937a51ac3129"], Cell[801594, 18982, 266, 4, 33, "Text",ExpressionUUID->"f6600f80-b74d-450f-b0b3-8d5ad6276b32"], Cell[801863, 18988, 176, 3, 33, "Text",ExpressionUUID->"6a33adc7-22b9-42b2-b80a-b041b21a8fef"], Cell[802042, 18993, 6179, 142, 979, "Input",ExpressionUUID->"ee5c85f0-fc41-44bb-9d1a-80f95a201095"], Cell[808224, 19137, 158, 3, 28, "Input",ExpressionUUID->"b74a6fdd-61cc-4ef1-b422-111a0b561fdc"] }, Closed]], Cell[CellGroupData[{ Cell[808419, 19145, 140, 1, 35, "Subsubsection",ExpressionUUID->"77fc041e-fb4c-4f87-83d7-d463b839f296"], Cell[808562, 19148, 149, 2, 33, "Text",ExpressionUUID->"e9e373bf-19c1-411d-95f2-7fadd74bec3b"], Cell[808714, 19152, 5804, 119, 1245, "Input",ExpressionUUID->"429ee9c3-fc20-4a14-87f7-5cdae997ca63"], Cell[814521, 19273, 559, 12, 85, "Input",ExpressionUUID->"f327440a-00f4-4b19-b28c-c24ee7ed2a91"], Cell[815083, 19287, 669, 17, 66, "Input",ExpressionUUID->"0ee37682-e3c4-44fd-b1da-ec96bf9e07af"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[815801, 19310, 115, 0, 37, "Subsection",ExpressionUUID->"563624ef-c592-495a-b9fe-fa7380145cf1"], Cell[815919, 19312, 168, 3, 33, "Text",ExpressionUUID->"5466e09e-7549-4a8c-82f0-110232b480b3"], Cell[816090, 19317, 180, 4, 77, "Text",ExpressionUUID->"e3841b17-91c3-45f9-99f3-342b795c5e55"], Cell[816273, 19323, 146, 2, 33, "Text",ExpressionUUID->"1a3e2a2a-ddfa-45ca-b788-61d060d14b46"], Cell[CellGroupData[{ Cell[816444, 19329, 487, 14, 70, "Input",ExpressionUUID->"6be5ae13-3a4d-4f3b-a31a-1e1078451286"], Cell[816934, 19345, 669, 21, 46, "Output",ExpressionUUID->"4a3d773f-bd3d-4606-b88d-d9a086616508"] }, {2}]], Cell[817615, 19369, 4515, 103, 522, "Input",ExpressionUUID->"208c53cc-262f-4094-9f97-3f5f156472d5"], Cell[822133, 19474, 224, 3, 55, "Text",ExpressionUUID->"cba54afc-a22a-4880-b38c-ce007d73cb2c"], Cell[822360, 19479, 203, 3, 55, "Text",ExpressionUUID->"dcb87c02-e98d-46ef-87c6-37f485b54462"], Cell[822566, 19484, 2273, 51, 389, "Input",ExpressionUUID->"6871c2e9-0ec3-4451-9e06-9bbafef7240c"], Cell[824842, 19537, 149, 3, 28, "Input",ExpressionUUID->"6fe77fee-47dd-4d45-ad71-48c98ddfcbec"] }, Closed]], Cell[CellGroupData[{ Cell[825028, 19545, 114, 0, 37, "Subsection",ExpressionUUID->"8a7af492-c322-44b5-9faa-ad3787ac9ee6"], Cell[825145, 19547, 218, 3, 33, "Text",ExpressionUUID->"5ccff6a7-ec82-47c9-8053-e847f397ff13"], Cell[CellGroupData[{ Cell[825388, 19554, 92, 0, 43, "Subsubsection",ExpressionUUID->"1d6f5e20-5460-4d11-890c-779e9c730e8a"], Cell[825483, 19556, 649, 15, 123, "Input",ExpressionUUID->"68a38dac-8a76-4c3e-b4a3-484cc829320a"] }, Closed]], Cell[CellGroupData[{ Cell[826169, 19576, 93, 0, 35, "Subsubsection",ExpressionUUID->"a0aee41f-a7e8-4b32-82de-90f880496337"], Cell[826265, 19578, 545, 9, 99, "Text",ExpressionUUID->"6c65192d-b334-477b-bcb6-853b3a8ca96d"], Cell[826813, 19589, 2816, 68, 503, "Input",ExpressionUUID->"911910ab-a4b4-4bf4-9a25-f864917f2504"], Cell[829632, 19659, 156, 3, 28, "Input",ExpressionUUID->"b0aa1fd6-8650-4958-a0f7-4d3a0356f0ff"] }, Closed]], Cell[CellGroupData[{ Cell[829825, 19667, 96, 0, 35, "Subsubsection",ExpressionUUID->"98b77193-4284-4f61-8c38-2be3d91f813a"], Cell[829924, 19669, 369, 6, 77, "Text",ExpressionUUID->"b767efd0-80b6-4223-a619-a3da035685e8"], Cell[830296, 19677, 4522, 105, 789, "Input",ExpressionUUID->"820c5a4d-cdbd-4595-9858-933e19827f2e"], Cell[834821, 19784, 156, 3, 28, "Input",ExpressionUUID->"1f07e70f-19dd-42a9-ad8a-e5105494fd8a"] }, Closed]], Cell[CellGroupData[{ Cell[835014, 19792, 97, 0, 35, "Subsubsection",ExpressionUUID->"91d408af-c1e4-493a-a3c9-af1fea426570"], Cell[835114, 19794, 336, 5, 77, "Text",ExpressionUUID->"a49a5b62-140b-465b-81bf-03f30b02096e"], Cell[835453, 19801, 2822, 68, 560, "Input",ExpressionUUID->"6ef28272-9441-4421-a4e5-756645c5c1a0"], Cell[838278, 19871, 156, 3, 28, "Input",ExpressionUUID->"e6022c58-0ed9-42ae-9792-83ab2917ecc1"] }, Closed]], Cell[CellGroupData[{ Cell[838471, 19879, 96, 0, 35, "Subsubsection",ExpressionUUID->"40fb2c02-eaa1-48d9-9b9f-882bdc20740d"], Cell[838570, 19881, 195, 3, 55, "Text",ExpressionUUID->"444e7ab2-3b18-44b6-b708-6b831ba85440"], Cell[838768, 19886, 223, 3, 55, "Text",ExpressionUUID->"d3a82566-d856-4862-ad7a-163d53e3e3d4"], Cell[CellGroupData[{ Cell[839016, 19893, 617, 19, 70, "Input",ExpressionUUID->"e31b7c82-f7ce-48e5-aa6f-e845b20edc8b"], Cell[839636, 19914, 795, 25, 46, "Output",ExpressionUUID->"1b26a21c-3040-4e53-96ae-dafcffb39e07"] }, {2}]], Cell[840443, 19942, 5672, 128, 637, "Input",ExpressionUUID->"e6f16111-613d-469d-9bd5-d0a9dc8b9c4a"], Cell[846118, 20072, 365, 5, 77, "Text",ExpressionUUID->"42a919af-8118-49ec-9a55-1097f4b13b22"], Cell[846486, 20079, 5144, 119, 922, "Input",ExpressionUUID->"68082f1d-2073-4faa-9e98-54820f9f8e9e"], Cell[851633, 20200, 156, 3, 28, "Input",ExpressionUUID->"16103f8f-03be-4be5-8f70-f3605c6b91bd"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[851838, 20209, 108, 0, 37, "Subsection",ExpressionUUID->"72c98d55-d0e5-4cf3-8e75-5fe04d3e9731"], Cell[851949, 20211, 315, 5, 77, "Text",ExpressionUUID->"12a27c5d-c77b-4914-a2a8-0890adce16dd"], Cell[CellGroupData[{ Cell[852289, 20220, 93, 0, 43, "Subsubsection",ExpressionUUID->"3f2c7407-9a9f-4490-9025-eb720ca58eea"], Cell[852385, 20222, 199, 3, 55, "Text",ExpressionUUID->"af6f8b81-4ec4-4003-ba01-d69b7c591453"], Cell[852587, 20227, 6887, 165, 1074, "Input",ExpressionUUID->"c09fc0d9-2d75-480e-8c24-39732f95753c"], Cell[859477, 20394, 156, 3, 28, "Input",ExpressionUUID->"abb09a58-9d0e-43d3-a9ab-6af2eb08653a"] }, Closed]], Cell[CellGroupData[{ Cell[859670, 20402, 123, 0, 35, "Subsubsection",ExpressionUUID->"c10d1ded-cd0b-4a5a-8063-2fff453f2149"], Cell[859796, 20404, 231, 3, 55, "Text",ExpressionUUID->"0a763dd5-d27d-471e-ad9e-b8af079abb7e"], Cell[860030, 20409, 2248, 54, 370, "Input",ExpressionUUID->"3c5994c2-9313-45bc-9739-60e7429d49ea"], Cell[862281, 20465, 156, 3, 28, "Input",ExpressionUUID->"6379b1ef-4dff-4770-b2ef-9c1ba95e216e"] }, Closed]], Cell[CellGroupData[{ Cell[862474, 20473, 121, 0, 35, "Subsubsection",ExpressionUUID->"5e65f049-e55e-448f-89c4-94efb338e3c5"], Cell[862598, 20475, 288, 4, 77, "Text",ExpressionUUID->"1e091f0a-6ed0-4a58-a197-3a655d5f1812"], Cell[862889, 20481, 7104, 162, 1169, "Input",ExpressionUUID->"724f6b62-46c2-4a27-8ae1-4a66c009125e"], Cell[869996, 20645, 156, 3, 28, "Input",ExpressionUUID->"3fd3a2da-5e8b-44de-bda1-282ca872dd87"] }, Closed]], Cell[CellGroupData[{ Cell[870189, 20653, 93, 0, 35, "Subsubsection",ExpressionUUID->"73b3a0a1-9575-4da5-9aa4-c1a275f8086d"], Cell[870285, 20655, 266, 4, 55, "Text",ExpressionUUID->"d6912cb2-812b-491b-baf1-0783a32db1d7"], Cell[870554, 20661, 3916, 90, 656, "Input",ExpressionUUID->"6b0f4c34-d712-4c56-8b58-8b547b6c5cfe"], Cell[874473, 20753, 156, 3, 28, "Input",ExpressionUUID->"ae5315d6-5aa4-47b6-acc3-f6b900d3cb57"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[874678, 20762, 109, 0, 37, "Subsection",ExpressionUUID->"812f1fd6-1ccf-4938-a3a3-9456439997b1"], Cell[874790, 20764, 335, 5, 99, "Text",ExpressionUUID->"3f7962fc-9cfe-4015-a9f8-f70e2a707537"], Cell[CellGroupData[{ Cell[875150, 20773, 92, 0, 43, "Subsubsection",ExpressionUUID->"f2cca57a-aab2-486d-b912-a8a342953fad"], Cell[875245, 20775, 1360, 24, 389, "Input",ExpressionUUID->"f3ded21b-d3a8-4905-a3c5-997f31448817"] }, Closed]], Cell[CellGroupData[{ Cell[876642, 20804, 93, 0, 35, "Subsubsection",ExpressionUUID->"f85126a4-d7d8-411d-903a-fdce01a243bd"], Cell[876738, 20806, 17032, 394, 2311, "Input",ExpressionUUID->"8e05c522-5791-4a5e-8fbd-5f4efc93784e"], Cell[893773, 21202, 152, 2, 28, "Input",ExpressionUUID->"51821de8-7e6f-4ccc-b8bb-5e7f0c191ebd"] }, Closed]], Cell[CellGroupData[{ Cell[893962, 21209, 96, 0, 35, "Subsubsection",ExpressionUUID->"61be26dd-873e-4ac0-8571-ac867fd73121"], Cell[894061, 21211, 349, 5, 77, "Text",ExpressionUUID->"5c3a1c23-9153-4879-a210-51129451700f"], Cell[894413, 21218, 13001, 282, 2026, "Input",ExpressionUUID->"6f90e019-99fd-4c93-9d05-622d24b19fcc"], Cell[907417, 21502, 152, 2, 28, "Input",ExpressionUUID->"fb4d9506-ee98-4b64-8c49-98ababe5137f"] }, Closed]], Cell[CellGroupData[{ Cell[907606, 21509, 97, 0, 35, "Subsubsection",ExpressionUUID->"655e4168-701c-418a-8056-d1e3e9fb4a73"], Cell[907706, 21511, 369, 6, 55, "Text",ExpressionUUID->"705091c1-d1ef-4985-9827-0ec6f16f6580"], Cell[908078, 21519, 13220, 300, 1949, "Input",ExpressionUUID->"b3a23a2d-88ce-4b85-b6a4-5415fae25c5e"], Cell[921301, 21821, 156, 3, 28, "Input",ExpressionUUID->"0738d3c7-cc75-4614-a8e3-c45518fb3c15"] }, Closed]], Cell[CellGroupData[{ Cell[921494, 21829, 96, 0, 35, "Subsubsection",ExpressionUUID->"541c03a2-884f-4b30-8fa8-485492541ca3"], Cell[921593, 21831, 291, 4, 77, "Text",ExpressionUUID->"7628fc4f-5b87-4c30-b051-c68d846d422a"], Cell[921887, 21837, 3039, 64, 694, "Input",ExpressionUUID->"38a566a3-21c6-4ee2-a0ef-71897b08b594"], Cell[924929, 21903, 156, 3, 28, "Input",ExpressionUUID->"a0f5cd5e-8199-468f-b3fe-b32a780c47c6"] }, Closed]], Cell[CellGroupData[{ Cell[925122, 21911, 96, 0, 35, "Subsubsection",ExpressionUUID->"d492dc51-4657-494a-8f83-c93491aae68d"], Cell[925221, 21913, 300, 5, 55, "Text",ExpressionUUID->"2b6c7dec-1121-446f-87d5-bc9be6896cbd"], Cell[925524, 21920, 3057, 71, 389, "Input",ExpressionUUID->"9e2b9b53-0762-4c2d-ab06-afd8485fe474"], Cell[928584, 21993, 479, 12, 47, "Input",ExpressionUUID->"0f7bee00-3d86-4830-b497-b598aa040956"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[929112, 22011, 113, 0, 37, "Subsection",ExpressionUUID->"d1d3fe04-bab6-47bc-b597-f2325079c0ed"], Cell[929228, 22013, 205, 3, 55, "Text",ExpressionUUID->"107d54e3-65a5-4880-bde6-e6ced0864a90"], Cell[929436, 22018, 267, 4, 55, "Text",ExpressionUUID->"6c3b4c26-cbfe-4a59-bb29-dd2fbf3b7d47"], Cell[CellGroupData[{ Cell[929728, 22026, 93, 0, 43, "Subsubsection",ExpressionUUID->"39e187d5-1dee-4426-a06f-0370a9afa0b2"], Cell[929824, 22028, 2949, 69, 446, "Input",ExpressionUUID->"43509910-87c1-4c38-8b85-6d9a2948e943"], Cell[932776, 22099, 219, 5, 28, "Input",ExpressionUUID->"79db81ae-b009-4340-b746-e1f0ddf012ae"] }, Closed]], Cell[CellGroupData[{ Cell[933032, 22109, 96, 0, 35, "Subsubsection",ExpressionUUID->"50b12d43-07a7-49b5-9add-7ae40fb60100"], Cell[933131, 22111, 238, 4, 55, "Text",ExpressionUUID->"ae64c10d-6dc3-439d-929f-7a72263bb514"], Cell[933372, 22117, 1247, 28, 199, "Input",ExpressionUUID->"655de7ce-d07f-4890-aba1-785562178e0b"], Cell[934622, 22147, 156, 3, 28, "Input",ExpressionUUID->"29668ad4-f3a8-4cbc-805d-eadd1b8fbc00"] }, Closed]], Cell[CellGroupData[{ Cell[934815, 22155, 93, 0, 35, "Subsubsection",ExpressionUUID->"25074e76-088e-420b-8930-c71e997f2642"], Cell[934911, 22157, 193, 3, 55, "Text",ExpressionUUID->"3546e041-0a78-451f-9882-a95da5ed21fd"], Cell[935107, 22162, 1650, 38, 256, "Input",ExpressionUUID->"4c3d5464-8eba-4cbb-ab02-d64ce7c58086"], Cell[936760, 22202, 156, 3, 28, "Input",ExpressionUUID->"cc69f105-6cdb-4ff5-9645-7cab4769ec39"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[936965, 22211, 119, 0, 37, "Subsection",ExpressionUUID->"db449e30-3a15-4651-836b-4374053658aa"], Cell[937087, 22213, 366, 6, 99, "Text",ExpressionUUID->"4d96b3b7-b558-418e-9f75-cfd7293eb903"], Cell[937456, 22221, 321, 9, 47, "Input",ExpressionUUID->"45f37892-00c5-4ca1-9424-b113a1b2bd32"], Cell[937780, 22232, 336, 6, 77, "Text",ExpressionUUID->"fdc64ac0-fcdb-4291-828c-15067eacdcf5"], Cell[938119, 22240, 112, 1, 28, "Input",ExpressionUUID->"7b4b1653-8805-4416-b2d2-057ea1ce4f0c"], Cell[938234, 22243, 243, 4, 55, "Text",ExpressionUUID->"e7a0a2c6-7b24-41a5-a3d9-a34d041acef6"], Cell[938480, 22249, 215, 3, 33, "Text",ExpressionUUID->"33a8086d-26a7-4136-8a55-f187d32c7b4d"], Cell[CellGroupData[{ Cell[938720, 22256, 95, 0, 43, "Subsubsection",ExpressionUUID->"4f91ea36-78ea-496f-a939-3b9e353f11f5"], Cell[938818, 22258, 341, 5, 55, "Text",ExpressionUUID->"23ec6047-18c8-4ed8-a45c-fe2d2becc5d9"], Cell[939162, 22265, 1902, 43, 332, "Input",ExpressionUUID->"bd2bd181-ec0c-4aff-a48b-27cefa5680af"], Cell[941067, 22310, 683, 16, 85, "Input",ExpressionUUID->"1fd06fa0-672b-458d-a48d-2d3362275e85"] }, Closed]], Cell[CellGroupData[{ Cell[941787, 22331, 90, 0, 35, "Subsubsection",ExpressionUUID->"c8060933-912c-4822-b3f3-b7993efe1d7f"], Cell[941880, 22333, 283, 4, 55, "Text",ExpressionUUID->"b4eb18de-d5fc-4690-bf86-df75628fe412"], Cell[942166, 22339, 3419, 78, 637, "Input",ExpressionUUID->"f6fbd9cf-6a2a-485d-ab45-b9b5f20238b1"], Cell[945588, 22419, 157, 3, 28, "Input",ExpressionUUID->"1b1dec94-88d0-4b86-9cd2-61afee660317"] }, Closed]], Cell[CellGroupData[{ Cell[945782, 22427, 128, 0, 35, "Subsubsection",ExpressionUUID->"001f6132-3b85-4422-886f-f159b1689a4a"], Cell[945913, 22429, 697, 11, 143, "Text",ExpressionUUID->"967b7f52-7f88-41ba-beaa-4cad2e775e73"], Cell[946613, 22442, 179, 2, 33, "Text",ExpressionUUID->"6e8d7e08-2576-4b6e-b13c-69ae8a140283"], Cell[946795, 22446, 74, 0, 33, "Text",ExpressionUUID->"46a91303-e108-4c40-b1b4-e68c9a0a2f6a"], Cell[946872, 22448, 520, 18, 28, "Input",ExpressionUUID->"4276e9c0-b43e-467b-a7da-36f550875e5e"], Cell[947395, 22468, 76, 0, 33, "Text",ExpressionUUID->"133f0752-6d5a-4595-9bdd-a69feecd647a"], Cell[947474, 22470, 176, 4, 28, "Input",ExpressionUUID->"fc890e08-2ca3-4444-baf6-82f2fbdad0bd"], Cell[947653, 22476, 159, 3, 33, "Text",ExpressionUUID->"da50d09d-9624-406d-b136-3dc5a84999b5"], Cell[947815, 22481, 74, 0, 33, "Text",ExpressionUUID->"fae7e6c8-e774-4afe-b157-4fbb65aeaacf"], Cell[947892, 22483, 520, 18, 28, "Input",ExpressionUUID->"e9776f6a-a151-472a-831a-b91ca08e2f2a"], Cell[948415, 22503, 76, 0, 33, "Text",ExpressionUUID->"576bd27f-477e-4369-b214-d62c9cf1d827"], Cell[948494, 22505, 203, 5, 28, "Input",ExpressionUUID->"c8954b35-0c39-4323-b346-f1ae4decf986"], Cell[948700, 22512, 248, 4, 55, "Text",ExpressionUUID->"321db477-9051-4cd8-9b69-655358aaa74b"], Cell[948951, 22518, 5695, 121, 751, "Input",ExpressionUUID->"b523f71b-57eb-4fce-a881-29429703e13b"], Cell[954649, 22641, 157, 3, 28, "Input",ExpressionUUID->"5b8b82f2-d26c-44c1-b0ee-10a3b0e19ba2"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[954855, 22650, 137, 1, 37, "Subsection",ExpressionUUID->"80bac012-f39f-4759-b1ed-f59b85255241"], Cell[954995, 22653, 324, 5, 99, "Text",ExpressionUUID->"65965991-7edf-4104-af2c-659b6be13a9e"], Cell[CellGroupData[{ Cell[955344, 22662, 95, 0, 43, "Subsubsection",ExpressionUUID->"d8e97376-3c4a-4f57-adcc-b7d2e472ace4"], Cell[955442, 22664, 204, 3, 55, "Text",ExpressionUUID->"8c9c3f0c-f508-4685-a0f8-3518fe52b108"], Cell[955649, 22669, 1898, 42, 332, "Input",ExpressionUUID->"e8c07a06-ddcd-4d62-b2f9-150cb45d5f2c"], Cell[957550, 22713, 716, 16, 85, "Input",ExpressionUUID->"21d9fe5f-54cc-46a8-adf3-bdad93ec3dbf"] }, Closed]], Cell[CellGroupData[{ Cell[958303, 22734, 96, 0, 35, "Subsubsection",ExpressionUUID->"972f3d72-b134-4f19-b042-0131ec38bc51"], Cell[958402, 22736, 639, 9, 143, "Text",ExpressionUUID->"a0f2b17d-1e86-4dd6-9f97-fe3dbc704c08"], Cell[959044, 22747, 483, 7, 77, "Text",ExpressionUUID->"ccb28ec1-f6b7-411f-b10b-16d3c7a2b6ca"], Cell[959530, 22756, 7988, 181, 1207, "Input",ExpressionUUID->"c4bab121-f2c1-4eda-ba87-b0f3467c5aae"], Cell[967521, 22939, 156, 3, 28, "Input",ExpressionUUID->"a6a5e309-87d9-4fe1-8ba3-b7ff4bee0738"] }, Closed]], Cell[CellGroupData[{ Cell[967714, 22947, 97, 0, 35, "Subsubsection",ExpressionUUID->"2a6b7759-5648-44ba-bdbd-7eab7536f2e9"], Cell[967814, 22949, 242, 4, 55, "Text",ExpressionUUID->"d3df5906-1d21-42df-8c22-efab3ac7f80d"], Cell[968059, 22955, 6005, 142, 975, "Input",ExpressionUUID->"fb02cd6d-c0b0-4ccf-af38-7a8bfe9f7f73"], Cell[974067, 23099, 152, 2, 28, "Input",ExpressionUUID->"1a32ebd5-f6bc-410b-931c-3baacf23a0ec"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[974268, 23107, 152, 2, 37, "Subsection",ExpressionUUID->"85496e65-e53c-4299-8d3a-d8c1eeee23b1"], Cell[974423, 23111, 246, 4, 77, "Text",ExpressionUUID->"9aa0bc05-7923-4e88-a78b-9938861326e0"], Cell[CellGroupData[{ Cell[974694, 23119, 93, 0, 43, "Subsubsection",ExpressionUUID->"96bf2f07-f185-4e56-b001-0bd9fef6cad1"], Cell[974790, 23121, 240, 4, 55, "Text",ExpressionUUID->"0b006c9b-5a5d-4d81-9a9d-38ea084dff74"], Cell[975033, 23127, 896, 22, 85, "Input",ExpressionUUID->"01854bd6-7e93-4271-b413-032fc75df3a1"], Cell[975932, 23151, 152, 2, 28, "Input",ExpressionUUID->"0927f1b8-57db-4e65-a73a-81a966146336"] }, Closed]], Cell[CellGroupData[{ Cell[976121, 23158, 96, 0, 35, "Subsubsection",ExpressionUUID->"e49956c7-40fa-420a-b4f9-32417bb54721"], Cell[976220, 23160, 627, 9, 121, "Text",ExpressionUUID->"86be1d28-f70a-44eb-8161-9ecaaeddff99"], Cell[976850, 23171, 4826, 117, 789, "Input",ExpressionUUID->"cee61e21-95a6-495f-ac0a-1483c9527c16"], Cell[981679, 23290, 152, 2, 28, "Input",ExpressionUUID->"a9a1dd2e-67ec-4f94-9d09-26a392553130"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[981880, 23298, 155, 2, 37, "Subsection",ExpressionUUID->"b958e583-43ad-4e23-9afe-fc52593359cc"], Cell[982038, 23302, 510, 7, 121, "Text",ExpressionUUID->"d24f5ffb-9333-4cb7-84ff-e613cf6c92ce"], Cell[982551, 23311, 283, 7, 33, "Text",ExpressionUUID->"32402770-f928-48ad-b5ae-5bf9e33426bf"], Cell[982837, 23320, 3322, 79, 484, "Input",ExpressionUUID->"77026a82-6801-434c-a3d1-32d17d59d68f"], Cell[986162, 23401, 151, 2, 28, "Input",ExpressionUUID->"e1dfd714-8e96-4f0b-baeb-ef539d171e6b"] }, Closed]], Cell[CellGroupData[{ Cell[986350, 23408, 124, 0, 37, "Subsection",ExpressionUUID->"f38c7f5e-7ab9-4742-b0ca-edea15c0ca40"], Cell[986477, 23410, 420, 6, 121, "Text",ExpressionUUID->"40024dfe-8662-45c8-8634-e90fde112f79"], Cell[986900, 23418, 223, 3, 55, "Text",ExpressionUUID->"bd278449-91ca-4389-ab81-55c0aeef8b3a"], Cell[CellGroupData[{ Cell[987148, 23425, 93, 0, 43, "Subsubsection",ExpressionUUID->"c3218f46-1f72-4847-8966-a71d5f2b1ef2"], Cell[987244, 23427, 2651, 67, 370, "Input",ExpressionUUID->"7d6f9a1e-00b1-4dde-897a-cc1df5530575"], Cell[989898, 23496, 152, 2, 28, "Input",ExpressionUUID->"7dd8708a-7a7b-4d67-bed9-d41562e9832a"] }, Closed]], Cell[CellGroupData[{ Cell[990087, 23503, 96, 0, 35, "Subsubsection",ExpressionUUID->"b289c5a7-d32f-4ff9-9acb-dd3407191f48"], Cell[990186, 23505, 722, 12, 186, "Text",ExpressionUUID->"84c758b6-7723-47e1-af12-2576bba8eee2"], Cell[990911, 23519, 6090, 142, 903, "Input",ExpressionUUID->"c7dddc32-7a00-421d-b14c-1ed40cf0a35c"], Cell[997004, 23663, 152, 2, 28, "Input",ExpressionUUID->"b3692ccf-f4f2-436a-9ba5-62c37b606972"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[997205, 23671, 120, 0, 37, "Subsection",ExpressionUUID->"be4a7148-8f4c-46ad-8000-e2fb8c0c8ae2"], Cell[997328, 23673, 268, 4, 77, "Text",ExpressionUUID->"61c5e85d-6b53-49ae-a60f-c6d15a264141"], Cell[CellGroupData[{ Cell[997621, 23681, 93, 0, 43, "Subsubsection",ExpressionUUID->"24410418-54c8-4941-bf1b-94a89c65fec3"], Cell[997717, 23683, 215, 3, 55, "Text",ExpressionUUID->"3056e246-7509-434a-b840-c0b449bcaacf"], Cell[997935, 23688, 1228, 31, 180, "Input",ExpressionUUID->"28e488c1-e9ea-49f1-9bb5-d41f3bc53b02"], Cell[999166, 23721, 152, 2, 28, "Input",ExpressionUUID->"09a785ea-4a07-40ce-bd4f-ed837e02d53d"] }, Closed]], Cell[CellGroupData[{ Cell[999355, 23728, 96, 0, 35, "Subsubsection",ExpressionUUID->"abf472cd-7ce7-462d-baac-778ee478b3dd"], Cell[999454, 23730, 380, 5, 99, "Text",ExpressionUUID->"e2e316bb-ecfa-43cb-afc1-81f324a1695a"], Cell[999837, 23737, 4620, 111, 656, "Input",ExpressionUUID->"1c67af7a-0d68-4f51-82e2-b81b71e122dc"], Cell[1004460, 23850, 156, 3, 28, "Input",ExpressionUUID->"a2a715db-5e85-46d9-a753-b0c773483ab3"] }, Closed]], Cell[CellGroupData[{ Cell[1004653, 23858, 97, 0, 35, "Subsubsection",ExpressionUUID->"108e4a14-52e7-4fb3-a285-88fa126e0901"], Cell[1004753, 23860, 987, 15, 230, "Text",ExpressionUUID->"00beec26-d942-4927-a8e4-10f724af3ac4"], Cell[1005743, 23877, 7163, 169, 960, "Input",ExpressionUUID->"02ba8cce-1df2-4e37-bccf-e10a013a49b8"], Cell[1012909, 24048, 156, 3, 28, "Input",ExpressionUUID->"32db4d59-3ecd-42da-9dfb-64641752fa1e"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[1013114, 24057, 121, 0, 37, "Subsection",ExpressionUUID->"a2718367-9c44-4219-b0f7-322c29578e7d"], Cell[1013238, 24059, 268, 4, 77, "Text",ExpressionUUID->"c11c207d-4315-4819-a76e-f5c37fe98555"], Cell[CellGroupData[{ Cell[1013531, 24067, 93, 0, 43, "Subsubsection",ExpressionUUID->"06fd2ea4-e504-4462-9c51-1989c9e0918e"], Cell[1013627, 24069, 326, 5, 77, "Text",ExpressionUUID->"5904ec18-4bec-4475-af99-946cf71a8ec5"], Cell[1013956, 24076, 1154, 30, 180, "Input",ExpressionUUID->"6a7c23db-2a9b-43c6-99f9-b6bed64b842d"], Cell[1015113, 24108, 156, 3, 28, "Input",ExpressionUUID->"9bec37ee-f2f2-4c8f-960c-3c41df5d363e"] }, Closed]], Cell[CellGroupData[{ Cell[1015306, 24116, 96, 0, 35, "Subsubsection",ExpressionUUID->"e07aa4d8-ca6f-4cc0-9194-f3a49c94c02d"], Cell[1015405, 24118, 178, 3, 55, "Text",ExpressionUUID->"a4a97bf7-1a1d-4c72-83bd-6e4db756cde7"], Cell[1015586, 24123, 285, 5, 99, "Text",ExpressionUUID->"ded2fc3c-31df-4da6-964b-ba0f1f164a36"], Cell[1015874, 24130, 172, 3, 33, "Text",ExpressionUUID->"1a75a61b-aea1-421b-9323-32e457858d2f"], Cell[1016049, 24135, 5292, 125, 751, "Input",ExpressionUUID->"769dec76-8614-4679-9904-c07cd35444a0"], Cell[1021344, 24262, 156, 3, 28, "Input",ExpressionUUID->"50843857-9957-48ed-b5d6-6b108b1aa87c"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[1021549, 24271, 117, 0, 37, "Subsection",ExpressionUUID->"ca96bb64-4a9f-4dbc-94f3-422f2675c925"], Cell[1021669, 24273, 219, 3, 55, "Text",ExpressionUUID->"70d9fa9c-a69c-41e1-a4ac-777aa8dd698f"], Cell[1021891, 24278, 151, 2, 33, "Text",ExpressionUUID->"8071992b-2bbe-4e3d-8cc8-50373922d01b"], Cell[1022045, 24282, 224, 6, 28, "Input",ExpressionUUID->"62eaa9d2-e865-48df-a0f7-2c52bfce9240"], Cell[1022272, 24290, 237, 4, 55, "Text",ExpressionUUID->"d52804aa-e6d1-4cd6-858f-8c01ceb96e06"], Cell[CellGroupData[{ Cell[1022534, 24298, 93, 0, 43, "Subsubsection",ExpressionUUID->"169a017b-7348-419f-aef0-f59ad254d4af"], Cell[1022630, 24300, 147, 2, 33, "Text",ExpressionUUID->"0bc14b16-0c4a-4e1a-8811-c5c395c716a8"], Cell[1022780, 24304, 1396, 38, 272, "Input",ExpressionUUID->"ea9f4030-aa15-4ecd-b3b1-8678fdbe2f2f"], Cell[1024179, 24344, 156, 3, 28, "Input",ExpressionUUID->"32153ff3-8d7f-4e2d-9170-9a194c60373a"] }, Closed]], Cell[CellGroupData[{ Cell[1024372, 24352, 96, 0, 35, "Subsubsection",ExpressionUUID->"90cc9aee-98d9-4ba3-a809-d06b110918bb"], Cell[1024471, 24354, 228, 3, 55, "Text",ExpressionUUID->"5457109a-bde4-4759-bcef-9da597772590"], Cell[1024702, 24359, 2063, 50, 456, "Input",ExpressionUUID->"a82f84d0-b4a7-4a41-ae65-f5a51ee421af"], Cell[1026768, 24411, 156, 3, 28, "Input",ExpressionUUID->"8228ff51-7dfa-4e50-b535-d0ef98e5303b"] }, Closed]], Cell[CellGroupData[{ Cell[1026961, 24419, 97, 0, 35, "Subsubsection",ExpressionUUID->"f1e30cc8-2421-4dcd-8c71-314f9397dd1c"], Cell[1027061, 24421, 186, 3, 55, "Text",ExpressionUUID->"32b69b81-face-46f1-bdcc-598f519507ee"], Cell[1027250, 24426, 698, 25, 47, "Input",ExpressionUUID->"f1249a9c-2ed3-438f-922c-b6fd25eef03b"], Cell[1027951, 24453, 470, 10, 77, "Text",ExpressionUUID->"8d51eeae-9b13-44b1-8fa6-bb20827af83f"], Cell[1028424, 24465, 2141, 51, 473, "Input",ExpressionUUID->"e5785ef9-f0da-42e0-a05b-2f177246e773"], Cell[1030568, 24518, 156, 3, 28, "Input",ExpressionUUID->"161ea543-8fe7-4619-80de-55c8f5cf97f3"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[1030773, 24527, 170, 3, 37, "Subsection",ExpressionUUID->"7b17f6c1-2837-524e-be33-0c6bad21c394"], Cell[1030946, 24532, 452, 8, 55, "Text",ExpressionUUID->"f1b0335c-4577-494a-86e0-608b2d2850c1"], Cell[CellGroupData[{ Cell[1031423, 24544, 163, 3, 43, "Subsubsection",ExpressionUUID->"e23f584d-8800-1446-be10-ad038553ab38"], Cell[1031589, 24549, 535, 9, 77, "Text",ExpressionUUID->"4ea201ff-48f4-4a44-b3d2-19f2750ddfd9"], Cell[1032127, 24560, 3817, 77, 637, "Input",ExpressionUUID->"633820a0-ab5a-d54c-9da2-96419f0eb146"], Cell[1035947, 24639, 416, 8, 28, "Input",ExpressionUUID->"bfa89b66-2092-274e-924b-f85daf0b9494"] }, Closed]], Cell[CellGroupData[{ Cell[1036400, 24652, 167, 3, 35, "Subsubsection",ExpressionUUID->"de82d39b-cd1b-a140-a23e-709c8ed9d048"], Cell[1036570, 24657, 997, 16, 186, "Text",ExpressionUUID->"e18d3675-3658-b648-bcea-51f3c609b394"], Cell[1037570, 24675, 6004, 117, 884, "Input",ExpressionUUID->"555889a0-345c-684b-b078-654976290a46"], Cell[1043577, 24794, 1060, 16, 28, "Input",ExpressionUUID->"c943d131-07c5-af42-8b42-47f983062804"] }, Closed]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[1044698, 24817, 159, 3, 52, "Section",ExpressionUUID->"5861d877-bbe8-4b6b-8bf6-d46f0e28619e"], Cell[1044860, 24822, 156, 3, 33, "Text",ExpressionUUID->"bccb800d-a7cd-4fc6-a286-d05ffb71ddfe"] }, Open ]] } ] *)