Skip to content

Commit e687f00

Browse files
committed
Updates across Algebra, Naturals and Set
1 parent d33ac05 commit e687f00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2533
-706
lines changed

Mathematics.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ import Mathematics.Logic
22
import Mathematics.Structures.Numbers.Natural
33
import Mathematics.Structures.Set
44
import Mathematics.Algebra.Group
5+
import Mathematics.Algebra.Field

Mathematics/Algebra/Field.lean

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
class Field (T: Type) extends Zero T, OfNat T 1, Add T, Sub T, Neg T, Mul T, Div T, LE T, LT T where
2+
different: (0: T) ≠ (1: T)
3+
add_zero: ∀x: T, x + 0 = x
4+
zero_add: ∀x: T, 0 + x = x
5+
add_associative: ∀a b c: T, a + (b + c) = (a + b) + c
6+
add_commutative: ∀a b: T, a + b = b + a
7+
zero_mul: ∀x: T, 0 * x = 0
8+
one_mul: ∀x: T, 1 * x = x
9+
mul_associative: ∀a b c: T, a * (b * c) = a * b * c
10+
mul_commutative: ∀a b: T, a * b = b * a
11+
neg_def: ∀x: T, -x = -1 * x
12+
sub_eq: ∀x y: T, x = y ↔ x - y = 0
13+
sub_def: ∀x y: T, x - y = x + (-1 * y)
14+
distributive: ∀a b c: T, a * c + b * c = (a + b) * c
15+
-- TODO can this one be proven from above?
16+
neg_neg: ∀x: T, - (-x) = x
17+
div_self : ∀a: T, (a / a) = 1
18+
add_neg_assoc : ∀a b c: T, a - (b + c) = a - b - c
19+
add_neg_rerrange : ∀a b c d: T, a + b - c - d = (a - c) + (b - d)
20+
-- Double check
21+
add_neg_rerrange₂ : ∀a b c d: T, a - b + (c - d) = (a - d) - (b - c)
22+
-- TODO can these be proven
23+
div_add: ∀a b c: T, (a / c) + (b / c) = (a + b) / c
24+
div_mul: ∀a b c: T, (a * b) / c = a * (b / c)
25+
26+
theorem Field.sub_distributive {T: Type} [Field T] (a b c: T): a * b - a * c = a * (b - c) := by
27+
rw [
28+
sub_def,
29+
mul_commutative a c,
30+
mul_associative,
31+
mul_commutative a _,
32+
distributive,
33+
←sub_def,
34+
mul_commutative a _,
35+
]
36+
37+
theorem Field.distributive' {T: Type} [f: Field T] (a b c: T): a * b + a * c = a * (b + c) := by
38+
rw [f.mul_commutative a (b + c), ←f.distributive, f.mul_commutative a b, f.mul_commutative c a]
39+
40+
-- TODO via calc
41+
theorem Field.difference_of_squares {T: Type} [Field T] (a b: T) : (a * a - b * b) = (a + b) * (a - b) := by
42+
rw [
43+
←distributive,
44+
←sub_distributive,
45+
←sub_distributive,
46+
add_neg_rerrange₂,
47+
-- This line is a little complex
48+
(sub_eq (a * b) (b * a)).mp (mul_commutative a b),
49+
-- TODO this can be extracted as their own theorems
50+
sub_def _ 0,
51+
mul_commutative _ 0,
52+
zero_mul,
53+
add_zero
54+
]
55+
56+
theorem Field.sub_zero {T: Type} [Field T] (a: T) : a - 0 = a := by
57+
rw [Field.sub_def, Field.mul_commutative, Field.zero_mul, Field.add_zero]
58+
59+
theorem Field.mul_one {T: Type} [Field T] (a: T) : a * 1 = a := (Field.mul_commutative _ (1: T)) ▸ Field.one_mul a
60+
61+
theorem Field.add_self {T: Type} [Field T] (a: T): a + a = (1 + 1) * a := by
62+
conv => lhs; rw [←Field.one_mul a];
63+
rw [Field.distributive]
64+
65+
class OrderedField (T: Type) [Field T] extends LE T, LT T where
66+
eq_then_leq: ∀a: T, a = a → a <= a
67+
total: ∀a b: T, a < b ∨ a >= b
68+
le_def: ∀a b: T, a <= b ↔ (a = b ∨ a < b)
69+
gt_zero_one: 0 < (1: T)
70+
-- TODO this might need some work
71+
le_def₂: ∀a b: T, a <= b ↔ ∃c: T, c >= 0 ∧ a + c = b
72+
73+
lt_lt_trans : ∀a b c: T, a < b → b < c → a < c
74+
ge_one_two: 1 <= (1 + 1: T)
75+
gt_zero_two: 0 < (1 + 1: T)
76+
gt_one_two: 1 < (1 + 1: T)
77+
lt_div : ∀a b: T, a > b → (a / (1 + 1)) > b
78+
lt_add: ∀a b c d: T, a < b → c < d → (a + c) < (b + d)
79+
lt_sub: ∀a b c: T, a - b > c → a > b + c
80+
lt_sub': ∀a b c: T, a - b < c → a < c + b
81+
lt_mul_cancel: ∀a b c: T, b > 0 → b * a < b * c → a < c
82+
83+
theorem OrderedField.lt_implies_le {T: Type} [Field T] [OrderedField T] (a b: T) (h1: a < b) : a <= b := (OrderedField.le_def a b).mpr (Or.inr h1)
84+
85+
theorem OrderedField.le_lt_trans {T: Type} [Field T] [OrderedField T] (a b c: T) (h1: a <= b) (h2: b < c): a < c := by
86+
cases (OrderedField.le_def a b).mp h1 with
87+
| inl h3 => rw [h3]; exact h2
88+
| inr h3 => exact OrderedField.lt_lt_trans a b c h3 h2
89+
90+
theorem OrderedField.lt_le_trans {T: Type} [Field T] [OrderedField T] (a b c: T) (h1: a < b) (h2: b <= c): a < c := by
91+
cases (OrderedField.le_def b c).mp h2 with
92+
| inl h3 => rw [←h3]; exact h1
93+
| inr h3 => exact OrderedField.lt_lt_trans a b c h1 h3
94+
95+
theorem OrderedField.ge_zero_one {T: Type} [Field T] [OrderedField T] : 0 <= (1: T) := (OrderedField.le_def 0 1).mpr (Or.inr OrderedField.gt_zero_one)
96+
97+
theorem OrderedField.ge_zero_two {T: Type} [Field T] [OrderedField T] : 0 <= (1 + 1: T) := by
98+
sorry
99+
-- rw [OrderedField.le_def₂]
100+
-- exists (1 + 1)
101+
102+
def Real: Type := sorry
103+
104+
-- variable {Real: Type} [Field Real] [OrderedField Real]
105+
-- variable [Field Real] [OrderedField Real]
106+
107+
instance : Field Real := sorry
108+
instance : OrderedField Real := sorry
109+
110+
-- TODO constraints
111+
class FieldWithAbsConjugate (T: Type) extends Field T where
112+
abs: T → Real
113+
conigate: T → T
114+
115+
example : (0: Real) ≠ (1: Real) := Field.different
116+
117+
-- class ConjugateField (T: Type) extends Field T
118+
-- conjugate: T → T

Mathematics/Algebra/Group.lean

Lines changed: 4 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import Mathematics.Structures.Relation
2-
31
class Inverse (T : Type) where
4-
inverse' : T → T
2+
inverseOfElement : T → T
53

6-
postfix:max "⁻¹" => Inverse.inverse'
4+
postfix:max "⁻¹" => Inverse.inverseOfElement
75

8-
class Group (T: Type) extends Mul T, Inverse T, OfNat T 1 :=
6+
class Group (T: Type) extends Mul T, Inverse T, OfNat T 1 where
97
associativity : ∀ a b c: T, a * (b * c) = (a * b) * c
108
identity : ∀ a: T, a * 1 = a ∧ 1 * a = a
119
inverse : ∀ a: T, a⁻¹ * a = 1 ∧ a * a⁻¹ = 1
1210

13-
class AbelianGroup (T: Type) extends Group T :=
11+
class AbelianGroup (T: Type) extends Group T where
1412
commutativity : ∀ a b : T, a * b = b * a
1513

1614
namespace groups
@@ -74,73 +72,3 @@ theorem one.unique_left (e: T) : ∀ x: T, e * x = x → e = 1 := by
7472
exact (multiply.right_cancel_iff x e 1).1 h1
7573

7674
end groups
77-
78-
def conjugation { T: Type } [Group T] (c: T) := fun (x: T) => c * x * c⁻¹
79-
80-
namespace random
81-
82-
variable {T: Type} [Group T]
83-
84-
def are_conjugate (x x': T) : Prop := ∃g, x' = conjugation g x
85-
86-
open groups in
87-
instance : Relation T are_conjugate := {
88-
symmetric := by
89-
intro a b h1
90-
let ⟨g, h2⟩ := h1
91-
apply Exists.intro g⁻¹
92-
unfold conjugation at *
93-
rw [
94-
h2,
95-
inv.double,
96-
multiply.associative,
97-
←multiply.associative _ g⁻¹ g,
98-
(Group.inverse g).1,
99-
multiply.one,
100-
multiply.associative,
101-
(Group.inverse g).1,
102-
one.multiply
103-
]
104-
reflexivity := by
105-
intro a
106-
apply Exists.intro 1
107-
unfold conjugation at *
108-
rw [one.multiply, one.inverse, multiply.one]
109-
transitivity := by
110-
intro a b c h1
111-
let ⟨⟨g1, h2⟩, ⟨g2, h3⟩⟩ := h1
112-
apply Exists.intro (g2 * g1)
113-
unfold conjugation at *
114-
rw [h3, h2, inv.multiply, multiply.associative, multiply.associative, multiply.associative]
115-
}
116-
117-
end random
118-
119-
namespace product
120-
121-
def Group.Product (A B: Type) [Group A] [Group B] : Type := A × B
122-
123-
instance (A B: Type) [Group A] [Group B] : Mul (Group.Product A B) := ⟨fun (g1, g2) (h1, h2) => (g1 * h1, g2 * h2)⟩
124-
instance (A B: Type) [Group A] [Group B] : Inverse (Group.Product A B) := ⟨fun (g1, g2) => (g1⁻¹, g2⁻¹)⟩
125-
instance (A B: Type) [Group A] [Group B] : OfNat (Group.Product A B) 1 := ⟨(1, 1)⟩
126-
127-
theorem mul_eq (A B: Type) [Group A] [Group B] (a b: Group.Product A B) : a * b = (a.1 * b.1, a.2 * b.2) := rfl
128-
theorem mul_inv (A B: Type) [Group A] [Group B] (a: Group.Product A B) : a⁻¹ = (a.1⁻¹, a.2⁻¹) := rfl
129-
theorem one_left (A B: Type) [Group A] [Group B] : (1: Group.Product A B) = (1, 1) := rfl
130-
131-
instance (A B: Type) {ga: Group A} {gb: Group B} : Group (Group.Product A B) := {
132-
associativity := by
133-
intro a b c
134-
rw [mul_eq, mul_eq, ga.associativity, gb.associativity]
135-
rfl
136-
inverse := by
137-
intro a
138-
rw [mul_inv, mul_eq, (ga.inverse _).1, (gb.inverse _).1, mul_eq, (ga.inverse _).2, (gb.inverse _).2]
139-
exact ⟨one_left _ _, one_left _ _⟩
140-
identity := by
141-
intro a
142-
rw [mul_eq, one_left, (ga.identity _).1, (gb.identity _).1, mul_eq, (ga.identity _).2, (gb.identity _).2]
143-
exact ⟨rfl, rfl⟩
144-
}
145-
146-
end product
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Mathematics.Algebra.Group
2+
import Mathematics.Relation.Relation
3+
4+
def conjugation { T: Type } [Group T] (c: T) := fun (x: T) => c * x * c⁻¹
5+
6+
variable {T: Type} [Group T]
7+
8+
def are_conjugate (x x': T) : Prop := ∃g, x' = conjugation g x
9+
10+
open groups in
11+
instance : Relation T are_conjugate := {
12+
symmetric := by
13+
intro a b h1
14+
let ⟨g, h2⟩ := h1
15+
exists g⁻¹
16+
unfold conjugation at *
17+
rw [
18+
h2,
19+
inv.double,
20+
multiply.associative,
21+
←multiply.associative _ g⁻¹ g,
22+
(Group.inverse g).1,
23+
multiply.one,
24+
multiply.associative,
25+
(Group.inverse g).1,
26+
one.multiply
27+
]
28+
reflexivity := by
29+
intro a
30+
exists 1
31+
unfold conjugation at *
32+
rw [one.multiply, one.inverse, multiply.one]
33+
transitivity := by
34+
intro a b c h1
35+
let ⟨⟨g1, h2⟩, ⟨g2, h3⟩⟩ := h1
36+
exists (g2 * g1)
37+
unfold conjugation at *
38+
rw [h3, h2, inv.multiply, multiply.associative, multiply.associative, multiply.associative]
39+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Mathematics.Algebra.Group
2+
3+
def Group.Product (A B: Type) [Group A] [Group B] : Type := A × B
4+
5+
instance (A B: Type) [Group A] [Group B] : Mul (Group.Product A B) := ⟨fun (g1, g2) (h1, h2) => (g1 * h1, g2 * h2)⟩
6+
instance (A B: Type) [Group A] [Group B] : Inverse (Group.Product A B) := ⟨fun (g1, g2) => (g1⁻¹, g2⁻¹)⟩
7+
instance (A B: Type) [Group A] [Group B] : OfNat (Group.Product A B) 1 := ⟨(1, 1)⟩
8+
9+
theorem mul_eq (A B: Type) [Group A] [Group B] (a b: Group.Product A B) : a * b = (a.1 * b.1, a.2 * b.2) := rfl
10+
theorem mul_inv (A B: Type) [Group A] [Group B] (a: Group.Product A B) : a⁻¹ = (a.1⁻¹, a.2⁻¹) := rfl
11+
theorem one_left (A B: Type) [Group A] [Group B] : (1: Group.Product A B) = (1, 1) := rfl
12+
13+
instance (A B: Type) {ga: Group A} {gb: Group B} : Group (Group.Product A B) := {
14+
associativity := by
15+
intro a b c
16+
rw [mul_eq, mul_eq, ga.associativity, gb.associativity]
17+
rfl
18+
inverse := by
19+
intro a
20+
rw [mul_inv, mul_eq, (ga.inverse _).1, (gb.inverse _).1, mul_eq, (ga.inverse _).2, (gb.inverse _).2]
21+
exact ⟨one_left _ _, one_left _ _⟩
22+
identity := by
23+
intro a
24+
rw [mul_eq, one_left, (ga.identity _).1, (gb.identity _).1, mul_eq, (ga.identity _).2, (gb.identity _).2]
25+
exact ⟨rfl, rfl⟩
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Mathematics.Algebra.Group
2+
import Mathematics.Structures.Set
3+
4+
class Subgroup (T: Type) [Group T] (H: Set T) where
5+
closure: ∀a ∈ H, ∀b ∈ H, (a * b) ∈ H
6+
7+
-- TODO contains 0 etc
8+
9+
variable {T: Type} [Group T]
10+
11+
-- TODO name wrong
12+
def Subgroup.unit : Subgroup T (Set.universal T) where
13+
closure := by
14+
intro a _ b _
15+
trivial
16+
17+
-- TODO name wrong
18+
def Subgroup.identity : Subgroup T (Set.singleton 1) where
19+
closure := by
20+
intro a h1 b h2
21+
rw [h1, h2, groups.one.multiply]
22+
rfl

Mathematics/Algebra/PartialOrder.lean

Lines changed: 0 additions & 4 deletions
This file was deleted.

Mathematics/Algebra/VectorSpace.lean

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Mathematics.Algebra.Field
2+
3+
class VectorSpace (X F: Type) [Field F] extends Zero X, OfNat X 1, Add X, Sub X, HMul F X X, Neg X where
4+
zero_mul: ∀x: X, (0: F) * x = (0: X)
5+
one_mul: ∀x: X, (1: F) * x = x
6+
add_zero: ∀x: X, x + (0: X) = x
7+
sub_eq: ∀x y: X, x = y ↔ x - y = 0
8+
sub_def: ∀x y: X, x - y = x + ((-1: F) * y)
9+
neg_def: ∀x: X, -x = (-1: F) * x
10+
mul_associative: ∀x: X, ∀a b: F, a * (b * x) = (a * b) * x
11+
add_commutative: ∀x y: X, x + y = y + x
12+
distributive: ∀b c: X, ∀a: F, a * b + a * c = a * (b + c)
13+
14+
instance {T: Type} [f: Field T] : VectorSpace T T where
15+
zero_mul := f.zero_mul
16+
one_mul := f.one_mul
17+
add_zero := f.add_zero
18+
sub_eq := f.sub_eq
19+
sub_def := f.sub_def
20+
neg_def := f.neg_def
21+
add_commutative := f.add_commutative
22+
mul_associative := fun a b c => f.mul_associative b c a
23+
distributive := fun a b c => f.distributive' c a b

Mathematics/Analysis/Abs.lean

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Mathematics.Algebra.Field
2+
3+
class Abs {F: Type} [Field F] [OrderedField F] (abs: F → Real) where
4+
positive: ∀a: F, abs a >= 0
5+
equal: ∀a: F, abs a = 0 ↔ a = 0
6+
multiplicative: ∀a b: F, abs (a * b) = (abs a) * (abs b)
7+
negative: ∀a: F, abs (-a) = abs a

0 commit comments

Comments
 (0)