Compare commits
5 Commits
f5ed87f740
...
782ce38c87
Author | SHA1 | Date |
---|---|---|
Leni Aniva | 782ce38c87 | |
Leni Aniva | d809a960f9 | |
Leni Aniva | db706070ad | |
Leni Aniva | 754fb69cff | |
Leni Aniva | dc2cc5be77 |
|
@ -38,6 +38,7 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
|
||||||
| "options.print" => run options_print
|
| "options.print" => run options_print
|
||||||
| "goal.start" => run goal_start
|
| "goal.start" => run goal_start
|
||||||
| "goal.tactic" => run goal_tactic
|
| "goal.tactic" => run goal_tactic
|
||||||
|
| "goal.continue" => run goal_continue
|
||||||
| "goal.delete" => run goal_delete
|
| "goal.delete" => run goal_delete
|
||||||
| "goal.print" => run goal_print
|
| "goal.print" => run goal_print
|
||||||
| cmd =>
|
| cmd =>
|
||||||
|
@ -170,6 +171,30 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
|
||||||
return .error $ errorIndex s!"Invalid goal id index {goalId}"
|
return .error $ errorIndex s!"Invalid goal id index {goalId}"
|
||||||
| .ok (.failure messages) =>
|
| .ok (.failure messages) =>
|
||||||
return .ok { tacticErrors? := .some messages }
|
return .ok { tacticErrors? := .some messages }
|
||||||
|
goal_continue (args: Protocol.GoalContinue): MainM (CR Protocol.GoalContinueResult) := do
|
||||||
|
let state ← get
|
||||||
|
match state.goalStates.get? args.target with
|
||||||
|
| .none => return .error $ errorIndex s!"Invalid state index {args.target}"
|
||||||
|
| .some target => do
|
||||||
|
let nextState? ← match args.branch?, args.goals? with
|
||||||
|
| .some branchId, .none => do
|
||||||
|
match state.goalStates.get? branchId with
|
||||||
|
| .none => return .error $ errorIndex s!"Invalid state index {branchId}"
|
||||||
|
| .some branch => pure $ target.continue branch
|
||||||
|
| .none, .some goals =>
|
||||||
|
let goals := goals.map (λ name => { name := str_to_name name })
|
||||||
|
pure $ target.resume goals
|
||||||
|
| _, _ => return .error <| errorI "arguments" "Exactly one of {branch, goals} must be supplied"
|
||||||
|
match nextState? with
|
||||||
|
| .error error => return .ok { error? := .some error }
|
||||||
|
| .ok nextGoalState =>
|
||||||
|
let (goalStates, nextStateId) := state.goalStates.insert nextGoalState
|
||||||
|
set { state with goalStates }
|
||||||
|
let goals ← nextGoalState.serializeGoals (parent := .some target) (options := state.options)
|
||||||
|
return .ok {
|
||||||
|
nextStateId? := .some nextStateId,
|
||||||
|
goals? := .some goals,
|
||||||
|
}
|
||||||
goal_delete (args: Protocol.GoalDelete): MainM (CR Protocol.GoalDeleteResult) := do
|
goal_delete (args: Protocol.GoalDelete): MainM (CR Protocol.GoalDeleteResult) := do
|
||||||
let state ← get
|
let state ← get
|
||||||
let goalStates := args.stateIds.foldl (λ map id => map.remove id) state.goalStates
|
let goalStates := args.stateIds.foldl (λ map id => map.remove id) state.goalStates
|
||||||
|
|
|
@ -169,27 +169,36 @@ protected def GoalState.tryAssign (state: GoalState) (goalId: Nat) (expr: String
|
||||||
return .failure #[← exception.toMessageData.toString]
|
return .failure #[← exception.toMessageData.toString]
|
||||||
tacticM { elaborator := .anonymous } |>.run' state.savedState.tactic
|
tacticM { elaborator := .anonymous } |>.run' state.savedState.tactic
|
||||||
|
|
||||||
/-- After finishing one branch of a proof (`graftee`), pick up from the point where the proof was left off (`target`) -/
|
/--
|
||||||
protected def GoalState.continue (target: GoalState) (graftee: GoalState): Except String GoalState :=
|
Brings into scope a list of goals
|
||||||
if target.root != graftee.root then
|
-/
|
||||||
.error s!"Roots of two continued goal states do not match: {target.root.name} != {graftee.root.name}"
|
protected def GoalState.resume (state: GoalState) (goals: List MVarId): Except String GoalState :=
|
||||||
-- Ensure goals are not dangling
|
if ¬ (goals.all (λ goal => state.mvars.contains goal)) then
|
||||||
else if ¬ (target.goals.all (λ goal => graftee.mvars.contains goal)) then
|
.error s!"Goals not in scope"
|
||||||
.error s!"Some goals in target are not present in the graftee"
|
|
||||||
else
|
else
|
||||||
-- Set goals to the goals that have not been assigned yet, similar to the `focus` tactic.
|
-- Set goals to the goals that have not been assigned yet, similar to the `focus` tactic.
|
||||||
let unassigned := target.goals.filter (λ goal =>
|
let unassigned := goals.filter (λ goal =>
|
||||||
let mctx := graftee.mctx
|
let mctx := state.mctx
|
||||||
¬(mctx.eAssignment.contains goal || mctx.dAssignment.contains goal))
|
¬(mctx.eAssignment.contains goal || mctx.dAssignment.contains goal))
|
||||||
.ok {
|
.ok {
|
||||||
|
state with
|
||||||
savedState := {
|
savedState := {
|
||||||
term := graftee.savedState.term,
|
term := state.savedState.term,
|
||||||
tactic := { goals := unassigned },
|
tactic := { goals := unassigned },
|
||||||
},
|
},
|
||||||
root := target.root,
|
|
||||||
newMVars := graftee.newMVars,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/--
|
||||||
|
Brings into scope all goals from `branch`
|
||||||
|
-/
|
||||||
|
protected def GoalState.continue (target: GoalState) (branch: GoalState): Except String GoalState :=
|
||||||
|
if !target.goals.isEmpty then
|
||||||
|
.error s!"Target state has unresolved goals"
|
||||||
|
else if target.root != branch.root then
|
||||||
|
.error s!"Roots of two continued goal states do not match: {target.root.name} != {branch.root.name}"
|
||||||
|
else
|
||||||
|
target.resume (goals := branch.goals)
|
||||||
|
|
||||||
protected def GoalState.rootExpr? (goalState: GoalState): Option Expr :=
|
protected def GoalState.rootExpr? (goalState: GoalState): Option Expr :=
|
||||||
let expr := goalState.mctx.eAssignment.find! goalState.root
|
let expr := goalState.mctx.eAssignment.find! goalState.root
|
||||||
let (expr, _) := instantiateMVarsCore (mctx := goalState.mctx) (e := expr)
|
let (expr, _) := instantiateMVarsCore (mctx := goalState.mctx) (e := expr)
|
||||||
|
|
|
@ -163,6 +163,21 @@ structure GoalTacticResult where
|
||||||
-- Existence of this field shows the tactic parsing has failed
|
-- Existence of this field shows the tactic parsing has failed
|
||||||
parseError?: Option String := .none
|
parseError?: Option String := .none
|
||||||
deriving Lean.ToJson
|
deriving Lean.ToJson
|
||||||
|
structure GoalContinue where
|
||||||
|
-- State from which the continuation acquires the context
|
||||||
|
target: Nat
|
||||||
|
|
||||||
|
-- One of the following must be supplied
|
||||||
|
-- The state which is an ancestor of `target` where goals will be extracted from
|
||||||
|
branch?: Option Nat := .none
|
||||||
|
-- Or, the particular goals that should be brought back into scope
|
||||||
|
goals?: Option (List String) := .none
|
||||||
|
deriving Lean.FromJson
|
||||||
|
structure GoalContinueResult where
|
||||||
|
error?: Option String := .none
|
||||||
|
nextStateId?: Option Nat := .none
|
||||||
|
goals?: Option (Array Goal) := .none
|
||||||
|
deriving Lean.ToJson
|
||||||
|
|
||||||
-- Remove goal states
|
-- Remove goal states
|
||||||
structure GoalDelete where
|
structure GoalDelete where
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
namespace Pantograph
|
namespace Pantograph
|
||||||
|
|
||||||
def version := "0.2.7"
|
def version := "0.2.8"
|
||||||
|
|
||||||
end Pantograph
|
end Pantograph
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import Pantograph.Protocol
|
import Pantograph.Protocol
|
||||||
|
import Pantograph.Goal
|
||||||
|
import LSpec
|
||||||
|
|
||||||
namespace Pantograph
|
namespace Pantograph
|
||||||
|
|
||||||
|
@ -15,6 +17,19 @@ def Goal.devolatilize (goal: Goal): Goal :=
|
||||||
v with
|
v with
|
||||||
name := ""
|
name := ""
|
||||||
}
|
}
|
||||||
|
deriving instance DecidableEq, Repr for Expression
|
||||||
|
deriving instance DecidableEq, Repr for Variable
|
||||||
|
deriving instance DecidableEq, Repr for Goal
|
||||||
end Protocol
|
end Protocol
|
||||||
|
|
||||||
|
def TacticResult.toString : TacticResult → String
|
||||||
|
| .success state => s!".success ({state.goals.length} goals)"
|
||||||
|
| .failure messages =>
|
||||||
|
let messages := "\n".intercalate messages.toList
|
||||||
|
s!".failure {messages}"
|
||||||
|
| .parseError error => s!".parseError {error}"
|
||||||
|
| .indexError index => s!".indexError {index}"
|
||||||
|
|
||||||
|
def assertUnreachable (message: String): LSpec.TestSeq := LSpec.check message false
|
||||||
|
|
||||||
end Pantograph
|
end Pantograph
|
||||||
|
|
176
Test/Holes.lean
176
Test/Holes.lean
|
@ -1,31 +1,28 @@
|
||||||
import LSpec
|
import LSpec
|
||||||
import Pantograph.Goal
|
import Pantograph.Goal
|
||||||
import Pantograph.Serial
|
import Pantograph.Serial
|
||||||
|
import Test.Common
|
||||||
|
|
||||||
namespace Pantograph.Test.Holes
|
namespace Pantograph.Test.Holes
|
||||||
open Pantograph
|
open Pantograph
|
||||||
open Lean
|
open Lean
|
||||||
|
|
||||||
abbrev TestM := StateRefT LSpec.TestSeq (ReaderT Commands.Options M)
|
abbrev TestM := StateRefT LSpec.TestSeq (ReaderT Protocol.Options M)
|
||||||
|
|
||||||
deriving instance DecidableEq, Repr for Commands.Expression
|
def addTest (test: LSpec.TestSeq): TestM Unit := do
|
||||||
deriving instance DecidableEq, Repr for Commands.Variable
|
|
||||||
deriving instance DecidableEq, Repr for Commands.Goal
|
|
||||||
|
|
||||||
def add_test (test: LSpec.TestSeq): TestM Unit := do
|
|
||||||
set $ (← get) ++ test
|
set $ (← get) ++ test
|
||||||
|
|
||||||
def start_goal (hole: String): TestM (Option GoalState) := do
|
def startProof (expr: String): TestM (Option GoalState) := do
|
||||||
let env ← Lean.MonadEnv.getEnv
|
let env ← Lean.MonadEnv.getEnv
|
||||||
let syn? := syntax_from_str env hole
|
let syn? := syntax_from_str env expr
|
||||||
add_test $ LSpec.check s!"Parsing {hole}" (syn?.isOk)
|
addTest $ LSpec.check s!"Parsing {expr}" (syn?.isOk)
|
||||||
match syn? with
|
match syn? with
|
||||||
| .error error =>
|
| .error error =>
|
||||||
IO.println error
|
IO.println error
|
||||||
return Option.none
|
return Option.none
|
||||||
| .ok syn =>
|
| .ok syn =>
|
||||||
let expr? ← syntax_to_expr syn
|
let expr? ← syntax_to_expr_type syn
|
||||||
add_test $ LSpec.check s!"Elaborating" expr?.isOk
|
addTest $ LSpec.check s!"Elaborating" expr?.isOk
|
||||||
match expr? with
|
match expr? with
|
||||||
| .error error =>
|
| .error error =>
|
||||||
IO.println error
|
IO.println error
|
||||||
|
@ -34,40 +31,21 @@ def start_goal (hole: String): TestM (Option GoalState) := do
|
||||||
let goal ← GoalState.create (expr := expr)
|
let goal ← GoalState.create (expr := expr)
|
||||||
return Option.some goal
|
return Option.some goal
|
||||||
|
|
||||||
def assert_unreachable (message: String): LSpec.TestSeq := LSpec.check message false
|
def buildGoal (nameType: List (String × String)) (target: String) (userName?: Option String := .none): Protocol.Goal :=
|
||||||
|
|
||||||
def build_goal (nameType: List (String × String)) (target: String): Commands.Goal :=
|
|
||||||
{
|
{
|
||||||
|
userName?,
|
||||||
target := { pp? := .some target},
|
target := { pp? := .some target},
|
||||||
vars := (nameType.map fun x => ({
|
vars := (nameType.map fun x => ({
|
||||||
name := x.fst,
|
userName := x.fst,
|
||||||
type? := .some { pp? := .some x.snd },
|
type? := .some { pp? := .some x.snd },
|
||||||
isInaccessible? := .some false
|
isInaccessible? := .some false
|
||||||
})).toArray
|
})).toArray
|
||||||
}
|
}
|
||||||
-- Like `build_goal` but allow certain variables to be elided.
|
def proofRunner (env: Lean.Environment) (tests: TestM Unit): IO LSpec.TestSeq := do
|
||||||
def build_goal_selective (nameType: List (String × Option String)) (target: String): Commands.Goal :=
|
|
||||||
{
|
|
||||||
target := { pp? := .some target},
|
|
||||||
vars := (nameType.map fun x => ({
|
|
||||||
name := x.fst,
|
|
||||||
type? := x.snd.map (λ type => { pp? := type }),
|
|
||||||
isInaccessible? := x.snd.map (λ _ => false)
|
|
||||||
})).toArray
|
|
||||||
}
|
|
||||||
|
|
||||||
def construct_sigma: TestM Unit := do
|
|
||||||
let goal? ← start_goal "∀ (n m: Nat), n + m = m + n"
|
|
||||||
add_test $ LSpec.check "Start goal" goal?.isSome
|
|
||||||
if let .some goal := goal? then
|
|
||||||
return ()
|
|
||||||
|
|
||||||
|
|
||||||
def proof_runner (env: Lean.Environment) (tests: TestM Unit): IO LSpec.TestSeq := do
|
|
||||||
let termElabM := tests.run LSpec.TestSeq.done |>.run {} -- with default options
|
let termElabM := tests.run LSpec.TestSeq.done |>.run {} -- with default options
|
||||||
|
|
||||||
let coreContext: Lean.Core.Context := {
|
let coreContext: Lean.Core.Context := {
|
||||||
currNamespace := str_to_name "Aniva",
|
currNamespace := Name.append .anonymous "Aniva",
|
||||||
openDecls := [], -- No 'open' directives needed
|
openDecls := [], -- No 'open' directives needed
|
||||||
fileName := "<Pantograph>",
|
fileName := "<Pantograph>",
|
||||||
fileMap := { source := "", positions := #[0], lines := #[1] }
|
fileMap := { source := "", positions := #[0], lines := #[1] }
|
||||||
|
@ -83,17 +61,141 @@ def proof_runner (env: Lean.Environment) (tests: TestM Unit): IO LSpec.TestSeq :
|
||||||
| .ok (_, a) =>
|
| .ok (_, a) =>
|
||||||
return a
|
return a
|
||||||
|
|
||||||
|
/-- M-coupled goals -/
|
||||||
|
def test_m_couple: TestM Unit := do
|
||||||
|
let state? ← startProof "(2: Nat) ≤ 5"
|
||||||
|
let state0 ← match state? with
|
||||||
|
| .some state => pure state
|
||||||
|
| .none => do
|
||||||
|
addTest $ assertUnreachable "Goal could not parse"
|
||||||
|
return ()
|
||||||
|
|
||||||
|
let state1 ← match ← state0.execute (goalId := 0) (tactic := "apply Nat.le_trans") with
|
||||||
|
| .success state => pure state
|
||||||
|
| other => do
|
||||||
|
addTest $ assertUnreachable $ other.toString
|
||||||
|
return ()
|
||||||
|
addTest $ LSpec.check "apply Nat.le_trans" ((← state1.serializeGoals (options := ← read)).map (·.target.pp?) =
|
||||||
|
#[.some "2 ≤ ?m", .some "?m ≤ 5", .some "Nat"])
|
||||||
|
addTest $ LSpec.test "(1 root)" state1.rootExpr?.isNone
|
||||||
|
-- Set m to 3
|
||||||
|
let state2 ← match ← state1.execute (goalId := 2) (tactic := "exact 3") with
|
||||||
|
| .success state => pure state
|
||||||
|
| other => do
|
||||||
|
addTest $ assertUnreachable $ other.toString
|
||||||
|
return ()
|
||||||
|
addTest $ LSpec.test "(1b root)" state2.rootExpr?.isNone
|
||||||
|
let state1b ← match state2.continue state1 with
|
||||||
|
| .error msg => do
|
||||||
|
addTest $ assertUnreachable $ msg
|
||||||
|
return ()
|
||||||
|
| .ok state => pure state
|
||||||
|
addTest $ LSpec.check "exact 3" ((← state1b.serializeGoals (options := ← read)).map (·.target.pp?) =
|
||||||
|
#[.some "2 ≤ 3", .some "3 ≤ 5"])
|
||||||
|
addTest $ LSpec.test "(2 root)" state1b.rootExpr?.isNone
|
||||||
|
return ()
|
||||||
|
|
||||||
|
def test_proposition_generation: TestM Unit := do
|
||||||
|
let state? ← startProof "Σ' p:Prop, p"
|
||||||
|
let state0 ← match state? with
|
||||||
|
| .some state => pure state
|
||||||
|
| .none => do
|
||||||
|
addTest $ assertUnreachable "Goal could not parse"
|
||||||
|
return ()
|
||||||
|
|
||||||
|
let state1 ← match ← state0.execute (goalId := 0) (tactic := "apply PSigma.mk") with
|
||||||
|
| .success state => pure state
|
||||||
|
| other => do
|
||||||
|
addTest $ assertUnreachable $ other.toString
|
||||||
|
return ()
|
||||||
|
addTest $ LSpec.check "apply PSigma.mk" ((← state1.serializeGoals (options := ← read)).map (·.devolatilize) =
|
||||||
|
#[
|
||||||
|
buildGoal [] "?fst" (userName? := .some "snd"),
|
||||||
|
buildGoal [] "Prop" (userName? := .some "fst")
|
||||||
|
])
|
||||||
|
if let #[goal1, goal2] := ← state1.serializeGoals (options := { (← read) with printExprAST := true }) then
|
||||||
|
addTest $ LSpec.test "(1 reference)" (goal1.target.sexp? = .some s!"(:mv {goal2.name})")
|
||||||
|
addTest $ LSpec.test "(1 root)" state1.rootExpr?.isNone
|
||||||
|
|
||||||
|
let state2 ← match ← state1.tryAssign (goalId := 0) (expr := "λ (x: Nat) => _") with
|
||||||
|
| .success state => pure state
|
||||||
|
| other => do
|
||||||
|
addTest $ assertUnreachable $ other.toString
|
||||||
|
return ()
|
||||||
|
addTest $ LSpec.check ":= λ (x: Nat), _" ((← state2.serializeGoals (options := ← read)).map (·.target.pp?) =
|
||||||
|
#[.some "Nat → Prop", .some "∀ (x : Nat), ?m.29 x"])
|
||||||
|
addTest $ LSpec.test "(2 root)" state2.rootExpr?.isNone
|
||||||
|
|
||||||
|
let state3 ← match ← state2.tryAssign (goalId := 1) (expr := "fun x => Eq.refl x") with
|
||||||
|
| .success state => pure state
|
||||||
|
| other => do
|
||||||
|
addTest $ assertUnreachable $ other.toString
|
||||||
|
return ()
|
||||||
|
addTest $ LSpec.check ":= Eq.refl" ((← state3.serializeGoals (options := ← read)).map (·.target.pp?) =
|
||||||
|
#[])
|
||||||
|
|
||||||
|
addTest $ LSpec.test "(3 root)" state3.rootExpr?.isSome
|
||||||
|
return ()
|
||||||
|
|
||||||
|
def test_partial_continuation: TestM Unit := do
|
||||||
|
let state? ← startProof "(2: Nat) ≤ 5"
|
||||||
|
let state0 ← match state? with
|
||||||
|
| .some state => pure state
|
||||||
|
| .none => do
|
||||||
|
addTest $ assertUnreachable "Goal could not parse"
|
||||||
|
return ()
|
||||||
|
|
||||||
|
let state1 ← match ← state0.execute (goalId := 0) (tactic := "apply Nat.le_trans") with
|
||||||
|
| .success state => pure state
|
||||||
|
| other => do
|
||||||
|
addTest $ assertUnreachable $ other.toString
|
||||||
|
return ()
|
||||||
|
addTest $ LSpec.check "apply Nat.le_trans" ((← state1.serializeGoals (options := ← read)).map (·.target.pp?) =
|
||||||
|
#[.some "2 ≤ ?m", .some "?m ≤ 5", .some "Nat"])
|
||||||
|
|
||||||
|
let state2 ← match ← state1.execute (goalId := 2) (tactic := "apply Nat.succ") with
|
||||||
|
| .success state => pure state
|
||||||
|
| other => do
|
||||||
|
addTest $ assertUnreachable $ other.toString
|
||||||
|
return ()
|
||||||
|
addTest $ LSpec.check "apply Nat.succ" ((← state2.serializeGoals (options := ← read)).map (·.target.pp?) =
|
||||||
|
#[.some "Nat"])
|
||||||
|
|
||||||
|
-- Execute a partial continuation
|
||||||
|
let coupled_goals := state1.goals ++ state2.goals
|
||||||
|
let state1b ← match state2.resume (goals := coupled_goals) with
|
||||||
|
| .error msg => do
|
||||||
|
addTest $ assertUnreachable $ msg
|
||||||
|
return ()
|
||||||
|
| .ok state => pure state
|
||||||
|
addTest $ LSpec.check "(continue)" ((← state1b.serializeGoals (options := ← read)).map (·.target.pp?) =
|
||||||
|
#[.some "2 ≤ Nat.succ ?m", .some "Nat.succ ?m ≤ 5", .some "Nat"])
|
||||||
|
addTest $ LSpec.test "(2 root)" state1b.rootExpr?.isNone
|
||||||
|
|
||||||
|
-- Continuation should fail if the state does not exist:
|
||||||
|
match state0.resume coupled_goals with
|
||||||
|
| .error error => addTest $ LSpec.check "(continuation failure message)" (error = "Goals not in scope")
|
||||||
|
| .ok _ => addTest $ assertUnreachable "(continuation failure)"
|
||||||
|
-- Continuation should fail if some goals have not been solved
|
||||||
|
match state2.continue state1 with
|
||||||
|
| .error error => addTest $ LSpec.check "(continuation failure message)" (error = "Target state has unresolved goals")
|
||||||
|
| .ok _ => addTest $ assertUnreachable "(continuation failure)"
|
||||||
|
return ()
|
||||||
|
|
||||||
|
|
||||||
def suite: IO LSpec.TestSeq := do
|
def suite: IO LSpec.TestSeq := do
|
||||||
let env: Lean.Environment ← Lean.importModules
|
let env: Lean.Environment ← Lean.importModules
|
||||||
(imports := #["Init"].map (λ str => { module := str_to_name str, runtimeOnly := false }))
|
(imports := #["Init"].map (λ str => { module := str_to_name str, runtimeOnly := false }))
|
||||||
(opts := {})
|
(opts := {})
|
||||||
(trustLevel := 1)
|
(trustLevel := 1)
|
||||||
let tests := [
|
let tests := [
|
||||||
("Σ'", construct_sigma)
|
("2 < 5", test_m_couple),
|
||||||
|
("Proposition Generation", test_proposition_generation),
|
||||||
|
("Partial Continuation", test_partial_continuation)
|
||||||
]
|
]
|
||||||
let tests ← tests.foldlM (fun acc tests => do
|
let tests ← tests.foldlM (fun acc tests => do
|
||||||
let (name, tests) := tests
|
let (name, tests) := tests
|
||||||
let tests ← proof_runner env tests
|
let tests ← proofRunner env tests
|
||||||
return acc ++ (LSpec.group name tests)) LSpec.TestSeq.done
|
return acc ++ (LSpec.group name tests)) LSpec.TestSeq.done
|
||||||
|
|
||||||
return LSpec.group "Holes" tests
|
return LSpec.group "Holes" tests
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import LSpec
|
import LSpec
|
||||||
--import Test.Holes
|
import Test.Holes
|
||||||
import Test.Integration
|
import Test.Integration
|
||||||
import Test.Proofs
|
import Test.Proofs
|
||||||
import Test.Serial
|
import Test.Serial
|
||||||
|
@ -11,7 +11,7 @@ unsafe def main := do
|
||||||
Lean.initSearchPath (← Lean.findSysroot)
|
Lean.initSearchPath (← Lean.findSysroot)
|
||||||
|
|
||||||
let suites := [
|
let suites := [
|
||||||
--Holes.suite,
|
Holes.suite,
|
||||||
Integration.suite,
|
Integration.suite,
|
||||||
Proofs.suite,
|
Proofs.suite,
|
||||||
Serial.suite
|
Serial.suite
|
||||||
|
|
|
@ -6,17 +6,6 @@ import Pantograph.Goal
|
||||||
import Pantograph.Serial
|
import Pantograph.Serial
|
||||||
import Test.Common
|
import Test.Common
|
||||||
|
|
||||||
namespace Pantograph
|
|
||||||
|
|
||||||
def TacticResult.toString : TacticResult → String
|
|
||||||
| .success state => s!".success ({state.goals.length} goals)"
|
|
||||||
| .failure messages =>
|
|
||||||
let messages := "\n".intercalate messages.toList
|
|
||||||
s!".failure {messages}"
|
|
||||||
| .parseError error => s!".parseError {error}"
|
|
||||||
| .indexError index => s!".indexError {index}"
|
|
||||||
end Pantograph
|
|
||||||
|
|
||||||
namespace Pantograph.Test.Proofs
|
namespace Pantograph.Test.Proofs
|
||||||
open Pantograph
|
open Pantograph
|
||||||
open Lean
|
open Lean
|
||||||
|
@ -27,10 +16,6 @@ inductive Start where
|
||||||
|
|
||||||
abbrev TestM := StateRefT LSpec.TestSeq (ReaderT Protocol.Options M)
|
abbrev TestM := StateRefT LSpec.TestSeq (ReaderT Protocol.Options M)
|
||||||
|
|
||||||
deriving instance DecidableEq, Repr for Protocol.Expression
|
|
||||||
deriving instance DecidableEq, Repr for Protocol.Variable
|
|
||||||
deriving instance DecidableEq, Repr for Protocol.Goal
|
|
||||||
|
|
||||||
def addTest (test: LSpec.TestSeq): TestM Unit := do
|
def addTest (test: LSpec.TestSeq): TestM Unit := do
|
||||||
set $ (← get) ++ test
|
set $ (← get) ++ test
|
||||||
|
|
||||||
|
@ -64,8 +49,6 @@ def startProof (start: Start): TestM (Option GoalState) := do
|
||||||
let goal ← GoalState.create (expr := expr)
|
let goal ← GoalState.create (expr := expr)
|
||||||
return Option.some goal
|
return Option.some goal
|
||||||
|
|
||||||
def assertUnreachable (message: String): LSpec.TestSeq := LSpec.check message false
|
|
||||||
|
|
||||||
def buildGoal (nameType: List (String × String)) (target: String) (userName?: Option String := .none): Protocol.Goal :=
|
def buildGoal (nameType: List (String × String)) (target: String) (userName?: Option String := .none): Protocol.Goal :=
|
||||||
{
|
{
|
||||||
userName?,
|
userName?,
|
||||||
|
@ -270,7 +253,7 @@ def proof_or_comm: TestM Unit := do
|
||||||
addTest $ LSpec.check " assumption" state4_2.goals.isEmpty
|
addTest $ LSpec.check " assumption" state4_2.goals.isEmpty
|
||||||
addTest $ LSpec.check "(4_2 root)" state4_2.rootExpr?.isNone
|
addTest $ LSpec.check "(4_2 root)" state4_2.rootExpr?.isNone
|
||||||
-- Ensure the proof can continue from `state4_2`.
|
-- Ensure the proof can continue from `state4_2`.
|
||||||
let state2b ← match state2.continue state4_2 with
|
let state2b ← match state4_2.continue state2 with
|
||||||
| .error msg => do
|
| .error msg => do
|
||||||
addTest $ assertUnreachable $ msg
|
addTest $ assertUnreachable $ msg
|
||||||
return ()
|
return ()
|
||||||
|
@ -303,80 +286,6 @@ def proof_or_comm: TestM Unit := do
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
/-- M-coupled goals -/
|
|
||||||
def proof_m_couple: TestM Unit := do
|
|
||||||
let state? ← startProof (.expr "(2: Nat) ≤ 5")
|
|
||||||
let state0 ← match state? with
|
|
||||||
| .some state => pure state
|
|
||||||
| .none => do
|
|
||||||
addTest $ assertUnreachable "Goal could not parse"
|
|
||||||
return ()
|
|
||||||
|
|
||||||
let state1 ← match ← state0.execute (goalId := 0) (tactic := "apply Nat.le_trans") with
|
|
||||||
| .success state => pure state
|
|
||||||
| other => do
|
|
||||||
addTest $ assertUnreachable $ other.toString
|
|
||||||
return ()
|
|
||||||
addTest $ LSpec.check "apply Nat.le_trans" ((← state1.serializeGoals (options := ← read)).map (·.target.pp?) =
|
|
||||||
#[.some "2 ≤ ?m", .some "?m ≤ 5", .some "Nat"])
|
|
||||||
addTest $ LSpec.test "(1 root)" state1.rootExpr?.isNone
|
|
||||||
-- Set m to 3
|
|
||||||
let state2 ← match ← state1.execute (goalId := 2) (tactic := "exact 3") with
|
|
||||||
| .success state => pure state
|
|
||||||
| other => do
|
|
||||||
addTest $ assertUnreachable $ other.toString
|
|
||||||
return ()
|
|
||||||
addTest $ LSpec.test "(1b root)" state2.rootExpr?.isNone
|
|
||||||
let state1b ← match state1.continue state2 with
|
|
||||||
| .error msg => do
|
|
||||||
addTest $ assertUnreachable $ msg
|
|
||||||
return ()
|
|
||||||
| .ok state => pure state
|
|
||||||
addTest $ LSpec.check "exact 3" ((← state1b.serializeGoals (options := ← read)).map (·.target.pp?) =
|
|
||||||
#[.some "2 ≤ 3", .some "3 ≤ 5"])
|
|
||||||
addTest $ LSpec.test "(2 root)" state1b.rootExpr?.isNone
|
|
||||||
return ()
|
|
||||||
|
|
||||||
def proof_proposition_generation: TestM Unit := do
|
|
||||||
let state? ← startProof (.expr "Σ' p:Prop, p")
|
|
||||||
let state0 ← match state? with
|
|
||||||
| .some state => pure state
|
|
||||||
| .none => do
|
|
||||||
addTest $ assertUnreachable "Goal could not parse"
|
|
||||||
return ()
|
|
||||||
|
|
||||||
let state1 ← match ← state0.execute (goalId := 0) (tactic := "apply PSigma.mk") with
|
|
||||||
| .success state => pure state
|
|
||||||
| other => do
|
|
||||||
addTest $ assertUnreachable $ other.toString
|
|
||||||
return ()
|
|
||||||
addTest $ LSpec.check "apply PSigma.mk" ((← state1.serializeGoals (options := ← read)).map (·.devolatilize) =
|
|
||||||
#[
|
|
||||||
buildGoal [] "?fst" (userName? := .some "snd"),
|
|
||||||
buildGoal [] "Prop" (userName? := .some "fst")
|
|
||||||
])
|
|
||||||
if let #[goal1, goal2] := ← state1.serializeGoals (options := { (← read) with printExprAST := true }) then
|
|
||||||
addTest $ LSpec.test "(1 reference)" (goal1.target.sexp? = .some s!"(:mv {goal2.name})")
|
|
||||||
addTest $ LSpec.test "(1 root)" state1.rootExpr?.isNone
|
|
||||||
|
|
||||||
let state2 ← match ← state1.tryAssign (goalId := 0) (expr := "λ (x: Nat) => _") with
|
|
||||||
| .success state => pure state
|
|
||||||
| other => do
|
|
||||||
addTest $ assertUnreachable $ other.toString
|
|
||||||
return ()
|
|
||||||
addTest $ LSpec.check ":= λ (x: Nat), _" ((← state2.serializeGoals (options := ← read)).map (·.target.pp?) =
|
|
||||||
#[.some "Nat → Prop", .some "∀ (x : Nat), ?m.29 x"])
|
|
||||||
addTest $ LSpec.test "(2 root)" state2.rootExpr?.isNone
|
|
||||||
|
|
||||||
let state3 ← match ← state2.tryAssign (goalId := 1) (expr := "fun x => Eq.refl x") with
|
|
||||||
| .success state => pure state
|
|
||||||
| other => do
|
|
||||||
addTest $ assertUnreachable $ other.toString
|
|
||||||
return ()
|
|
||||||
addTest $ LSpec.check ":= Eq.refl" ((← state3.serializeGoals (options := ← read)).map (·.target.pp?) =
|
|
||||||
#[])
|
|
||||||
addTest $ LSpec.test "(3 root)" state3.rootExpr?.isSome
|
|
||||||
return ()
|
|
||||||
|
|
||||||
def suite: IO LSpec.TestSeq := do
|
def suite: IO LSpec.TestSeq := do
|
||||||
let env: Lean.Environment ← Lean.importModules
|
let env: Lean.Environment ← Lean.importModules
|
||||||
|
@ -388,9 +297,7 @@ def suite: IO LSpec.TestSeq := do
|
||||||
("Nat.add_comm manual", proof_nat_add_comm true),
|
("Nat.add_comm manual", proof_nat_add_comm true),
|
||||||
("Nat.add_comm delta", proof_delta_variable),
|
("Nat.add_comm delta", proof_delta_variable),
|
||||||
("arithmetic", proof_arith),
|
("arithmetic", proof_arith),
|
||||||
("Or.comm", proof_or_comm),
|
("Or.comm", proof_or_comm)
|
||||||
("2 < 5", proof_m_couple),
|
|
||||||
("Proposition Generation", proof_proposition_generation)
|
|
||||||
]
|
]
|
||||||
let tests ← tests.foldlM (fun acc tests => do
|
let tests ← tests.foldlM (fun acc tests => do
|
||||||
let (name, tests) := tests
|
let (name, tests) := tests
|
||||||
|
|
Loading…
Reference in New Issue