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

Commit deb1681

Browse files
committed
refactor(*): import content from lean/library/data and library_dev
1 parent 21aca92 commit deb1681

Some content is hidden

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

71 files changed

+22461
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.olean
2+
/_target
3+
/leanpkg.path

algebra/group.lean

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/-
2+
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Jeremy Avigad, Leonardo de Moura
5+
6+
Various multiplicative and additive structures.
7+
-/
8+
import pending
9+
10+
universe variable uu
11+
variable {A : Type uu}
12+
13+
section group
14+
variable [group A]
15+
16+
variable (A)
17+
theorem left_inverse_inv : function.left_inverse (λ a : A, a⁻¹) (λ a, a⁻¹) :=
18+
assume a, inv_inv a
19+
variable {A}
20+
21+
theorem inv_eq_inv_iff_eq (a b : A) : a⁻¹ = b⁻¹ ↔ a = b :=
22+
iff.intro inv_inj (begin intro h, simp [h] end)
23+
24+
theorem inv_eq_one_iff_eq_one (a : A) : a⁻¹ = 1 ↔ a = 1 :=
25+
have a⁻¹ = 1⁻¹ ↔ a = 1, from inv_eq_inv_iff_eq a 1,
26+
begin rewrite this^.symm, simp end
27+
28+
theorem eq_one_of_inv_eq_one (a : A) : a⁻¹ = 1 → a = 1 :=
29+
iff.mp (inv_eq_one_iff_eq_one a)
30+
31+
theorem eq_inv_iff_eq_inv (a b : A) : a = b⁻¹ ↔ b = a⁻¹ :=
32+
iff.intro eq_inv_of_eq_inv eq_inv_of_eq_inv
33+
34+
theorem eq_of_mul_inv_eq_one {a b : A} (H : a * b⁻¹ = 1) : a = b :=
35+
calc
36+
a = a * b⁻¹ * b : by simp
37+
... = b : begin rewrite H, simp end
38+
39+
theorem mul_eq_iff_eq_inv_mul (a b c : A) : a * b = c ↔ b = a⁻¹ * c :=
40+
iff.intro eq_inv_mul_of_mul_eq mul_eq_of_eq_inv_mul
41+
42+
theorem mul_eq_iff_eq_mul_inv (a b c : A) : a * b = c ↔ a = c * b⁻¹ :=
43+
iff.intro eq_mul_inv_of_mul_eq mul_eq_of_eq_mul_inv
44+
end group
45+
46+
/- transport versions to additive -/
47+
run_cmd transport_multiplicative_to_additive'
48+
[ (`left_inverse_inv, `left_inverse_neg),
49+
(`inv_eq_inv_iff_eq, `neg_eq_neg_iff_eq),
50+
(`inv_eq_one_iff_eq_one, `neg_eq_zero_iff_eq_zero),
51+
(`eq_one_of_inv_eq_one, `eq_zero_of_neg_eq_zero),
52+
(`eq_inv_iff_eq_inv, `eq_neg_iff_eq_neg),
53+
(`mul_right_inv, `add_right_inv),
54+
(`eq_of_mul_inv_eq_one, `eq_of_add_neg_eq_zero),
55+
(`mul_eq_iff_eq_inv_mul, `add_eq_iff_eq_neg_add),
56+
(`mul_eq_iff_eq_mul_inv, `add_eq_iff_eq_add_neg)
57+
-- (`mul_eq_one_of_mul_eq_one, `add_eq_zero_of_add_eq_zero) not needed for commutative groups
58+
-- (`muleq_one_iff_mul_eq_one, `add_eq_zero_iff_add_eq_zero)
59+
]
60+
61+
section add_group
62+
variable [add_group A]
63+
64+
local attribute [simp] sub_eq_add_neg
65+
66+
theorem eq_iff_sub_eq_zero (a b : A) : a = b ↔ a - b = 0 :=
67+
iff.intro (assume h, by simp [h]) (assume h, eq_of_sub_eq_zero h)
68+
69+
theorem sub_eq_iff_eq_add (a b c : A) : a - b = c ↔ a = c + b :=
70+
iff.intro (assume H, eq_add_of_add_neg_eq H) (assume H, add_neg_eq_of_eq_add H)
71+
72+
theorem eq_sub_iff_add_eq (a b c : A) : a = b - c ↔ a + c = b :=
73+
iff.intro (assume H, add_eq_of_eq_add_neg H) (assume H, eq_add_neg_of_add_eq H)
74+
75+
theorem eq_iff_eq_of_sub_eq_sub {a b c d : A} (H : a - b = c - d) : a = b ↔ c = d :=
76+
calc
77+
a = b ↔ a - b = 0 : eq_iff_sub_eq_zero a b
78+
... = (c - d = 0) : by rewrite H
79+
... ↔ c = d : iff.symm (eq_iff_sub_eq_zero c d)
80+
81+
theorem left_inverse_sub_add_left (c : A) : function.left_inverse (λ x, x - c) (λ x, x + c) :=
82+
assume x, add_sub_cancel x c
83+
84+
theorem left_inverse_add_left_sub (c : A) : function.left_inverse (λ x, x + c) (λ x, x - c) :=
85+
assume x, sub_add_cancel x c
86+
87+
theorem left_inverse_add_right_neg_add (c : A) :
88+
function.left_inverse (λ x, c + x) (λ x, - c + x) :=
89+
assume x, add_neg_cancel_left c x
90+
91+
theorem left_inverse_neg_add_add_right (c : A) :
92+
function.left_inverse (λ x, - c + x) (λ x, c + x) :=
93+
assume x, neg_add_cancel_left c x
94+
end add_group
95+
96+
97+
/-
98+
namespace norm_num
99+
reveal add.assoc
100+
101+
def add1 [has_add A] [has_one A] (a : A) : A := add a one
102+
103+
local attribute add1 bit0 bit1 [reducible]
104+
105+
theorem add_comm_four [add_comm_semigroup A] (a b : A) : a + a + (b + b) = (a + b) + (a + b) :=
106+
sorry -- by simp
107+
108+
theorem add_comm_middle [add_comm_semigroup A] (a b c : A) : a + b + c = a + c + b :=
109+
sorry -- by simp
110+
111+
theorem bit0_add_bit0 [add_comm_semigroup A] (a b : A) : bit0 a + bit0 b = bit0 (a + b) :=
112+
sorry -- by simp
113+
114+
theorem bit0_add_bit0_helper [add_comm_semigroup A] (a b t : A) (H : a + b = t) :
115+
bit0 a + bit0 b = bit0 t :=
116+
sorry -- by rewrite -H; simp
117+
118+
theorem bit1_add_bit0 [add_comm_semigroup A] [has_one A] (a b : A) :
119+
bit1 a + bit0 b = bit1 (a + b) :=
120+
sorry -- by simp
121+
122+
theorem bit1_add_bit0_helper [add_comm_semigroup A] [has_one A] (a b t : A)
123+
(H : a + b = t) : bit1 a + bit0 b = bit1 t :=
124+
sorry -- by rewrite -H; simp
125+
126+
theorem bit0_add_bit1 [add_comm_semigroup A] [has_one A] (a b : A) :
127+
bit0 a + bit1 b = bit1 (a + b) :=
128+
sorry -- by simp
129+
130+
theorem bit0_add_bit1_helper [add_comm_semigroup A] [has_one A] (a b t : A)
131+
(H : a + b = t) : bit0 a + bit1 b = bit1 t :=
132+
sorry -- by rewrite -H; simp
133+
134+
theorem bit1_add_bit1 [add_comm_semigroup A] [has_one A] (a b : A) :
135+
bit1 a + bit1 b = bit0 (add1 (a + b)) :=
136+
sorry -- by simp
137+
138+
theorem bit1_add_bit1_helper [add_comm_semigroup A] [has_one A] (a b t s: A)
139+
(H : (a + b) = t) (H2 : add1 t = s) : bit1 a + bit1 b = bit0 s :=
140+
sorry -- by inst_simp
141+
142+
theorem bin_add_zero [add_monoid A] (a : A) : a + zero = a :=
143+
sorry -- by simp
144+
145+
theorem bin_zero_add [add_monoid A] (a : A) : zero + a = a :=
146+
sorry -- by simp
147+
148+
theorem one_add_bit0 [add_comm_semigroup A] [has_one A] (a : A) : one + bit0 a = bit1 a :=
149+
sorry -- by simp
150+
151+
theorem bit0_add_one [has_add A] [has_one A] (a : A) : bit0 a + one = bit1 a :=
152+
rfl
153+
154+
theorem bit1_add_one [has_add A] [has_one A] (a : A) : bit1 a + one = add1 (bit1 a) :=
155+
rfl
156+
157+
theorem bit1_add_one_helper [has_add A] [has_one A] (a t : A) (H : add1 (bit1 a) = t) :
158+
bit1 a + one = t :=
159+
sorry -- by inst_simp
160+
161+
theorem one_add_bit1 [add_comm_semigroup A] [has_one A] (a : A) : one + bit1 a = add1 (bit1 a) :=
162+
sorry -- by simp
163+
164+
theorem one_add_bit1_helper [add_comm_semigroup A] [has_one A] (a t : A)
165+
(H : add1 (bit1 a) = t) : one + bit1 a = t :=
166+
sorry -- by inst_simp
167+
168+
theorem add1_bit0 [has_add A] [has_one A] (a : A) : add1 (bit0 a) = bit1 a :=
169+
rfl
170+
171+
theorem add1_bit1 [add_comm_semigroup A] [has_one A] (a : A) :
172+
add1 (bit1 a) = bit0 (add1 a) :=
173+
sorry -- by simp
174+
175+
theorem add1_bit1_helper [add_comm_semigroup A] [has_one A] (a t : A) (H : add1 a = t) :
176+
add1 (bit1 a) = bit0 t :=
177+
sorry -- by inst_simp
178+
179+
theorem add1_one [has_add A] [has_one A] : add1 (one : A) = bit0 one :=
180+
rfl
181+
182+
theorem add1_zero [add_monoid A] [has_one A] : add1 (zero : A) = one :=
183+
sorry -- by simp
184+
185+
theorem one_add_one [has_add A] [has_one A] : (one : A) + one = bit0 one :=
186+
rfl
187+
188+
theorem subst_into_sum [has_add A] (l r tl tr t : A) (prl : l = tl) (prr : r = tr)
189+
(prt : tl + tr = t) : l + r = t :=
190+
sorry -- by simp
191+
192+
theorem neg_zero_helper [add_group A] (a : A) (H : a = 0) : - a = 0 :=
193+
sorry -- by simp
194+
195+
end norm_num
196+
197+
attribute [simp]
198+
zero_add add_zero one_mul mul_one
199+
200+
attribute [simp]
201+
neg_neg sub_eq_add_neg
202+
203+
attribute [simp]
204+
add.assoc add.comm add.left_comm
205+
mul.left_comm mul.comm mul.assoc
206+
-/

algebra/group_power.lean

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/-
2+
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Jeremy Avigad, Robert Y. Lewis
5+
6+
The power operation on monoids and groups. We separate this from group, because it depends on
7+
nat, which in turn depends on other parts of algebra.
8+
9+
We have "pow a n" for natural number powers, and "gpow a i" for integer powers. The notation
10+
a^n is used for the first, but users can locally redefine it to gpow when needed.
11+
12+
Note: power adopts the convention that 0^0=1.
13+
-/
14+
import data.nat.basic data.int.basic ..tools.auto.finish
15+
16+
universe u
17+
variable {α : Type u}
18+
19+
class has_pow_nat (α : Type u) :=
20+
(pow_nat : α → nat → α)
21+
22+
def pow_nat {α : Type u} [s : has_pow_nat α] : α → nat → α :=
23+
has_pow_nat.pow_nat
24+
25+
infix ` ^ ` := pow_nat
26+
27+
class has_pow_int (α : Type u) :=
28+
(pow_int : α → int → α)
29+
30+
def pow_int {α : Type u} [s : has_pow_int α] : α → int → α :=
31+
has_pow_int.pow_int
32+
33+
/- monoid -/
34+
section monoid
35+
open nat
36+
37+
variable [s : monoid α]
38+
include s
39+
40+
def monoid.pow (a : α) : ℕ → α
41+
| 0 := 1
42+
| (n+1) := a * monoid.pow n
43+
44+
instance monoid.has_pow_nat : has_pow_nat α :=
45+
has_pow_nat.mk monoid.pow
46+
47+
@[simp] theorem pow_zero (a : α) : a^0 = 1 := rfl
48+
@[simp] theorem pow_succ (a : α) (n : ℕ) : a^(succ n) = a * a^n := rfl
49+
@[simp] theorem pow_one (a : α) : a^1 = a := mul_one _
50+
51+
theorem pow_succ' (a : α) : ∀ (n : ℕ), a^(succ n) = (a^n) * a
52+
| 0 := by simp
53+
| (succ n) :=
54+
suffices a * (a ^ n * a) = a * a ^ succ n, by simp [this],
55+
by rw <-pow_succ'
56+
57+
@[simp] theorem one_pow : ∀ n : ℕ, (1 : α)^n = (1:α)
58+
| 0 := rfl
59+
| (succ n) := by simp; rw one_pow
60+
61+
theorem pow_add (a : α) : ∀ m n : ℕ, a^(m + n) = a^m * a^n
62+
| m 0 := by simp
63+
| m (n+1) := by rw [add_succ, pow_succ', pow_succ', pow_add, mul_assoc]
64+
65+
theorem pow_mul (a : α) (m : ℕ) : ∀ n, a^(m * n) = (a^m)^n
66+
| 0 := by simp
67+
| (succ n) := by rw [nat.mul_succ, pow_add, pow_succ', pow_mul]
68+
69+
theorem pow_comm (a : α) (m n : ℕ) : a^m * a^n = a^n * a^m :=
70+
by rw [←pow_add, ←pow_add, add_comm]
71+
72+
end monoid
73+
74+
/- commutative monoid -/
75+
76+
section comm_monoid
77+
open nat
78+
variable [s : comm_monoid α]
79+
include s
80+
81+
theorem mul_pow (a b : α) : ∀ n, (a * b)^n = a^n * b^n
82+
| 0 := by simp
83+
| (succ n) := by simp; rw mul_pow
84+
85+
end comm_monoid
86+
87+
section group
88+
variable [s : group α]
89+
include s
90+
91+
section nat
92+
open nat
93+
theorem inv_pow (a : α) : ∀n, (a⁻¹)^n = (a^n)⁻¹
94+
| 0 := by simp
95+
| (succ n) := by rw [pow_succ', _root_.pow_succ, mul_inv_rev, inv_pow]
96+
97+
theorem pow_sub (a : α) {m n : ℕ} (h : m ≥ n) : a^(m - n) = a^m * (a^n)⁻¹ :=
98+
have h1 : m - n + n = m, from nat.sub_add_cancel h,
99+
have h2 : a^(m - n) * a^n = a^m, by rw [←pow_add, h1],
100+
eq_mul_inv_of_mul_eq h2
101+
102+
theorem pow_inv_comm (a : α) : ∀m n, (a⁻¹)^m * a^n = a^n * (a⁻¹)^m
103+
| 0 n := by simp
104+
| m 0 := by simp
105+
| (succ m) (succ n) := calc
106+
a⁻¹ ^ succ m * a ^ succ n = (a⁻¹ ^ m * a⁻¹) * (a * a^n) : by rw [pow_succ', _root_.pow_succ]
107+
... = a⁻¹ ^ m * (a⁻¹ * a) * a^n : by simp
108+
... = a⁻¹ ^ m * a^n : by simp
109+
... = a ^ n * (a⁻¹)^m : by rw pow_inv_comm
110+
... = a ^ n * (a * a⁻¹) * (a⁻¹)^m : by simp
111+
... = (a^n * a) * (a⁻¹ * (a⁻¹)^m) : by simp only [mul_assoc]
112+
... = a ^ succ n * a⁻¹ ^ succ m : by rw [pow_succ', _root_.pow_succ]; simp
113+
114+
end nat
115+
116+
open int
117+
118+
119+
def gpow (a : α) : ℤ → α
120+
| (of_nat n) := a^n
121+
| -[1+n] := (a^(nat.succ n))⁻¹
122+
123+
local attribute [ematch] le_of_lt
124+
open nat
125+
private lemma gpow_add_aux (a : α) (m n : nat) :
126+
gpow a ((of_nat m) + -[1+n]) = gpow a (of_nat m) * gpow a (-[1+n]) :=
127+
or.elim (nat.lt_or_ge m (nat.succ n))
128+
(assume : m < succ n,
129+
have m ≤ n, from le_of_lt_succ this,
130+
suffices gpow a -[1+ n-m] = (gpow a (of_nat m)) * (gpow a -[1+n]), by simp [*, of_nat_add_neg_succ_of_nat_of_lt],
131+
suffices (a^(nat.succ (n - m)))⁻¹ = (gpow a (of_nat m)) * (gpow a -[1+n]), from this,
132+
suffices (a^(nat.succ n - m))⁻¹ = (gpow a (of_nat m)) * (gpow a -[1+n]), by rw ←succ_sub; assumption,
133+
by rw pow_sub; finish [gpow])
134+
(assume : m ≥ succ n,
135+
suffices gpow a (of_nat (m - succ n)) = (gpow a (of_nat m)) * (gpow a -[1+ n]),
136+
by rw [of_nat_add_neg_succ_of_nat_of_ge]; assumption,
137+
suffices a ^ (m - succ n) = a^m * (a^succ n)⁻¹, from this,
138+
by rw pow_sub; assumption)
139+
140+
141+
theorem gpow_add (a : α) : ∀i j : int, gpow a (i + j) = gpow a i * gpow a j
142+
| (of_nat m) (of_nat n) := pow_add _ _ _
143+
| (of_nat m) -[1+n] := gpow_add_aux _ _ _
144+
| -[1+m] (of_nat n) := begin rw [add_comm, gpow_add_aux], unfold gpow, rw [←inv_pow, pow_inv_comm] end
145+
| -[1+m] -[1+n] :=
146+
suffices (a ^ (m + succ (succ n)))⁻¹ = (a ^ succ m)⁻¹ * (a ^ succ n)⁻¹, from this,
147+
by rw [←succ_add_eq_succ_add, add_comm, pow_add, mul_inv_rev]
148+
149+
150+
theorem gpow_comm (a : α) (i j : ℤ) : gpow a i * gpow a j = gpow a j * gpow a i :=
151+
by rw [←gpow_add, ←gpow_add, add_comm]
152+
end group
153+
154+
section ordered_ring
155+
open nat
156+
variable [s : linear_ordered_ring α]
157+
include s
158+
159+
theorem pow_pos {a : α} (H : a > 0) : ∀ (n : ℕ), a ^ n > 0
160+
| 0 := by simp; apply zero_lt_one
161+
| (succ n) := begin simp, apply mul_pos, assumption, apply pow_pos end
162+
163+
theorem pow_ge_one_of_ge_one {a : α} (H : a ≥ 1) : ∀ (n : ℕ), a ^ n ≥ 1
164+
| 0 := by simp; apply le_refl
165+
| (succ n) :=
166+
begin
167+
simp, rw ←(one_mul (1 : α)),
168+
apply mul_le_mul,
169+
assumption,
170+
apply pow_ge_one_of_ge_one,
171+
apply zero_le_one,
172+
transitivity, apply zero_le_one, assumption
173+
end
174+
175+
end ordered_ring
176+

0 commit comments

Comments
 (0)