Zulip Chat Archive

Stream: mathlib4

Topic: squeeze_simp and simp?


Arthur Paulino (Mar 14 2022 at 21:00):

I'd like to kickoff this discussion regarding squeeze_simp and simp?. Some progress has been made on #5901.

It's been proposed that simp? could eventually replace squeeze_simp. I like that idea because simp? is shorter and the interrogation mark makes for a good pattern of extracting data from tactics. Also, with Lean 4, simp? would stand as a syntax of its own (it wouldn't necessarily trigger the implementation of simp with a parameter indicating the interrogation mark), so we don't need to change the implementation of simp to accommodate the ?.

Another point mentioned was that squeeze_simp seems to nail some simplifications that simp? doesn't. Are there things that simp? does which squeeze_simp can't? Or is it the case that the Lean 3 behavior of simp? can simply be dropped?

Ruben Van de Velde (Mar 14 2022 at 21:25):

I think the only feature of simp? I've cared about is that it's much faster than squeeze_simp - all behavioural differences I've seen were bugs

Mario Carneiro (Mar 14 2022 at 22:09):

There is no need for these to be separate tactics. The difference is entirely historical and they have the same spec

Arthur Paulino (Mar 14 2022 at 22:17):

Mario Carneiro said:

they have the same spec

Do you mean they're supposed to have the same behavior?

Mario Carneiro (Mar 14 2022 at 22:17):

yes

Mario Carneiro (Mar 14 2022 at 22:18):

that is, if you are asked "what does simp? do" or "what does squeeze_simp do" then the answer is the same

Mario Carneiro (Mar 14 2022 at 22:19):

simp? is the better name according to our general patterns for tactic naming

Arthur Paulino (Mar 14 2022 at 22:20):

Why is simp? faster (according to @Ruben Van de Velde)?

Mario Carneiro (Mar 14 2022 at 22:20):

because squeeze_simp just runs simp with every subset of arguments to see which work

Mario Carneiro (Mar 14 2022 at 22:21):

simp? is implemented in C++ and instruments simp to report what lemmas it used

Mario Carneiro (Mar 14 2022 at 22:22):

That is definitely the correct implementation strategy, but it has some false negative issues so it can sometimes produce incorrect calls, while squeeze_simp is relying on the observational behavior of simp [lemmas, ...] so it is always correct

Mario Carneiro (Mar 14 2022 at 22:23):

I think both of them have trouble with re-printing the input terms though

Arthur Paulino (Mar 14 2022 at 22:32):

I didn't understand how false negatives would cause incorrect calls. Wouldn't it make the tactic give up when it's actually possible to find a simplification?

Arthur Paulino (Mar 14 2022 at 22:45):

Mario Carneiro said:

That is definitely the correct implementation strategy

Do you mean this for Lean/mathlib 4 as well? Is Lean 4's simp implemented in C++?

Mario Carneiro (Mar 14 2022 at 22:47):

simp? can fail to report that a lemma was used even though it did have an influence on the proof

Mario Carneiro (Mar 14 2022 at 22:48):

Yes, I mean that lean 4 simp? should watch simp to report used lemmas, but without the bugs

Mario Carneiro (Mar 14 2022 at 22:48):

Lean 4 simp is not implemented in C++, it is in lean like most tactics

Arthur Paulino (Mar 14 2022 at 22:51):

Got it. Is it currently easy to query what simp used in Lean 4?

Eric Rodriguez (Mar 14 2022 at 23:01):

Mario Carneiro said:

I think both of them have trouble with re-printing the input terms though

Me and Arthur fixed this for squeeze_simp in lean3 j think, not sure how well roundtripping works in lean4

Mario Carneiro (Mar 14 2022 at 23:03):

Arthur Paulino said:

Got it. Is it currently easy to query what simp used in Lean 4?

Maybe, maybe not, but you can always copy and paste enough of the internal implementation until you have access to the relevant data

Arthur Paulino (Mar 15 2022 at 00:08):

@Eric Rodriguez I believe we will need the workaround for dealing with namespaces again

Arthur Paulino (Mar 15 2022 at 00:15):

@Mario Carneiro when you said that squeeze_simp runs every subset of arguments you didn't mean iterating on the entire power set, right?

Arthur Paulino (Mar 15 2022 at 00:17):

Were you talking about that linear process of argument elimination that stops when the result of tactic application changes? (I'm not on PC so I can't search code right now)

Mario Carneiro (Mar 15 2022 at 00:20):

It's finding a minimal working subset, assuming that simp is monotonic wrt its arguments

Arthur Paulino (Mar 15 2022 at 00:21):

I see. I know exactly the function you're referring to

Mario Carneiro (Mar 15 2022 at 00:21):

which is linear time (or rather O(n) times the performance of simp itself)

Mario Carneiro (Mar 15 2022 at 00:21):

hence squeeze_simp will usually be O(n) times slower than simp?

Arthur Paulino (Mar 15 2022 at 00:26):

Should we aim for minimality with simp? in mathlib4?

Arthur Paulino (Mar 15 2022 at 00:32):

(should I be worried that simp might be slower in Lean 4 than in Lean 3?)

Eric Rodriguez (Mar 15 2022 at 00:35):

that should really not be the case ever at all

Mario Carneiro (Mar 15 2022 at 00:50):

Arthur Paulino said:

Should we aim for minimality with simp? in mathlib4?

Minimality is not usually a target goal of tactics. I wouldn't say that there are any upper complexity limits except that a tactic that is too complex can be hard to maintain and/or slow, but it's not a big deal if you write a small tactic to begin with and we refine it later

Arthur Paulino (Mar 15 2022 at 02:06):

Eric Rodriguez said:

that should really not be the case ever at all

simp is implemented in Lean 4 itself in Lean 4 and in C++ in Lean 3 so it's plausible

Mario Carneiro (Mar 15 2022 at 02:20):

simp has a more efficient implementation in lean 4 than lean 3, in particular because of its discrimination tree indexing

Arthur Paulino (Mar 15 2022 at 12:09):

By reading simp's code I'm starting to think that it would be better to have it equipped with a way to report the theorems it used otherwise we will end up with a lot of duplicated code. What do you guys think? The code base is not very short

Arthur Paulino (Mar 15 2022 at 12:09):

(maybe simp? is not a good tactic to port at the moment)

Kevin Buzzard (Mar 15 2022 at 17:58):

I guess simp? is not used at all in mathlib...

Arthur Paulino (Mar 15 2022 at 18:01):

Kevin Buzzard said:

I guess simp? is not used at all in mathlib...

I meant simp? as a tactic with the same behavior of squeeze_simp (to catch up)

Kevin Buzzard (Mar 15 2022 at 18:30):

Sure, and I'm pointing out that whilst of course we use it to write new mathlib, the simp? tactic (or variant or whatever it is) itself is not used at all in mathlib master, so if the main goal here is to get mathlib ported then maybe it can wait for a while?


Last updated: Dec 20 2023 at 11:08 UTC