lean4-htt/tests/lean/run/grind_10160.lean
Leonardo de Moura ab26eaf647
feat: enable implicit argument transparency bump (part 2) (#12572)
This PR is part 2 of the `implicit_reducible` refactoring (part 1:
#12567).

**Background.** When Lean checks definitional equality of function
applications
`f a₁ ... aₙ =?= f b₁ ... bₙ`, it compares arguments `aᵢ =?= bᵢ` at a
transparency level determined by the binder type. Previously, only
instance-implicit (`[C]`) arguments received a transparency bump to
`.instances`. With `backward.isDefEq.implicitBump` enabled, ALL implicit
arguments (`{x}`, `⦃x⦄`, and `[x]`) are bumped to `.instances`, so that
definitions marked `[implicit_reducible]` unfold when comparing implicit
arguments. This is important because implicit arguments often carry type
information (e.g., `P (i + 0)` vs `P i`) where the mismatch is in
non-proof positions (Sort arguments to `cast`) — proof irrelevance does
not
help here, so the relevant definitions must actually unfold.

**`[implicit_reducible]`** (renamed from `[instance_reducible]` in part
1) marks
definitions that should unfold at `TransparencyMode.instances` — between
`[reducible]` (unfolds at `.reducible` and above) and the default
`[semireducible]` (unfolds only at `.default` and above). This is the
right
level for core arithmetic operations that appear in type indices.

## Changes

- **Enable `backward.isDefEq.implicitBump` by default** and set it in
  `stage0/src/stdlib_flags.h` so stage0 also compiles with it
- **Mark `Nat.add`, `Nat.mul`, `Nat.sub`, `Array.size` as
`[implicit_reducible]`**
so they unfold when comparing implicit arguments at `.instances`
transparency
- **Remove redundant unification hints** (`n + 0 =?= n`, `n - 0 =?= n`,
  `n * 0 =?= 0`) that are now handled by `[implicit_reducible]`
- **Rename all remaining `[instance_reducible]` attribute usages** to
`[implicit_reducible]` across the codebase (the old name remains as an
alias)
- **Remove 28 `set_option backward.isDefEq.respectTransparency false
in`**
  workarounds that are no longer needed

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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 03:28:48 +00:00

46 lines
1.4 KiB
Text

structure PreInt where
minuend : Nat
subtrahend : Nat
/-- Definition 4.1.1 -/
instance PreInt.instSetoid : Setoid PreInt where
r a b := a.minuend + b.subtrahend = b.minuend + a.subtrahend
iseqv := {
refl := by grind
symm := by grind
trans := by grind
}
abbrev MyInt := Quotient PreInt.instSetoid
abbrev MyInt.formalDiff (a b : Nat) : MyInt := Quotient.mk PreInt.instSetoid ⟨ a, b ⟩
theorem MyInt.eq (a b c d : Nat) : formalDiff a b = formalDiff c d ↔ a + d = c + b :=
⟨ Quotient.exact, by intro h; exact Quotient.sound h ⟩
instance MyInt.instOfNat {n : Nat} : OfNat MyInt n where
ofNat := formalDiff n 0
instance MyInt.instNatCast : NatCast MyInt where
natCast n := formalDiff n 0
theorem MyInt.natCast_eq (n : Nat) : (n : MyInt) = formalDiff n 0 := rfl
theorem MyInt.natCast_inj (n m : Nat) :
(n : MyInt) = (m : MyInt) ↔ n = m := by
rw [natCast_eq, natCast_eq, eq]; simp
example (n m : Nat) : (n : MyInt) = (m : MyInt) ↔ n = m := by
grind [MyInt.natCast_eq, MyInt.eq]
@[grind]
theorem MyInt.eq_0_of_cast_eq_0 (n : Nat) (h : (n : MyInt) = 0) : n = 0 := by
rw [show (0 : MyInt) = ((0 : Nat) : MyInt) by rfl] at h
rwa [natCast_inj] at h
theorem MyInt.pos_iff_gt_0 {a : MyInt} : (∃ (n:Nat), n > 0 ∧ a = n) → a ≠ 0 := by
intro ⟨ w, hw ⟩ h
grind
example {a : MyInt} : (∃ (n:Nat), n > 0 ∧ a = n) → a ≠ 0 := by
grind