Zulip Chat Archive

Stream: lean4

Topic: Getting Started with Tactics


Daniel Bourgeois (Feb 21 2023 at 04:47):

I'd like to create a tactic that

  1. reads in all ?x < ?y, ?u = ?v hypothesis (for Int's)
  2. applies transitive rules to get the complete set of possible relations
  3. adds in the not cases -- like ?x < ?y -> Not ?x = ?y
  4. searches for a contradiction to prove the goal

However, I don't know where to get started and have only a rudimentary
idea of how tactics work.

Any suggestions?

James Gallicchio (Feb 21 2023 at 04:48):

Definitely check out Arthur et al's metaprogramming book here. Goes through all the basics of metaprogramming in Lean!

James Gallicchio (Feb 21 2023 at 04:50):

(btw, is the tactic you're describing covered by linarith? though maybe that's a bit heavy of a tactic for your purposes)

Martin Dvořák (Feb 21 2023 at 09:52):

I cannot comment on how tactics are implemented because I never implemented one in my life. Just two cents:
(1) I think your step 3 is unnecessary.
(2) You will obtain something strictly weaker than linarith.

Martin Dvořák (Feb 21 2023 at 09:58):

Has omega been implemented in Lean 4 btw?

Johan Commelin (Feb 21 2023 at 09:59):

No, not yet

Martin Dvořák (Feb 21 2023 at 10:01):

So omega might be a great project for @Daniel Bourgeois instead!

Martin Dvořák (Feb 21 2023 at 10:02):

Not necessarily full omega but something along the lines @Daniel Bourgeois described but for Nat instead of Int.

Johan Commelin (Feb 21 2023 at 10:06):

I don't know much about this stuff, but I think implementing a performant version of omega is highly non-trivial.

Martin Dvořák (Feb 21 2023 at 10:08):

I feel a strong temptation to become a troll and say that omega was never performant.

Martin Dvořák (Feb 21 2023 at 10:10):

Anyways, I better shut up. Especially when I don't know shit about how tactics work inside.

Mario Carneiro (Feb 21 2023 at 10:17):

There is a micromega branch on mathlib4

Mario Carneiro (Feb 21 2023 at 10:19):

which apparently hasn't been touched since july

Martin Dvořák (Feb 21 2023 at 10:19):

https://github.com/leanprover-community/mathlib4/commits/micromega

Mario Carneiro (Feb 21 2023 at 10:20):

it's basically a port of https://github.com/coq/coq/tree/master/plugins/micromega

Martin Dvořák (Feb 21 2023 at 10:24):

Does Coq have something better than the micromega tho?

Mario Carneiro (Feb 21 2023 at 10:24):

don't let the name fool you, micromega is huge

Mario Carneiro (Feb 21 2023 at 10:24):

it is leagues better than lean 3 omega

Mario Carneiro (Feb 21 2023 at 10:25):

it also includes the equivalent of linarith and nlinarith

Mario Carneiro (Feb 21 2023 at 10:25):

(as separate tactics)

Mario Carneiro (Feb 21 2023 at 10:25):

micromega is the name of the overall package

Mario Carneiro (Feb 21 2023 at 10:27):

https://coq.github.io/doc/V8.11.0/refman/addendum/micromega.html

Martin Dvořák (Feb 21 2023 at 10:31):

Mario Carneiro said:

There is a micromega branch on mathlib4

Oh. I somehow wrongly assumed that micromega was supposed to be a temporary replacement for omega until the full omega gets implemented in Lean 4.

Mario Carneiro (Feb 21 2023 at 10:32):

no, lean 3 omega is not something we want to port. It was never complete in the first place

Martin Dvořák (Feb 21 2023 at 10:33):

I have a strong love-hate relationship with omega in Lean 3.

Mario Carneiro (Feb 21 2023 at 10:35):

if you are motivated I encourage you to pick up the branch and port the rest

Martin Dvořák (Feb 21 2023 at 10:35):

I am motivated but definitely not competent to do it.

Mario Carneiro (Feb 21 2023 at 10:36):

if you can read coq/ML it's mostly straightforward

Mario Carneiro (Feb 21 2023 at 10:36):

I stopped about a third of the way into https://github.com/coq/coq/blob/master/plugins/micromega/polynomial.ml

Martin Dvořák (Feb 21 2023 at 10:37):

I can hardly read Lean, let alone other languages.

Mario Carneiro (Feb 21 2023 at 10:37):

compare https://github.com/leanprover-community/mathlib4/blob/micromega/Mathlib/Tactic/Micromega/Polynomial.lean

Mario Carneiro (Feb 21 2023 at 10:39):

for me the hard part was knowing the types of things in the ML code, since I was just reading it from github and ML does global type inference so it's hard to see the types

Daniel Bourgeois (Feb 21 2023 at 15:24):

linarith worked, except it was necessary to insert have x : False := by linarith and then use x otherwise linarith complains that it can't synthesize LinearOrder

For learning purposes, I still want to have a go at implementing the tactic described.

James Gallicchio (Feb 21 2023 at 16:00):

Mario Carneiro said:

for me the hard part was knowing the types of things in the ML code, since I was just reading it from github and ML does global type inference so it's hard to see the types

highly recommend installing Millet (language server for ML), there's a vscode extension with everything packaged nicely


Last updated: Dec 20 2023 at 11:08 UTC