-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: simplify SimpM
recursive definitions
#3120
Conversation
|
src/Lean/Expr.lean
Outdated
loop : Nat → Expr → Array Expr → Array Expr | ||
| 0, _, as => as | ||
| i+1, .app f a, as => loop i f (as.set! i a) | ||
| _, _, as => as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will return an array with dummy entries if there aren't enough arguments, will it? Maybe worth pointing out in the docs, also on which side the dummies are? Or maybe just panic instead, its probably misuse if n
is too small?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
match n, e with | ||
| 0, _ => e | ||
| n+1, .app f _ => extractNumArgs f n | ||
| _, _ => e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused by the naming; this doesn't extract the args, but extracts the function, or strips the args, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
The new test exposes a performance problem found in software verification applications.
See new test for example that takes exponential time without new simp theorems. TODO: replace auxiliary theorems with simprocs as soon as we implement them.
The example was looping with the new `simp` reduction strategy. Here is the looping trace. ``` List.reverseAux (List.reverseAux as []) bs ==> rewrite using reverseAux_reverseAux List.reverseAux [] (List.reverseAux (List.reverseAux as []) bs) ==> unfold reverseAux List.reverseAux (List.reverseAux as []) bs ==> rewrite using reverseAux_reverseAux List.reverseAux [] (List.reverseAux (List.reverseAux as []) bs) ==> ... ```
Motivations: - We can simplify the big mutual recursion and the implementation. - We can implement the support for `match`-expressions in the `pre` method. - It is easier to define and simplify `Simprocs`.
8b2efea
to
4caa2f4
Compare
@[simp ↓] theorem ite_cond_true {_ : Decidable c} (a b : α) (h : c) : (if c then a else b) = a := by simp [h] | ||
@[simp ↓] theorem ite_cond_false {_ : Decidable c} (a b : α) (h : ¬ c) : (if c then a else b) = b := by simp [h] | ||
@[simp ↓] theorem dite_cond_true {α : Sort u} {_ : Decidable c} {t : c → α} {e : ¬ c → α} (h : c) : (dite c t e) = t h := by simp [h] | ||
@[simp ↓] theorem dite_cond_false {α : Sort u} {_ : Decidable c} {t : c → α} {e : ¬ c → α} (h : ¬ c) : (dite c t e) = e h := by simp [h] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the intended difference between these lemmas and if_pos
/if_neg
/dif_pos
/dif_neg
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment at 5b46fde
Subsumed by #3124 |
Depends on #3118.
It breaks
Std
, but it is an easy fix.