Std. Tactic
(Cure Standard Library v0.37.2)
View Source
Goal inspection for computed proof tactics.
This is the goal analogue of Std.Syntax. A tactic ... computed by
expander written over this module receives a goal value and can decide
what to do from what it sees, instead of expanding captures into a fixed
script.
What a goal value is
Goal carries the current proof state in a form ordinary Cure code can
inspect: the target proposition, the local hypotheses in scope, and an
opaque state handle that ties the value to the elaborator's checked goal.
The handle is not a proof and carries no evidence; it is only a key.
Every operation below is therefore a request, never a proof step.
The firewall
Nothing here produces evidence. Each operation names an existing checked
proof command (simplify, rewrite using e, by search, ...); the
elaborator runs that command against the goal the handle names and
kernel-checks the resulting evidence at the ORIGINAL goal. A tactic that
asks for the wrong thing gets a diagnostic, not a proof. reject_goal
exists so an expander can refuse in its own words.
Examples
mod MyTactics
use Std.Tactic
use Std.Syntax
use Std.Bool
macro Tactics
tactic close computed by close_goal
fn close_goal(g: Goal) -> MacroResult = match is_equality(g)
True() -> expand(Std.Tactic.simplify(g))
False() -> expand(Std.Tactic.search(g))
endLimits
A goal value exposes its target and hypotheses as quoted Syntax, which is
what an expander can pattern-match on. It does not expose a kernel term, a
proof object, or a way to build evidence directly: those would be a second,
unchecked path into the kernel. Operations run in the order the expander
emits them, and a failed operation fails the whole expansion.
Structural inspection schema
Family and constructor applications are Node(short_name, attrs, children).
attrs includes KV(:name, SAtom(qualified_name)); family applications
additionally carry KV(:parameters, SInt(parameter_count)), and children
are parameters followed by indices. Thus Equivalent(Int, x, y) has tag
:Equivalent and three children. Qualified identity stays available in
:name; short head matching is an inspection convenience, not evidence.
A local variable is Leaf(:variable, [KV(:index, SInt(index))], SStr(name)),
using its authored context name. Globals are Leaf(:global, attrs, SAtom(name)).
Other Core forms are Nodes tagged with their form (:app, :pi, :lam,
:let, :case, literal form, or effect form), with structural children;
scalar children use Raw literals and lists use Node(:list, [], children).
Pi/lambda/let and case-branch bodies introduce the synthetic inspection
name $binder. Case nodes hold scrutinee, motive, then :branch Nodes
carrying :name and :arity attributes and their body child.
This is an inspection schema, not parser syntax to use as proof evidence.
A callback takes one Syntax argument per capture, in declaration order,
followed by a typed Goal. Return expand(operation) or
expand(Node(:list, [], operations)). MacroResult is already unwrapped by
the executor; reject_goal preserves author diagnostics. Every operation
must retain the supplied Goal's state handle, including custom requests
made with operation. State handles from other invocations are refused.
At most 256 requests may be returned. Operation arguments cannot generate
another deferred computed use: compose ordinary checked commands instead.
Invoke a rule in a because block, or use by close as a checked function
body. Qualify Std.Tactic.simplify(g) to distinguish the helper function
from the contextual proof command. apply can open ordered premises;
following operations focus the first one, and dependent domains become
available after their earlier witnesses close. Unresolved implicit
witnesses are explicit typed obligations, not automatic proof search.
An imported bare callback reference requires a single-module provider file.
Multi-module homes must use an explicitly qualified callback reference;
an unavailable or ambiguous canonical provider is refused, never guessed.
Summary
Types
A goal value: the target, its local hypotheses, and the opaque handle the elaborator uses to find the checked goal this value describes.
One local hypothesis: the name the author can refer to, and its type.
Functions
apply proof at g.
by assumption at g: close with a local hypothesis whose type is the
goal. Deliberately narrower than search -- it consults no lemmas and no
projections, so its outcome is predictable from the goal state alone.
Structural equality on Atom values.
Unwrap the underlying character list from a String.
Structural elementwise equality on two character lists.
-- Small helpers --------------------------------------------------------
by decide at g: infer the certified Boolean-equality decider.
by decide using decision at g.
exact proof at g.
by ext at g: structural constructor congruence and registered @ext lemmas.
The local hypotheses of g, most recent first.
The target proposition of g.
Whether a local hypothesis with exactly this name is in scope.
Check whether a list of hypotheses contains one with the given name.
How many local hypotheses are in scope.
Whether the named hypothesis's type has head constructor name.
The name of a hypothesis.
The type of a hypothesis.
The type of the named hypothesis, when it is in scope.
Whether the goal is a propositional equality (Equivalent).
Whether the target's head constructor is named name.
Find the type of the first hypothesis in hypotheses matching name.
by omega at g: the bounded, checked IntOrder and Nat order fragments.
Build the operation request node. The elaborator validates the name against its own closed vocabulary; an unknown name is a diagnostic, never a silent no-op.
by positivity at g: the curated natural-number sign fragment.
Refuse the goal with a diagnostic of the expander's own making.
Refuse the goal with a reason and a repair hint.
rewrite using proof at g (forward, single occurrence).
rewrite using proof all at g: every original occurrence.
rewrite backwards using proof at g.
by ring at g: commutative-semiring normalization over Std.Nat equalities.
by search at g: local evidence, checked projections, tagged lemmas.
-- Operations -----------------------------------------------------------
simplify using [rules] at g, with the rules named by the expander.
String equality through the structural primitive, so Std.Tactic needs no
Equatable instance in scope at the expander's use site. String is
nominally a character list, so the comparison is on its characters -- the
same lowering Std.String's own Equatable instance uses.
Types
Functions
fn apply(g: Goal, proof: Syntax) -> Syntax
apply proof at g.
fn assumption(g: Goal) -> Syntax
by assumption at g: close with a local hypothesis whose type is the
goal. Deliberately narrower than search -- it consults no lemmas and no
projections, so its outcome is predictable from the goal state alone.
fn atom_eq(left: Atom, right: Atom) -> Bool
Structural equality on Atom values.
fn characters(value: String) -> List(Char)
Unwrap the underlying character list from a String.
fn characters_eq(left: List(Char), right: List(Char)) -> Bool
Structural elementwise equality on two character lists.
fn count(values: List(a)) -> Nat
-- Small helpers --------------------------------------------------------
Count the elements of a list as a Nat.
fn decide(g: Goal) -> Syntax
by decide at g: infer the certified Boolean-equality decider.
fn decide_using(g: Goal, decision: Syntax) -> Syntax
by decide using decision at g.
fn exact(g: Goal, proof: Syntax) -> Syntax
exact proof at g.
fn ext(g: Goal) -> Syntax
by ext at g: structural constructor congruence and registered @ext lemmas.
fn goal_hypotheses(g: Goal) -> List(Hypothesis)
The local hypotheses of g, most recent first.
fn goal_target(g: Goal) -> Syntax
The target proposition of g.
fn has_hypothesis(g: Goal, name: String) -> Bool
Whether a local hypothesis with exactly this name is in scope.
fn has_hypothesis_in(hypotheses: List(Hypothesis), name: String) -> Bool
Check whether a list of hypotheses contains one with the given name.
fn hypothesis_count(g: Goal) -> Nat
How many local hypotheses are in scope.
fn hypothesis_is(g: Goal, hypothesis: String, name: Atom) -> Bool
Whether the named hypothesis's type has head constructor name.
fn hypothesis_name(h: Hypothesis) -> String
The name of a hypothesis.
fn hypothesis_type(h: Hypothesis) -> Syntax
The type of a hypothesis.
fn hypothesis_type_of(g: Goal, name: String) -> Option(Syntax)
The type of the named hypothesis, when it is in scope.
fn is_equality(g: Goal) -> Bool
Whether the goal is a propositional equality (Equivalent).
fn is_head(g: Goal, name: Atom) -> Bool
Whether the target's head constructor is named name.
The comparison is on the target's own head tag, so is_head(g, :Equivalent)
holds exactly when the goal is an Equivalent(…) proposition. A target that
is a variable or a literal has no head and answers False().
fn lookup_hypothesis(hypotheses: List(Hypothesis), name: String) -> Option(Syntax)
Find the type of the first hypothesis in hypotheses matching name.
fn omega(g: Goal) -> Syntax
by omega at g: the bounded, checked IntOrder and Nat order fragments.
fn operation(kind: Atom, g: Goal, arguments: List(Syntax)) -> Syntax
Build the operation request node. The elaborator validates the name against its own closed vocabulary; an unknown name is a diagnostic, never a silent no-op.
fn positivity(g: Goal) -> Syntax
by positivity at g: the curated natural-number sign fragment.
fn reject_goal(reason: String) -> MacroResult
Refuse the goal with a diagnostic of the expander's own making.
fn reject_with(reason: String, hint: String) -> MacroResult
Refuse the goal with a reason and a repair hint.
fn rewrite(g: Goal, proof: Syntax) -> Syntax
rewrite using proof at g (forward, single occurrence).
fn rewrite_all(g: Goal, proof: Syntax) -> Syntax
rewrite using proof all at g: every original occurrence.
fn rewrite_backwards(g: Goal, proof: Syntax) -> Syntax
rewrite backwards using proof at g.
fn ring(g: Goal) -> Syntax
by ring at g: commutative-semiring normalization over Std.Nat equalities.
fn search(g: Goal) -> Syntax
by search at g: local evidence, checked projections, tagged lemmas.
fn simplify(g: Goal) -> Syntax
-- Operations -----------------------------------------------------------
Each operation names one existing checked proof command. The elaborator
runs it against g and kernel-checks the result at the original goal.
simplify at g: beta, iota, zeta, certified delta, and the ambient
@simp set.
fn simplify_using(g: Goal, rules: List(Syntax)) -> Syntax
simplify using [rules] at g, with the rules named by the expander.
fn string_eq(left: String, right: String) -> Bool
String equality through the structural primitive, so Std.Tactic needs no
Equatable instance in scope at the expander's use site. String is
nominally a character list, so the comparison is on its characters -- the
same lowering Std.String's own Equatable instance uses.