Zulip Chat Archive

Stream: general

Topic: squeeze_simp


Johan Commelin (Oct 08 2018 at 13:01):

@Simon Hudon To what extend do you think sed and lean could cooperate to automatically turn every simp into a squeeze_simp, and then every squeeze_simp into a simp only? Can we automate Kenny?

Simon Hudon (Oct 08 2018 at 14:18):

But we like Kenny!

Simon Hudon (Oct 08 2018 at 14:20):

I was thinking along those lines but I was thinking of adding a feature to the emacs Lean mode. I'm not how I would do it for VS code though. Do you know how to script it?

Johan Commelin (Oct 08 2018 at 14:20):

I don't know anything about VScode

Johan Commelin (Oct 08 2018 at 14:20):

But couldn't this just be a CLI-only thing?

Johan Commelin (Oct 08 2018 at 14:21):

For other purposes the output of squeeze_simp is already very useful.

Patrick Massot (Oct 08 2018 at 14:21):

Can't we use a hole command here again?

Mario Carneiro (Oct 08 2018 at 14:21):

you still have to click on a hole command

Johan Commelin (Oct 08 2018 at 14:22):

Exactly

Mario Carneiro (Oct 08 2018 at 14:22):

indeed, you have to manually edit the file to put a hole in in the first place

Johan Commelin (Oct 08 2018 at 14:22):

I want sed to "click" on the hole command.

Patrick Massot (Oct 08 2018 at 14:22):

Oh you mean you want this for batch processing?

Simon Hudon (Oct 08 2018 at 14:22):

The difficult thing about using something like sed is detecting the end of the input squeeze_simp

Simon Hudon (Oct 08 2018 at 14:22):

But I guess we could output it in Lean

Simon Hudon (Oct 08 2018 at 14:23):

@Patrick Massot exactly

Patrick Massot (Oct 08 2018 at 14:23):

Sorry I read too quickly the beginning of this thread (I'm fighting dependent rw)

Simon Hudon (Oct 08 2018 at 14:41):

@Mario Carneiro has shown us how useful awk can be in these situations. Do you think if we output the beginning line and column number of the input, the ending line and column number of the input and the replacement, we can get awk to go in there and do the replacement? You'd probably also have to go from the last to the first if you want to do it in one go so that the line numbers don't get invalidated.

Johan Commelin (Oct 08 2018 at 14:45):

Sure, that should definitely be possible

Johan Commelin (Oct 08 2018 at 14:45):

I guess squeeze_simp can get access to its location in the file via some tactic_state magic, right?

Johan Commelin (Oct 08 2018 at 14:46):

Or you make squeeze_simp output a patch (-;

Johan Commelin (Oct 08 2018 at 14:46):

Then we can just commit it, and git takes care of the rest :lol:

Simon Hudon (Oct 08 2018 at 16:08):

I just looked into the patch file format. It seems like more work to format than to just do it ourselves

Johan Commelin (Oct 08 2018 at 16:20):

Ok, so how about your suggestion, with line+col numbers

Simon Hudon (Oct 08 2018 at 16:40):

I think the best bet is to use awk but I'll have to learn it

Simon Hudon (Oct 08 2018 at 16:41):

Right now I'm experimenting with emacs to see if I can get a nice first approximation

Johan Commelin (Oct 08 2018 at 16:47):

awk is not hard. Also, I wouldn't mind helping you.

Johan Commelin (Oct 08 2018 at 16:48):

We could use sed to squeeze_simpify a .lean file. After that, we run lean --make on the file, and capture the stdout.

Johan Commelin (Oct 08 2018 at 16:48):

If squeeze_simp can produce output of the form line:column:replacement_text I think we can take it from there.

Simon Hudon (Oct 08 2018 at 16:52):

I was thinking of a format like this:

84:23:
86:0:
--- BEGIN ---
simp only [perm_cons, multiset.cons_coe, iff_self, multiset.coe_eq_coe, multiset.quot_mk_to_coe'']
--- END ---

Johan Commelin (Oct 08 2018 at 16:53):

unix prefers to keep everything on 1 line.

Simon Hudon (Oct 08 2018 at 16:54):

In that case, how about line0:col0:line1:col1:replacement_text?

Johan Commelin (Oct 08 2018 at 16:56):

Looks good

Johan Commelin (Oct 08 2018 at 16:56):

Unless we want to anticipate multiline replacement texts

Simon Hudon (Oct 08 2018 at 16:59):

That's what I'm looking at now. The replacement is sometimes multiline but there's no real reason to be. I'll restrict it to one line and let the user reformat if needed

Johan Commelin (Oct 08 2018 at 16:59):

There is no "user" if we run this in batch mode over 25 files.

Johan Commelin (Oct 08 2018 at 17:00):

But we can write a smart awk script

Johan Commelin (Oct 08 2018 at 17:00):

It can try to reformat that line, breaking on suitable ,

Simon Hudon (Oct 08 2018 at 17:03):

That's tricky because it might not be alone on its line

Johan Commelin (Oct 08 2018 at 17:05):

I can compute the old line length, and the new one, etc...

Johan Commelin (Oct 08 2018 at 17:05):

It definitely makes a trivial thing a lot harder

Simon Hudon (Oct 08 2018 at 17:07):

Let's leave it for the "future work" section

Simon Hudon (Oct 08 2018 at 17:08):

It might become necessary to have a Lean code formatter which would make all of that good work redundant

Johan Commelin (Oct 08 2018 at 17:08):

Yep, sounds good

Simon Hudon (Oct 08 2018 at 17:10):

This proof engineering stuff is so funny. We're tweaking eternal truths :P

Simon Hudon (Oct 08 2018 at 17:11):

As impatient as I get with Lean and mathlib, it's pretty great that it finds my mistakes faster than my supervisor :D

Bryan Gin-ge Chen (Oct 08 2018 at 17:15):

Are there other "tactics with output" where this kind of tooling would also be useful? Maybe tidy?

Mario Carneiro (Oct 08 2018 at 17:16):

tidy already makes output

Johan Commelin (Oct 08 2018 at 17:16):

I'll be reading a bit of Milne to my kids... see you guys soon!

Simon Hudon (Oct 08 2018 at 17:17):

Have fun!

Bryan Gin-ge Chen (Oct 08 2018 at 17:18):

Indeed, what I mean is the output format being discussed here something we should also consider for e.g. tidy?

Simon Hudon (Oct 08 2018 at 17:21):

That could be useful. It might be more useful for tidy to have it tied into the IDE because you probably don't use tidyen masse

Gabriel Ebner (Oct 08 2018 at 17:27):

Where are you printing the replacement text? Trace messages?

Simon Hudon (Oct 08 2018 at 17:28):

Yes exactly

Gabriel Ebner (Oct 08 2018 at 17:32):

It's pretty easy to hook them up in vscode: in the extension, you just need to return a list of code actions. Then you can execute these replacements with ctrl+. (similar to holes, which are also implemented using code actions in the extension).

Simon Hudon (Oct 08 2018 at 17:34):

Emacs gives the line and column of the command issuing the trace. Does VS code also do the same?

Gabriel Ebner (Oct 08 2018 at 17:34):

A few suggestions for the format: it should not occur by accident (in a simp trace e.g.). And it would be nice to have a (textual) description for the replacement (vscode shows this in the dropdown). Ideally also the kind of code action, e.g. vscode can apply all quickfixes in a given file automatically.

Gabriel Ebner (Oct 08 2018 at 17:35):

We have access to the same position information, yes. However it only includes the start position of the tactic unfortunately.

Simon Hudon (Oct 08 2018 at 17:35):

Does it run them backward so that the line numbers remain valid?

Gabriel Ebner (Oct 08 2018 at 17:36):

Good question. I don't really know. If we do one-line replacements then it shouldn't matter too much.

Simon Hudon (Oct 08 2018 at 17:36):

In the parser cur_pos can give me an arbitrary position. I'm putting it at the end and it gives me a good approximation

Mario Carneiro (Oct 08 2018 at 17:36):

Ooh, this is nice. Can we just get a generic hook for writing things from lean?

Sebastien Gouezel (Mar 10 2019 at 22:17):

I got a strange squeeze_simp behavior, where the trace output does not has the same effect as the original one. The example is as follows (in a complete lattice):

theorem Inf_sup_Inf : Inf s  Inf t = Inf ((λp : α × α, p.1  p.2) '' (set.prod s t)) :=
begin
  apply le_antisymm,
  { squeeze_simp,
    sorry },
  { sorry }
end

After squeeze_simp, the goal is

 (b x x_1 : α), x  s  x_1  t  x  x_1 = b  Inf s  b  Inf t  b

But if I copy the trace formula (hey, I never noticed that it looks like real math:) given by squeeze_simp, i.e.,

simp only [and_imp, set.mem_image, set.mem_prod, lattice.le_Inf_iff,
               exists_imp_distrib, lattice.sup_le_iff, prod.exists],

then I get the double goal

( (b x x_1 : α), x  s  x_1  t  x  x_1 = b  Inf s  b) 
     (b x x_1 : α), x  s  x_1  t  x  x_1 = b  Inf t  b

Any idea for the reason of this behavior?

Simon Hudon (Mar 10 2019 at 22:19):

Can you open an issue and put up a MWE? I'll look into it.

Sebastien Gouezel (Mar 10 2019 at 22:27):

Done.

Simon Hudon (Mar 10 2019 at 23:29):

If you remove lattice.sup_le_iff from the list, you get the same effect as not having simp only. I don't get why squeeze_simp suggests it. I'll keep working on it

Mario Carneiro (Mar 10 2019 at 23:35):

I'm not sure it is worth trying for 100% fidelity in translating squeeze_simp to an appropriate simp only. The commands are complicated and almost nondeterministic, so I'm not at all surprised that there are edge cases where it doesn't work, and also suggested rewrites that don't need to be in the rewrite list. You should take the output of squeeze_simp as a base for revision rather than an actual reliable representation of what was used.


Last updated: Dec 20 2023 at 11:08 UTC