Commit Graph

918 Commits

Author SHA1 Message Date
Gerwin Klein b92974d93f
lib: theory import fixes for new sessions
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-24 11:30:05 +11:00
Gerwin Klein 0aa42207e5
lib/monads: move Datatype_Schematic into wp
Not at monad definition itself, more tool setup for WPFix.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-24 11:30:05 +11:00
Gerwin Klein cc0ca9118e
lib: introduce Monads session
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-24 11:30:05 +11:00
Gerwin Klein 2722fdcfc1
lib: move more monad thys into Monads directory
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-24 11:30:05 +11:00
Gerwin Klein bba173cb99
lib+READMEs: rename Monad_WP to Monads
In preparation for a separate Monads session.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-24 11:30:05 +11:00
Gerwin Klein 34c427d09d
lib: add separate Eisbach_Tools session
The idea is to collect Eisbach extensions and things like Apply_Trace,
Apply_Debug etc here.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-24 11:30:04 +11:00
Gerwin Klein 0aa2914b84
lib/monads: move empty_fail_guard into NonDetMonadVCG
So that it is available together with the other empty_fail lemmas.
Eventually, these should go into their own theory.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-24 11:21:47 +11:00
Gerwin Klein 238acb46bb
lib+tools: MLUtils -> ML_Utils for consistency
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-20 13:43:39 +11:00
Gerwin Klein d86d577657
lib: make ML_Utils a separate session
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-20 13:43:39 +11:00
Gerwin Klein f0f19375f7
lib: rename ml-helpers to ML_Utils
In preparation for making it its own separate session.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-20 11:26:48 +11:00
Gerwin Klein 7424005a66
lib: make theLeft/theRight/isLeft/isRight abbreviations
Since the creation of these constants the sum type has been updated to
come with its own discriminators and selectors. We use these, but keep
our longer names as abbreviations.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-19 17:41:11 +11:00
Gerwin Klein 9c3a7faefd
lib+proofs: s/non_fail_/no_fail/
Some of the no_fail lemmas had he wrong name (non_fail instead of
no_fail).

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-19 17:02:10 +11:00
Gerwin Klein 79eccd3c10
lib+spec+proofs: proof fixes for NonDetMonadLemmaBucket split
Very minor changes, but in many modules.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-19 17:01:34 +11:00
Gerwin Klein fc5af7e402
lib: rename More_Monad to Monad_Lists and fix style
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-19 17:01:25 +11:00
Gerwin Klein d86acc885a
lib: move wp lemmas for mapM et al into More_Monad
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-19 17:01:13 +11:00
Gerwin Klein d275068826
lib: move empty_fail lemmas up into NonDetMonadVCG
This enables a few more moves of remaining lemmas in
NonDetMonadLemmaBucket into the theories they belong thematically.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-19 17:01:12 +11:00
Gerwin Klein f19364a38b
lib: split NonDetMonadLemmaBucket into multiple theories
- organizes the material
- enables more concurrency
- allows us to pick and choose which parts to import

Currently NonDetMonadLemmaBucket still imports Lib to keep the overall
exports from this theory unchanged, but none of the factored-out
theories depend on Lib.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-19 17:01:12 +11:00
Gerwin Klein de9cb04a11
lib: factor out monad dependencies
Factors out definitions and lemmas that are used in monads from Lib.thy
into a separate theory Monad_Lib, which itself does not have further
dependencies.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-19 17:00:14 +11:00
Michael McInerney 619e941631 c-parser+crefine+clib: move is_aligned_c_guard to c-parser session
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2023-01-12 11:48:59 +10:30
Gerwin Klein 3960115459
lib+proofs+sys-init+tools: proof updates for Fun_Pred_Syntax
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-09 14:54:11 +11:00
Gerwin Klein 369a926e4d
lib: factor out and generalise bool syntax for functions
pred_conj, pred_disj, and pred_neg only worked for functions with a
single argument and did not have the standard boolean laws available.

This commit factors out these declarations into their own theory, so
they can be used independently. It generalises them to functions of
arbitrarily many arguments, using the existing instance of fun in class
boolean_algebra.

We also factor out top/bottom, but leave them as abbreviations for now,
because the impact of changing them to the type class is too large.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-01-09 14:54:06 +11:00
Michael McInerney 03426eada0 lib: add hoare_from_abs rule
This also moves ex_abs_underlying from Corres_Method.thy to
ExtraCorres.thy and adds a variant of corres_underlying_split

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2022-11-10 16:09:13 +11:00
Michael McInerney 9b33cfad36 update copyright
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2022-11-09 15:52:50 +11:00
Corey Lewis 7e44994a55 isabelle2022 lib: update Concurrency
Signed-off-by: Corey Lewis <corey.lewis@proofcraft.systems>
2022-11-09 11:45:46 +11:00
Corey Lewis c6b137dfba isabelle2022 lib: update Lib
Signed-off-by: Corey Lewis <corey.lewis@proofcraft.systems>
2022-11-09 11:45:46 +11:00
Gerwin Klein e101f37cfc isabelle2022: import Word_Lib AFP changes
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-11-09 11:45:46 +11:00
Rafal Kolanski 87fadfcca5 lib: monadic rewrite: adjust single pass and symb exec methods
During deployment of these tactics, two problems appeared:
* monadic_rewrite_single_pass
  * would try to step after the action completed, which sometimes worked,
    yielding unpredictable results
  * finalise was called on monadic_rewrite goals generated by action,
    which was fine with the `solves <wpsimp>` default, but yielded
    unpredictable results with user-supplied finalise methods
* monadic_rewrite_symb_exec
  * did not schematise the precondition before attempting to apply the
    rule, resulting in lack of progress when it was expected;
    this now yields an extra subgoal in rare obvious-precondition
    cases, but is more user-friendly in the general case

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-11-02 05:05:44 +11:00
Rafal Kolanski 40e5f2b700 lib: monadic rewrite: overhaul tactics
In single-pass methods and symb_exec* methods, the finalise method
argument is optional, defaulting to solves<wpsimp> which is good enough
for most side-conditions and many WP goals.

`monadic_rewrite_symb_exec_l/r_known` methods internally supply the
instantiated theorem variable name, allowing specifying the
instantiation directly:
`monadic_rewrite_symb_exec_l cte_cap`

Symbolic execution removes no-name eta terms so that the actual variable
name in the monad is used, reducing need for rename_tac.

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-11-02 05:05:44 +11:00
Rafal Kolanski 29ded1c71f lib: monadic_rewrite improvements and renames
`_symb_exec` rules now assume `monadic_rewrite` statement first, to allow
chaining and automation, by deferring WP goals to later

`_symb_exec_*_known*`: better use of invariance of executed statement

renamed `monadic_rewrite_rule` to `monadic_rewrite_l_method`, added
equivalent for RHS

renamed `monadic_rewrite_simple` to `monadic_rewrite_l`, and changed
action argument into a supplied rule (expected single-fire usage), and
added equivalent for RHS

renamed `lhs`->`l` and `rhs`->`r`
renamed `monadic_rewrite_pre_imp_refl` -> `_eq`

added: generic rules for rewriting under corres_underlying
* `monadic_rewrite_corres_l_generic`
* `monadic_rewrite_corres_r_generic`

added: `monadic_rewrite_if_r_True/False`

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-11-02 05:05:44 +11:00
Rafal Kolanski 9847dc7fc1 lib: monadic_rewrite symb exec and corres cleanup
Overhauled symbolic execution lemmas, improved genericity:
* monadic_rewrite_symb_exec_l' and r' are now main lemmas
* _F/_nF variants for LHS, E/nE variants for RHS
* non-apostrophied versions combine the above
* same for drop/known lemmas

Consolidated monadic_rewrite and corres lemmas:
* old monadic_rewrite_corres was never used except when rotated, so
  monadic_rewrite_corres2 -> monadic_rewrite_corres
* monadic_rewrite_corres' unused and not needed -> removed

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-11-02 05:05:44 +11:00
Rafal Kolanski dcac294aac lib: single-pass monadic_rewrite tactics
Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-11-02 05:05:44 +11:00
Rafal Kolanski 4137ea1635 lib: monadic_rewrite improvements and renames
renamed:
* `monadic_rewrite_refl3` -> `monadic_rewrite_pre_imp_refl`
* `monadic_rewrite_symb_exec2` -> `monadic_rewrite_symb_exec_drop`
  (also removed trivial assumption)

removed:
* `monadic_rewrite_refl2`: use `monadic_rewrite_is_refl[OF ext]` instead
* `monadic_rewrite_bind2`: use `monadic_rewrite_bind_l` instead
* `monadic_rewrite_bind_alt`: use `monadic_rewrite_bind_l` instead

added:
* `monadic_rewrite_bindE_tail` to go with its bind version

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-11-02 05:05:44 +11:00
Rafal Kolanski 757483c897 lib: NonDetMonadVCG: add pred_conj_comm
Commutativity of `pred_conj`

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-11-02 05:05:44 +11:00
Rafal Kolanski 6c90b9002c lib: monadic_rewrite: use standard inv form
The standard form for a hoare triple showing the function is
state-invariant is `f {| P |}`, and that's what we crunch in later
proofs.
Using this form allows `[OF whatever_inv]` to instantiate, while using
the `f {|(=) s|}` form does not.

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-11-02 05:05:44 +11:00
Rafal Kolanski 11b1041282 lib: monadic_rewrite improvements and renames
Isabelle allows preservation of variable names across rules if the name
associated with a DeBruijn index matches. All forms of monadic symbolic
execution lemmas should therefore use some form of:
`f >== \<lambda>rv. g rv` and refer to `\<All>rv. some_prop_of rv` in
the assumptions, to expose the bound names in the proof, avoiding
unnecessary `rename_tac`.

The following lemmas have been renamed after multiple discussions:
* `monadic_rewrite_imp` -> `monadic_rewrite_guard_imp` (to match [c]corres)
* `monadic_rewrite_weaken` -> `monadic_rewrite_weaken_flags`
  (people expected "weaken" rules to weaken the precondition, not flags)
* `monadic_rewrite_weaken2` -> `monadic_rewrite_weaken_flags'`
  (same reason)

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-11-02 05:05:44 +11:00
Gerwin Klein 013115dcde lib: avoid @{file} for files that might be moved
The theory Value_Types is used without Value_Types_Test in the
AutoCorres release, which makes the @{file ..} antiquotation fail.
Including Value_Types_Test in the dependencies of Value_Types to
include it in the release doesn't work, because that would be a
circular dependency.

So to avoid manually enumerating release files, we make this a pure
@{text ..} antiquotation instead.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-10-31 11:45:05 +11:00
Gerwin Klein 08a31c1d99 lib: equality lemma for obind = None case
Co-authored-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-10-20 17:51:27 +11:00
Gerwin Klein 3faced9815 lib: additional is_inv lemmas
Co-authored-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-10-20 17:51:27 +11:00
Gerwin Klein 4404c5137d lib: more opt_map lemmas
- equality proof by focussing on the left side of an |>
- relationship between obind and opt_map

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-10-20 17:51:27 +11:00
Gerwin Klein 639ebf7eed lib: introduce fun_upd2
fun_upd for functions with two arguments.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-10-20 17:51:27 +11:00
Gerwin Klein ff1688e753 lib: better automation of dom equality
Domain equality is nice to state and sometimes nice to prove, but it is
hard to use in automation (fastforce/auto). The new phrasing here is not
as nice to read, but useful in automation.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-10-20 17:51:27 +11:00
Gerwin Klein 53e724808f lib: collect if_option lemmas in one place
Carefully not disturbing the simpset, because too many things break
otherwise.

Similarly, if_option_Some2 is not included with if_option_Some, because
the latter is being declared globally [simp] at some stage and then
breaks things in too many random places.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-10-20 17:51:27 +11:00
Gerwin Klein a45d32e574 word-lib: remove unused if/option lemma
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-10-20 17:51:27 +11:00
Gerwin Klein 8c796c5240 lib: opt_map equation for negative projection case
We so far have unfolded opt_map in these ... = None situations. Using
the new rule directly eliminates one of the cases (the Some case), so
is slightly more efficient when we stack them and get many of these.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-10-20 17:51:27 +11:00
Corey Lewis d7938b80b0 lib: reorder the assumptions of corres_split rules
This also removes corres_split_deprecated

Signed-off-by: Corey Lewis <corey.lewis@proofcraft.systems>
2022-10-20 08:59:52 +11:00
Rafal Kolanski 02448cc3fb lib: add fwd_all + fwd_all_new methods, combinators
fwd_all and ALLGOALS_FWD act like `all`, but supplied method is applied
to goals in first-to-last order, taking into account goals solved and
generated.

fwd_all_new and FWD_ALL_NEW act like `;` and THEN_ALL_NEW, but with the
second method is applied to the results of the first in the order they
were produced, making it safe for WP reasoning.

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-09-26 15:24:46 +10:00
Rafal Kolanski 120181631b lib: add rules_tac and related multi-thm instantiators
In `Rules_Tac`, add a `rules_tac` which is `rule_tac` but with the
ability to instantiate the same variable name in multiple theorems.

Also add the specialised `single_instantiate_tac` which allows using the
above mechanism to instantiate a specific variable name in a specific
set of theorems (e.g. "rv" in a set of symbolic-execution lemmas).

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-09-10 06:29:19 +10:00
Rafal Kolanski aa78eb08c7 lib: add if_then_else, has_concl, case_concl Eisbach_Methods
These allow for pattern-matching on the conclusion and reacting to
whether the match succeeded.

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-09-10 01:22:32 +10:00
Rafal Kolanski ce995b4e28 lib: add named_eta and no_name_eta methods
These allow selective eta-contraction in the goal based on the bound
variable's name. The `no_name_eta` method speficially targets
abstractions where the variable has no name, which can come up in
complicated unification scenarios.

These nameless abstractions can cause symbolic execution lemmas to no
longer pick up on the name of the bound variable in do-notation,
requiring multiple rename_tac invocations.

Co-authored-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-09-06 02:50:23 +10:00
Michael McInerney 4f0bbd4fcb lib: add monadic_rewrite_drop_return and monadic_rewrite_add_return
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2022-07-04 16:04:10 +09:30