2023-10-15 17:15:23 -07:00
|
|
|
|
/-
|
|
|
|
|
Tests pertaining to goals with no interdependencies
|
|
|
|
|
-/
|
2023-05-22 14:49:56 -07:00
|
|
|
|
import LSpec
|
2023-10-15 12:31:22 -07:00
|
|
|
|
import Pantograph.Goal
|
2024-11-08 13:04:00 -08:00
|
|
|
|
import Pantograph.Delate
|
2023-10-25 22:18:59 -07:00
|
|
|
|
import Test.Common
|
2023-05-22 14:49:56 -07:00
|
|
|
|
|
2023-10-06 17:31:36 -07:00
|
|
|
|
namespace Pantograph.Test.Proofs
|
2023-05-22 14:49:56 -07:00
|
|
|
|
open Pantograph
|
2023-05-24 00:54:48 -07:00
|
|
|
|
open Lean
|
2023-05-22 14:49:56 -07:00
|
|
|
|
|
|
|
|
|
inductive Start where
|
|
|
|
|
| copy (name: String) -- Start from some name in the environment
|
|
|
|
|
| expr (expr: String) -- Start from some expression
|
|
|
|
|
|
2024-04-06 21:52:25 -07:00
|
|
|
|
abbrev TestM := StateRefT LSpec.TestSeq (ReaderT Protocol.Options Elab.TermElabM)
|
2023-05-23 05:12:46 -07:00
|
|
|
|
|
2023-10-15 17:15:23 -07:00
|
|
|
|
def addTest (test: LSpec.TestSeq): TestM Unit := do
|
2023-08-27 19:53:09 -07:00
|
|
|
|
set $ (← get) ++ test
|
|
|
|
|
|
2023-10-15 17:15:23 -07:00
|
|
|
|
def startProof (start: Start): TestM (Option GoalState) := do
|
2023-05-23 05:12:46 -07:00
|
|
|
|
let env ← Lean.MonadEnv.getEnv
|
2023-05-22 14:49:56 -07:00
|
|
|
|
match start with
|
|
|
|
|
| .copy name =>
|
2023-11-06 10:45:11 -08:00
|
|
|
|
let cInfo? := name.toName |> env.find?
|
2023-10-15 17:15:23 -07:00
|
|
|
|
addTest $ LSpec.check s!"Symbol exists {name}" cInfo?.isSome
|
2023-05-22 14:49:56 -07:00
|
|
|
|
match cInfo? with
|
2023-05-23 05:12:46 -07:00
|
|
|
|
| .some cInfo =>
|
2023-08-27 19:53:09 -07:00
|
|
|
|
let goal ← GoalState.create (expr := cInfo.type)
|
|
|
|
|
return Option.some goal
|
2023-05-22 14:49:56 -07:00
|
|
|
|
| .none =>
|
2023-08-27 19:53:09 -07:00
|
|
|
|
return Option.none
|
2023-05-22 14:49:56 -07:00
|
|
|
|
| .expr expr =>
|
2024-03-31 15:55:08 -07:00
|
|
|
|
let syn? := parseTerm env expr
|
2023-10-15 17:15:23 -07:00
|
|
|
|
addTest $ LSpec.check s!"Parsing {expr}" (syn?.isOk)
|
2023-05-22 14:49:56 -07:00
|
|
|
|
match syn? with
|
|
|
|
|
| .error error =>
|
|
|
|
|
IO.println error
|
2023-08-27 19:53:09 -07:00
|
|
|
|
return Option.none
|
2023-05-22 14:49:56 -07:00
|
|
|
|
| .ok syn =>
|
2024-03-31 15:55:08 -07:00
|
|
|
|
let expr? ← elabType syn
|
2023-10-15 17:15:23 -07:00
|
|
|
|
addTest $ LSpec.check s!"Elaborating" expr?.isOk
|
2023-05-22 14:49:56 -07:00
|
|
|
|
match expr? with
|
|
|
|
|
| .error error =>
|
|
|
|
|
IO.println error
|
2023-08-27 19:53:09 -07:00
|
|
|
|
return Option.none
|
2023-05-22 14:49:56 -07:00
|
|
|
|
| .ok expr =>
|
2023-08-27 19:53:09 -07:00
|
|
|
|
let goal ← GoalState.create (expr := expr)
|
|
|
|
|
return Option.some goal
|
2023-05-22 14:49:56 -07:00
|
|
|
|
|
2024-04-18 14:19:25 -07:00
|
|
|
|
def buildNamedGoal (name: String) (nameType: List (String × String)) (target: String)
|
|
|
|
|
(userName?: Option String := .none): Protocol.Goal :=
|
2024-04-15 12:47:02 -07:00
|
|
|
|
{
|
|
|
|
|
name,
|
2024-04-18 14:19:25 -07:00
|
|
|
|
userName?,
|
2024-04-15 12:47:02 -07:00
|
|
|
|
target := { pp? := .some target},
|
|
|
|
|
vars := (nameType.map fun x => ({
|
|
|
|
|
userName := x.fst,
|
|
|
|
|
type? := .some { pp? := .some x.snd },
|
|
|
|
|
})).toArray
|
|
|
|
|
}
|
2024-04-18 14:19:25 -07:00
|
|
|
|
def buildGoal (nameType: List (String × String)) (target: String) (userName?: Option String := .none):
|
|
|
|
|
Protocol.Goal :=
|
2023-05-27 23:10:39 -07:00
|
|
|
|
{
|
2023-10-30 14:44:06 -07:00
|
|
|
|
userName?,
|
2023-08-14 21:43:40 -07:00
|
|
|
|
target := { pp? := .some target},
|
|
|
|
|
vars := (nameType.map fun x => ({
|
2023-10-25 22:18:59 -07:00
|
|
|
|
userName := x.fst,
|
2023-08-15 15:40:54 -07:00
|
|
|
|
type? := .some { pp? := .some x.snd },
|
|
|
|
|
})).toArray
|
2023-05-27 23:10:39 -07:00
|
|
|
|
}
|
2023-10-15 17:15:23 -07:00
|
|
|
|
def proofRunner (env: Lean.Environment) (tests: TestM Unit): IO LSpec.TestSeq := do
|
|
|
|
|
let termElabM := tests.run LSpec.TestSeq.done |>.run {} -- with default options
|
|
|
|
|
|
2024-03-28 00:06:35 -07:00
|
|
|
|
let coreContext: Lean.Core.Context ← createCoreContext #[]
|
2024-11-08 14:41:24 -08:00
|
|
|
|
let metaM := termElabM.run' (ctx := defaultElabContext)
|
2023-10-15 17:15:23 -07:00
|
|
|
|
let coreM := metaM.run'
|
|
|
|
|
match ← (coreM.run' coreContext { env := env }).toBaseIO with
|
|
|
|
|
| .error exception =>
|
|
|
|
|
return LSpec.test "Exception" (s!"internal exception #{← exception.toMessageData.toString}" = "")
|
|
|
|
|
| .ok (_, a) =>
|
|
|
|
|
return a
|
2023-08-27 19:53:09 -07:00
|
|
|
|
|
2024-05-19 15:43:10 -07:00
|
|
|
|
def test_identity: TestM Unit := do
|
|
|
|
|
let state? ← startProof (.expr "∀ (p: Prop), p → p")
|
|
|
|
|
let state0 ← match state? with
|
|
|
|
|
| .some state => pure state
|
|
|
|
|
| .none => do
|
|
|
|
|
addTest $ assertUnreachable "Goal could not parse"
|
|
|
|
|
return ()
|
|
|
|
|
|
|
|
|
|
let tactic := "intro p h"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state1 ← match ← state0.tacticOn 0 tactic with
|
2024-05-19 15:43:10 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
let inner := "_uniq.12"
|
|
|
|
|
addTest $ LSpec.check tactic ((← state1.serializeGoals (options := ← read)).map (·.name) =
|
|
|
|
|
#[inner])
|
|
|
|
|
let state1parent ← state1.withParentContext do
|
|
|
|
|
serializeExpressionSexp (← instantiateAll state1.parentExpr?.get!) (sanitize := false)
|
|
|
|
|
addTest $ LSpec.test "(1 parent)" (state1parent == s!"(:lambda p (:sort 0) (:lambda h 0 (:subst (:mv {inner}) 1 0)))")
|
|
|
|
|
|
2023-08-27 19:53:09 -07:00
|
|
|
|
-- Individual test cases
|
2023-05-22 14:49:56 -07:00
|
|
|
|
example: ∀ (a b: Nat), a + b = b + a := by
|
|
|
|
|
intro n m
|
|
|
|
|
rw [Nat.add_comm]
|
2024-04-06 16:33:20 -07:00
|
|
|
|
def test_nat_add_comm (manual: Bool): TestM Unit := do
|
2023-10-15 17:15:23 -07:00
|
|
|
|
let state? ← startProof <| match manual with
|
|
|
|
|
| false => .copy "Nat.add_comm"
|
|
|
|
|
| true => .expr "∀ (a b: Nat), a + b = b + a"
|
|
|
|
|
addTest $ LSpec.check "Start goal" state?.isSome
|
|
|
|
|
let state0 ← match state? with
|
|
|
|
|
| .some state => pure state
|
|
|
|
|
| .none => do
|
|
|
|
|
addTest $ assertUnreachable "Goal could not parse"
|
|
|
|
|
return ()
|
|
|
|
|
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state1 ← match ← state0.tacticOn 0 "intro n m" with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-15 17:15:23 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2023-10-26 22:47:42 -07:00
|
|
|
|
addTest $ LSpec.check "intro n m" ((← state1.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[buildGoal [("n", "Nat"), ("m", "Nat")] "n + m = m + n"])
|
2023-10-15 17:15:23 -07:00
|
|
|
|
|
2024-09-06 21:07:12 -07:00
|
|
|
|
match ← state1.tacticOn 0 "assumption" with
|
2023-10-15 17:15:23 -07:00
|
|
|
|
| .failure #[message] =>
|
|
|
|
|
addTest $ LSpec.check "assumption" (message = "tactic 'assumption' failed\nn m : Nat\n⊢ n + m = m + n")
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state2 ← match ← state1.tacticOn 0 "rw [Nat.add_comm]" with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-15 17:15:23 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2023-10-26 22:47:42 -07:00
|
|
|
|
addTest $ LSpec.test "rw [Nat.add_comm]" state2.goals.isEmpty
|
|
|
|
|
|
|
|
|
|
return ()
|
2024-04-06 16:33:20 -07:00
|
|
|
|
def test_delta_variable: TestM Unit := do
|
2023-10-26 22:47:42 -07:00
|
|
|
|
let options: Protocol.Options := { noRepeat := true }
|
|
|
|
|
let state? ← startProof <| .expr "∀ (a b: Nat), a + b = b + a"
|
|
|
|
|
addTest $ LSpec.check "Start goal" state?.isSome
|
|
|
|
|
let state0 ← match state? with
|
|
|
|
|
| .some state => pure state
|
|
|
|
|
| .none => do
|
|
|
|
|
addTest $ assertUnreachable "Goal could not parse"
|
|
|
|
|
return ()
|
2023-10-15 17:15:23 -07:00
|
|
|
|
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state1 ← match ← state0.tacticOn (goalId := 0) (tactic := "intro n") with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check "intro n" ((← state1.serializeGoals (parent := state0) options).map (·.devolatilize) =
|
|
|
|
|
#[buildGoalSelective [("n", .some "Nat")] "∀ (b : Nat), n + b = b + n"])
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state2 ← match ← state1.tacticOn (goalId := 0) (tactic := "intro m") with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check "intro m" ((← state2.serializeGoals (parent := state1) options).map (·.devolatilize) =
|
|
|
|
|
#[buildGoalSelective [("n", .none), ("m", .some "Nat")] "n + m = m + n"])
|
2023-10-15 17:15:23 -07:00
|
|
|
|
return ()
|
2023-10-26 22:47:42 -07:00
|
|
|
|
where
|
|
|
|
|
-- Like `buildGoal` but allow certain variables to be elided.
|
|
|
|
|
buildGoalSelective (nameType: List (String × Option String)) (target: String): Protocol.Goal :=
|
|
|
|
|
{
|
|
|
|
|
target := { pp? := .some target},
|
|
|
|
|
vars := (nameType.map fun x => ({
|
|
|
|
|
userName := x.fst,
|
|
|
|
|
type? := x.snd.map (λ type => { pp? := type }),
|
|
|
|
|
})).toArray
|
|
|
|
|
}
|
2023-08-27 19:53:09 -07:00
|
|
|
|
|
2023-10-26 11:22:02 -07:00
|
|
|
|
example (w x y z : Nat) (p : Nat → Prop)
|
|
|
|
|
(h : p (x * y + z * w * x)) : p (x * w * z + y * x) := by
|
|
|
|
|
simp [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm, Nat.mul_comm, Nat.mul_assoc, Nat.mul_left_comm] at *
|
|
|
|
|
assumption
|
2024-04-06 16:33:20 -07:00
|
|
|
|
def test_arith: TestM Unit := do
|
2023-10-26 11:22:02 -07:00
|
|
|
|
let state? ← startProof (.expr "∀ (w x y z : Nat) (p : Nat → Prop) (h : p (x * y + z * w * x)), p (x * w * z + y * x)")
|
|
|
|
|
let state0 ← match state? with
|
|
|
|
|
| .some state => pure state
|
|
|
|
|
| .none => do
|
|
|
|
|
addTest $ assertUnreachable "Goal could not parse"
|
|
|
|
|
return ()
|
|
|
|
|
|
2024-04-07 14:22:20 -07:00
|
|
|
|
let tactic := "intros"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state1 ← match ← state0.tacticOn (goalId := 0) (tactic := tactic) with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-26 11:22:02 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2024-04-07 14:22:20 -07:00
|
|
|
|
addTest $ LSpec.check tactic (state1.goals.length = 1)
|
2023-10-27 15:41:12 -07:00
|
|
|
|
addTest $ LSpec.test "(1 root)" state1.rootExpr?.isNone
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state2 ← match ← state1.tacticOn (goalId := 0) (tactic := "simp [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm, Nat.mul_comm, Nat.mul_assoc, Nat.mul_left_comm] at *") with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-26 11:22:02 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2023-10-26 22:47:42 -07:00
|
|
|
|
addTest $ LSpec.check "simp ..." (state2.goals.length = 1)
|
2023-10-27 15:41:12 -07:00
|
|
|
|
addTest $ LSpec.check "(2 root)" state2.rootExpr?.isNone
|
2024-04-07 14:22:20 -07:00
|
|
|
|
let tactic := "assumption"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3 ← match ← state2.tacticOn (goalId := 0) (tactic := tactic) with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-26 11:22:02 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2024-04-07 14:22:20 -07:00
|
|
|
|
addTest $ LSpec.test tactic state3.goals.isEmpty
|
2023-10-27 15:41:12 -07:00
|
|
|
|
addTest $ LSpec.check "(3 root)" state3.rootExpr?.isSome
|
2023-10-26 11:22:02 -07:00
|
|
|
|
return ()
|
2023-05-22 14:49:56 -07:00
|
|
|
|
|
2023-05-22 22:48:48 -07:00
|
|
|
|
-- Two ways to write the same theorem
|
2023-05-22 14:49:56 -07:00
|
|
|
|
example: ∀ (p q: Prop), p ∨ q → q ∨ p := by
|
|
|
|
|
intro p q h
|
|
|
|
|
cases h
|
|
|
|
|
apply Or.inr
|
|
|
|
|
assumption
|
|
|
|
|
apply Or.inl
|
|
|
|
|
assumption
|
2023-05-22 22:48:48 -07:00
|
|
|
|
example: ∀ (p q: Prop), p ∨ q → q ∨ p := by
|
|
|
|
|
intro p q h
|
|
|
|
|
cases h
|
|
|
|
|
. apply Or.inr
|
|
|
|
|
assumption
|
|
|
|
|
. apply Or.inl
|
|
|
|
|
assumption
|
2024-04-06 16:33:20 -07:00
|
|
|
|
def test_or_comm: TestM Unit := do
|
2023-10-15 17:15:23 -07:00
|
|
|
|
let state? ← startProof (.expr "∀ (p q: Prop), p ∨ q → q ∨ p")
|
|
|
|
|
let state0 ← match state? with
|
|
|
|
|
| .some state => pure state
|
|
|
|
|
| .none => do
|
|
|
|
|
addTest $ assertUnreachable "Goal could not parse"
|
|
|
|
|
return ()
|
2024-01-30 17:22:20 -08:00
|
|
|
|
addTest $ LSpec.check "(0 parent)" state0.parentExpr?.isNone
|
|
|
|
|
addTest $ LSpec.check "(0 root)" state0.rootExpr?.isNone
|
2023-05-22 14:49:56 -07:00
|
|
|
|
|
2024-04-06 21:52:25 -07:00
|
|
|
|
let tactic := "intro p q h"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state1 ← match ← state0.tacticOn (goalId := 0) (tactic := tactic) with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-15 17:15:23 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2024-05-16 10:31:38 -07:00
|
|
|
|
let fvP := "_uniq.10"
|
|
|
|
|
let fvQ := "_uniq.13"
|
|
|
|
|
let fvH := "_uniq.16"
|
|
|
|
|
let state1g0 := "_uniq.17"
|
|
|
|
|
addTest $ LSpec.check tactic ((← state1.serializeGoals (options := ← read)) =
|
|
|
|
|
#[{
|
|
|
|
|
name := state1g0,
|
|
|
|
|
target := { pp? := .some "q ∨ p" },
|
|
|
|
|
vars := #[
|
2024-08-17 00:53:38 -07:00
|
|
|
|
{ name := fvP, userName := "p", type? := .some { pp? := .some "Prop" } },
|
|
|
|
|
{ name := fvQ, userName := "q", type? := .some { pp? := .some "Prop" } },
|
|
|
|
|
{ name := fvH, userName := "h", type? := .some { pp? := .some "p ∨ q" } }
|
2024-05-16 10:31:38 -07:00
|
|
|
|
]
|
|
|
|
|
}])
|
2024-01-30 17:22:20 -08:00
|
|
|
|
addTest $ LSpec.check "(1 parent)" state1.parentExpr?.isSome
|
|
|
|
|
addTest $ LSpec.check "(1 root)" state1.rootExpr?.isNone
|
2024-04-06 21:52:25 -07:00
|
|
|
|
|
2024-05-19 15:43:10 -07:00
|
|
|
|
let state1parent ← state1.withParentContext do
|
|
|
|
|
serializeExpressionSexp (← instantiateAll state1.parentExpr?.get!) (sanitize := false)
|
|
|
|
|
addTest $ LSpec.test "(1 parent)" (state1parent == s!"(:lambda p (:sort 0) (:lambda q (:sort 0) (:lambda h ((:c Or) 1 0) (:subst (:mv {state1g0}) 2 1 0))))")
|
2024-04-06 21:52:25 -07:00
|
|
|
|
let tactic := "cases h"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state2 ← match ← state1.tacticOn (goalId := 0) (tactic := tactic) with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-15 17:15:23 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2024-04-06 21:52:25 -07:00
|
|
|
|
addTest $ LSpec.check tactic ((← state2.serializeGoals (options := ← read)).map (·.devolatilize) =
|
2023-10-26 22:47:42 -07:00
|
|
|
|
#[branchGoal "inl" "p", branchGoal "inr" "q"])
|
2024-05-19 15:43:10 -07:00
|
|
|
|
let (caseL, caseR) := ("_uniq.64", "_uniq.77")
|
2024-05-16 10:31:38 -07:00
|
|
|
|
addTest $ LSpec.check tactic ((← state2.serializeGoals (options := ← read)).map (·.name) =
|
|
|
|
|
#[caseL, caseR])
|
2024-05-19 15:43:10 -07:00
|
|
|
|
addTest $ LSpec.check "(2 parent exists)" state2.parentExpr?.isSome
|
2024-01-30 17:22:20 -08:00
|
|
|
|
addTest $ LSpec.check "(2 root)" state2.rootExpr?.isNone
|
2023-10-15 17:15:23 -07:00
|
|
|
|
|
2024-05-19 15:43:10 -07:00
|
|
|
|
let state2parent ← state2.withParentContext do
|
|
|
|
|
serializeExpressionSexp (← instantiateAll state2.parentExpr?.get!) (sanitize := false)
|
2024-05-16 10:31:38 -07:00
|
|
|
|
let orPQ := s!"((:c Or) (:fv {fvP}) (:fv {fvQ}))"
|
|
|
|
|
let orQP := s!"((:c Or) (:fv {fvQ}) (:fv {fvP}))"
|
2024-11-26 12:34:52 -08:00
|
|
|
|
let motive := s!"(:lambda t {orPQ} (:forall h ((:c Eq) ((:c Or) (:fv {fvP}) (:fv {fvQ})) (:fv {fvH}) 0) {orQP}))"
|
|
|
|
|
let caseL := s!"(:lambda h (:fv {fvP}) (:lambda h ((:c Eq) {orPQ} (:fv {fvH}) ((:c Or.inl) (:fv {fvP}) (:fv {fvQ}) 0)) (:subst (:mv {caseL}) (:fv {fvP}) (:fv {fvQ}) 1)))"
|
|
|
|
|
let caseR := s!"(:lambda h (:fv {fvQ}) (:lambda h ((:c Eq) {orPQ} (:fv {fvH}) ((:c Or.inr) (:fv {fvP}) (:fv {fvQ}) 0)) (:subst (:mv {caseR}) (:fv {fvP}) (:fv {fvQ}) 1)))"
|
2024-05-19 15:43:10 -07:00
|
|
|
|
let conduit := s!"((:c Eq.refl) {orPQ} (:fv {fvH}))"
|
2024-02-15 14:47:09 -08:00
|
|
|
|
addTest $ LSpec.test "(2 parent)" (state2parent ==
|
2024-05-19 15:43:10 -07:00
|
|
|
|
s!"((:c Or.casesOn) (:fv {fvP}) (:fv {fvQ}) {motive} (:fv {fvH}) {caseL} {caseR} {conduit})")
|
2024-02-15 14:47:09 -08:00
|
|
|
|
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3_1 ← match ← state2.tacticOn (goalId := 0) (tactic := "apply Or.inr") with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-15 17:15:23 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2024-05-19 15:43:10 -07:00
|
|
|
|
let state3_1parent ← state3_1.withParentContext do
|
|
|
|
|
serializeExpressionSexp (← instantiateAll state3_1.parentExpr?.get!) (sanitize := false)
|
|
|
|
|
addTest $ LSpec.test "(3_1 parent)" (state3_1parent == s!"((:c Or.inr) (:fv {fvQ}) (:fv {fvP}) (:mv _uniq.91))")
|
2023-10-26 22:47:42 -07:00
|
|
|
|
addTest $ LSpec.check "· apply Or.inr" (state3_1.goals.length = 1)
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state4_1 ← match ← state3_1.tacticOn (goalId := 0) (tactic := "assumption") with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-15 17:15:23 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2023-10-27 15:15:22 -07:00
|
|
|
|
addTest $ LSpec.check " assumption" state4_1.goals.isEmpty
|
2024-05-16 10:31:38 -07:00
|
|
|
|
let state4_1parent ← instantiateAll state4_1.parentExpr?.get!
|
|
|
|
|
addTest $ LSpec.test "(4_1 parent)" state4_1parent.isFVar
|
2023-10-27 15:41:12 -07:00
|
|
|
|
addTest $ LSpec.check "(4_1 root)" state4_1.rootExpr?.isNone
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3_2 ← match ← state2.tacticOn (goalId := 1) (tactic := "apply Or.inl") with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-15 17:15:23 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2023-10-26 22:47:42 -07:00
|
|
|
|
addTest $ LSpec.check "· apply Or.inl" (state3_2.goals.length = 1)
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state4_2 ← match ← state3_2.tacticOn (goalId := 0) (tactic := "assumption") with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-15 17:15:23 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2023-10-27 15:15:22 -07:00
|
|
|
|
addTest $ LSpec.check " assumption" state4_2.goals.isEmpty
|
2023-10-27 15:41:12 -07:00
|
|
|
|
addTest $ LSpec.check "(4_2 root)" state4_2.rootExpr?.isNone
|
2023-10-25 16:03:45 -07:00
|
|
|
|
-- Ensure the proof can continue from `state4_2`.
|
2023-11-04 15:33:53 -07:00
|
|
|
|
let state2b ← match state4_2.continue state2 with
|
2023-10-25 16:03:45 -07:00
|
|
|
|
| .error msg => do
|
|
|
|
|
addTest $ assertUnreachable $ msg
|
|
|
|
|
return ()
|
|
|
|
|
| .ok state => pure state
|
2023-10-26 22:47:42 -07:00
|
|
|
|
addTest $ LSpec.test "(resume)" (state2b.goals == [state2.goals.get! 0])
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3_1 ← match ← state2b.tacticOn (goalId := 0) (tactic := "apply Or.inr") with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-25 16:03:45 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2023-10-26 22:47:42 -07:00
|
|
|
|
addTest $ LSpec.check "· apply Or.inr" (state3_1.goals.length = 1)
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state4_1 ← match ← state3_1.tacticOn (goalId := 0) (tactic := "assumption") with
|
2023-10-26 22:47:42 -07:00
|
|
|
|
| .success state => pure state
|
2023-10-25 16:03:45 -07:00
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2023-10-27 15:15:22 -07:00
|
|
|
|
addTest $ LSpec.check " assumption" state4_1.goals.isEmpty
|
2023-10-27 15:41:12 -07:00
|
|
|
|
addTest $ LSpec.check "(4_1 root)" state4_1.rootExpr?.isSome
|
2023-10-15 17:15:23 -07:00
|
|
|
|
|
|
|
|
|
return ()
|
|
|
|
|
where
|
|
|
|
|
typeProp: Protocol.Expression := { pp? := .some "Prop" }
|
2023-10-30 14:44:06 -07:00
|
|
|
|
branchGoal (caseName varName: String): Protocol.Goal := {
|
|
|
|
|
userName? := .some caseName,
|
2023-10-15 17:15:23 -07:00
|
|
|
|
target := { pp? := .some "q ∨ p" },
|
|
|
|
|
vars := #[
|
2024-08-17 00:53:38 -07:00
|
|
|
|
{ userName := "p", type? := .some typeProp },
|
|
|
|
|
{ userName := "q", type? := .some typeProp },
|
|
|
|
|
{ userName := "h✝", type? := .some { pp? := .some varName }, isInaccessible := true }
|
2023-10-15 17:15:23 -07:00
|
|
|
|
]
|
|
|
|
|
}
|
2024-04-06 17:22:09 -07:00
|
|
|
|
|
2024-04-08 12:26:22 -07:00
|
|
|
|
example : ∀ (a b c1 c2: Nat), (b + a) + c1 = (b + a) + c2 → (a + b) + c1 = (b + a) + c2 := by
|
|
|
|
|
intro a b c1 c2 h
|
2024-04-06 17:22:09 -07:00
|
|
|
|
conv =>
|
|
|
|
|
lhs
|
|
|
|
|
congr
|
2024-04-08 12:26:22 -07:00
|
|
|
|
. rw [Nat.add_comm]
|
|
|
|
|
. rfl
|
|
|
|
|
exact h
|
2024-04-06 17:22:09 -07:00
|
|
|
|
|
|
|
|
|
def test_conv: TestM Unit := do
|
2024-04-08 12:26:22 -07:00
|
|
|
|
let state? ← startProof (.expr "∀ (a b c1 c2: Nat), (b + a) + c1 = (b + a) + c2 → (a + b) + c1 = (b + a) + c2")
|
2024-04-06 17:22:09 -07:00
|
|
|
|
let state0 ← match state? with
|
|
|
|
|
| .some state => pure state
|
|
|
|
|
| .none => do
|
|
|
|
|
addTest $ assertUnreachable "Goal could not parse"
|
|
|
|
|
return ()
|
2024-04-08 12:26:22 -07:00
|
|
|
|
|
|
|
|
|
let tactic := "intro a b c1 c2 h"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state1 ← match ← state0.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-04-06 17:22:09 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check tactic ((← state1.serializeGoals (options := ← read)).map (·.devolatilize) =
|
2024-04-08 12:26:22 -07:00
|
|
|
|
#[interiorGoal [] "a + b + c1 = b + a + c2"])
|
2024-04-06 17:22:09 -07:00
|
|
|
|
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state2 ← match ← state1.conv (state1.get! 0) with
|
2024-04-06 17:22:09 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2024-04-08 12:26:22 -07:00
|
|
|
|
addTest $ LSpec.check "conv => ..." ((← state2.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[{ interiorGoal [] "a + b + c1 = b + a + c2" with isConversion := true }])
|
2024-04-06 17:22:09 -07:00
|
|
|
|
|
2024-04-08 12:26:22 -07:00
|
|
|
|
let convTactic := "rhs"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3R ← match ← state2.tacticOn (goalId := 0) convTactic with
|
2024-04-07 14:22:20 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2024-04-08 12:26:22 -07:00
|
|
|
|
addTest $ LSpec.check s!" {convTactic} (discard)" ((← state3R.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[{ interiorGoal [] "b + a + c2" with isConversion := true }])
|
2024-04-07 14:22:20 -07:00
|
|
|
|
|
|
|
|
|
let convTactic := "lhs"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3L ← match ← state2.tacticOn (goalId := 0) convTactic with
|
2024-04-07 14:22:20 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check s!" {convTactic}" ((← state3L.serializeGoals (options := ← read)).map (·.devolatilize) =
|
2024-04-08 12:26:22 -07:00
|
|
|
|
#[{ interiorGoal [] "a + b + c1" with isConversion := true }])
|
2024-04-07 14:22:20 -07:00
|
|
|
|
|
2024-04-08 12:26:22 -07:00
|
|
|
|
let convTactic := "congr"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state4 ← match ← state3L.tacticOn (goalId := 0) convTactic with
|
2024-04-08 12:26:22 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check s!" {convTactic}" ((← state4.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[
|
|
|
|
|
{ interiorGoal [] "a + b" with isConversion := true, userName? := .some "a" },
|
|
|
|
|
{ interiorGoal [] "c1" with isConversion := true, userName? := .some "a" }
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
let convTactic := "rw [Nat.add_comm]"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state5_1 ← match ← state4.tacticOn (goalId := 0) convTactic with
|
2024-04-08 12:26:22 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check s!" · {convTactic}" ((← state5_1.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[{ interiorGoal [] "b + a" with isConversion := true, userName? := .some "a" }])
|
|
|
|
|
|
|
|
|
|
let convTactic := "rfl"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state6_1 ← match ← state5_1.tacticOn (goalId := 0) convTactic with
|
2024-04-08 12:26:22 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check s!" {convTactic}" ((← state6_1.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[])
|
|
|
|
|
|
|
|
|
|
let state4_1 ← match state6_1.continue state4 with
|
|
|
|
|
| .ok state => pure state
|
|
|
|
|
| .error e => do
|
|
|
|
|
addTest $ expectationFailure "continue" e
|
|
|
|
|
return ()
|
|
|
|
|
|
|
|
|
|
let convTactic := "rfl"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state6 ← match ← state4_1.tacticOn (goalId := 0) convTactic with
|
2024-04-08 12:26:22 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check s!" · {convTactic}" ((← state6.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[])
|
|
|
|
|
|
|
|
|
|
let state1_1 ← match ← state6.convExit with
|
2024-04-07 14:22:20 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2024-04-08 12:26:22 -07:00
|
|
|
|
|
|
|
|
|
let tactic := "exact h"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let stateF ← match ← state1_1.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-04-08 12:26:22 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check tactic ((← stateF.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[])
|
|
|
|
|
|
|
|
|
|
where
|
|
|
|
|
h := "b + a + c1 = b + a + c2"
|
|
|
|
|
interiorGoal (free: List (String × String)) (target: String) :=
|
|
|
|
|
let free := [("a", "Nat"), ("b", "Nat"), ("c1", "Nat"), ("c2", "Nat"), ("h", h)] ++ free
|
|
|
|
|
buildGoal free target
|
2024-04-07 14:22:20 -07:00
|
|
|
|
|
2024-04-11 14:59:55 -07:00
|
|
|
|
example : ∀ (a b c d: Nat), a + b = b + c → b + c = c + d → a + b = c + d := by
|
|
|
|
|
intro a b c d h1 h2
|
|
|
|
|
calc a + b = b + c := by apply h1
|
|
|
|
|
_ = c + d := by apply h2
|
2024-04-06 17:22:09 -07:00
|
|
|
|
|
|
|
|
|
def test_calc: TestM Unit := do
|
2024-04-11 14:59:55 -07:00
|
|
|
|
let state? ← startProof (.expr "∀ (a b c d: Nat), a + b = b + c → b + c = c + d → a + b = c + d")
|
2024-04-06 17:22:09 -07:00
|
|
|
|
let state0 ← match state? with
|
|
|
|
|
| .some state => pure state
|
|
|
|
|
| .none => do
|
|
|
|
|
addTest $ assertUnreachable "Goal could not parse"
|
|
|
|
|
return ()
|
2024-04-11 14:59:55 -07:00
|
|
|
|
let tactic := "intro a b c d h1 h2"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state1 ← match ← state0.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-04-06 17:22:09 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check tactic ((← state1.serializeGoals (options := ← read)).map (·.devolatilize) =
|
2024-04-11 14:59:55 -07:00
|
|
|
|
#[interiorGoal [] "a + b = c + d"])
|
|
|
|
|
let pred := "a + b = b + c"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state2 ← match ← state1.tryCalc (state1.get! 0) (pred := pred) with
|
2024-04-06 17:22:09 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2024-04-11 14:59:55 -07:00
|
|
|
|
addTest $ LSpec.check s!"calc {pred} := _" ((← state2.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[
|
|
|
|
|
interiorGoal [] "a + b = b + c" (.some "calc"),
|
|
|
|
|
interiorGoal [] "b + c = c + d"
|
|
|
|
|
])
|
2024-09-06 21:07:12 -07:00
|
|
|
|
addTest $ LSpec.test "(2.0 prev rhs)" (state2.calcPrevRhsOf? (state2.get! 0) |>.isNone)
|
|
|
|
|
addTest $ LSpec.test "(2.1 prev rhs)" (state2.calcPrevRhsOf? (state2.get! 1) |>.isSome)
|
2024-04-11 14:59:55 -07:00
|
|
|
|
|
|
|
|
|
let tactic := "apply h1"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state2m ← match ← state2.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-04-11 14:59:55 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
let state3 ← match state2m.continue state2 with
|
|
|
|
|
| .ok state => pure state
|
|
|
|
|
| .error e => do
|
|
|
|
|
addTest $ expectationFailure "continue" e
|
|
|
|
|
return ()
|
|
|
|
|
let pred := "_ = c + d"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state4 ← match ← state3.tryCalc (state3.get! 0) (pred := pred) with
|
2024-04-11 14:59:55 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check s!"calc {pred} := _" ((← state4.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[
|
|
|
|
|
interiorGoal [] "b + c = c + d" (.some "calc")
|
|
|
|
|
])
|
2024-09-06 21:07:12 -07:00
|
|
|
|
addTest $ LSpec.test "(4.0 prev rhs)" (state4.calcPrevRhsOf? (state4.get! 0) |>.isNone)
|
2024-04-11 14:59:55 -07:00
|
|
|
|
let tactic := "apply h2"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state4m ← match ← state4.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-04-11 14:59:55 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.test "(4m root)" state4m.rootExpr?.isSome
|
|
|
|
|
where
|
|
|
|
|
interiorGoal (free: List (String × String)) (target: String) (userName?: Option String := .none) :=
|
|
|
|
|
let free := [("a", "Nat"), ("b", "Nat"), ("c", "Nat"), ("d", "Nat"),
|
|
|
|
|
("h1", "a + b = b + c"), ("h2", "b + c = c + d")] ++ free
|
|
|
|
|
buildGoal free target userName?
|
2024-04-06 17:22:09 -07:00
|
|
|
|
|
2024-04-15 12:47:02 -07:00
|
|
|
|
def test_nat_zero_add: TestM Unit := do
|
|
|
|
|
let state? ← startProof (.expr "∀ (n: Nat), n + 0 = n")
|
|
|
|
|
let state0 ← match state? with
|
|
|
|
|
| .some state => pure state
|
|
|
|
|
| .none => do
|
|
|
|
|
addTest $ assertUnreachable "Goal could not parse"
|
|
|
|
|
return ()
|
|
|
|
|
let tactic := "intro n"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state1 ← match ← state0.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-04-15 12:47:02 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check tactic ((← state1.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[buildGoal [("n", "Nat")] "n + 0 = n"])
|
|
|
|
|
let recursor := "@Nat.brecOn"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state2 ← match ← state1.tryMotivatedApply (state1.get! 0) (recursor := recursor) with
|
2024-04-15 12:47:02 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check s!"mapply {recursor}" ((← state2.serializeGoals (options := ← read)).map (·.devolatilizeVars) =
|
|
|
|
|
#[
|
2024-12-05 18:55:30 -08:00
|
|
|
|
buildNamedGoal "_uniq.71" [("n", "Nat")] "Nat → Prop" (.some "motive"),
|
|
|
|
|
buildNamedGoal "_uniq.72" [("n", "Nat")] "Nat",
|
|
|
|
|
buildNamedGoal "_uniq.73" [("n", "Nat")] "∀ (t : Nat), Nat.below t → ?motive t",
|
|
|
|
|
buildNamedGoal "_uniq.74" [("n", "Nat")] "?motive ?m.72 = (n + 0 = n)" (.some "conduit")
|
2024-04-15 12:47:02 -07:00
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
let tactic := "exact n"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3b ← match ← state2.tacticOn (goalId := 1) (tactic := tactic) with
|
2024-04-15 12:47:02 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check tactic ((← state3b.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[])
|
|
|
|
|
let state2b ← match state3b.continue state2 with
|
|
|
|
|
| .ok state => pure state
|
|
|
|
|
| .error e => do
|
|
|
|
|
addTest $ assertUnreachable e
|
|
|
|
|
return ()
|
|
|
|
|
let tactic := "exact (λ x => x + 0 = x)"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3c ← match ← state2b.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-04-15 12:47:02 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check tactic ((← state3c.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[])
|
|
|
|
|
let state2c ← match state3c.continue state2b with
|
|
|
|
|
| .ok state => pure state
|
|
|
|
|
| .error e => do
|
|
|
|
|
addTest $ assertUnreachable e
|
|
|
|
|
return ()
|
|
|
|
|
let tactic := "intro t h"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3 ← match ← state2c.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-04-15 12:47:02 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check tactic ((← state3.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[buildGoal [("n", "Nat"), ("t", "Nat"), ("h", "Nat.below t")] "t + 0 = t"])
|
|
|
|
|
|
|
|
|
|
let tactic := "simp"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3d ← match ← state3.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-04-22 10:02:09 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
let state2d ← match state3d.continue state2c with
|
|
|
|
|
| .ok state => pure state
|
|
|
|
|
| .error e => do
|
|
|
|
|
addTest $ assertUnreachable e
|
|
|
|
|
return ()
|
|
|
|
|
let tactic := "rfl"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let stateF ← match ← state2d.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-04-15 12:47:02 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check tactic ((← stateF.serializeGoals (options := ← read)) =
|
|
|
|
|
#[])
|
|
|
|
|
|
2024-04-22 00:11:41 -07:00
|
|
|
|
let expr := stateF.mctx.eAssignment.find! stateF.root
|
|
|
|
|
let (expr, _) := instantiateMVarsCore (mctx := stateF.mctx) (e := expr)
|
2024-04-15 12:47:02 -07:00
|
|
|
|
addTest $ LSpec.check "(F root)" stateF.rootExpr?.isSome
|
|
|
|
|
|
2024-05-09 14:02:43 -07:00
|
|
|
|
def test_nat_zero_add_alt: TestM Unit := do
|
|
|
|
|
let state? ← startProof (.expr "∀ (n: Nat), n + 0 = n")
|
|
|
|
|
let state0 ← match state? with
|
|
|
|
|
| .some state => pure state
|
|
|
|
|
| .none => do
|
|
|
|
|
addTest $ assertUnreachable "Goal could not parse"
|
|
|
|
|
return ()
|
|
|
|
|
let tactic := "intro n"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state1 ← match ← state0.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-05-09 14:02:43 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check tactic ((← state1.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[buildGoal [("n", "Nat")] "n + 0 = n"])
|
|
|
|
|
let recursor := "@Nat.brecOn"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state2 ← match ← state1.tryMotivatedApply (state1.get! 0) (recursor := recursor) with
|
2024-05-09 14:02:43 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2024-12-05 18:55:30 -08:00
|
|
|
|
let major := "_uniq.72"
|
2024-05-09 14:02:43 -07:00
|
|
|
|
addTest $ LSpec.check s!"mapply {recursor}" ((← state2.serializeGoals (options := ← read)).map (·.devolatilizeVars) =
|
|
|
|
|
#[
|
2024-12-05 18:55:30 -08:00
|
|
|
|
buildNamedGoal "_uniq.71" [("n", "Nat")] "Nat → Prop" (.some "motive"),
|
2024-05-13 13:49:05 -07:00
|
|
|
|
buildNamedGoal major [("n", "Nat")] "Nat",
|
2024-12-05 18:55:30 -08:00
|
|
|
|
buildNamedGoal "_uniq.73" [("n", "Nat")] "∀ (t : Nat), Nat.below t → ?motive t",
|
|
|
|
|
buildNamedGoal "_uniq.74" [("n", "Nat")] "?motive ?m.72 = (n + 0 = n)" (.some "conduit")
|
2024-05-09 14:02:43 -07:00
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
let tactic := "intro x"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3m ← match ← state2.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-05-09 14:02:43 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
|
|
|
|
addTest $ LSpec.check tactic ((← state3m.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
|
|
|
#[buildGoal [("n", "Nat"), ("x", "Nat")] "Prop" (.some "motive")])
|
|
|
|
|
let tactic := "apply Eq"
|
2024-09-06 21:07:12 -07:00
|
|
|
|
let state3m2 ← match ← state3m.tacticOn (goalId := 0) (tactic := tactic) with
|
2024-05-09 14:02:43 -07:00
|
|
|
|
| .success state => pure state
|
|
|
|
|
| other => do
|
|
|
|
|
addTest $ assertUnreachable $ other.toString
|
|
|
|
|
return ()
|
2024-12-05 18:55:30 -08:00
|
|
|
|
let (eqL, eqR, eqT) := ("_uniq.92", "_uniq.93", "_uniq.91")
|
2024-05-13 13:49:05 -07:00
|
|
|
|
addTest $ LSpec.check tactic $ state3m2.goals.map (·.name.toString) = [eqL, eqR, eqT]
|
2024-05-12 22:33:38 -07:00
|
|
|
|
let [_motive, _major, _step, conduit] := state2.goals | panic! "Goals conflict"
|
|
|
|
|
let state2b ← match state3m2.resume [conduit] with
|
2024-05-09 14:02:43 -07:00
|
|
|
|
| .ok state => pure state
|
|
|
|
|
| .error e => do
|
|
|
|
|
addTest $ assertUnreachable e
|
|
|
|
|
return ()
|
2024-05-12 22:33:38 -07:00
|
|
|
|
|
|
|
|
|
let cNatAdd := "(:c HAdd.hAdd) (:c Nat) (:c Nat) (:c Nat) ((:c instHAdd) (:c Nat) (:c instAddNat))"
|
|
|
|
|
let cNat0 := "((:c OfNat.ofNat) (:c Nat) (:lit 0) ((:c instOfNatNat) (:lit 0)))"
|
2024-12-05 18:55:30 -08:00
|
|
|
|
let fvN := "_uniq.67"
|
2024-05-19 15:43:10 -07:00
|
|
|
|
let conduitRight := s!"((:c Eq) (:c Nat) ({cNatAdd} (:fv {fvN}) {cNat0}) (:fv {fvN}))"
|
|
|
|
|
let substOf (mv: String) := s!"(:subst (:mv {mv}) (:fv {fvN}) (:mv {major}))"
|
2024-05-12 22:33:38 -07:00
|
|
|
|
addTest $ LSpec.check "resume" ((← state2b.serializeGoals (options := { ← read with printExprAST := true })) =
|
|
|
|
|
#[
|
|
|
|
|
{
|
2024-12-05 18:55:30 -08:00
|
|
|
|
name := "_uniq.74",
|
2024-05-12 22:33:38 -07:00
|
|
|
|
userName? := .some "conduit",
|
|
|
|
|
target := {
|
2024-12-05 18:55:30 -08:00
|
|
|
|
pp? := .some "(?m.96 ?m.72 = ?m.98 ?m.72) = (n + 0 = n)",
|
2024-05-19 15:43:10 -07:00
|
|
|
|
sexp? := .some s!"((:c Eq) (:sort 0) ((:c Eq) {substOf eqT} {substOf eqL} {substOf eqR}) {conduitRight})",
|
2024-05-12 22:33:38 -07:00
|
|
|
|
},
|
|
|
|
|
vars := #[{
|
|
|
|
|
name := fvN,
|
|
|
|
|
userName := "n",
|
|
|
|
|
type? := .some { pp? := .some "Nat", sexp? := .some "(:c Nat)" },
|
|
|
|
|
}],
|
|
|
|
|
}
|
|
|
|
|
])
|
2024-05-09 14:02:43 -07:00
|
|
|
|
|
2024-04-06 14:07:13 -07:00
|
|
|
|
def suite (env: Environment): List (String × IO LSpec.TestSeq) :=
|
2023-08-27 19:53:09 -07:00
|
|
|
|
let tests := [
|
2024-05-19 15:43:10 -07:00
|
|
|
|
("identity", test_identity),
|
2024-04-06 16:33:20 -07:00
|
|
|
|
("Nat.add_comm", test_nat_add_comm false),
|
|
|
|
|
("Nat.add_comm manual", test_nat_add_comm true),
|
|
|
|
|
("Nat.add_comm delta", test_delta_variable),
|
|
|
|
|
("arithmetic", test_arith),
|
|
|
|
|
("Or.comm", test_or_comm),
|
2024-04-06 17:22:09 -07:00
|
|
|
|
("conv", test_conv),
|
|
|
|
|
("calc", test_calc),
|
2024-04-15 12:47:02 -07:00
|
|
|
|
("Nat.zero_add", test_nat_zero_add),
|
2024-05-09 14:02:43 -07:00
|
|
|
|
("Nat.zero_add alt", test_nat_zero_add_alt),
|
2023-08-27 19:53:09 -07:00
|
|
|
|
]
|
2024-04-06 14:07:13 -07:00
|
|
|
|
tests.map (fun (name, test) => (name, proofRunner env test))
|
2023-05-22 14:49:56 -07:00
|
|
|
|
|
2024-04-06 17:22:09 -07:00
|
|
|
|
|
|
|
|
|
|
2023-10-06 17:31:36 -07:00
|
|
|
|
end Pantograph.Test.Proofs
|