GithubHelp home page GithubHelp logo

lean-ssr's Introduction

LeanSSR: an SSReflect-Like Tactic Language for Lean

This repository provides LeanSSR: a SSReflect tactic DSL for Lean4. LeanSSR extends Coq/SSReflect's tactic DSL with various new DSL constructions and enhanced mechanism for computational reflection.

Building

With elan installed, lake build should suffice.

Adding LeanSSR to your project

To use the latest version of LeanSSR in a Lean 4 project, first add this package as a dependency. In your lakefile.lean, add

require ssreflect from git "https://github.com/verse-lab/lean-ssr" @ "master"

Then run

lake update ssreflect

You also need to make sure that your lean-toolchain file contains the same version of Lean 4 as LeanSSR's, and that your versions of LeanSSR's dependencies (currently only Batteries4) match. THe project does not support version ranges at the moment.

You may also consider using a stable release of the framework by adding the following to your lakefile.lean instead:

require ssreflect from git "https://github.com/verse-lab/lean-ssr" @ "v1.0"

Once LeanSSR is downloaded and compiler, the following test file should compile:

import Ssreflect.Lang

example {α : Type} : α → α := by
  -- The following is equivalent to 
  -- intro x; trivial
  move=> x//

Documentation

Examples

You can find LeanSSR use case examples at Examples folder

Contributors

lean-ssr's People

Contributors

volodeyka avatar dranov avatar ilyasergey avatar

Stargazers

Jason Manuel avatar Kyle Miller avatar Cameron Low avatar  avatar Zhang Qixiang avatar yi avatar saddle196883 avatar Alok Singh avatar Alexey Solovyev avatar  avatar Evgeniy Moiseenko avatar yibit avatar Dexin avatar Ken Sonoda avatar Rémi avatar Lîm Tsú-thuàn avatar aconite avatar Junyan Xu avatar Mukesh Tiwari avatar Philip Zucker avatar Tim Kersey avatar cybai (Haku) avatar SnO₂WMaN avatar Kaiyu Yang avatar  avatar Gregory Gerasev avatar kei avatar Qiyuan Zhao avatar C H avatar Alexander Chichigin avatar Paul Cadman avatar

Watchers

 avatar

lean-ssr's Issues

Error message when `->` fails has the top of the stack as a hypothesis in the context

/-- error:
tactic 'rewrite' failed, did not find instance of the pattern in the target expression
  x
x y z : Nat
H : x = y
⊢ z = z
---
error: unsolved goals
x y z : Nat
⊢ x = y → z = z
-/
theorem rrw_intro_fail : ∀ (x y z : Nat), x = y → z = z := by
  move=>x y z ->

I would expect the H to not be there in the error message (it isn't there after the tactic fails), but this is not very important.

Goals forgotten: `(kernel) declaration has metavariables`

-- FAILING test case: what is going on here??
/-- error:
(kernel) declaration has metavariables 'subnDA'
-/
theorem subnDA (m n p : Nat) : n - (m + p) = (n - m) - p := by
  elim: m;
  move=>//;

I've added a test case – making an issue so we don't lose track of this.

Error when using rewrite that solves the goal

@[simp] theorem size_nseq n (x : α) : size (nseq x n) = n := by
  elim: n=>[ // | n /= ->]

There is an error highlighted at -> ("no goals to be solved") and by ("unsolved goals").

However, #print size_nseq then actually prints a term without sorry, so this might be an issue just with how the errors are attributed.

I've slightly modified the code in IntroPats.lean to try to figure out what's going on:

    | `(ssrIntro| ->) => do
      let name ← fresh "H"
      run `(tactic| intros $name)
      let nGoals := (← getUnsolvedGoals).length
      dbg_trace s!"goals before rw: {nGoals}"
      run `(tactic| rw [$name:ident])
      let nGoals := (← getUnsolvedGoals).length
      dbg_trace s!"goals left after rw: {nGoals}"
      if (← getUnsolvedGoals).length != 0 then
        dbg_trace "clear"
        run `(tactic| try clear $name)

The issue doesn't seem to be related to try clear – the error shows up even if that doesn't run as in the above code.

Unexpected end of input

-- Left rewrite
theorem lrw_intro_1 : ∀ (x y z : Nat), x = y → y = z → z = x := by
  move=>x y z <-
  trace_state
  move=>->

This gives an unexpected end of input on the last line. It's not related to it being ->; other intro patterns result in the same error. Moving the move=>-> line above trace_state, the error disappears, so it seems inherently related to this being the last tactic in a proof.

Eliminate/generalize terms, not just hypotheses

In the proof of last_ind in Seq.v, one needs to generalize a term []. This is done by elim: s [] Hnil, but this is currently not supported in Ssrlean.

Lemma last_ind P :
  P [::] -> (forall s x, P s -> P (rcons s x)) -> forall s, P s.
Proof.
move=> Hnil Hlast s; rewrite -(cat0s s).
elim: s [::] Hnil => [|x s2 IHs] s1 Hs1; first by rewrite cats0.
by rewrite -cat_rcons; apply/IHs/Hlast.
Qed.

Here's the equivalent Lean proof:

theorem last_ind (P : Seq α → Prop) :
  P [] → (∀ s x, P s → P (rcons s x)) → ∀ s, P s := by
  move=> Hnil Hlast s <;> srw -(cat0s s);
  revert Hnil; generalize [] = s1; revert s1
  elim: s=>[|x s2 IHs] s1 Hs1
  { sby srw cats0 }
  { sby srw -cat_rcons; apply IHs; apply Hlast }

Intro top-of-stack does not support multiple arguments

-- FAILING: Intro top of stack with multiple arguments
/--
info: α : Type
x y : α
xs : List α
⊢ List.length (y :: xs) ≤ List.length (x :: y :: xs) → List.length (y :: xs) ≤ List.length (x :: y :: xs)
-/
#guard_msgs(info) in
theorem length_cons_3 {α : Type} (x : α) (y : α) (xs : List α) :
  List.length (y :: xs) ≤ List.length (x :: y :: xs) := by
  have H: ∀ (x : α) (xs : List α), List.length xs ≤ List.length (x :: xs)
    := by induction xs with | nil => move=>//= | cons x xs ih => move=>//=
  revert H;
  move=> /(_ x (y :: xs));
  trace_state
  move=>//=;

Sequence with case split

In Coq, I can write something like:

Lemma lastP s : last_spec s.
Proof. case: s => [|x s]; [left | rewrite lastI; right]. Qed.

Is there something similar in Ssrlean?

Currently I do the following, which is a bit verbose:

theorem lastP (s : Seq α) : last_spec s := by
  scase: s => [|x s]
  { left }
  { srw lastI; right }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.