lean4-htt/tests/elab/cbv_at.lean
Wojciech Różowski 7ca47aad7d
feat: add cbv at location syntax (#12773)
This PR adds `at` location syntax to the `cbv` tactic, matching the
interface of `simp at`. Previously `cbv` could only reduce the goal
target; now it supports `cbv at h`, `cbv at h |-`, and `cbv at *`.

`cbvGoal` is rewritten to use `Sym.preprocessMVar` followed by `cbvCore`
within a single `SymM` context, sharing the term table across all
hypotheses and the target. The old `cbvGoalCore` (which reduced one side
of an equation goal at a time) is replaced by a general approach that
reduces arbitrary goal types and hypothesis types, with special handling
for `True` targets and `False` hypotheses. `cbvDecideGoal` is updated to
use the extracted `cbvCore` as well.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 16:12:07 +00:00

64 lines
1.3 KiB
Text

set_option cbv.warning false
set_option linter.unusedVariables false
example : 2 + 3 = 5 := by cbv
example : (fun x => x + 1) 3 = 4 := by cbv
def foo : Nat := 42
example : foo = 42 := by cbv
-- Bare `cbv` on non-equation goals (new: reduces and replaces target)
-- `cbv` reduces ground equalities to True/False and uses mkOfEqTrue for True
example : id (1 = 1) := by cbv
example : Nat.succ 0 = 1 ∧ Nat.succ 1 = 2 := by cbv
/--
trace: h : True
⊢ True
-/
#guard_msgs in
example (h : 2 + 3 = 5) : True := by
cbv at h
trace_state
trivial
-- False equation in hypothesis: goal is closed automatically
example (h : 2 + 3 = 6) : 42 = 0 := by
cbv at h
-- `cbv at h |-` — reduces both hypothesis and target
example (h : 2 + 3 = 5) : 1 + 1 = 2 := by
cbv at h |-
/--
trace: h₁ h₂ : True
⊢ False
---
warning: declaration uses `sorry`
-/
#guard_msgs in
example (h₁ : 2 + 3 = 5) (h₂ : 1 + 1 = 2) : False := by
cbv at *
trace_state
sorry
-- Reduces hypothesis but not target when only hypothesis is specified
/-- warning: declaration uses `sorry` -/
#guard_msgs in
example (h : (fun x => x + 1) 0 = 1) : 2 + 2 = 5 := by
cbv at h
sorry
/--
trace: x : Nat
⊢ x = 4
---
warning: declaration uses `sorry`
-/
#guard_msgs in
example : x = 2 + 2 := by
cbv
trace_state
sorry