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))
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.

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

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.

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

struct Goal

 struct Goal
   ?
   ?
   ?

A goal value: the target, its local hypotheses, and the opaque handle the elaborator uses to find the checked goal this value describes.

struct Hypothesis

 struct Hypothesis
   ?
   ?

One local hypothesis: the name the author can refer to, and its type.

Functions

apply(g: Goal, proof: Syntax) -> Syntax

 fn apply(g: Goal, proof: Syntax) -> Syntax

apply proof at g.

assumption(g: Goal) -> Syntax

 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.

atom_eq(left: Atom, right: Atom) -> Bool

 fn atom_eq(left: Atom, right: Atom) -> Bool

Structural equality on Atom values.

characters(value: String) -> List(Char)

 fn characters(value: String) -> List(Char)

Unwrap the underlying character list from a String.

characters_eq(left: List(Char), right: List(Char)) -> Bool

 fn characters_eq(left: List(Char), right: List(Char)) -> Bool

Structural elementwise equality on two character lists.

count(values: List(a)) -> Nat

 fn count(values: List(a)) -> Nat

-- Small helpers --------------------------------------------------------

Count the elements of a list as a Nat.

decide(g: Goal) -> Syntax

 fn decide(g: Goal) -> Syntax

by decide at g: infer the certified Boolean-equality decider.

decide_using(g: Goal, decision: Syntax) -> Syntax

 fn decide_using(g: Goal, decision: Syntax) -> Syntax

by decide using decision at g.

exact(g: Goal, proof: Syntax) -> Syntax

 fn exact(g: Goal, proof: Syntax) -> Syntax

exact proof at g.

ext(g: Goal) -> Syntax

 fn ext(g: Goal) -> Syntax

by ext at g: structural constructor congruence and registered @ext lemmas.

goal_hypotheses(g: Goal) -> List(Hypothesis)

 fn goal_hypotheses(g: Goal) -> List(Hypothesis)

The local hypotheses of g, most recent first.

goal_target(g: Goal) -> Syntax

 fn goal_target(g: Goal) -> Syntax

The target proposition of g.

has_hypothesis(g: Goal, name: String) -> Bool

 fn has_hypothesis(g: Goal, name: String) -> Bool

Whether a local hypothesis with exactly this name is in scope.

has_hypothesis_in(hypotheses: List(Hypothesis), name: String) -> Bool

 fn has_hypothesis_in(hypotheses: List(Hypothesis), name: String) -> Bool

Check whether a list of hypotheses contains one with the given name.

hypothesis_count(g: Goal) -> Nat

 fn hypothesis_count(g: Goal) -> Nat

How many local hypotheses are in scope.

hypothesis_is(g: Goal, hypothesis: String, name: Atom) -> Bool

 fn hypothesis_is(g: Goal, hypothesis: String, name: Atom) -> Bool

Whether the named hypothesis's type has head constructor name.

hypothesis_name(h: Hypothesis) -> String

 fn hypothesis_name(h: Hypothesis) -> String

The name of a hypothesis.

hypothesis_type(h: Hypothesis) -> Syntax

 fn hypothesis_type(h: Hypothesis) -> Syntax

The type of a hypothesis.

hypothesis_type_of(g: Goal, name: String) -> Option(Syntax)

 fn hypothesis_type_of(g: Goal, name: String) -> Option(Syntax)

The type of the named hypothesis, when it is in scope.

is_equality(g: Goal) -> Bool

 fn is_equality(g: Goal) -> Bool

Whether the goal is a propositional equality (Equivalent).

is_head(g: Goal, name: Atom) -> Bool

 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().

lookup_hypothesis(hypotheses: List(Hypothesis), name: String) -> Option(Syntax)

 fn lookup_hypothesis(hypotheses: List(Hypothesis), name: String) -> Option(Syntax)

Find the type of the first hypothesis in hypotheses matching name.

omega(g: Goal) -> Syntax

 fn omega(g: Goal) -> Syntax

by omega at g: the bounded, checked IntOrder and Nat order fragments.

operation(kind: Atom, g: Goal, arguments: List(Syntax)) -> Syntax

 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.

positivity(g: Goal) -> Syntax

 fn positivity(g: Goal) -> Syntax

by positivity at g: the curated natural-number sign fragment.

reject_goal(reason: String) -> MacroResult

 fn reject_goal(reason: String) -> MacroResult

Refuse the goal with a diagnostic of the expander's own making.

reject_with(reason: String, hint: String) -> MacroResult

 fn reject_with(reason: String, hint: String) -> MacroResult

Refuse the goal with a reason and a repair hint.

rewrite(g: Goal, proof: Syntax) -> Syntax

 fn rewrite(g: Goal, proof: Syntax) -> Syntax

rewrite using proof at g (forward, single occurrence).

rewrite_all(g: Goal, proof: Syntax) -> Syntax

 fn rewrite_all(g: Goal, proof: Syntax) -> Syntax

rewrite using proof all at g: every original occurrence.

rewrite_backwards(g: Goal, proof: Syntax) -> Syntax

 fn rewrite_backwards(g: Goal, proof: Syntax) -> Syntax

rewrite backwards using proof at g.

ring(g: Goal) -> Syntax

 fn ring(g: Goal) -> Syntax

by ring at g: commutative-semiring normalization over Std.Nat equalities.

search(g: Goal) -> Syntax

 fn search(g: Goal) -> Syntax

by search at g: local evidence, checked projections, tagged lemmas.

simplify(g: Goal) -> Syntax

 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.

simplify_using(g: Goal, rules: List(Syntax)) -> Syntax

 fn simplify_using(g: Goal, rules: List(Syntax)) -> Syntax

simplify using [rules] at g, with the rules named by the expander.

string_eq(left: String, right: String) -> Bool

 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.