Zulip Chat Archive
Stream: general
Topic: Help needed to write laws and theorems of my PSBP library
Luc Duponcheel (Aug 10 2025 at 10:05):
Hello folks,
I have a question about how to get started with
calculational proofs of laws of my PSBP library.
Below is minimal documented code that illustrates
what I want to do.
I know that there are tactics like simp to let
Lean do the details, but I first want to write
calculational proofs myself.
All comments are welcome.
Code listing
Robin Arnez (Aug 10 2025 at 10:20):
The proof would like this:
theorem asProgram_sequential_theorem_1 {α β γ : Type}
[Monad computation] [LawfulMonad computation]
(αfβ : α → β) (βfγ : β → γ) :
(asProgram αfβ >=> asProgram βfγ :
FromComputationValuedFunction computation α γ) =
(asProgram (βfγ ∘ αfβ) :
FromComputationValuedFunction computation α γ) :=
let left : FromComputationValuedFunction computation α γ :=
asProgram αfβ >=> asProgram βfγ
let right : FromComputationValuedFunction computation α γ :=
asProgram (βfγ ∘ αfβ)
calc
left = (⟨λ α => pure $ αfβ α⟩ >=> ⟨λ β => pure $ βfγ β⟩) := rfl
_ = ⟨λ α => (pure $ αfβ α) >>= λ β => pure $ βfγ β⟩ := rfl
_ = ⟨λ α => pure $ βfγ (αfβ α)⟩ := congrArg _ <| funext fun _ => pure_bind _ _
_ = ⟨λ α => pure $ ((βfγ ∘ αfβ) α)⟩ := rfl
_ = right := rfl
Note:
[Applicative computation]
[Functional (FromComputationValuedFunction computation)]
[Sequential (FromComputationValuedFunction computation)]
can already be determined from Monad computation so you basically declare 3 instances that might be completely different from the implementations above (so you'd have to prove "this works for any exotic Functional (FromComputationValuedFunction computation) instance" which would be false).
Also, you need to specify [LawfulMonad computation] to get pure_bind. The actual application of pure_bind gets a bit more complicated then but you can basically use congrArg to go inside of the ⟨...⟩ and funext to go into the λ α => ...
Luc Duponcheel (Aug 10 2025 at 10:57):
Robin, thanks for the reply, gonna try it out asap (gonna first do some race bycicle cycling (good weather)). Of course, already knew that Monad computation implied Applicative computation. Without any [...]'s, Lean suggested me Functional (FromComputationValuedFunction computation) and I simply forgot to remove them afterwards, sorry.
Luc Duponcheel (Aug 10 2025 at 11:05):
Robin, about congrArg, and funext, ok, that was the thing I was wondering how to do. I knew about congrArg (but >=> is an operation with 2 arguments, not 1, therefore the extra underscore _ I suppose ), but I did not know about funext (and how to glue everything together).
Thanks so much, now I can start with all the laws of my PSBP library!
(but first some :cyclist:)
Cool
Robin Arnez (Aug 10 2025 at 11:16):
To be precise, it's congrArg FromComputationValuedFunction.mk _ here which turns a = b into FromComputationValuedFunction.mk a = FromComputationValuedFunction.mk b (i.e. ⟨a⟩ = ⟨b⟩) and then funext turns ∀ a, x[a] = y[a] into (λ a, x[a]) = λ a, y[a]
Last updated: Dec 20 2025 at 21:32 UTC