Std.Tactic
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.
Example
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))
end
Limits
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.
Functions
-
# fn apply(g: Goal, proof: Syntax) -> Syntax
apply proofatg. -
# fn assumption(g: Goal) -> Syntax
by assumptionatg: close with a local hypothesis whose type is the goal. Deliberately narrower thansearch-- 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
-
# fn characters(value: String) -> List(Char)
-
# fn characters_eq(left: List(Char), right: List(Char)) -> Bool
-
# fn count(values: List(a)) -> Nat
-- Small helpers --------------------------------------------------------
-
# fn decide(g: Goal) -> Syntax
by decideatg: infer the certified Boolean-equality decider. -
# fn decide_using(g: Goal, decision: Syntax) -> Syntax
by decide using decisionatg. -
# fn exact(g: Goal, proof: Syntax) -> Syntax
exact proofatg. -
# 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
-
# 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 anEquivalent(…)proposition. A target that is a variable or a literal has no head and answersFalse(). -
# fn lookup_hypothesis(hypotheses: List(Hypothesis), name: String) -> Option(Syntax)
-
# fn omega(g: Goal) -> Syntax
by omegaatg: the bounded, checked non-strict IntOrder fragment. -
# 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 positivityatg: 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 proofatg(forward, single occurrence). -
# fn rewrite_all(g: Goal, proof: Syntax) -> Syntax
rewrite using proof allatg: every original occurrence. -
# fn rewrite_backwards(g: Goal, proof: Syntax) -> Syntax
rewrite backwards using proofatg. -
# fn search(g: Goal) -> Syntax
by searchatg: 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
gand kernel-checks the result at the original goal.simplifyatg: beta, iota, zeta, certified delta, and the ambient@simpset. -
# fn simplify_using(g: Goal, rules: List(Syntax)) -> Syntax
simplify using [rules]atg, with the rules named by the expander. -
# fn string_eq(left: String, right: String) -> Bool
String equality through the structural primitive, so
Std.Tacticneeds noEquatableinstance in scope at the expander's use site.Stringis nominally a character list, so the comparison is on its characters -- the same loweringStd.String's ownEquatableinstance uses.