Gradual Exact Logic
Unifying Hoare Logic and Incorrectness Logic via Gradual Verification
Abstract.
Previously, gradual verification has been developed using overapproximating logics such as Hoare logic. We show that the static verification component of gradual verification is also connected to underapproximating logics like incorrectness logic. To do this, we use a novel definition of gradual verification and a novel gradualization of exact logic (Maksimovic et al., 2023) which we call gradual exact logic. Further, we show that Hoare logic, incorrectness logic, and gradual verification can be defined in terms of gradual exact logic.
We hope that this connection can be used to develop tools and techniques that apply to both gradual verification and bug-finding. For example, we envision that techniques defined in terms of exact logic can be directly applied to verification, bug-finding, and gradual verification, using the principles of gradual typing (Garcia et al., 2016).
1. Overview
Incorrectness logic (O’Hearn, 2020) has been recently developed as a formal basis for “true bug-finding” and has been applied in industrial-strength tools (Le et al., 2022). Deductions in this logic prove reachability, which enables bug-finding tools to prove the existence of an invalid state while selectively exploring the possible paths.
At the same time, gradual verification (GV) (Bader et al., 2018) addresses the complexity of traditional static verification. Gradually verified programs may contain imprecise specifications—logical formulas annotated to indicate that they contain only a partial specification of behavior. A gradual verifier checks the imprecise specifications using static verification where it can and run-time checks (i.e. dynamic verification) elsewhere. These run-time checks can be exercised, e.g. with testing, giving the programmer confidence that their code will not enter a state that violates their partial specifications. Using gradual verification, programmers can incrementally verify a program, incrementally learn verification constructs, and safely guard unverified components.
More recent work (Zilberstein et al., 2023; Maksimovic et al., 2023; Lööw et al., 2024) has produced logics and tools that unify over-approximating (OX) logic, often used in verification, and under-approximating (UX) logics including IL. In this paper, we propose another unification of OX and UX logics that we derive using the principles of gradual verification. The resulting characterization of IL demonstrates a previously unexplored connection between GV and IL.
1.1. Hoare logic
A triple in Hoare logic (HL) (Hoare, 1969) is denoted . ( refer to logical specifications; refers to a program statement.) Semantically, the triple is valid if, for every state (i.e., is true of ), when (i.e., executing results in ), then :
Thus HL is an overapproximating (OX) logic—the postcondition overapproximates the states that are reachable from ; precisely, . HL is a formal foundation for program verification precisely because the postcondition is true in all ending states.
1.2. Incorrectness logic
A triple in incorrectness logic (IL) (O’Hearn, 2020) is denoted 111IL triples often include a specification for error states, but we omit error handling to simplify the comparison with other logics.. Semantically, the triple is valid if, for every , there is some such that :
Thus IL is an underapproximating (UX) logic—the postcondition underapproximates the states that are reachable from ; precisely, . Interpreting as a specification of a bug, IL is a logic for finding bugs since a valid triple indicates that the bug is reachable.
1.3. Gradual verification
Gradual verification (GV) (Bader et al., 2018) reduces the burden of static verification by allowing incomplete (imprecise) specifications. A gradual verifier may make optimistic assumptions when verifying imprecisely-specified code. Typically, the final program is elaborated to check these assumptions at run-time. However, in this work we focus solely on the static verification component of GV so that we can compare its logic with HL and IL.
We denote imprecise triples by . Intuitively, this triple is valid if there is some such that is valid in HL. One can think of ? as representing the additional assumptions introduced by .
For example, the following imprecise triple is valid:
This follows from the validity of
That is, the postcondition is ensured when assuming .
However, the assumptions must be plausible; formally, (and thus ) must be satisfiable (i.e., ). Otherwise, all imprecise triples would be vacuously valid by taking . With this in mind, GV can be stated as a reachability problem—semantically, is valid if there exists some states and such that , , and :
By contrapositive, the triple is invalid (i.e., static verification will error) if it is never possible for to ensure , given .
By comparing this diagram with those in §1.1 and §1.2, we can deduce that HL and IL triples are valid imprecise triples, except for vacuous cases where in HL or in IL.
Our semantic definition of validity is equivalent to the previous definition which uses Hoare triples: Let be a formula that represents as specifically as possible, then (intuitively) is valid since and .
But, we can also define valid imprecise triples in terms of IL— is valid if is valid for some . In §2.5 we will prove these definitions equivalent.
2. Formal foundations
We will now sketch our formal definitions and results. See the appendices for the full statements and proofs.
- (1)
-
(2)
We show that HL, IL, and GV can be characterized by gradual exact logic.
-
(3)
We show that GV contains OX and UX deductions.
-
(4)
We show that, for imprecise specifications, GV can be equivalently defined using OX or UX logics.
2.1. Exact logic
Exact logic (EL) (Maksimovic et al., 2023) is the intersection of HL and IL: an EL triple is valid if and are both valid. Deductions are thus exact—they can neither under- or overapproximate behavior (see Appendix E for rules).
2.2. Gradual exact logic
We further define gradual exact logic () as a consistent lifting (Garcia et al., 2016) of EL.
First, some definitions: Formula denotes all formulas in FOL with arithmetic; we call these precise. SatFormula denotes all satisfiable formulas. An imprecise formula is of the form where . A gradual formula can be either precise or imprecise.
The concretization interprets a gradual formulas as sets of precise formulas:
Let denote a valid EL triple. Deductions in , denoted , are defined as a consistent lifting of EL deductions (Section E.2):
2.3. Strongest postconditions
denotes the strongest (WRT ) for which is valid (calculated as usual; see Section B.2). Strongest postconditions are related to HL, IL, and EL as follows:
2.4. HL and IL via
We can characterize valid HL triples as triples where the postcondition is made imprecise. Assuming that and terminates (in either of these cases is vacuous), we have and thus (Theorem 6)
Likewise, we can characterize valid IL triples as triples where the precondition is made imprecise. Weakest preconditions are not always defined for IL (O’Hearn, 2020), however, we can reuse weakest preconditions for HL to witness the necessary formula (see Section B.3). Assuming (otherwise is vacuous), we have (Theorem 7)
2.5. GV via HL, , and IL
We can now give a precise definition of GV in terms of HL, as sketched in §1.3222Here we define GV more generally for all gradual preconditions, whereas in §1.3 we defined it for imprecise preconditions.. We denote valid GV triples as .
Using this definition and applying the characterization of HL from §2.4 to characterize GV in terms of EL:
For sake of comparison, we can define as a lifting of IL, the same way we have lifted HL to GV.
But, in the case of imprecision this is equivalent to GV. We can see this using the characterization of IL given in §2.4:
Note: GV and differ on precise formulas— is not equivalent to . Also, we do not gradualize postconditions in HL or preconditions in IL because we can arbitrarily weaken these specifications already.
While verification of precise formulas is a key aspect of GV, this demonstrates that verification of imprecise formulas can be accomplished using IL, and moreover that GV, when verifying imprecisely-specified code, is proving an IL deduction. Finally, we can make precise our claim from §1.3 that both OX and UX deductions are valid in (the imprecise fragment of) GV. Assuming , we have (immediate from definition of GV)
Also, assuming , we have
Thus GV (and ) represents the union of HL and IL, while EL represents the intersection.
3. Applications
GV and IL verifiers in practice operate quite similarly; for example, compare the core consume operation of Zimmerman et al. (2024) for a gradual verifier and of Lööw et al. (2024) for an IL verifier. Both types of verifiers make assumptions, including pruning paths, when establishing a postcondition. This work formalizes the connection between these methods of verification; in particular, gradual verification of imprecisely-specified code is equivalent to IL deductions. We hope that this will allow verifiers that already incorporate both OX and UX logics, for example Lööw et al. (2024), to be easily extended to GV.
Similarly, we hope our approach can be used as a framework for unifying techniques across static verification, GV, and bug-finding. For example, bi-abduction has been developed in OX logics (Calcagno et al., 2011), applied to UX verification (Lööw et al., 2024), and is related to GV (DiVincenzo, 2023). We expect that techniques like this could be developed in the context of an exact logic, and then their applications to OX, UX, and GV logics could be derived using AGT-style techniques (Garcia et al., 2016).
4. Caveats and future work
While we have proven the results described, we have done so only for a very restrictive language, and thus our results should be considered preliminary. In particular, we do not consider heaps, method calls, or loops. We expect our results extend to these constructs, but showing this will require significant work.
Our definition of GV differs from previous definitions (Bader et al., 2018; Wise et al., 2020; Zimmerman et al., 2024). Our novel definition more clearly demonstrates the connection with IL, and we believe it captures the essence of GV. However, this definition only considers static verification, and thus does not consider run-time assertions. We expect this could be added, and we have hopes that we may be able to model run-time assertions using an evidence-based calculus similar to that of gradual typing Garcia et al. (2016). In addition, further work is necessary to elucidate how the “gradual guarantees” (Garcia et al., 2016) affect the relation of GV to IL. In particular, the static gradual guarantee seems to prohibit arbitrarily dropping paths, which IL can do.
Finally, our work is (to our knowledge) the first to explore a gradualization of exact logic. It remains to be seen whether this is useful its own right. For example, if library developers write exact specifications, a gradual exact logic could be used to aid development of these specifications, similar to how GV aids OX verification. But significantly more work would be necessary for this.
5. Conclusion
We have demonstrated the similarities and differences of GV and IL. Specifically, the relation between IL deductions and deductions with imprecise preconditions shows that the notion of assumptions used in GV is equivalent to the consequence rule (and path pruning) in IL. We also have shown that GV with imprecise specifications is equivalent to IL. Furthermore, we have defined gradual exact logic and used this to formally compare IL, HL, and GV. While much work remains before it is widely applicable, we hope that this framework can be used to develop techniques that uniformly target all three methods of verification.
Acknowledgements.
We thank Devin Singh for his contributions to this work.References
- (1)
- Bader et al. (2018) Johannes Bader, Jonathan Aldrich, and Éric Tanter. 2018. Gradual Program Verification. In Verification, Model Checking, and Abstract Interpretation - 19th International Conference, VMCAI 2018, Los Angeles, CA, USA, January 7-9, 2018, Proceedings (Lecture Notes in Computer Science, Vol. 10747), Isil Dillig and Jens Palsberg (Eds.). Springer, 25–46. https://doi.org/10.1007/978-3-319-73721-8_2
- Calcagno et al. (2011) Cristiano Calcagno, Dino Distefano, Peter W. O’Hearn, and Hongseok Yang. 2011. Compositional Shape Analysis by Means of Bi-Abduction. J. ACM 58, 6, Article 26 (Dec. 2011), 66 pages. https://doi.org/10.1145/2049697.2049700
- DiVincenzo (2023) Jenna Wise DiVincenzo. 2023. Gradual Verification of Recursive Heap Data Structures. Ph. D. Dissertation. Carnegie Mellon University.
- Garcia et al. (2016) Ronald Garcia, Alison M. Clark, and Éric Tanter. 2016. Abstracting gradual typing. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, St. Petersburg, FL, USA, January 20 - 22, 2016, Rastislav Bodík and Rupak Majumdar (Eds.). ACM, 429–442. https://doi.org/10.1145/2837614.2837670
- Hoare (1969) C. A. R. Hoare. 1969. An Axiomatic Basis for Computer Programming. Commun. ACM 12, 10 (1969), 576–580. https://doi.org/10.1145/363235.363259
- Le et al. (2022) Quang Loc Le, Azalea Raad, Jules Villard, Josh Berdine, Derek Dreyer, and Peter W. O’Hearn. 2022. Finding real bugs in big programs with incorrectness logic. Proc. ACM Program. Lang. 6, OOPSLA1 (2022), 1–27. https://doi.org/10.1145/3527325
- Lööw et al. (2024) Andreas Lööw, Daniele Nantes-Sobrinho, Sacha-Élie Ayoun, Caroline Cronjäger, Petar Maksimovic, and Philippa Gardner. 2024. Compositional Symbolic Execution for Correctness and Incorrectness Reasoning. In 38th European Conference on Object-Oriented Programming, ECOOP 2024, September 16-20, 2024, Vienna, Austria (LIPIcs, Vol. 313), Jonathan Aldrich and Guido Salvaneschi (Eds.). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 25:1–25:28. https://doi.org/10.4230/LIPICS.ECOOP.2024.25
- Maksimovic et al. (2023) Petar Maksimovic, Caroline Cronjäger, Andreas Lööw, Julian Sutherland, and Philippa Gardner. 2023. Exact Separation Logic: Towards Bridging the Gap Between Verification and Bug-Finding. In 37th European Conference on Object-Oriented Programming, ECOOP 2023, July 17-21, 2023, Seattle, Washington, United States (LIPIcs, Vol. 263), Karim Ali and Guido Salvaneschi (Eds.). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 19:1–19:27. https://doi.org/10.4230/LIPICS.ECOOP.2023.19
- O’Hearn (2020) Peter W. O’Hearn. 2020. Incorrectness logic. Proc. ACM Program. Lang. 4, POPL (2020), 10:1–10:32. https://doi.org/10.1145/3371078
- Wise et al. (2020) Jenna Wise, Johannes Bader, Cameron Wong, Jonathan Aldrich, Éric Tanter, and Joshua Sunshine. 2020. Gradual verification of recursive heap data structures. Proc. ACM Program. Lang. 4, OOPSLA (2020), 228:1–228:28. https://doi.org/10.1145/3428296
- Zilberstein et al. (2023) Noam Zilberstein, Derek Dreyer, and Alexandra Silva. 2023. Outcome Logic: A Unifying Foundation for Correctness and Incorrectness Reasoning. Proc. ACM Program. Lang. 7, OOPSLA1 (2023), 522–550. https://doi.org/10.1145/3586045
- Zimmerman et al. (2024) Conrad Zimmerman, Jenna DiVincenzo, and Jonathan Aldrich. 2024. Sound Gradual Verification with Symbolic Execution. Proc. ACM Program. Lang. 8, POPL (2024), 2547–2576. https://doi.org/10.1145/3632927
Appendix A Grammar
We define a basic language that includes mutable variables and conditionals. Note that we do not include while loops or functions; these constructs are left for future work.
where and a variable name.
We assume that programs are typed correctly; for example, expressions in will always evaluate to a boolean value.
Definition 0 (Implication).
if all states that satisfy also satisfy .
Note: we do not formalize states or the semantics of assertions; we assume that our logic is close enough to first-order logic and thus use FOL deductions to reason about assertions.
Note: We use to denote implication between formulas in first-order logic with booleans and arithmetic. denotes “if-then” in our metatheory.
Definition 0 (Equivalence of propositions).
denotes that and are logically equivalent; that is,
Throughout this paper, we assume that identity of propositions coincides with equivalence; that is, when we write an individual proposition, technically we are denoting the equivalence class that contains that proposition. For example, .
Definition 0 (Replacement).
denotes with all free occurrences of replaced by .
Definition 0.
denotes the free variables in the assertion .
Definition 0.
denotes all variables referenced or assigned in .
Definition 0.
denotes all variables assigned in . Explicitly,
Appendix B Predicate transformers
B.1. Weakest preconditions
Definition 0.
is the weakest precondition for a statement and postcondition , denoted , if it is the weakest predicate (WRT ) that ensures that if a state satisfies , then after executing , holds.
The following explicit calculations correspond to the previous definition (proved in Theorem 4):
Lemma 0 (Stronger postcondition).
If then
.
Proof.
By induction on :
- skip::
-
- ::
-
- ::
-
- (1):
-
by induction
- (2):
-
by induction using (1)
- (3):
-
by (2) and definition of
- ::
-
- (1):
-
by induction
- (2):
-
by induction
- (3):
-
By (1) and (2)
- (4):
-
By (3) and definition of
B.2. Strongest postconditions
Definition 0.
is the strongest postcondition for precondition and statement , denoted , if it is the strongest predicate (WRT ) that ensures that if a state satisfies , then after executing , holds.
The following explicit calculations correspond to the previous definition (proved in Theorem 8):
where | ||
Lemma 0 (Stronger precondition).
If then
.
Proof.
By induction on :
- skip::
-
.
- ::
-
Note that by logic. Then:
defn logic defn - ::
-
- (1):
-
by induction
- (2):
-
by induction using (1)
- (3):
-
By (2) and definition of ,
- ::
-
- (1):
-
by logic
- (2):
-
by induction using (1)
- (3):
-
by logic
- (4):
-
by induction using (3)
- (5):
-
defn (2), (4), logic defn
Lemma 0.
Proof.
By induction on :
- skip::
-
by definition.
- ::
-
by logic.
- ::
-
defn logic induction logic - ::
-
defn induction induction
Lemma 0.
Note: for a more expressive language, we would also need termination for this to hold.
Proof.
By induction on :
- skip::
-
by definition.
- ::
-
- (1):
-
by assumption
- (2):
-
- (3):
-
by logic using (1) and (2)
- (4):
-
by logic using (3)
We prove this using a semantic argument (assuming standard Kripke semantics for FOL):
Let be a model and . By (3) we have , and thus .
Let . Then we have .
Thus we have . Since , we have . Thus we can conclude that .
- (5):
-
by logic using (4) and since
- (6):
-
by logic using (5)
- :
-
- (1):
-
by assumption
- (2):
-
by definition
- (3):
-
by logic using (1) and (2)
- (4):
-
by induction using (3)
- (5):
-
by induction using (4)
[]
- (1):
-
by assumption
- (2):
-
by definition
- (3):
-
by (1) and (2)
- (4):
-
by logic using (3)
- (5):
-
by logic using (3)
- (6):
-
by induction using (4)
- (7):
-
by induction using (5)
- (8):
-
by logic using (6) and (7) ∎
Lemma 0.
If then .
Proof.
We prove the contrapositive: assume , then , and thus by Lemma 6 . Therefore . ∎
Lemma 0.
If then .
Proof.
By induction on :
- skip::
-
- ::
-
Assuming ,
defn defn - ::
-
defn induction induction defn - ::
-
defn induction logic defn
Lemma 0.
Proof.
By induction on :
- skip::
-
.
- ::
-
defn subst. logic logic defn - ::
-
defn induction induction defn - ::
-
Lemma 0 (Frame rule).
If then
.
Proof.
By induction on :
- skip::
-
- ::
-
Let . Note that , thus from our assumptions Then,
defn defn - ::
-
Note that thus and . Then,
defn induction induction defn - ::
-
Note that by assumption
thus and . Then,defn ind. logic defn
Lemma 0.
Proof.
defn | |||
logic | |||
logic |
defn sp | |||
logic | |||
logic ∎ |
B.3. Fixpoint
We can define a function . We demonstrate that this function reaches a fixpoint.
Lemma 0.
Proof.
By induction on :
- skip::
-
- ::
-
Let . Then,
defn defn subst subst = redundant defn - ::
-
- (1):
-
by induction using
- (2):
-
by induction using
- (3):
-
defn logic (1), (2) defn
- ::
-
- (1):
-
by induction using
- (2):
-
by induction using . Then,
defn (2) (1) defn defn
Lemma 0 (Fixpoint property).
If then
.
Proof.
Immediate from Lemma 12, noting that in this case. ∎
Lemma 0.
If then .
Proof.
Appendix C Hoare logic
Hoare triples are denoted by . Deductions in Hoare logic are characterized by the following rules:
[OX-Skip]
⊢{P} skip {P} \inferrule[OX-Assign]
⊢{P[x/E]} x :-E {P} \inferrule[OX-Seq]
⊢{P} C_1 {R}
⊢{R} C_2 {Q}
⊢{P} C_1; C_2 {Q} \inferrule[OX-If]
⊢{E ∧P} C_1 {Q}
⊢{¬E ∧P} C_2 {Q}
⊢{P} if E then C_1 else C_2 {Q} \inferrule[OX-Cons]
P ⇒P’
⊢{P’} C {Q’}
Q’ ⇒Q
⊢{P} C {Q}
C.1. Weakest preconditions
Lemma 0.
If then .
Proof.
By induction on the derivation of :
- OX-Skip::
-
- (1):
-
by inversion
- (2):
-
by definition
- OX-Assign::
-
- (1):
-
by inversion
- (2):
-
by definition
- OX-Seq::
-
- (1):
-
for some by inversion
- (2):
-
by induction using (1)
- (3):
-
by inversion
- (4):
-
by induction using (3)
- (5):
-
by Lemma 2 using (4)
- (6):
-
By (4), (5), and definition of ,
- OX-If::
-
- (1):
-
by inversion
- (2):
-
by induction using (1)
- (3):
-
by inversion
- (4):
-
by induction using (3)
- (5):
-
logic (2) and (4) defn
- OX-Cons::
-
- (1):
-
for some by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by induction using (3)
- (5):
-
by Lemma 2 using (4)
- (6):
-
by (1), (4), and (5) ∎
Lemma 0.
Proof.
By induction on :
- skip::
-
by definition; by OX-Skip.
- ::
-
- (1):
-
by definition
- (2):
-
by OX-Assign using (1)
- ::
-
- (1):
-
by induction
- (2):
-
by induction
- (3):
-
by OX-Seq using (1) and (2)
- (4):
-
by definition
- (5):
-
by (3) and (4)
- ::
-
- (1):
-
Let
- (2):
-
by induction
- (3):
-
by logic
- (4):
-
by OX-Cons using (2) and (3)
- (5):
-
by induction
- (6):
-
by logic
- (7):
-
by OX-Cons using (5) and (6)
- (8):
-
by OX-If using (4) and (7)
- (9):
-
by (1) and definition of
- (10):
-
by (8) and (9) ∎
Lemma 0.
If then .
Proof.
By Lemma 2, , thus by OX-Cons . ∎
Theorem 4.
.
C.2. Strongest postconditions
Lemma 0.
If then .
Proof.
By induction on :
- OX-Skip::
-
Then and , thus
. - OX-Assign::
-
Then and . Assuming :
defn substitution subst. equality redundant - OX-Seq::
-
- (1):
-
for some by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by induction using (2)
- (5):
-
by Lemma 4 using (4)
- (6):
-
by induction using (3)
- (7):
-
by (5) and (6)
- (8):
-
by (1), (7), and definition of
- OX-If::
-
- (1):
-
for some by inversion
- (2):
-
by inversion
- (3):
-
by inversion
- (4):
-
by induction using (2)
- (5):
-
by induction using (3)
- (6):
-
by logic using (4) and (5)
- (7):
-
by (6) and definition of
- OX-Cons::
-
- (1):
-
for some by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by Lemma 4 and (1)
- (5):
-
by induction using (3)
- (6):
-
by (4), (5), and (2) ∎
Lemma 0.
Proof.
By induction on :
- skip::
-
- (1):
-
by OX-Skip
- (2):
-
by OX-Skip
- (3):
-
by OX-Cons using (1) and (2)
- ::
-
- (1):
-
Let where .
- (2):
-
by OX-Assign
- (3):
-
by logic (witnessed by letting ).
- (4):
-
by OX-Cons using (2) and (3)
- (5):
-
by (1), (4), and definition of
- ::
-
- (1):
-
by induction
- (2):
-
by induction
- (3):
-
by OX-Seq using (1) and (2)
- (4):
-
by definition
- (5):
-
by (3) and (4)
- ::
-
- (1):
-
by induction
- (2):
-
by induction
- (3):
-
by OX-Cons using (1)
- (4):
-
by OX-Cons using (2)
- (5):
-
by OX-If using (3) and (4)
- (6):
-
by (5) and definition of ∎
Lemma 0.
If then .
Proof.
Immediate from Lemma 6, applying OX-Cons. ∎
Theorem 8.
Appendix D Incorrectness logic
Incorrectness logic triples are denoted . Deductions in incorrectness logic are defined as follows:
{mathpar}
\inferrule[UX-Skip]
⊢[P] skip [P] \inferrule[UX-Seq]
⊢[P] C_1 [Q]
⊢[Q] C_2 [R]
⊢[P] C_1; C_2 [R] \inferrule[UX-Assign]
⊢[P] x :-E [∃v (x = E[x/v] ∧P[x/v])] \inferrule[UX-IfThen]
⊢[E ∧P] C_1 [Q]
⊢[E ∧P] if E then C_1 else C_2 [Q] \inferrule[UX-IfElse]
⊢[¬E ∧P] C_2 [Q]
⊢[¬E ∧P] if E then C_1 else C_2 [Q]
\inferrule[UX-Cons]
P’ ⇒P
⊢[P’] C [Q’]
Q ⇒Q’
⊢[P] C [Q] \inferrule[UX-Disj]
⊢[P_1] C [Q_1]
⊢[P_2] C [Q_2]
⊢[P_1 ∨P_2] C [Q_1 ∨Q_2]
D.1. Strongest postconditions
Lemma 0.
Proof.
By induction on :
- skip::
-
By UX-Skip and by definition.
- ::
-
- (1):
-
by UX-Assign
- (2):
-
by definition of
- (3):
-
by (1) and (2)
- ::
-
- (1):
-
by induction
- (2):
-
by induction
- (3):
-
by UX-Seq using (1), (2)
- (4):
-
by definition
- (5):
-
by (3), (4)
- ::
-
- (1):
-
by induction
- (2):
-
by induction
- (3):
-
by UX-IfThen using (1)
- (4):
-
by UX-IfElse using (2)
- (5):
-
by UX-Disj using (3) and (4)
- (6):
-
by definition
- (7):
-
by (5) and (6) ∎
Lemma 0.
If then .
Proof.
Immediate from Lemma 1 and UX-Cons. ∎
Lemma 0.
If then .
Proof.
By induction on the derivation :
- UX-Skip::
-
- (1):
-
by inversion
- (2):
-
by definition
- (3):
-
by (1) and (2)
- UX-Assign::
-
- (1):
-
by inversion
- (2):
-
by definition
- (3):
-
by (1) and (2)
- UX-Seq::
-
- (1):
-
for some by inversion
- (2):
-
by inversion
- (3):
-
by induction using (2)
- (4):
-
by induction using (1)
- (5):
-
by Lemma 4 using (4)
- (6):
-
(3) (5) defn
- UX-IfThen::
-
- (1):
-
for some by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by induction using (3)
- (5):
-
by Lemma 11
- (6):
-
(4) (5) (2)
- UX-IfElse::
-
- (1):
-
for some by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by induction using (3)
- (5):
-
by Lemma 11
- (6):
-
(4) (5) (2)
- UX-Cons::
-
- (1):
-
for some by inversion
- (2):
-
by inversion
- (3):
-
by inversion
- (4):
-
by induction using (1)
- (5):
-
by Lemma 4 using (2)
- (6):
-
by (3), (4), and (5)
- UX-Disj::
-
- (1):
-
for some by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by inversion
- (5):
-
by induction using (1)
- (6):
-
by induction using (2)
- (7):
-
by logic using (5) and (6)
- (8):
-
(4) (7) (3)
Theorem 4.
D.2. Satisfiability
Lemma 0.
If then .
Lemma 0.
If and then .
Proof.
Assume , then we prove the contrapositive; that is, .
Assuming , since we get , and thus by assumption. Then by Lemma 5, thus . ∎
Lemma 0.
If and then .
Appendix E Exact logic
Exact logic triples are denoted by . Deductions in exact logic are characterized by the following rules:
{mathpar}
\inferrule[EX-Skip]
⊢(⊤) skip (⊤) \inferrule[EX-Assign]
x ∉fv(E’)
⊢(x = E’) x :-E (x = E[x/E’])
\inferrule[EX-IfThen]
⊢(P ∧E) C_1 (Q)
⊢(P ∧E) if E then C_1 else C_2 (Q) \inferrule[EX-Seq]
⊢(P) C_1 (R)
⊢(R) C_2 (Q)
⊢(P) C_1; C_2 (Q)
\inferrule[EX-IfElse]
⊢(P ∧¬E) C_2 (Q)
⊢(P ∧¬E) if E then C_1 else C_2 (Q) \inferrule[EX-Frame]
mod(C) ∩fv(R) = ∅
⊢(P) C (Q)
⊢(P ∧R) C (Q ∧R)
\inferrule[EX-Exists]
⊢(P) C (Q)
x ∉fv(C)
⊢(∃x P) C (∃x Q) \inferrule[EX-Disj]
⊢(P_1) C (Q_1)
⊢(P_2) C (Q_2)
⊢(P_1 ∨P_2) C (Q_1 ∨Q_2)
Note: We drop the equivalence rule, since it is immediately valid by our characterization of formulas by equivalence classes.
E.1. Strongest postconditions
Lemma 0.
Proof.
By induction on :
- skip::
-
By EX-Skip and by definition.
- ::
-
- (1):
-
for some since is a tautology. WLOG assume (instances of can be replaced with ).
- (2):
-
by EX-Assign.
- (3):
-
by EX-Frame and (2).
- (4):
-
by EX-Exists and (3).
- (5):
-
defn (1) logic - (6):
-
by (1), (4), and (5).
- ::
-
- (1):
-
by induction
- (2):
-
by induction
- (3):
-
by EX-Seq using (1), (2)
- (4):
-
by definition
- (5):
-
by (3) and (4)
- ::
-
- (1):
-
by induction
- (2):
-
by induction
- (3):
-
by EX-IfThen using (1)
- (4):
-
by EX-IfElse using (2)
- (5):
-
by EX-Disj using (3), (4)
- (6):
-
by logic
- (7):
-
by definition
- (8):
-
by (5), (6), and (7) ∎
Lemma 0.
If then .
Proof.
By induction on the derivation :
- EX-Skip::
-
By inversion and , and by definition . Thus .
- EX-Assign::
-
- (1):
-
for some by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by inversion
- (5):
-
(1), (2) defn (4) logic (4) logic (3)
- EX-IfThen::
-
- (1):
-
by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by induction using (3)
- (5):
-
(1), (2) (4)
- EX-IfElse::
-
- (1):
-
by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by induction using (3)
- (5):
-
(1), (2) (4)
- EX-Seq::
-
- (1):
-
for some by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by induction using (2)
- (5):
-
by induction using (3)
- (6):
-
(1) defn (4) (5)
- EX-Exists::
-
- (1):
-
for some by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by inversion
- (5):
-
by induction using (3)
- (6):
-
(2) (5) (2)
- EX-Disj::
-
- (1):
-
for some by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by inversion
- (5):
-
by induction using (3)
- (6):
-
by induction using (4)
- (7):
-
(1) (5), (6) (2)
- EX-Frame::
-
- (1):
-
for some by inversion
- (2):
-
for some by inversion
- (3):
-
by inversion
- (4):
-
by inversion
- (5):
-
by induction using (4)
- (6):
-
by Lemma 10 using (3)
- (7):
-
(1) (6) (5) (2)
Theorem 3.
E.2. Gradual exact logic
Valid triples in gradual exact logic are denoted .
Definition 0.
The concretization maps a gradual formula to the set of all formulas it can represent:
Definition 0.
Deductions in gradual exact logic directly are lifted deductions in exact logic:
for some and |
Theorem 6.
For ,
That is, except for the vacuous case where , gradualizing the postcondition exactly characterizes deductions in Hoare logic.
Proof.
:
Theorem 7.
If ,
That is, except in the vacuous case where , gradualizing the precondition exactly characterizes deductions in incorrectness logic.
Proof.
: