Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 1c110ad

Browse files
committed
fix(tactic/linarith): elaborate and insert arguments before destructing hypotheses (#5501)
closes #5480 Arguments to `linarith` can depend on hypotheses (e.g. conjunctions) that get destructed during preprocessing, after which the arguments will no longer elaborate or typecheck. This just moves the elaboration earlier and adds these arguments as hypotheses themselves. Co-authored-by: Rob Lewis <rob.y.lewis@gmail.com>
1 parent 7c6020f commit 1c110ad

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/tactic/linarith/frontend.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ do t ← target,
242242
if t.is_eq.is_some then
243243
linarith_trace "target is an equality: splitting" >>
244244
seq' (applyc ``eq_of_not_lt_of_not_gt) tactic.linarith else
245-
do when cfg.split_hypotheses (linarith_trace "trying to split hypotheses" >> try auto.split_hyps),
245+
do hyps ← hyps.mmap $ λ e, i_to_expr e >>= note_anon none,
246+
when cfg.split_hypotheses (linarith_trace "trying to split hypotheses" >> try auto.split_hyps),
246247
/- If we are proving a comparison goal (and not just `false`), we consider the type of the
247248
elements in the comparison to be the "preferred" type. That is, if we find comparison
248249
hypotheses in multiple types, we will run `linarith` on the goal type first.
@@ -255,7 +256,6 @@ do when cfg.split_hypotheses (linarith_trace "trying to split hypotheses" >> try
255256
let cfg := cfg.update_reducibility reduce_semi,
256257
let (pref_type, new_var) := pref_type_and_new_var_from_tgt.elim (none, none) (λ ⟨a, b⟩, (some a, some b)),
257258
-- set up the list of hypotheses, considering the `only_on` and `restrict_type` options
258-
hyps ← hyps.mmap i_to_expr,
259259
hyps ← if only_on then return (new_var.elim [] singleton ++ hyps) else (++ hyps) <$> local_context,
260260
hyps ← (do t ← get_restrict_type cfg.restrict_type_reflect, filter_hyps_to_type t hyps) <|> return hyps,
261261
linarith_trace_proofs "linarith is running on the following hypotheses:" hyps,

test/linarith.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,6 @@ by linarith {split_ne := tt}
392392
example (x y : ℚ) (h₁ : 0 ≤ y) (h₂ : y ≤ x) : y * x ≤ x * x := by nlinarith
393393

394394
example (x y : ℚ) (h₁ : 0 ≤ y) (h₂ : y ≤ x) : y * x ≤ x ^ 2 := by nlinarith
395+
396+
axiom foo {x : int} : 1 ≤ x → 1 ≤ x*x
397+
lemma bar (x y: int)(h : 0 ≤ y ∧ 1 ≤ x) : 1 ≤ y + x*x := by linarith [foo h.2]

0 commit comments

Comments
 (0)