Skip to content

Commit 5b6da2f

Browse files
committed
Separate div2_zero out from Div2, to allow types that don't have a Zero
1 parent a96f006 commit 5b6da2f

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

Interval/Approx/Div2.lean

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ variable {α 𝕜 : Type}
1616
section Defs
1717

1818
/-- Division by 2 -/
19-
class Div2 α [Zero α] where
19+
class Div2 α where
2020
div2 : α → α
21-
div2_zero : div2 (0 : α) = 0
2221

23-
export Div2 (div2 div2_zero)
22+
/-- Division by 2 respects zero -/
23+
class Div2Zero α [Zero α] [Div2 α] where
24+
div2_zero : Div2.div2 (0 : α) = 0
25+
26+
export Div2 (div2)
27+
export Div2Zero (div2_zero)
2428
attribute [simp] div2_zero
2529

2630
/-- Division by 2 is conservative -/
27-
class ApproxDiv2 (α α' : Type) [Approx α α'] [Zero α] [Zero α'] [Div2 α] [Div2 α'] where
31+
class ApproxDiv2 (α α' : Type) [Approx α α'] [Div2 α] [Div2 α'] where
2832
approx_div2 {x : α} {x' : α'} (a : approx x x') : approx (div2 x) (div2 x')
2933

3034
export ApproxDiv2 (approx_div2)
@@ -45,6 +49,9 @@ variable {E : Type} [Zero E] [SMulZeroClass ℚ E]
4549
/-- Division by 2 for modules -/
4650
instance {E : Type} [Zero E] [SMulZeroClass ℚ E] : Div2 E where
4751
div2 x := (2⁻¹ : ℚ) • x
52+
53+
/-- Division by 2 respects zero for modules -/
54+
instance {E : Type} [Zero E] [SMulZeroClass ℚ E] : Div2Zero E where
4855
div2_zero := smul_zero _
4956

5057
lemma div2_eq_smul {E : Type} [Zero E] [SMulZeroClass ℚ E] (x : E) : div2 x = (2⁻¹ : ℚ) • x := rfl

Interval/Approx/Dyadic.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ instance : Repr Dyadic where
2828

2929
instance : Div2 Dyadic where
3030
div2 x := x >>> 1
31+
32+
instance : Div2Zero Dyadic where
3133
div2_zero := rfl
3234

3335
lemma Dyadic.natCast_zero : (0 : ℕ) = (0 : Dyadic) := rfl

0 commit comments

Comments
 (0)