Zulip Chat Archive

Stream: mathlib4

Topic: missing tactic port


Arien Malec (Nov 16 2022 at 17:21):

I have a ported file that depends on a local tactic with a meta

meta def rbtree.default_lt : tactic unit :=
`[apply has_lt.lt]

used like this: (lt : α → α → Prop . rbtree.default_lt)

What's the Lean4 approach for a default parameter value?

Arien Malec (Nov 16 2022 at 19:18):

So, digging, it looks like has_lt is now spelled LT but subbing the seeming equivalent statement lt : α → α → Prop := by apply LT.lt gets invalid auto tactic

Arien Malec (Nov 16 2022 at 19:41):

I'm just not sure if the goal is for the the comparator to be pluggable, or if the goal is to implicitly constrain α to be of class LT?

Arien Malec (Nov 16 2022 at 20:05):

Or maybe the goal is: if I have an lt, use that, otherwise require the α to be of typeclass LT and use the native lt?

Scott Morrison (Nov 16 2022 at 22:33):

This tactic is only used to supply an auto_param. In Lean 4, you can use tactics in the default value, instead of using an autoparam.

Scott Morrison (Nov 16 2022 at 22:34):

i.e. replace . rbtree.default_lt in the structure definition with := by apply LT.lt?

Scott Morrison (Nov 16 2022 at 22:34):

Oh, hmm, you tried that. What's your branch?

Arien Malec (Nov 16 2022 at 22:44):

PR mathlib4#611, arienmalec/port_rbtree_init

Jireh Loreaux (Nov 16 2022 at 22:45):

@Arien Malec : that's mathlib4#611, not #611

Arien Malec (Nov 16 2022 at 22:47):

Gotcha -- Zulip defaults to mathlib PRs..

Jireh Loreaux (Nov 16 2022 at 22:49):

For now, yes. If you look in the "Organization Settings" menu you can see how the various linkifiers are expanded.

Kevin Buzzard (Nov 16 2022 at 22:59):

More details:

def RBTree (α : Type u)
    (lt : α  α  Prop := by apply LT.lt) :
    Type u :=
  { t : RBNode α // t.WellFormed lt }

(in file Mathlib.Data.RBTree.Init on the branch above) gives error invalid auto tactic, identifier is not allowed on LT.lt

Arien Malec (Nov 16 2022 at 23:35):

@Ruben Van de Velde notes that Std has an RBMap so probably the call here is to deprecate RBTree and unwind the dependencies in the port. (The RBMap implementation punts on the fancy autoparam stuff, and just has you pass a comparator...

Arien Malec (Nov 16 2022 at 23:39):

From what I could see, the dependencies in mathlib are through data.tree, and all data.tree does is allow conversion from an rbtree

Arien Malec (Nov 16 2022 at 23:41):

It also blocks data.list.defsbut all that's done there is convert to an rbtree

Arien Malec (Nov 16 2022 at 23:53):

Also used in ring2 which is separately ported.

Scott Morrison (Nov 16 2022 at 23:57):

Yes, sorry, should have thought to say this earlier. I don't think this file should be ported at all. :-)

Arien Malec (Nov 17 2022 at 00:59):

Hmm. all data.tree seems to do is be used in tactics and testing -- not sure how it even got pulled into one of the dependency graphs.

Arien Malec (Nov 17 2022 at 01:07):

When I look at the graph from data.tree it's basically everything, but comes in through the tactic metaverse.

Arien Malec (Nov 17 2022 at 01:08):

eg, linarith via cancel_denoms which is the only direct dependency.

Arien Malec (Nov 17 2022 at 01:36):

I'm doing the --exclude-tactics thing but maybe things are getting pulled in transitively...

leanproject import-graph --from data.tree --exclude-tactics data.tree.pdf --port-status

Scott Morrison (Nov 17 2022 at 02:01):

Yes, I made a change so that when --exclude-tactics deletes a tactic node in the graph, it adds all "grandparent" edges.

Scott Morrison (Nov 17 2022 at 02:02):

Perhaps this was a bad idea and has led you astray. :-)

Scott Morrison (Nov 17 2022 at 02:03):

Perhaps just port as mostly empty file: just a comment to say that the code is no longer needed because it was only use in tactics, which are being reimplemented.

Arien Malec (Nov 17 2022 at 02:55):

I think it might be better to remove nodes that have only a single edge from tactic/meta

Scott Morrison (Nov 17 2022 at 02:57):

It's not really clear what the algorithm should be. What is there are theory files that are genuinely needed, but only imported in matlib3 transitively via tactics files?

Mario Carneiro (Nov 17 2022 at 02:57):

well, we'd have to run that "needed" script again...

Mario Carneiro (Nov 17 2022 at 02:59):

you could try removing all tactic files including their edges in and out from the graph, but I suspect that there is quite a lot of "cheating" with declarations being transitively pulled in for stuff like data.list.basic, which is used by a downstream file which only does e.g. import tactic.linarith

Mario Carneiro (Nov 17 2022 at 03:02):

Regarding this particular file, I suggest the following course of action:

Mario Carneiro said:

I think a suitable "port" of the data.rbtree is: make a list of all the theorems about rbtree that don't yet exist in Std.Data.RBMap, open an issue for them on std4, and then remove everything from the module except for #aligns if possible (if the types are too different, just leave them unaligned). Std.Data.RBMap intends to completely replace that directory.

Arien Malec (Nov 17 2022 at 03:19):

Have pushed part 2, with deprecate statements as well.

Arien Malec (Nov 17 2022 at 03:19):

Will go through the RBMap theorems

Arien Malec (Nov 17 2022 at 03:31):

Looks like Std heavily covers the well-formed invariants associated with insert/delete, but mathlib additionally covers the behavior or searching and ordering

Mario Carneiro (Nov 17 2022 at 03:33):

yes, you should translate the mathlib statements to something about RBMap, then put them in the mathlib4 file for now (it's okay to comment out / sorry the proofs if the originals don't work) and open an issue to move them to std4

Mario Carneiro (Nov 17 2022 at 03:34):

we don't want to just delete the file if that means some theorems get lost without there being a replacement or an issue tracking said replacement

Arien Malec (Nov 17 2022 at 03:49):

No theorems in init.lean; insert.lean covers the wellfoundedness work that's already in Std, so it's basic.lean, find.lean and min_max.lean that want to be saved.

Mario Carneiro (Nov 17 2022 at 03:55):

Could you translate the statements into actual lean 4 theorems with sorry? That's the equivalent of porting work for these files

Arien Malec (Nov 17 2022 at 03:57):

K


Last updated: Dec 20 2023 at 11:08 UTC