siddhartha-gadgil / LeanAide

Tools based on AI for helping with Lean 4
Apache License 2.0
65 stars 5 forks source link

Targeted rewrite: conv_rw? #27

Open siddhartha-gadgil opened 1 year ago

siddhartha-gadgil commented 1 year ago

This follows an idea of Scott Morrison, and is for use both directly in Mathlib (potentially) and with LeanAide.

0art0 commented 1 year ago

The built-in Lean type SubExpr may be useful here. A SubExpr is determined by a SubExpr.Pos, which is a type synonym for Nat; however, the function SubExpr.Pos.toArray decodes the Nat to a familiar Array of indices which determine the path along the expression tree.

0art0 commented 1 year ago

Closely related to targeted rewriting with conv is this demo from the ProofWidgets repository. A variation of the solveLevel function might be what is required.

siddhartha-gadgil commented 1 year ago

@0art0 Does the widget work under binders, for example with:

example : ∀ x: ℕ, x + 3 = 3 + x := by
  conv =>
    enter [x, 2]
    rw [Nat.add_comm]
  intro _ 
  rfl

If so I agree we should follow that code, with navigating to all positions instead of based on clicks.

0art0 commented 1 year ago

Yes, I tested the above example and it does work under binders too.

siddhartha-gadgil commented 1 year ago

@0art0 What is the suggested tactic sequence there? Does it give enter [x, 2] or equivalent?

0art0 commented 1 year ago

Yes, it gave enter [x, 1] (as I chose to rewrite the left-hand side).

siddhartha-gadgil commented 1 year ago

That is perfect then. One just has to copy part of the code (excluding widget stuff) and simulate clicking everywhere. Then one can use the code of rw? (maybe not going into sub-expressions).

0art0 commented 1 year ago

I will try to tackle this tomorrow.