feat(untyped): the Leftmost Reduction Theorem#700
Conversation
|
Can you add 2 theorems :
|
|
@lengyijun Sounds good, I'll get both into a separate PR soon :) |
|
Should we rename
|
09edd8f to
6ed85b7
Compare
|
@m-ow Hi, what's your plan after this pr |
|
Honestly, no fixed plan yet, but your project sounds really interesting. Feel free to point me at what's the priority on your side, happy to take a look! |
|
We will formalize "2 vars are not enough" after this pr is merged. There will still be 1400 cases unprocessed. I haven't even studied them at all. You can randomly pick a few and research them. I will also pr my fork step by step. |
|
@m-ow Before I review for more detailed changes, I think I'm missing some high-level points about the defintions (some of which I maybe should have asked in earlier PRs, sorry!).
|
|
You're right, it's not there. The results here only rely on the inductive Standard relation, both sources I followed actually keep the sequence definition as a separate development. It's clearly worth having though, sorry for the gap! If you think it's best, I'll open a new PR to add the sequence definition and its equivalence with Standard. |
|
Yeah, it is pretty standard to use some equivalent inductive that's easier to work with (I assume this is why we have Maybe because these are so closely related they should just go in the same module? Feel free to move things around as needed. |
|
I've added the equivalence! Feel free to take another look whenever it suits you :) |
|
Is it possible to prove |
|
Sure, added. |
Yes, I'll add it! Probably together with |
chenson2018
left a comment
There was a problem hiding this comment.
A few more questions/comments about the definitions added:
| | appNoAbsL : BetaAt M M' i → ¬IsAbs M → BetaAt (app M N) (app M' N) i | ||
| /-- Reducing an abstraction operator advances the position by one. -/ | ||
| | appAbsL : BetaAt M M' i → IsAbs M → BetaAt (app M N) (app M' N) (i + 1) |
There was a problem hiding this comment.
What do you think about combining these like
| | appNoAbsL : BetaAt M M' i → ¬IsAbs M → BetaAt (app M N) (app M' N) i | |
| /-- Reducing an abstraction operator advances the position by one. -/ | |
| | appAbsL : BetaAt M M' i → IsAbs M → BetaAt (app M N) (app M' N) (i + 1) | |
| | appL : BetaAt M M' i → BetaAt (app M N) (app M' N) (i + if IsAbs M then 1 else 0) |
and similarly for the right? (Either adding a Decidable instance for IsAbs or making it boolean-valued)
There was a problem hiding this comment.
Good idea, did it. Went with Decidable IsAbs over boolean
There was a problem hiding this comment.
Marking as unresolved in light of the dependent elimination issue discussed below. I do still like it, I think we just need an additional induction principle.
| /-- The empty sequence is standard for any lower bound. -/ | ||
| | refl : StandardSeq n M M | ||
| /-- A first step at position `i ≥ n`, followed by a standard sequence bounded below by `i`. -/ | ||
| | head : BetaAt M P i → n ≤ i → StandardSeq i P N → StandardSeq n M N |
There was a problem hiding this comment.
I think it would be more intuitive for this to follow Relation.ReflTransGen and have the contructors be refl and tail (not just switching the naming, but the side you build the reduction on) and have StandardSeq.head as an additional theorem/induction principle.
There was a problem hiding this comment.
Addressed. StandardSeq now follows ReflTransGen, with refl, tail, and a derived head theorem
There was a problem hiding this comment.
How do you feel about the ergonomics of this change, since this now carries a lower bound as well? Do you think it is a useful addition?
/-- Values are irreducible terms. -/
inductive Value : Term Var → Prop
| abs (e : Term Var) : e.abs.LC → e.abs.Value
/-- `IsAbs m` holds when `m` is an abstraction. -/
@[scoped grind]
inductive IsAbs : Term Var → Prop
| abs (m : Term Var) : IsAbs (abs m)
instance (m : Term Var) : Decidable (IsAbs m) := by
cases m
case abs => exact isTrue (.abs _)
all_goals exact isFalse (by intro _; contradiction)Why put in lcat.lean ? Unrelated, strange. |
I very briefly explained why I asked for this above, but to be more explicit:
Edit: and lastly while you could place |
|
I know, the position of Value is quite strange before this pr. |
I don't understand the reasoning here. It makes sense for this definition to occur as soon as local closure is available. A single definition like this is not a detriment to the structure of the module. (Let's maybe table this discussion for later, it's gotten a bit off topic for this PR) |
|
@m-ow Could you please group the theorems ? |
|
My more aggressive opinion is to separate countredex to a new file. BTW StandardReduction.lean is the largest file in untyped lambda calculus now. |
|
Can you add theorm of fv |
|
Can you rebase on main? |
…dReduction.lean Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
|
@lengyijun Addressed everything except the free-variable theorem, which I'll handle in a follow-up PR to keep this diff smaller |
|
@m-ow @chenson2018 Unable to cases t.abs ⭢ℓ t' Expected: fall into the |
Yes, with the typing of |
|
@m-ow Can you group the theorems ? |
Thx, I got it. I should generalize 0 to variable |
Leftmost.normalization (lc : LC M) LC M is redundant |
|
Can you add 2 theorems :
|
|
Can you add this theorem as well : omit [HasFresh Var] in
lemma BetaAt.lc_l (h : BetaAt i M M') (lc : LC M') : LC M := by
induction h with
| outer lc_M lc_N => grind
| appL _ ih =>
cases lc with
| app lc_L lc_R => exact .app (ih lc_L) lc_R
| appR _ ih =>
cases lc with
| app lc_L lc_R => exact .app lc_L (ih lc_R)
| abs xs _ ih =>
cases lc with
| abs ys _ h_body =>
apply LC.abs (xs ∪ ys)
intro z hz
exact ih z (by grind) (h_body z (by grind)) |
|
@m-ow Lc is redundant : |
Introduces leftmost reduction
⭢ℓ, a beta-step contracting the redex at position 0, together with normal forms, and proves the Leftmost Reduction Theorem: if a term beta-reduces to a normal form, the leftmost strategy reaches it too.The result falls out of standardization, following Copes (2018).
Builds on top of #679