-
Notifications
You must be signed in to change notification settings - Fork 2
Description
A proof in src/Bluebell/Logic/WeakestPre.lean contains a sorry.
🤖 AI Analysis:
Statement Explanation
This theorem states the law of composition for the weakest precondition (wp). It asserts that the weakest precondition for two sequentially composed programs is equivalent to nesting their weakest preconditions.
The statement is (wp t₁ (wp t₂ Q)) ⊣⊢ (wp (t₁ ∘ t₂) Q). Let's break this down:
t₁andt₂are program transformers. In Lean,t₁ ∘ t₂means function composition, so(t₁ ∘ t₂) (m) = t₁ (t₂ (m)). This represents running programt₂first, then programt₁.wp t Pis the weakest precondition for programtand postconditionP.- The standard rule for sequential composition
S₁; S₂iswp(S₁; S₂, R) = wp(S₁, wp(S₂, R)). - If we let
S₁ = t₂andS₂ = t₁, then the composition ist₂; t₁, which corresponds tot₁ ∘ t₂. The standard rule would then bewp(t₁ ∘ t₂, Q) = wp(t₂, wp(t₁, Q)). - Your theorem is stated as
wp t₁ (wp t₂ Q) ⊣⊢ wp (t₁ ∘ t₂) Q. It seems that the roles oft₁andt₂on the left-hand side are swapped compared to the standard formulation. You may want to double-check if the intended statement was(wp t₂ (wp t₁ Q)) ⊣⊢ (wp (t₁ ∘ t₂) Q).
Assuming the statement is a typo and should be (wp t₂ (wp t₁ Q)) ⊣⊢ (wp (t₁ ∘ t₂) Q), the goal is to prove that these two hyper-assertions are equivalent, which means proving entailment in both directions.
Context
This theorem is a cornerstone of any weakest precondition calculus. It provides the rule for handling sequential composition of programs, allowing proofs about complex programs to be broken down into proofs about their constituent parts. In the context of the Bluebell project, which formalizes a probabilistic separation logic, this property is crucial for verifying programs that execute in sequence.
The proof will deeply interact with the definition of wp, which is defined for initial states of the form IndexedPSpPm.liftProb μ₀. A key challenge is that the state after the first program (t₂) runs, t₂ (liftProb μ₀), is not necessarily in this specific "lifted probability" form. Your proof will likely require a way to bridge this gap, perhaps via a more general property of wp or a specific property of the program transformers t.
Proof Suggestion
Assuming the theorem is corrected to (wp t₂ (wp t₁ Q)) ⊣⊢ (wp (t₁ ∘ t₂) Q), the proof involves two parts:
Part 1: (wp t₂ (wp t₁ Q)) ⊢ (wp (t₁ ∘ t₂) Q) (Forward direction)
- Start by unfolding the definitions. Use
unfold entails wp HyperAssertion.predorintro a h_a; unfold wp at h_a; ...to get to the core propositions. - Your hypothesis will be
a ∈ wp t₂ (wp t₁ Q). After unfolding, you'll have∀ μ₀ c, (a • c) ≤ liftProb μ₀ → ∃ b₁, (b₁ • c) ≤ t₂ (liftProb μ₀) ∧ b₁ ∈ wp t₁ Q. - Your goal is
a ∈ wp (t₁ ∘ t₂) Q, which unfolds to∀ μ₀ c, (a • c) ≤ liftProb μ₀ → ∃ b, (b • c) ≤ t₁ (t₂ (liftProb μ₀)) ∧ Q b. - After introducing
μ₀andc, apply the hypothesis to get a witnessb₁. You now haveh_inc: (b₁ • c) ≤ t₂ (liftProb μ₀)andh_wp: b₁ ∈ wp t₁ Q. - The main challenge:
h_wpis defined over initial states of the formliftProb μ'₀, but you need to reason about runningt₁on the statet₂ (liftProb μ₀). You will likely need a lemma that generalizes thewpproperty. This lemma might look like:You would need to prove this lemma first, possibly assuming monotonicity of the transformerslemma wp_generic_state (ht : monotonic t) (a : M) (m : M) (c : M) : a ∈ wp t Q → (a • c) ≤ m → ∃ b, (b • c) ≤ t m ∧ Q b := by ...
t. - Apply this hypothetical lemma with the state
m := t₂ (liftProb μ₀), the resourceb₁, and the framec. The condition(b₁ • c) ≤ mis exactly your hypothesish_inc. - The lemma will yield the existence of the final resource
bthat satisfies the goal.
Part 2: (wp (t₁ ∘ t₂) Q) ⊢ (wp t₂ (wp t₁ Q)) (Backward direction)
- Unfold definitions again. Your hypothesis
h_awill bea ∈ wp (t₁ ∘ t₂) Q. Your goal isa ∈ wp t₂ (wp t₁ Q). - After introducing
μ₀andc, your goal is to find a witnessb₂such that(b₂ • c) ≤ t₂(liftProb μ₀)andb₂ ∈ wp t₁ Q. b₂ ∈ wp t₁ Qmeans∀ μ'₀ c', (b₂ • c') ≤ liftProb μ'₀ → ∃ b', (b' • c') ≤ t₁(liftProb μ'₀) ∧ Q b'.- This direction is often more challenging because you have to construct the intermediate resource
b₂. - Let
m₁ := t₂(liftProb μ₀). The hypothesish_atells you that if you runt₁onm₁, you can get a resourcebsatisfyingQ. That is,∃ b, (b • c) ≤ t₁ m₁ ∧ Q b. - You need to construct a
b₂that "owns" enough resources to guaranteeQafter runningt₁from any compatible stateliftProb μ'₀. - A possible approach is to define
b₂as the weakest precondition fort₁andQitself. However, sincewp t₁ Qis a set of resources (HyperAssertion), you cannot simply use it as a witness. The construction is subtle and depends on the properties of your resource model (CMRA). This direction might require a deeper dive into the algebraic properties ofIndexedPSpPm.
Goal: Replace the sorry with a complete proof.
Code Snippet:
theorem wp_comp : (wp t₁ (wp t₂ Q)) ⊣⊢ (wp (t₁ ∘ t₂) Q) := by sorry