Zulip Chat Archive

Stream: general

Topic: Still don't understand simp


Kevin Buzzard (Jul 27 2018 at 20:55):

I still don't understand simp. I tried

example (c : ) (H : 0 + 0 + c = 0) : c = 0 := by simp [H]

fully expecting it to work, and it didn't. So I switched to by simp at H;assumption which works fine -- but I feel like I'm missing a trick. What is the correct way to solve this goal? I know I could prove it using zero_add a couple of times -- is best practice to spell out the proof in full or use automation?

Kevin Buzzard (Jul 27 2018 at 20:57):

The moment I try zero_add in term mode I find myself in triangle hell.

Chris Hughes (Jul 27 2018 at 20:58):

simpa using h

Chris Hughes (Jul 27 2018 at 20:58):

simp * at *

Kevin Buzzard (Jul 27 2018 at 21:05):

simpa using h

Do I need an import for this?

Mario Carneiro (Jul 27 2018 at 21:17):

just the usual

Kevin Buzzard (Jul 27 2018 at 21:30):

That's happening to me more and more. Is there any way I can import every mathlib tactic automatically?

Mario Carneiro (Jul 27 2018 at 21:31):

import tactic.interactive gets the main tactics, but advanced tactics have their own imports, in particular ring and finish

Kevin Buzzard (Jul 27 2018 at 21:31):

Is there any reason I shouldn't import ring always?

Mario Carneiro (Jul 27 2018 at 21:31):

if you don't need it, don't import it

Mario Carneiro (Jul 27 2018 at 21:31):

and you shouldn't overuse it anyway, it's slow

Kevin Buzzard (Jul 27 2018 at 21:31):

if you don't need it, don't import it

Why not? If I don't use it, it doesn't even matter

Mario Carneiro (Jul 27 2018 at 21:32):

it adds a spurious dependency, which is probably a bigger problem for me than for you

Mario Carneiro (Jul 27 2018 at 21:33):

Of course, adding additional dependencies also slows down startup and recompile times

Kevin Buzzard (Jul 27 2018 at 21:33):

Even if I never use them?

Kevin Buzzard (Jul 27 2018 at 21:34):

They're compiled on sight?

Mario Carneiro (Jul 27 2018 at 21:34):

of course, how would it know if you have used the file unless it compiles the dependency?

Mario Carneiro (Jul 27 2018 at 21:34):

the way you are supposed to signal what you depend on is in your import list

Kevin Buzzard (Jul 27 2018 at 21:35):

How about I don't import it, and every time I use it a little pop-up appears saying "I see you're using ring. Do you want to import tactic.ring?"

Mario Carneiro (Jul 27 2018 at 21:35):

how would it know that ring exists?

Kevin Buzzard (Jul 27 2018 at 21:35):

and same for simpa and tactic.interactive

Kevin Buzzard (Jul 27 2018 at 21:35):

how would it know that ring exists?

Because I just tell it, using a "snippet" or something?

Kevin Buzzard (Jul 27 2018 at 21:36):

"I see that you just deleted the last occurrence of simpa. Do you want me to unimport it again?"

Kevin Buzzard (Jul 27 2018 at 21:36):

"I see that you used simp. Do you want me to replace that argument with what Lean actually did?"

Mario Carneiro (Jul 27 2018 at 21:36):

hm, I suppose one option is to somehow generate an "index" of all definitions in mathlib and their locations, and then store this info in some file with no dependencies and use it for hints

Mario Carneiro (Jul 27 2018 at 21:37):

Import analysis like that is very expensive

Kevin Buzzard (Jul 27 2018 at 21:37):

I'm basically asking for some sort of tactic manager I think.

Kevin Buzzard (Jul 27 2018 at 21:37):

I just have no idea about what is possible.

Kevin Buzzard (Jul 27 2018 at 21:39):

Does simpa !? only? (* | [(* | (- id | expr)), ...]?) (with id*)? (using expr)? tactic.simp_config_ext? actually mean something? Where can I learn about what it means?

Mario Carneiro (Jul 27 2018 at 21:39):

It is hard to get the analysis exactly right without just recompiling the current file, and if it's not exactly right then there is the possibility of incorrect hints, which will get old fast

Mario Carneiro (Jul 27 2018 at 21:39):

yes, it's a description of the parsing of arguments following simpa

Kevin Buzzard (Jul 27 2018 at 21:40):

I want it to be a regex but I can't make sense of it

Mario Carneiro (Jul 27 2018 at 21:40):

Basically ? means that the previous thing may or may not be present, and * means zero or more of the previous thing

Sebastian Ullrich (Jul 27 2018 at 21:40):

It's a pseudorex

Kevin Buzzard (Jul 27 2018 at 21:40):

oh is it just a regex but using stuff I don't know?

Kevin Buzzard (Jul 27 2018 at 21:41):

Aah thanks!

Mario Carneiro (Jul 27 2018 at 21:41):

| means alternatives

Mario Carneiro (Jul 27 2018 at 21:41):

i.e. a | b means parse a or parse b

Kevin Buzzard (Jul 27 2018 at 21:42):

and expr is some kind of variable? Or you want something of type expr?

Mario Carneiro (Jul 27 2018 at 21:42):

expr means parse an expression

Mario Carneiro (Jul 27 2018 at 21:42):

and id means parse an identifier

Kevin Buzzard (Jul 27 2018 at 21:42):

I thought that h was a name in simpa using h, not an expr

Mario Carneiro (Jul 27 2018 at 21:43):

nope, look for simpa using show in mathlib and you will find several larger examples

Mario Carneiro (Jul 27 2018 at 21:43):

it's a nice way to say "use this term, but clean it up first"

Kevin Buzzard (Jul 27 2018 at 21:44):

so what's with?

Kevin Buzzard (Jul 27 2018 at 21:44):

I just apply these things at random usually.

Mario Carneiro (Jul 27 2018 at 21:44):

most of the args are just passed to simp as is

Kevin Buzzard (Jul 27 2018 at 21:44):

I have a list of "incantations formed with simp or simpa which have worked for me in the past"

Mario Carneiro (Jul 27 2018 at 21:44):

that includes ! and with

Mario Carneiro (Jul 27 2018 at 21:45):

the with arg of simp allows you to simplify with custom simp sets, like functor_norm

Mario Carneiro (Jul 27 2018 at 21:45):

I don't use it much at all

Kevin Buzzard (Jul 27 2018 at 21:46):

What does simpa [this] do? Does that not even parse?

Chris Hughes (Jul 27 2018 at 21:47):

The same as simp [this], assumption

Kevin Buzzard (Jul 27 2018 at 21:49):

example (c : ) (H : 0 + 0 + c = 0) : c = 0 := by simpa -- fails
example (c : ) : 0 + 0 + c = 0  c = 0 := by simpa -- works

If you'd told me one works and one failed I would have guessed the other way around.

Chris Hughes (Jul 27 2018 at 21:50):

The second one is simplified to c=0 -> c=0. The first one doesn't simplify H

Kevin Buzzard (Jul 27 2018 at 21:51):

example : ∀ (y : ℕ), (λ (c : ℕ), 0 + 0 + c = 0) y → y = 0 := by simp

Kevin Buzzard (Jul 27 2018 at 21:52):

I wouldn't have dreamed of applying simp to that because it's not an equality. Am I using simp completely wrong?

Mario Carneiro (Jul 27 2018 at 21:52):

Actually simpa [this] is a bit funny - it's more like have this' := this, simp [this] at this', simp [this], exact this'

Mario Carneiro (Jul 27 2018 at 21:53):

for the first example you want by simpa using H

Mario Carneiro (Jul 27 2018 at 21:54):

The using argument of simpa is pretty important. It's not really optional, it just has a default value of this

Mario Carneiro (Jul 27 2018 at 21:54):

so by simpa where there is no this in the context is kind of pointless

Chris Hughes (Jul 27 2018 at 21:54):

One nice feature of simp I discovered today, is it doesn't let you make horrible simp lemma. I tried to prove forall x : zmod 2, x = -x and it didn't let me make it simp

Kevin Buzzard (Jul 27 2018 at 21:55):

If you try it again you might get banned

Kevin Buzzard (Jul 27 2018 at 21:55):

"no more simp for you for a week"

Mario Carneiro (Jul 27 2018 at 21:56):

your use of simp to prove that is valid but a bit funny and doesn't generalize well

Mario Carneiro (Jul 27 2018 at 21:57):

I would do intros y H; simpa using H

Mario Carneiro (Jul 27 2018 at 21:57):

simp {contextual := tt} often works in these situations, but I don't think it simplifies the assumptions first


Last updated: Dec 20 2023 at 11:08 UTC