Commit Graph

992 Commits

Author SHA1 Message Date
Michael McInerney 1273ba314a clib: generalise monadic_rewrite_ccorres_assemble
This makes the flags schematic

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-04-27 08:12:31 +10:00
Corey Lewis b8714328cb word_lib+crefine: add and_one_neq_simps and adjust proofs
Signed-off-by: Corey Lewis <corey.lewis@proofcraft.systems>
2023-04-18 13:23:42 +10:00
Gerwin Klein 1d2e75fd81
word_lib: lemma to turn < into bitwise reasoning
word_less_bit_eq turns `<` into a bitwise expression on abstract word
length to make it easier to reason about the relationship of < and bit
operations (boolean, but also shift etc).

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-11 13:17:54 +10:00
Gerwin Klein d4a63b2784
word_lib: more docs on word_bitwise and word_eqI
The Eisbach method command doesn't seem to allow providing a doc
string. Instead at least place a comment right next to the definition
so that people can find that when they discover the method name with
print_methods.

Update doc string of word_bitwise to clarify where it is useful.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-11 13:17:53 +10:00
Gerwin Klein b72e177677
word_lib: laws about min, max, and NOT
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-11 13:17:53 +10:00
Gerwin Klein d163d41b63
word_lib: some cleanup in More_Word
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-11 13:17:53 +10:00
Gerwin Klein 20ef209b30
word_lib: boolean operations and arithmetic
Adds generic (ring_bit_operations) relationships between boolean and
arithmetic operations. These automatically hold for word and int.

In particular:

   x + y = (x OR y) + (x AND y)
   x + y = (x XOR y) + 2 * (x AND y)
   x XOR y = (x OR y) - (x AND y)

Similar laws for OR, AND, and -.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-11 13:17:53 +10:00
Gerwin Klein d1858007d2
word_lib: all binary boolean inequalities
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-11 13:17:53 +10:00
Gerwin Klein 4bae25bb93
word_lib: sgn and abs instances for word
Provide sgn (sign, mapping to -1, 0, 1) and abs (absolute value)
functions for 'a word by instantiating the relevant type classes.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-11 13:17:53 +10:00
Gerwin Klein ac1cda74f9
word_lib: remove warning
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-11 13:17:49 +10:00
Corey Lewis 75db914627
word_lib: new lemmas about mask, AND, and shift
Signed-off-by: Corey Lewis <corey.lewis@proofcraft.systems>
2023-03-29 11:05:25 +11:00
Michael McInerney 27d838af86 lib+proof: rename bind_assoc_reverse to bind_assoc_return_reverse
This also improves the style of this lemma

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-03-27 10:34:03 +10:30
Michael McInerney 3981e9a60e lib+ainvs: make monadic_rewrite available in AInvs session
This also reduces the imports of MonadicRewrite

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-03-21 18:22:34 +10:30
Michael McInerney 96e6e6a983 lib: add empty_fail_ifME and empty_fail_notM
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-03-21 10:45:28 +10:30
Michael McInerney fa9373674c lib: some corres rules for monadic combinators
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-03-21 10:45:28 +10:30
Michael McInerney adc7499aea lib: add ifME_liftE
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-03-21 10:45:28 +10:30
Gerwin Klein f4a9758d8b lib: add ifME
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-03-21 10:45:28 +10:30
Michael McInerney f74d42f745 lib: add ifM_throwError_returnOk
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-03-21 10:45:28 +10:30
Michael McInerney dc27565fbb lib: add notM and notM_wp
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-03-21 10:45:28 +10:30
Michael McInerney 1c0ceba850 lib: several lemmas involving exs_valid and the reader monad
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-03-20 18:55:49 +10:30
Michael McInerney d844d691cb lib: move bind_assoc_reverse to lib
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-03-10 16:53:08 +10:30
Michael McInerney 909402d887 clib: add ccorres_call_getter_setter
This rule allows us to prove correspondence in the case
where the result of a function call is assigned to a
global variable

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-03-10 16:53:08 +10:30
Gerwin Klein 63ef58cbdb
lib: simp setup for If and option
Terms of the form "(if P then None else Some _) = None" and all their
combinations can be simplified automatically. For the "Some" variants
we provide a safer form, e.g.:

    ((if P then Some x else None) = Some x) = P

because

    ((if P then Some x else None) = Some y) = (P /\ x = y)

adds an equation to the goal that the simplifier will pick up. That is
often wanted, but sometimes leads to non-termination.

Even the safer form can lead to non-termination if P is an equation, so
none of these are [simp] by default.

- `if_option_eq` is the safer set
- `if_option` is the less safe set that simplifies more

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-03-09 10:34:00 +11:00
Gerwin Klein a454a093c0
lib: connection between exs_valid and wp conjugate (#588)
Draw connection between conjugate wp in the literature and our
exs_valid definition.

Add exs_valid_alt lemma, which is one of the main rules that is
different between wp and conjugate wp (or vs and).

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-03-08 13:02:54 +11:00
Michael McInerney cf1af81384 lib: add more rules from MCS work
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-02-14 14:05:05 +10:30
Michael McInerney 015fe74f04 lib: add some lemmas from MCS work to OptionMonadWP.thy
This includes some style improvements, too

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-02-14 11:15:32 +10:30
Gerwin Klein 81513b894f
lib: fix link in Monads README (#576)
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-10 09:12:34 +11:00
michaelmcinerney 087a01ee7c
lib: add hoare_case_option_wp2 (#575)
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-02-10 08:58:35 +11:00
Gerwin Klein 0bee918631
Word_Lib: enable "eval" for word quantifiers (#574)
Enable use of "eval" and "value" for formulas that quantify over word
values. The code generator will exhaustively run all possible values.

For small word sizes, this works in very reasonable time. E.g. try

    lemma "∀(x::8 word) y. x + y = (x AND y) + (x OR y)"
      by eval

or

    value "∀(x::4 word) y z. y mod z = 0 ⟶
                             (x * y) div z = x * (y div z)"

Note that as usual for "eval" and "value" terms have to be close, i.e.
you need to use object logic quantifiers.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-10 08:54:18 +11:00
Gerwin Klein e89813ecf2
proofs: updates for monad refactor
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:55 +11:00
Gerwin Klein bafe2586f4
clib: fix up qualified names
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:51 +11:00
Gerwin Klein bd449a071d
lib: theory imports + proof updates for monad refactor
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:51 +11:00
Gerwin Klein 549cb893de
lib+ainvs: pull up more empty_fail lemmas
- pull base-level empty_fail lemmas from AInvs into Monads.Empty_Fail
- apply consistent naming
- apply consistent [intro!, wp]
- make all non-conditional lemmas [simp]
- re-add context building to empty_fail rules, because the select_*
  rules may need context to solve their side condition

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:50 +11:00
Gerwin Klein a6e2d73e72
lib: introduce [empty_fail] and merge EmptyFailLib
- merge EmptyFailLib into Monads.Empty_Fail
- group Empty_Fail lemmas so it is clear where to add new ones
- add [empty_fail] so not every lemma has to declare multiple attributes
- add instructions

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:50 +11:00
Gerwin Klein e3c74c2b6e
lib/monads: remove alternative_valid in TraceMonad
subsumed by alternative_wp

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:50 +11:00
Gerwin Klein c679117676
lib/monads: style cleanup in NonDetMonadLemmas
- apply modern style
- contract some proofs
- this commit includes some lemmas factored out from NonDetMonadVCG in
  a previous commit

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:50 +11:00
Gerwin Klein 9573e5cb85
lib/monads: style cleanup in NonDetMonad
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:50 +11:00
Gerwin Klein b0da6b3ee9
lib/monads: style cleanup in MonadEq+MonadEq_Lemmas
Style and proof contraction.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:50 +11:00
Gerwin Klein 4f44b1ce7e
lib/monads: style cleanup in In_Monad
- style and some proof contraction
- `in_monad` set remains unchanged for now (could now add additional
  lemmas, but they might break things)

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:49 +11:00
Gerwin Klein 708cee52f6
lib/monads: style cleanup in WhileLoopRules
- adjusted thy imports for new theories
- apply consistent style
- fix indentation
- minor proof contraction

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:49 +11:00
Gerwin Klein 8e81962b47
lib/monads: refactor + cleanup in No_Fail
- factor out valid_NF definition and lemmas into NonDetMonad_Total
- apply modern style and (very) occasional proof contraction in both

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:49 +11:00
Gerwin Klein 6758f2b3e7
lib/monads: refactor + cleanup in NonDetMonadVCG
- factor out valid_exs definition and properties into NonDetMonad_Sat
- apply modern style to both of these and More_NonDetMonadVCG
- factor out one lemma into Monad_Lib
- better grouping of lemmas in NonDetMonadVCG
- occasional proof contraction

Should contain no real semantic differences, but might have subtle
wp set changes due to reordering (to be fixed up in a later commit).

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:49 +11:00
Gerwin Klein dfc7699407
lib/monads: add sum type to Datatype_Schematic
This should allow wpfix to automatically fix up projl/projr proofs.
This was previously not possible without drawing in Lib, but will now
be picked up by Lib since theLeft/theRight are now abbreviations.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:49 +11:00
Gerwin Klein b93335745e
lib/monads: style cleanup in Empty_Fail
Mostly contraction and some refactoring.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:48 +11:00
Gerwin Klein e51723ce5a
lib/monads: style cleanup in No_Throw
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:48 +11:00
Gerwin Klein 5e04e1b7ca
lib/monads: split up NonDetMonadVCG
Split up the material in NonDetMonadVCG into In_Monad, Det, Empty_Fail,
No_Fail, and No_Throw. Most of these can run concurrently and not all
applications need to include all of the material.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-02-09 11:46:46 +11:00
Michael McInerney 421dd9785b libtest: qualify bind for NonDetMonad
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-02-07 11:30:30 +10:30
Michael McInerney 527cdd329a clib: add ccorres_While rule
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-02-07 11:30:30 +10:30
Michael McInerney 7bf5798c0b clib: add ccorresE_gets_the rule
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-02-07 11:30:30 +10:30
Michael McInerney 3573111a7c clib: add exec_handlers_use_hoare_nothrow_hoarep rule
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-02-07 11:30:30 +10:30