refactor(library/data/nat/basic): mark some theorems as protected to avoid overloading
This commit is contained in:
parent
0aaa8a9770
commit
6df31d3406
68 changed files with 195 additions and 262 deletions
|
@ -25,7 +25,7 @@ Here is an example
|
|||
|
||||
#+BEGIN_SRC lean
|
||||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
constants a b c d e : nat.
|
||||
axiom Ax1 : a = b.
|
||||
axiom Ax2 : b = c + 1.
|
||||
|
@ -53,7 +53,7 @@ some form of transitivity. It can even combine different relations.
|
|||
|
||||
#+BEGIN_SRC lean
|
||||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
theorem T2 (a b c : nat) (H1 : a = b) (H2 : b = c + 1) : a ≠ 0
|
||||
:= calc a = b : H1
|
||||
|
|
|
@ -242,7 +242,7 @@ an additional indent for every line after the first, as in the following
|
|||
example:
|
||||
#+BEGIN_SRC lean
|
||||
import data.nat
|
||||
open nat eq
|
||||
open nat eq algebra
|
||||
theorem add_right_inj {n m k : nat} : n + m = n + k → m = k :=
|
||||
nat.induction_on n
|
||||
(take H : 0 + m = 0 + k,
|
||||
|
|
|
@ -752,7 +752,7 @@ of two even numbers is an even number.
|
|||
|
||||
#+BEGIN_SRC lean
|
||||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
namespace hide
|
||||
definition even (a : nat) := ∃ b, a = 2*b
|
||||
|
@ -762,7 +762,7 @@ of two even numbers is an even number.
|
|||
exists.intro (w1 + w2)
|
||||
(calc a + b = 2*w1 + b : {Hw1}
|
||||
... = 2*w1 + 2*w2 : {Hw2}
|
||||
... = 2*(w1 + w2) : eq.symm !mul.left_distrib)))
|
||||
... = 2*(w1 + w2) : eq.symm !left_distrib)))
|
||||
end hide
|
||||
#+END_SRC
|
||||
|
||||
|
@ -774,7 +774,7 @@ With this macro we can write the example above in a more natural way
|
|||
|
||||
#+BEGIN_SRC lean
|
||||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
namespace hide
|
||||
definition even (a : nat) := ∃ b, a = 2*b
|
||||
|
@ -784,6 +784,6 @@ With this macro we can write the example above in a more natural way
|
|||
exists.intro (w1 + w2)
|
||||
(calc a + b = 2*w1 + b : {Hw1}
|
||||
... = 2*w1 + 2*w2 : {Hw2}
|
||||
... = 2*(w1 + w2) : eq.symm !mul.left_distrib)
|
||||
... = 2*(w1 + w2) : eq.symm !left_distrib)
|
||||
end hide
|
||||
#+END_SRC
|
||||
|
|
|
@ -131,10 +131,14 @@ definition add_comm_monoid.to_comm_monoid {A : Type} [s : add_comm_monoid A] : c
|
|||
⦄
|
||||
|
||||
section add_comm_monoid
|
||||
variables [s : add_comm_monoid A]
|
||||
include s
|
||||
|
||||
theorem add_comm_three {A : Type} [s : add_comm_monoid A] (a b c : A) : a + b + c = c + b + a :=
|
||||
theorem add_comm_three (a b c : A) : a + b + c = c + b + a :=
|
||||
by rewrite [{a + _}add.comm, {_ + c}add.comm, -*add.assoc]
|
||||
|
||||
theorem add.comm4 : ∀ (n m k l : A), n + m + (k + l) = n + k + (m + l) :=
|
||||
comm4 add.comm add.assoc
|
||||
end add_comm_monoid
|
||||
|
||||
/- group -/
|
||||
|
|
|
@ -81,7 +81,7 @@ theorem pow_mul (a : A) (m : ℕ) : ∀ n, a^(m * n) = (a^m)^n
|
|||
| (succ n) := by rewrite [nat.mul_succ, pow_add, pow_succ', pow_mul]
|
||||
|
||||
theorem pow_comm (a : A) (m n : ℕ) : a^m * a^n = a^n * a^m :=
|
||||
by rewrite [-*pow_add, nat.add.comm]
|
||||
by rewrite [-*pow_add, add.comm]
|
||||
|
||||
end monoid
|
||||
|
||||
|
@ -219,7 +219,7 @@ theorem one_nmul (a : A) : 1 ⬝ a = a := pow_one a
|
|||
|
||||
theorem add_nmul (m n : ℕ) (a : A) : (m + n) ⬝ a = (m ⬝ a) + (n ⬝ a) := pow_add a m n
|
||||
|
||||
theorem mul_nmul (m n : ℕ) (a : A) : (m * n) ⬝ a = m ⬝ (n ⬝ a) := eq.subst (nat.mul.comm n m) (pow_mul a n m)
|
||||
theorem mul_nmul (m n : ℕ) (a : A) : (m * n) ⬝ a = m ⬝ (n ⬝ a) := eq.subst (mul.comm n m) (pow_mul a n m)
|
||||
|
||||
theorem nmul_comm (m n : ℕ) (a : A) : (m ⬝ a) + (n ⬝ a) = (n ⬝ a) + (m ⬝ a) := pow_comm a m n
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ Type class for encodable types.
|
|||
Note that every encodable type is countable.
|
||||
-/
|
||||
import data.fintype data.list data.list.sort data.sum data.nat.div data.countable data.equiv data.finset
|
||||
open option list nat function
|
||||
open option list nat function algebra
|
||||
|
||||
structure encodable [class] (A : Type) :=
|
||||
(encode : A → nat) (decode : nat → option A) (encodek : ∀ a, decode (encode a) = some a)
|
||||
|
|
|
@ -7,7 +7,7 @@ This file demonstrates how to encode vectors using indexed inductive families.
|
|||
In standard library we do not use this approach.
|
||||
-/
|
||||
import data.nat data.list data.fin
|
||||
open nat prod fin
|
||||
open nat prod fin algebra
|
||||
|
||||
inductive vector (A : Type) : nat → Type :=
|
||||
| nil {} : vector A zero
|
||||
|
|
|
@ -245,7 +245,7 @@ lemma madd_comm (i j : fin (succ n)) : madd i j = madd j i :=
|
|||
by apply eq_of_veq; rewrite [*val_madd, add.comm (val i)]
|
||||
|
||||
lemma zero_madd (i : fin (succ n)) : madd 0 i = i :=
|
||||
have H : madd (fin.zero n) i = i,
|
||||
have H : madd (fin.zero n) i = i,
|
||||
by apply eq_of_veq; rewrite [val_madd, ↑fin.zero, nat.zero_add, mod_eq_of_lt (is_lt i)],
|
||||
H
|
||||
|
||||
|
@ -446,7 +446,7 @@ assert aux₁ : ∀ {v₁ v₂}, v₁ < n → v₂ < m → v₁ + v₂ * n < n*m
|
|||
take v₁ v₂, assume h₁ h₂,
|
||||
have nat.succ v₂ ≤ m, from succ_le_of_lt h₂,
|
||||
assert nat.succ v₂ * n ≤ m * n, from mul_le_mul_right _ this,
|
||||
have v₂ * n + n ≤ n * m, by rewrite [-add_one at this, mul.right_distrib at this, one_mul at this, mul.comm m n at this]; exact this,
|
||||
have v₂ * n + n ≤ n * m, by rewrite [-add_one at this, right_distrib at this, one_mul at this, mul.comm m n at this]; exact this,
|
||||
assert v₁ + (v₂ * n + n) < n + n * m, from add_lt_add_of_lt_of_le h₁ this,
|
||||
have v₁ + v₂ * n + n < n * m + n, by rewrite [add.assoc, add.comm (n*m) n]; exact this,
|
||||
lt_of_add_lt_add_right this,
|
||||
|
|
|
@ -191,7 +191,7 @@ begin
|
|||
induction s with a s' H IH,
|
||||
rewrite [Sum_empty, card_empty, zero_mul],
|
||||
rewrite [Sum_insert_of_not_mem _ H, IH, card_insert_of_not_mem H, add.comm,
|
||||
mul.right_distrib, one_mul]
|
||||
right_distrib, one_mul]
|
||||
end
|
||||
|
||||
theorem Sum_one_eq_card (s : finset A) : (∑ x ∈ s, (1 : nat)) = card s :=
|
||||
|
|
|
@ -94,7 +94,7 @@ lemma length_all_lists : ∀ {n : nat}, length (@all_lists_of_len A _ n) = (card
|
|||
| 0 := calc length [[]] = 1 : length_cons
|
||||
| (succ n) := calc length _ = card A * length (all_lists_of_len n) : length_cons_all
|
||||
... = card A * (card A ^ n) : length_all_lists
|
||||
... = (card A ^ n) * card A : nat.mul.comm
|
||||
... = (card A ^ n) * card A : mul.comm
|
||||
... = (card A) ^ (succ n) : pow_succ'
|
||||
|
||||
|
||||
|
|
|
@ -370,16 +370,16 @@ calc
|
|||
... = nat_abs a : abstr_repr
|
||||
|
||||
theorem padd_pneg (p : ℕ × ℕ) : padd p (pneg p) ≡ (0, 0) :=
|
||||
show pr1 p + pr2 p + 0 = pr2 p + pr1 p + 0, from !nat.add.comm ▸ rfl
|
||||
show pr1 p + pr2 p + 0 = pr2 p + pr1 p + 0, from !nat.add_comm ▸ rfl
|
||||
|
||||
theorem padd_padd_pneg (p q : ℕ × ℕ) : padd (padd p q) (pneg q) ≡ p :=
|
||||
calc pr1 p + pr1 q + pr2 q + pr2 p
|
||||
= pr1 p + (pr1 q + pr2 q) + pr2 p : nat.add.assoc
|
||||
... = pr1 p + (pr1 q + pr2 q + pr2 p) : nat.add.assoc
|
||||
... = pr1 p + (pr2 q + pr1 q + pr2 p) : nat.add.comm
|
||||
... = pr1 p + (pr2 q + pr2 p + pr1 q) : by rewrite add.right_comm
|
||||
... = pr1 p + (pr2 p + pr2 q + pr1 q) : nat.add.comm
|
||||
... = pr2 p + pr2 q + pr1 q + pr1 p : nat.add.comm
|
||||
= pr1 p + (pr1 q + pr2 q) + pr2 p : algebra.add.assoc
|
||||
... = pr1 p + (pr1 q + pr2 q + pr2 p) : algebra.add.assoc
|
||||
... = pr1 p + (pr2 q + pr1 q + pr2 p) : algebra.add.comm
|
||||
... = pr1 p + (pr2 q + pr2 p + pr1 q) : algebra.add.right_comm
|
||||
... = pr1 p + (pr2 p + pr2 q + pr1 q) : algebra.add.comm
|
||||
... = pr2 p + pr2 q + pr1 q + pr1 p : algebra.add.comm
|
||||
|
||||
theorem add.left_inv (a : ℤ) : -a + a = 0 :=
|
||||
have H : repr (-a + a) ≡ repr 0, from
|
||||
|
@ -450,21 +450,25 @@ theorem equiv_mul_prep {xa ya xb yb xn yn xm ym : ℕ}
|
|||
nat.add.cancel_right (calc
|
||||
xa*xn+ya*yn + (xb*ym+yb*xm) + (yb*xn+xb*yn + (xb*xn+yb*yn))
|
||||
= xa*xn+ya*yn + (yb*xn+xb*yn) + (xb*ym+yb*xm + (xb*xn+yb*yn)) : by rewrite add.comm4
|
||||
... = xa*xn+ya*yn + (yb*xn+xb*yn) + (xb*xn+yb*yn + (xb*ym+yb*xm)) : by rewrite {xb*ym+yb*xm +_}nat.add.comm
|
||||
... = xa*xn+yb*xn + (ya*yn+xb*yn) + (xb*xn+xb*ym + (yb*yn+yb*xm)) : by exact !congr_arg2 add.comm4 add.comm4
|
||||
... = ya*xn+xb*xn + (xa*yn+yb*yn) + (xb*yn+xb*xm + (yb*xn+yb*ym)) : by rewrite[-+mul.left_distrib,-+mul.right_distrib]; exact H1 ▸ H2 ▸ rfl
|
||||
... = ya*xn+xa*yn + (xb*xn+yb*yn) + (xb*yn+yb*xn + (xb*xm+yb*ym)) : by exact !congr_arg2 add.comm4 add.comm4
|
||||
... = xa*yn+ya*xn + (xb*xn+yb*yn) + (xb*yn+yb*xn + (xb*xm+yb*ym)) : by rewrite {xa*yn + _}nat.add.comm
|
||||
... = xa*yn+ya*xn + (xb*xn+yb*yn) + (yb*xn+xb*yn + (xb*xm+yb*ym)) : by rewrite {xb*yn + _}nat.add.comm
|
||||
... = xa*yn+ya*xn + (yb*xn+xb*yn) + (xb*xn+yb*yn + (xb*xm+yb*ym)) : by rewrite add.comm4
|
||||
... = xa*yn+ya*xn + (yb*xn+xb*yn) + (xb*xm+yb*ym + (xb*xn+yb*yn)) : by rewrite {xb*xn+yb*yn + _}nat.add.comm
|
||||
... = xa*xn+ya*yn + (yb*xn+xb*yn) + (xb*xn+yb*yn + (xb*ym+yb*xm)) : by rewrite {xb*ym+yb*xm +_}nat.add_comm
|
||||
... = xa*xn+yb*xn + (ya*yn+xb*yn) + (xb*xn+xb*ym + (yb*yn+yb*xm)) : by exact !congr_arg2 !add.comm4 !add.comm4
|
||||
... = ya*xn+xb*xn + (xa*yn+yb*yn) + (xb*yn+xb*xm + (yb*xn+yb*ym)) : by rewrite[-+left_distrib,-+right_distrib]; exact H1 ▸ H2 ▸ rfl
|
||||
... = ya*xn+xa*yn + (xb*xn+yb*yn) + (xb*yn+yb*xn + (xb*xm+yb*ym)) : by exact !congr_arg2 !add.comm4 !add.comm4
|
||||
... = xa*yn+ya*xn + (xb*xn+yb*yn) + (xb*yn+yb*xn + (xb*xm+yb*ym)) : by rewrite {xa*yn + _}nat.add_comm
|
||||
... = xa*yn+ya*xn + (xb*xn+yb*yn) + (yb*xn+xb*yn + (xb*xm+yb*ym)) : by rewrite {xb*yn + _}nat.add_comm
|
||||
... = xa*yn+ya*xn + (yb*xn+xb*yn) + (xb*xn+yb*yn + (xb*xm+yb*ym)) : by rewrite (!add.comm4)
|
||||
... = xa*yn+ya*xn + (yb*xn+xb*yn) + (xb*xm+yb*ym + (xb*xn+yb*yn)) : by rewrite {xb*xn+yb*yn + _}nat.add_comm
|
||||
... = xa*yn+ya*xn + (xb*xm+yb*ym) + (yb*xn+xb*yn + (xb*xn+yb*yn)) : by rewrite add.comm4)
|
||||
|
||||
theorem pmul_congr {p p' q q' : ℕ × ℕ} : p ≡ p' → q ≡ q' → pmul p q ≡ pmul p' q' := equiv_mul_prep
|
||||
|
||||
theorem pmul_comm (p q : ℕ × ℕ) : pmul p q = pmul q p :=
|
||||
show (_,_) = (_,_), from !congr_arg2
|
||||
(!congr_arg2 !mul.comm !mul.comm) (!nat.add.comm ⬝ (!congr_arg2 !mul.comm !mul.comm))
|
||||
show (_,_) = (_,_),
|
||||
begin
|
||||
congruence,
|
||||
{ congruence, repeat rewrite mul.comm },
|
||||
{ rewrite algebra.add.comm, congruence, repeat rewrite mul.comm }
|
||||
end
|
||||
|
||||
theorem mul.comm (a b : ℤ) : a * b = b * a :=
|
||||
eq_of_repr_equiv_repr
|
||||
|
@ -476,9 +480,11 @@ eq_of_repr_equiv_repr
|
|||
private theorem pmul_assoc_prep {p1 p2 q1 q2 r1 r2 : ℕ} :
|
||||
((p1*q1+p2*q2)*r1+(p1*q2+p2*q1)*r2, (p1*q1+p2*q2)*r2+(p1*q2+p2*q1)*r1) =
|
||||
(p1*(q1*r1+q2*r2)+p2*(q1*r2+q2*r1), p1*(q1*r2+q2*r1)+p2*(q1*r1+q2*r2)) :=
|
||||
by rewrite[+mul.left_distrib,+mul.right_distrib,*mul.assoc];
|
||||
exact (congr_arg2 pair (!add.comm4 ⬝ (!congr_arg !nat.add.comm))
|
||||
(!add.comm4 ⬝ (!congr_arg !nat.add.comm)))
|
||||
begin
|
||||
rewrite[+left_distrib,+right_distrib,*algebra.mul.assoc],
|
||||
exact (congr_arg2 pair (!add.comm4 ⬝ (!congr_arg !nat.add_comm))
|
||||
(!add.comm4 ⬝ (!congr_arg !nat.add_comm)))
|
||||
end
|
||||
|
||||
theorem pmul_assoc (p q r: ℕ × ℕ) : pmul (pmul p q) r = pmul p (pmul q r) := pmul_assoc_prep
|
||||
|
||||
|
@ -500,19 +506,23 @@ theorem one_mul (a : ℤ) : 1 * a = a :=
|
|||
mul.comm a 1 ▸ mul_one a
|
||||
|
||||
private theorem mul_distrib_prep {a1 a2 b1 b2 c1 c2 : ℕ} :
|
||||
((a1+b1)*c1+(a2+b2)*c2, (a1+b1)*c2+(a2+b2)*c1) =
|
||||
((a1+b1)*c1+(a2+b2)*c2, (a1+b1)*c2+(a2+b2)*c1) =
|
||||
(a1*c1+a2*c2+(b1*c1+b2*c2), a1*c2+a2*c1+(b1*c2+b2*c1)) :=
|
||||
by rewrite[+mul.right_distrib] ⬝ (!congr_arg2 !add.comm4 !add.comm4)
|
||||
begin
|
||||
rewrite +right_distrib, congruence,
|
||||
{rewrite add.comm4},
|
||||
{rewrite add.comm4}
|
||||
end
|
||||
|
||||
theorem mul.right_distrib (a b c : ℤ) : (a + b) * c = a * c + b * c :=
|
||||
eq_of_repr_equiv_repr
|
||||
(calc
|
||||
repr ((a + b) * c) = pmul (repr (a + b)) (repr c) : repr_mul
|
||||
... ≡ pmul (padd (repr a) (repr b)) (repr c) : pmul_congr !repr_add equiv.refl
|
||||
... ≡ pmul (padd (repr a) (repr b)) (repr c) : pmul_congr !repr_add equiv.refl
|
||||
... = padd (pmul (repr a) (repr c)) (pmul (repr b) (repr c)) : mul_distrib_prep
|
||||
... = padd (repr (a * c)) (pmul (repr b) (repr c)) : repr_mul
|
||||
... = padd (repr (a * c)) (repr (b * c)) : repr_mul
|
||||
... ≡ repr (a * c + b * c) : repr_add)
|
||||
... = padd (repr (a * c)) (pmul (repr b) (repr c)) : repr_mul
|
||||
... = padd (repr (a * c)) (repr (b * c)) : repr_mul
|
||||
... ≡ repr (a * c + b * c) : repr_add)
|
||||
|
||||
theorem mul.left_distrib (a b c : ℤ) : a * (b + c) = a * b + a * c :=
|
||||
calc
|
||||
|
|
|
@ -162,10 +162,10 @@ or.elim (nat.lt_or_ge m (n * k))
|
|||
have (-[1+m] + n * k) div k = -[1+m] div k + n, from calc
|
||||
(-[1+m] + n * k) div k
|
||||
= of_nat ((k * n - (m + 1)) div k) :
|
||||
by rewrite [add.comm, neg_succ_of_nat_eq, of_nat_div, nat.mul.comm k n,
|
||||
by rewrite [add.comm, neg_succ_of_nat_eq, of_nat_div, algebra.mul.comm k n,
|
||||
of_nat_sub H3]
|
||||
... = of_nat (n - m div k - 1) :
|
||||
nat.mul_sub_div_of_lt (!nat.mul.comm ▸ m_lt_nk)
|
||||
nat.mul_sub_div_of_lt (!nat.mul_comm ▸ m_lt_nk)
|
||||
... = -[1+m] div k + n :
|
||||
by rewrite [nat.sub_sub, of_nat_sub H4, add.comm, sub_eq_add_neg,
|
||||
!neg_succ_of_nat_div (of_nat_lt_of_nat_of_lt H2),
|
||||
|
|
|
@ -6,7 +6,7 @@ Authors: Leonardo de Moura, Haitao Zhang
|
|||
List combinators.
|
||||
-/
|
||||
import data.list.basic data.equiv
|
||||
open nat prod decidable function helper_tactics
|
||||
open nat prod decidable function helper_tactics algebra
|
||||
|
||||
namespace list
|
||||
variables {A B C : Type}
|
||||
|
@ -368,7 +368,7 @@ theorem length_product : ∀ (l₁ : list A) (l₂ : list B), length (product l
|
|||
| (x::l₁) l₂ :=
|
||||
assert length (product l₁ l₂) = length l₁ * length l₂, from length_product l₁ l₂,
|
||||
by rewrite [product_cons, length_append, length_cons,
|
||||
length_map, this, mul.right_distrib, one_mul, add.comm]
|
||||
length_map, this, right_distrib, one_mul, add.comm]
|
||||
end product
|
||||
|
||||
-- new for list/comb dependent map theory
|
||||
|
|
|
@ -102,15 +102,15 @@ general m
|
|||
|
||||
/- addition -/
|
||||
|
||||
theorem add_zero [simp] (n : ℕ) : n + 0 = n :=
|
||||
protected theorem add_zero [simp] (n : ℕ) : n + 0 = n :=
|
||||
rfl
|
||||
|
||||
theorem add_succ [simp] (n m : ℕ) : n + succ m = succ (n + m) :=
|
||||
rfl
|
||||
|
||||
theorem zero_add [simp] (n : ℕ) : 0 + n = n :=
|
||||
protected theorem zero_add [simp] (n : ℕ) : 0 + n = n :=
|
||||
nat.induction_on n
|
||||
!add_zero
|
||||
!nat.add_zero
|
||||
(take m IH, show 0 + succ m = succ m, from
|
||||
calc
|
||||
0 + succ m = succ (0 + m) : add_succ
|
||||
|
@ -118,15 +118,15 @@ nat.induction_on n
|
|||
|
||||
theorem succ_add [simp] (n m : ℕ) : (succ n) + m = succ (n + m) :=
|
||||
nat.induction_on m
|
||||
(!add_zero ▸ !add_zero)
|
||||
(!nat.add_zero ▸ !nat.add_zero)
|
||||
(take k IH, calc
|
||||
succ n + succ k = succ (succ n + k) : add_succ
|
||||
... = succ (succ (n + k)) : IH
|
||||
... = succ (n + succ k) : add_succ)
|
||||
|
||||
theorem add.comm [simp] (n m : ℕ) : n + m = m + n :=
|
||||
protected theorem add_comm [simp] (n m : ℕ) : n + m = m + n :=
|
||||
nat.induction_on m
|
||||
(by rewrite [add_zero, zero_add])
|
||||
(by rewrite [nat.add_zero, nat.zero_add])
|
||||
(take k IH, calc
|
||||
n + succ k = succ (n+k) : add_succ
|
||||
... = succ (k + n) : IH
|
||||
|
@ -135,9 +135,9 @@ nat.induction_on m
|
|||
theorem succ_add_eq_succ_add (n m : ℕ) : succ n + m = n + succ m :=
|
||||
!succ_add ⬝ !add_succ⁻¹
|
||||
|
||||
theorem add.assoc [simp] (n m k : ℕ) : (n + m) + k = n + (m + k) :=
|
||||
protected theorem add_assoc [simp] (n m k : ℕ) : (n + m) + k = n + (m + k) :=
|
||||
nat.induction_on k
|
||||
(by rewrite +add_zero)
|
||||
(by rewrite +nat.add_zero)
|
||||
(take l IH,
|
||||
calc
|
||||
(n + m) + succ l = succ ((n + m) + l) : add_succ
|
||||
|
@ -145,19 +145,16 @@ nat.induction_on k
|
|||
... = n + succ (m + l) : add_succ
|
||||
... = n + (m + succ l) : add_succ)
|
||||
|
||||
theorem add.left_comm [simp] : Π (n m k : ℕ), n + (m + k) = m + (n + k) :=
|
||||
left_comm add.comm add.assoc
|
||||
protected theorem add.left_comm : Π (n m k : ℕ), n + (m + k) = m + (n + k) :=
|
||||
left_comm nat.add_comm nat.add_assoc
|
||||
|
||||
theorem add.right_comm : Π (n m k : ℕ), n + m + k = n + k + m :=
|
||||
right_comm add.comm add.assoc
|
||||
|
||||
theorem add.comm4 : Π {n m k l : ℕ}, n + m + (k + l) = n + k + (m + l) :=
|
||||
comm4 add.comm add.assoc
|
||||
protected theorem add.right_comm : Π (n m k : ℕ), n + m + k = n + k + m :=
|
||||
right_comm nat.add_comm nat.add_assoc
|
||||
|
||||
theorem add.cancel_left {n m k : ℕ} : n + m = n + k → m = k :=
|
||||
nat.induction_on n
|
||||
(take H : 0 + m = 0 + k,
|
||||
!zero_add⁻¹ ⬝ H ⬝ !zero_add)
|
||||
!nat.zero_add⁻¹ ⬝ H ⬝ !nat.zero_add)
|
||||
(take (n : ℕ) (IH : n + m = n + k → m = k) (H : succ n + m = succ n + k),
|
||||
have succ (n + m) = succ (n + k),
|
||||
from calc
|
||||
|
@ -168,7 +165,7 @@ nat.induction_on n
|
|||
IH this)
|
||||
|
||||
theorem add.cancel_right {n m k : ℕ} (H : n + m = k + m) : n = k :=
|
||||
have H2 : m + n = m + k, from !add.comm ⬝ H ⬝ !add.comm,
|
||||
have H2 : m + n = m + k, from !nat.add_comm ⬝ H ⬝ !nat.add_comm,
|
||||
add.cancel_left H2
|
||||
|
||||
theorem eq_zero_of_add_eq_zero_right {n m : ℕ} : n + m = 0 → n = 0 :=
|
||||
|
@ -183,20 +180,20 @@ nat.induction_on n
|
|||
!succ_ne_zero)
|
||||
|
||||
theorem eq_zero_of_add_eq_zero_left {n m : ℕ} (H : n + m = 0) : m = 0 :=
|
||||
eq_zero_of_add_eq_zero_right (!add.comm ⬝ H)
|
||||
eq_zero_of_add_eq_zero_right (!nat.add_comm ⬝ H)
|
||||
|
||||
theorem eq_zero_and_eq_zero_of_add_eq_zero {n m : ℕ} (H : n + m = 0) : n = 0 ∧ m = 0 :=
|
||||
and.intro (eq_zero_of_add_eq_zero_right H) (eq_zero_of_add_eq_zero_left H)
|
||||
|
||||
theorem add_one [simp] (n : ℕ) : n + 1 = succ n :=
|
||||
!add_zero ▸ !add_succ
|
||||
!nat.add_zero ▸ !add_succ
|
||||
|
||||
theorem one_add (n : ℕ) : 1 + n = succ n :=
|
||||
!zero_add ▸ !succ_add
|
||||
!nat.zero_add ▸ !succ_add
|
||||
|
||||
/- multiplication -/
|
||||
|
||||
theorem mul_zero [simp] (n : ℕ) : n * 0 = 0 :=
|
||||
protected theorem mul_zero [simp] (n : ℕ) : n * 0 = 0 :=
|
||||
rfl
|
||||
|
||||
theorem mul_succ [simp] (n m : ℕ) : n * succ m = n * m + n :=
|
||||
|
@ -204,75 +201,75 @@ rfl
|
|||
|
||||
-- commutativity, distributivity, associativity, identity
|
||||
|
||||
theorem zero_mul [simp] (n : ℕ) : 0 * n = 0 :=
|
||||
protected theorem zero_mul [simp] (n : ℕ) : 0 * n = 0 :=
|
||||
nat.induction_on n
|
||||
!mul_zero
|
||||
(take m IH, !mul_succ ⬝ !add_zero ⬝ IH)
|
||||
!nat.mul_zero
|
||||
(take m IH, !mul_succ ⬝ !nat.add_zero ⬝ IH)
|
||||
|
||||
theorem succ_mul [simp] (n m : ℕ) : (succ n) * m = (n * m) + m :=
|
||||
nat.induction_on m
|
||||
(by rewrite mul_zero)
|
||||
(by rewrite nat.mul_zero)
|
||||
(take k IH, calc
|
||||
succ n * succ k = succ n * k + succ n : mul_succ
|
||||
... = n * k + k + succ n : IH
|
||||
... = n * k + (k + succ n) : add.assoc
|
||||
... = n * k + (succ n + k) : add.comm
|
||||
... = n * k + (k + succ n) : nat.add_assoc
|
||||
... = n * k + (succ n + k) : nat.add_comm
|
||||
... = n * k + (n + succ k) : succ_add_eq_succ_add
|
||||
... = n * k + n + succ k : add.assoc
|
||||
... = n * k + n + succ k : nat.add_assoc
|
||||
... = n * succ k + succ k : mul_succ)
|
||||
|
||||
theorem mul.comm [simp] (n m : ℕ) : n * m = m * n :=
|
||||
protected theorem mul_comm [simp] (n m : ℕ) : n * m = m * n :=
|
||||
nat.induction_on m
|
||||
(!mul_zero ⬝ !zero_mul⁻¹)
|
||||
(!nat.mul_zero ⬝ !nat.zero_mul⁻¹)
|
||||
(take k IH, calc
|
||||
n * succ k = n * k + n : mul_succ
|
||||
... = k * n + n : IH
|
||||
... = (succ k) * n : succ_mul)
|
||||
|
||||
theorem mul.right_distrib (n m k : ℕ) : (n + m) * k = n * k + m * k :=
|
||||
protected theorem right_distrib (n m k : ℕ) : (n + m) * k = n * k + m * k :=
|
||||
nat.induction_on k
|
||||
(calc
|
||||
(n + m) * 0 = 0 : mul_zero
|
||||
... = 0 + 0 : add_zero
|
||||
... = n * 0 + 0 : mul_zero
|
||||
... = n * 0 + m * 0 : mul_zero)
|
||||
(n + m) * 0 = 0 : nat.mul_zero
|
||||
... = 0 + 0 : nat.add_zero
|
||||
... = n * 0 + 0 : nat.mul_zero
|
||||
... = n * 0 + m * 0 : nat.mul_zero)
|
||||
(take l IH, calc
|
||||
(n + m) * succ l = (n + m) * l + (n + m) : mul_succ
|
||||
... = n * l + m * l + (n + m) : IH
|
||||
... = n * l + m * l + n + m : add.assoc
|
||||
... = n * l + n + m * l + m : add.right_comm
|
||||
... = n * l + n + (m * l + m) : add.assoc
|
||||
... = n * l + m * l + n + m : nat.add_assoc
|
||||
... = n * l + n + m * l + m : nat.add.right_comm
|
||||
... = n * l + n + (m * l + m) : nat.add_assoc
|
||||
... = n * succ l + (m * l + m) : mul_succ
|
||||
... = n * succ l + m * succ l : mul_succ)
|
||||
|
||||
theorem mul.left_distrib (n m k : ℕ) : n * (m + k) = n * m + n * k :=
|
||||
protected theorem left_distrib (n m k : ℕ) : n * (m + k) = n * m + n * k :=
|
||||
calc
|
||||
n * (m + k) = (m + k) * n : mul.comm
|
||||
... = m * n + k * n : mul.right_distrib
|
||||
... = n * m + k * n : mul.comm
|
||||
... = n * m + n * k : mul.comm
|
||||
n * (m + k) = (m + k) * n : nat.mul_comm
|
||||
... = m * n + k * n : nat.right_distrib
|
||||
... = n * m + k * n : nat.mul_comm
|
||||
... = n * m + n * k : nat.mul_comm
|
||||
|
||||
theorem mul.assoc [simp] (n m k : ℕ) : (n * m) * k = n * (m * k) :=
|
||||
protected theorem mul_assoc [simp] (n m k : ℕ) : (n * m) * k = n * (m * k) :=
|
||||
nat.induction_on k
|
||||
(calc
|
||||
(n * m) * 0 = n * (m * 0) : mul_zero)
|
||||
(n * m) * 0 = n * (m * 0) : nat.mul_zero)
|
||||
(take l IH,
|
||||
calc
|
||||
(n * m) * succ l = (n * m) * l + n * m : mul_succ
|
||||
... = n * (m * l) + n * m : IH
|
||||
... = n * (m * l + m) : mul.left_distrib
|
||||
... = n * (m * l + m) : nat.left_distrib
|
||||
... = n * (m * succ l) : mul_succ)
|
||||
|
||||
theorem mul_one [simp] (n : ℕ) : n * 1 = n :=
|
||||
protected theorem mul_one [simp] (n : ℕ) : n * 1 = n :=
|
||||
calc
|
||||
n * 1 = n * 0 + n : mul_succ
|
||||
... = 0 + n : mul_zero
|
||||
... = n : zero_add
|
||||
... = 0 + n : nat.mul_zero
|
||||
... = n : nat.zero_add
|
||||
|
||||
theorem one_mul [simp] (n : ℕ) : 1 * n = n :=
|
||||
protected theorem one_mul [simp] (n : ℕ) : 1 * n = n :=
|
||||
calc
|
||||
1 * n = n * 1 : mul.comm
|
||||
... = n : mul_one
|
||||
1 * n = n * 1 : nat.mul_comm
|
||||
... = n : nat.mul_one
|
||||
|
||||
theorem eq_zero_or_eq_zero_of_mul_eq_zero {n m : ℕ} : n * m = 0 → n = 0 ∨ m = 0 :=
|
||||
nat.cases_on n
|
||||
|
@ -293,22 +290,21 @@ open algebra
|
|||
protected definition comm_semiring [reducible] [trans_instance] : algebra.comm_semiring nat :=
|
||||
⦃algebra.comm_semiring,
|
||||
add := nat.add,
|
||||
|
||||
add_assoc := add.assoc,
|
||||
add_assoc := nat.add_assoc,
|
||||
zero := nat.zero,
|
||||
zero_add := zero_add,
|
||||
add_zero := add_zero,
|
||||
add_comm := add.comm,
|
||||
zero_add := nat.zero_add,
|
||||
add_zero := nat.add_zero,
|
||||
add_comm := nat.add_comm,
|
||||
mul := nat.mul,
|
||||
mul_assoc := mul.assoc,
|
||||
mul_assoc := nat.mul_assoc,
|
||||
one := nat.succ nat.zero,
|
||||
one_mul := one_mul,
|
||||
mul_one := mul_one,
|
||||
left_distrib := mul.left_distrib,
|
||||
right_distrib := mul.right_distrib,
|
||||
zero_mul := zero_mul,
|
||||
mul_zero := mul_zero,
|
||||
mul_comm := mul.comm⦄
|
||||
one_mul := nat.one_mul,
|
||||
mul_one := nat.mul_one,
|
||||
left_distrib := nat.left_distrib,
|
||||
right_distrib := nat.right_distrib,
|
||||
zero_mul := nat.zero_mul,
|
||||
mul_zero := nat.mul_zero,
|
||||
mul_comm := nat.mul_comm⦄
|
||||
end nat
|
||||
|
||||
section
|
||||
|
|
|
@ -263,7 +263,7 @@ else
|
|||
(calc
|
||||
((z * x) div (z * y)) * (z * y) + (z * x) mod (z * y) = z * x : eq_div_mul_add_mod
|
||||
... = z * (x div y * y + x mod y) : eq_div_mul_add_mod
|
||||
... = z * (x div y * y) + z * (x mod y) : mul.left_distrib
|
||||
... = z * (x div y * y) + z * (x mod y) : left_distrib
|
||||
... = (x div y) * (z * y) + z * (x mod y) : mul.left_comm)
|
||||
|
||||
theorem mul_div_mul_right {x z y : ℕ} (zpos : z > 0) : (x * z) div (y * z) = x div y :=
|
||||
|
@ -286,7 +286,7 @@ or.elim (eq_zero_or_pos z)
|
|||
(calc
|
||||
((z * x) div (z * y)) * (z * y) + (z * x) mod (z * y) = z * x : eq_div_mul_add_mod
|
||||
... = z * (x div y * y + x mod y) : eq_div_mul_add_mod
|
||||
... = z * (x div y * y) + z * (x mod y) : mul.left_distrib
|
||||
... = z * (x div y * y) + z * (x mod y) : left_distrib
|
||||
... = (x div y) * (z * y) + z * (x mod y) : mul.left_comm)))
|
||||
|
||||
theorem mul_mod_mul_right (x z y : ℕ) : (x * z) mod (y * z) = (x mod y) * z :=
|
||||
|
@ -300,7 +300,7 @@ theorem mul_mod_eq_mod_mul_mod (m n k : nat) : (m * n) mod k = ((m mod k) * n) m
|
|||
calc
|
||||
(m * n) mod k = (((m div k) * k + m mod k) * n) mod k : eq_div_mul_add_mod
|
||||
... = ((m mod k) * n) mod k :
|
||||
by rewrite [mul.right_distrib, mul.right_comm, add.comm, add_mul_mod_self]
|
||||
by rewrite [right_distrib, mul.right_comm, add.comm, add_mul_mod_self]
|
||||
|
||||
theorem mul_mod_eq_mul_mod_mod (m n k : nat) : (m * n) mod k = (m * (n mod k)) mod k :=
|
||||
!mul.comm ▸ !mul.comm ▸ !mul_mod_eq_mod_mul_mod
|
||||
|
@ -558,7 +558,7 @@ calc
|
|||
... = ((n - k div m) * m - (k mod m + 1)) div m :
|
||||
by rewrite [mul.comm m, mul_sub_right_distrib]
|
||||
... = ((n - k div m - 1) * m + m - (k mod m + 1)) div m :
|
||||
by rewrite [H3 at {1}, mul.right_distrib, nat.one_mul]
|
||||
by rewrite [H3 at {1}, right_distrib, nat.one_mul]
|
||||
... = ((n - k div m - 1) * m + (m - (k mod m + 1))) div m : {add_sub_assoc H5 _}
|
||||
... = (m - (k mod m + 1)) div m + (n - k div m - 1) :
|
||||
by rewrite [add.comm, (add_mul_div_self H4)]
|
||||
|
@ -610,7 +610,7 @@ lemma div_lt_of_ne_zero : ∀ {n : nat}, n ≠ 0 → n div 2 < n
|
|||
| (succ n) h :=
|
||||
begin
|
||||
apply div_lt_of_lt_mul,
|
||||
rewrite [-add_one, mul.right_distrib],
|
||||
rewrite [-add_one, right_distrib],
|
||||
change n + 1 < (n * 1 + n) + (1 + 1),
|
||||
rewrite [mul_one, -add.assoc],
|
||||
apply add_lt_add_right,
|
||||
|
|
|
@ -6,7 +6,7 @@ Author: Leonardo de Moura
|
|||
Show that tail recursive fib is equal to standard one.
|
||||
-/
|
||||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
definition fib : nat → nat
|
||||
| 0 := 1
|
||||
|
|
|
@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
|
|||
Author: Leonardo de Moura
|
||||
-/
|
||||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
definition partial_sum : nat → nat
|
||||
| 0 := 0
|
||||
|
@ -19,10 +19,10 @@ rfl
|
|||
lemma two_mul_partial_sum_eq : ∀ n, 2 * partial_sum n = (succ n) * n
|
||||
| 0 := by reflexivity
|
||||
| (succ n) := calc
|
||||
2 * (succ n + partial_sum n) = 2 * succ n + 2 * partial_sum n : mul.left_distrib
|
||||
2 * (succ n + partial_sum n) = 2 * succ n + 2 * partial_sum n : left_distrib
|
||||
... = 2 * succ n + succ n * n : two_mul_partial_sum_eq
|
||||
... = 2 * succ n + n * succ n : mul.comm
|
||||
... = (2 + n) * succ n : mul.right_distrib
|
||||
... = (2 + n) * succ n : right_distrib
|
||||
... = (n + 2) * succ n : add.comm
|
||||
... = (succ (succ n)) * succ n : rfl
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad
|
|||
The order relation on the natural numbers.
|
||||
-/
|
||||
import data.nat.basic algebra.ordered_ring
|
||||
open eq.ops
|
||||
open eq.ops algebra
|
||||
|
||||
namespace nat
|
||||
|
||||
|
@ -73,7 +73,7 @@ theorem lt_add_of_pos_right {n k : ℕ} (H : k > 0) : n < n + k :=
|
|||
|
||||
theorem mul_le_mul_left {n m : ℕ} (k : ℕ) (H : n ≤ m) : k * n ≤ k * m :=
|
||||
obtain (l : ℕ) (Hl : n + l = m), from le.elim H,
|
||||
have k * n + k * l = k * m, by rewrite [-mul.left_distrib, Hl],
|
||||
have k * n + k * l = k * m, by rewrite [-left_distrib, Hl],
|
||||
le.intro this
|
||||
|
||||
theorem mul_le_mul_right {n m : ℕ} (k : ℕ) (H : n ≤ m) : n * k ≤ m * k :=
|
||||
|
|
|
@ -185,7 +185,7 @@ lemma even_add_of_even_of_even {n m} : even n → even m → even (n+m) :=
|
|||
suppose even n, suppose even m,
|
||||
obtain k₁ (hk₁ : n = 2 * k₁), from exists_of_even `even n`,
|
||||
obtain k₂ (hk₂ : m = 2 * k₂), from exists_of_even `even m`,
|
||||
even_of_exists (exists.intro (k₁+k₂) (by rewrite [hk₁, hk₂, mul.left_distrib]))
|
||||
even_of_exists (exists.intro (k₁+k₂) (by rewrite [hk₁, hk₂, left_distrib]))
|
||||
|
||||
lemma even_add_of_odd_of_odd {n m} : odd n → odd m → even (n+m) :=
|
||||
suppose odd n, suppose odd m,
|
||||
|
|
|
@ -45,7 +45,7 @@ theorem le_pow_self {x : ℕ} (H : x > 1) : ∀ i, i ≤ x^i
|
|||
succ j = j + 1 : rfl
|
||||
... ≤ x^j + 1 : add_le_add_right (le_pow_self j)
|
||||
... ≤ x^j + x^j : add_le_add_left h₁
|
||||
... = x^j * (1 + 1) : by rewrite [mul.left_distrib, *mul_one]
|
||||
... = x^j * (1 + 1) : by rewrite [left_distrib, *mul_one]
|
||||
... = x^j * 2 : rfl
|
||||
... ≤ x^j * x : mul_le_mul_left _ `x ≥ 2`
|
||||
... = x^(succ j) : pow_succ'
|
||||
|
|
|
@ -6,7 +6,7 @@ Authors: Floris van Doorn, Jeremy Avigad
|
|||
Subtraction on the natural numbers, as well as min, max, and distance.
|
||||
-/
|
||||
import .order
|
||||
open eq.ops
|
||||
open eq.ops algebra
|
||||
|
||||
namespace nat
|
||||
|
||||
|
@ -144,11 +144,11 @@ calc
|
|||
... = n * m - n * k : {!mul.comm}
|
||||
|
||||
theorem mul_self_sub_mul_self_eq (a b : nat) : a * a - b * b = (a + b) * (a - b) :=
|
||||
by rewrite [mul_sub_left_distrib, *mul.right_distrib, mul.comm b a, add.comm (a*a) (a*b), add_sub_add_left]
|
||||
by rewrite [mul_sub_left_distrib, *right_distrib, mul.comm b a, add.comm (a*a) (a*b), add_sub_add_left]
|
||||
|
||||
theorem succ_mul_succ_eq (a : nat) : succ a * succ a = a*a + a + a + 1 :=
|
||||
calc succ a * succ a = (a+1)*(a+1) : by rewrite [add_one]
|
||||
... = a*a + a + a + 1 : by rewrite [mul.right_distrib, mul.left_distrib, one_mul, mul_one]
|
||||
... = a*a + a + a + 1 : by rewrite [right_distrib, left_distrib, one_mul, mul_one]
|
||||
|
||||
/- interaction with inequalities -/
|
||||
|
||||
|
@ -458,7 +458,7 @@ H ▸ !dist.triangle_inequality
|
|||
|
||||
theorem dist_mul_right (n k m : ℕ) : dist (n * k) (m * k) = dist n m * k :=
|
||||
assert ∀ n m, dist n m = n - m + (m - n), from take n m, rfl,
|
||||
by rewrite [this, this n m, mul.right_distrib, *mul_sub_right_distrib]
|
||||
by rewrite [this, this n m, right_distrib, *mul_sub_right_distrib]
|
||||
|
||||
theorem dist_mul_left (k n m : ℕ) : dist (k * n) (k * m) = k * dist n m :=
|
||||
begin rewrite [mul.comm k n, mul.comm k m, dist_mul_right, mul.comm] end
|
||||
|
|
|
@ -177,7 +177,7 @@ theorem one_mul (n : ℕ+) : pone * n = n :=
|
|||
begin
|
||||
apply pnat.eq,
|
||||
unfold pone,
|
||||
rewrite [mul.def, ↑nat_of_pnat, one_mul]
|
||||
rewrite [mul.def, ↑nat_of_pnat, algebra.one_mul]
|
||||
end
|
||||
|
||||
theorem pone_le (n : ℕ+) : pone ≤ n :=
|
||||
|
@ -256,13 +256,13 @@ begin
|
|||
end
|
||||
|
||||
theorem mul.assoc (a b c : ℕ+) : a * b * c = a * (b * c) :=
|
||||
pnat.eq !nat.mul.assoc
|
||||
pnat.eq !mul.assoc
|
||||
|
||||
theorem mul.comm (a b : ℕ+) : a * b = b * a :=
|
||||
pnat.eq !nat.mul.comm
|
||||
pnat.eq !mul.comm
|
||||
|
||||
theorem add.assoc (a b c : ℕ+) : a + b + c = a + (b + c) :=
|
||||
pnat.eq !nat.add.assoc
|
||||
pnat.eq !add.assoc
|
||||
|
||||
theorem mul_le_mul_left (p q : ℕ+) : q ≤ p * q :=
|
||||
begin
|
||||
|
|
|
@ -276,7 +276,7 @@ private theorem canon_bound {s : seq} (Hs : regular s) (n : ℕ+) : abs (s n)
|
|||
by rewrite [add.comm 1 (abs (s pone)), rat.add.comm 1, rat.add.assoc]
|
||||
... ≤ of_nat (ubound (abs (s pone))) + (1 + 1) : algebra.add_le_add_right (!ubound_ge)
|
||||
... = of_nat (ubound (abs (s pone)) + (1 + 1)) : of_nat_add
|
||||
... = of_nat (ubound (abs (s pone)) + 1 + 1) : nat.add.assoc
|
||||
... = of_nat (ubound (abs (s pone)) + 1 + 1) : algebra.add.assoc
|
||||
... = rat_of_pnat (K s) : by esimp
|
||||
|
||||
theorem bdd_of_regular {s : seq} (H : regular s) : ∃ b : ℚ, ∀ n : ℕ+, s n ≤ b :=
|
||||
|
|
|
@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
|
|||
Author: Leonardo de Moura
|
||||
-/
|
||||
import data.nat data.list data.equiv
|
||||
open nat function option
|
||||
open nat function option algebra
|
||||
|
||||
definition stream (A : Type) := nat → A
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ Tuples are lists of a fixed size.
|
|||
It is implemented as a subtype.
|
||||
-/
|
||||
import logic data.list data.fin
|
||||
open nat list subtype function
|
||||
open nat list subtype function algebra
|
||||
|
||||
definition tuple [reducible] (A : Type) (n : nat) := {l : list A | length l = n}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ exists.intro N
|
|||
|
||||
proposition converges_to_seq_offset_left {X : ℕ → M} {y : M} (k : ℕ) (H : X ⟶ y in ℕ) :
|
||||
(λ n, X (k + n)) ⟶ y in ℕ :=
|
||||
have aux : (λ n, X (k + n)) = (λ n, X (n + k)), from funext (take n, by rewrite nat.add.comm),
|
||||
have aux : (λ n, X (k + n)) = (λ n, X (n + k)), from funext (take n, by rewrite add.comm),
|
||||
by+ rewrite aux; exact converges_to_seq_offset k H
|
||||
|
||||
proposition converges_to_seq_offset_succ {X : ℕ → M} {y : M} (H : X ⟶ y in ℕ) :
|
||||
|
@ -127,7 +127,7 @@ exists.intro (N + k)
|
|||
proposition converges_to_seq_of_converges_to_seq_offset_left
|
||||
{X : ℕ → M} {y : M} {k : ℕ} (H : (λ n, X (k + n)) ⟶ y in ℕ) :
|
||||
X ⟶ y in ℕ :=
|
||||
have aux : (λ n, X (k + n)) = (λ n, X (n + k)), from funext (take n, by rewrite nat.add.comm),
|
||||
have aux : (λ n, X (k + n)) = (λ n, X (n + k)), from funext (take n, by rewrite add.comm),
|
||||
by+ rewrite aux at H; exact converges_to_seq_of_converges_to_seq_offset H
|
||||
|
||||
proposition converges_to_seq_of_converges_to_seq_offset_succ
|
||||
|
|
|
@ -85,12 +85,12 @@ begin
|
|||
cases k with k',
|
||||
{rewrite [*choose_self, one_mul, mul_one]},
|
||||
{have H : 1 < succ (succ k'), from succ_lt_succ !zero_lt_succ,
|
||||
rewrite [one_mul, choose_zero_succ, choose_eq_zero_of_lt H, zero_mul]}},
|
||||
krewrite [one_mul, choose_zero_succ, choose_eq_zero_of_lt H, zero_mul]}},
|
||||
intro k,
|
||||
cases k with k',
|
||||
{rewrite [choose_zero_right, choose_one_right]},
|
||||
rewrite [choose_succ_succ (succ n), mul.right_distrib, -ih (succ k')],
|
||||
rewrite [choose_succ_succ at {1}, mul.left_distrib, *succ_mul (succ n), mul_succ, -ih k'],
|
||||
rewrite [choose_succ_succ (succ n), right_distrib, -ih (succ k')],
|
||||
rewrite [choose_succ_succ at {1}, left_distrib, *succ_mul (succ n), mul_succ, -ih k'],
|
||||
rewrite [*add.assoc, add.left_comm (choose n _)]
|
||||
end
|
||||
|
||||
|
|
|
@ -278,7 +278,7 @@ eq_of_veq begin rewrite [↑rotl, val_madd], esimp [mk_mod], rewrite [ mod_add_m
|
|||
lemma rotl_compose : ∀ {n : nat} {j k : nat}, (@rotl n j) ∘ (rotl k) = rotl (j + k)
|
||||
| 0 := take j k, funext take i, elim0 i
|
||||
| (succ n) := take j k, funext take i, eq.symm begin
|
||||
rewrite [*rotl_succ', mul.left_distrib, -(@madd_mk_mod n (n*j)), madd_assoc],
|
||||
rewrite [*rotl_succ', left_distrib, -(@madd_mk_mod n (n*j)), madd_assoc],
|
||||
end
|
||||
|
||||
lemma rotr_rotl : ∀ {n : nat} (m : nat) {i : fin n}, rotr m (rotl m i) = i
|
||||
|
|
|
@ -120,7 +120,7 @@ private theorem mult_pow_mul {p n : ℕ} (i : ℕ) (pgt1 : p > 1) (npos : n > 0)
|
|||
mult p (p^i * n) = i + mult p n :=
|
||||
begin
|
||||
induction i with [i, ih],
|
||||
{rewrite [pow_zero, one_mul, zero_add]},
|
||||
{krewrite [pow_zero, one_mul, zero_add]},
|
||||
have p > 0, from lt.trans zero_lt_one pgt1,
|
||||
have psin_pos : p^(succ i) * n > 0, from mul_pos (!pow_pos_of_pos this) npos,
|
||||
have p ∣ p^(succ i) * n, by rewrite [pow_succ, mul.assoc]; apply dvd_mul_right,
|
||||
|
@ -175,7 +175,7 @@ calc
|
|||
theorem mult_pow {p m : ℕ} (n : ℕ) (mpos : m > 0) (primep : prime p) : mult p (m^n) = n * mult p m :=
|
||||
begin
|
||||
induction n with n ih,
|
||||
rewrite [pow_zero, mult_one_right, zero_mul],
|
||||
krewrite [pow_zero, mult_one_right, zero_mul],
|
||||
rewrite [pow_succ, mult_mul primep mpos (!pow_pos_of_pos mpos), ih, succ_mul, add.comm]
|
||||
end
|
||||
|
||||
|
|
|
@ -43,9 +43,6 @@ add_test(NAME "lean_eqn_macro"
|
|||
add_test(NAME "lean_print_notation"
|
||||
WORKING_DIRECTORY "${LEAN_SOURCE_DIR}/../tests/lean/extra"
|
||||
COMMAND bash "./test_single.sh" "${CMAKE_CURRENT_BINARY_DIR}/lean" "print_tests.lean")
|
||||
add_test(NAME "auto_completion_issue_422"
|
||||
WORKING_DIRECTORY "${LEAN_SOURCE_DIR}/../tests/lean/extra"
|
||||
COMMAND bash "./ac_bug.sh" "${CMAKE_CURRENT_BINARY_DIR}/lean")
|
||||
add_test(NAME "issue_597"
|
||||
WORKING_DIRECTORY "${LEAN_SOURCE_DIR}/../tests/lean/extra"
|
||||
COMMAND bash "./issue_597.sh" "${CMAKE_CURRENT_BINARY_DIR}/lean")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
example (a b c : nat) : a = 2 → b = 3 → a + b + c = c + 5 :=
|
||||
begin
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Regression test for issue https://github.com/leanprover/lean/issues/422
|
||||
set -e
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage: ac_bug.sh [lean-executable-path]"
|
||||
exit 1
|
||||
fi
|
||||
LEAN=$1
|
||||
export LEAN_PATH=../../../library:.
|
||||
for f in `ls ac_bug*.input`; do
|
||||
echo "testing $f..."
|
||||
"$LEAN" --server-trace "$f" > "$f.produced.out"
|
||||
if grep "nat.mul.assoc" "$f.produced.out"; then
|
||||
echo "FAILED"
|
||||
exit 1
|
||||
fi
|
||||
rm -f -- "$f.produced.out"
|
||||
done
|
||||
echo "done"
|
|
@ -1,9 +0,0 @@
|
|||
VISIT ac_bug.lean
|
||||
SYNC 4
|
||||
import data.nat
|
||||
namespace nat
|
||||
check mul.as
|
||||
exit
|
||||
WAIT
|
||||
FINDP 3
|
||||
mul.as
|
|
@ -1,9 +0,0 @@
|
|||
VISIT ac_bug.lean
|
||||
SYNC 4
|
||||
import data.nat
|
||||
namespace nat
|
||||
check mul.as
|
||||
end nat
|
||||
WAIT
|
||||
FINDP 3
|
||||
mul.as
|
|
@ -1,10 +0,0 @@
|
|||
VISIT ac_bug.lean
|
||||
SYNC 5
|
||||
import data.nat
|
||||
namespace nat
|
||||
check mul.as
|
||||
end
|
||||
nat
|
||||
WAIT
|
||||
FINDP 3
|
||||
mul.as
|
|
@ -1,10 +0,0 @@
|
|||
VISIT ac_bug.lean
|
||||
SYNC 5
|
||||
import data.nat
|
||||
namespace nat
|
||||
check mul.as
|
||||
def a := 10
|
||||
end nat
|
||||
WAIT
|
||||
FINDP 3
|
||||
mul.as
|
|
@ -1,9 +0,0 @@
|
|||
VISIT ac_bug.lean
|
||||
SYNC 4
|
||||
import data.nat
|
||||
namespace nat
|
||||
check mul.as
|
||||
def a := 10
|
||||
WAIT
|
||||
FINDP 3
|
||||
mul.as
|
|
@ -1,10 +0,0 @@
|
|||
VISIT ac_bug.lean
|
||||
SYNC 5
|
||||
import data.nat
|
||||
namespace nat
|
||||
check mul.as
|
||||
def a := 10
|
||||
exit
|
||||
WAIT
|
||||
FINDP 3
|
||||
mul.as
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
example (a b c d : nat) : a + b = 0 → b = 0 → c + 1 + a = 1 → d = c - 1 → d = 0 :=
|
||||
begin
|
||||
|
@ -14,7 +14,7 @@ begin
|
|||
rewrite aeq0 at h₃,
|
||||
rewrite add_zero at h₃,
|
||||
rewrite add_succ at h₃,
|
||||
rewrite add_zero at h₃,
|
||||
krewrite add_zero at h₃,
|
||||
injection h₃, exact a_1
|
||||
end,
|
||||
rewrite ceq at h₄,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
VISIT consume_args.lean
|
||||
SYNC 7
|
||||
import logic data.nat.basic
|
||||
open nat eq.ops
|
||||
open nat eq.ops algebra
|
||||
|
||||
theorem tst (a b c : nat) : a + b + c = a + c + b :=
|
||||
calc a + b + c = a + (b + c) : !add.assoc
|
||||
|
|
|
@ -44,7 +44,7 @@ b
|
|||
a + c + b = a + (c + b)
|
||||
-- ACK
|
||||
-- IDENTIFIER|7|33
|
||||
nat.add.assoc
|
||||
algebra.add.assoc
|
||||
-- ACK
|
||||
-- TYPE|7|43
|
||||
a + c + b = a + (c + b) → a + (c + b) = a + c + b
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
definition foo (a b : nat) := a * b
|
||||
|
||||
|
|
|
@ -3,5 +3,5 @@ open nat
|
|||
|
||||
example (a b : nat) : 0 + a + 0 = a :=
|
||||
begin
|
||||
rewrite [add_zero, zero_add,]
|
||||
rewrite [nat.add_zero, nat.zero_add,]
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
attribute nat.add [unfold 2]
|
||||
attribute nat.rec_on [unfold 2]
|
||||
|
|
|
@ -18,6 +18,6 @@ example (a b c : nat) : (a + 0 = 0 + a ∧ b + 0 = 0 + b) ∧ c = c :=
|
|||
|
||||
begin
|
||||
apply and.intro,
|
||||
apply and.intro ;; (state; rewrite zero_add),
|
||||
apply and.intro ;; (state; rewrite nat.zero_add),
|
||||
apply rfl
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ open nat
|
|||
|
||||
theorem zero_left (n : ℕ) : 0 + n = n :=
|
||||
nat.induction_on n
|
||||
!add_zero
|
||||
!nat.add_zero
|
||||
(take m IH, show 0 + succ m = succ m, from
|
||||
calc
|
||||
0 + succ m = succ (0 + m) : add_succ
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
theorem tst (a b : nat) (H : a = 0) : a + b = b :=
|
||||
begin
|
||||
revert H,
|
||||
match a with
|
||||
| zero := λ H, by rewrite zero_add
|
||||
| zero := λ H, by krewrite zero_add
|
||||
| (n+1) := λ H, nat.no_confusion H
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,4 +2,4 @@ import data.nat
|
|||
open nat
|
||||
|
||||
example (x : ℕ) : 0 = x * 0 :=
|
||||
calc 0 = x * 0 : mul_zero
|
||||
calc 0 = x * 0 : nat.mul_zero
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import data.nat
|
||||
open algebra
|
||||
|
||||
theorem tst2 (A B C D : Type) : (A × B) × (C × D) → C × B × A :=
|
||||
assume p : (A × B) × (C × D),
|
||||
|
@ -62,5 +63,5 @@ obtain y (Hy : b = 2*y), from H₂,
|
|||
exists.intro
|
||||
(x+y)
|
||||
(calc a+b = 2*x + 2*y : by rewrite [Hx, Hy]
|
||||
... = 2*(x+y) : by rewrite mul.left_distrib)
|
||||
... = 2*(x+y) : by rewrite left_distrib)
|
||||
end hidden
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
namespace foo
|
||||
|
||||
|
@ -20,7 +20,7 @@ definition parity : Π (n : nat), Parity n
|
|||
end,
|
||||
begin
|
||||
change (Parity (2*k + 2*1)),
|
||||
rewrite -mul.left_distrib,
|
||||
rewrite -left_distrib,
|
||||
apply (Parity.even (k+1))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ print nat.rec
|
|||
print classical.em
|
||||
print quot.lift
|
||||
print nat.of_num
|
||||
print nat.add.assoc
|
||||
print nat.add_assoc
|
||||
|
||||
section
|
||||
parameter {A : Type}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat.basic
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
theorem zero_left (n : ℕ) : 0 + n = n :=
|
||||
nat.induction_on n
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
section
|
||||
variables (a b c d e : nat)
|
||||
|
@ -9,7 +9,7 @@ section
|
|||
end
|
||||
|
||||
example (x y : ℕ) : (x + y) * (x + y) = x * x + y * x + x * y + y * y :=
|
||||
by rewrite [*mul.left_distrib, *mul.right_distrib, -add.assoc]
|
||||
by rewrite [*left_distrib, *right_distrib, -add.assoc]
|
||||
|
||||
namespace tst
|
||||
definition even (a : nat) := ∃b, a = 2*b
|
||||
|
@ -19,7 +19,7 @@ exists.elim H1 (fun (w1 : nat) (Hw1 : a = 2*w1),
|
|||
exists.elim H2 (fun (w2 : nat) (Hw2 : b = 2*w2),
|
||||
exists.intro (w1 + w2)
|
||||
begin
|
||||
rewrite [Hw1, Hw2, mul.left_distrib]
|
||||
rewrite [Hw1, Hw2, left_distrib]
|
||||
end))
|
||||
|
||||
theorem T2 (a b c : nat) (H1 : a = b) (H2 : b = c + 1) : a ≠ 0 :=
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
variables (f : nat → nat → nat → nat) (a b c : nat)
|
||||
|
||||
example (H₁ : a = b) (H₂ : f b a b = 0) : f a a a = 0 :=
|
||||
|
|
|
@ -3,4 +3,4 @@ open nat
|
|||
constant f : nat → nat
|
||||
|
||||
theorem tst1 (x y : nat) (H1 : (λ z, z + 0) x = y) : f x = f y :=
|
||||
by rewrite [▸* at H1, add_zero at H1, H1]
|
||||
by rewrite [▸* at H1, nat.add_zero at H1, H1]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
constant f : nat → nat
|
||||
|
||||
example (x y : nat) (H1 : (λ z, z + 0) x = y) : f x = f y :=
|
||||
|
|
|
@ -8,5 +8,5 @@ attribute of_num [unfold 1]
|
|||
|
||||
example (x y : nat) (H1 : f x 0 0 = 0) : x = 0 :=
|
||||
begin
|
||||
rewrite [↑f at H1, 4>add_zero at H1, H1]
|
||||
rewrite [↑f at H1, 4>nat.add_zero at H1, H1]
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
set_option rewriter.syntactic true
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
theorem tst (x : nat) (H1 : x = 0) : x = 0 :=
|
||||
begin
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import data.nat
|
||||
|
||||
namespace foo
|
||||
attribute nat.add.assoc [simp]
|
||||
print nat.add.assoc
|
||||
attribute nat.add_assoc [simp]
|
||||
print nat.add_assoc
|
||||
end foo
|
||||
|
||||
print nat.add.assoc
|
||||
print nat.add_assoc
|
||||
|
||||
namespace foo
|
||||
print nat.add.assoc
|
||||
attribute nat.add.comm [simp]
|
||||
print nat.add_assoc
|
||||
attribute nat.add_comm [simp]
|
||||
open nat
|
||||
print "---------"
|
||||
print [simp]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
example : ∀ a b : nat, a + b = b + a :=
|
||||
show ∀ a b : nat, a + b = b + a
|
||||
|
|
|
@ -7,7 +7,7 @@ structure semigroup [class] (A : Type) :=
|
|||
mk {} :: (mul: A → A → A) (mul_assoc : associative mul)
|
||||
|
||||
definition nat_semigroup [instance] : semigroup nat :=
|
||||
semigroup.mk nat.mul nat.mul.assoc
|
||||
semigroup.mk nat.mul nat.mul_assoc
|
||||
|
||||
example (a b c : nat) : (a * b) * c = a * (b * c) :=
|
||||
semigroup.mul_assoc a b c
|
||||
|
@ -15,7 +15,7 @@ semigroup.mul_assoc a b c
|
|||
structure semigroup2 (A : Type) :=
|
||||
mk () :: (mul: A → A → A) (mul_assoc : associative mul)
|
||||
|
||||
definition s := semigroup2.mk nat nat.mul nat.mul.assoc
|
||||
definition s := semigroup2.mk nat nat.mul nat.mul_assoc
|
||||
|
||||
example (a b c : nat) : (a * b) * c = a * (b * c) :=
|
||||
semigroup2.mul_assoc nat s a b c
|
||||
|
|
|
@ -12,7 +12,7 @@ structure s3 (A : Type) extends s1 A, s2 A :=
|
|||
|
||||
definition v1 : s1 nat := {| s1, x := 10, y := 10, h := rfl |}
|
||||
definition v2 : s2 nat := {| s2, mul := nat.add, one := zero |}
|
||||
definition v3 : s3 nat := {| s3, mul_one := add_zero, v1, v2 |}
|
||||
definition v3 : s3 nat := {| s3, mul_one := nat.add_zero, v1, v2 |}
|
||||
|
||||
example : s3.x v3 = 10 := rfl
|
||||
example : s3.y v3 = 10 := rfl
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import data.nat
|
||||
open algebra
|
||||
|
||||
example (a b c : Prop) : a → b → c → a ∧ b ∧ c :=
|
||||
begin
|
||||
|
|
|
@ -18,7 +18,7 @@ private definition fib_fast_aux : nat → nat → nat → nat
|
|||
| (succ n) i j := fib_fast_aux n j (j+i)
|
||||
|
||||
lemma fib_fast_aux_lemma : ∀ n m, fib_fast_aux n (fib m) (fib (succ m)) = fib (succ (n + m))
|
||||
| 0 m := by rewrite zero_add
|
||||
| 0 m := by rewrite nat.zero_add
|
||||
| (succ n) m :=
|
||||
begin
|
||||
have ih : fib_fast_aux n (fib (succ m)) (fib (succ (succ m))) = fib (succ (n + succ m)), from fib_fast_aux_lemma n (succ m),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
example (a b : nat) : a = b → 0 + a = 0 + b :=
|
||||
begin
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
import logic data.nat
|
||||
-- import congr
|
||||
|
||||
open nat
|
||||
open nat algebra
|
||||
-- open congr
|
||||
open eq.ops eq
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import data.nat
|
||||
open nat
|
||||
open nat algebra
|
||||
|
||||
definition f (a b : nat) := a + b
|
||||
|
||||
|
|
Loading…
Reference in a new issue