Zulip Chat Archive
Stream: general
Topic: behaviour of simp in Lean vs Coq
Arthur Paulino (Oct 21 2021 at 12:43):
Johan Commelin said:
Arthur Paulino
simp
already exists, and is used a lot.
Hm, shouldn't I see true = true
in the Lean Infoview here?
image.png
I tested simp
but it didn't seem to do anything. And it doesn't show anything on hover. Also I can't crtl+click on it :thinking:
Eric Wieser (Oct 21 2021 at 12:44):
Using ;
makes the goal view behave unhelpfully (at least in Lean 3, but it seems you're using Lean 4)
Sebastian Ullrich (Oct 21 2021 at 12:45):
Please note that this is Lean 4
Yaël Dillies (Oct 21 2021 at 12:46):
Johan Commelin said:
All my colleagues work with things like Kähler manifolds, or triangulated categories of motives.
Do you know we have a branch trying to define Kähler manifolds?
Arthur Paulino (Oct 21 2021 at 12:46):
You mean it behaves as expected in Lean 3?
Sebastian Ullrich (Oct 21 2021 at 12:49):
No, simp
here behaves as expected. It applies all registered and explicitly passed equations, none of which are applicable here. Use @[simp] def orr
or simp [orr]
to add orr
's equations to either set.
Sebastian Ullrich (Oct 21 2021 at 12:49):
Coq-Equations' simp
also needs to be passed explicit arguments, doesn't it?
Yaël Dillies (Oct 21 2021 at 12:50):
Ahah! @Johan Commelin, not Kähler manifolds but Kähler modules: it's #4753.
Johan Commelin (Oct 21 2021 at 12:51):
Ooh, I know that one. It's important, but quite different from Kähler manifolds (-;
Arthur Paulino (Oct 21 2021 at 12:52):
In Coq you can just call simpl.
:
image.png
Johan Commelin (Oct 21 2021 at 12:53):
(I've renamed this tail of the thread, because it was going in a different direction.)
Sebastian Ullrich (Oct 21 2021 at 12:55):
Ah, that is yet another Coq tactic. We don't have a normalization tactic like that. It seems most people prefer passing the defs to reduce explicitly.
Arthur Paulino (Oct 21 2021 at 12:56):
simp [orr]
did the simplification and Lean was already satisfied with true = true
image.png
Arthur Paulino (Oct 21 2021 at 12:57):
maybe it simplified true = true
further to true
?
Sebastian Ullrich (Oct 21 2021 at 12:57):
to True
, but yes :)
Sebastian Ullrich (Oct 21 2021 at 12:57):
In other words, Lean's simp
is modelled after Isabelle, not Coq
Arthur Paulino (Oct 21 2021 at 12:58):
I see, but now it got me thinking because I asked Lean to explicitly simplify the orr
and it feels like it did more than I wanted
Yaël Dillies (Oct 21 2021 at 12:59):
That's why you can use simp only [orr]
.
Arthur Paulino (Oct 21 2021 at 13:00):
simp only [orr]
goes all the way down too
Eric Wieser (Oct 21 2021 at 13:07):
That's because one of the equation lemmas for "orr" is precisely your goal
Eric Wieser (Oct 21 2021 at 13:08):
If you're trying to prove a = b
and you have h : a = b
, you wouldn't say "rewrite to b = b
, then reflexivity", you'd jump directly to "h is the proof"
Mario Carneiro (Oct 21 2021 at 13:10):
Sebastian Ullrich said:
Ah, that is yet another Coq tactic. We don't have a normalization tactic like that. It seems most people prefer passing the defs to reduce explicitly.
It would be really really nice to get a reduction tactic in lean. simp
is the best we have but it's a poor approximation of kernel reduction. whnf
can be made to work but is not configurable, and often goes too far.
Mario Carneiro (Oct 21 2021 at 13:11):
And yes, there are a lot of open design questions about how far to reduce given what input
Arthur Paulino (Oct 21 2021 at 13:12):
From an user standpoint, I'd want it to go as far as I want so I feel like I have complete control of what I'm doing
Mario Carneiro (Oct 21 2021 at 13:13):
I'd want it to go as far as I want
well yes, the hard part is reading the user's mind about this
Mario Carneiro (Oct 21 2021 at 13:13):
you can reduce too much and you can reduce not enough and both are bad
Mario Carneiro (Oct 21 2021 at 13:14):
simp
has some control over reduction in the form of specifying what functions to reduce (plus some basic simp things like x = x
is true)
Arthur Paulino (Oct 21 2021 at 13:15):
Hm, what if I could tell the number of reduction rounds? Lean would be able to know how many recursive calls would be allowed
Mario Carneiro (Oct 21 2021 at 13:15):
I think there is a cfg for that
Mario Carneiro (Oct 21 2021 at 13:16):
but it's really not a good way to write proof scripts because it is very specific to the particular rewrite sequence
Mario Carneiro (Oct 21 2021 at 13:17):
and if it has to backtrack then it gets much harder to specify where in the tree you want to go
Arthur Paulino (Oct 21 2021 at 13:17):
Right, I might want to take baby steps for a particularly hard step
Mario Carneiro (Oct 21 2021 at 13:17):
rw
is better suited for baby steps. simp
is more like "do all these things until you can't find anything to do"
Arthur Paulino (Oct 21 2021 at 13:18):
let me try rw
Arthur Paulino (Oct 21 2021 at 13:22):
How do I make rw
accept one of my matches for orr
?
image.png
Mario Carneiro (Oct 21 2021 at 13:27):
rw [orr]
Mario Carneiro (Oct 21 2021 at 13:28):
also, post code, not images
Mario Carneiro (Oct 21 2021 at 13:28):
see #backticks
Arthur Paulino (Oct 21 2021 at 13:29):
ah, the code itself doesn't show where the error lies. but now orr
is underlined in red and the error says
tactic 'rewrite' failed, equality or iff proof expected
Bool
b : Bool
⊢ orr true b = true
Mario Carneiro (Oct 21 2021 at 13:30):
this will work in lean 3, but I think lean 4 doesn't support it yet and you have to make do with simp
Mario Carneiro (Oct 21 2021 at 13:30):
There are some settings you can give to simp to make it act basically like rw
, this is the simp_rw
tactic in lean 3
Mario Carneiro (Oct 21 2021 at 13:31):
eh, could you post your code?
Arthur Paulino (Oct 21 2021 at 13:32):
def orr : Bool → Bool → Bool
| true, _ => true
| false, b => b
theorem orr_true (b : Bool) : orr true b = true := by
{rw [orr]}
Arthur Paulino (Oct 21 2021 at 13:35):
I'm satisfied if it's because it's still WIP tho, no worries :smiley:
Yaël Dillies (Oct 21 2021 at 13:36):
rfl
does it :wink:
Arthur Paulino (Oct 21 2021 at 13:39):
Oh, I know. I'm not just trying to prove the theorem. I'm trying to do it in a controlled way. Going directly to reflexivity might be a big leap for people who are trying to understand how computers handle programmed proofs
Mario Carneiro (Oct 21 2021 at 13:41):
Oh, it looks like you can't turn off eq_self
, even if you use simp only
. There should probably be a config option for that
Mario Carneiro (Oct 21 2021 at 13:44):
lean 3 has a whole collection of more controlled unfolding tactics, like dsimp
, unfold
, delta
and others. As far as I know most of them don't exist in lean 4 yet
Mario Carneiro (Oct 21 2021 at 13:45):
and some of them might be "won't fix" since the number of unfolding tactics in lean 3 is a little ridiculous
Mario Carneiro (Oct 21 2021 at 13:48):
One way to prevent it from closing the goal is to change the rhs to something less trivial:
theorem orr_true (b : Bool) : orr true b = c := by
simp only [orr]
-- |- true = c
Arthur Paulino (Oct 21 2021 at 13:49):
Makes sense. Let's see how the API design will evolve. For me it was very impactful to my learning process to see how Coq processed everything until it ends up with types I defined on both ends of the equation
Mario Carneiro (Oct 21 2021 at 14:01):
well, API design doesn't evolve on its own, it needs input from people "in the field" to see what works. Generally things don't change unless someone (usually one of the developers) runs across a paper cut and tries to fix it
Arthur Paulino (Oct 21 2021 at 14:06):
Right, that's what I meant :smiley:
Arthur Paulino (Oct 21 2021 at 14:22):
But just to rephrase what I meant before. It would make more sense to me for simp
to go all the way until it can't progress if it didn't accept parameters. But if I have to explicit the orr
as a parameter, I would expect it to be more surgical on what to simplify.
Mario Carneiro (Oct 21 2021 at 14:34):
it is being surgical; it is just that your definition of surgical doesn't include reflexivity and simp's does
Mario Carneiro (Oct 21 2021 at 14:39):
also, keep in mind that simp only
is not only for teaching; mathlib uses it a lot, because the default simp set is expensive in many circumstances, and adding eq_self
all the time for proofs of e.g. (x + y) + z = x + (z + y)
by simp only [add_comm, add_assoc]
would get tiresome
Arthur Paulino (Oct 21 2021 at 15:23):
Mario Carneiro said:
it is being surgical; it is just that your definition of surgical doesn't include reflexivity and simp's does
Thanks for the clarification. That's precisely it. You were surgical :smiley:
Last updated: Dec 20 2023 at 11:08 UTC