blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
7
139
content_id
stringlengths
40
40
detected_licenses
listlengths
0
16
license_type
stringclasses
2 values
repo_name
stringlengths
7
55
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
6 values
visit_date
int64
1,471B
1,694B
revision_date
int64
1,378B
1,694B
committer_date
int64
1,378B
1,694B
github_id
float64
1.33M
604M
star_events_count
int64
0
43.5k
fork_events_count
int64
0
1.5k
gha_license_id
stringclasses
6 values
gha_event_created_at
int64
1,402B
1,695B
gha_created_at
int64
1,359B
1,637B
gha_language
stringclasses
19 values
src_encoding
stringclasses
2 values
language
stringclasses
1 value
is_vendor
bool
1 class
is_generated
bool
1 class
length_bytes
int64
3
6.4M
extension
stringclasses
4 values
content
stringlengths
3
6.12M
d285567b863d12d2b26f4012a04f030a0d153326
8e31b9e0d8cec76b5aa1e60a240bbd557d01047c
/scratch/simplex_no_prebasis.lean
6a480bc27131e63410d16cae1f1620b95a109096
[]
no_license
ChrisHughes24/LP
7bdd62cb648461c67246457f3ddcb9518226dd49
e3ed64c2d1f642696104584e74ae7226d8e916de
refs/heads/master
1,685,642,642,858
1,578,070,602,000
1,578,070,602,000
195,268,102
4
3
null
1,569,229,518,000
1,562,255,287,000
Lean
UTF-8
Lean
false
false
12,544
lean
import data.matrix data.rat.basic .misc tactic.fin_cases import .matrix_pequiv order.order_iso .simplex_new_pivot open matrix fintype finset function pequiv simplex simplex.prebasis variables {m n k: ℕ} local notation `rvec`:2000 n := matrix (fin 1) (fin n) ℚ local notation `cvec`:2000 m := matrix (fin m) (fin 1) ℚ local infix ` ⬝ `:70 := matrix.mul local postfix `ᵀ` : 1500 := transpose local attribute [instance] matrix.partial_order namespace simplex' def choose_pivot_column (AN_bar : matrix (fin m) (fin (n - m)) ℚ) (c : rvec (n - m)) : option (fin (n - m)) := fin.find (λ s : fin (n - m), 0 < c 0 s) def choose_pivot_row (AN_bar : matrix (fin m) (fin (n - m)) ℚ) (b_bar : cvec m) (s : fin (n - m)) : option (fin m) := fin.find (λ r : fin m, 0 < AN_bar r s ∧ ∀ i : fin m, 0 < AN_bar i s → (AN_bar r s)⁻¹ * b_bar r 0 ≤ (AN_bar i s)⁻¹ * b_bar i 0) lemma choose_pivot_column_eq_none (B : prebasis m n) (A_bar : matrix (fin m) (fin n) ℚ) (b_bar : cvec m) (c : rvec n) (hA_bar : A_bar ⬝ B.basis.to_matrixᵀ = 1) (h0b : 0 ≤ b_bar) (h : choose_pivot_column (A_bar ⬝ B.nonbasis.to_matrixᵀ) (reduced_cost B A_bar c) = none) : is_optimal_basis B A_bar b_bar c := is_optimal_basis_of_reduced_cost_nonpos _ _ hA_bar h0b $ begin intros i j, fin_cases i, exact le_of_not_gt (fin.find_eq_none_iff.1 h j : _) end lemma choose_pivot_row_eq_none (B : prebasis m n) (A_bar : matrix (fin m) (fin n) ℚ) (b_bar : cvec m) (r : fin m) (s : fin (n - m)) (hn : choose_pivot_row (A_bar ⬝ B.nonbasis.to_matrixᵀ) b_bar s = none) : (A_bar ⬝ B.nonbasis.to_matrixᵀ) r s ≤ 0 := le_of_not_gt $ λ (hpivot : _ < _), begin rw [choose_pivot_row, fin.find_eq_none_iff] at hn, cases @finset.min_of_mem _ _ ((univ.filter (λ j : fin m, 0 < (A_bar ⬝ B.nonbasis.to_matrixᵀ) j s)).image (λ i, ((A_bar ⬝ B.nonbasis.to_matrixᵀ) i s)⁻¹ * b_bar i 0)) (((A_bar ⬝ B.nonbasis.to_matrixᵀ) r s)⁻¹ * b_bar r 0) (mem_image_of_mem _ (by simp *)) with q hq, rcases mem_image.1 (mem_of_min hq) with ⟨i, hip, hiq⟩, subst hiq, refine hn i ⟨(finset.mem_filter.1 hip).2, λ j hj, _⟩, refine min_le_of_mem _ hq, refine mem_image_of_mem _ _, simpa using hj end lemma choose_pivot_column_spec (AN_bar : matrix (fin m) (fin (n - m)) ℚ) (c : rvec (n - m)) (s : fin (n - m)) (hs : s ∈ choose_pivot_column AN_bar c) : 0 < c 0 s := fin.find_spec _ hs def swap_inverse (AN_bar : matrix (fin m) (fin (n - m)) ℚ) (r : fin m) (s : fin (n - m)) : matrix (fin m) (fin m) ℚ := let pivot_inv := (AN_bar r s)⁻¹ in (1 : matrix (fin m) (fin m) ℚ).write_column r (λ i, if i = r then pivot_inv else -AN_bar i s * pivot_inv) lemma pivot_element_eq (B : prebasis m n) (A_bar : matrix (fin m) (fin n) ℚ) (r : fin m) (s : fin (n - m)) : (pivot_element B A_bar r s) = (λ _ _, (A_bar ⬝ B.nonbasis.to_matrixᵀ) r s) := begin ext i j, have hi : i = 0, from subsingleton.elim _ _, have hj : j = 0, from subsingleton.elim _ _, substs hi hj, simp only [pivot_element, matrix_mul_apply, mul_matrix_apply, (to_matrix_symm _).symm], refl end lemma single_apply {α β : Type*} [decidable_eq α] [decidable_eq β] (a a' : α) (b : β) : single a b a' = if a' = a then some b else none := rfl @[simp] lemma add_add_neg_cancel'_right {α : Type*} [add_comm_group α] (a b : α) : a + (b + -a) = b := add_sub_cancel'_right a b lemma swap_inverse_eq_swap_inverse (B : prebasis m n) (AN_bar : matrix (fin m) (fin (n - m)) ℚ) (r : fin m) (s : fin (n - m)) (hpivot : AN_bar r s ≠ 0) : swap_inverse AN_bar r s = simplex.swap_inverse B (AN_bar ⬝ B.nonbasis.to_matrix) r s := have ∀ i j r s, (AN_bar ⬝ ((single s (0 : fin 1)).to_matrix ⬝ (λ (_ _ : fin 1), (AN_bar r s)⁻¹))) i j = (AN_bar r s)⁻¹ * AN_bar i s, begin intros, fin_cases j, rw [← matrix.mul_assoc, mul_eq_smul, matrix.smul_val, matrix_mul_apply, symm_single, simplex'.single_apply, if_pos], congr, end, begin ext i j, simp [simplex'.swap_inverse, simplex.swap_inverse, matrix.mul_add, matrix.add_mul, matrix.add_val, write_column_apply, matrix.neg_val, mul_matrix_apply, matrix_mul_apply, one_val, pivot_element_eq, inv_def], dsimp [symm_single, simplex'.single_apply], split_ifs, { rw [if_pos h.symm, if_pos h_1], simp [add_val, neg_val, one_val, matrix.mul_assoc, this, h_1, inv_mul_cancel hpivot], }, { cc }, { cc }, { rw [if_neg h_1, if_pos h.symm], simp [matrix.mul_assoc, this, mul_comm] }, { cc }, { rw [if_neg (ne.symm h), if_neg h_2], simp }, { rw [if_pos h_2, if_neg (ne.symm h)], simp }, { rw [if_neg h_2, if_neg (ne.symm h)], simp } end lemma swap_nonbasis_eq (B : prebasis m n) (r : fin m) (s : fin (n - m)) : (B.swap r s).nonbasis.to_matrix = (B.nonbasis.to_matrix : matrix _ _ ℚ) + (single s (B.basisg r)).to_matrix - (single s (B.nonbasisg s)).to_matrix := begin dsimp [prebasis.swap], simp only [to_matrix_swap, to_matrix_trans], simp [matrix.mul_add, (to_matrix_trans _ _).symm, trans_single_of_mem _ (nonbasisg_mem B s), trans_single_of_eq_none _ (nonbasis_basisg_eq_none B r)] end lemma nonbasis_transpose_mul_single (B : prebasis m n) (i : fin (n - m)) (j : fin k) : (B.nonbasis.to_matrixᵀ : matrix _ _ ℚ) ⬝ (single i j).to_matrix = (single (B.nonbasisg i) j).to_matrix := by rw [← to_matrix_symm, ← to_matrix_trans, trans_single_of_mem _ (nonbasis_nonbasisg _ _)] lemma basis_transpose_mul_single (B : prebasis m n) (i : fin m) (j : fin k) : (B.basis.to_matrixᵀ : matrix _ _ ℚ) ⬝ (single i j).to_matrix = (single (B.basisg i) j).to_matrix := by rw [← to_matrix_symm, ← to_matrix_trans, trans_single_of_mem _ (basis_basisg _ _)] @[simp] lemma swap_nonbasis_mul_single_of_eq (B : prebasis m n) (r : fin m) (s : fin (n - m)) : ((B.swap r s).nonbasis.to_matrixᵀ : matrix _ _ ℚ) ⬝ (single s (0 : fin 1)).to_matrix = B.basis.to_matrixᵀ ⬝ (single r 0).to_matrix := begin simp [swap_nonbasis_eq, transpose_add, (to_matrix_symm _).symm, matrix.add_mul], simp [to_matrix_symm, nonbasis_transpose_mul_single, basis_transpose_mul_single], end @[simp] lemma swap_nonbasis_mul_single_of_ne (B : prebasis m n) (r : fin m) {s : fin (n - m)} {j : fin (n - m)} (hsj : s ≠ j) : ((B.swap r s).nonbasis.to_matrixᵀ : matrix _ _ ℚ) ⬝ (single j (0 : fin 1)).to_matrix = B.nonbasis.to_matrixᵀ ⬝ (single j 0).to_matrix := begin simp [swap_nonbasis_eq, transpose_add, (to_matrix_symm _).symm, matrix.add_mul], simp [to_matrix_symm, nonbasis_transpose_mul_single, basis_transpose_mul_single, single_mul_single_of_ne hsj], end lemma reduced_cost_swap (B : prebasis m n) (A_bar : matrix (fin m) (fin n) ℚ) (c : rvec n) (r : fin m) (s : fin (n - m)) (hA_bar : A_bar ⬝ B.basis.to_matrixᵀ = 1) (hpivot : pivot_element B A_bar r s ≠ 0) : reduced_cost (B.swap r s) (simplex.swap_inverse B A_bar r s ⬝ A_bar) c = reduced_cost B A_bar c ⬝ (1 - (single s (0 : fin 1)).to_matrix ⬝ (pivot_element B A_bar r s)⁻¹ ⬝ (single 0 r).to_matrix ⬝ A_bar ⬝ B.nonbasis.to_matrixᵀ - (single s 0).to_matrix ⬝ (pivot_element B A_bar r s)⁻¹ ⬝ (single 0 s).to_matrix) := have h₁ : simplex.swap_inverse B A_bar r s ⬝ A_bar ⬝ (to_matrix ((swap B r s).basis))ᵀ = 1, by rw [matrix.mul_assoc, swap_mul_swap_inverse hA_bar hpivot], have h₂ : ∀ {k : ℕ}, ∀ {M : matrix (fin 1) (fin k) ℚ}, to_matrix (single s r) ⬝ (A_bar ⬝ ((to_matrix (B.nonbasis))ᵀ ⬝ (to_matrix (single s 0) ⬝ ((pivot_element B A_bar r s)⁻¹ ⬝ M)))) = (single s 0).to_matrix ⬝ M, begin intros, rw [← single_mul_single s (0 : fin 1) r, matrix.mul_assoc], refine congr_arg (matrix.mul _) _, simp only [(matrix.mul_assoc _ _ _).symm, pivot_element, inv_eq_inverse] at ⊢ hpivot, rw [one_by_one_mul_inv_cancel hpivot, matrix.one_mul] end, begin refine mul_single_ext (λ j, _), let x : matrix _ _ ℚ := (B.swap r s).nonbasis.to_matrixᵀ ⬝ (single j (0 : fin 1)).to_matrix, have hxdef : x = (B.swap r s).nonbasis.to_matrixᵀ ⬝ (single j (0 : fin 1)).to_matrix, from rfl, have hx : (single j (0 : fin 1)).to_matrix = (B.swap r s).nonbasis.to_matrix ⬝ x, { simp [x, (matrix.mul_assoc _ _ _).symm] }, let b_bar := (simplex.swap_inverse B A_bar r s ⬝ A_bar) ⬝ x, rw [hx, ← matrix.mul_assoc, ← add_left_inj (c ⬝ (B.swap r s).basis.to_matrixᵀ ⬝ b_bar), ← objective_function_eq rfl h₁, matrix.mul_assoc c _ b_bar], have h₃ : A_bar ⬝ ((to_matrix ((swap B r s).basis))ᵀ ⬝ b_bar) = A_bar ⬝ x, { simp only [b_bar, x, (matrix.mul_assoc _ _ _).symm], rw [mul_eq_one_comm.1 (swap_mul_swap_inverse hA_bar hpivot), matrix.one_mul], }, conv_rhs {rw [objective_function_eq h₃ hA_bar], }, conv_lhs {rw [objective_function_eq rfl hA_bar] }, simp [x, b_bar, simplex.swap_inverse, matrix.mul_add, matrix.mul_assoc, mul_right_eq_of_mul_eq (nonbasis_mul_nonbasis_transpose _), matrix.add_mul, mul_right_eq_of_mul_eq (nonbasis_mul_swap_basis_tranpose _ _ _), h₂], by_cases hjs : j = s, { simp only [pivot_element, matrix.mul_assoc] at hpivot, simp [hjs, mul_right_eq_of_mul_eq hA_bar, matrix.mul_assoc, mul_right_eq_of_mul_eq (nonbasis_mul_basis_transpose _), pivot_element, inv_eq_inverse, one_by_one_inv_mul_cancel hpivot] }, { simp [mul_right_eq_of_mul_eq hA_bar, single_mul_single_of_ne (ne.symm hjs), swap_nonbasis_mul_single_of_ne _ _ (ne.symm hjs), mul_right_eq_of_mul_eq (nonbasis_mul_nonbasis_transpose _)] } end set_option eqn_compiler.zeta true def simplex : Π (B : prebasis m n) (AN_bar : matrix (fin m) (fin (n - m)) ℚ) (b_bar : cvec m) (c : rvec (n - m)), option (prebasis m n × matrix (fin m) (fin (n - m)) ℚ × (cvec m) × (rvec (n - m))) | B AN_bar b_bar c := match choose_pivot_column AN_bar c with | none := some (B, AN_bar, b_bar, c) | some s := match choose_pivot_row AN_bar b_bar s with | none := none | some r := have wf : false, from sorry, let S := simplex'.swap_inverse AN_bar r s in let AN_bar' : matrix (fin m) (fin (n - m)) ℚ := AN_bar.write_column s (λ j, if j = r then (1 : ℚ) else 0) in simplex (B.swap r s) (S ⬝ AN_bar') (S ⬝ b_bar) ((c - (c 0 s / AN_bar r s) • (λ _, AN_bar r) - (0 : matrix _ _ ℚ).write_column s (λ _, c 0 s / AN_bar r s))) end end using_well_founded { rel_tac := λ _ _, `[exact ⟨_, empty_wf⟩], dec_tac := tactic.assumption } lemma simplex_spec : Π (B : prebasis m n) (A_bar : matrix (fin m) (fin n) ℚ) (b_bar : cvec m) (c : rvec n) (hA_bar : A_bar ⬝ B.basis.to_matrixᵀ = 1) (h0b : 0 ≤ b_bar), (option.cases_on (simplex B (A_bar ⬝ B.nonbasis.to_matrixᵀ) b_bar (reduced_cost B A_bar c)) (is_unbounded A_bar b_bar c) (λ P, is_optimal_basis P.1 A_bar b_bar c) : Prop) | B A_bar b_bar c := assume hA_bar h0b, begin rw [simplex'.simplex], cases hs : choose_pivot_column (A_bar ⬝ B.nonbasis.to_matrixᵀ) (reduced_cost B A_bar c) with s, { dsimp [simplex'.simplex._match_3], exact choose_pivot_column_eq_none _ _ _ _ hA_bar h0b hs }, { dsimp [simplex'.simplex._match_3], cases hr : choose_pivot_row (A_bar ⬝ B.nonbasis.to_matrixᵀ) b_bar s with r, { dsimp [simplex'.simplex._match_4], have : 0 < reduced_cost B A_bar c ⬝ (single s (0 : fin 1)).to_matrix, { rw [cvec_one_lt_iff, matrix_mul_apply], exact choose_pivot_column_spec _ _ _ hs }, exact is_unbounded_of_pivot_element_nonpos b_bar _ hA_bar h0b this (λ r i j, by rw [pivot_element_eq]; exact choose_pivot_row_eq_none _ _ _ _ _ hr) }, { dsimp [simplex'.simplex._match_4], let AN_bar := A_bar ⬝ B.nonbasis.to_matrixᵀ, let S := simplex'.swap_inverse AN_bar r s, let AN_bar' : matrix (fin m) (fin (n - m)) ℚ := AN_bar.write_column s (λ j, if j = r then (1 : ℚ) else 0), have := simplex_spec (B.swap r s) _ _ _ _ _, } }, end end simplex' def ex.A := list.to_matrix 3 4 [[1/64443321, 18932, -1, 9], [1/2, -7/145931, -1/145903, 3], [ -11, -1111, 22, 100]] def ex.b : cvec 3 := (λ i _, list.nth_le [0,0,1] i sorry) --#eval ex.b def ex.c : rvec 4 := λ _ i, (list.nth_le [3/4, -20, 1/2, -6] i sorry) #eval @_root_.simplex 3 7 ex.A ex.b ex.c
a48159ea13816dc24c9156efb1f7b1647953e313
432d948a4d3d242fdfb44b81c9e1b1baacd58617
/src/algebra/lie/classical.lean
4c367d69213d9ca8f50da84d091a3af4dbcf6c3f
[ "Apache-2.0" ]
permissive
JLimperg/aesop3
306cc6570c556568897ed2e508c8869667252e8a
a4a116f650cc7403428e72bd2e2c4cda300fe03f
refs/heads/master
1,682,884,916,368
1,620,320,033,000
1,620,320,033,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
13,446
lean
/- Copyright (c) 2020 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import algebra.invertible import algebra.lie.skew_adjoint import algebra.lie.abelian /-! # Classical Lie algebras This file is the place to find definitions and basic properties of the classical Lie algebras: * Aₗ = sl(l+1) * Bₗ ≃ so(l+1, l) ≃ so(2l+1) * Cₗ = sp(l) * Dₗ ≃ so(l, l) ≃ so(2l) ## Main definitions * `lie_algebra.special_linear.sl` * `lie_algebra.symplectic.sp` * `lie_algebra.orthogonal.so` * `lie_algebra.orthogonal.so'` * `lie_algebra.orthogonal.so_indefinite_equiv` * `lie_algebra.orthogonal.type_D` * `lie_algebra.orthogonal.type_B` * `lie_algebra.orthogonal.type_D_equiv_so'` * `lie_algebra.orthogonal.type_B_equiv_so'` ## Implementation notes ### Matrices or endomorphisms Given a finite type and a commutative ring, the corresponding square matrices are equivalent to the endomorphisms of the corresponding finite-rank free module as Lie algebras, see `lie_equiv_matrix'`. We can thus define the classical Lie algebras as Lie subalgebras either of matrices or of endomorphisms. We have opted for the former. At the time of writing (August 2020) it is unclear which approach should be preferred so the choice should be assumed to be somewhat arbitrary. ### Diagonal quadratic form or diagonal Cartan subalgebra For the algebras of type `B` and `D`, there are two natural definitions. For example since the the `2l × 2l` matrix: $$ J = \left[\begin{array}{cc} 0_l & 1_l\\ 1_l & 0_l \end{array}\right] $$ defines a symmetric bilinear form equivalent to that defined by the identity matrix `I`, we can define the algebras of type `D` to be the Lie subalgebra of skew-adjoint matrices either for `J` or for `I`. Both definitions have their advantages (in particular the `J`-skew-adjoint matrices define a Lie algebra for which the diagonal matrices form a Cartan subalgebra) and so we provide both. We thus also provide equivalences `type_D_equiv_so'`, `so_indefinite_equiv` which show the two definitions are equivalent. Similarly for the algebras of type `B`. ## Tags classical lie algebra, special linear, symplectic, orthogonal -/ universes u₁ u₂ namespace lie_algebra open_locale matrix variables (n p q l : Type*) (R : Type u₂) variables [fintype n] [fintype l] [fintype p] [fintype q] variables [decidable_eq n] [decidable_eq p] [decidable_eq q] [decidable_eq l] variables [comm_ring R] @[simp] lemma matrix_trace_commutator_zero (X Y : matrix n n R) : matrix.trace n R R ⁅X, Y⁆ = 0 := begin -- TODO: if we use matrix.mul here, we get a timeout change matrix.trace n R R (X * Y - Y * X) = 0, erw [linear_map.map_sub, matrix.trace_mul_comm, sub_self] end namespace special_linear /-- The special linear Lie algebra: square matrices of trace zero. -/ def sl : lie_subalgebra R (matrix n n R) := { lie_mem' := λ X Y _ _, linear_map.mem_ker.2 $ matrix_trace_commutator_zero _ _ _ _, ..linear_map.ker (matrix.trace n R R) } lemma sl_bracket (A B : sl n R) : ⁅A, B⁆.val = A.val ⬝ B.val - B.val ⬝ A.val := rfl section elementary_basis variables {n} (i j : n) /-- It is useful to define these matrices for explicit calculations in sl n R. -/ abbreviation E : matrix n n R := λ i' j', if i = i' ∧ j = j' then 1 else 0 @[simp] lemma E_apply_one : E R i j i j = 1 := if_pos (and.intro rfl rfl) @[simp] lemma E_apply_zero (i' j' : n) (h : ¬(i = i' ∧ j = j')) : E R i j i' j' = 0 := if_neg h @[simp] lemma E_diag_zero (h : j ≠ i) : matrix.diag n R R (E R i j) = 0 := begin ext k, rw matrix.diag_apply, suffices : ¬(i = k ∧ j = k), by exact if_neg this, rintros ⟨e₁, e₂⟩, apply h, subst e₁, exact e₂, end lemma E_trace_zero (h : j ≠ i) : matrix.trace n R R (E R i j) = 0 := by simp [h] /-- When j ≠ i, the elementary matrices are elements of sl n R, in fact they are part of a natural basis of sl n R. -/ def Eb (h : j ≠ i) : sl n R := ⟨E R i j, by { change E R i j ∈ linear_map.ker (matrix.trace n R R), simp [E_trace_zero R i j h], }⟩ @[simp] lemma Eb_val (h : j ≠ i) : (Eb R i j h).val = E R i j := rfl end elementary_basis lemma sl_non_abelian [nontrivial R] (h : 1 < fintype.card n) : ¬is_lie_abelian ↥(sl n R) := begin rcases fintype.exists_pair_of_one_lt_card h with ⟨j, i, hij⟩, let A := Eb R i j hij, let B := Eb R j i hij.symm, intros c, have c' : A.val ⬝ B.val = B.val ⬝ A.val, by { rw [← sub_eq_zero, ← sl_bracket, c.trivial], refl }, have : (1 : R) = 0 := by simpa [matrix.mul_apply, hij] using (congr_fun (congr_fun c' i) i), exact one_ne_zero this, end end special_linear namespace symplectic /-- The matrix defining the canonical skew-symmetric bilinear form. -/ def J : matrix (l ⊕ l) (l ⊕ l) R := matrix.from_blocks 0 (-1) 1 0 /-- The symplectic Lie algebra: skew-adjoint matrices with respect to the canonical skew-symmetric bilinear form. -/ def sp : lie_subalgebra R (matrix (l ⊕ l) (l ⊕ l) R) := skew_adjoint_matrices_lie_subalgebra (J l R) end symplectic namespace orthogonal /-- The definite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric bilinear form defined by the identity matrix. -/ def so : lie_subalgebra R (matrix n n R) := skew_adjoint_matrices_lie_subalgebra (1 : matrix n n R) @[simp] lemma mem_so (A : matrix n n R) : A ∈ so n R ↔ Aᵀ = -A := begin erw mem_skew_adjoint_matrices_submodule, simp only [matrix.is_skew_adjoint, matrix.is_adjoint_pair, matrix.mul_one, matrix.one_mul], end /-- The indefinite diagonal matrix with `p` 1s and `q` -1s. -/ def indefinite_diagonal : matrix (p ⊕ q) (p ⊕ q) R := matrix.diagonal $ sum.elim (λ _, 1) (λ _, -1) /-- The indefinite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric bilinear form defined by the indefinite diagonal matrix. -/ def so' : lie_subalgebra R (matrix (p ⊕ q) (p ⊕ q) R) := skew_adjoint_matrices_lie_subalgebra $ indefinite_diagonal p q R /-- A matrix for transforming the indefinite diagonal bilinear form into the definite one, provided the parameter `i` is a square root of -1. -/ def Pso (i : R) : matrix (p ⊕ q) (p ⊕ q) R := matrix.diagonal $ sum.elim (λ _, 1) (λ _, i) lemma Pso_inv {i : R} (hi : i*i = -1) : (Pso p q R i) * (Pso p q R (-i)) = 1 := begin ext x y, rcases x; rcases y, { -- x y : p by_cases h : x = y; simp [Pso, indefinite_diagonal, h], }, { -- x : p, y : q simp [Pso, indefinite_diagonal], }, { -- x : q, y : p simp [Pso, indefinite_diagonal], }, { -- x y : q by_cases h : x = y; simp [Pso, indefinite_diagonal, h, hi], }, end lemma is_unit_Pso {i : R} (hi : i*i = -1) : is_unit (Pso p q R i) := ⟨{ val := Pso p q R i, inv := Pso p q R (-i), val_inv := Pso_inv p q R hi, inv_val := by { apply matrix.nonsing_inv_left_right, exact Pso_inv p q R hi, }, }, rfl⟩ lemma indefinite_diagonal_transform {i : R} (hi : i*i = -1) : (Pso p q R i)ᵀ ⬝ (indefinite_diagonal p q R) ⬝ (Pso p q R i) = 1 := begin ext x y, rcases x; rcases y, { -- x y : p by_cases h : x = y; simp [Pso, indefinite_diagonal, h], }, { -- x : p, y : q simp [Pso, indefinite_diagonal], }, { -- x : q, y : p simp [Pso, indefinite_diagonal], }, { -- x y : q by_cases h : x = y; simp [Pso, indefinite_diagonal, h, hi], }, end /-- An equivalence between the indefinite and definite orthogonal Lie algebras, over a ring containing a square root of -1. -/ noncomputable def so_indefinite_equiv {i : R} (hi : i*i = -1) : so' p q R ≃ₗ⁅R⁆ so (p ⊕ q) R := begin apply (skew_adjoint_matrices_lie_subalgebra_equiv (indefinite_diagonal p q R) (Pso p q R i) (is_unit_Pso p q R hi)).trans, apply lie_equiv.of_eq, ext A, rw indefinite_diagonal_transform p q R hi, refl, end lemma so_indefinite_equiv_apply {i : R} (hi : i*i = -1) (A : so' p q R) : (so_indefinite_equiv p q R hi A : matrix (p ⊕ q) (p ⊕ q) R) = (Pso p q R i)⁻¹ ⬝ (A : matrix (p ⊕ q) (p ⊕ q) R) ⬝ (Pso p q R i) := by erw [lie_equiv.trans_apply, lie_equiv.of_eq_apply, skew_adjoint_matrices_lie_subalgebra_equiv_apply] /-- A matrix defining a canonical even-rank symmetric bilinear form. It looks like this as a `2l x 2l` matrix of `l x l` blocks: [ 0 1 ] [ 1 0 ] -/ def JD : matrix (l ⊕ l) (l ⊕ l) R := matrix.from_blocks 0 1 1 0 /-- The classical Lie algebra of type D as a Lie subalgebra of matrices associated to the matrix `JD`. -/ def type_D := skew_adjoint_matrices_lie_subalgebra (JD l R) /-- A matrix transforming the bilinear form defined by the matrix `JD` into a split-signature diagonal matrix. It looks like this as a `2l x 2l` matrix of `l x l` blocks: [ 1 -1 ] [ 1 1 ] -/ def PD : matrix (l ⊕ l) (l ⊕ l) R := matrix.from_blocks 1 (-1) 1 1 /-- The split-signature diagonal matrix. -/ def S := indefinite_diagonal l l R lemma S_as_blocks : S l R = matrix.from_blocks 1 0 0 (-1) := begin rw [← matrix.diagonal_one, matrix.diagonal_neg, matrix.from_blocks_diagonal], refl, end lemma JD_transform : (PD l R)ᵀ ⬝ (JD l R) ⬝ (PD l R) = (2 : R) • (S l R) := begin have h : (PD l R)ᵀ ⬝ (JD l R) = matrix.from_blocks 1 1 1 (-1) := by { simp [PD, JD, matrix.from_blocks_transpose, matrix.from_blocks_multiply], }, erw [h, S_as_blocks, matrix.from_blocks_multiply, matrix.from_blocks_smul], congr; simp [two_smul], end lemma PD_inv [invertible (2 : R)] : (PD l R) * (⅟(2 : R) • (PD l R)ᵀ) = 1 := begin have h : ⅟(2 : R) • (1 : matrix l l R) + ⅟(2 : R) • 1 = 1 := by rw [← smul_add, ← (two_smul R _), smul_smul, inv_of_mul_self, one_smul], erw [matrix.from_blocks_transpose, matrix.from_blocks_smul, matrix.mul_eq_mul, matrix.from_blocks_multiply], simp [h], end lemma is_unit_PD [invertible (2 : R)] : is_unit (PD l R) := ⟨{ val := PD l R, inv := ⅟(2 : R) • (PD l R)ᵀ, val_inv := PD_inv l R, inv_val := by { apply matrix.nonsing_inv_left_right, exact PD_inv l R, }, }, rfl⟩ /-- An equivalence between two possible definitions of the classical Lie algebra of type D. -/ noncomputable def type_D_equiv_so' [invertible (2 : R)] : type_D l R ≃ₗ⁅R⁆ so' l l R := begin apply (skew_adjoint_matrices_lie_subalgebra_equiv (JD l R) (PD l R) (is_unit_PD l R)).trans, apply lie_equiv.of_eq, ext A, rw [JD_transform, ← unit_of_invertible_val (2 : R), lie_subalgebra.mem_coe, mem_skew_adjoint_matrices_lie_subalgebra_unit_smul], refl, end /-- A matrix defining a canonical odd-rank symmetric bilinear form. It looks like this as a `(2l+1) x (2l+1)` matrix of blocks: [ 2 0 0 ] [ 0 0 1 ] [ 0 1 0 ] where sizes of the blocks are: [`1 x 1` `1 x l` `1 x l`] [`l x 1` `l x l` `l x l`] [`l x 1` `l x l` `l x l`] -/ def JB := matrix.from_blocks ((2 : R) • 1 : matrix unit unit R) 0 0 (JD l R) /-- The classical Lie algebra of type B as a Lie subalgebra of matrices associated to the matrix `JB`. -/ def type_B := skew_adjoint_matrices_lie_subalgebra (JB l R) /-- A matrix transforming the bilinear form defined by the matrix `JB` into an almost-split-signature diagonal matrix. It looks like this as a `(2l+1) x (2l+1)` matrix of blocks: [ 1 0 0 ] [ 0 1 -1 ] [ 0 1 1 ] where sizes of the blocks are: [`1 x 1` `1 x l` `1 x l`] [`l x 1` `l x l` `l x l`] [`l x 1` `l x l` `l x l`] -/ def PB := matrix.from_blocks (1 : matrix unit unit R) 0 0 (PD l R) lemma PB_inv [invertible (2 : R)] : (PB l R) * (matrix.from_blocks 1 0 0 (PD l R)⁻¹) = 1 := begin simp [PB, matrix.from_blocks_multiply, (PD l R).mul_nonsing_inv, is_unit_PD, ← (PD l R).is_unit_iff_is_unit_det] end lemma is_unit_PB [invertible (2 : R)] : is_unit (PB l R) := ⟨{ val := PB l R, inv := matrix.from_blocks 1 0 0 (PD l R)⁻¹, val_inv := PB_inv l R, inv_val := by { apply matrix.nonsing_inv_left_right, exact PB_inv l R, }, }, rfl⟩ lemma JB_transform : (PB l R)ᵀ ⬝ (JB l R) ⬝ (PB l R) = (2 : R) • matrix.from_blocks 1 0 0 (S l R) := by simp [PB, JB, JD_transform, matrix.from_blocks_transpose, matrix.from_blocks_multiply, matrix.from_blocks_smul] lemma indefinite_diagonal_assoc : indefinite_diagonal (unit ⊕ l) l R = matrix.reindex_lie_equiv (equiv.sum_assoc unit l l).symm (matrix.from_blocks 1 0 0 (indefinite_diagonal l l R)) := begin ext i j, rcases i with ⟨⟨i₁ | i₂⟩ | i₃⟩; rcases j with ⟨⟨j₁ | j₂⟩ | j₃⟩; simp [indefinite_diagonal, matrix.diagonal], end /-- An equivalence between two possible definitions of the classical Lie algebra of type B. -/ noncomputable def type_B_equiv_so' [invertible (2 : R)] : type_B l R ≃ₗ⁅R⁆ so' (unit ⊕ l) l R := begin apply (skew_adjoint_matrices_lie_subalgebra_equiv (JB l R) (PB l R) (is_unit_PB l R)).trans, symmetry, apply (skew_adjoint_matrices_lie_subalgebra_equiv_transpose (indefinite_diagonal (unit ⊕ l) l R) (matrix.reindex_alg_equiv (equiv.sum_assoc punit l l)) (matrix.transpose_reindex _ _)).trans, apply lie_equiv.of_eq, ext A, rw [JB_transform, ← unit_of_invertible_val (2 : R), lie_subalgebra.mem_coe, lie_subalgebra.mem_coe, mem_skew_adjoint_matrices_lie_subalgebra_unit_smul], simpa [indefinite_diagonal_assoc], end end orthogonal end lie_algebra
cff42e258316d7b013ed294848b31aaadfe08e1c
07c6143268cfb72beccd1cc35735d424ebcb187b
/src/data/nat/choose.lean
26fe07a9839813c8504b036444daaad51869abd2
[ "Apache-2.0" ]
permissive
khoek/mathlib
bc49a842910af13a3c372748310e86467d1dc766
aa55f8b50354b3e11ba64792dcb06cccb2d8ee28
refs/heads/master
1,588,232,063,837
1,587,304,803,000
1,587,304,803,000
176,688,517
0
0
Apache-2.0
1,553,070,585,000
1,553,070,585,000
null
UTF-8
Lean
false
false
4,296
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Bhavik Mehta -/ import data.nat.basic data.nat.prime import algebra.big_operators algebra.commute open nat lemma nat.prime.dvd_choose {p k : ℕ} (hk : 0 < k) (hkp : k < p) (hp : prime p) : p ∣ choose p k := have h₁ : p ∣ fact p, from hp.dvd_fact.2 (le_refl _), have h₂ : ¬p ∣ fact k, from mt hp.dvd_fact.1 (not_le_of_gt hkp), have h₃ : ¬p ∣ fact (p - k), from mt hp.dvd_fact.1 (not_le_of_gt (nat.sub_lt_self hp.pos hk)), by rw [← choose_mul_fact_mul_fact (le_of_lt hkp), mul_assoc, hp.dvd_mul, hp.dvd_mul] at h₁; exact h₁.resolve_right (not_or_distrib.2 ⟨h₂, h₃⟩) /-- Show that choose is increasing for small values of the right argument. -/ lemma choose_le_succ_of_lt_half_left {r n : ℕ} (h : r < n/2) : choose n r ≤ choose n (r+1) := begin refine le_of_mul_le_mul_right _ (nat.lt_sub_left_of_add_lt (lt_of_lt_of_le h (nat.div_le_self n 2))), rw ← choose_succ_right_eq, apply nat.mul_le_mul_left, rw [← nat.lt_iff_add_one_le, nat.lt_sub_left_iff_add_lt, ← mul_two], exact lt_of_lt_of_le (mul_lt_mul_of_pos_right h zero_lt_two) (nat.div_mul_le_self n 2), end /-- Show that for small values of the right argument, the middle value is largest. -/ private lemma choose_le_middle_of_le_half_left {n r : ℕ} (hr : r ≤ n/2) : choose n r ≤ choose n (n/2) := decreasing_induction (λ _ k a, (eq_or_lt_of_le a).elim (λ t, t.symm ▸ le_refl _) (λ h, trans (choose_le_succ_of_lt_half_left h) (k h))) hr (λ _, le_refl _) hr /-- `choose n r` is maximised when `r` is `n/2`. -/ lemma choose_le_middle {r n : ℕ} : nat.choose n r ≤ nat.choose n (n/2) := begin cases le_or_gt r n with b b, { cases le_or_lt r (n/2) with a h, { apply choose_le_middle_of_le_half_left a }, { rw ← choose_symm b, apply choose_le_middle_of_le_half_left, rw [div_lt_iff_lt_mul' zero_lt_two] at h, rw [le_div_iff_mul_le' zero_lt_two, nat.mul_sub_right_distrib, nat.sub_le_iff, mul_two, nat.add_sub_cancel], exact le_of_lt h } }, { rw nat.choose_eq_zero_of_lt b, apply nat.zero_le } end section binomial open finset variables {α : Type*} /-- A version of the binomial theorem for noncommutative semirings. -/ theorem commute.add_pow [semiring α] {x y : α} (h : commute x y) (n : ℕ) : (x + y) ^ n = (range (succ n)).sum (λ m, x ^ m * y ^ (n - m) * choose n m) := begin let t : ℕ → ℕ → α := λ n i, x ^ i * (y ^ (n - i)) * (choose n i), change (x + y) ^ n = (range n.succ).sum (t n), have h_first : ∀ n, t n 0 = y ^ n := λ n, by { dsimp [t], rw[choose_zero_right, nat.cast_one, mul_one, one_mul] }, have h_last : ∀ n, t n n.succ = 0 := λ n, by { dsimp [t], rw [choose_succ_self, nat.cast_zero, mul_zero] }, have h_middle : ∀ (n i : ℕ), (i ∈ finset.range n.succ) → ((t n.succ) ∘ nat.succ) i = x * (t n i) + y * (t n i.succ) := begin intros n i h_mem, have h_le : i ≤ n := nat.le_of_lt_succ (finset.mem_range.mp h_mem), dsimp [t], rw [choose_succ_succ, nat.cast_add, mul_add], congr' 1, { rw[pow_succ x, succ_sub_succ, mul_assoc, mul_assoc, mul_assoc] }, { rw[← mul_assoc y, ← mul_assoc y, (h.symm.pow_right i.succ).eq], by_cases h_eq : i = n, { rw [h_eq, choose_succ_self, nat.cast_zero, mul_zero, mul_zero] }, { rw[succ_sub (lt_of_le_of_ne h_le h_eq)], rw[pow_succ y, mul_assoc, mul_assoc, mul_assoc, mul_assoc] } } end, induction n with n ih, { rw [_root_.pow_zero, sum_range_succ, range_zero, sum_empty, add_zero], dsimp [t], rw [choose_self, nat.cast_one, mul_one, mul_one] }, { rw[sum_range_succ', h_first], rw[finset.sum_congr rfl (h_middle n), finset.sum_add_distrib, add_assoc], rw[pow_succ (x + y), ih, add_mul, finset.mul_sum, finset.mul_sum], congr' 1, rw[finset.sum_range_succ', finset.sum_range_succ, h_first, h_last, mul_zero, zero_add, _root_.pow_succ] } end /-- The binomial theorem-/ theorem add_pow [comm_semiring α] (x y : α) (n : ℕ) : (x + y) ^ n = (range (succ n)).sum (λ m, x ^ m * y ^ (n - m) * choose n m) := (commute.all x y).add_pow n end binomial
5bbfcf8aca75c9bf273a866be99df8e2e4cd13d2
0c1546a496eccfb56620165cad015f88d56190c5
/library/tools/super/lpo.lean
46584aa4836aba3ce68b56685e46a479dfcc6522
[ "Apache-2.0" ]
permissive
Solertis/lean
491e0939957486f664498fbfb02546e042699958
84188c5aa1673fdf37a082b2de8562dddf53df3f
refs/heads/master
1,610,174,257,606
1,486,263,620,000
1,486,263,620,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,633
lean
/- Copyright (c) 2016 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner -/ -- Polytime version of lexicographic path order as described in: -- Things to know when implementing LPO, Bernd Löchner, ESFOR 2004 import .utils open expr decidable monad def lex {T} [decidable_eq T] (gt : T → T → bool) : list T → list T → bool | (s::ss) (t::ts) := if s = t then lex ss ts else gt s t | _ _ := ff def majo {T} (gt : T → T → bool) (s : T) : list T → bool | [] := tt | (t::ts) := gt s t && majo ts meta def alpha (lpo : expr → expr → bool) : list expr → expr → bool | [] _ := ff | (s::ss) t := to_bool (s = t) || lpo s t || alpha ss t meta def lex_ma (lpo : expr → expr → bool) (s t : expr) : list expr → list expr → bool | (si::ss) (ti::ts) := if si = ti then lex_ma ss ts else if lpo si ti then majo lpo s ts else alpha lpo (si::ss) t | _ _ := ff meta def lpo (prec_gt : expr → expr → bool) : expr → expr → bool | s t := if prec_gt (get_app_fn s) (get_app_fn t) then majo lpo s (get_app_args t) else if get_app_fn s = get_app_fn t then lex_ma lpo s t (get_app_args s) (get_app_args t) else alpha lpo (get_app_args s) t meta def prec_gt_of_name_list (ns : list name) : expr → expr → bool := let nis := rb_map.of_list ns^.zip_with_index in λs t, match (nis^.find (name_of_funsym s), nis^.find (name_of_funsym t)) with | (some si, some ti) := to_bool (si > ti) | _ := ff end meta def mk_lpo (ns : list name) : expr → expr → bool := let prec_gt := prec_gt_of_name_list ns in lpo (prec_gt_of_name_list ns)
a67c75c0ddd7a673e68a3f4f777f59d613db2230
4038e103ed66b0dd716900a90166626946bc33fd
/example/src/limits.lean
1214da740143939749eb7c94c735b61b0c1812de
[ "Apache-2.0" ]
permissive
mpedramfar/format_lean
4be57fda2840ed11aed56d3149597ce693b3a6bc
6d9885532699fcf6bd8fa9048c68762d5b6bfd8d
refs/heads/master
1,587,910,517,162
1,555,352,005,000
1,555,352,005,000
173,606,917
1
0
Apache-2.0
1,553,459,953,000
1,551,634,180,000
CSS
UTF-8
Lean
false
false
7,079
lean
import data.real.basic import algebra.pi_instances import tactic.linarith import xenalib.M1P1 noncomputable theory local attribute [instance, priority 0] classical.prop_decidable namespace M1P1 notation `|` x `|` := abs x definition is_limit (a : ℕ → ℝ) (l : ℝ) : Prop := ∀ ε > 0, ∃ N, ∀ n ≥ N, | a n - l | < ε definition has_limit (a : ℕ → ℝ) : Prop := ∃ l : ℝ, is_limit a l lemma tendsto_const (a : ℝ) : is_limit (λ n, a) a := begin intros ε εpos, use 0, intros n _, simpa using εpos end local attribute [-simp] sub_eq_add_neg local attribute [simp] sub_zero lemma tendsto_iff_sub_tendsto_zero {a : ℕ → ℝ} {l : ℝ} : is_limit (λ n, a n - l) 0 ↔ is_limit a l := begin split ; { intros h ε εpos, rcases h ε εpos with ⟨N, H⟩, use N, intros n hn, simpa using H n hn } end lemma tendsto_of_mul_eps (a : ℕ → ℝ) (l : ℝ) (A : ℝ) (h : ∀ ε > 0, ∃ N, ∀ n ≥ N, | a n - l | < A*ε) : is_limit a l := begin intros ε εpos, cases le_or_gt A 0 with Anonpos Apos, { exfalso, rcases h 1 (by linarith) with ⟨N, H⟩, specialize H N (by linarith), have : |a N - l| ≥ 0, from abs_nonneg _, linarith }, { rcases h (ε/A) (div_pos εpos Apos) with ⟨N, H⟩, rw mul_div_cancel' _ (ne_of_gt Apos) at H, tauto } end lemma zero_of_abs_lt_all (x : ℝ) (h : ∀ ε > 0, |x| < ε) : x = 0 := eq_zero_of_abs_eq_zero $ eq_of_le_of_forall_le_of_dense (abs_nonneg x) $ λ ε ε_pos, le_of_lt (h ε ε_pos) theorem limits_are_unique (a : ℕ → ℝ) (l m : ℝ) (hl : is_limit a l) (hm : is_limit a m) : l = m := begin --l = m suffices : ∀ ε : ℝ, ε > 0 → |l - m| < ε, from eq_of_sub_eq_zero (zero_of_abs_lt_all _ this), intros ε ε_pos, cases hl (ε/2) (by obvious_ineq) with Nₗ Hₗ, cases hm (ε/2) (by obvious_ineq) with Nₘ Hₘ, let N := max Nₗ Nₘ, have H₁ : Nₗ ≤ N := by obvious_ineq, have H : | a N - l| < ε/2 := Hₗ N H₁, have H₂ : Nₘ ≤ N := by obvious_ineq, have H' : | a N - m| < ε/2 := Hₘ N H₂, calc |l - m| = |(l - a N) + (a N - m)| : by ring ... ≤ |l - a N| + |a N - m| : abs_add _ _ ... = |a N - l | + |a N - m| : by rw abs_sub ... < ε/2 + ε/2 : by obvious_ineq ... = ε : by ring, end theorem tendsto_add (a : ℕ → ℝ) (b : ℕ → ℝ) (l m : ℝ) (h1 : is_limit a l) (h2 : is_limit b m) : is_limit (a + b) (l + m) := begin apply tendsto_of_mul_eps, intros ε Hε, cases (h1 ε Hε) with M₁ HM₁, cases (h2 ε Hε) with M₂ HM₂, let N := max M₁ M₂, use N, have H₁ : N ≥ M₁ := by obvious_ineq, have H₂ : N ≥ M₂ := by obvious_ineq, intros n Hn, have Hn₁ : n ≥ M₁ := by linarith, have H3 : |a n - l| < ε := HM₁ n Hn₁, have H4 : |b n - m| < ε := HM₂ n (by linarith), calc |(a + b) n - (l + m)| = |(a n - l) + (b n - m)| : by ring ... ≤ |(a n - l)| + |(b n - m)| : abs_add _ _ ... < ε + ε : by linarith ... = 2*ε : by ring end definition has_bound (a : ℕ → ℝ) (B : ℝ) := ∀ n, |a n| ≤ B definition is_bounded (a : ℕ → ℝ) := ∃ B, has_bound a B lemma has_bound_const (m : ℝ): has_bound (λ n, m) $ |m| := assume n, by simp open finset theorem bounded_of_convergent (a : ℕ → ℝ) (Ha : has_limit a) : is_bounded a := begin cases Ha with l Hl, cases Hl 1 (zero_lt_one) with N HN, let X := image (abs ∘ a) (range (N + 1)), have H2 : |a 0| ∈ X := mem_image_of_mem _ (mem_range.2 (nat.zero_lt_succ _)), have H3 : X ≠ ∅ := ne_empty_of_mem H2, let B₀ := max' X H3, have HB₀ : ∀ n ≤ N, |a n| ≤ B₀ := λ n Hn, le_max' X H3 _ (mem_image_of_mem _ (mem_range.2 (nat.lt_succ_of_le Hn))), let B := max B₀ ( |l| + 1), use B, intro n, cases le_or_gt n N with Hle Hgt, { have h : |a n| ≤ B₀ := HB₀ n Hle, have h2 : B₀ ≤ B := le_max_left _ _, linarith }, { have h : |a n - l| < 1 := HN n (le_of_lt Hgt), have h2 : |a n| < |l| + 1, revert h,unfold abs,unfold max,split_ifs;intros;linarith {restrict_type := ℝ}, have h3 : |l| + 1 ≤ B := le_max_right _ _, linarith } end theorem bounded_pos_of_convergent (a : ℕ → ℝ) (Ha : has_limit a) : ∃ B : ℝ, B > 0 ∧ has_bound a B := begin cases bounded_of_convergent a Ha with B₀ HB₀, let B := |B₀| + 1, use B, split, { apply lt_of_lt_of_le zero_lt_one, show 1 ≤ |B₀| + 1, apply le_add_of_nonneg_left', exact abs_nonneg _ }, intro n, apply le_trans (HB₀ n), show B₀ ≤ |B₀| + 1, apply le_trans (le_abs_self B₀), simp [zero_le_one], end lemma tendsto_bounded_mul_zero {a : ℕ → ℝ} {b : ℕ → ℝ} {A : ℝ} (Apos : A > 0) (hA : has_bound a A) (hB : is_limit b 0) : is_limit (a*b) 0 := begin apply tendsto_of_mul_eps, intros ε εpos, cases hB ε εpos with N H, simp at H, use N, intros n nN, calc |(a * b) n - 0| = |a n * b n| : by simp ... = |a n| * |b n| : abs_mul _ _ ... ≤ A*|b n| : mul_le_mul_of_nonneg_right (hA n) (abs_nonneg _) ... < A*ε : mul_lt_mul_of_pos_left (H n nN) Apos end theorem tendsto_mul (a : ℕ → ℝ) (b : ℕ → ℝ) (l m : ℝ) (h1 : is_limit a l) (h2 : is_limit b m) : is_limit (a * b) (l * m) := begin rw ←tendsto_iff_sub_tendsto_zero, have key : (λ n, (a*b) n - l*m) = (λ n, (a n)*(b n - m) + m*(a n - l)), by simp ; ring, rw key, suffices : is_limit (λ n, a n * (b n - m)) 0 ∧ is_limit (λ n, m * (a n - l)) 0, { rw [show (0 : ℝ) = 0 + 0, by simp], exact tendsto_add _ _ _ _ this.left this.right}, split, { rcases bounded_pos_of_convergent a ⟨l, h1⟩ with ⟨A, A_pos, hA⟩, have limb : is_limit (λ n, b n - m) 0, from tendsto_iff_sub_tendsto_zero.2 h2, exact tendsto_bounded_mul_zero A_pos hA limb }, { by_cases Hm : m = 0, { simp [Hm, tendsto_const] }, { have lima : is_limit (λ n, a n - l) 0, from tendsto_iff_sub_tendsto_zero.2 h1, exact tendsto_bounded_mul_zero (abs_pos_iff.2 Hm) (has_bound_const m) lima } } end theorem tendsto_le_of_le (a : ℕ → ℝ) (b : ℕ → ℝ) (l : ℝ) (m : ℝ) (hl : is_limit a l) (hm : is_limit b m) (hle : ∀ n, a n ≤ b n) : l ≤ m := begin apply le_of_not_lt, intro hlt, let ε := (l - m) /2, have Hε : ε > 0 := show (l - m) / 2 > 0 , by linarith, cases hl ε Hε with Na HNa, have Hε : ε > 0 := show (l - m) / 2 > 0 , by linarith, cases hm ε Hε with Nb HNb, let N := max Na Nb, have HNa' : Na ≤ N := le_max_left _ _, have HNb' : Nb ≤ N := le_max_right _ _, have Hl' : |a N - l| < ε := HNa N HNa', have Hm' : |b N - m| < ε := HNb N HNb', have HN : a N ≤ b N := hle N, have Hε : ε = (l - m) / 2 := rfl, revert Hl' Hm', unfold abs,unfold max,split_ifs;intros;linarith end end M1P1
59d5d2fc2db9cfa251cac22eaf58e9a4a214370f
367134ba5a65885e863bdc4507601606690974c1
/src/data/finset/lattice.lean
7f4fd05ff626fd79583b04bc2c00e3973768122d
[ "Apache-2.0" ]
permissive
kodyvajjha/mathlib
9bead00e90f68269a313f45f5561766cfd8d5cad
b98af5dd79e13a38d84438b850a2e8858ec21284
refs/heads/master
1,624,350,366,310
1,615,563,062,000
1,615,563,062,000
162,666,963
0
0
Apache-2.0
1,545,367,651,000
1,545,367,651,000
null
UTF-8
Lean
false
false
30,805
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro -/ import data.finset.fold import data.multiset.lattice import order.order_dual import order.complete_lattice /-! # Lattice operations on finsets -/ variables {α β γ : Type*} namespace finset open multiset order_dual /-! ### sup -/ section sup variables [semilattice_sup_bot α] /-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/ def sup (s : finset β) (f : β → α) : α := s.fold (⊔) ⊥ f variables {s s₁ s₂ : finset β} {f : β → α} lemma sup_def : s.sup f = (s.1.map f).sup := rfl @[simp] lemma sup_empty : (∅ : finset β).sup f = ⊥ := fold_empty @[simp] lemma sup_insert [decidable_eq β] {b : β} : (insert b s : finset β).sup f = f b ⊔ s.sup f := fold_insert_idem @[simp] lemma sup_singleton {b : β} : ({b} : finset β).sup f = f b := sup_singleton lemma sup_union [decidable_eq β] : (s₁ ∪ s₂).sup f = s₁.sup f ⊔ s₂.sup f := finset.induction_on s₁ (by rw [empty_union, sup_empty, bot_sup_eq]) $ λ a s has ih, by rw [insert_union, sup_insert, sup_insert, ih, sup_assoc] theorem sup_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a∈s₂, f a = g a) : s₁.sup f = s₂.sup g := by subst hs; exact finset.fold_congr hfg @[simp] lemma sup_le_iff {a : α} : s.sup f ≤ a ↔ (∀b ∈ s, f b ≤ a) := begin apply iff.trans multiset.sup_le, simp only [multiset.mem_map, and_imp, exists_imp_distrib], exact ⟨λ k b hb, k _ _ hb rfl, λ k a' b hb h, h ▸ k _ hb⟩, end lemma sup_const {s : finset β} (h : s.nonempty) (c : α) : s.sup (λ _, c) = c := eq_of_forall_ge_iff $ λ b, sup_le_iff.trans h.forall_const lemma sup_le {a : α} : (∀b ∈ s, f b ≤ a) → s.sup f ≤ a := sup_le_iff.2 lemma le_sup {b : β} (hb : b ∈ s) : f b ≤ s.sup f := sup_le_iff.1 (le_refl _) _ hb @[simp] lemma map_sup (f : γ ↪ β) (g : β → α) (s : finset γ) : (s.map f).sup g = s.sup (g ∘ f) := by simp [finset.sup] lemma sup_mono_fun {g : β → α} (h : ∀b∈s, f b ≤ g b) : s.sup f ≤ s.sup g := sup_le (λ b hb, le_trans (h b hb) (le_sup hb)) lemma sup_mono (h : s₁ ⊆ s₂) : s₁.sup f ≤ s₂.sup f := sup_le $ assume b hb, le_sup (h hb) @[simp] lemma sup_lt_iff [is_total α (≤)] {a : α} (ha : ⊥ < a) : s.sup f < a ↔ (∀b ∈ s, f b < a) := by letI := classical.dec_eq β; from ⟨ λh b hb, lt_of_le_of_lt (le_sup hb) h, finset.induction_on s (by simp [ha]) (by simp {contextual := tt}) ⟩ lemma comp_sup_eq_sup_comp [semilattice_sup_bot γ] {s : finset β} {f : β → α} (g : α → γ) (g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) := by letI := classical.dec_eq β; from finset.induction_on s (by simp [bot]) (by simp [g_sup] {contextual := tt}) lemma comp_sup_eq_sup_comp_of_is_total [is_total α (≤)] {γ : Type} [semilattice_sup_bot γ] (g : α → γ) (mono_g : monotone g) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) := comp_sup_eq_sup_comp g mono_g.map_sup bot /-- Computating `sup` in a subtype (closed under `sup`) is the same as computing it in `α`. -/ lemma sup_coe {P : α → Prop} {Pbot : P ⊥} {Psup : ∀{{x y}}, P x → P y → P (x ⊔ y)} (t : finset β) (f : β → {x : α // P x}) : (@sup _ _ (subtype.semilattice_sup_bot Pbot Psup) t f : α) = t.sup (λ x, f x) := by { classical, rw [comp_sup_eq_sup_comp coe]; intros; refl } @[simp] lemma sup_to_finset {α β} [decidable_eq β] (s : finset α) (f : α → multiset β) : (s.sup f).to_finset = s.sup (λ x, (f x).to_finset) := comp_sup_eq_sup_comp multiset.to_finset to_finset_union rfl theorem subset_range_sup_succ (s : finset ℕ) : s ⊆ range (s.sup id).succ := λ n hn, mem_range.2 $ nat.lt_succ_of_le $ le_sup hn theorem exists_nat_subset_range (s : finset ℕ) : ∃n : ℕ, s ⊆ range n := ⟨_, s.subset_range_sup_succ⟩ lemma sup_subset {α β} [semilattice_sup_bot β] {s t : finset α} (hst : s ⊆ t) (f : α → β) : s.sup f ≤ t.sup f := by classical; calc t.sup f = (s ∪ t).sup f : by rw [finset.union_eq_right_iff_subset.mpr hst] ... = s.sup f ⊔ t.sup f : by rw finset.sup_union ... ≥ s.sup f : le_sup_left lemma sup_closed_of_sup_closed {s : set α} (t : finset α) (htne : t.nonempty) (h_subset : ↑t ⊆ s) (h : ∀⦃a b⦄, a ∈ s → b ∈ s → a ⊔ b ∈ s) : t.sup id ∈ s := begin classical, induction t using finset.induction_on with x t h₀ h₁, { exfalso, apply finset.not_nonempty_empty htne, }, { rw [finset.coe_insert, set.insert_subset] at h_subset, cases t.eq_empty_or_nonempty with hte htne, { subst hte, simp only [insert_emptyc_eq, id.def, finset.sup_singleton, h_subset], }, { rw [finset.sup_insert, id.def], exact h h_subset.1 (h₁ htne h_subset.2), }, }, end lemma sup_le_of_le_directed {α : Type*} [semilattice_sup_bot α] (s : set α) (hs : s.nonempty) (hdir : directed_on (≤) s) (t : finset α): (∀ x ∈ t, ∃ y ∈ s, x ≤ y) → ∃ x, x ∈ s ∧ t.sup id ≤ x := begin classical, apply finset.induction_on t, { simpa only [forall_prop_of_true, and_true, forall_prop_of_false, bot_le, not_false_iff, sup_empty, forall_true_iff, not_mem_empty], }, { intros a r har ih h, have incs : ↑r ⊆ ↑(insert a r), by { rw finset.coe_subset, apply finset.subset_insert, }, -- x ∈ s is above the sup of r obtain ⟨x, ⟨hxs, hsx_sup⟩⟩ := ih (λ x hx, h x $ incs hx), -- y ∈ s is above a obtain ⟨y, hys, hay⟩ := h a (finset.mem_insert_self a r), -- z ∈ s is above x and y obtain ⟨z, hzs, ⟨hxz, hyz⟩⟩ := hdir x hxs y hys, use [z, hzs], rw [sup_insert, id.def, _root_.sup_le_iff], exact ⟨le_trans hay hyz, le_trans hsx_sup hxz⟩, }, end end sup lemma sup_eq_supr [complete_lattice β] (s : finset α) (f : α → β) : s.sup f = (⨆a∈s, f a) := le_antisymm (finset.sup_le $ assume a ha, le_supr_of_le a $ le_supr _ ha) (supr_le $ assume a, supr_le $ assume ha, le_sup ha) lemma sup_eq_Sup [complete_lattice α] (s : finset α) : s.sup id = Sup s := by simp [Sup_eq_supr, sup_eq_supr] lemma exists_mem_eq_sup [complete_linear_order β] (s : finset α) (h : s.nonempty) (f : α → β) : ∃ a, a ∈ s ∧ s.sup f = f a := begin classical, induction s using finset.induction_on with x xs hxm ih, { exact (not_nonempty_empty h).elim, }, { rw sup_insert, by_cases hx : xs.sup f ≤ f x, { refine ⟨x, mem_insert_self _ _, sup_eq_left.mpr hx⟩, }, by_cases hxs : xs.nonempty, { obtain ⟨a, ham, ha⟩ := ih hxs, refine ⟨a, mem_insert_of_mem ham, _⟩, simpa only [ha, sup_eq_right] using le_of_not_le hx, }, { rw not_nonempty_iff_eq_empty.mp hxs, refine ⟨x, mem_singleton_self _, _⟩, simp, } } end /-! ### inf -/ section inf variables [semilattice_inf_top α] /-- Infimum of a finite set: `inf {a, b, c} f = f a ⊓ f b ⊓ f c` -/ def inf (s : finset β) (f : β → α) : α := s.fold (⊓) ⊤ f variables {s s₁ s₂ : finset β} {f : β → α} lemma inf_def : s.inf f = (s.1.map f).inf := rfl @[simp] lemma inf_empty : (∅ : finset β).inf f = ⊤ := fold_empty lemma le_inf_iff {a : α} : a ≤ s.inf f ↔ ∀b ∈ s, a ≤ f b := @sup_le_iff (order_dual α) _ _ _ _ _ @[simp] lemma inf_insert [decidable_eq β] {b : β} : (insert b s : finset β).inf f = f b ⊓ s.inf f := fold_insert_idem @[simp] lemma inf_singleton {b : β} : ({b} : finset β).inf f = f b := inf_singleton lemma inf_union [decidable_eq β] : (s₁ ∪ s₂).inf f = s₁.inf f ⊓ s₂.inf f := @sup_union (order_dual α) _ _ _ _ _ _ theorem inf_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a∈s₂, f a = g a) : s₁.inf f = s₂.inf g := by subst hs; exact finset.fold_congr hfg lemma inf_le {b : β} (hb : b ∈ s) : s.inf f ≤ f b := le_inf_iff.1 (le_refl _) _ hb lemma le_inf {a : α} : (∀b ∈ s, a ≤ f b) → a ≤ s.inf f := le_inf_iff.2 @[simp] lemma map_inf (f : γ ↪ β) (g : β → α) (s : finset γ) : (s.map f).inf g = s.inf (g ∘ f) := by simp [finset.inf] lemma inf_mono_fun {g : β → α} (h : ∀b∈s, f b ≤ g b) : s.inf f ≤ s.inf g := le_inf (λ b hb, le_trans (inf_le hb) (h b hb)) lemma inf_mono (h : s₁ ⊆ s₂) : s₂.inf f ≤ s₁.inf f := le_inf $ assume b hb, inf_le (h hb) lemma lt_inf_iff [h : is_total α (≤)] {a : α} (ha : a < ⊤) : a < s.inf f ↔ (∀b ∈ s, a < f b) := @sup_lt_iff (order_dual α) _ _ _ _ (@is_total.swap α _ h) _ ha lemma comp_inf_eq_inf_comp [semilattice_inf_top γ] {s : finset β} {f : β → α} (g : α → γ) (g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) := @comp_sup_eq_sup_comp (order_dual α) _ (order_dual γ) _ _ _ _ _ g_inf top lemma comp_inf_eq_inf_comp_of_is_total [h : is_total α (≤)] {γ : Type} [semilattice_inf_top γ] (g : α → γ) (mono_g : monotone g) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) := comp_inf_eq_inf_comp g mono_g.map_inf top /-- Computating `inf` in a subtype (closed under `inf`) is the same as computing it in `α`. -/ lemma inf_coe {P : α → Prop} {Ptop : P ⊤} {Pinf : ∀{{x y}}, P x → P y → P (x ⊓ y)} (t : finset β) (f : β → {x : α // P x}) : (@inf _ _ (subtype.semilattice_inf_top Ptop Pinf) t f : α) = t.inf (λ x, f x) := by { classical, rw [comp_inf_eq_inf_comp coe]; intros; refl } end inf lemma inf_eq_infi [complete_lattice β] (s : finset α) (f : α → β) : s.inf f = (⨅a∈s, f a) := @sup_eq_supr _ (order_dual β) _ _ _ lemma inf_eq_Inf [complete_lattice α] (s : finset α) : s.inf id = Inf s := by simp [Inf_eq_infi, inf_eq_infi] lemma exists_mem_eq_inf [complete_linear_order β] (s : finset α) (h : s.nonempty) (f : α → β) : ∃ a, a ∈ s ∧ s.inf f = f a := @exists_mem_eq_sup _ (order_dual β) _ _ h _ /-! ### max and min of finite sets -/ section max_min variables [linear_order α] /-- Let `s` be a finset in a linear order. Then `s.max` is the maximum of `s` if `s` is not empty, and `none` otherwise. It belongs to `option α`. If you want to get an element of `α`, see `s.max'`. -/ protected def max : finset α → option α := fold (option.lift_or_get max) none some theorem max_eq_sup_with_bot (s : finset α) : s.max = @sup (with_bot α) α _ s some := rfl @[simp] theorem max_empty : (∅ : finset α).max = none := rfl @[simp] theorem max_insert {a : α} {s : finset α} : (insert a s).max = option.lift_or_get max (some a) s.max := fold_insert_idem @[simp] theorem max_singleton {a : α} : finset.max {a} = some a := by { rw [← insert_emptyc_eq], exact max_insert } theorem max_of_mem {s : finset α} {a : α} (h : a ∈ s) : ∃ b, b ∈ s.max := (@le_sup (with_bot α) _ _ _ _ _ h _ rfl).imp $ λ b, Exists.fst theorem max_of_nonempty {s : finset α} (h : s.nonempty) : ∃ a, a ∈ s.max := let ⟨a, ha⟩ := h in max_of_mem ha theorem max_eq_none {s : finset α} : s.max = none ↔ s = ∅ := ⟨λ h, s.eq_empty_or_nonempty.elim id (λ H, let ⟨a, ha⟩ := max_of_nonempty H in by rw h at ha; cases ha), λ h, h.symm ▸ max_empty⟩ theorem mem_of_max {s : finset α} : ∀ {a : α}, a ∈ s.max → a ∈ s := finset.induction_on s (λ _ H, by cases H) (λ b s _ (ih : ∀ {a}, a ∈ s.max → a ∈ s) a (h : a ∈ (insert b s).max), begin by_cases p : b = a, { induction p, exact mem_insert_self b s }, { cases option.lift_or_get_choice max_choice (some b) s.max with q q; rw [max_insert, q] at h, { cases h, cases p rfl }, { exact mem_insert_of_mem (ih h) } } end) theorem le_max_of_mem {s : finset α} {a b : α} (h₁ : a ∈ s) (h₂ : b ∈ s.max) : a ≤ b := by rcases @le_sup (with_bot α) _ _ _ _ _ h₁ _ rfl with ⟨b', hb, ab⟩; cases h₂.symm.trans hb; assumption /-- Let `s` be a finset in a linear order. Then `s.min` is the minimum of `s` if `s` is not empty, and `none` otherwise. It belongs to `option α`. If you want to get an element of `α`, see `s.min'`. -/ protected def min : finset α → option α := fold (option.lift_or_get min) none some theorem min_eq_inf_with_top (s : finset α) : s.min = @inf (with_top α) α _ s some := rfl @[simp] theorem min_empty : (∅ : finset α).min = none := rfl @[simp] theorem min_insert {a : α} {s : finset α} : (insert a s).min = option.lift_or_get min (some a) s.min := fold_insert_idem @[simp] theorem min_singleton {a : α} : finset.min {a} = some a := by { rw ← insert_emptyc_eq, exact min_insert } theorem min_of_mem {s : finset α} {a : α} (h : a ∈ s) : ∃ b, b ∈ s.min := (@inf_le (with_top α) _ _ _ _ _ h _ rfl).imp $ λ b, Exists.fst theorem min_of_nonempty {s : finset α} (h : s.nonempty) : ∃ a, a ∈ s.min := let ⟨a, ha⟩ := h in min_of_mem ha theorem min_eq_none {s : finset α} : s.min = none ↔ s = ∅ := ⟨λ h, s.eq_empty_or_nonempty.elim id (λ H, let ⟨a, ha⟩ := min_of_nonempty H in by rw h at ha; cases ha), λ h, h.symm ▸ min_empty⟩ theorem mem_of_min {s : finset α} : ∀ {a : α}, a ∈ s.min → a ∈ s := @mem_of_max (order_dual α) _ s theorem min_le_of_mem {s : finset α} {a b : α} (h₁ : b ∈ s) (h₂ : a ∈ s.min) : a ≤ b := by rcases @inf_le (with_top α) _ _ _ _ _ h₁ _ rfl with ⟨b', hb, ab⟩; cases h₂.symm.trans hb; assumption /-- Given a nonempty finset `s` in a linear order `α `, then `s.min' h` is its minimum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.min`, taking values in `option α`. -/ def min' (s : finset α) (H : s.nonempty) : α := @option.get _ s.min $ let ⟨k, hk⟩ := H in let ⟨b, hb⟩ := min_of_mem hk in by simp at hb; simp [hb] /-- Given a nonempty finset `s` in a linear order `α `, then `s.max' h` is its maximum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.max`, taking values in `option α`. -/ def max' (s : finset α) (H : s.nonempty) : α := @option.get _ s.max $ let ⟨k, hk⟩ := H in let ⟨b, hb⟩ := max_of_mem hk in by simp at hb; simp [hb] variables (s : finset α) (H : s.nonempty) theorem min'_mem : s.min' H ∈ s := mem_of_min $ by simp [min'] theorem min'_le (x) (H2 : x ∈ s) : s.min' ⟨x, H2⟩ ≤ x := min_le_of_mem H2 $ option.get_mem _ theorem le_min' (x) (H2 : ∀ y ∈ s, x ≤ y) : x ≤ s.min' H := H2 _ $ min'_mem _ _ theorem is_least_min' : is_least ↑s (s.min' H) := ⟨min'_mem _ _, min'_le _⟩ @[simp] lemma le_min'_iff {x} : x ≤ s.min' H ↔ ∀ y ∈ s, x ≤ y := le_is_glb_iff (is_least_min' s H).is_glb /-- `{a}.min' _` is `a`. -/ @[simp] lemma min'_singleton (a : α) : ({a} : finset α).min' (singleton_nonempty _) = a := by simp [min'] theorem max'_mem : s.max' H ∈ s := mem_of_max $ by simp [max'] theorem le_max' (x) (H2 : x ∈ s) : x ≤ s.max' ⟨x, H2⟩ := le_max_of_mem H2 $ option.get_mem _ theorem max'_le (x) (H2 : ∀ y ∈ s, y ≤ x) : s.max' H ≤ x := H2 _ $ max'_mem _ _ theorem is_greatest_max' : is_greatest ↑s (s.max' H) := ⟨max'_mem _ _, le_max' _⟩ @[simp] lemma max'_le_iff {x} : s.max' H ≤ x ↔ ∀ y ∈ s, y ≤ x := is_lub_le_iff (is_greatest_max' s H).is_lub /-- `{a}.max' _` is `a`. -/ @[simp] lemma max'_singleton (a : α) : ({a} : finset α).max' (singleton_nonempty _) = a := by simp [max'] theorem min'_lt_max' {i j} (H1 : i ∈ s) (H2 : j ∈ s) (H3 : i ≠ j) : s.min' ⟨i, H1⟩ < s.max' ⟨i, H1⟩ := is_glb_lt_is_lub_of_ne (s.is_least_min' _).is_glb (s.is_greatest_max' _).is_lub H1 H2 H3 /-- If there's more than 1 element, the min' is less than the max'. An alternate version of `min'_lt_max'` which is sometimes more convenient. -/ lemma min'_lt_max'_of_card (h₂ : 1 < card s) : s.min' (finset.card_pos.mp $ lt_trans zero_lt_one h₂) < s.max' (finset.card_pos.mp $ lt_trans zero_lt_one h₂) := begin rcases one_lt_card.1 h₂ with ⟨a, ha, b, hb, hab⟩, exact s.min'_lt_max' ha hb hab end lemma max'_eq_of_dual_min' {s : finset α} (hs : s.nonempty) : max' s hs = of_dual (min' (image to_dual s) (nonempty.image hs to_dual)) := begin rw [of_dual, to_dual, equiv.coe_fn_mk, equiv.coe_fn_symm_mk, id.def], simp_rw (@image_id (order_dual α) (s : finset (order_dual α))), refl, end lemma min'_eq_of_dual_max' {s : finset α} (hs : s.nonempty) : min' s hs = of_dual (max' (image to_dual s) (nonempty.image hs to_dual)) := begin rw [of_dual, to_dual, equiv.coe_fn_mk, equiv.coe_fn_symm_mk, id.def], simp_rw (@image_id (order_dual α) (s : finset (order_dual α))), refl, end @[simp] lemma of_dual_max_eq_min_of_dual {a b : α} : of_dual (max a b) = min (of_dual a) (of_dual b) := rfl @[simp] lemma of_dual_min_eq_max_of_dual {a b : α} : of_dual (min a b) = max (of_dual a) (of_dual b) := rfl lemma max'_subset {s t : finset α} (H : s.nonempty) (hst : s ⊆ t) : s.max' H ≤ t.max' (H.mono hst) := le_max' _ _ (hst (s.max'_mem H)) lemma min'_subset {s t : finset α} (H : s.nonempty) (hst : s ⊆ t) : t.min' (H.mono hst) ≤ s.min' H := min'_le _ _ (hst (s.min'_mem H)) lemma max'_insert (a : α) (s : finset α) (H : s.nonempty) : (insert a s).max' (s.insert_nonempty a) = max (s.max' H) a := (is_greatest_max' _ _).unique $ by { rw [coe_insert, max_comm], exact (is_greatest_max' _ _).insert _ } lemma min'_insert (a : α) (s : finset α) (H : s.nonempty) : (insert a s).min' (s.insert_nonempty a) = min (s.min' H) a := (is_least_min' _ _).unique $ by { rw [coe_insert, min_comm], exact (is_least_min' _ _).insert _ } /-- Induction principle for `finset`s in a linearly ordered type: a predicate is true on all `s : finset α` provided that: * it is true on the empty `finset`, * for every `s : finset α` and an element `a` strictly greater than all elements of `s`, `p s` implies `p (insert a s)`. -/ @[elab_as_eliminator] lemma induction_on_max {p : finset α → Prop} (s : finset α) (h0 : p ∅) (step : ∀ a s, (∀ x ∈ s, x < a) → p s → p (insert a s)) : p s := begin induction hn : s.card with n ihn generalizing s, { rwa [card_eq_zero.1 hn] }, { have A : s.nonempty, from card_pos.1 (hn.symm ▸ n.succ_pos), have B : s.max' A ∈ s, from max'_mem s A, rw [← insert_erase B], refine step _ _ (λ x hx, _) (ihn _ _), { rw [mem_erase] at hx, exact (le_max' s x hx.2).lt_of_ne hx.1 }, { rw [card_erase_of_mem B, hn, nat.pred_succ] } } end /-- Induction principle for `finset`s in a linearly ordered type: a predicate is true on all `s : finset α` provided that: * it is true on the empty `finset`, * for every `s : finset α` and an element `a` strictly less than all elements of `s`, `p s` implies `p (insert a s)`. -/ @[elab_as_eliminator] lemma induction_on_min {p : finset α → Prop} (s : finset α) (h0 : p ∅) (step : ∀ a s, (∀ x ∈ s, a < x) → p s → p (insert a s)) : p s := begin refine @induction_on_max (order_dual α) _ _ s h0 (λ a s has hs, _), convert step a s has hs end end max_min section exists_max_min variables [linear_order α] lemma exists_max_image (s : finset β) (f : β → α) (h : s.nonempty) : ∃ x ∈ s, ∀ x' ∈ s, f x' ≤ f x := begin cases max_of_nonempty (h.image f) with y hy, rcases mem_image.mp (mem_of_max hy) with ⟨x, hx, rfl⟩, exact ⟨x, hx, λ x' hx', le_max_of_mem (mem_image_of_mem f hx') hy⟩, end lemma exists_min_image (s : finset β) (f : β → α) (h : s.nonempty) : ∃ x ∈ s, ∀ x' ∈ s, f x ≤ f x' := @exists_max_image (order_dual α) β _ s f h end exists_max_min end finset namespace multiset lemma count_sup [decidable_eq β] (s : finset α) (f : α → multiset β) (b : β) : count b (s.sup f) = s.sup (λa, count b (f a)) := begin letI := classical.dec_eq α, refine s.induction _ _, { exact count_zero _ }, { assume i s his ih, rw [finset.sup_insert, sup_eq_union, count_union, finset.sup_insert, ih], refl } end lemma mem_sup {α β} [decidable_eq β] {s : finset α} {f : α → multiset β} {x : β} : x ∈ s.sup f ↔ ∃ v ∈ s, x ∈ f v := begin classical, apply s.induction_on, { simp }, { intros a s has hxs, rw [finset.sup_insert, multiset.sup_eq_union, multiset.mem_union], split, { intro hxi, cases hxi with hf hf, { refine ⟨a, _, hf⟩, simp only [true_or, eq_self_iff_true, finset.mem_insert] }, { rcases hxs.mp hf with ⟨v, hv, hfv⟩, refine ⟨v, _, hfv⟩, simp only [hv, or_true, finset.mem_insert] } }, { rintros ⟨v, hv, hfv⟩, rw [finset.mem_insert] at hv, rcases hv with rfl | hv, { exact or.inl hfv }, { refine or.inr (hxs.mpr ⟨v, hv, hfv⟩) } } }, end end multiset namespace finset lemma mem_sup {α β} [decidable_eq β] {s : finset α} {f : α → finset β} {x : β} : x ∈ s.sup f ↔ ∃ v ∈ s, x ∈ f v := begin change _ ↔ ∃ v ∈ s, x ∈ (f v).val, rw [←multiset.mem_sup, ←multiset.mem_to_finset, sup_to_finset], simp_rw [val_to_finset], end lemma sup_eq_bUnion {α β} [decidable_eq β] (s : finset α) (t : α → finset β) : s.sup t = s.bUnion t := by { ext, rw [mem_sup, mem_bUnion], } end finset section lattice variables {ι : Type*} {ι' : Sort*} [complete_lattice α] /-- Supremum of `s i`, `i : ι`, is equal to the supremum over `t : finset ι` of suprema `⨆ i ∈ t, s i`. This version assumes `ι` is a `Type*`. See `supr_eq_supr_finset'` for a version that works for `ι : Sort*`. -/ lemma supr_eq_supr_finset (s : ι → α) : (⨆i, s i) = (⨆t:finset ι, ⨆i∈t, s i) := begin classical, exact le_antisymm (supr_le $ assume b, le_supr_of_le {b} $ le_supr_of_le b $ le_supr_of_le (by simp) $ le_refl _) (supr_le $ assume t, supr_le $ assume b, supr_le $ assume hb, le_supr _ _) end /-- Supremum of `s i`, `i : ι`, is equal to the supremum over `t : finset ι` of suprema `⨆ i ∈ t, s i`. This version works for `ι : Sort*`. See `supr_eq_supr_finset` for a version that assumes `ι : Type*` but has no `plift`s. -/ lemma supr_eq_supr_finset' (s : ι' → α) : (⨆i, s i) = (⨆t:finset (plift ι'), ⨆i∈t, s (plift.down i)) := by rw [← supr_eq_supr_finset, ← equiv.plift.surjective.supr_comp]; refl /-- Infimum of `s i`, `i : ι`, is equal to the infimum over `t : finset ι` of infima `⨆ i ∈ t, s i`. This version assumes `ι` is a `Type*`. See `infi_eq_infi_finset'` for a version that works for `ι : Sort*`. -/ lemma infi_eq_infi_finset (s : ι → α) : (⨅i, s i) = (⨅t:finset ι, ⨅i∈t, s i) := @supr_eq_supr_finset (order_dual α) _ _ _ /-- Infimum of `s i`, `i : ι`, is equal to the infimum over `t : finset ι` of infima `⨆ i ∈ t, s i`. This version works for `ι : Sort*`. See `infi_eq_infi_finset` for a version that assumes `ι : Type*` but has no `plift`s. -/ lemma infi_eq_infi_finset' (s : ι' → α) : (⨅i, s i) = (⨅t:finset (plift ι'), ⨅i∈t, s (plift.down i)) := @supr_eq_supr_finset' (order_dual α) _ _ _ end lattice namespace set variables {ι : Type*} {ι' : Sort*} /-- Union of an indexed family of sets `s : ι → set α` is equal to the union of the unions of finite subfamilies. This version assumes `ι : Type*`. See also `Union_eq_Union_finset'` for a version that works for `ι : Sort*`. -/ lemma Union_eq_Union_finset (s : ι → set α) : (⋃i, s i) = (⋃t:finset ι, ⋃i∈t, s i) := supr_eq_supr_finset s /-- Union of an indexed family of sets `s : ι → set α` is equal to the union of the unions of finite subfamilies. This version works for `ι : Sort*`. See also `Union_eq_Union_finset` for a version that assumes `ι : Type*` but avoids `plift`s in the right hand side. -/ lemma Union_eq_Union_finset' (s : ι' → set α) : (⋃i, s i) = (⋃t:finset (plift ι'), ⋃i∈t, s (plift.down i)) := supr_eq_supr_finset' s /-- Intersection of an indexed family of sets `s : ι → set α` is equal to the intersection of the intersections of finite subfamilies. This version assumes `ι : Type*`. See also `Inter_eq_Inter_finset'` for a version that works for `ι : Sort*`. -/ lemma Inter_eq_Inter_finset (s : ι → set α) : (⋂i, s i) = (⋂t:finset ι, ⋂i∈t, s i) := infi_eq_infi_finset s /-- Intersection of an indexed family of sets `s : ι → set α` is equal to the intersection of the intersections of finite subfamilies. This version works for `ι : Sort*`. See also `Inter_eq_Inter_finset` for a version that assumes `ι : Type*` but avoids `plift`s in the right hand side. -/ lemma Inter_eq_Inter_finset' (s : ι' → set α) : (⋂i, s i) = (⋂t:finset (plift ι'), ⋂i∈t, s (plift.down i)) := infi_eq_infi_finset' s end set namespace finset open function /-! ### Interaction with big lattice/set operations -/ section lattice lemma supr_coe [has_Sup β] (f : α → β) (s : finset α) : (⨆ x ∈ (↑s : set α), f x) = ⨆ x ∈ s, f x := rfl lemma infi_coe [has_Inf β] (f : α → β) (s : finset α) : (⨅ x ∈ (↑s : set α), f x) = ⨅ x ∈ s, f x := rfl variables [complete_lattice β] theorem supr_singleton (a : α) (s : α → β) : (⨆ x ∈ ({a} : finset α), s x) = s a := by simp theorem infi_singleton (a : α) (s : α → β) : (⨅ x ∈ ({a} : finset α), s x) = s a := by simp lemma supr_option_to_finset (o : option α) (f : α → β) : (⨆ x ∈ o.to_finset, f x) = ⨆ x ∈ o, f x := by { congr, ext, rw [option.mem_to_finset] } lemma infi_option_to_finset (o : option α) (f : α → β) : (⨅ x ∈ o.to_finset, f x) = ⨅ x ∈ o, f x := @supr_option_to_finset _ (order_dual β) _ _ _ variables [decidable_eq α] theorem supr_union {f : α → β} {s t : finset α} : (⨆ x ∈ s ∪ t, f x) = (⨆x∈s, f x) ⊔ (⨆x∈t, f x) := by simp [supr_or, supr_sup_eq] theorem infi_union {f : α → β} {s t : finset α} : (⨅ x ∈ s ∪ t, f x) = (⨅ x ∈ s, f x) ⊓ (⨅ x ∈ t, f x) := by simp [infi_or, infi_inf_eq] lemma supr_insert (a : α) (s : finset α) (t : α → β) : (⨆ x ∈ insert a s, t x) = t a ⊔ (⨆ x ∈ s, t x) := by { rw insert_eq, simp only [supr_union, finset.supr_singleton] } lemma infi_insert (a : α) (s : finset α) (t : α → β) : (⨅ x ∈ insert a s, t x) = t a ⊓ (⨅ x ∈ s, t x) := by { rw insert_eq, simp only [infi_union, finset.infi_singleton] } lemma supr_finset_image {f : γ → α} {g : α → β} {s : finset γ} : (⨆ x ∈ s.image f, g x) = (⨆ y ∈ s, g (f y)) := by rw [← supr_coe, coe_image, supr_image, supr_coe] lemma sup_finset_image {f : γ → α} {g : α → β} {s : finset γ} : s.sup (g ∘ f) = (s.image f).sup g := by { simp_rw [sup_eq_supr, comp_app], rw supr_finset_image, } lemma infi_finset_image {f : γ → α} {g : α → β} {s : finset γ} : (⨅ x ∈ s.image f, g x) = (⨅ y ∈ s, g (f y)) := by rw [← infi_coe, coe_image, infi_image, infi_coe] lemma supr_insert_update {x : α} {t : finset α} (f : α → β) {s : β} (hx : x ∉ t) : (⨆ (i ∈ insert x t), function.update f x s i) = (s ⊔ ⨆ (i ∈ t), f i) := begin simp only [finset.supr_insert, update_same], rcongr i hi, apply update_noteq, rintro rfl, exact hx hi end lemma infi_insert_update {x : α} {t : finset α} (f : α → β) {s : β} (hx : x ∉ t) : (⨅ (i ∈ insert x t), update f x s i) = (s ⊓ ⨅ (i ∈ t), f i) := @supr_insert_update α (order_dual β) _ _ _ _ f _ hx lemma supr_bUnion (s : finset γ) (t : γ → finset α) (f : α → β) : (⨆ y ∈ s.bUnion t, f y) = ⨆ (x ∈ s) (y ∈ t x), f y := calc (⨆ y ∈ s.bUnion t, f y) = ⨆ y (hy : ∃ x ∈ s, y ∈ t x), f y : congr_arg _ $ funext $ λ y, by rw [mem_bUnion] ... = _ : by simp only [supr_exists, @supr_comm _ α] lemma infi_bUnion (s : finset γ) (t : γ → finset α) (f : α → β) : (⨅ y ∈ s.bUnion t, f y) = ⨅ (x ∈ s) (y ∈ t x), f y := @supr_bUnion _ (order_dual β) _ _ _ _ _ _ end lattice @[simp] theorem set_bUnion_coe (s : finset α) (t : α → set β) : (⋃ x ∈ (↑s : set α), t x) = ⋃ x ∈ s, t x := rfl @[simp] theorem set_bInter_coe (s : finset α) (t : α → set β) : (⋂ x ∈ (↑s : set α), t x) = ⋂ x ∈ s, t x := rfl @[simp] theorem set_bUnion_singleton (a : α) (s : α → set β) : (⋃ x ∈ ({a} : finset α), s x) = s a := supr_singleton a s @[simp] theorem set_bInter_singleton (a : α) (s : α → set β) : (⋂ x ∈ ({a} : finset α), s x) = s a := infi_singleton a s @[simp] lemma set_bUnion_preimage_singleton (f : α → β) (s : finset β) : (⋃ y ∈ s, f ⁻¹' {y}) = f ⁻¹' ↑s := set.bUnion_preimage_singleton f ↑s @[simp] lemma set_bUnion_option_to_finset (o : option α) (f : α → set β) : (⋃ x ∈ o.to_finset, f x) = ⋃ x ∈ o, f x := supr_option_to_finset o f @[simp] lemma set_bInter_option_to_finset (o : option α) (f : α → set β) : (⋂ x ∈ o.to_finset, f x) = ⋂ x ∈ o, f x := infi_option_to_finset o f variables [decidable_eq α] lemma set_bUnion_union (s t : finset α) (u : α → set β) : (⋃ x ∈ s ∪ t, u x) = (⋃ x ∈ s, u x) ∪ (⋃ x ∈ t, u x) := supr_union lemma set_bInter_inter (s t : finset α) (u : α → set β) : (⋂ x ∈ s ∪ t, u x) = (⋂ x ∈ s, u x) ∩ (⋂ x ∈ t, u x) := infi_union @[simp] lemma set_bUnion_insert (a : α) (s : finset α) (t : α → set β) : (⋃ x ∈ insert a s, t x) = t a ∪ (⋃ x ∈ s, t x) := supr_insert a s t @[simp] lemma set_bInter_insert (a : α) (s : finset α) (t : α → set β) : (⋂ x ∈ insert a s, t x) = t a ∩ (⋂ x ∈ s, t x) := infi_insert a s t @[simp] lemma set_bUnion_finset_image {f : γ → α} {g : α → set β} {s : finset γ} : (⋃x ∈ s.image f, g x) = (⋃y ∈ s, g (f y)) := supr_finset_image @[simp] lemma set_bInter_finset_image {f : γ → α} {g : α → set β} {s : finset γ} : (⋂ x ∈ s.image f, g x) = (⋂ y ∈ s, g (f y)) := infi_finset_image lemma set_bUnion_insert_update {x : α} {t : finset α} (f : α → set β) {s : set β} (hx : x ∉ t) : (⋃ (i ∈ insert x t), @update _ _ _ f x s i) = (s ∪ ⋃ (i ∈ t), f i) := supr_insert_update f hx lemma set_bInter_insert_update {x : α} {t : finset α} (f : α → set β) {s : set β} (hx : x ∉ t) : (⋂ (i ∈ insert x t), @update _ _ _ f x s i) = (s ∩ ⋂ (i ∈ t), f i) := infi_insert_update f hx @[simp] lemma set_bUnion_bUnion (s : finset γ) (t : γ → finset α) (f : α → set β) : (⋃ y ∈ s.bUnion t, f y) = ⋃ (x ∈ s) (y ∈ t x), f y := supr_bUnion s t f @[simp] lemma set_bInter_bUnion (s : finset γ) (t : γ → finset α) (f : α → set β) : (⋂ y ∈ s.bUnion t, f y) = ⋂ (x ∈ s) (y ∈ t x), f y := infi_bUnion s t f end finset
59c06e091a8e97b73f578f133c0e7015e028cc97
3f7026ea8bef0825ca0339a275c03b911baef64d
/src/tactic/core.lean
50a4dcd7e848407e3f5de5159a24b789b65a05e8
[ "Apache-2.0" ]
permissive
rspencer01/mathlib
b1e3afa5c121362ef0881012cc116513ab09f18c
c7d36292c6b9234dc40143c16288932ae38fdc12
refs/heads/master
1,595,010,346,708
1,567,511,503,000
1,567,511,503,000
206,071,681
0
0
Apache-2.0
1,567,513,643,000
1,567,513,643,000
null
UTF-8
Lean
false
false
40,885
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Simon Hudon, Scott Morrison, Keeley Hoek -/ import data.dlist.basic category.basic meta.expr meta.rb_map data.string.defs namespace expr open tactic attribute [derive has_reflect] binder_info protected meta def of_nat (α : expr) : ℕ → tactic expr := nat.binary_rec (tactic.mk_mapp ``has_zero.zero [some α, none]) (λ b n tac, if n = 0 then mk_mapp ``has_one.one [some α, none] else do e ← tac, tactic.mk_app (cond b ``bit1 ``bit0) [e]) protected meta def of_int (α : expr) : ℤ → tactic expr | (n : ℕ) := expr.of_nat α n | -[1+ n] := do e ← expr.of_nat α (n+1), tactic.mk_app ``has_neg.neg [e] /- only traverses the direct descendents -/ meta def {u} traverse {m : Type → Type u} [applicative m] {elab elab' : bool} (f : expr elab → m (expr elab')) : expr elab → m (expr elab') | (var v) := pure $ var v | (sort l) := pure $ sort l | (const n ls) := pure $ const n ls | (mvar n n' e) := mvar n n' <$> f e | (local_const n n' bi e) := local_const n n' bi <$> f e | (app e₀ e₁) := app <$> f e₀ <*> f e₁ | (lam n bi e₀ e₁) := lam n bi <$> f e₀ <*> f e₁ | (pi n bi e₀ e₁) := pi n bi <$> f e₀ <*> f e₁ | (elet n e₀ e₁ e₂) := elet n <$> f e₀ <*> f e₁ <*> f e₂ | (macro mac es) := macro mac <$> list.traverse f es meta def mfoldl {α : Type} {m} [monad m] (f : α → expr → m α) : α → expr → m α | x e := prod.snd <$> (state_t.run (e.traverse $ λ e', (get >>= monad_lift ∘ flip f e' >>= put) $> e') x : m _) end expr namespace interaction_monad open result meta def get_result {σ α} (tac : interaction_monad σ α) : interaction_monad σ (interaction_monad.result σ α) | s := match tac s with | r@(success _ s') := success r s' | r@(exception _ _ s') := success r s' end end interaction_monad namespace lean.parser open lean interaction_monad.result meta def of_tactic' {α} (tac : tactic α) : parser α := do r ← of_tactic (interaction_monad.get_result tac), match r with | (success a _) := return a | (exception f pos _) := exception f pos end -- Override the builtin `lean.parser.of_tactic` coe, which is broken. -- (See test/tactics.lean for a failure case.) @[priority 2000] meta instance has_coe' {α} : has_coe (tactic α) (parser α) := ⟨of_tactic'⟩ meta def emit_command_here (str : string) : lean.parser string := do (_, left) ← with_input command_like str, return left -- Emit a source code string at the location being parsed. meta def emit_code_here : string → lean.parser unit | str := do left ← emit_command_here str, if left.length = 0 then return () else emit_code_here left end lean.parser namespace format meta def intercalate (x : format) : list format → format := format.join ∘ list.intersperse x end format namespace tactic meta def eval_expr' (α : Type*) [_inst_1 : reflected α] (e : expr) : tactic α := mk_app ``id [e] >>= eval_expr α -- `mk_fresh_name` returns identifiers starting with underscores, -- which are not legal when emitted by tactic programs. Turn the -- useful source of random names provided by `mk_fresh_name` into -- names which are usable by tactic programs. -- -- The returned name has four components which are all strings. meta def mk_user_fresh_name : tactic name := do nm ← mk_fresh_name, return $ `user__ ++ nm.pop_prefix.sanitize_name ++ `user__ /-- Checks whether n' has attribute n. -/ meta def has_attribute' : name → name → tactic bool | n n' := succeeds (has_attribute n n') /-- Checks whether the name is a simp lemma -/ meta def is_simp_lemma : name → tactic bool := has_attribute' `simp /-- Checks whether the name is an instance. -/ meta def is_instance : name → tactic bool := has_attribute' `instance meta def local_decls : tactic (name_map declaration) := do e ← tactic.get_env, let xs := e.fold native.mk_rb_map (λ d s, if environment.in_current_file' e d.to_name then s.insert d.to_name d else s), pure xs /-- Returns a pair (e, t), where `e ← mk_const d.to_name`, and `t = d.type` but with universe params updated to match the fresh universe metavariables in `e`. This should have the same effect as just ``` do e ← mk_const d.to_name, t ← infer_type e, return (e, t) ``` but is hopefully faster. -/ meta def decl_mk_const (d : declaration) : tactic (expr × expr) := do subst ← d.univ_params.mmap $ λ u, prod.mk u <$> mk_meta_univ, let e : expr := expr.const d.to_name (prod.snd <$> subst), return (e, d.type.instantiate_univ_params subst) meta def simp_lemmas_from_file : tactic name_set := do s ← local_decls, let s := s.map (expr.list_constant ∘ declaration.value), xs ← s.to_list.mmap ((<$>) name_set.of_list ∘ mfilter tactic.is_simp_lemma ∘ name_set.to_list ∘ prod.snd), return $ name_set.filter (λ x, ¬ s.contains x) (xs.foldl name_set.union mk_name_set) meta def file_simp_attribute_decl (attr : name) : tactic unit := do s ← simp_lemmas_from_file, trace format!"run_cmd mk_simp_attr `{attr}", let lmms := format.join $ list.intersperse " " $ s.to_list.map to_fmt, trace format!"local attribute [{attr}] {lmms}" meta def mk_local (n : name) : expr := expr.local_const n n binder_info.default (expr.const n []) meta def local_def_value (e : expr) : tactic expr := do do (v,_) ← solve_aux `(true) (do (expr.elet n t v _) ← (revert e >> target) | fail format!"{e} is not a local definition", return v), return v meta def check_defn (n : name) (e : pexpr) : tactic unit := do (declaration.defn _ _ _ d _ _) ← get_decl n, e' ← to_expr e, guard (d =ₐ e') <|> trace d >> failed -- meta def compile_eqn (n : name) (univ : list name) (args : list expr) (val : expr) (num : ℕ) : tactic unit := -- do let lhs := (expr.const n $ univ.map level.param).mk_app args, -- stmt ← mk_app `eq [lhs,val], -- let vs := stmt.list_local_const, -- let stmt := stmt.pis vs, -- (_,pr) ← solve_aux stmt (tactic.intros >> reflexivity), -- add_decl $ declaration.thm (n <.> "equations" <.> to_string (format!"_eqn_{num}")) univ stmt (pure pr) meta def to_implicit : expr → expr | (expr.local_const uniq n bi t) := expr.local_const uniq n binder_info.implicit t | e := e meta def pis : list expr → expr → tactic expr | (e@(expr.local_const uniq pp info _) :: es) f := do t ← infer_type e, f' ← pis es f, pure $ expr.pi pp info t (expr.abstract_local f' uniq) | _ f := pure f meta def lambdas : list expr → expr → tactic expr | (e@(expr.local_const uniq pp info _) :: es) f := do t ← infer_type e, f' ← lambdas es f, pure $ expr.lam pp info t (expr.abstract_local f' uniq) | _ f := pure f meta def extract_def (n : name) (trusted : bool) (elab_def : tactic unit) : tactic unit := do cxt ← list.map to_implicit <$> local_context, t ← target, (eqns,d) ← solve_aux t elab_def, d ← instantiate_mvars d, t' ← pis cxt t, d' ← lambdas cxt d, let univ := t'.collect_univ_params, add_decl $ declaration.defn n univ t' d' (reducibility_hints.regular 1 tt) trusted, applyc n meta def exact_dec_trivial : tactic unit := `[exact dec_trivial] /-- Runs a tactic for a result, reverting the state after completion -/ meta def retrieve {α} (tac : tactic α) : tactic α := λ s, result.cases_on (tac s) (λ a s', result.success a s) result.exception /-- Repeat a tactic at least once, calling it recursively on all subgoals, until it fails. This tactic fails if the first invocation fails. -/ meta def repeat1 (t : tactic unit) : tactic unit := t; repeat t /-- `iterate_range m n t`: Repeat the given tactic at least `m` times and at most `n` times or until `t` fails. Fails if `t` does not run at least m times. -/ meta def iterate_range : ℕ → ℕ → tactic unit → tactic unit | 0 0 t := skip | 0 (n+1) t := try (t >> iterate_range 0 n t) | (m+1) n t := t >> iterate_range m (n-1) t meta def replace_at (tac : expr → tactic (expr × expr)) (hs : list expr) (tgt : bool) : tactic bool := do to_remove ← hs.mfilter $ λ h, do { h_type ← infer_type h, succeeds $ do (new_h_type, pr) ← tac h_type, assert h.local_pp_name new_h_type, mk_eq_mp pr h >>= tactic.exact }, goal_simplified ← succeeds $ do { guard tgt, (new_t, pr) ← target >>= tac, replace_target new_t pr }, to_remove.mmap' (λ h, try (clear h)), return (¬ to_remove.empty ∨ goal_simplified) meta def simp_bottom_up' (post : expr → tactic (expr × expr)) (e : expr) (cfg : simp_config := {}) : tactic (expr × expr) := prod.snd <$> simplify_bottom_up () (λ _, (<$>) (prod.mk ()) ∘ post) e cfg meta structure instance_cache := (α : expr) (univ : level) (inst : name_map expr) meta def mk_instance_cache (α : expr) : tactic instance_cache := do u ← mk_meta_univ, infer_type α >>= unify (expr.sort (level.succ u)), u ← get_univ_assignment u, return ⟨α, u, mk_name_map⟩ namespace instance_cache meta def get (c : instance_cache) (n : name) : tactic (instance_cache × expr) := match c.inst.find n with | some i := return (c, i) | none := do e ← mk_app n [c.α] >>= mk_instance, return (⟨c.α, c.univ, c.inst.insert n e⟩, e) end open expr meta def append_typeclasses : expr → instance_cache → list expr → tactic (instance_cache × list expr) | (pi _ binder_info.inst_implicit (app (const n _) (var _)) body) c l := do (c, p) ← c.get n, return (c, p :: l) | _ c l := return (c, l) meta def mk_app (c : instance_cache) (n : name) (l : list expr) : tactic (instance_cache × expr) := do d ← get_decl n, (c, l) ← append_typeclasses d.type.binding_body c l, return (c, (expr.const n [c.univ]).mk_app (c.α :: l)) end instance_cache meta def match_head (e : expr) : expr → tactic unit | e' := unify e e' <|> do `(_ → %%e') ← whnf e', v ← mk_mvar, match_head (e'.instantiate_var v) meta def find_matching_head : expr → list expr → tactic (list expr) | e [] := return [] | e (H :: Hs) := do t ← infer_type H, ((::) H <$ match_head e t <|> pure id) <*> find_matching_head e Hs meta def subst_locals (s : list (expr × expr)) (e : expr) : expr := (e.abstract_locals (s.map (expr.local_uniq_name ∘ prod.fst)).reverse).instantiate_vars (s.map prod.snd) meta def set_binder : expr → list binder_info → expr | e [] := e | (expr.pi v _ d b) (bi :: bs) := expr.pi v bi d (set_binder b bs) | e _ := e meta def last_explicit_arg : expr → tactic expr | (expr.app f e) := do t ← infer_type f >>= whnf, if t.binding_info = binder_info.default then pure e else last_explicit_arg f | e := pure e private meta def get_expl_pi_arity_aux : expr → tactic nat | (expr.pi n bi d b) := do m ← mk_fresh_name, let l := expr.local_const m n bi d, new_b ← whnf (expr.instantiate_var b l), r ← get_expl_pi_arity_aux new_b, if bi = binder_info.default then return (r + 1) else return r | e := return 0 /-- Compute the arity of explicit arguments of the given (Pi-)type -/ meta def get_expl_pi_arity (type : expr) : tactic nat := whnf type >>= get_expl_pi_arity_aux /-- Compute the arity of explicit arguments of the given function -/ meta def get_expl_arity (fn : expr) : tactic nat := infer_type fn >>= get_expl_pi_arity /-- Auxilliary defintion for `get_pi_binders`. -/ meta def get_pi_binders_aux : list binder → expr → tactic (list binder × expr) | es (expr.pi n bi d b) := do m ← mk_fresh_name, let l := expr.local_const m n bi d, let new_b := expr.instantiate_var b l, get_pi_binders_aux (⟨n, bi, d⟩::es) new_b | es e := return (es, e) /-- Get the binders and target of a pi-type. Instantiates bound variables by local constants. -/ meta def get_pi_binders : expr → tactic (list binder × expr) | e := do (es, e) ← get_pi_binders_aux [] e, return (es.reverse, e) /-- variation on `assert` where a (possibly incomplete) proof of the assertion is provided as a parameter. ``(h,gs) ← local_proof `h p tac`` creates a local `h : p` and use `tac` to (partially) construct a proof for it. `gs` is the list of remaining goals in the proof of `h`. The benefits over assert are: - unlike with ``h ← assert `h p, tac`` , `h` cannot be used by `tac`; - when `tac` does not complete the proof of `h`, returning the list of goals allows one to write a tactic using `h` and with the confidence that a proof will not boil over to goals left over from the proof of `h`, unlike what would be the case when using `tactic.swap`. -/ meta def local_proof (h : name) (p : expr) (tac₀ : tactic unit) : tactic (expr × list expr) := focus1 $ do h' ← assert h p, [g₀,g₁] ← get_goals, set_goals [g₀], tac₀, gs ← get_goals, set_goals [g₁], return (h', gs) meta def var_names : expr → list name | (expr.pi n _ _ b) := n :: var_names b | _ := [] meta def drop_binders : expr → tactic expr | (expr.pi n bi t b) := b.instantiate_var <$> mk_local' n bi t >>= drop_binders | e := pure e meta def subobject_names (struct_n : name) : tactic (list name × list name) := do env ← get_env, [c] ← pure $ env.constructors_of struct_n | fail "too many constructors", vs ← var_names <$> (mk_const c >>= infer_type), fields ← env.structure_fields struct_n, return $ fields.partition (λ fn, ↑("_" ++ fn.to_string) ∈ vs) meta def expanded_field_list' : name → tactic (dlist $ name × name) | struct_n := do (so,fs) ← subobject_names struct_n, ts ← so.mmap (λ n, do e ← mk_const (n.update_prefix struct_n) >>= infer_type >>= drop_binders, expanded_field_list' $ e.get_app_fn.const_name), return $ dlist.join ts ++ dlist.of_list (fs.map $ prod.mk struct_n) open functor function meta def expanded_field_list (struct_n : name) : tactic (list $ name × name) := dlist.to_list <$> expanded_field_list' struct_n meta def get_classes (e : expr) : tactic (list name) := attribute.get_instances `class >>= list.mfilter (λ n, succeeds $ mk_app n [e] >>= mk_instance) open nat meta def mk_mvar_list : ℕ → tactic (list expr) | 0 := pure [] | (succ n) := (::) <$> mk_mvar <*> mk_mvar_list n /-- Returns the only goal, or fails if there isn't just one goal. -/ meta def get_goal : tactic expr := do gs ← get_goals, match gs with | [a] := return a | [] := fail "there are no goals" | _ := fail "there are too many goals" end /--`iterate_at_most_on_all_goals n t`: repeat the given tactic at most `n` times on all goals, or until it fails. Always succeeds. -/ meta def iterate_at_most_on_all_goals : nat → tactic unit → tactic unit | 0 tac := trace "maximal iterations reached" | (succ n) tac := tactic.all_goals $ (do tac, iterate_at_most_on_all_goals n tac) <|> skip /--`iterate_at_most_on_subgoals n t`: repeat the tactic `t` at most `n` times on the first goal and on all subgoals thus produced, or until it fails. Fails iff `t` fails on current goal. -/ meta def iterate_at_most_on_subgoals : nat → tactic unit → tactic unit | 0 tac := trace "maximal iterations reached" | (succ n) tac := focus1 (do tac, iterate_at_most_on_all_goals n tac) /--`apply_list l`: try to apply the tactics in the list `l` on the first goal, and fail if none succeeds -/ meta def apply_list_expr : list expr → tactic unit | [] := fail "no matching rule" | (h::t) := do interactive.concat_tags (apply h) <|> apply_list_expr t /-- constructs a list of expressions given a list of p-expressions, as follows: - if the p-expression is the name of a theorem, use `i_to_expr_for_apply` on it - if the p-expression is a user attribute, add all the theorems with this attribute to the list.-/ meta def build_list_expr_for_apply : list pexpr → tactic (list expr) | [] := return [] | (h::t) := do tail ← build_list_expr_for_apply t, a ← i_to_expr_for_apply h, (do l ← attribute.get_instances (expr.const_name a), m ← list.mmap mk_const l, return (m.append tail)) <|> return (a::tail) /--`apply_rules hs n`: apply the list of rules `hs` (given as pexpr) and `assumption` on the first goal and the resulting subgoals, iteratively, at most `n` times -/ meta def apply_rules (hs : list pexpr) (n : nat) : tactic unit := do l ← build_list_expr_for_apply hs, iterate_at_most_on_subgoals n (assumption <|> apply_list_expr l) meta def replace (h : name) (p : pexpr) : tactic unit := do h' ← get_local h, p ← to_expr p, note h none p, clear h' /-- Auxiliary function for `iff_mp` and `iff_mpr`. Takes a name, which should be either `` `iff.mp`` or `` `iff.mpr``. If the passed expression is an iterated function type eventually producing an `iff`, returns an expression with the `iff` converted to either the forwards or backwards implication, as requested. -/ meta def mk_iff_mp_app (iffmp : name) : expr → (nat → expr) → option expr | (expr.pi n bi e t) f := expr.lam n bi e <$> mk_iff_mp_app t (λ n, f (n+1) (expr.var n)) | `(%%a ↔ %%b) f := some $ @expr.const tt iffmp [] a b (f 0) | _ f := none meta def iff_mp_core (e ty: expr) : option expr := mk_iff_mp_app `iff.mp ty (λ_, e) meta def iff_mpr_core (e ty: expr) : option expr := mk_iff_mp_app `iff.mpr ty (λ_, e) /-- Given an expression whose type is (a possibly iterated function producing) an `iff`, create the expression which is the forward implication. -/ meta def iff_mp (e : expr) : tactic expr := do t ← infer_type e, iff_mp_core e t <|> fail "Target theorem must have the form `Π x y z, a ↔ b`" /-- Given an expression whose type is (a possibly iterated function producing) an `iff`, create the expression which is the reverse implication. -/ meta def iff_mpr (e : expr) : tactic expr := do t ← infer_type e, iff_mpr_core e t <|> fail "Target theorem must have the form `Π x y z, a ↔ b`" /-- Attempts to apply `e`, and if that fails, if `e` is an `iff`, try applying both directions separately. -/ meta def apply_iff (e : expr) : tactic (list (name × expr)) := let ap e := tactic.apply e {new_goals := new_goals.non_dep_only} in ap e <|> (iff_mp e >>= ap) <|> (iff_mpr e >>= ap) meta def symm_apply (e : expr) (cfg : apply_cfg := {}) : tactic (list (name × expr)) := tactic.apply e cfg <|> (symmetry >> tactic.apply e cfg) meta def apply_assumption (asms : tactic (list expr) := local_context) (tac : tactic unit := skip) : tactic unit := do { ctx ← asms, ctx.any_of (λ H, symm_apply H >> tac) } <|> do { exfalso, ctx ← asms, ctx.any_of (λ H, symm_apply H >> tac) } <|> fail "assumption tactic failed" meta def change_core (e : expr) : option expr → tactic unit | none := tactic.change e | (some h) := do num_reverted : ℕ ← revert h, expr.pi n bi d b ← target, tactic.change $ expr.pi n bi e b, intron num_reverted /-- assuming olde and newe are defeq when elaborated, replaces occurences of olde with newe at hypothesis h. -/ meta def change_with_at (olde newe : pexpr) (hyp : name) : tactic unit := do h ← get_local hyp, tp ← infer_type h, olde ← to_expr olde, newe ← to_expr newe, let repl_tp := tp.replace (λ a n, if a = olde then some newe else none), change_core repl_tp (some h) meta def metavariables : tactic (list expr) := do r ← result, pure (r.list_meta_vars) /-- Succeeds only if the current goal is a proposition. -/ meta def propositional_goal : tactic unit := do goals ← get_goals, p ← is_proof goals.head, guard p /-- Succeeds only if we can construct an instance showing the current goal is a subsingleton type. -/ meta def subsingleton_goal : tactic unit := do goals ← get_goals, ty ← infer_type goals.head >>= instantiate_mvars, to_expr ``(subsingleton %%ty) >>= mk_instance >> skip /-- Succeeds only if the current goal is "terminal", in the sense that no other goals depend on it. -/ meta def terminal_goal : tactic unit := -- We can't merely test for subsingletons, as sometimes in the presence of metavariables -- `propositional_goal` succeeds while `subsingleton_goal` does not. propositional_goal <|> subsingleton_goal <|> do g₀ :: _ ← get_goals, mvars ← (λ L, list.erase L g₀) <$> metavariables, mvars.mmap' $ λ g, do t ← infer_type g >>= instantiate_mvars, d ← kdepends_on t g₀, monad.whenb d $ pp t >>= λ s, fail ("The current goal is not terminal: " ++ s.to_string ++ " depends on it.") meta def triv' : tactic unit := do c ← mk_const `trivial, exact c reducible variable {α : Type} private meta def iterate_aux (t : tactic α) : list α → tactic (list α) | L := (do r ← t, iterate_aux (r :: L)) <|> return L /-- Apply a tactic as many times as possible, collecting the results in a list. -/ meta def iterate' (t : tactic α) : tactic (list α) := list.reverse <$> iterate_aux t [] /-- Like iterate', but fail if the tactic does not succeed at least once. -/ meta def iterate1 (t : tactic α) : tactic (α × list α) := do r ← decorate_ex "iterate1 failed: tactic did not succeed" t, L ← iterate' t, return (r, L) meta def intros1 : tactic (list expr) := iterate1 intro1 >>= λ p, return (p.1 :: p.2) /-- `successes` invokes each tactic in turn, returning the list of successful results. -/ meta def successes (tactics : list (tactic α)) : tactic (list α) := list.filter_map id <$> monad.sequence (tactics.map (λ t, try_core t)) /-- Return target after instantiating metavars and whnf -/ private meta def target' : tactic expr := target >>= instantiate_mvars >>= whnf /-- Just like `split`, `fsplit` applies the constructor when the type of the target is an inductive data type with one constructor. However it does not reorder goals or invoke `auto_param` tactics. -/ -- FIXME check if we can remove `auto_param := ff` meta def fsplit : tactic unit := do [c] ← target' >>= get_constructors_for | tactic.fail "fsplit tactic failed, target is not an inductive datatype with only one constructor", mk_const c >>= λ e, apply e {new_goals := new_goals.all, auto_param := ff} >> skip run_cmd add_interactive [`fsplit] /-- Calls `injection` on each hypothesis, and then, for each hypothesis on which `injection` succeeds, clears the old hypothesis. -/ meta def injections_and_clear : tactic unit := do l ← local_context, results ← successes $ l.map $ λ e, injection e >> clear e, when (results.empty) (fail "could not use `injection` then `clear` on any hypothesis") run_cmd add_interactive [`injections_and_clear] /-- calls `cases` on every local hypothesis, succeeding if it succeeds on at least one hypothesis. -/ meta def case_bash : tactic unit := do l ← local_context, r ← successes (l.reverse.map (λ h, cases h >> skip)), when (r.empty) failed /-- given a proof `pr : t`, adds `h : t` to the current context, where the name `h` is fresh. -/ meta def note_anon (e : expr) : tactic expr := do n ← get_unused_name "lh", note n none e /-- `find_local t` returns a local constant with type t, or fails if none exists. -/ meta def find_local (t : pexpr) : tactic expr := do t' ← to_expr t, prod.snd <$> solve_aux t' assumption /-- `dependent_pose_core l`: introduce dependent hypothesis, where the proofs depend on the values of the previous local constants. `l` is a list of local constants and their values. -/ meta def dependent_pose_core (l : list (expr × expr)) : tactic unit := do let lc := l.map prod.fst, let lm := l.map (λ⟨l, v⟩, (l.local_uniq_name, v)), t ← target, new_goal ← mk_meta_var (t.pis lc), old::other_goals ← get_goals, set_goals (old :: new_goal :: other_goals), exact ((new_goal.mk_app lc).instantiate_locals lm), return () /-- like `mk_local_pis` but translating into weak head normal form before checking if it is a Π. -/ meta def mk_local_pis_whnf : expr → tactic (list expr × expr) | e := do (expr.pi n bi d b) ← whnf e | return ([], e), p ← mk_local' n bi d, (ps, r) ← mk_local_pis (expr.instantiate_var b p), return ((p :: ps), r) /-- Changes `(h : ∀xs, ∃a:α, p a) ⊢ g` to `(d : ∀xs, a) (s : ∀xs, p (d xs) ⊢ g` -/ meta def choose1 (h : expr) (data : name) (spec : name) : tactic expr := do t ← infer_type h, (ctxt, t) ← mk_local_pis_whnf t, `(@Exists %%α %%p) ← whnf t transparency.all | fail "expected a term of the shape ∀xs, ∃a, p xs a", α_t ← infer_type α, expr.sort u ← whnf α_t transparency.all, value ← mk_local_def data (α.pis ctxt), t' ← head_beta (p.app (value.mk_app ctxt)), spec ← mk_local_def spec (t'.pis ctxt), dependent_pose_core [ (value, ((((expr.const `classical.some [u]).app α).app p).app (h.mk_app ctxt)).lambdas ctxt), (spec, ((((expr.const `classical.some_spec [u]).app α).app p).app (h.mk_app ctxt)).lambdas ctxt)], try (tactic.clear h), intro1, intro1 /-- Changes `(h : ∀xs, ∃as, p as) ⊢ g` to a list of functions `as`, an a final hypothesis on `p as` -/ meta def choose : expr → list name → tactic unit | h [] := fail "expect list of variables" | h [n] := do cnt ← revert h, intro n, intron (cnt - 1), return () | h (n::ns) := do v ← get_unused_name >>= choose1 h n, choose v ns /-- This makes sure that the execution of the tactic does not change the tactic state. This can be helpful while using rewrite, apply, or expr munging. Remember to instantiate your metavariables before you're done! -/ meta def lock_tactic_state {α} (t : tactic α) : tactic α | s := match t s with | result.success a s' := result.success a s | result.exception msg pos s' := result.exception msg pos s end /-- similar to `mk_local_pis` but make meta variables instead of local constants -/ meta def mk_meta_pis : expr → tactic (list expr × expr) | (expr.pi n bi d b) := do p ← mk_meta_var d, (ps, r) ← mk_meta_pis (expr.instantiate_var b p), return ((p :: ps), r) | e := return ([], e) /-- Hole command used to fill in a structure's field when specifying an instance. In the following: ``` instance : monad id := {! !} ``` invoking hole command `Instance Stub` produces: ``` instance : monad id := { map := _, map_const := _, pure := _, seq := _, seq_left := _, seq_right := _, bind := _ } ``` -/ @[hole_command] meta def instance_stub : hole_command := { name := "Instance Stub", descr := "Generate a skeleton for the structure under construction.", action := λ _, do tgt ← target >>= whnf, let cl := tgt.get_app_fn.const_name, env ← get_env, fs ← expanded_field_list cl, let fs := fs.map prod.snd, let fs := format.intercalate (",\n " : format) $ fs.map (λ fn, format!"{fn} := _"), let out := format.to_string format!"{{ {fs} }", return [(out,"")] } meta def strip_prefix' (n : name) : list string → name → tactic name | s name.anonymous := pure $ s.foldl (flip name.mk_string) name.anonymous | s (name.mk_string a p) := do let n' := s.foldl (flip name.mk_string) name.anonymous, do { n'' ← tactic.resolve_constant n', if n'' = n then pure n' else strip_prefix' (a :: s) p } <|> strip_prefix' (a :: s) p | s (name.mk_numeral a p) := interaction_monad.failed meta def strip_prefix : name → tactic name | n@(name.mk_string a a_1) := strip_prefix' n [a] a_1 | _ := interaction_monad.failed meta def local_binding_info : expr → binder_info | (expr.local_const _ _ bi _) := bi | _ := binder_info.default meta def is_default_local : expr → bool | (expr.local_const _ _ binder_info.default _) := tt | _ := ff meta def mk_patterns (t : expr) : tactic (list format) := do let cl := t.get_app_fn.const_name, env ← get_env, let fs := env.constructors_of cl, fs.mmap $ λ f, do { (vs,_) ← mk_const f >>= infer_type >>= mk_local_pis, let vs := vs.filter (λ v, is_default_local v), vs ← vs.mmap (λ v, do v' ← get_unused_name v.local_pp_name, pose v' none `(()), pure v' ), vs.mmap' $ λ v, get_local v >>= clear, let args := list.intersperse (" " : format) $ vs.map to_fmt, f ← strip_prefix f, if args.empty then pure $ format!"| {f} := _\n" else pure format!"| ({f} {format.join args}) := _\n" } /-- Hole command used to generate a `match` expression. In the following: ``` meta def foo (e : expr) : tactic unit := {! e !} ``` invoking hole command `Match Stub` produces: ``` meta def foo (e : expr) : tactic unit := match e with | (expr.var a) := _ | (expr.sort a) := _ | (expr.const a a_1) := _ | (expr.mvar a a_1 a_2) := _ | (expr.local_const a a_1 a_2 a_3) := _ | (expr.app a a_1) := _ | (expr.lam a a_1 a_2 a_3) := _ | (expr.pi a a_1 a_2 a_3) := _ | (expr.elet a a_1 a_2 a_3) := _ | (expr.macro a a_1) := _ end ``` -/ @[hole_command] meta def match_stub : hole_command := { name := "Match Stub", descr := "Generate a list of equations for a `match` expression.", action := λ es, do [e] ← pure es | fail "expecting one expression", e ← to_expr e, t ← infer_type e >>= whnf, fs ← mk_patterns t, e ← pp e, let out := format.to_string format!"match {e} with\n{format.join fs}end\n", return [(out,"")] } /-- Hole command used to generate a `match` expression. In the following: ``` meta def foo : {! expr → tactic unit !} -- `:=` is omitted ``` invoking hole command `Equations Stub` produces: ``` meta def foo : expr → tactic unit | (expr.var a) := _ | (expr.sort a) := _ | (expr.const a a_1) := _ | (expr.mvar a a_1 a_2) := _ | (expr.local_const a a_1 a_2 a_3) := _ | (expr.app a a_1) := _ | (expr.lam a a_1 a_2 a_3) := _ | (expr.pi a a_1 a_2 a_3) := _ | (expr.elet a a_1 a_2 a_3) := _ | (expr.macro a a_1) := _ ``` A similar result can be obtained by invoking `Equations Stub` on the following: ``` meta def foo : expr → tactic unit := -- do not forget to write `:=`!! {! !} ``` ``` meta def foo : expr → tactic unit := -- don't forget to erase `:=`!! | (expr.var a) := _ | (expr.sort a) := _ | (expr.const a a_1) := _ | (expr.mvar a a_1 a_2) := _ | (expr.local_const a a_1 a_2 a_3) := _ | (expr.app a a_1) := _ | (expr.lam a a_1 a_2 a_3) := _ | (expr.pi a a_1 a_2 a_3) := _ | (expr.elet a a_1 a_2 a_3) := _ | (expr.macro a a_1) := _ ``` -/ @[hole_command] meta def eqn_stub : hole_command := { name := "Equations Stub", descr := "Generate a list of equations for a recursive definition.", action := λ es, do t ← match es with | [t] := to_expr t | [] := target | _ := fail "expecting one type" end, e ← whnf t, (v :: _,_) ← mk_local_pis e | fail "expecting a Pi-type", t' ← infer_type v, fs ← mk_patterns t', t ← pp t, let out := if es.empty then format.to_string format!"-- do not forget to erase `:=`!!\n{format.join fs}" else format.to_string format!"{t}\n{format.join fs}", return [(out,"")] } /-- This command lists the constructors that can be used to satisfy the expected type. When used in the following hole: ``` def foo : ℤ ⊕ ℕ := {! !} ``` the command will produce: ``` def foo : ℤ ⊕ ℕ := {! sum.inl, sum.inr !} ``` and will display: ``` sum.inl : ℤ → ℤ ⊕ ℕ sum.inr : ℕ → ℤ ⊕ ℕ ``` -/ @[hole_command] meta def list_constructors_hole : hole_command := { name := "List Constructors", descr := "Show the list of constructors of the expected type.", action := λ es, do t ← target >>= whnf, (_,t) ← mk_local_pis t, let cl := t.get_app_fn.const_name, let args := t.get_app_args, env ← get_env, let cs := env.constructors_of cl, ts ← cs.mmap $ λ c, do { e ← mk_const c, t ← infer_type (e.mk_app args) >>= pp, c ← strip_prefix c, pure format!"\n{c} : {t}\n" }, fs ← format.intercalate ", " <$> cs.mmap (strip_prefix >=> pure ∘ to_fmt), let out := format.to_string format!"{{! {fs} !}", trace (format.join ts).to_string, return [(out,"")] } meta def classical : tactic unit := do h ← get_unused_name `_inst, mk_const `classical.prop_decidable >>= note h none, reset_instance_cache open expr meta def add_prime : name → name | (name.mk_string s p) := name.mk_string (s ++ "'") p | n := (name.mk_string "x'" n) meta def mk_comp (v : expr) : expr → tactic expr | (app f e) := if e = v then pure f else do guard (¬ v.occurs f) <|> fail "bad guard", e' ← mk_comp e >>= instantiate_mvars, f ← instantiate_mvars f, mk_mapp ``function.comp [none,none,none,f,e'] | e := do guard (e = v), t ← infer_type e, mk_mapp ``id [t] meta def mk_higher_order_type : expr → tactic expr | (pi n bi d b@(pi _ _ _ _)) := do v ← mk_local_def n d, let b' := (b.instantiate_var v), (pi n bi d ∘ flip abstract_local v.local_uniq_name) <$> mk_higher_order_type b' | (pi n bi d b) := do v ← mk_local_def n d, let b' := (b.instantiate_var v), (l,r) ← match_eq b' <|> fail format!"not an equality {b'}", l' ← mk_comp v l, r' ← mk_comp v r, mk_app ``eq [l',r'] | e := failed open lean.parser interactive.types @[user_attribute] meta def higher_order_attr : user_attribute unit (option name) := { name := `higher_order, parser := optional ident, descr := "From a lemma of the shape `f (g x) = h x` derive an auxiliary lemma of the form `f ∘ g = h` for reasoning about higher-order functions.", after_set := some $ λ lmm _ _, do env ← get_env, decl ← env.get lmm, let num := decl.univ_params.length, let lvls := (list.iota num).map (`l).append_after, let l : expr := expr.const lmm $ lvls.map level.param, t ← infer_type l >>= instantiate_mvars, t' ← mk_higher_order_type t, (_,pr) ← solve_aux t' $ do { intros, applyc ``_root_.funext, intro1, applyc lmm; assumption }, pr ← instantiate_mvars pr, lmm' ← higher_order_attr.get_param lmm, lmm' ← (flip name.update_prefix lmm.get_prefix <$> lmm') <|> pure (add_prime lmm), add_decl $ declaration.thm lmm' lvls t' (pure pr), copy_attribute `simp lmm tt lmm', copy_attribute `functor_norm lmm tt lmm' } attribute [higher_order map_comp_pure] map_pure private meta def tactic.use_aux (h : pexpr) : tactic unit := (focus1 (refine h >> done)) <|> (fconstructor >> tactic.use_aux) meta def tactic.use (l : list pexpr) : tactic unit := focus1 $ l.mmap' $ λ h, tactic.use_aux h <|> fail format!"failed to instantiate goal with {h}" meta def clear_aux_decl_aux : list expr → tactic unit | [] := skip | (e::l) := do cond e.is_aux_decl (tactic.clear e) skip, clear_aux_decl_aux l meta def clear_aux_decl : tactic unit := local_context >>= clear_aux_decl_aux /-- `apply_at_aux e et [] h ht` (with `et` the type of `e` and `ht` the type of `h`) finds a list of expressions `vs` and returns (e.mk_args (vs ++ [h]), vs) -/ meta def apply_at_aux (arg t : expr) : list expr → expr → expr → tactic (expr × list expr) | vs e (pi n bi d b) := do { v ← mk_meta_var d, apply_at_aux (v :: vs) (e v) (b.instantiate_var v) } <|> (e arg, vs) <$ unify d t | vs e _ := failed /-- `apply_at e h` applies implication `e` on hypothesis `h` and replaces `h` with the result -/ meta def apply_at (e h : expr) : tactic unit := do ht ← infer_type h, et ← infer_type e, (h', gs') ← apply_at_aux h ht [] e et, note h.local_pp_name none h', clear h, gs' ← gs'.mfilter is_assigned, (g :: gs) ← get_goals, set_goals (g :: gs' ++ gs) /-- `symmetry_hyp h` applies symmetry on hypothesis `h` -/ meta def symmetry_hyp (h : expr) (md := semireducible) : tactic unit := do tgt ← infer_type h, env ← get_env, let r := get_app_fn tgt, match env.symm_for (const_name r) with | (some symm) := do s ← mk_const symm, apply_at s h | none := fail "symmetry tactic failed, target is not a relation application with the expected property." end precedence `setup_tactic_parser`:0 @[user_command] meta def setup_tactic_parser_cmd (_ : interactive.parse $ tk "setup_tactic_parser") : lean.parser unit := emit_code_here " open lean open lean.parser open interactive interactive.types local postfix `?`:9001 := optional local postfix *:9001 := many . " meta def trace_error (msg : string) (t : tactic α) : tactic α | s := match t s with | (result.success r s') := result.success r s' | (result.exception (some msg') p s') := (trace msg >> trace (msg' ()) >> result.exception (some msg') p) s' | (result.exception none p s') := result.exception none p s' end /-- This combinator is for testing purposes. It succeeds if `t` fails with message `msg`, and fails otherwise. -/ meta def {u} success_if_fail_with_msg {α : Type u} (t : tactic α) (msg : string) : tactic unit := λ s, match t s with | (interaction_monad.result.exception msg' _ s') := if msg = (msg'.iget ()).to_string then result.success () s else mk_exception "failure messages didn't match" none s | (interaction_monad.result.success a s) := mk_exception "success_if_fail_with_msg combinator failed, given tactic succeeded" none s end open lean interactive meta def pformat := tactic format meta def pformat.mk (fmt : format) : pformat := pure fmt meta def to_pfmt {α} [has_to_tactic_format α] (x : α) : pformat := pp x meta instance pformat.has_to_tactic_format : has_to_tactic_format pformat := ⟨ id ⟩ meta instance : has_append pformat := ⟨ λ x y, (++) <$> x <*> y ⟩ meta instance tactic.has_to_tactic_format [has_to_tactic_format α] : has_to_tactic_format (tactic α) := ⟨ λ x, x >>= to_pfmt ⟩ private meta def parse_pformat : string → list char → parser pexpr | acc [] := pure ``(to_pfmt %%(reflect acc)) | acc ('\n'::s) := do f ← parse_pformat "" s, pure ``(to_pfmt %%(reflect acc) ++ pformat.mk format.line ++ %%f) | acc ('{'::'{'::s) := parse_pformat (acc ++ "{") s | acc ('{'::s) := do (e, s) ← with_input (lean.parser.pexpr 0) s.as_string, '}'::s ← return s.to_list | fail "'}' expected", f ← parse_pformat "" s, pure ``(to_pfmt %%(reflect acc) ++ to_pfmt %%e ++ %%f) | acc (c::s) := parse_pformat (acc.str c) s reserve prefix `pformat! `:100 /-- See `format!` in `init/meta/interactive_base.lean`. The main differences are that `pp` is called instead of `to_fmt` and that we can use arguments of type `tactic α` in the quotations. Now, consider the following: ``` e ← to_expr ``(3 + 7), trace format!"{e}" -- outputs `has_add.add.{0} nat nat.has_add (bit1.{0} nat nat.has_one nat.has_add (has_one.one.{0} nat nat.has_one)) ...` trace pformat!"{e}" -- outputs `3 + 7` ``` The difference is significant. And now, the following is expressible: ``` e ← to_expr ``(3 + 7), trace pformat!"{e} : {infer_type e}" -- outputs `3 + 7 : ℕ` ``` See also: `trace!` and `fail!` -/ @[user_notation] meta def pformat_macro (_ : parse $ tk "pformat!") (s : string) : parser pexpr := do e ← parse_pformat "" s.to_list, return ``(%%e : pformat) reserve prefix `fail! `:100 /-- the combination of `pformat` and `fail` -/ @[user_notation] meta def fail_macro (_ : parse $ tk "fail!") (s : string) : parser pexpr := do e ← pformat_macro () s, pure ``((%%e : pformat) >>= fail) reserve prefix `trace! `:100 /-- the combination of `pformat` and `fail` -/ @[user_notation] meta def trace_macro (_ : parse $ tk "trace!") (s : string) : parser pexpr := do e ← pformat_macro () s, pure ``((%%e : pformat) >>= trace) /-- A hackish way to get the `src` directory of mathlib. -/ meta def get_mathlib_dir : tactic string := do e ← get_env, s ← e.decl_olean `tactic.reset_instance_cache, return $ s.popn_back 17 /-- Checks whether `ml` is a prefix of the file where `n` is declared. If you want to run `is_in_mathlib` many times, you should use this tactic instead, since it is expensive to execute get_mathlib_dir many times. -/ meta def is_in_mathlib_aux (ml : string) (n : name) : tactic bool := do e ← get_env, return $ ml.is_prefix_of $ (e.decl_olean n).get_or_else "" /-- Checks whether a declaration with the given name is declared in mathlib. If you want to run this tactic many times, you should use `is_in_mathlib_aux` instead, since it is expensive to execute get_mathlib_dir many times. -/ meta def is_in_mathlib (n : name) : tactic bool := do ml ← get_mathlib_dir, is_in_mathlib_aux ml n end tactic open tactic
827d08ac52977c424eaa1c239618363d3fdb30c9
4727251e0cd73359b15b664c3170e5d754078599
/src/ring_theory/perfection.lean
c4f8b0bb7bb69d571370d19e842512c2598f237a
[ "Apache-2.0" ]
permissive
Vierkantor/mathlib
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
refs/heads/master
1,658,323,012,449
1,652,256,003,000
1,652,256,003,000
209,296,341
0
1
Apache-2.0
1,568,807,655,000
1,568,807,655,000
null
UTF-8
Lean
false
false
25,423
lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import algebra.char_p.pi import algebra.char_p.quotient import algebra.char_p.subring import algebra.ring.pi import analysis.special_functions.pow import field_theory.perfect_closure import ring_theory.localization.fraction_ring import ring_theory.subring.basic import ring_theory.valuation.integers /-! # Ring Perfection and Tilt In this file we define the perfection of a ring of characteristic p, and the tilt of a field given a valuation to `ℝ≥0`. ## TODO Define the valuation on the tilt, and define a characteristic predicate for the tilt. -/ universes u₁ u₂ u₃ u₄ open_locale nnreal /-- The perfection of a monoid `M`, defined to be the projective limit of `M` using the `p`-th power maps `M → M` indexed by the natural numbers, implemented as `{ f : ℕ → M | ∀ n, f (n + 1) ^ p = f n }`. -/ def monoid.perfection (M : Type u₁) [comm_monoid M] (p : ℕ) : submonoid (ℕ → M) := { carrier := { f | ∀ n, f (n + 1) ^ p = f n }, one_mem' := λ n, one_pow _, mul_mem' := λ f g hf hg n, (mul_pow _ _ _).trans $ congr_arg2 _ (hf n) (hg n) } /-- The perfection of a ring `R` with characteristic `p`, as a subsemiring, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{ f : ℕ → R | ∀ n, f (n + 1) ^ p = f n }`. -/ def ring.perfection_subsemiring (R : Type u₁) [comm_semiring R] (p : ℕ) [hp : fact p.prime] [char_p R p] : subsemiring (ℕ → R) := { zero_mem' := λ n, zero_pow $ hp.1.pos, add_mem' := λ f g hf hg n, (frobenius_add R p _ _).trans $ congr_arg2 _ (hf n) (hg n), .. monoid.perfection R p } /-- The perfection of a ring `R` with characteristic `p`, as a subring, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{ f : ℕ → R | ∀ n, f (n + 1) ^ p = f n }`. -/ def ring.perfection_subring (R : Type u₁) [comm_ring R] (p : ℕ) [hp : fact p.prime] [char_p R p] : subring (ℕ → R) := (ring.perfection_subsemiring R p).to_subring $ λ n, by simp_rw [← frobenius_def, pi.neg_apply, pi.one_apply, ring_hom.map_neg, ring_hom.map_one] /-- The perfection of a ring `R` with characteristic `p`, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{f : ℕ → R // ∀ n, f (n + 1) ^ p = f n}`. -/ def ring.perfection (R : Type u₁) [comm_semiring R] (p : ℕ) : Type u₁ := {f // ∀ (n : ℕ), (f : ℕ → R) (n + 1) ^ p = f n} namespace perfection variables (R : Type u₁) [comm_semiring R] (p : ℕ) [hp : fact p.prime] [char_p R p] include hp instance : comm_semiring (ring.perfection R p) := (ring.perfection_subsemiring R p).to_comm_semiring instance : char_p (ring.perfection R p) p := char_p.subsemiring (ℕ → R) p (ring.perfection_subsemiring R p) instance ring (R : Type u₁) [comm_ring R] [char_p R p] : ring (ring.perfection R p) := (ring.perfection_subring R p).to_ring instance comm_ring (R : Type u₁) [comm_ring R] [char_p R p] : comm_ring (ring.perfection R p) := (ring.perfection_subring R p).to_comm_ring instance : inhabited (ring.perfection R p) := ⟨0⟩ /-- The `n`-th coefficient of an element of the perfection. -/ def coeff (n : ℕ) : ring.perfection R p →+* R := { to_fun := λ f, f.1 n, map_one' := rfl, map_mul' := λ f g, rfl, map_zero' := rfl, map_add' := λ f g, rfl } variables {R p} @[ext] lemma ext {f g : ring.perfection R p} (h : ∀ n, coeff R p n f = coeff R p n g) : f = g := subtype.eq $ funext h variables (R p) /-- The `p`-th root of an element of the perfection. -/ def pth_root : ring.perfection R p →+* ring.perfection R p := { to_fun := λ f, ⟨λ n, coeff R p (n + 1) f, λ n, f.2 _⟩, map_one' := rfl, map_mul' := λ f g, rfl, map_zero' := rfl, map_add' := λ f g, rfl } variables {R p} @[simp] lemma coeff_mk (f : ℕ → R) (hf) (n : ℕ) : coeff R p n ⟨f, hf⟩ = f n := rfl lemma coeff_pth_root (f : ring.perfection R p) (n : ℕ) : coeff R p n (pth_root R p f) = coeff R p (n + 1) f := rfl lemma coeff_pow_p (f : ring.perfection R p) (n : ℕ) : coeff R p (n + 1) (f ^ p) = coeff R p n f := by { rw ring_hom.map_pow, exact f.2 n } lemma coeff_pow_p' (f : ring.perfection R p) (n : ℕ) : coeff R p (n + 1) f ^ p = coeff R p n f := f.2 n lemma coeff_frobenius (f : ring.perfection R p) (n : ℕ) : coeff R p (n + 1) (frobenius _ p f) = coeff R p n f := by apply coeff_pow_p f n -- `coeff_pow_p f n` also works but is slow! lemma coeff_iterate_frobenius (f : ring.perfection R p) (n m : ℕ) : coeff R p (n + m) (frobenius _ p ^[m] f) = coeff R p n f := nat.rec_on m rfl $ λ m ih, by erw [function.iterate_succ_apply', coeff_frobenius, ih] lemma coeff_iterate_frobenius' (f : ring.perfection R p) (n m : ℕ) (hmn : m ≤ n) : coeff R p n (frobenius _ p ^[m] f) = coeff R p (n - m) f := eq.symm $ (coeff_iterate_frobenius _ _ m).symm.trans $ (tsub_add_cancel_of_le hmn).symm ▸ rfl lemma pth_root_frobenius : (pth_root R p).comp (frobenius _ p) = ring_hom.id _ := ring_hom.ext $ λ x, ext $ λ n, by rw [ring_hom.comp_apply, ring_hom.id_apply, coeff_pth_root, coeff_frobenius] lemma frobenius_pth_root : (frobenius _ p).comp (pth_root R p) = ring_hom.id _ := ring_hom.ext $ λ x, ext $ λ n, by rw [ring_hom.comp_apply, ring_hom.id_apply, ring_hom.map_frobenius, coeff_pth_root, ← ring_hom.map_frobenius, coeff_frobenius] lemma coeff_add_ne_zero {f : ring.perfection R p} {n : ℕ} (hfn : coeff R p n f ≠ 0) (k : ℕ) : coeff R p (n + k) f ≠ 0 := nat.rec_on k hfn $ λ k ih h, ih $ by erw [← coeff_pow_p, ring_hom.map_pow, h, zero_pow hp.1.pos] lemma coeff_ne_zero_of_le {f : ring.perfection R p} {m n : ℕ} (hfm : coeff R p m f ≠ 0) (hmn : m ≤ n) : coeff R p n f ≠ 0 := let ⟨k, hk⟩ := nat.exists_eq_add_of_le hmn in hk.symm ▸ coeff_add_ne_zero hfm k variables (R p) instance perfect_ring : perfect_ring (ring.perfection R p) p := { pth_root' := pth_root R p, frobenius_pth_root' := congr_fun $ congr_arg ring_hom.to_fun $ @frobenius_pth_root R _ p _ _, pth_root_frobenius' := congr_fun $ congr_arg ring_hom.to_fun $ @pth_root_frobenius R _ p _ _ } /-- Given rings `R` and `S` of characteristic `p`, with `R` being perfect, any homomorphism `R →+* S` can be lifted to a homomorphism `R →+* perfection S p`. -/ @[simps] def lift (R : Type u₁) [comm_semiring R] [char_p R p] [perfect_ring R p] (S : Type u₂) [comm_semiring S] [char_p S p] : (R →+* S) ≃ (R →+* ring.perfection S p) := { to_fun := λ f, { to_fun := λ r, ⟨λ n, f $ _root_.pth_root R p ^[n] r, λ n, by rw [← f.map_pow, function.iterate_succ_apply', pth_root_pow_p]⟩, map_one' := ext $ λ n, (congr_arg f $ ring_hom.iterate_map_one _ _).trans f.map_one, map_mul' := λ x y, ext $ λ n, (congr_arg f $ ring_hom.iterate_map_mul _ _ _ _).trans $ f.map_mul _ _, map_zero' := ext $ λ n, (congr_arg f $ ring_hom.iterate_map_zero _ _).trans f.map_zero, map_add' := λ x y, ext $ λ n, (congr_arg f $ ring_hom.iterate_map_add _ _ _ _).trans $ f.map_add _ _ }, inv_fun := ring_hom.comp $ coeff S p 0, left_inv := λ f, ring_hom.ext $ λ r, rfl, right_inv := λ f, ring_hom.ext $ λ r, ext $ λ n, show coeff S p 0 (f (_root_.pth_root R p ^[n] r)) = coeff S p n (f r), by rw [← coeff_iterate_frobenius _ 0 n, zero_add, ← ring_hom.map_iterate_frobenius, right_inverse_pth_root_frobenius.iterate] } lemma hom_ext {R : Type u₁} [comm_semiring R] [char_p R p] [perfect_ring R p] {S : Type u₂} [comm_semiring S] [char_p S p] {f g : R →+* ring.perfection S p} (hfg : ∀ x, coeff S p 0 (f x) = coeff S p 0 (g x)) : f = g := (lift p R S).symm.injective $ ring_hom.ext hfg variables {R} {S : Type u₂} [comm_semiring S] [char_p S p] /-- A ring homomorphism `R →+* S` induces `perfection R p →+* perfection S p` -/ @[simps] def map (φ : R →+* S) : ring.perfection R p →+* ring.perfection S p := { to_fun := λ f, ⟨λ n, φ (coeff R p n f), λ n, by rw [← φ.map_pow, coeff_pow_p']⟩, map_one' := subtype.eq $ funext $ λ n, φ.map_one, map_mul' := λ f g, subtype.eq $ funext $ λ n, φ.map_mul _ _, map_zero' := subtype.eq $ funext $ λ n, φ.map_zero, map_add' := λ f g, subtype.eq $ funext $ λ n, φ.map_add _ _ } lemma coeff_map (φ : R →+* S) (f : ring.perfection R p) (n : ℕ) : coeff S p n (map p φ f) = φ (coeff R p n f) := rfl end perfection /-- A perfection map to a ring of characteristic `p` is a map that is isomorphic to its perfection. -/ @[nolint has_inhabited_instance] structure perfection_map (p : ℕ) [fact p.prime] {R : Type u₁} [comm_semiring R] [char_p R p] {P : Type u₂} [comm_semiring P] [char_p P p] [perfect_ring P p] (π : P →+* R) : Prop := (injective : ∀ ⦃x y : P⦄, (∀ n, π (pth_root P p ^[n] x) = π (pth_root P p ^[n] y)) → x = y) (surjective : ∀ f : ℕ → R, (∀ n, f (n + 1) ^ p = f n) → ∃ x : P, ∀ n, π (pth_root P p ^[n] x) = f n) namespace perfection_map variables {p : ℕ} [fact p.prime] variables {R : Type u₁} [comm_semiring R] [char_p R p] variables {P : Type u₃} [comm_semiring P] [char_p P p] [perfect_ring P p] /-- Create a `perfection_map` from an isomorphism to the perfection. -/ @[simps] lemma mk' {f : P →+* R} (g : P ≃+* ring.perfection R p) (hfg : perfection.lift p P R f = g) : perfection_map p f := { injective := λ x y hxy, g.injective $ (ring_hom.ext_iff.1 hfg x).symm.trans $ eq.symm $ (ring_hom.ext_iff.1 hfg y).symm.trans $ perfection.ext $ λ n, (hxy n).symm, surjective := λ y hy, let ⟨x, hx⟩ := g.surjective ⟨y, hy⟩ in ⟨x, λ n, show perfection.coeff R p n (perfection.lift p P R f x) = perfection.coeff R p n ⟨y, hy⟩, by rw [hfg, ← coe_fn_coe_base, hx]⟩ } variables (p R P) /-- The canonical perfection map from the perfection of a ring. -/ lemma of : perfection_map p (perfection.coeff R p 0) := mk' (ring_equiv.refl _) $ (equiv.apply_eq_iff_eq_symm_apply _).2 rfl /-- For a perfect ring, it itself is the perfection. -/ lemma id [perfect_ring R p] : perfection_map p (ring_hom.id R) := { injective := λ x y hxy, hxy 0, surjective := λ f hf, ⟨f 0, λ n, show pth_root R p ^[n] (f 0) = f n, from nat.rec_on n rfl $ λ n ih, injective_pow_p p $ by rw [function.iterate_succ_apply', pth_root_pow_p _, ih, hf]⟩ } variables {p R P} /-- A perfection map induces an isomorphism to the prefection. -/ noncomputable def equiv {π : P →+* R} (m : perfection_map p π) : P ≃+* ring.perfection R p := ring_equiv.of_bijective (perfection.lift p P R π) ⟨λ x y hxy, m.injective $ λ n, (congr_arg (perfection.coeff R p n) hxy : _), λ f, let ⟨x, hx⟩ := m.surjective f.1 f.2 in ⟨x, perfection.ext $ hx⟩⟩ lemma equiv_apply {π : P →+* R} (m : perfection_map p π) (x : P) : m.equiv x = perfection.lift p P R π x := rfl lemma comp_equiv {π : P →+* R} (m : perfection_map p π) (x : P) : perfection.coeff R p 0 (m.equiv x) = π x := rfl lemma comp_equiv' {π : P →+* R} (m : perfection_map p π) : (perfection.coeff R p 0).comp ↑m.equiv = π := ring_hom.ext $ λ x, rfl lemma comp_symm_equiv {π : P →+* R} (m : perfection_map p π) (f : ring.perfection R p) : π (m.equiv.symm f) = perfection.coeff R p 0 f := (m.comp_equiv _).symm.trans $ congr_arg _ $ m.equiv.apply_symm_apply f lemma comp_symm_equiv' {π : P →+* R} (m : perfection_map p π) : π.comp ↑m.equiv.symm = perfection.coeff R p 0 := ring_hom.ext m.comp_symm_equiv variables (p R P) /-- Given rings `R` and `S` of characteristic `p`, with `R` being perfect, any homomorphism `R →+* S` can be lifted to a homomorphism `R →+* P`, where `P` is any perfection of `S`. -/ @[simps] noncomputable def lift [perfect_ring R p] (S : Type u₂) [comm_semiring S] [char_p S p] (P : Type u₃) [comm_semiring P] [char_p P p] [perfect_ring P p] (π : P →+* S) (m : perfection_map p π) : (R →+* S) ≃ (R →+* P) := { to_fun := λ f, ring_hom.comp ↑m.equiv.symm $ perfection.lift p R S f, inv_fun := λ f, π.comp f, left_inv := λ f, by { simp_rw [← ring_hom.comp_assoc, comp_symm_equiv'], exact (perfection.lift p R S).symm_apply_apply f }, right_inv := λ f, ring_hom.ext $ λ x, m.equiv.injective $ (m.equiv.apply_symm_apply _).trans $ show perfection.lift p R S (π.comp f) x = ring_hom.comp ↑m.equiv f x, from ring_hom.ext_iff.1 ((perfection.lift p R S).apply_eq_iff_eq_symm_apply.2 rfl) _ } variables {R p} lemma hom_ext [perfect_ring R p] {S : Type u₂} [comm_semiring S] [char_p S p] {P : Type u₃} [comm_semiring P] [char_p P p] [perfect_ring P p] (π : P →+* S) (m : perfection_map p π) {f g : R →+* P} (hfg : ∀ x, π (f x) = π (g x)) : f = g := (lift p R S P π m).symm.injective $ ring_hom.ext hfg variables {R P} (p) {S : Type u₂} [comm_semiring S] [char_p S p] variables {Q : Type u₄} [comm_semiring Q] [char_p Q p] [perfect_ring Q p] /-- A ring homomorphism `R →+* S` induces `P →+* Q`, a map of the respective perfections. -/ @[nolint unused_arguments] noncomputable def map {π : P →+* R} (m : perfection_map p π) {σ : Q →+* S} (n : perfection_map p σ) (φ : R →+* S) : P →+* Q := lift p P S Q σ n $ φ.comp π lemma comp_map {π : P →+* R} (m : perfection_map p π) {σ : Q →+* S} (n : perfection_map p σ) (φ : R →+* S) : σ.comp (map p m n φ) = φ.comp π := (lift p P S Q σ n).symm_apply_apply _ lemma map_map {π : P →+* R} (m : perfection_map p π) {σ : Q →+* S} (n : perfection_map p σ) (φ : R →+* S) (x : P) : σ (map p m n φ x) = φ (π x) := ring_hom.ext_iff.1 (comp_map p m n φ) x -- Why is this slow? lemma map_eq_map (φ : R →+* S) : @map p _ R _ _ _ _ _ _ S _ _ _ _ _ _ _ (of p R) _ (of p S) φ = perfection.map p φ := hom_ext _ (of p S) $ λ f, by rw [map_map, perfection.coeff_map] end perfection_map section perfectoid variables (K : Type u₁) [field K] (v : valuation K ℝ≥0) variables (O : Type u₂) [comm_ring O] [algebra O K] (hv : v.integers O) variables (p : ℕ) include hv /-- `O/(p)` for `O`, ring of integers of `K`. -/ @[nolint unused_arguments has_inhabited_instance] def mod_p := O ⧸ (ideal.span {p} : ideal O) variables [hp : fact p.prime] [hvp : fact (v p ≠ 1)] namespace mod_p instance : comm_ring (mod_p K v O hv p) := ideal.quotient.comm_ring _ include hp hvp instance : char_p (mod_p K v O hv p) p := char_p.quotient O p $ mt hv.one_of_is_unit $ (map_nat_cast (algebra_map O K) p).symm ▸ hvp.1 instance : nontrivial (mod_p K v O hv p) := char_p.nontrivial_of_char_ne_one hp.1.ne_one section classical local attribute [instance] classical.dec omit hp hvp /-- For a field `K` with valuation `v : K → ℝ≥0` and ring of integers `O`, a function `O/(p) → ℝ≥0` that sends `0` to `0` and `x + (p)` to `v(x)` as long as `x ∉ (p)`. -/ noncomputable def pre_val (x : mod_p K v O hv p) : ℝ≥0 := if x = 0 then 0 else v (algebra_map O K x.out') variables {K v O hv p} lemma pre_val_mk {x : O} (hx : (ideal.quotient.mk _ x : mod_p K v O hv p) ≠ 0) : pre_val K v O hv p (ideal.quotient.mk _ x) = v (algebra_map O K x) := begin obtain ⟨r, hr⟩ := ideal.mem_span_singleton'.1 (ideal.quotient.eq.1 $ quotient.sound' $ @quotient.mk_out' O (ideal.span {p} : ideal O).quotient_rel x), refine (if_neg hx).trans (v.map_eq_of_sub_lt $ lt_of_not_le _), erw [← ring_hom.map_sub, ← hr, hv.le_iff_dvd], exact λ hprx, hx (ideal.quotient.eq_zero_iff_mem.2 $ ideal.mem_span_singleton.2 $ dvd_of_mul_left_dvd hprx), end lemma pre_val_zero : pre_val K v O hv p 0 = 0 := if_pos rfl lemma pre_val_mul {x y : mod_p K v O hv p} (hxy0 : x * y ≠ 0) : pre_val K v O hv p (x * y) = pre_val K v O hv p x * pre_val K v O hv p y := begin have hx0 : x ≠ 0 := mt (by { rintro rfl, rw zero_mul }) hxy0, have hy0 : y ≠ 0 := mt (by { rintro rfl, rw mul_zero }) hxy0, obtain ⟨r, rfl⟩ := ideal.quotient.mk_surjective x, obtain ⟨s, rfl⟩ := ideal.quotient.mk_surjective y, rw ← ring_hom.map_mul at hxy0 ⊢, rw [pre_val_mk hx0, pre_val_mk hy0, pre_val_mk hxy0, ring_hom.map_mul, v.map_mul] end lemma pre_val_add (x y : mod_p K v O hv p) : pre_val K v O hv p (x + y) ≤ max (pre_val K v O hv p x) (pre_val K v O hv p y) := begin by_cases hx0 : x = 0, { rw [hx0, zero_add], exact le_max_right _ _ }, by_cases hy0 : y = 0, { rw [hy0, add_zero], exact le_max_left _ _ }, by_cases hxy0 : x + y = 0, { rw [hxy0, pre_val_zero], exact zero_le _ }, obtain ⟨r, rfl⟩ := ideal.quotient.mk_surjective x, obtain ⟨s, rfl⟩ := ideal.quotient.mk_surjective y, rw ← ring_hom.map_add at hxy0 ⊢, rw [pre_val_mk hx0, pre_val_mk hy0, pre_val_mk hxy0, ring_hom.map_add], exact v.map_add _ _ end lemma v_p_lt_pre_val {x : mod_p K v O hv p} : v p < pre_val K v O hv p x ↔ x ≠ 0 := begin refine ⟨λ h hx, by { rw [hx, pre_val_zero] at h, exact not_lt_zero' h }, λ h, lt_of_not_le $ λ hp, h _⟩, obtain ⟨r, rfl⟩ := ideal.quotient.mk_surjective x, rw [pre_val_mk h, ← map_nat_cast (algebra_map O K) p, hv.le_iff_dvd] at hp, rw [ideal.quotient.eq_zero_iff_mem, ideal.mem_span_singleton], exact hp end lemma pre_val_eq_zero {x : mod_p K v O hv p} : pre_val K v O hv p x = 0 ↔ x = 0 := ⟨λ hvx, classical.by_contradiction $ λ hx0 : x ≠ 0, by { rw [← v_p_lt_pre_val, hvx] at hx0, exact not_lt_zero' hx0 }, λ hx, hx.symm ▸ pre_val_zero⟩ variables (hv hvp) lemma v_p_lt_val {x : O} : v p < v (algebra_map O K x) ↔ (ideal.quotient.mk _ x : mod_p K v O hv p) ≠ 0 := by rw [lt_iff_not_le, not_iff_not, ← map_nat_cast (algebra_map O K) p, hv.le_iff_dvd, ideal.quotient.eq_zero_iff_mem, ideal.mem_span_singleton] open nnreal variables {hv} [hvp] include hp lemma mul_ne_zero_of_pow_p_ne_zero {x y : mod_p K v O hv p} (hx : x ^ p ≠ 0) (hy : y ^ p ≠ 0) : x * y ≠ 0 := begin obtain ⟨r, rfl⟩ := ideal.quotient.mk_surjective x, obtain ⟨s, rfl⟩ := ideal.quotient.mk_surjective y, have h1p : (0 : ℝ) < 1 / p := one_div_pos.2 (nat.cast_pos.2 hp.1.pos), rw ← ring_hom.map_mul, rw ← ring_hom.map_pow at hx hy, rw ← v_p_lt_val hv at hx hy ⊢, rw [ring_hom.map_pow, v.map_pow, ← rpow_lt_rpow_iff h1p, ← rpow_nat_cast, ← rpow_mul, mul_one_div_cancel (nat.cast_ne_zero.2 hp.1.ne_zero : (p : ℝ) ≠ 0), rpow_one] at hx hy, rw [ring_hom.map_mul, v.map_mul], refine lt_of_le_of_lt _ (mul_lt_mul₀ hx hy), by_cases hvp : v p = 0, { rw hvp, exact zero_le _ }, replace hvp := zero_lt_iff.2 hvp, conv_lhs { rw ← rpow_one (v p) }, rw ← rpow_add (ne_of_gt hvp), refine rpow_le_rpow_of_exponent_ge hvp (map_nat_cast (algebra_map O K) p ▸ hv.2 _) _, rw [← add_div, div_le_one (nat.cast_pos.2 hp.1.pos : 0 < (p : ℝ))], exact_mod_cast hp.1.two_le end end classical end mod_p /-- Perfection of `O/(p)` where `O` is the ring of integers of `K`. -/ @[nolint has_inhabited_instance] def pre_tilt := ring.perfection (mod_p K v O hv p) p include hp hvp namespace pre_tilt instance : comm_ring (pre_tilt K v O hv p) := perfection.comm_ring p _ instance : char_p (pre_tilt K v O hv p) p := perfection.char_p (mod_p K v O hv p) p section classical open_locale classical open perfection /-- The valuation `Perfection(O/(p)) → ℝ≥0` as a function. Given `f ∈ Perfection(O/(p))`, if `f = 0` then output `0`; otherwise output `pre_val(f(n))^(p^n)` for any `n` such that `f(n) ≠ 0`. -/ noncomputable def val_aux (f : pre_tilt K v O hv p) : ℝ≥0 := if h : ∃ n, coeff _ _ n f ≠ 0 then mod_p.pre_val K v O hv p (coeff _ _ (nat.find h) f) ^ (p ^ nat.find h) else 0 variables {K v O hv p} lemma coeff_nat_find_add_ne_zero {f : pre_tilt K v O hv p} {h : ∃ n, coeff _ _ n f ≠ 0} (k : ℕ) : coeff _ _ (nat.find h + k) f ≠ 0 := coeff_add_ne_zero (nat.find_spec h) k lemma val_aux_eq {f : pre_tilt K v O hv p} {n : ℕ} (hfn : coeff _ _ n f ≠ 0) : val_aux K v O hv p f = mod_p.pre_val K v O hv p (coeff _ _ n f) ^ (p ^ n) := begin have h : ∃ n, coeff _ _ n f ≠ 0 := ⟨n, hfn⟩, rw [val_aux, dif_pos h], obtain ⟨k, rfl⟩ := nat.exists_eq_add_of_le (nat.find_min' h hfn), induction k with k ih, { refl }, obtain ⟨x, hx⟩ := ideal.quotient.mk_surjective (coeff _ _ (nat.find h + k + 1) f), have h1 : (ideal.quotient.mk _ x : mod_p K v O hv p) ≠ 0 := hx.symm ▸ hfn, have h2 : (ideal.quotient.mk _ (x ^ p) : mod_p K v O hv p) ≠ 0, by { erw [ring_hom.map_pow, hx, ← ring_hom.map_pow, coeff_pow_p], exact coeff_nat_find_add_ne_zero k }, erw [ih (coeff_nat_find_add_ne_zero k), ← hx, ← coeff_pow_p, ring_hom.map_pow, ← hx, ← ring_hom.map_pow, mod_p.pre_val_mk h1, mod_p.pre_val_mk h2, ring_hom.map_pow, v.map_pow, ← pow_mul, pow_succ], refl end lemma val_aux_zero : val_aux K v O hv p 0 = 0 := dif_neg $ λ ⟨n, hn⟩, hn rfl lemma val_aux_one : val_aux K v O hv p 1 = 1 := (val_aux_eq $ show coeff (mod_p K v O hv p) p 0 1 ≠ 0, from one_ne_zero).trans $ by { rw [pow_zero, pow_one, ring_hom.map_one, ← (ideal.quotient.mk _).map_one, mod_p.pre_val_mk, ring_hom.map_one, v.map_one], exact @one_ne_zero (mod_p K v O hv p) _ _ } lemma val_aux_mul (f g : pre_tilt K v O hv p) : val_aux K v O hv p (f * g) = val_aux K v O hv p f * val_aux K v O hv p g := begin by_cases hf : f = 0, { rw [hf, zero_mul, val_aux_zero, zero_mul] }, by_cases hg : g = 0, { rw [hg, mul_zero, val_aux_zero, mul_zero] }, obtain ⟨m, hm⟩ : ∃ n, coeff _ _ n f ≠ 0 := not_forall.1 (λ h, hf $ perfection.ext h), obtain ⟨n, hn⟩ : ∃ n, coeff _ _ n g ≠ 0 := not_forall.1 (λ h, hg $ perfection.ext h), replace hm := coeff_ne_zero_of_le hm (le_max_left m n), replace hn := coeff_ne_zero_of_le hn (le_max_right m n), have hfg : coeff _ _ (max m n + 1) (f * g) ≠ 0, { rw ring_hom.map_mul, refine mod_p.mul_ne_zero_of_pow_p_ne_zero _ _, { rw [← ring_hom.map_pow, coeff_pow_p f], assumption }, { rw [← ring_hom.map_pow, coeff_pow_p g], assumption } }, rw [val_aux_eq (coeff_add_ne_zero hm 1), val_aux_eq (coeff_add_ne_zero hn 1), val_aux_eq hfg], rw ring_hom.map_mul at hfg ⊢, rw [mod_p.pre_val_mul hfg, mul_pow] end lemma val_aux_add (f g : pre_tilt K v O hv p) : val_aux K v O hv p (f + g) ≤ max (val_aux K v O hv p f) (val_aux K v O hv p g) := begin by_cases hf : f = 0, { rw [hf, zero_add, val_aux_zero, max_eq_right], exact zero_le _ }, by_cases hg : g = 0, { rw [hg, add_zero, val_aux_zero, max_eq_left], exact zero_le _ }, by_cases hfg : f + g = 0, { rw [hfg, val_aux_zero], exact zero_le _ }, replace hf : ∃ n, coeff _ _ n f ≠ 0 := not_forall.1 (λ h, hf $ perfection.ext h), replace hg : ∃ n, coeff _ _ n g ≠ 0 := not_forall.1 (λ h, hg $ perfection.ext h), replace hfg : ∃ n, coeff _ _ n (f + g) ≠ 0 := not_forall.1 (λ h, hfg $ perfection.ext h), obtain ⟨m, hm⟩ := hf, obtain ⟨n, hn⟩ := hg, obtain ⟨k, hk⟩ := hfg, replace hm := coeff_ne_zero_of_le hm (le_trans (le_max_left m n) (le_max_left _ k)), replace hn := coeff_ne_zero_of_le hn (le_trans (le_max_right m n) (le_max_left _ k)), replace hk := coeff_ne_zero_of_le hk (le_max_right (max m n) k), rw [val_aux_eq hm, val_aux_eq hn, val_aux_eq hk, ring_hom.map_add], cases le_max_iff.1 (mod_p.pre_val_add (coeff _ _ (max (max m n) k) f) (coeff _ _ (max (max m n) k) g)) with h h, { exact le_max_of_le_left (pow_le_pow_of_le_left' h _) }, { exact le_max_of_le_right (pow_le_pow_of_le_left' h _) } end variables (K v O hv p) /-- The valuation `Perfection(O/(p)) → ℝ≥0`. Given `f ∈ Perfection(O/(p))`, if `f = 0` then output `0`; otherwise output `pre_val(f(n))^(p^n)` for any `n` such that `f(n) ≠ 0`. -/ noncomputable def val : valuation (pre_tilt K v O hv p) ℝ≥0 := { to_fun := val_aux K v O hv p, map_one' := val_aux_one, map_mul' := val_aux_mul, map_zero' := val_aux_zero, map_add_le_max' := val_aux_add } variables {K v O hv p} lemma map_eq_zero {f : pre_tilt K v O hv p} : val K v O hv p f = 0 ↔ f = 0 := begin by_cases hf0 : f = 0, { rw hf0, exact iff_of_true (valuation.map_zero _) rfl }, obtain ⟨n, hn⟩ : ∃ n, coeff _ _ n f ≠ 0 := not_forall.1 (λ h, hf0 $ perfection.ext h), show val_aux K v O hv p f = 0 ↔ f = 0, refine iff_of_false (λ hvf, hn _) hf0, rw val_aux_eq hn at hvf, replace hvf := pow_eq_zero hvf, rwa mod_p.pre_val_eq_zero at hvf end end classical instance : is_domain (pre_tilt K v O hv p) := { exists_pair_ne := (char_p.nontrivial_of_char_ne_one hp.1.ne_one).1, eq_zero_or_eq_zero_of_mul_eq_zero := λ f g hfg, by { simp_rw ← map_eq_zero at hfg ⊢, contrapose! hfg, rw valuation.map_mul, exact mul_ne_zero hfg.1 hfg.2 }, .. (infer_instance : comm_ring (pre_tilt K v O hv p)) } end pre_tilt /-- The tilt of a field, as defined in Perfectoid Spaces by Peter Scholze, as in [scholze2011perfectoid]. Given a field `K` with valuation `K → ℝ≥0` and ring of integers `O`, this is implemented as the fraction field of the perfection of `O/(p)`. -/ @[nolint has_inhabited_instance] def tilt := fraction_ring (pre_tilt K v O hv p) namespace tilt noncomputable instance : field (tilt K v O hv p) := fraction_ring.field end tilt end perfectoid
9d29f368f3496df0a8fd85208e44a50c6bd000ac
3f7026ea8bef0825ca0339a275c03b911baef64d
/src/category_theory/pempty.lean
4866002e44c05a213f8aa5863bbc3365406227c4
[ "Apache-2.0" ]
permissive
rspencer01/mathlib
b1e3afa5c121362ef0881012cc116513ab09f18c
c7d36292c6b9234dc40143c16288932ae38fdc12
refs/heads/master
1,595,010,346,708
1,567,511,503,000
1,567,511,503,000
206,071,681
0
0
Apache-2.0
1,567,513,643,000
1,567,513,643,000
null
UTF-8
Lean
false
false
1,044
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.discrete_category import category_theory.equivalence /-! # The empty category Defines a category structure on `pempty`, and the unique functor `pempty ⥤ C` for any category `C`. -/ universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation namespace category_theory /-- The empty category -/ instance pempty_category : small_category pempty := { hom := λ X Y, pempty, id := by obviously, comp := by obviously } namespace functor variables (C : Type u) [𝒞 : category.{v} C] include 𝒞 /-- The unique functor from the empty category to any target category. -/ def empty : pempty ⥤ C := by tidy end functor /-- The category `pempty` is equivalent to the category `discrete pempty`. -/ instance pempty_equiv_discrete_pempty : is_equivalence (functor.empty (discrete pempty)) := by obviously end category_theory
6266b1e3a558057e957be339f8da33b4a346d8f6
94e33a31faa76775069b071adea97e86e218a8ee
/src/data/nat/pow.lean
f7b3ff1ca9c3f8f7f16e6e9f9e0855470531ec47
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
11,344
lean
/- Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import algebra.group_power.order /-! # `nat.pow` Results on the power operation on natural numbers. -/ namespace nat /-! ### `pow` -/ -- This is redundant with `pow_le_pow_of_le_left'`, -- We leave a version in the `nat` namespace as well. -- (The global `pow_le_pow_of_le_left` needs an extra hypothesis `0 ≤ x`.) protected theorem pow_le_pow_of_le_left {x y : ℕ} (H : x ≤ y) : ∀ i : ℕ, x^i ≤ y^i := pow_le_pow_of_le_left' H theorem pow_le_pow_of_le_right {x : ℕ} (H : 0 < x) {i j : ℕ} (h : i ≤ j) : x ^ i ≤ x ^ j := pow_le_pow' H h theorem pow_lt_pow_of_lt_left {x y : ℕ} (H : x < y) {i} (h : 0 < i) : x^i < y^i := pow_lt_pow_of_lt_left H (zero_le _) h theorem pow_lt_pow_of_lt_right {x : ℕ} (H : 1 < x) {i j : ℕ} (h : i < j) : x^i < x^j := pow_lt_pow H h lemma pow_lt_pow_succ {p : ℕ} (h : 1 < p) (n : ℕ) : p^n < p^(n+1) := pow_lt_pow_of_lt_right h n.lt_succ_self lemma lt_pow_self {p : ℕ} (h : 1 < p) : ∀ n : ℕ, n < p ^ n | 0 := by simp [zero_lt_one] | (n+1) := calc n + 1 < p^n + 1 : nat.add_lt_add_right (lt_pow_self _) _ ... ≤ p ^ (n+1) : pow_lt_pow_succ h _ lemma lt_two_pow (n : ℕ) : n < 2^n := lt_pow_self dec_trivial n lemma one_le_pow (n m : ℕ) (h : 0 < m) : 1 ≤ m^n := by { rw ←one_pow n, exact nat.pow_le_pow_of_le_left h n } lemma one_le_pow' (n m : ℕ) : 1 ≤ (m+1)^n := one_le_pow n (m+1) (succ_pos m) lemma one_le_two_pow (n : ℕ) : 1 ≤ 2^n := one_le_pow n 2 dec_trivial lemma one_lt_pow (n m : ℕ) (h₀ : 0 < n) (h₁ : 1 < m) : 1 < m^n := by { rw ←one_pow n, exact pow_lt_pow_of_lt_left h₁ h₀ } lemma one_lt_pow' (n m : ℕ) : 1 < (m+2)^(n+1) := one_lt_pow (n+1) (m+2) (succ_pos n) (nat.lt_of_sub_eq_succ rfl) @[simp] lemma one_lt_pow_iff {k n : ℕ} (h : 0 ≠ k) : 1 < n ^ k ↔ 1 < n := begin cases n, { cases k; simp [zero_pow_eq] }, cases n, { rw one_pow }, refine ⟨λ _, one_lt_succ_succ n, λ _, _⟩, induction k with k hk, { exact absurd rfl h }, cases k, { simp }, exact one_lt_mul (one_lt_succ_succ _).le (hk (succ_ne_zero k).symm), end lemma one_lt_two_pow (n : ℕ) (h₀ : 0 < n) : 1 < 2^n := one_lt_pow n 2 h₀ dec_trivial lemma one_lt_two_pow' (n : ℕ) : 1 < 2^(n+1) := one_lt_pow (n+1) 2 (succ_pos n) dec_trivial lemma pow_right_strict_mono {x : ℕ} (k : 2 ≤ x) : strict_mono (λ (n : ℕ), x^n) := λ _ _, pow_lt_pow_of_lt_right k lemma pow_le_iff_le_right {x m n : ℕ} (k : 2 ≤ x) : x^m ≤ x^n ↔ m ≤ n := strict_mono.le_iff_le (pow_right_strict_mono k) lemma pow_lt_iff_lt_right {x m n : ℕ} (k : 2 ≤ x) : x^m < x^n ↔ m < n := strict_mono.lt_iff_lt (pow_right_strict_mono k) lemma pow_right_injective {x : ℕ} (k : 2 ≤ x) : function.injective (λ (n : ℕ), x^n) := strict_mono.injective (pow_right_strict_mono k) lemma pow_left_strict_mono {m : ℕ} (k : 1 ≤ m) : strict_mono (λ (x : ℕ), x^m) := λ _ _ h, pow_lt_pow_of_lt_left h k lemma mul_lt_mul_pow_succ {n a q : ℕ} (a0 : 0 < a) (q1 : 1 < q) : n * q < a * q ^ (n + 1) := begin rw [pow_succ', ← mul_assoc, mul_lt_mul_right (zero_lt_one.trans q1)], exact lt_mul_of_one_le_of_lt (nat.succ_le_iff.mpr a0) (nat.lt_pow_self q1 n), end end nat lemma strict_mono.nat_pow {n : ℕ} (hn : 1 ≤ n) {f : ℕ → ℕ} (hf : strict_mono f) : strict_mono (λ m, (f m) ^ n) := (nat.pow_left_strict_mono hn).comp hf namespace nat lemma pow_le_iff_le_left {m x y : ℕ} (k : 1 ≤ m) : x^m ≤ y^m ↔ x ≤ y := strict_mono.le_iff_le (pow_left_strict_mono k) lemma pow_lt_iff_lt_left {m x y : ℕ} (k : 1 ≤ m) : x^m < y^m ↔ x < y := strict_mono.lt_iff_lt (pow_left_strict_mono k) lemma pow_left_injective {m : ℕ} (k : 1 ≤ m) : function.injective (λ (x : ℕ), x^m) := strict_mono.injective (pow_left_strict_mono k) theorem sq_sub_sq (a b : ℕ) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := by { rw [sq, sq], exact nat.mul_self_sub_mul_self_eq a b } alias sq_sub_sq ← pow_two_sub_pow_two /-! ### `pow` and `mod` / `dvd` -/ theorem pow_mod (a b n : ℕ) : a ^ b % n = (a % n) ^ b % n := begin induction b with b ih, refl, simp [pow_succ, nat.mul_mod, ih], end theorem mod_pow_succ {b : ℕ} (w m : ℕ) : m % (b^succ w) = b * (m/b % b^w) + m % b := begin by_cases b_h : b = 0, { simp [b_h, pow_succ], }, have b_pos := nat.pos_of_ne_zero b_h, apply nat.strong_induction_on m, clear m, intros p IH, cases lt_or_ge p (b^succ w) with h₁ h₁, -- base case: p < b^succ w { have h₂ : p / b < b^w, { rw [div_lt_iff_lt_mul b_pos], simpa [pow_succ'] using h₁ }, rw [mod_eq_of_lt h₁, mod_eq_of_lt h₂], simp [div_add_mod] }, -- step: p ≥ b^succ w { -- Generate condition for induction hypothesis have h₂ : p - b^succ w < p, { exact tsub_lt_self ((pow_pos b_pos _).trans_le h₁) (pow_pos b_pos _) }, -- Apply induction rw [mod_eq_sub_mod h₁, IH _ h₂], -- Normalize goal and h1 simp only [pow_succ], simp only [ge, pow_succ] at h₁, -- Pull subtraction outside mod and div rw [sub_mul_mod _ _ _ h₁, sub_mul_div _ _ _ h₁], -- Cancel subtraction inside mod b^w have p_b_ge : b^w ≤ p / b, { rw [le_div_iff_mul_le b_pos, mul_comm], exact h₁ }, rw [eq.symm (mod_eq_sub_mod p_b_ge)] } end lemma pow_dvd_pow_iff_pow_le_pow {k l : ℕ} : Π {x : ℕ} (w : 0 < x), x^k ∣ x^l ↔ x^k ≤ x^l | (x+1) w := begin split, { intro a, exact le_of_dvd (pow_pos (succ_pos x) l) a, }, { intro a, cases x with x, { simp only [one_pow], }, { have le := (pow_le_iff_le_right (nat.le_add_left _ _)).mp a, use (x+2)^(l-k), rw [←pow_add, add_comm k, tsub_add_cancel_of_le le], } } end /-- If `1 < x`, then `x^k` divides `x^l` if and only if `k` is at most `l`. -/ lemma pow_dvd_pow_iff_le_right {x k l : ℕ} (w : 1 < x) : x^k ∣ x^l ↔ k ≤ l := by rw [pow_dvd_pow_iff_pow_le_pow (lt_of_succ_lt w), pow_le_iff_le_right w] lemma pow_dvd_pow_iff_le_right' {b k l : ℕ} : (b+2)^k ∣ (b+2)^l ↔ k ≤ l := pow_dvd_pow_iff_le_right (nat.lt_of_sub_eq_succ rfl) lemma not_pos_pow_dvd : ∀ {p k : ℕ} (hp : 1 < p) (hk : 1 < k), ¬ p^k ∣ p | (succ p) (succ k) hp hk h := have succ p * (succ p)^k ∣ succ p * 1, by simpa [pow_succ] using h, have (succ p) ^ k ∣ 1, from dvd_of_mul_dvd_mul_left (succ_pos _) this, have he : (succ p) ^ k = 1, from eq_one_of_dvd_one this, have k < (succ p) ^ k, from lt_pow_self hp k, have k < 1, by rwa [he] at this, have k = 0, from nat.eq_zero_of_le_zero $ le_of_lt_succ this, have 1 < 1, by rwa [this] at hk, absurd this dec_trivial lemma pow_dvd_of_le_of_pow_dvd {p m n k : ℕ} (hmn : m ≤ n) (hdiv : p ^ n ∣ k) : p ^ m ∣ k := (pow_dvd_pow _ hmn).trans hdiv lemma dvd_of_pow_dvd {p k m : ℕ} (hk : 1 ≤ k) (hpk : p^k ∣ m) : p ∣ m := by rw ←pow_one p; exact pow_dvd_of_le_of_pow_dvd hk hpk lemma pow_div {x m n : ℕ} (h : n ≤ m) (hx : 0 < x) : x ^ m / x ^ n = x ^ (m - n) := by rw [nat.div_eq_iff_eq_mul_left (pow_pos hx n) (pow_dvd_pow _ h), pow_sub_mul_pow _ h] /-! ### `shiftl` and `shiftr` -/ lemma shiftl_eq_mul_pow (m) : ∀ n, shiftl m n = m * 2 ^ n | 0 := (nat.mul_one _).symm | (k+1) := show bit0 (shiftl m k) = m * (2 * 2 ^ k), by rw [bit0_val, shiftl_eq_mul_pow, mul_left_comm, mul_comm 2] lemma shiftl'_tt_eq_mul_pow (m) : ∀ n, shiftl' tt m n + 1 = (m + 1) * 2 ^ n | 0 := by simp [shiftl, shiftl', pow_zero, nat.one_mul] | (k+1) := begin change bit1 (shiftl' tt m k) + 1 = (m + 1) * (2 * 2 ^ k), rw bit1_val, change 2 * (shiftl' tt m k + 1) = _, rw [shiftl'_tt_eq_mul_pow, mul_left_comm, mul_comm 2], end lemma one_shiftl (n) : shiftl 1 n = 2 ^ n := (shiftl_eq_mul_pow _ _).trans (nat.one_mul _) @[simp] lemma zero_shiftl (n) : shiftl 0 n = 0 := (shiftl_eq_mul_pow _ _).trans (nat.zero_mul _) lemma shiftr_eq_div_pow (m) : ∀ n, shiftr m n = m / 2 ^ n | 0 := (nat.div_one _).symm | (k+1) := (congr_arg div2 (shiftr_eq_div_pow k)).trans $ by rw [div2_val, nat.div_div_eq_div_mul, mul_comm]; refl @[simp] lemma zero_shiftr (n) : shiftr 0 n = 0 := (shiftr_eq_div_pow _ _).trans (nat.zero_div _) theorem shiftl'_ne_zero_left (b) {m} (h : m ≠ 0) (n) : shiftl' b m n ≠ 0 := by induction n; simp [shiftl', bit_ne_zero, *] theorem shiftl'_tt_ne_zero (m) : ∀ {n} (h : n ≠ 0), shiftl' tt m n ≠ 0 | 0 h := absurd rfl h | (succ n) _ := nat.bit1_ne_zero _ /-! ### `size` -/ @[simp] theorem size_zero : size 0 = 0 := by simp [size] @[simp] theorem size_bit {b n} (h : bit b n ≠ 0) : size (bit b n) = succ (size n) := begin rw size, conv { to_lhs, rw [binary_rec], simp [h] }, rw div2_bit, end @[simp] theorem size_bit0 {n} (h : n ≠ 0) : size (bit0 n) = succ (size n) := @size_bit ff n (nat.bit0_ne_zero h) @[simp] theorem size_bit1 (n) : size (bit1 n) = succ (size n) := @size_bit tt n (nat.bit1_ne_zero n) @[simp] theorem size_one : size 1 = 1 := show size (bit1 0) = 1, by rw [size_bit1, size_zero] @[simp] theorem size_shiftl' {b m n} (h : shiftl' b m n ≠ 0) : size (shiftl' b m n) = size m + n := begin induction n with n IH; simp [shiftl'] at h ⊢, rw [size_bit h, nat.add_succ], by_cases s0 : shiftl' b m n = 0; [skip, rw [IH s0]], rw s0 at h ⊢, cases b, {exact absurd rfl h}, have : shiftl' tt m n + 1 = 1 := congr_arg (+1) s0, rw [shiftl'_tt_eq_mul_pow] at this, obtain rfl := succ.inj (eq_one_of_dvd_one ⟨_, this.symm⟩), rw one_mul at this, obtain rfl : n = 0 := nat.eq_zero_of_le_zero (le_of_not_gt $ λ hn, ne_of_gt (pow_lt_pow_of_lt_right dec_trivial hn) this), refl end @[simp] theorem size_shiftl {m} (h : m ≠ 0) (n) : size (shiftl m n) = size m + n := size_shiftl' (shiftl'_ne_zero_left _ h _) theorem lt_size_self (n : ℕ) : n < 2^size n := begin rw [← one_shiftl], have : ∀ {n}, n = 0 → n < shiftl 1 (size n), { simp }, apply binary_rec _ _ n, {apply this rfl}, intros b n IH, by_cases bit b n = 0, {apply this h}, rw [size_bit h, shiftl_succ], exact bit_lt_bit0 _ IH end theorem size_le {m n : ℕ} : size m ≤ n ↔ m < 2^n := ⟨λ h, lt_of_lt_of_le (lt_size_self _) (pow_le_pow_of_le_right dec_trivial h), begin rw [← one_shiftl], revert n, apply binary_rec _ _ m, { intros n h, simp }, { intros b m IH n h, by_cases e : bit b m = 0, { simp [e] }, rw [size_bit e], cases n with n, { exact e.elim (nat.eq_zero_of_le_zero (le_of_lt_succ h)) }, { apply succ_le_succ (IH _), apply lt_imp_lt_of_le_imp_le (λ h', bit0_le_bit _ h') h } } end⟩ theorem lt_size {m n : ℕ} : m < size n ↔ 2^m ≤ n := by rw [← not_lt, decidable.iff_not_comm, not_lt, size_le] theorem size_pos {n : ℕ} : 0 < size n ↔ 0 < n := by rw lt_size; refl theorem size_eq_zero {n : ℕ} : size n = 0 ↔ n = 0 := by have := @size_pos n; simp [pos_iff_ne_zero] at this; exact decidable.not_iff_not.1 this theorem size_pow {n : ℕ} : size (2^n) = n+1 := le_antisymm (size_le.2 $ pow_lt_pow_of_lt_right dec_trivial (lt_succ_self _)) (lt_size.2 $ le_rfl) theorem size_le_size {m n : ℕ} (h : m ≤ n) : size m ≤ size n := size_le.2 $ lt_of_le_of_lt h (lt_size_self _) end nat
4a0354a1e37cfd40a0464e2ec606256a6bc4e4bf
ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5
/stage0/src/Lean/CoreM.lean
e2a3f6b2552f9f6efbf80ea432f5e8ff6539edfe
[ "Apache-2.0" ]
permissive
dupuisf/lean4
d082d13b01243e1de29ae680eefb476961221eef
6a39c65bd28eb0e28c3870188f348c8914502718
refs/heads/master
1,676,948,755,391
1,610,665,114,000
1,610,665,114,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
4,375
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Util.RecDepth import Lean.Util.Trace import Lean.Environment import Lean.Exception import Lean.InternalExceptionId import Lean.Eval import Lean.MonadEnv import Lean.ResolveName namespace Lean namespace Core structure State where env : Environment nextMacroScope : MacroScope := firstFrontendMacroScope + 1 ngen : NameGenerator := {} traceState : TraceState := {} deriving Inhabited structure Context where options : Options := {} currRecDepth : Nat := 0 maxRecDepth : Nat := 1000 ref : Syntax := Syntax.missing currNamespace : Name := Name.anonymous openDecls : List OpenDecl := [] abbrev CoreM := ReaderT Context $ StateRefT State (EIO Exception) instance : Inhabited (CoreM α) where default := fun _ _ => throw arbitrary instance : MonadRef CoreM where getRef := return (← read).ref withRef ref x := withReader (fun ctx => { ctx with ref := ref }) x instance : MonadEnv CoreM where getEnv := return (← get).env modifyEnv f := modify fun s => { s with env := f s.env } instance : MonadOptions CoreM where getOptions := return (← read).options instance : AddMessageContext CoreM where addMessageContext := addMessageContextPartial instance : MonadNameGenerator CoreM where getNGen := return (← get).ngen setNGen ngen := modify fun s => { s with ngen := ngen } instance : MonadRecDepth CoreM where withRecDepth d x := withReader (fun ctx => { ctx with currRecDepth := d }) x getRecDepth := return (← read).currRecDepth getMaxRecDepth := return (← read).maxRecDepth instance : MonadResolveName CoreM where getCurrNamespace := return (← read).currNamespace getOpenDecls := return (← read).openDecls @[inline] def liftIOCore (x : IO α) : CoreM α := do let ref ← getRef IO.toEIO (fun (err : IO.Error) => Exception.error ref (toString err)) x instance : MonadLift IO CoreM where monadLift := liftIOCore instance : MonadTrace CoreM where getTraceState := return (← get).traceState modifyTraceState f := modify fun s => { s with traceState := f s.traceState } private def mkFreshNameImp (n : Name) : CoreM Name := do let fresh ← modifyGet fun s => (s.nextMacroScope, { s with nextMacroScope := s.nextMacroScope + 1 }) let env ← getEnv pure $ addMacroScope env.mainModule n fresh def mkFreshUserName [MonadLiftT CoreM m] (n : Name) : m Name := liftM $ mkFreshNameImp n @[inline] def CoreM.run (x : CoreM α) (ctx : Context) (s : State) : EIO Exception (α × State) := (x ctx).run s @[inline] def CoreM.run' (x : CoreM α) (ctx : Context) (s : State) : EIO Exception α := Prod.fst <$> x.run ctx s @[inline] def CoreM.toIO (x : CoreM α) (ctx : Context) (s : State) : IO (α × State) := do match (← (x.run ctx s).toIO') with | Except.error (Exception.error _ msg) => do let e ← msg.toString; throw $ IO.userError e | Except.error (Exception.internal id _) => throw $ IO.userError $ "internal exception #" ++ toString id.idx | Except.ok a => pure a instance [MetaEval α] : MetaEval (CoreM α) where eval env opts x _ := do let x : CoreM α := do try x finally printTraces let (a, s) ← x.toIO { maxRecDepth := getMaxRecDepth opts, options := opts } { env := env } MetaEval.eval s.env opts a (hideUnit := true) -- withIncRecDepth for a monad `m` such that `[MonadControlT CoreM n]` protected def withIncRecDepth [Monad m] [MonadControlT CoreM m] (x : m α) : m α := controlAt CoreM fun runInBase => withIncRecDepth (runInBase x) end Core export Core (CoreM mkFreshUserName) @[inline] def catchInternalId [Monad m] [MonadExcept Exception m] (id : InternalExceptionId) (x : m α) (h : Exception → m α) : m α := do try x catch ex => match ex with | Exception.error _ _ => throw ex | Exception.internal id' _ => if id == id' then h ex else throw ex @[inline] def catchInternalIds [Monad m] [MonadExcept Exception m] (ids : List InternalExceptionId) (x : m α) (h : Exception → m α) : m α := do try x catch ex => match ex with | Exception.error _ _ => throw ex | Exception.internal id _ => if ids.contains id then h ex else throw ex end Lean
bcafbad784958cc8f22b73a59ef925a750781eea
5749d8999a76f3a8fddceca1f6941981e33aaa96
/src/geometry/manifold/manifold.lean
844c6557bef8ef2b8b1b85d14837df187968c57f
[ "Apache-2.0" ]
permissive
jdsalchow/mathlib
13ab43ef0d0515a17e550b16d09bd14b76125276
497e692b946d93906900bb33a51fd243e7649406
refs/heads/master
1,585,819,143,348
1,580,072,892,000
1,580,072,892,000
154,287,128
0
0
Apache-2.0
1,540,281,610,000
1,540,281,609,000
null
UTF-8
Lean
false
false
26,482
lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import topology.local_homeomorph /-! # Manifolds A manifold is a topological space M locally modelled on a model space H, i.e., the manifold is covered by open subsets on which there are local homeomorphisms (the charts) going to H. If the changes of charts satisfy some additional property (for instance if they are smooth), then M inherits additional structure (it makes sense to talk about smooth manifolds). There are therefore two different ingredients in a manifold: * the set of charts, which is data * the fact that changes of charts belong to some group (in fact groupoid), which is additional Prop. We separate these two parts in the definition: the manifold structure is just the set of charts, and then the different smoothness requirements (smooth manifold, orientable manifold, contact manifold, and so on) are additional properties of these charts. These properties are formalized through the notion of structure groupoid, i.e., a set of local homeomorphisms stable under composition and inverse, to which the change of coordinates should belong. ## Main definitions * `structure_groupoid H` : a subset of local homeomorphisms of `H` stable under composition, inverse and restriction (ex: local diffeos) * `pregroupoid H` : a subset of local homeomorphisms of `H` stable under composition and restriction, but not inverse (ex: smooth maps) * `groupoid_of_pregroupoid`: construct a groupoid from a pregroupoid, by requiring that a map and its inverse both belong to the pregroupoid (ex: construct diffeos from smooth maps) * `continuous_groupoid H` : the groupoid of all local homeomorphisms of `H` * `manifold H M` : manifold structure on `M` modelled on `H`, given by an atlas of local homeomorphisms from `M` to `H` whose sources cover `M`. This is a type class. * `has_groupoid M G` : when `G` is a structure groupoid on `H` and `M` is a manifold modelled on `H`, require that all coordinate changes belong to `G`. This is a type class * `atlas H M` : when `M` is a manifold modelled on `H`, the atlas of this manifold structure, i.e., the set of charts * `structomorph G M M'` : the set of diffeomorphisms between the manifolds `M` and `M'` for the groupoid `G`. We avoid the word diffeomorphisms, keeping it for the smooth category. As a basic example, we give the instance `instance manifold_model_space (H : Type*) [topological_space H] : manifold H H` saying that a topological space is a manifold over itself, with the identity as unique chart. This manifold structure is compatible with any groupoid. ## Implementation notes The atlas in a manifold is *not* a maximal atlas in general: the notion of maximality depends on the groupoid one considers, and changing groupoids changes the maximal atlas. With the current formalization, it makes sense first to choose the atlas, and then to ask whether this precise atlas defines a smooth manifold, an orientable manifold, and so on. A consequence is that structomorphisms between M and M' do *not* induce a bijection between the atlases of M and M': the definition is only that, read in charts, the structomorphism locally belongs to the groupoid under consideration. (This is equivalent to inducing a bijection between elements of the maximal atlas). A consequence is that the invariance under structomorphisms of properties defined in terms of the atlas is not obvious in general, and could require some work in theory (amounting to the fact that these properties only depend on the maximal atlas, for instance). In practice, this does not create any real difficulty. We use the letter `H` for the model space thinking of the case of manifolds with boundary, where the model space is a half space. Manifolds are sometimes defined as topological spaces with an atlas of local diffeomorphisms, and sometimes as spaces with an atlas from which a topology is deduced. We use the former approach: otherwise, there would be an instance from manifolds to topological spaces, which means that any instance search for topological spaces would try to find manifold structures involving a yet unknown model space, leading to problems. However, we also introduce the latter approach, through a structure `manifold_core` making it possible to construct a topology out of a set of local equivs with compatibility conditions (but we do not register it as an instance). In the definition of a manifold, the model space is written as an explicit parameter as there can be several model spaces for a given topological space. For instance, a complex manifold (modelled over ℂ^n) will also be seen sometimes as a real manifold modelled over ℝ^(2n). -/ noncomputable theory local attribute [instance, priority 0] classical.decidable_inhabited classical.prop_decidable universes u variables {H : Type u} {M : Type*} {M' : Type*} {M'' : Type*} /- Notational shortcut for the composition of local homeomorphisms, i.e., `local_homeomorph.trans`. Note that, as is usual for equivs, the composition is from left to right, hence the direction of the arrow. -/ local infixr ` ≫ₕ `:100 := local_homeomorph.trans open set local_homeomorph section groupoid /- One could add to the definition of a structure groupoid the fact that the restriction of an element of the groupoid to any open set still belongs to the groupoid. (This is in Kobayashi-Nomizu.) I am not sure I want this, for instance on H × E where E is a vector space, and the groupoid is made of functions respecting the fibers and linear in the fibers (so that a manifold over this groupoid is naturally a vector bundle) I prefer that the members of the groupoid are always defined on sets of the form s × E The only nontrivial requirement is locality: if a local homeomorphism belongs to the groupoid around each point in its domain of definition, then it belongs to the groupoid. Without this requirement, the composition of diffeomorphisms does not have to be a diffeomorphism. Note that this implies that a local homeomorphism with empty source belongs to any structure groupoid, as it trivially satisfies this condition. There is also a technical point, related to the fact that a local homeomorphism is by definition a global map which is a homeomorphism when restricted to its source subset (and its values outside of the source are not relevant). Therefore, we also require that being a member of the groupoid only depends on the values on the source. -/ /-- A structure groupoid is a set of local homeomorphisms of a topological space stable under composition and inverse. They appear in the definition of the smoothness class of a manifold. -/ structure structure_groupoid (H : Type u) [topological_space H] := (members : set (local_homeomorph H H)) (comp : ∀e e' : local_homeomorph H H, e ∈ members → e' ∈ members → e ≫ₕ e' ∈ members) (inv : ∀e : local_homeomorph H H, e ∈ members → e.symm ∈ members) (id_mem : local_homeomorph.refl H ∈ members) (locality : ∀e : local_homeomorph H H, (∀x ∈ e.source, ∃s, is_open s ∧ x ∈ s ∧ e.restr s ∈ members) → e ∈ members) (eq_on_source : ∀ e e' : local_homeomorph H H, e ∈ members → e' ≈ e → e' ∈ members) variable [topological_space H] @[reducible] instance : has_mem (local_homeomorph H H) (structure_groupoid H) := ⟨λ(e : local_homeomorph H H) (G : structure_groupoid H), e ∈ G.members⟩ /-- Partial order on the set of groupoids, given by inclusion of the members of the groupoid -/ instance structure_groupoid.partial_order : partial_order (structure_groupoid H) := partial_order.lift structure_groupoid.members (λa b h, by { cases a, cases b, dsimp at h, induction h, refl }) (by apply_instance) /-- The trivial groupoid, containing only the identity (and maps with empty source, as this is necessary from the definition) -/ def id_groupoid (H : Type u) [topological_space H] : structure_groupoid H := { members := {local_homeomorph.refl H} ∪ {e : local_homeomorph H H | e.source = ∅}, comp := λe e' he he', begin cases he; simp at he he', { simpa [he] }, { have : (e ≫ₕ e').source ⊆ e.source := sep_subset _ _, rw he at this, have : (e ≫ₕ e') ∈ {e : local_homeomorph H H | e.source = ∅} := disjoint_iff.1 this, exact (mem_union _ _ _).2 (or.inr this) }, end, inv := λe he, begin cases (mem_union _ _ _).1 he with E E, { finish }, { right, simpa [e.to_local_equiv.image_source_eq_target.symm] using E }, end, id_mem := mem_union_left _ (mem_insert _ ∅), locality := λe he, begin by_cases h : e.source = ∅, { right, exact h }, { left, rcases ne_empty_iff_exists_mem.1 h with ⟨x, hx⟩, rcases he x hx with ⟨s, open_s, xs, hs⟩, have x's : x ∈ (e.restr s).source, { rw [restr_source, interior_eq_of_open open_s], exact ⟨hx, xs⟩ }, cases hs, { replace hs : local_homeomorph.restr e s = local_homeomorph.refl H, by simpa using hs, have : (e.restr s).source = univ, by { rw hs, simp }, change (e.to_local_equiv).source ∩ interior s = univ at this, have : univ ⊆ interior s, by { rw ← this, exact inter_subset_right _ _ }, have : s = univ, by rwa [interior_eq_of_open open_s, univ_subset_iff] at this, simpa [this, restr_univ] using hs }, { exfalso, rw mem_set_of_eq at hs, rwa hs at x's } }, end, eq_on_source := λe e' he he'e, begin cases he, { left, have : e = e', { refine eq_of_eq_on_source_univ (setoid.symm he'e) _ _; rw set.mem_singleton_iff.1 he ; refl }, rwa ← this }, { right, change (e.to_local_equiv).source = ∅ at he, rwa [set.mem_set_of_eq, source_eq_of_eq_on_source he'e] } end } /-- Every structure groupoid contains the identity groupoid -/ instance : lattice.order_bot (structure_groupoid H) := { bot := id_groupoid H, bot_le := begin assume u f hf, change f ∈ {local_homeomorph.refl H} ∪ {e : local_homeomorph H H | e.source = ∅} at hf, simp only [singleton_union, mem_set_of_eq, mem_insert_iff] at hf, cases hf, { rw hf, apply u.id_mem }, { apply u.locality, assume x hx, rw [hf, mem_empty_eq] at hx, exact hx.elim } end, ..structure_groupoid.partial_order } /-- To construct a groupoid, one may consider classes of local homeos such that both the function and its inverse have some property. If this property is stable under composition, one gets a groupoid. `pregroupoid` bundles the properties needed for this construction, with the groupoid of smooth functions with smooth inverses as an application. -/ structure pregroupoid (H : Type*) [topological_space H] := (property : (H → H) → (set H) → Prop) (comp : ∀{f g u v}, property f u → property g v → is_open (u ∩ f ⁻¹' v) → property (g ∘ f) (u ∩ f ⁻¹' v)) (id_mem : property id univ) (locality : ∀{f u}, is_open u → (∀x∈u, ∃v, is_open v ∧ x ∈ v ∧ property f (u ∩ v)) → property f u) (congr : ∀{f g : H → H} {u}, is_open u → (∀x∈u, g x = f x) → property f u → property g u) /-- Construct a groupoid of local homeos for which the map and its inverse have some property, from a pregroupoid asserting that this property is stable under composition. -/ def pregroupoid.groupoid (PG : pregroupoid H) : structure_groupoid H := { members := {e : local_homeomorph H H | PG.property e.to_fun e.source ∧ PG.property e.inv_fun e.target}, comp := λe e' he he', begin split, { apply PG.comp he.1 he'.1, apply e.continuous_to_fun.preimage_open_of_open e.open_source e'.open_source }, { apply PG.comp he'.2 he.2, apply e'.continuous_inv_fun.preimage_open_of_open e'.open_target e.open_target } end, inv := λe he, ⟨he.2, he.1⟩, id_mem := ⟨PG.id_mem, PG.id_mem⟩, locality := λe he, begin split, { apply PG.locality e.open_source (λx xu, _), rcases he x xu with ⟨s, s_open, xs, hs⟩, refine ⟨s, s_open, xs, _⟩, convert hs.1, exact (interior_eq_of_open s_open).symm }, { apply PG.locality e.open_target (λx xu, _), rcases he (e.inv_fun x) (e.map_target xu) with ⟨s, s_open, xs, hs⟩, refine ⟨e.target ∩ e.inv_fun ⁻¹' s, _, ⟨xu, xs⟩, _⟩, { exact continuous_on.preimage_open_of_open e.continuous_inv_fun e.open_target s_open }, { rw [← inter_assoc, inter_self], convert hs.2, exact (interior_eq_of_open s_open).symm } }, end, eq_on_source := λe e' he ee', begin split, { apply PG.congr e'.open_source ee'.2, simp only [ee'.1, he.1] }, { have A := eq_on_source_symm ee', apply PG.congr e'.symm.open_source A.2, convert he.2, rw A.1, refl } end } lemma mem_groupoid_of_pregroupoid (PG : pregroupoid H) (e : local_homeomorph H H) : e ∈ PG.groupoid ↔ PG.property e.to_fun e.source ∧ PG.property e.inv_fun e.target := iff.rfl lemma groupoid_of_pregroupoid_le (PG₁ PG₂ : pregroupoid H) (h : ∀f s, PG₁.property f s → PG₂.property f s) : PG₁.groupoid ≤ PG₂.groupoid := begin assume e he, rw mem_groupoid_of_pregroupoid at he ⊢, exact ⟨h _ _ he.1, h _ _ he.2⟩ end lemma mem_pregroupoid_of_eq_on_source (PG : pregroupoid H) {e e' : local_homeomorph H H} (he' : e ≈ e') (he : PG.property e.to_fun e.source) : PG.property e'.to_fun e'.source := begin rw ← he'.1, exact PG.congr e.open_source (λx hx, (he'.2 x hx).symm) he, end /-- The groupoid of all local homeomorphisms on a topological space H -/ def continuous_groupoid (H : Type*) [topological_space H] : structure_groupoid H := pregroupoid.groupoid { property := λf s, true, comp := λf g u v hf hg huv, trivial, id_mem := trivial, locality := λf u u_open h, trivial, congr := λf g u u_open hcongr hf, trivial } /-- Every structure groupoid is contained in the groupoid of all local homeomorphisms -/ instance : lattice.order_top (structure_groupoid H) := { top := continuous_groupoid H, le_top := λ u f hf, by { split; exact dec_trivial }, ..structure_groupoid.partial_order } end groupoid /-- A manifold is a topological space endowed with an atlas, i.e., a set of local homeomorphisms taking value in a model space H, called charts, such that the domains of the charts cover the whole space. We express the covering property by chosing for each x a member `chart_at x` of the atlas containing x in its source: in the smooth case, this is convenient to construct the tangent bundle in an efficient way. The model space is written as an explicit parameter as there can be several model spaces for a given topological space. For instance, a complex manifold (modelled over ℂ^n) will also be seen sometimes as a real manifold over ℝ^(2n). -/ class manifold (H : Type*) [topological_space H] (M : Type*) [topological_space M] := (atlas : set (local_homeomorph M H)) (chart_at : M → local_homeomorph M H) (mem_chart_source : ∀x, x ∈ (chart_at x).source) (chart_mem_atlas : ∀x, chart_at x ∈ atlas) export manifold attribute [simp] mem_chart_source chart_mem_atlas section manifold /-- Any space is a manifold modelled over itself, by just using the identity chart -/ instance manifold_model_space (H : Type*) [topological_space H] : manifold H H := { atlas := {local_homeomorph.refl H}, chart_at := λx, local_homeomorph.refl H, mem_chart_source := λx, mem_univ x, chart_mem_atlas := λx, mem_singleton _ } /-- In the trivial manifold structure of a space modelled over itself through the identity, the atlas members are just the identity -/ @[simp] lemma model_space_atlas {H : Type*} [topological_space H] {e : local_homeomorph H H} : e ∈ atlas H H ↔ e = local_homeomorph.refl H := by simp [atlas, manifold.atlas] /-- In the model space, chart_at is always the identity -/ @[simp] lemma chart_at_model_space_eq {H : Type*} [topological_space H] {x : H} : chart_at H x = local_homeomorph.refl H := by simpa using chart_mem_atlas H x end manifold /-- Sometimes, one may want to construct a manifold structure on a space which does not yet have a topological structure, where the topology would come from the charts. For this, one needs charts that are only local equivs, and continuity properties for their composition. This is formalised in `manifold_core`. -/ structure manifold_core (H : Type*) [topological_space H] (M : Type*) := (atlas : set (local_equiv M H)) (chart_at : M → local_equiv M H) (mem_chart_source : ∀x, x ∈ (chart_at x).source) (chart_mem_atlas : ∀x, chart_at x ∈ atlas) (open_source : ∀e e' : local_equiv M H, e ∈ atlas → e' ∈ atlas → is_open (e.symm.trans e').source) (continuous_to_fun : ∀e e' : local_equiv M H, e ∈ atlas → e' ∈ atlas → continuous_on (e.symm.trans e').to_fun (e.symm.trans e').source) namespace manifold_core variables [topological_space H] (c : manifold_core H M) {e : local_equiv M H} /-- Topology generated by a set of charts on a Type. -/ protected def to_topological_space : topological_space M := topological_space.generate_from $ ⋃ (e : local_equiv M H) (he : e ∈ c.atlas) (s : set H) (s_open : is_open s), {e.to_fun ⁻¹' s ∩ e.source} lemma open_source' (he : e ∈ c.atlas) : @is_open M c.to_topological_space e.source := begin apply topological_space.generate_open.basic, simp only [exists_prop, mem_Union, mem_singleton_iff], refine ⟨e, he, univ, is_open_univ, _⟩, simp only [set.univ_inter, set.preimage_univ] end lemma open_target (he : e ∈ c.atlas) : is_open e.target := begin have E : e.target ∩ e.inv_fun ⁻¹' e.source = e.target := subset.antisymm (inter_subset_left _ _) (λx hx, ⟨hx, local_equiv.target_subset_preimage_source _ hx⟩), simpa [local_equiv.trans_source, E] using c.open_source e e he he end def local_homeomorph (e : local_equiv M H) (he : e ∈ c.atlas) : @local_homeomorph M H c.to_topological_space _ := { open_source := by convert c.open_source' he, open_target := by convert c.open_target he, continuous_to_fun := begin letI : topological_space M := c.to_topological_space, rw continuous_on_open_iff (c.open_source' he), assume s s_open, rw inter_comm, apply topological_space.generate_open.basic, simp only [exists_prop, mem_Union, mem_singleton_iff], exact ⟨e, he, ⟨s, s_open, rfl⟩⟩ end, continuous_inv_fun := begin letI : topological_space M := c.to_topological_space, apply continuous_on_open_of_generate_from (c.open_target he), assume t ht, simp only [exists_prop, mem_Union, mem_singleton_iff] at ht, rcases ht with ⟨e', e'_atlas, s, s_open, ts⟩, rw ts, let f := e.symm.trans e', have : is_open (f.to_fun ⁻¹' s ∩ f.source), by simpa [inter_comm] using (continuous_on_open_iff (c.open_source e e' he e'_atlas)).1 (c.continuous_to_fun e e' he e'_atlas) s s_open, have A : e'.to_fun ∘ e.inv_fun ⁻¹' s ∩ (e.target ∩ e.inv_fun ⁻¹' e'.source) = e.target ∩ (e'.to_fun ∘ e.inv_fun ⁻¹' s ∩ e.inv_fun ⁻¹' e'.source), by { rw [← inter_assoc, ← inter_assoc], congr' 1, exact inter_comm _ _ }, simpa [local_equiv.trans_source, preimage_inter, preimage_comp.symm, A] using this end, ..e } def to_manifold : @manifold H _ M c.to_topological_space := { atlas := ⋃ (e : local_equiv M H) (he : e ∈ c.atlas), {c.local_homeomorph e he}, chart_at := λx, c.local_homeomorph (c.chart_at x) (c.chart_mem_atlas x), mem_chart_source := λx, c.mem_chart_source x, chart_mem_atlas := λx, begin simp only [mem_Union, mem_singleton_iff], exact ⟨c.chart_at x, c.chart_mem_atlas x, rfl⟩, end } end manifold_core section has_groupoid variables [topological_space H] [topological_space M] [manifold H M] /-- A manifold has an atlas in a groupoid G if the change of coordinates belong to the groupoid -/ class has_groupoid {H : Type*} [topological_space H] (M : Type*) [topological_space M] [manifold H M] (G : structure_groupoid H) : Prop := (compatible : ∀{e e' : local_homeomorph M H}, e ∈ atlas H M → e' ∈ atlas H M → e.symm ≫ₕ e' ∈ G) lemma has_groupoid_of_le {G₁ G₂ : structure_groupoid H} (h : has_groupoid M G₁) (hle : G₁ ≤ G₂) : has_groupoid M G₂ := ⟨ λ e e' he he', hle ((h.compatible : _) he he') ⟩ lemma has_groupoid_of_pregroupoid (PG : pregroupoid H) (h : ∀{e e' : local_homeomorph M H}, e ∈ atlas H M → e' ∈ atlas H M → PG.property (e.symm ≫ₕ e').to_fun (e.symm ≫ₕ e').source) : has_groupoid M (PG.groupoid) := ⟨assume e e' he he', (mem_groupoid_of_pregroupoid PG _).mpr ⟨h he he', h he' he⟩⟩ /-- The trivial manifold structure on the model space is compatible with any groupoid -/ instance has_groupoid_model_space (H : Type*) [topological_space H] (G : structure_groupoid H) : has_groupoid H G := { compatible := λe e' he he', begin replace he : e ∈ atlas H H := he, replace he' : e' ∈ atlas H H := he', rw model_space_atlas at he he', simp [he, he', structure_groupoid.id_mem] end } /-- Any manifold structure is compatible with the groupoid of all local homeomorphisms -/ instance has_groupoid_continuous_groupoid : has_groupoid M (continuous_groupoid H) := ⟨begin assume e e' he he', rw [continuous_groupoid, mem_groupoid_of_pregroupoid], simp only [and_self] end⟩ /-- A G-diffeomorphism between two manifolds is a homeomorphism which, when read in the charts, belongs to G. We avoid the word diffeomorph as it is too related to the smooth category, and use structomorph instead. -/ structure structomorph (G : structure_groupoid H) (M : Type*) (M' : Type*) [topological_space M] [topological_space M'] [manifold H M] [manifold H M'] extends homeomorph M M' := (to_fun_mem_groupoid : ∀c : local_homeomorph M H, ∀c' : local_homeomorph M' H, c ∈ atlas H M → c' ∈ atlas H M' → c.symm ≫ₕ to_homeomorph.to_local_homeomorph ≫ₕ c' ∈ G) variables [topological_space M'] [topological_space M''] {G : structure_groupoid H} [manifold H M'] [manifold H M''] /-- The identity is a diffeomorphism of any manifold, for any groupoid. -/ def structomorph.refl (M : Type*) [topological_space M] [manifold H M] [has_groupoid M G] : structomorph G M M := { to_fun_mem_groupoid := λc c' hc hc', begin change (local_homeomorph.symm c) ≫ₕ (local_homeomorph.refl M) ≫ₕ c' ∈ G, rw local_homeomorph.refl_trans, exact has_groupoid.compatible G hc hc' end, ..homeomorph.refl M } /-- The inverse of a structomorphism is a structomorphism -/ def structomorph.symm (e : structomorph G M M') : structomorph G M' M := { to_fun_mem_groupoid := begin assume c c' hc hc', have : (c'.symm ≫ₕ e.to_homeomorph.to_local_homeomorph ≫ₕ c).symm ∈ G := G.inv _ (e.to_fun_mem_groupoid c' c hc' hc), simp at this, rwa [trans_symm_eq_symm_trans_symm, trans_symm_eq_symm_trans_symm, symm_symm, trans_assoc] at this, end, ..e.to_homeomorph.symm} /-- The composition of structomorphisms is a structomorphism -/ def structomorph.trans (e : structomorph G M M') (e' : structomorph G M' M'') : structomorph G M M'' := { to_fun_mem_groupoid := begin /- Let c and c' be two charts in M and M''. We want to show that e' ∘ e is smooth in these charts, around any point x. For this, let y = e (c⁻¹ x), and consider a chart g around y. Then g ∘ e ∘ c⁻¹ and c' ∘ e' ∘ g⁻¹ are both smooth as e and e' are structomorphisms, so their composition is smooth, and it coincides with c' ∘ e' ∘ e ∘ c⁻¹ around x. -/ assume c c' hc hc', refine G.locality _ (λx hx, _), let f₁ := e.to_homeomorph.to_local_homeomorph, let f₂ := e'.to_homeomorph.to_local_homeomorph, let f := (e.to_homeomorph.trans e'.to_homeomorph).to_local_homeomorph, have feq : f = f₁ ≫ₕ f₂ := homeomorph.trans_to_local_homeomorph _ _, -- define the atlas g around y let y := (c.symm ≫ₕ f₁).to_fun x, let g := chart_at H y, have hg₁ := chart_mem_atlas H y, have hg₂ := mem_chart_source H y, let s := (c.symm ≫ₕ f₁).source ∩ (c.symm ≫ₕ f₁).to_fun ⁻¹' g.source, have open_s : is_open s, by apply (c.symm ≫ₕ f₁).continuous_to_fun.preimage_open_of_open; apply open_source, have : x ∈ s, { split, { simp only [trans_source, preimage_univ, inter_univ, homeomorph.to_local_homeomorph_source], rw trans_source at hx, exact hx.1 }, { exact hg₂ } }, refine ⟨s, open_s, ⟨this, _⟩⟩, let F₁ := (c.symm ≫ₕ f₁ ≫ₕ g) ≫ₕ (g.symm ≫ₕ f₂ ≫ₕ c'), have A : F₁ ∈ G := G.comp _ _ (e.to_fun_mem_groupoid c g hc hg₁) (e'.to_fun_mem_groupoid g c' hg₁ hc'), let F₂ := (c.symm ≫ₕ f ≫ₕ c').restr s, have : F₁ ≈ F₂ := calc F₁ ≈ c.symm ≫ₕ f₁ ≫ₕ (g ≫ₕ g.symm) ≫ₕ f₂ ≫ₕ c' : by simp [F₁, trans_assoc] ... ≈ c.symm ≫ₕ f₁ ≫ₕ (of_set g.source g.open_source) ≫ₕ f₂ ≫ₕ c' : by simp [eq_on_source_trans, trans_self_symm g] ... ≈ ((c.symm ≫ₕ f₁) ≫ₕ (of_set g.source g.open_source)) ≫ₕ (f₂ ≫ₕ c') : by simp [trans_assoc] ... ≈ ((c.symm ≫ₕ f₁).restr s) ≫ₕ (f₂ ≫ₕ c') : by simp [s, trans_of_set'] ... ≈ ((c.symm ≫ₕ f₁) ≫ₕ (f₂ ≫ₕ c')).restr s : by simp [restr_trans] ... ≈ (c.symm ≫ₕ (f₁ ≫ₕ f₂) ≫ₕ c').restr s : by simp [eq_on_source_restr, trans_assoc] ... ≈ F₂ : by simp [F₂, feq], have : F₂ ∈ G := G.eq_on_source F₁ F₂ A (setoid.symm this), exact this end, ..homeomorph.trans e.to_homeomorph e'.to_homeomorph } end has_groupoid
ed39cc688e7913a09243b3495254748f56d5cc86
33340b3a23ca62ef3c8a7f6a2d4e14c07c6d3354
/lia/wf_sqe.lean
1f0481ad0c9872ed574d32ae6e4de24754c9aef7
[]
no_license
lclem/cooper
79554e72ced343c64fed24b2d892d24bf9447dfe
812afc6b158821f2e7dac9c91d3b6123c7a19faf
refs/heads/master
1,607,554,257,488
1,578,694,133,000
1,578,694,133,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
5,380
lean
import .sqe .wf open list lemma atom.unify_dvd (m d i k ks) : k ≠ 0 → atom.unify m (atom.dvd d i (k::ks)) = (let m' := has_div.div m k in atom.dvd (m' * d) (m' * i) (1 :: list.map (λ x, m' * x) ks)) := begin intro hne, cases k, exfalso, apply hne, repeat {refl} end lemma atom.unify_ndvd (m d i k ks) : k ≠ 0 → atom.unify m (atom.ndvd d i (k::ks)) = (let m' := has_div.div m k in atom.ndvd (m' * d) (m' * i) (1 :: list.map (λ x, m' * x) ks)) := begin intro hne, cases k, exfalso, apply hne, repeat {refl} end lemma wf_inf_minus : ∀ {p : formula}, formula.wf p → formula.wf (inf_minus p) | ⊤' h := by trivial | ⊥' h := by trivial | (A' a) h := begin cases a; try {trivial}, cases a_a_1 with z zs, simp [inf_minus], rw inf_minus_le_eq, apply ite.rec; intro h, trivial, apply ite.rec; intro h; trivial end | (p ∧' q) h := begin cases h with h1 h2, apply cases_and_o; try {trivial}; try {apply wf_inf_minus, assumption}, constructor; {apply wf_inf_minus, assumption} end | (p ∨' q) h := begin cases h with h1 h2, apply cases_or_o; try {trivial}; try {apply wf_inf_minus, assumption}, constructor; {apply wf_inf_minus, assumption} end | (¬' p) h := by assumption | (∃' p) h := by assumption lemma wf_asubst : ∀ a : atom, atom.wf a → ∀ i ks, atom.wf (asubst i ks a) := begin intro a, cases a with i ks d i ks d i ks; intros h i' ks'; cases ks with k ks; trivial end lemma wf_subst (i ks) : ∀ p, formula.wf p → formula.wf (subst i ks p) | ⊤' h := by unfold subst | ⊥' h := by unfold subst | (A' a) h := begin unfold subst, unfold formula.map, unfold formula.wf, apply wf_asubst _ h end | (p ∧' q) h := begin cases h with hp hq, apply and.intro; apply wf_subst; assumption end | (p ∨' q) h := begin cases h with hp hq, apply and.intro; apply wf_subst; assumption end | (¬' p) h := wf_subst p h | (∃' p) h := by unfold subst lemma atom.wf_unify (z : znum) (hne : z ≠ 0) : ∀ (a : atom), atom.wf a → (head_coeff a ∣ z ∨ head_coeff a = 0) → atom.wf (atom.unify z a) | (atom.le i ks) ha1 ha2 := begin cases ks with k ks, trivial, cases k with m m; trivial end | (atom.dvd d i ks) ha1 ha2 := begin cases ks with k ks, trivial, cases (classical.em (k = 0)) with hk hk, subst hk, trivial, cases ha2 with ha2 ha2, rewrite atom.unify_dvd, simp, apply znum.mul_nonzero, unfold head_coeff at ha2, apply znum.div_nonzero, apply hne, apply ha2, apply ha1, apply hk, exfalso, apply hk ha2 end | (atom.ndvd d i ks) ha1 ha2 := begin cases ks with k ks, trivial, cases (classical.em (k = 0)) with hk hk, subst hk, trivial, cases ha2 with ha2 ha2, rewrite atom.unify_ndvd, simp, apply znum.mul_nonzero, unfold head_coeff at ha2, apply znum.div_nonzero, apply hne, apply ha2, apply ha1, apply hk, exfalso, apply hk ha2 end meta def formula.wf_map_hco_of_formula.wf_tac := `[unfold formula.map, unfold formula.wf, cases hn with hnp hnq, unfold formula.atoms at hnz, rewrite list.forall_mem_append at hnz, cases hnz with hnzp hnzq, apply and.intro; apply formula.wf_map_hco_of_formula.wf; assumption] lemma formula.wf_map_hco_of_formula.wf {z : znum} (hz : z ≠ 0) : ∀ {p : formula}, (formula.wf p) → (∀ a ∈ p.atoms, has_dvd.dvd (head_coeff a) z ∨ head_coeff a = 0) → formula.wf (p.map (atom.unify z)) | ⊤' hn hnz := by unfold formula.map | ⊥' hn hnz := by unfold formula.map | (A' a) hn hnz := begin unfold formula.map, unfold formula.wf, unfold formula.wf at hn, apply atom.wf_unify z hz _ hn, apply hnz, unfold formula.atoms, simp, end | (p ∧' q) hn hnz := by formula.wf_map_hco_of_formula.wf_tac | (p ∨' q) hn hnz := by formula.wf_map_hco_of_formula.wf_tac | (¬' p) hp hpz := begin unfold formula.map, unfold formula.wf, apply @formula.wf_map_hco_of_formula.wf p hp hpz, end | (∃' p) hn hnz := by unfold formula.map lemma formula.wf_hcso : ∀ {φ : formula}, formula.wf φ → formula.wf (φ.unify) := begin intros p hp, unfold formula.unify, unfold formula.wf, have hne : znum.lcms (list.map head_coeff (p.atoms_dep_0)) ≠ 0, { apply znum.nonzero_of_pos, apply znum.lcms_pos, apply @forall_mem_map _ _ head_coeff (λ (z : znum), z ≠ 0), unfold formula.atoms_dep_0, intros a ha, apply list.of_mem_filter ha }, { apply and.intro, { intro hc, apply hne hc }, { apply formula.wf_map_hco_of_formula.wf hne hp, intros a ha, apply or_of_not_imp_right, intro haz, apply znum.dvd_lcms, rewrite list.mem_map, existsi a, apply and.intro, unfold formula.atoms_dep_0, apply list.mem_filter_of_mem, apply ha, apply haz, refl } } end lemma wf_sqe_core : ∀ {φ : formula}, formula.wf φ → formula.wf (sqe_core φ) := begin intros p hp, simp [sqe_core], apply wf_or_o, apply wf_disj, { apply forall_mem_map, intros z hz, apply wf_subst, apply wf_inf_minus, apply hp }, { apply wf_disj, apply forall_mem_map, intros zzs hzzs, apply wf_disj, apply forall_mem_map, intros z hz, apply wf_subst, apply hp } end lemma wf_sqe : ∀ (φ : formula), formula.wf φ → formula.wf (sqe φ) := begin intros p hp, apply wf_sqe_core, apply formula.wf_hcso hp end
bd57687399347b1f8e24ddbb405457b5299fc254
6d50885e7b3f72447a03f21d5268d6af87c0a404
/instructor-notes/quiz1.lean
6f178c08fdeb4fa458be82f4f121bce252e18078
[]
no_license
kevinsullivan/uva-cs-dm-s20-old
583c756cded281fcee7f1afc42cb3e08f89c2493
797672cb0ffae6a42a3518c9225d5807191fd113
refs/heads/master
1,607,500,914,982
1,578,752,991,000
1,578,752,991,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
355
lean
def s1 := "Hello, " def s2 := "Lean!" def s3 := "Hello, Lean!" theorem t1 : s1 ++ s2 = s3 := eq.refl "Hello, Lean!" theorem t2 : 4 * 4 = 16 := eq.refl 16 def square : ℕ → ℕ | n := n^2 theorem t3 : s1 ++ s2 = s3 ∧ square 5 = 25 := and.intro t1 (eq.refl 25) theorem t4 : (s1 ++ s2 = s3 ∧ square 5 = 25) → (square 5 = 25) := λ h, h.right
dd91d8639b958caf97e54f55fc753e2e20ffd2f1
22e97a5d648fc451e25a06c668dc03ac7ed7bc25
/src/algebra/associated.lean
b7a3b895ba74efed8a6ebf532a877ea7e8d64d29
[ "Apache-2.0" ]
permissive
keeferrowan/mathlib
f2818da875dbc7780830d09bd4c526b0764a4e50
aad2dfc40e8e6a7e258287a7c1580318e865817e
refs/heads/master
1,661,736,426,952
1,590,438,032,000
1,590,438,032,000
266,892,663
0
0
Apache-2.0
1,590,445,835,000
1,590,445,835,000
null
UTF-8
Lean
false
false
25,125
lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker -/ import data.multiset /-! # Associated, prime, and irreducible elements. -/ variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} @[simp] theorem is_unit_zero_iff [semiring α] : is_unit (0 : α) ↔ (0:α) = 1 := ⟨λ ⟨⟨_, a, (a0 : 0 * a = 1), _⟩, rfl⟩, by rwa zero_mul at a0, λ h, begin haveI := subsingleton_of_zero_eq_one _ h, refine ⟨⟨0, 0, _, _⟩, rfl⟩; apply subsingleton.elim end⟩ @[simp] theorem not_is_unit_zero [nonzero_comm_ring α] : ¬ is_unit (0 : α) := mt is_unit_zero_iff.1 zero_ne_one lemma is_unit_pow [monoid α] {a : α} (n : ℕ) : is_unit a → is_unit (a ^ n) := λ ⟨u, hu⟩, ⟨u ^ n, by simp *⟩ theorem is_unit_iff_dvd_one [comm_semiring α] {x : α} : is_unit x ↔ x ∣ 1 := ⟨by rintro ⟨u, rfl⟩; exact ⟨_, u.mul_inv.symm⟩, λ ⟨y, h⟩, ⟨⟨x, y, h.symm, by rw [h, mul_comm]⟩, rfl⟩⟩ theorem is_unit_iff_forall_dvd [comm_semiring α] {x : α} : is_unit x ↔ ∀ y, x ∣ y := is_unit_iff_dvd_one.trans ⟨λ h y, dvd.trans h (one_dvd _), λ h, h _⟩ theorem mul_dvd_of_is_unit_left [comm_semiring α] {x y z : α} (h : is_unit x) : x * y ∣ z ↔ y ∣ z := ⟨dvd_trans (dvd_mul_left _ _), dvd_trans $ by simpa using mul_dvd_mul_right (is_unit_iff_dvd_one.1 h) y⟩ theorem mul_dvd_of_is_unit_right [comm_semiring α] {x y z : α} (h : is_unit y) : x * y ∣ z ↔ x ∣ z := by rw [mul_comm, mul_dvd_of_is_unit_left h] @[simp] lemma unit_mul_dvd_iff [comm_semiring α] {a b : α} {u : units α} : (u : α) * a ∣ b ↔ a ∣ b := mul_dvd_of_is_unit_left (is_unit_unit _) lemma mul_unit_dvd_iff [comm_semiring α] {a b : α} {u : units α} : a * u ∣ b ↔ a ∣ b := units.coe_mul_dvd _ _ _ theorem is_unit_of_dvd_unit {α} [comm_semiring α] {x y : α} (xy : x ∣ y) (hu : is_unit y) : is_unit x := is_unit_iff_dvd_one.2 $ dvd_trans xy $ is_unit_iff_dvd_one.1 hu theorem is_unit_int {n : ℤ} : is_unit n ↔ n.nat_abs = 1 := ⟨λ ⟨u, hu⟩, (int.units_eq_one_or u).elim (by simp *) (by simp *), λ h, is_unit_iff_dvd_one.2 ⟨n, by rw [← int.nat_abs_mul_self, h]; refl⟩⟩ lemma is_unit_of_dvd_one [comm_semiring α] : ∀a ∣ 1, is_unit (a:α) | a ⟨b, eq⟩ := ⟨units.mk_of_mul_eq_one a b eq.symm, rfl⟩ lemma dvd_and_not_dvd_iff [integral_domain α] {x y : α} : x ∣ y ∧ ¬y ∣ x ↔ x ≠ 0 ∧ ∃ d : α, ¬ is_unit d ∧ y = x * d := ⟨λ ⟨⟨d, hd⟩, hyx⟩, ⟨λ hx0, by simpa [hx0] using hyx, ⟨d, mt is_unit_iff_dvd_one.1 (λ ⟨e, he⟩, hyx ⟨e, by rw [hd, mul_assoc, ← he, mul_one]⟩), hd⟩⟩, λ ⟨hx0, d, hdu, hdx⟩, ⟨⟨d, hdx⟩, λ ⟨e, he⟩, hdu (is_unit_of_dvd_one _ ⟨e, (domain.mul_right_inj hx0).1 $ by conv {to_lhs, rw [he, hdx]};simp [mul_assoc]⟩)⟩⟩ lemma pow_dvd_pow_iff [integral_domain α] {x : α} {n m : ℕ} (h0 : x ≠ 0) (h1 : ¬ is_unit x) : x ^ n ∣ x ^ m ↔ n ≤ m := begin split, { intro h, rw [← not_lt], intro hmn, apply h1, have : x * x ^ m ∣ 1 * x ^ m, { rw [← pow_succ, one_mul], exact dvd_trans (pow_dvd_pow _ (nat.succ_le_of_lt hmn)) h }, rwa [mul_dvd_mul_iff_right, ← is_unit_iff_dvd_one] at this, apply pow_ne_zero m h0 }, { apply pow_dvd_pow } end /-- prime element of a semiring -/ def prime [comm_semiring α] (p : α) : Prop := p ≠ 0 ∧ ¬ is_unit p ∧ (∀a b, p ∣ a * b → p ∣ a ∨ p ∣ b) namespace prime lemma ne_zero [comm_semiring α] {p : α} (hp : prime p) : p ≠ 0 := hp.1 lemma not_unit [comm_semiring α] {p : α} (hp : prime p) : ¬ is_unit p := hp.2.1 lemma div_or_div [comm_semiring α] {p : α} (hp : prime p) {a b : α} (h : p ∣ a * b) : p ∣ a ∨ p ∣ b := hp.2.2 a b h end prime @[simp] lemma not_prime_zero [comm_semiring α] : ¬ prime (0 : α) := λ h, h.ne_zero rfl @[simp] lemma not_prime_one [comm_semiring α] : ¬ prime (1 : α) := λ h, h.not_unit is_unit_one lemma exists_mem_multiset_dvd_of_prime [comm_semiring α] {s : multiset α} {p : α} (hp : prime p) : p ∣ s.prod → ∃a∈s, p ∣ a := multiset.induction_on s (assume h, (hp.not_unit $ is_unit_of_dvd_one _ h).elim) $ assume a s ih h, have p ∣ a * s.prod, by simpa using h, match hp.div_or_div this with | or.inl h := ⟨a, multiset.mem_cons_self a s, h⟩ | or.inr h := let ⟨a, has, h⟩ := ih h in ⟨a, multiset.mem_cons_of_mem has, h⟩ end /-- `irreducible p` states that `p` is non-unit and only factors into units. We explicitly avoid stating that `p` is non-zero, this would require a semiring. Assuming only a monoid allows us to reuse irreducible for associated elements. -/ @[class] def irreducible [monoid α] (p : α) : Prop := ¬ is_unit p ∧ ∀a b, p = a * b → is_unit a ∨ is_unit b namespace irreducible lemma not_unit [monoid α] {p : α} (hp : irreducible p) : ¬ is_unit p := hp.1 lemma is_unit_or_is_unit [monoid α] {p : α} (hp : irreducible p) {a b : α} (h : p = a * b) : is_unit a ∨ is_unit b := hp.2 a b h end irreducible @[simp] theorem not_irreducible_one [monoid α] : ¬ irreducible (1 : α) := by simp [irreducible] @[simp] theorem not_irreducible_zero [semiring α] : ¬ irreducible (0 : α) | ⟨hn0, h⟩ := have is_unit (0:α) ∨ is_unit (0:α), from h 0 0 ((mul_zero 0).symm), this.elim hn0 hn0 theorem irreducible.ne_zero [semiring α] : ∀ {p:α}, irreducible p → p ≠ 0 | _ hp rfl := not_irreducible_zero hp theorem of_irreducible_mul {α} [monoid α] {x y : α} : irreducible (x * y) → is_unit x ∨ is_unit y | ⟨_, h⟩ := h _ _ rfl theorem irreducible_or_factor {α} [monoid α] (x : α) (h : ¬ is_unit x) : irreducible x ∨ ∃ a b, ¬ is_unit a ∧ ¬ is_unit b ∧ a * b = x := begin haveI := classical.dec, refine or_iff_not_imp_right.2 (λ H, _), simp [h, irreducible] at H ⊢, refine λ a b h, classical.by_contradiction $ λ o, _, simp [not_or_distrib] at o, exact H _ o.1 _ o.2 h.symm end lemma irreducible_of_prime [integral_domain α] {p : α} (hp : prime p) : irreducible p := ⟨hp.not_unit, λ a b hab, (show a * b ∣ a ∨ a * b ∣ b, from hab ▸ hp.div_or_div (hab ▸ (dvd_refl _))).elim (λ ⟨x, hx⟩, or.inr (is_unit_iff_dvd_one.2 ⟨x, (domain.mul_left_inj (show a ≠ 0, from λ h, by simp [*, prime] at *)).1 $ by conv {to_lhs, rw hx}; simp [mul_comm, mul_assoc, mul_left_comm]⟩)) (λ ⟨x, hx⟩, or.inl (is_unit_iff_dvd_one.2 ⟨x, (domain.mul_left_inj (show b ≠ 0, from λ h, by simp [*, prime] at *)).1 $ by conv {to_lhs, rw hx}; simp [mul_comm, mul_assoc, mul_left_comm]⟩))⟩ lemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul [integral_domain α] {p : α} (hp : prime p) {a b : α} {k l : ℕ} : p ^ k ∣ a → p ^ l ∣ b → p ^ ((k + l) + 1) ∣ a * b → p ^ (k + 1) ∣ a ∨ p ^ (l + 1) ∣ b := λ ⟨x, hx⟩ ⟨y, hy⟩ ⟨z, hz⟩, have h : p ^ (k + l) * (x * y) = p ^ (k + l) * (p * z), by simpa [mul_comm, _root_.pow_add, hx, hy, mul_assoc, mul_left_comm] using hz, have hp0: p ^ (k + l) ≠ 0, from pow_ne_zero _ hp.ne_zero, have hpd : p ∣ x * y, from ⟨z, by rwa [domain.mul_right_inj hp0] at h⟩, (hp.div_or_div hpd).elim (λ ⟨d, hd⟩, or.inl ⟨d, by simp [*, _root_.pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩) (λ ⟨d, hd⟩, or.inr ⟨d, by simp [*, _root_.pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩) /-- Two elements of a `monoid` are `associated` if one of them is another one multiplied by a unit on the right. -/ def associated [monoid α] (x y : α) : Prop := ∃u:units α, x * u = y local infix ` ~ᵤ ` : 50 := associated namespace associated @[refl] protected theorem refl [monoid α] (x : α) : x ~ᵤ x := ⟨1, by simp⟩ @[symm] protected theorem symm [monoid α] : ∀{x y : α}, x ~ᵤ y → y ~ᵤ x | x _ ⟨u, rfl⟩ := ⟨u⁻¹, by rw [mul_assoc, units.mul_inv, mul_one]⟩ @[trans] protected theorem trans [monoid α] : ∀{x y z : α}, x ~ᵤ y → y ~ᵤ z → x ~ᵤ z | x _ _ ⟨u, rfl⟩ ⟨v, rfl⟩ := ⟨u * v, by rw [units.coe_mul, mul_assoc]⟩ protected def setoid (α : Type*) [monoid α] : setoid α := { r := associated, iseqv := ⟨associated.refl, λa b, associated.symm, λa b c, associated.trans⟩ } end associated local attribute [instance] associated.setoid theorem unit_associated_one [monoid α] {u : units α} : (u : α) ~ᵤ 1 := ⟨u⁻¹, units.mul_inv u⟩ theorem associated_one_iff_is_unit [monoid α] {a : α} : (a : α) ~ᵤ 1 ↔ is_unit a := iff.intro (assume h, let ⟨c, h⟩ := h.symm in h ▸ ⟨c, one_mul _⟩) (assume ⟨c, h⟩, associated.symm ⟨c, by simp [h]⟩) theorem associated_zero_iff_eq_zero [comm_semiring α] (a : α) : a ~ᵤ 0 ↔ a = 0 := iff.intro (assume h, let ⟨u, h⟩ := h.symm in by simpa using h.symm) (assume h, h ▸ associated.refl a) theorem associated_one_of_mul_eq_one [comm_monoid α] {a : α} (b : α) (hab : a * b = 1) : a ~ᵤ 1 := show (units.mk_of_mul_eq_one a b hab : α) ~ᵤ 1, from unit_associated_one theorem associated_one_of_associated_mul_one [comm_monoid α] {a b : α} : a * b ~ᵤ 1 → a ~ᵤ 1 | ⟨u, h⟩ := associated_one_of_mul_eq_one (b * u) $ by simpa [mul_assoc] using h lemma associated_mul_mul [comm_monoid α] {a₁ a₂ b₁ b₂ : α} : a₁ ~ᵤ b₁ → a₂ ~ᵤ b₂ → (a₁ * a₂) ~ᵤ (b₁ * b₂) | ⟨c₁, h₁⟩ ⟨c₂, h₂⟩ := ⟨c₁ * c₂, by simp [h₁.symm, h₂.symm, mul_assoc, mul_comm, mul_left_comm]⟩ theorem associated_of_dvd_dvd [integral_domain α] {a b : α} (hab : a ∣ b) (hba : b ∣ a) : a ~ᵤ b := begin haveI := classical.dec_eq α, rcases hab with ⟨c, rfl⟩, rcases hba with ⟨d, a_eq⟩, by_cases ha0 : a = 0, { simp [*] at * }, have : a * 1 = a * (c * d), { simpa [mul_assoc] using a_eq }, have : 1 = (c * d), from eq_of_mul_eq_mul_left ha0 this, exact ⟨units.mk_of_mul_eq_one c d (this.symm), by rw [units.mk_of_mul_eq_one, units.val_coe]⟩ end lemma exists_associated_mem_of_dvd_prod [integral_domain α] {p : α} (hp : prime p) {s : multiset α} : (∀ r ∈ s, prime r) → p ∣ s.prod → ∃ q ∈ s, p ~ᵤ q := multiset.induction_on s (by simp [mt is_unit_iff_dvd_one.2 hp.not_unit]) (λ a s ih hs hps, begin rw [multiset.prod_cons] at hps, cases hp.div_or_div hps with h h, { use [a, by simp], cases h with u hu, cases ((irreducible_of_prime (hs a (multiset.mem_cons.2 (or.inl rfl)))).2 p u hu).resolve_left hp.not_unit with v hv, exact ⟨v, by simp [hu, hv]⟩ }, { rcases ih (λ r hr, hs _ (multiset.mem_cons.2 (or.inr hr))) h with ⟨q, hq₁, hq₂⟩, exact ⟨q, multiset.mem_cons.2 (or.inr hq₁), hq₂⟩ } end) lemma dvd_iff_dvd_of_rel_left [comm_semiring α] {a b c : α} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c := let ⟨u, hu⟩ := h in hu ▸ mul_unit_dvd_iff.symm lemma dvd_mul_unit_iff [comm_semiring α] {a b : α} {u : units α} : a ∣ b * u ↔ a ∣ b := units.dvd_coe_mul _ _ _ lemma dvd_iff_dvd_of_rel_right [comm_semiring α] {a b c : α} (h : b ~ᵤ c) : a ∣ b ↔ a ∣ c := let ⟨u, hu⟩ := h in hu ▸ dvd_mul_unit_iff.symm lemma eq_zero_iff_of_associated [comm_semiring α] {a b : α} (h : a ~ᵤ b) : a = 0 ↔ b = 0 := ⟨λ ha, let ⟨u, hu⟩ := h in by simp [hu.symm, ha], λ hb, let ⟨u, hu⟩ := h.symm in by simp [hu.symm, hb]⟩ lemma ne_zero_iff_of_associated [comm_semiring α] {a b : α} (h : a ~ᵤ b) : a ≠ 0 ↔ b ≠ 0 := by haveI := classical.dec; exact not_iff_not.2 (eq_zero_iff_of_associated h) lemma prime_of_associated [comm_semiring α] {p q : α} (h : p ~ᵤ q) (hp : prime p) : prime q := ⟨(ne_zero_iff_of_associated h).1 hp.ne_zero, let ⟨u, hu⟩ := h in ⟨λ ⟨v, hv⟩, hp.not_unit ⟨v * u⁻¹, by simp [hv.symm, hu.symm]⟩, hu ▸ by { simp [mul_unit_dvd_iff], intros a b, exact hp.div_or_div }⟩⟩ lemma prime_iff_of_associated [comm_semiring α] {p q : α} (h : p ~ᵤ q) : prime p ↔ prime q := ⟨prime_of_associated h, prime_of_associated h.symm⟩ lemma is_unit_iff_of_associated [monoid α] {a b : α} (h : a ~ᵤ b) : is_unit a ↔ is_unit b := ⟨let ⟨u, hu⟩ := h in λ ⟨v, hv⟩, ⟨v * u, by simp [hv, hu.symm]⟩, let ⟨u, hu⟩ := h.symm in λ ⟨v, hv⟩, ⟨v * u, by simp [hv, hu.symm]⟩⟩ lemma irreducible_of_associated [comm_semiring α] {p q : α} (h : p ~ᵤ q) (hp : irreducible p) : irreducible q := ⟨mt (is_unit_iff_of_associated h).2 hp.1, let ⟨u, hu⟩ := h in λ a b hab, have hpab : p = a * (b * (u⁻¹ : units α)), from calc p = (p * u) * (u ⁻¹ : units α) : by simp ... = _ : by rw hu; simp [hab, mul_assoc], (hp.2 _ _ hpab).elim or.inl (λ ⟨v, hv⟩, or.inr ⟨v * u, by simp [hv.symm]⟩)⟩ lemma irreducible_iff_of_associated [comm_semiring α] {p q : α} (h : p ~ᵤ q) : irreducible p ↔ irreducible q := ⟨irreducible_of_associated h, irreducible_of_associated h.symm⟩ lemma associated_mul_left_cancel [integral_domain α] {a b c d : α} (h : a * b ~ᵤ c * d) (h₁ : a ~ᵤ c) (ha : a ≠ 0) : b ~ᵤ d := let ⟨u, hu⟩ := h in let ⟨v, hv⟩ := associated.symm h₁ in ⟨u * (v : units α), (domain.mul_right_inj ha).1 begin rw [← hv, mul_assoc c (v : α) d, mul_left_comm c, ← hu], simp [hv.symm, mul_assoc, mul_comm, mul_left_comm] end⟩ lemma associated_mul_right_cancel [integral_domain α] {a b c d : α} : a * b ~ᵤ c * d → b ~ᵤ d → b ≠ 0 → a ~ᵤ c := by rw [mul_comm a, mul_comm c]; exact associated_mul_left_cancel def associates (α : Type*) [monoid α] : Type* := quotient (associated.setoid α) namespace associates open associated protected def mk {α : Type*} [monoid α] (a : α) : associates α := ⟦ a ⟧ instance [monoid α] : inhabited (associates α) := ⟨⟦1⟧⟩ theorem mk_eq_mk_iff_associated [monoid α] {a b : α} : associates.mk a = associates.mk b ↔ a ~ᵤ b := iff.intro quotient.exact quot.sound theorem quotient_mk_eq_mk [monoid α] (a : α) : ⟦ a ⟧ = associates.mk a := rfl theorem quot_mk_eq_mk [monoid α] (a : α) : quot.mk setoid.r a = associates.mk a := rfl theorem forall_associated [monoid α] {p : associates α → Prop} : (∀a, p a) ↔ (∀a, p (associates.mk a)) := iff.intro (assume h a, h _) (assume h a, quotient.induction_on a h) instance [monoid α] : has_one (associates α) := ⟨⟦ 1 ⟧⟩ theorem one_eq_mk_one [monoid α] : (1 : associates α) = associates.mk 1 := rfl instance [monoid α] : has_bot (associates α) := ⟨1⟩ section comm_monoid variable [comm_monoid α] instance : has_mul (associates α) := ⟨λa' b', quotient.lift_on₂ a' b' (λa b, ⟦ a * b ⟧) $ assume a₁ a₂ b₁ b₂ ⟨c₁, h₁⟩ ⟨c₂, h₂⟩, quotient.sound $ ⟨c₁ * c₂, by simp [h₁.symm, h₂.symm, mul_assoc, mul_comm, mul_left_comm]⟩⟩ theorem mk_mul_mk {x y : α} : associates.mk x * associates.mk y = associates.mk (x * y) := rfl instance : comm_monoid (associates α) := { one := 1, mul := (*), mul_one := assume a', quotient.induction_on a' $ assume a, show ⟦a * 1⟧ = ⟦ a ⟧, by simp, one_mul := assume a', quotient.induction_on a' $ assume a, show ⟦1 * a⟧ = ⟦ a ⟧, by simp, mul_assoc := assume a' b' c', quotient.induction_on₃ a' b' c' $ assume a b c, show ⟦a * b * c⟧ = ⟦a * (b * c)⟧, by rw [mul_assoc], mul_comm := assume a' b', quotient.induction_on₂ a' b' $ assume a b, show ⟦a * b⟧ = ⟦b * a⟧, by rw [mul_comm] } instance : preorder (associates α) := { le := λa b, ∃c, a * c = b, le_refl := assume a, ⟨1, by simp⟩, le_trans := assume a b c ⟨f₁, h₁⟩ ⟨f₂, h₂⟩, ⟨f₁ * f₂, h₂ ▸ h₁ ▸ (mul_assoc _ _ _).symm⟩} instance : has_dvd (associates α) := ⟨(≤)⟩ @[simp] lemma mk_one : associates.mk (1 : α) = 1 := rfl lemma mk_pow (a : α) (n : ℕ) : associates.mk (a ^ n) = (associates.mk a) ^ n := by induction n; simp [*, pow_succ, associates.mk_mul_mk.symm] lemma dvd_eq_le : ((∣) : associates α → associates α → Prop) = (≤) := rfl theorem prod_mk {p : multiset α} : (p.map associates.mk).prod = associates.mk p.prod := multiset.induction_on p (by simp; refl) $ assume a s ih, by simp [ih]; refl theorem rel_associated_iff_map_eq_map {p q : multiset α} : multiset.rel associated p q ↔ p.map associates.mk = q.map associates.mk := by rw [← multiset.rel_eq]; simp [multiset.rel_map_left, multiset.rel_map_right, mk_eq_mk_iff_associated] theorem mul_eq_one_iff {x y : associates α} : x * y = 1 ↔ (x = 1 ∧ y = 1) := iff.intro (quotient.induction_on₂ x y $ assume a b h, have a * b ~ᵤ 1, from quotient.exact h, ⟨quotient.sound $ associated_one_of_associated_mul_one this, quotient.sound $ associated_one_of_associated_mul_one $ by rwa [mul_comm] at this⟩) (by simp {contextual := tt}) theorem prod_eq_one_iff {p : multiset (associates α)} : p.prod = 1 ↔ (∀a ∈ p, (a:associates α) = 1) := multiset.induction_on p (by simp) (by simp [mul_eq_one_iff, or_imp_distrib, forall_and_distrib] {contextual := tt}) theorem coe_unit_eq_one : ∀u:units (associates α), (u : associates α) = 1 | ⟨u, v, huv, hvu⟩ := by rw [mul_eq_one_iff] at huv; exact huv.1 theorem is_unit_iff_eq_one (a : associates α) : is_unit a ↔ a = 1 := iff.intro (assume ⟨u, h⟩, h.symm ▸ coe_unit_eq_one _) (assume h, h.symm ▸ is_unit_one) theorem is_unit_mk {a : α} : is_unit (associates.mk a) ↔ is_unit a := calc is_unit (associates.mk a) ↔ a ~ᵤ 1 : by rw [is_unit_iff_eq_one, one_eq_mk_one, mk_eq_mk_iff_associated] ... ↔ is_unit a : associated_one_iff_is_unit section order theorem mul_mono {a b c d : associates α} (h₁ : a ≤ b) (h₂ : c ≤ d) : a * c ≤ b * d := let ⟨x, hx⟩ := h₁, ⟨y, hy⟩ := h₂ in ⟨x * y, by simp [hx.symm, hy.symm, mul_comm, mul_assoc, mul_left_comm]⟩ theorem one_le {a : associates α} : 1 ≤ a := ⟨a, one_mul a⟩ theorem prod_le_prod {p q : multiset (associates α)} (h : p ≤ q) : p.prod ≤ q.prod := begin haveI := classical.dec_eq (associates α), haveI := classical.dec_eq α, suffices : p.prod ≤ (p + (q - p)).prod, { rwa [multiset.add_sub_of_le h] at this }, suffices : p.prod * 1 ≤ p.prod * (q - p).prod, { simpa }, exact mul_mono (le_refl p.prod) one_le end theorem le_mul_right {a b : associates α} : a ≤ a * b := ⟨b, rfl⟩ theorem le_mul_left {a b : associates α} : a ≤ b * a := by rw [mul_comm]; exact le_mul_right end order end comm_monoid instance [has_zero α] [monoid α] : has_zero (associates α) := ⟨⟦ 0 ⟧⟩ instance [has_zero α] [monoid α] : has_top (associates α) := ⟨0⟩ section comm_semiring variables [comm_semiring α] @[simp] theorem mk_zero_eq (a : α) : associates.mk a = 0 ↔ a = 0 := ⟨assume h, (associated_zero_iff_eq_zero a).1 $ quotient.exact h, assume h, h.symm ▸ rfl⟩ @[simp] theorem mul_zero : ∀(a : associates α), a * 0 = 0 := by rintros ⟨a⟩; show associates.mk (a * 0) = associates.mk 0; rw [mul_zero] @[simp] protected theorem zero_mul : ∀(a : associates α), 0 * a = 0 := by rintros ⟨a⟩; show associates.mk (0 * a) = associates.mk 0; rw [zero_mul] theorem mk_eq_zero_iff_eq_zero {a : α} : associates.mk a = 0 ↔ a = 0 := calc associates.mk a = 0 ↔ (a ~ᵤ 0) : mk_eq_mk_iff_associated ... ↔ a = 0 : associated_zero_iff_eq_zero a theorem dvd_of_mk_le_mk {a b : α} : associates.mk a ≤ associates.mk b → a ∣ b | ⟨c', hc'⟩ := (quotient.induction_on c' $ assume c hc, let ⟨d, hd⟩ := (quotient.exact hc).symm in ⟨(↑d⁻¹) * c, calc b = (a * c) * ↑d⁻¹ : by rw [← hd, mul_assoc, units.mul_inv, mul_one] ... = a * (↑d⁻¹ * c) : by ac_refl⟩) hc' theorem mk_le_mk_of_dvd {a b : α} : a ∣ b → associates.mk a ≤ associates.mk b := assume ⟨c, hc⟩, ⟨associates.mk c, by simp [hc]; refl⟩ theorem mk_le_mk_iff_dvd_iff {a b : α} : associates.mk a ≤ associates.mk b ↔ a ∣ b := iff.intro dvd_of_mk_le_mk mk_le_mk_of_dvd def prime (p : associates α) : Prop := p ≠ 0 ∧ p ≠ 1 ∧ (∀a b, p ≤ a * b → p ≤ a ∨ p ≤ b) lemma prime.ne_zero {p : associates α} (hp : prime p) : p ≠ 0 := hp.1 lemma prime.ne_one {p : associates α} (hp : prime p) : p ≠ 1 := hp.2.1 lemma prime.le_or_le {p : associates α} (hp : prime p) {a b : associates α} (h : p ≤ a * b) : p ≤ a ∨ p ≤ b := hp.2.2 a b h lemma exists_mem_multiset_le_of_prime {s : multiset (associates α)} {p : associates α} (hp : prime p) : p ≤ s.prod → ∃a∈s, p ≤ a := multiset.induction_on s (assume ⟨d, eq⟩, (hp.ne_one (mul_eq_one_iff.1 eq).1).elim) $ assume a s ih h, have p ≤ a * s.prod, by simpa using h, match hp.le_or_le this with | or.inl h := ⟨a, multiset.mem_cons_self a s, h⟩ | or.inr h := let ⟨a, has, h⟩ := ih h in ⟨a, multiset.mem_cons_of_mem has, h⟩ end lemma prime_mk (p : α) : prime (associates.mk p) ↔ _root_.prime p := begin rw [associates.prime, _root_.prime, forall_associated], transitivity, { apply and_congr, refl, apply and_congr, refl, apply forall_congr, assume a, exact forall_associated }, apply and_congr, { rw [(≠), mk_zero_eq] }, apply and_congr, { rw [(≠), ← is_unit_iff_eq_one, is_unit_mk], }, apply forall_congr, assume a, apply forall_congr, assume b, rw [mk_mul_mk, mk_le_mk_iff_dvd_iff, mk_le_mk_iff_dvd_iff, mk_le_mk_iff_dvd_iff] end end comm_semiring section integral_domain variable [integral_domain α] instance : partial_order (associates α) := { le_antisymm := assume a' b', quotient.induction_on₂ a' b' $ assume a b ⟨f₁', h₁⟩ ⟨f₂', h₂⟩, (quotient.induction_on₂ f₁' f₂' $ assume f₁ f₂ h₁ h₂, let ⟨c₁, h₁⟩ := quotient.exact h₁, ⟨c₂, h₂⟩ := quotient.exact h₂ in quotient.sound $ associated_of_dvd_dvd (h₁ ▸ dvd_mul_of_dvd_left (dvd_mul_right _ _) _) (h₂ ▸ dvd_mul_of_dvd_left (dvd_mul_right _ _) _)) h₁ h₂ .. associates.preorder } instance : order_bot (associates α) := { bot := 1, bot_le := assume a, one_le, .. associates.partial_order } instance : order_top (associates α) := { top := 0, le_top := assume a, ⟨0, mul_zero a⟩, .. associates.partial_order } theorem zero_ne_one : (0 : associates α) ≠ 1 := assume h, have (0 : α) ~ᵤ 1, from quotient.exact h, have (0 : α) = 1, from ((associated_zero_iff_eq_zero 1).1 this.symm).symm, zero_ne_one this theorem mul_eq_zero_iff {x y : associates α} : x * y = 0 ↔ x = 0 ∨ y = 0 := iff.intro (quotient.induction_on₂ x y $ assume a b h, have a * b = 0, from (associated_zero_iff_eq_zero _).1 (quotient.exact h), have a = 0 ∨ b = 0, from mul_eq_zero_iff_eq_zero_or_eq_zero.1 this, this.imp (assume h, h.symm ▸ rfl) (assume h, h.symm ▸ rfl)) (by simp [or_imp_distrib] {contextual := tt}) theorem prod_eq_zero_iff {s : multiset (associates α)} : s.prod = 0 ↔ (0 : associates α) ∈ s := multiset.induction_on s (by simp; exact zero_ne_one.symm) $ assume a s, by simp [mul_eq_zero_iff, @eq_comm _ 0 a] {contextual := tt} theorem irreducible_mk_iff (a : α) : irreducible (associates.mk a) ↔ irreducible a := begin simp [irreducible, is_unit_mk], apply and_congr iff.rfl, split, { assume h x y eq, have : is_unit (associates.mk x) ∨ is_unit (associates.mk y), from h _ _ (by rw [eq]; refl), simpa [is_unit_mk] }, { refine assume h x y, quotient.induction_on₂ x y (assume x y eq, _), rcases quotient.exact eq.symm with ⟨u, eq⟩, have : a = x * (y * u), by rwa [mul_assoc, eq_comm] at eq, show is_unit (associates.mk x) ∨ is_unit (associates.mk y), simpa [is_unit_mk] using h _ _ this } end lemma eq_of_mul_eq_mul_left : ∀(a b c : associates α), a ≠ 0 → a * b = a * c → b = c := begin rintros ⟨a⟩ ⟨b⟩ ⟨c⟩ ha h, rcases quotient.exact' h with ⟨u, hu⟩, have hu : a * (b * ↑u) = a * c, { rwa [← mul_assoc] }, exact quotient.sound' ⟨u, eq_of_mul_eq_mul_left (mt (mk_zero_eq a).2 ha) hu⟩ end lemma le_of_mul_le_mul_left (a b c : associates α) (ha : a ≠ 0) : a * b ≤ a * c → b ≤ c | ⟨d, hd⟩ := ⟨d, eq_of_mul_eq_mul_left a _ _ ha $ by rwa ← mul_assoc⟩ lemma one_or_eq_of_le_of_prime : ∀(p m : associates α), prime p → m ≤ p → (m = 1 ∨ m = p) | _ m ⟨hp0, hp1, h⟩ ⟨d, rfl⟩ := match h m d (le_refl _) with | or.inl h := classical.by_cases (assume : m = 0, by simp [this]) $ assume : m ≠ 0, have m * d ≤ m * 1, by simpa using h, have d ≤ 1, from associates.le_of_mul_le_mul_left m d 1 ‹m ≠ 0› this, have d = 1, from bot_unique this, by simp [this] | or.inr h := classical.by_cases (assume : d = 0, by simp [this] at hp0; contradiction) $ assume : d ≠ 0, have d * m ≤ d * 1, by simpa [mul_comm] using h, or.inl $ bot_unique $ associates.le_of_mul_le_mul_left d m 1 ‹d ≠ 0› this end end integral_domain end associates
b6d7bc2bf4e2945ee7ca287f65737dd5f1448bc1
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/src/Lean/Meta/Tactic/Simp/Types.lean
5e43fd79f4f5a901bb5e3695d0d1bb38acd9b148
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
leanprover/lean4
4bdf9790294964627eb9be79f5e8f6157780b4cc
f1f9dc0f2f531af3312398999d8b8303fa5f096b
refs/heads/master
1,693,360,665,786
1,693,350,868,000
1,693,350,868,000
129,571,436
2,827
311
Apache-2.0
1,694,716,156,000
1,523,760,560,000
Lean
UTF-8
Lean
false
false
3,239
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Meta.AppBuilder import Lean.Meta.CongrTheorems import Lean.Meta.Tactic.Simp.SimpTheorems import Lean.Meta.Tactic.Simp.SimpCongrTheorems namespace Lean.Meta namespace Simp structure Result where expr : Expr proof? : Option Expr := none -- If none, proof is assumed to be `refl` dischargeDepth : Nat := 0 deriving Inhabited abbrev Cache := ExprMap Result abbrev CongrCache := ExprMap (Option CongrTheorem) structure Context where config : Config := {} simpTheorems : SimpTheoremsArray := {} congrTheorems : SimpCongrTheorems := {} parent? : Option Expr := none dischargeDepth : Nat := 0 deriving Inhabited def Context.isDeclToUnfold (ctx : Context) (declName : Name) : Bool := ctx.simpTheorems.isDeclToUnfold declName def Context.mkDefault : MetaM Context := return { config := {}, simpTheorems := #[(← getSimpTheorems)], congrTheorems := (← getSimpCongrTheorems) } abbrev UsedSimps := HashMap Origin Nat structure State where cache : Cache := {} congrCache : CongrCache := {} usedTheorems : UsedSimps := {} numSteps : Nat := 0 abbrev SimpM := ReaderT Context $ StateRefT State MetaM instance : MonadBacktrack SavedState SimpM where saveState := Meta.saveState restoreState s := s.restore inductive Step where | visit : Result → Step | done : Result → Step deriving Inhabited def Step.result : Step → Result | Step.visit r => r | Step.done r => r def Step.updateResult : Step → Result → Step | Step.visit _, r => Step.visit r | Step.done _, r => Step.done r structure Methods where pre : Expr → SimpM Step := fun e => return Step.visit { expr := e } post : Expr → SimpM Step := fun e => return Step.done { expr := e } discharge? : Expr → SimpM (Option Expr) := fun _ => return none deriving Inhabited /- Internal monad -/ abbrev M := ReaderT Methods SimpM def pre (e : Expr) : M Step := do (← read).pre e def post (e : Expr) : M Step := do (← read).post e def discharge? (e : Expr) : M (Option Expr) := do (← read).discharge? e def getConfig : M Config := return (← readThe Context).config @[inline] def withParent (parent : Expr) (f : M α) : M α := withTheReader Context (fun ctx => { ctx with parent? := parent }) f def getSimpTheorems : M SimpTheoremsArray := return (← readThe Context).simpTheorems def getSimpCongrTheorems : M SimpCongrTheorems := return (← readThe Context).congrTheorems @[inline] def withSimpTheorems (s : SimpTheoremsArray) (x : M α) : M α := do let cacheSaved := (← get).cache modify fun s => { s with cache := {} } try withTheReader Context (fun ctx => { ctx with simpTheorems := s }) x finally modify fun s => { s with cache := cacheSaved } def recordSimpTheorem (thmId : Origin) : SimpM Unit := modify fun s => if s.usedTheorems.contains thmId then s else let n := s.usedTheorems.size { s with usedTheorems := s.usedTheorems.insert thmId n } end Simp export Simp (SimpM) end Lean.Meta
d9f99297643bce7a49f118f819bc3f2698c8a3c3
38bf3fd2bb651ab70511408fcf70e2029e2ba310
/src/ring_theory/integral_closure.lean
b62b126ac3f9f5cf6df98daf0cc967fdd53b8259
[ "Apache-2.0" ]
permissive
JaredCorduan/mathlib
130392594844f15dad65a9308c242551bae6cd2e
d5de80376088954d592a59326c14404f538050a1
refs/heads/master
1,595,862,206,333
1,570,816,457,000
1,570,816,457,000
209,134,499
0
0
Apache-2.0
1,568,746,811,000
1,568,746,811,000
null
UTF-8
Lean
false
false
13,716
lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau Integral closure of a subring. -/ import ring_theory.adjoin linear_algebra.finsupp universes u v open polynomial submodule variables (R : Type u) {A : Type v} variables [comm_ring R] [comm_ring A] variables [decidable_eq R] [decidable_eq A] variables [algebra R A] def is_integral (x : A) : Prop := ∃ p : polynomial R, monic p ∧ aeval R A x p = 0 variables {R} theorem is_integral_algebra_map {x : R} : is_integral R (algebra_map A x) := ⟨X - C x, monic_X_sub_C _, by rw [alg_hom.map_sub, aeval_def, aeval_def, eval₂_X, eval₂_C, sub_self]⟩ theorem is_integral_of_subring {x : A} (T : set R) [is_subring T] (hx : is_integral T (algebra.comap.to_comap T R A x)) : is_integral R (x : A) := let ⟨p, hpm, hpx⟩ := hx in ⟨⟨p.support, λ n, (p.to_fun n).1, λ n, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ H, have _ := congr_arg subtype.val H, this, λ H, subtype.eq H⟩)⟩, have _ := congr_arg subtype.val hpm, this, hpx⟩ theorem is_integral_iff_is_integral_closure_finite {r : A} : is_integral R r ↔ ∃ s : set R, s.finite ∧ is_integral (ring.closure s) (algebra.comap.to_comap (ring.closure s) R A r) := begin split; intro hr, { rcases hr with ⟨p, hmp, hpr⟩, exact ⟨_, set.finite_mem_finset _, p.restriction, subtype.eq hmp, hpr⟩ }, rcases hr with ⟨s, hs, hsr⟩, exact is_integral_of_subring _ hsr end theorem fg_adjoin_singleton_of_integral (x : A) (hx : is_integral R x) : (algebra.adjoin R ({x} : set A) : submodule R A).fg := begin rcases hx with ⟨f, hfm, hfx⟩, existsi finset.image ((^) x) (finset.range (nat_degree f + 1)), apply le_antisymm, { rw span_le, intros s hs, rw finset.mem_coe at hs, rcases finset.mem_image.1 hs with ⟨k, hk, rfl⟩, clear hk, exact is_submonoid.pow_mem (algebra.subset_adjoin (set.mem_singleton _)) }, intros r hr, change r ∈ algebra.adjoin R ({x} : set A) at hr, rw algebra.adjoin_singleton_eq_range at hr, rcases hr with ⟨p, rfl⟩, rw ← mod_by_monic_add_div p hfm, rw [alg_hom.map_add, alg_hom.map_mul, hfx, zero_mul, add_zero], have : degree (p %ₘ f) ≤ degree f := degree_mod_by_monic_le p hfm, generalize_hyp : p %ₘ f = q at this ⊢, rw [← sum_C_mul_X_eq q, aeval_def, eval₂_sum, finsupp.sum, mem_coe], refine sum_mem _ (λ k hkq, _), rw [eval₂_mul, eval₂_C, eval₂_pow, eval₂_X, ← algebra.smul_def], refine smul_mem _ _ (subset_span _), rw finset.mem_coe, refine finset.mem_image.2 ⟨_, _, rfl⟩, rw [finset.mem_range, nat.lt_succ_iff], refine le_of_not_lt (λ hk, _), rw [degree_le_iff_coeff_zero] at this, rw [finsupp.mem_support_iff] at hkq, apply hkq, apply this, exact lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 hk) end theorem fg_adjoin_of_finite {s : set A} (hfs : s.finite) (his : ∀ x ∈ s, is_integral R x) : (algebra.adjoin R s : submodule R A).fg := set.finite.induction_on hfs (λ _, ⟨finset.singleton 1, le_antisymm (span_le.2 $ set.singleton_subset_iff.2 $ is_submonoid.one_mem _) (show ring.closure _ ⊆ _, by rw set.union_empty; exact set.subset.trans (ring.closure_subset (set.subset.refl _)) (λ y ⟨x, hx⟩, hx ▸ mul_one (algebra_map A x) ▸ algebra.smul_def x (1:A) ▸ (mem_coe _).2 (submodule.smul_mem _ x $ subset_span $ or.inl rfl)))⟩) (λ a s has hs ih his, by rw [← set.union_singleton, algebra.adjoin_union_coe_submodule]; exact fg_mul _ _ (ih $ λ i hi, his i $ set.mem_insert_of_mem a hi) (fg_adjoin_singleton_of_integral _ $ his a $ set.mem_insert a s)) his theorem is_integral_of_noetherian' (H : is_noetherian R A) (x : A) : is_integral R x := begin let leval : @linear_map R (polynomial R) A _ _ _ _ _ := (aeval R A x).to_linear_map, let D : ℕ → submodule R A := λ n, (degree_le R n).map leval, let M := well_founded.min (is_noetherian_iff_well_founded.1 H) (set.range D) (set.ne_empty_of_mem ⟨0, rfl⟩), have HM : M ∈ set.range D := well_founded.min_mem _ _ _, cases HM with N HN, have HM : ¬M < D (N+1) := well_founded.not_lt_min (is_noetherian_iff_well_founded.1 H) (set.range D) _ ⟨N+1, rfl⟩, rw ← HN at HM, have HN2 : D (N+1) ≤ D N := classical.by_contradiction (λ H, HM (lt_of_le_not_le (map_mono (degree_le_mono (with_bot.coe_le_coe.2 (nat.le_succ N)))) H)), have HN3 : leval (X^(N+1)) ∈ D N, { exact HN2 (mem_map_of_mem (mem_degree_le.2 (degree_X_pow_le _))) }, rcases HN3 with ⟨p, hdp, hpe⟩, refine ⟨X^(N+1) - p, monic_X_pow_sub (mem_degree_le.1 hdp), _⟩, show leval (X ^ (N + 1) - p) = 0, rw [linear_map.map_sub, hpe, sub_self] end theorem is_integral_of_noetherian (M : subalgebra R A) (H : is_noetherian R (M : submodule R A)) (x : A) (hx : x ∈ M) : is_integral R x := begin letI : algebra R M := M.algebra, letI : comm_ring M := M.comm_ring R A, suffices : is_integral R (⟨x, hx⟩ : M), { rcases this with ⟨p, hpm, hpx⟩, replace hpx := congr_arg subtype.val hpx, refine ⟨p, hpm, eq.trans _ hpx⟩, simp only [aeval_def, eval₂, finsupp.sum], rw ← finset.sum_hom subtype.val, { refine finset.sum_congr rfl (λ n hn, _), change _ = _ * _, rw is_semiring_hom.map_pow subtype.val, refl, split; intros; refl }, refine { map_add := _, map_zero := _ }; intros; refl }, refine is_integral_of_noetherian' H ⟨x, hx⟩ end set_option class.instance_max_depth 100 theorem is_integral_of_mem_of_fg (M : subalgebra R A) (HM : (M : submodule R A).fg) (x : A) (hx : x ∈ M) : is_integral R x := begin cases HM with m hm, have hxm : x ∈ (M : submodule R A) := hx, rw [← hm, ← set.image_id ↑m, finsupp.mem_span_iff_total] at hxm, rcases hxm with ⟨lx, hlx1, hlx2⟩, have : ∀ (jk : (↑(m.product m) : set (A × A))), jk.1.1 * jk.1.2 ∈ (span R ↑m : submodule R A), { intros jk, let j : ↥(↑m : set A) := ⟨jk.1.1, (finset.mem_product.1 jk.2).1⟩, let k : ↥(↑m : set A) := ⟨jk.1.2, (finset.mem_product.1 jk.2).2⟩, have hj : j.1 ∈ (span R ↑m : submodule R A) := subset_span j.2, have hk : k.1 ∈ (span R ↑m : submodule R A) := subset_span k.2, revert hj hk, rw hm, exact @is_submonoid.mul_mem A _ M _ j.1 k.1 }, rw ← set.image_id ↑m at this, simp only [finsupp.mem_span_iff_total] at this, choose lm hlm1 hlm2, let S₀' : finset R := lx.frange ∪ finset.bind finset.univ (finsupp.frange ∘ lm), let S₀ : set R := ring.closure ↑S₀', refine is_integral_of_subring (ring.closure ↑S₀') _, letI : algebra S₀ (algebra.comap S₀ R A) := algebra.comap.algebra _ _ _, letI : module S₀ (algebra.comap S₀ R A) := algebra.to_module, have : (span S₀ (insert 1 (↑m:set A) : set (algebra.comap S₀ R A)) : submodule S₀ (algebra.comap S₀ R A)) = (algebra.adjoin S₀ ((↑m : set A) : set (algebra.comap S₀ R A)) : subalgebra S₀ (algebra.comap S₀ R A)), { apply le_antisymm, { rw [span_le, set.insert_subset, mem_coe], split, change _ ∈ ring.closure _, exact is_submonoid.one_mem _, exact algebra.subset_adjoin }, rw [algebra.adjoin_eq_span, span_le], intros r hr, refine monoid.in_closure.rec_on hr _ _ _, { intros r hr, exact subset_span (set.mem_insert_of_mem _ hr) }, { exact subset_span (set.mem_insert _ _) }, intros r1 r2 hr1 hr2 ih1 ih2, rw ← set.image_id (insert _ ↑m) at ih1 ih2, simp only [mem_coe, finsupp.mem_span_iff_total] at ih1 ih2, have ih1' := ih1, have ih2' := ih2, rcases ih1' with ⟨l1, hl1, rfl⟩, rcases ih2' with ⟨l2, hl2, rfl⟩, simp only [finsupp.total_apply, finsupp.sum_mul, finsupp.mul_sum, mem_coe], rw [finsupp.sum], refine sum_mem _ _, intros r2 hr2, rw [finsupp.sum], refine sum_mem _ _, intros r1 hr1, rw [algebra.mul_smul_comm, algebra.smul_mul_assoc], letI : module ↥S₀ A := _inst_6, refine smul_mem _ _ (smul_mem _ _ _), rcases hl1 hr1 with rfl | hr1, { change 1 * r2 ∈ _, rw one_mul r2, exact subset_span (hl2 hr2) }, rcases hl2 hr2 with rfl | hr2, { change r1 * 1 ∈ _, rw mul_one, exact subset_span (set.mem_insert_of_mem _ hr1) }, let jk : ↥(↑(finset.product m m) : set (A × A)) := ⟨(r1, r2), finset.mem_product.2 ⟨hr1, hr2⟩⟩, specialize hlm2 jk, change _ = r1 * r2 at hlm2, rw [id, id, ← hlm2, finsupp.total_apply], rw [finsupp.sum], refine sum_mem _ _, intros z hz, have : lm jk z ∈ S₀, { apply ring.subset_closure, apply finset.mem_union_right, apply finset.mem_bind.2, exact ⟨jk, finset.mem_univ _, by convert finset.mem_image_of_mem _ hz⟩ }, change @has_scalar.smul S₀ (algebra.comap S₀ R A) _inst_6.to_has_scalar ⟨lm jk z, this⟩ z ∈ _, exact smul_mem _ _ (subset_span (set.mem_insert_of_mem _ (hlm1 _ hz))) }, haveI : is_noetherian_ring ↥S₀ :=(by convert is_noetherian_ring_closure _ (finset.finite_to_set _); apply_instance), apply is_integral_of_noetherian (algebra.adjoin S₀ ((↑m : set A) : set (algebra.comap S₀ R A)) : subalgebra S₀ (algebra.comap S₀ R A)) (is_noetherian_of_fg_of_noetherian _ ⟨insert 1 m, by rw finset.coe_insert; convert this⟩), show x ∈ ((algebra.adjoin S₀ ((↑m : set A) : set (algebra.comap S₀ R A)) : subalgebra S₀ (algebra.comap S₀ R A)) : submodule S₀ (algebra.comap S₀ R A)), rw [← hlx2, finsupp.total_apply, finsupp.sum], refine sum_mem _ _, intros r hr, rw ← this, have : lx r ∈ ring.closure ↑S₀' := ring.subset_closure (finset.mem_union_left _ (by convert finset.mem_image_of_mem _ hr)), change @has_scalar.smul S₀ (algebra.comap S₀ R A) _inst_6.to_has_scalar ⟨lx r, this⟩ r ∈ _, exact smul_mem _ _ (subset_span (set.mem_insert_of_mem _ (hlx1 hr))) end theorem is_integral_of_mem_closure {x y z : A} (hx : is_integral R x) (hy : is_integral R y) (hz : z ∈ ring.closure ({x, y} : set A)) : is_integral R z := begin have := fg_mul _ _ (fg_adjoin_singleton_of_integral x hx) (fg_adjoin_singleton_of_integral y hy), rw [← algebra.adjoin_union_coe_submodule, set.union_singleton, insert] at this, exact is_integral_of_mem_of_fg (algebra.adjoin R {x, y}) this z (ring.closure_mono (set.subset_union_right _ _) hz) end theorem is_integral_zero : is_integral R (0:A) := algebra.map_zero R A ▸ is_integral_algebra_map theorem is_integral_one : is_integral R (1:A) := algebra.map_one R A ▸ is_integral_algebra_map theorem is_integral_add {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x + y) := is_integral_of_mem_closure hx hy (is_add_submonoid.add_mem (ring.subset_closure (or.inr (or.inl rfl))) (ring.subset_closure (or.inl rfl))) theorem is_integral_neg {x : A} (hx : is_integral R x) : is_integral R (-x) := is_integral_of_mem_closure hx hx (is_add_subgroup.neg_mem (ring.subset_closure (or.inl rfl))) theorem is_integral_sub {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x - y) := is_integral_add hx (is_integral_neg hy) theorem is_integral_mul {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x * y) := is_integral_of_mem_closure hx hy (is_submonoid.mul_mem (ring.subset_closure (or.inr (or.inl rfl))) (ring.subset_closure (or.inl rfl))) variables (R A) def integral_closure : subalgebra R A := { carrier := { r | is_integral R r }, subring := { zero_mem := is_integral_zero, one_mem := is_integral_one, add_mem := λ _ _, is_integral_add, neg_mem := λ _, is_integral_neg, mul_mem := λ _ _, is_integral_mul }, range_le := λ y ⟨x, hx⟩, hx ▸ is_integral_algebra_map } theorem mem_integral_closure_iff_mem_fg {r : A} : r ∈ integral_closure R A ↔ ∃ M : subalgebra R A, (M : submodule R A).fg ∧ r ∈ M := ⟨λ hr, ⟨algebra.adjoin R {r}, fg_adjoin_singleton_of_integral _ hr, algebra.subset_adjoin (or.inl rfl)⟩, λ ⟨M, Hf, hrM⟩, is_integral_of_mem_of_fg M Hf _ hrM⟩ theorem integral_closure_idem : integral_closure (integral_closure R A : set A) A = ⊥ := begin rw lattice.eq_bot_iff, intros r hr, rcases is_integral_iff_is_integral_closure_finite.1 hr with ⟨s, hfs, hr⟩, apply algebra.mem_bot.2, refine ⟨⟨_, _⟩, rfl⟩, refine (mem_integral_closure_iff_mem_fg _ _).2 ⟨algebra.adjoin _ (subtype.val '' s ∪ {r}), algebra.fg_trans (fg_adjoin_of_finite (set.finite_image _ hfs) (λ y ⟨x, hx, hxy⟩, hxy ▸ x.2)) _, algebra.subset_adjoin (or.inr (or.inl rfl))⟩, refine fg_adjoin_singleton_of_integral _ _, rcases hr with ⟨p, hmp, hpx⟩, refine ⟨to_subring (of_subring _ (of_subring _ p)) _ _, _, hpx⟩, { intros x hx, rcases finsupp.mem_frange.1 hx with ⟨h1, n, rfl⟩, change (coeff p n).1.1 ∈ ring.closure _, rcases ring.exists_list_of_mem_closure (coeff p n).2 with ⟨L, HL1, HL2⟩, rw ← HL2, clear HL2 hfs h1 hx n hmp hpx hr r p, induction L with hd tl ih, { exact is_add_submonoid.zero_mem _ }, rw list.forall_mem_cons at HL1, rw [list.map_cons, list.sum_cons], refine is_add_submonoid.add_mem _ (ih HL1.2), cases HL1 with HL HL', clear HL' ih tl, induction hd with hd tl ih, { exact is_submonoid.one_mem _ }, rw list.forall_mem_cons at HL, rw list.prod_cons, refine is_submonoid.mul_mem _ (ih HL.2), rcases HL.1 with hs | rfl, { exact algebra.subset_adjoin (set.mem_image_of_mem _ hs) }, exact is_add_subgroup.neg_mem (is_submonoid.one_mem _) }, replace hmp := congr_arg subtype.val hmp, replace hmp := congr_arg subtype.val hmp, exact subtype.eq hmp end
31f6be00945a29deec437b007dc2e67b4c561fc5
e24425fbf75189e4b34ef6b29f5f274e70cd5011
/src/cheatsheet.lean
66819e2519c8460ec5f00a35b46c03d47b23c53f
[]
no_license
UVM-M52/week04-chuyisun
a654ea18050ca25b2d2865cfcf568c89cde593dd
ed1dafaa43d33e878e71dbdac00535118afd3afc
refs/heads/master
1,609,225,390,456
1,581,527,077,000
1,581,527,077,000
238,504,390
0
0
null
null
null
null
UTF-8
Lean
false
false
1,905
lean
-- Math 52: Cheatsheet -------------------------------- -- BASIC GOAL TRANSFORMATIONS -- -------------------------------- -- Conjunctive Goal -- Use `split`: example (P Q : Prop) : P ∧ Q := begin split, -- you can use braces to separate the two resulting goals { sorry }, { sorry }, end -- Conditional Goal -- Use `intro`: example (P Q : Prop) : P → Q := begin intro H, -- you can give the hypothesis any name you want sorry, end -- Universal Goal -- Use `intro`: example (U : Type) (P : U → Prop) : ∀ (x : U), P x := begin intro x, -- you can rename the variable x if necessary sorry, end -- Existential Goal -- Use `existsi`: example (U : Type) (P : U → Prop) : ∃ (x : U), P x := begin existsi (sorry : U), -- you need to figure out what to put in sorry, end --------------------------------- -- BASIC GIVEN TRANSFORMATIONS -- --------------------------------- -- Conjunctive Hypothesis -- Use `cases`: example (P Q R : Prop) (H : P ∧ Q) : R := begin cases H with H₁ H₂, sorry, end -- Disjunctive Hypothesis -- Use `cases`: example (P Q R : Prop) (H : P ∨ Q) : R := begin cases H with H₁ H₂, -- you can use braces to separate the two resulting goals. { sorry }, { sorry }, end -- Existential Hypothesis -- Use `cases`: example (U : Type) (P : U → Prop) (R : Prop) (H : ∃ (x : U), P x) : R := begin cases H with x Hx, -- you can use any name you want for x sorry, end ----------------------- -- COMMON IDENTITIES -- ----------------------- #check add_assoc -- (a + b) + c = a + (b + c) #check add_comm -- a + b = b + a #check add_zero -- a + 0 = a #check zero_add -- 0 + a = a #check mul_assoc -- (a * b) * c = a * (b * c) #check mul_comm -- a * b = b * a #check mul_one -- a * 1 = a #check one_mul -- 1 * a = a #check mul_zero -- a * 0 = 0 #check zero_mul -- 0 * a = 0 #check add_mul -- (a + b) * c = a * c + b * c #check mul_add -- a * (b + c) = a * b + a * c
bd889dd5fe691bfd5f3a7c211f6daf08ba276eeb
63abd62053d479eae5abf4951554e1064a4c45b4
/src/data/polynomial/lifts.lean
7287e62f4e9cffe5ade3ac61f22921e71cb07bfb
[ "Apache-2.0" ]
permissive
Lix0120/mathlib
0020745240315ed0e517cbf32e738d8f9811dd80
e14c37827456fc6707f31b4d1d16f1f3a3205e91
refs/heads/master
1,673,102,855,024
1,604,151,044,000
1,604,151,044,000
308,930,245
0
0
Apache-2.0
1,604,164,710,000
1,604,163,547,000
null
UTF-8
Lean
false
false
10,845
lean
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Riccardo Brasca -/ import data.polynomial.algebra_map import algebra.algebra.subalgebra import algebra.polynomial.big_operators import data.polynomial.erase_lead import data.polynomial.degree.basic /-! # Polynomials that lift Given semirings `R` and `S` with a morphism `f : R →+* S`, we define a subsemiring `lifts` of `polynomial S` by the image of `ring_hom.of (map f)`. Then, we prove that a polynomial that lifts can always be lifted to a polynomial of the same degree and that a monic polynomial that lifts can be lifted to a monic polynomial (of the same degree). ## Main definition * `lifts (f : R →+* S)` : the subsemiring of polynomials that lift. ## Main results * `lifts_and_degree_eq` : A polynomial lifts if and only if it can be lifted to a polynomial of the same degree. * `lifts_and_degree_eq_and_monic` : A monic polynomial lifts if and only if it can be lifted to a monic polynomial of the same degree. * `lifts_iff_alg` : if `R` is commutative, a polynomial lifts if and only if it is in the image of `map_alg`, where `map_alg : polynomial R →ₐ[R] polynomial S` is the only `R`-algebra map that sends `X` to `X`. ## Implementation details In general `R` and `S` are semiring, so `lifts` is a semiring. In the case of rings, see `lifts_iff_lifts_ring`. Since we do not assume `R` to be commutative, we cannot say in general that the set of polynomials that lift is a subalgebra. (By `lift_iff` this is true if `R` is commutative.) -/ open_locale classical big_operators noncomputable theory namespace polynomial universes u v w section semiring variables {R : Type u} [semiring R] {S : Type v} [semiring S] {f : R →+* S} /-- We define the subsemiring of polynomials that lifts as the image of `ring_hom.of (map f)`. -/ def lifts (f : R →+* S) : subsemiring (polynomial S) := ring_hom.srange (ring_hom.of (map f)) lemma mem_lifts (p : polynomial S) : p ∈ lifts f ↔ ∃ (q : polynomial R), map f q = p := by simp only [lifts, ring_hom.coe_of, ring_hom.mem_srange] lemma lifts_iff_set_range (p : polynomial S) : p ∈ lifts f ↔ p ∈ set.range (map f) := by simp only [lifts, set.mem_range, ring_hom.coe_of, ring_hom.mem_srange] lemma lifts_iff_coeff_lifts (p : polynomial S) : p ∈ lifts f ↔ ∀ (n : ℕ), p.coeff n ∈ set.range f := by rw [lifts_iff_set_range, mem_map_range] /--If `(r : R)`, then `C (f r)` lifts. -/ lemma C_mem_lifts (f : R →+* S) (r : R) : (C (f r)) ∈ lifts f := ⟨C r, by simp only [map_C, set.mem_univ, subsemiring.coe_top, eq_self_iff_true, ring_hom.coe_of, and_self]⟩ /-- If `(s : S)` is in the image of `f`, then `C s` lifts. -/ lemma C'_mem_lifts {f : R →+* S} {s : S} (h : s ∈ set.range f) : (C s) ∈ lifts f := begin obtain ⟨r, rfl⟩ := set.mem_range.1 h, use C r, simp only [map_C, set.mem_univ, subsemiring.coe_top, eq_self_iff_true, ring_hom.coe_of, and_self] end /-- The polynomial `X` lifts. -/ lemma X_mem_lifts (f : R →+* S) : (X : polynomial S) ∈ lifts f := ⟨X, by simp only [set.mem_univ, subsemiring.coe_top, eq_self_iff_true, map_X, ring_hom.coe_of, and_self]⟩ /-- The polynomial `X ^ n` lifts. -/ lemma X_pow_mem_lifts (f : R →+* S) (n : ℕ) : (X ^ n : polynomial S) ∈ lifts f := ⟨X ^ n, by simp only [map_pow, set.mem_univ, subsemiring.coe_top, eq_self_iff_true, map_X, ring_hom.coe_of, and_self]⟩ /-- If `p` lifts and `(r : R)` then `r * p` lifts. -/ lemma base_mul_mem_lifts {p : polynomial S} (r : R) (hp : p ∈ lifts f) : C (f r) * p ∈ lifts f := begin simp only [lifts, ring_hom.coe_of, ring_hom.mem_srange] at hp ⊢, obtain ⟨p₁, rfl⟩ := hp, use C r * p₁, simp only [map_C, map_mul] end /-- If `(s : S)` is in the image of `f`, then `monomial n s` lifts. -/ lemma monomial_mem_lifts {s : S} (n : ℕ) (h : s ∈ set.range f) : (monomial n s) ∈ lifts f := begin obtain ⟨r, rfl⟩ := set.mem_range.1 h, use monomial n r, simp only [set.mem_univ, map_monomial, subsemiring.coe_top, eq_self_iff_true, ring_hom.coe_of, and_self], end /-- If `p` lifts then `p.erase n` lifts. -/ lemma erase_mem_lifts {p : polynomial S} (n : ℕ) (h : p ∈ lifts f) : p.erase n ∈ lifts f := begin rw [lifts_iff_set_range, mem_map_range, coeff] at h ⊢, intros k, by_cases hk : k = n, { use 0, simp only [hk, ring_hom.map_zero, finsupp.erase_same] }, obtain ⟨i, hi⟩ := h k, use i, simp only [hi, hk, finsupp.erase_ne, ne.def, not_false_iff], end section lift_deg lemma monomial_mem_lifts_and_degree_eq {s : S} {n : ℕ} (hl : monomial n s ∈ lifts f) : ∃ (q : polynomial R), map f q = (monomial n s) ∧ q.degree = (monomial n s).degree := begin by_cases hzero : s = 0, { use 0, simp only [hzero, degree_zero, eq_self_iff_true, and_self, monomial_zero_right, map_zero] }, rw lifts_iff_set_range at hl, obtain ⟨q, hq⟩ := hl, replace hq := (ext_iff.1 hq) n, have hcoeff : f (q.coeff n) = s, { simp [coeff_monomial] at hq, exact hq }, use (monomial n (q.coeff n)), split, { simp only [hcoeff, map_monomial] }, have hqzero : q.coeff n ≠ 0, { intro habs, simp only [habs, ring_hom.map_zero] at hcoeff, exact hzero hcoeff.symm }, repeat {rw single_eq_C_mul_X}, simp only [hzero, hqzero, ne.def, not_false_iff, degree_C_mul_X_pow], end /-- A polynomial lifts if and only if it can be lifted to a polynomial of the same degree. -/ lemma mem_lifts_and_degree_eq {p : polynomial S} (hlifts : p ∈ lifts f) : ∃ (q : polynomial R), map f q = p ∧ q.degree = p.degree := begin generalize' hd : p.nat_degree = d, revert hd p, apply nat.strong_induction_on d, intros n hn p hlifts hdeg, by_cases erase_zero : p.erase_lead = 0, { rw [← erase_lead_add_monomial_nat_degree_leading_coeff p, erase_zero, zero_add, leading_coeff], exact monomial_mem_lifts_and_degree_eq (monomial_mem_lifts p.nat_degree ((lifts_iff_coeff_lifts p).1 hlifts p.nat_degree)) }, have deg_erase := or.resolve_right (erase_lead_nat_degree_lt_or_erase_lead_eq_zero p) erase_zero, have pzero : p ≠ 0, { intro habs, exfalso, rw [habs, erase_lead_zero, eq_self_iff_true, not_true] at erase_zero, exact erase_zero }, have lead_zero : p.coeff p.nat_degree ≠ 0, { rw [← leading_coeff, ne.def, leading_coeff_eq_zero]; exact pzero }, obtain ⟨lead, hlead⟩ := monomial_mem_lifts_and_degree_eq (monomial_mem_lifts p.nat_degree ((lifts_iff_coeff_lifts p).1 hlifts p.nat_degree)), have deg_lead : lead.degree = p.nat_degree, { rw [hlead.2, single_eq_C_mul_X, degree_C_mul_X_pow p.nat_degree lead_zero] }, rw hdeg at deg_erase, obtain ⟨erase, herase⟩ := hn p.erase_lead.nat_degree deg_erase (erase_mem_lifts p.nat_degree hlifts) (refl p.erase_lead.nat_degree), use erase + lead, split, { simp only [hlead, herase, map_add], nth_rewrite 0 erase_lead_add_monomial_nat_degree_leading_coeff p }, rw [←hdeg, erase_lead] at deg_erase, replace deg_erase := lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 deg_erase), rw [← deg_lead, ← herase.2] at deg_erase, rw [degree_add_eq_of_degree_lt deg_erase, deg_lead, degree_eq_nat_degree pzero] end end lift_deg section monic /-- A monic polynomial lifts if and only if it can be lifted to a monic polynomial of the same degree. -/ lemma lifts_and_degree_eq_and_monic [nontrivial S] {p : polynomial S} (hlifts :p ∈ lifts f) (hmonic : p.monic) : ∃ (q : polynomial R), map f q = p ∧ q.degree = p.degree ∧ q.monic := begin by_cases Rtrivial : nontrivial R, swap, { rw not_nontrivial_iff_subsingleton at Rtrivial, obtain ⟨q, hq⟩ := mem_lifts_and_degree_eq hlifts, use q, exact ⟨hq.1, hq.2, @monic_of_subsingleton _ _ Rtrivial q⟩ }, by_cases er_zero : p.erase_lead = 0, { rw [← erase_lead_add_C_mul_X_pow p, er_zero, zero_add, monic.def.1 hmonic, C_1, one_mul], use X ^ p.nat_degree, repeat {split}, { simp only [map_pow, map_X] }, { rw [@degree_X_pow R _ Rtrivial, degree_X_pow] }, {exact monic_pow monic_X p.nat_degree } }, obtain ⟨q, hq⟩ := mem_lifts_and_degree_eq (erase_mem_lifts p.nat_degree hlifts), have deg_er : p.erase_lead.nat_degree < p.nat_degree := or.resolve_right (erase_lead_nat_degree_lt_or_erase_lead_eq_zero p) er_zero, replace deg_er := with_bot.coe_lt_coe.2 deg_er, rw [← degree_eq_nat_degree er_zero, erase_lead, ← hq.2, ← @degree_X_pow R _ Rtrivial p.nat_degree] at deg_er, use q + X ^ p.nat_degree, repeat {split}, { simp only [hq, map_add, map_pow, map_X], nth_rewrite 3 [← erase_lead_add_C_mul_X_pow p], rw [erase_lead, monic.leading_coeff hmonic, C_1, one_mul] }, { rw [degree_add_eq_of_degree_lt deg_er, @degree_X_pow R _ Rtrivial p.nat_degree, degree_eq_nat_degree (monic.ne_zero hmonic)] }, { rw [monic.def, leading_coeff_add_of_degree_lt deg_er], exact monic_pow monic_X p.nat_degree } end end monic end semiring section ring variables {R : Type u} [ring R] {S : Type v} [ring S] (f : R →+* S) /-- The subring of polynomials that lift. -/ def lifts_ring (f : R →+* S) : subring (polynomial S) := ring_hom.range (ring_hom.of (map f)) /-- If `R` and `S` are rings, `p` is in the subring of polynomials that lift if and only if it is in the subsemiring of polynomials that lift. -/ lemma lifts_iff_lifts_ring (p : polynomial S) : p ∈ lifts f ↔ p ∈ lifts_ring f := by simp only [lifts, lifts_ring, ring_hom.mem_range, ring_hom.mem_srange] end ring section algebra variables {R : Type u} [comm_semiring R] {S : Type v} [semiring S] [algebra R S] /-- The map `polynomial R → polynomial S` as an algebra homomorphism. -/ def map_alg (R : Type u) [comm_semiring R] (S : Type v) [semiring S] [algebra R S] : polynomial R →ₐ[R] polynomial S := @aeval _ (polynomial S) _ _ _ (X : polynomial S) /-- `map_alg` is the morphism induced by `R → S`. -/ lemma map_alg_eq_map (p : polynomial R) : map_alg R S p = map (algebra_map R S) p := by simp only [map_alg, aeval_def, eval₂, map, algebra_map_apply, ring_hom.coe_comp] /-- A polynomial `p` lifts if and only if it is in the image of `map_alg`. -/ lemma mem_lifts_iff_mem_alg (R : Type u) [comm_semiring R] {S : Type v} [semiring S] [algebra R S] (p : polynomial S) :p ∈ lifts (algebra_map R S) ↔ p ∈ (alg_hom.range (@map_alg R _ S _ _)) := by simp only [lifts, map_alg_eq_map, alg_hom.mem_range, ring_hom.coe_of, ring_hom.mem_srange] /-- If `p` lifts and `(r : R)` then `r • p` lifts. -/ lemma smul_mem_lifts {p : polynomial S} (r : R) (hp : p ∈ lifts (algebra_map R S)) : r • p ∈ lifts (algebra_map R S) := by { rw mem_lifts_iff_mem_alg at hp ⊢, exact subalgebra.smul_mem (map_alg R S).range hp r } end algebra end polynomial
4858fca8d9b4583a2ca12c719cb0b68e31c1dd87
5883d9218e6f144e20eee6ca1dab8529fa1a97c0
/src/data/sigma/extra.lean
c3be336d7caf20262630a9adb505f5e58184b426
[]
no_license
spl/alpha-conversion-is-easy
0d035bc570e52a6345d4890e4d0c9e3f9b8126c1
ed937fe85d8495daffd9412a5524c77b9fcda094
refs/heads/master
1,607,649,280,020
1,517,380,240,000
1,517,380,240,000
52,174,747
4
0
null
1,456,052,226,000
1,456,001,163,000
Lean
UTF-8
Lean
false
false
770
lean
/- This file contains extra definitions and theorems for `sigma` and `psigma`. -/ universes u v namespace psigma --------------------------------------------------------------- variables {A : Sort u} {B : A → Sort v} {a₁ a₂ : A} {b₁ : B a₁} {b₂ : B a₂} @[simp] theorem fst.unwrap (a : A) (b : B a) : (psigma.mk a b).fst = a := rfl @[simp] theorem snd.unwrap (a : A) (b : B a) : (psigma.mk a b).snd = b := rfl theorem fst.eq (P : psigma.mk a₁ b₁ = psigma.mk a₂ b₂) : a₁ = a₂ := psigma.no_confusion P (λ H₁ H₂, H₁) theorem snd.heq (P : psigma.mk a₁ b₁ = psigma.mk a₂ b₂) : b₁ == b₂ := psigma.no_confusion P (λ H₁ H₂, H₂) end /- namespace -/ psigma -----------------------------------------------------
7fdce22e41aefcf6d43b89e10dc51ce354ea6806
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/category_theory/limits/small_complete.lean
ec2c0890459c543e17f80f78aa38717665243980
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
1,404
lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Bhavik Mehta -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.limits.shapes.products import Mathlib.set_theory.cardinal import Mathlib.PostPort universes u namespace Mathlib /-! # Any small complete category is a preorder We show that any small category which has all (small) limits is a preorder: In particular, we show that if a small category `C` in universe `u` has products of size `u`, then for any `X Y : C` there is at most one morphism `X ⟶ Y`. Note that in Lean, a preorder category is strictly one where the morphisms are in `Prop`, so we instead show that the homsets are subsingleton. ## References * https://ncatlab.org/nlab/show/complete+small+category#in_classical_logic ## Tags small complete, preorder, Freyd -/ namespace category_theory /-- A small category with products is a thin category. in Lean, a preorder category is one where the morphisms are in Prop, which is weaker than the usual notion of a preorder/thin category which says that each homset is subsingleton; we show the latter rather than providing a `preorder C` instance. -/ protected instance has_hom.hom.subsingleton {C : Type u} [small_category C] [limits.has_products C] {X : C} {Y : C} : subsingleton (X ⟶ Y) := sorry
a06501afc585e4ea2dc08f44b0e13fc7f2388468
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/analysis/inner_product_space/projection.lean
da8e75c73031edb064da82fcb8de3c7501fc83a5
[ "Apache-2.0" ]
permissive
AntoineChambert-Loir/mathlib
64aabb896129885f12296a799818061bc90da1ff
07be904260ab6e36a5769680b6012f03a4727134
refs/heads/master
1,693,187,631,771
1,636,719,886,000
1,636,719,886,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
48,519
lean
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth -/ import analysis.inner_product_space.basic import analysis.convex.basic /-! # The orthogonal projection Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs `orthogonal_projection K : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map satisfies: for any point `u` in `E`, the point `v = orthogonal_projection K u` in `K` minimizes the distance `∥u - v∥` to `u`. Also a linear isometry equivalence `reflection K : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for each `u : E`, the point `reflection K u` to satisfy `u + (reflection K u) = 2 • orthogonal_projection K u`. Basic API for `orthogonal_projection` and `reflection` is developed. Next, the orthogonal projection is used to prove a series of more subtle lemmas about the the orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was defined in `analysis.inner_product_space.basic`); the lemma `submodule.sup_orthogonal_of_is_complete`, stating that for a complete subspace `K` of `E` we have `K ⊔ Kᗮ = ⊤`, is a typical example. The last section covers orthonormal bases, Hilbert bases, etc. The lemma `maximal_orthonormal_iff_dense_span`, whose proof requires the theory on the orthogonal complement developed earlier in this file, states that an orthonormal set in an inner product space is maximal, if and only if its span is dense (i.e., iff it is Hilbert basis, although we do not make that definition). Various consequences are stated, including that if `E` is finite-dimensional then a maximal orthonormal set is a basis (`maximal_orthonormal_iff_basis_of_finite_dimensional`). ## References The orthogonal projection construction is adapted from * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable theory open is_R_or_C real filter open_locale big_operators classical topological_space variables {𝕜 E F : Type*} [is_R_or_C 𝕜] variables [inner_product_space 𝕜 E] [inner_product_space ℝ F] local notation `⟪`x`, `y`⟫` := @inner 𝕜 E _ x y local notation `absR` := has_abs.abs /-! ### Orthogonal projection in inner product spaces -/ /-- Existence of minimizers Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset. Then there exists a (unique) `v` in `K` that minimizes the distance `∥u - v∥` to `u`. -/ -- FIXME this monolithic proof causes a deterministic timeout with `-T50000` -- It should be broken in a sequence of more manageable pieces, -- perhaps with individual statements for the three steps below. theorem exists_norm_eq_infi_of_complete_convex {K : set F} (ne : K.nonempty) (h₁ : is_complete K) (h₂ : convex ℝ K) : ∀ u : F, ∃ v ∈ K, ∥u - v∥ = ⨅ w : K, ∥u - w∥ := assume u, begin let δ := ⨅ w : K, ∥u - w∥, letI : nonempty K := ne.to_subtype, have zero_le_δ : 0 ≤ δ := le_cinfi (λ _, norm_nonneg _), have δ_le : ∀ w : K, δ ≤ ∥u - w∥, from cinfi_le ⟨0, set.forall_range_iff.2 $ λ _, norm_nonneg _⟩, have δ_le' : ∀ w ∈ K, δ ≤ ∥u - w∥ := assume w hw, δ_le ⟨w, hw⟩, -- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K` -- such that `∥u - w n∥ < δ + 1 / (n + 1)` (which implies `∥u - w n∥ --> δ`); -- maybe this should be a separate lemma have exists_seq : ∃ w : ℕ → K, ∀ n, ∥u - w n∥ < δ + 1 / (n + 1), { have hδ : ∀n:ℕ, δ < δ + 1 / (n + 1), from λ n, lt_add_of_le_of_pos (le_refl _) nat.one_div_pos_of_nat, have h := λ n, exists_lt_of_cinfi_lt (hδ n), let w : ℕ → K := λ n, classical.some (h n), exact ⟨w, λ n, classical.some_spec (h n)⟩ }, rcases exists_seq with ⟨w, hw⟩, have norm_tendsto : tendsto (λ n, ∥u - w n∥) at_top (nhds δ), { have h : tendsto (λ n:ℕ, δ) at_top (nhds δ) := tendsto_const_nhds, have h' : tendsto (λ n:ℕ, δ + 1 / (n + 1)) at_top (nhds δ), { convert h.add tendsto_one_div_add_at_top_nhds_0_nat, simp only [add_zero] }, exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (λ x, δ_le _) (λ x, le_of_lt (hw _)) }, -- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence have seq_is_cauchy : cauchy_seq (λ n, ((w n):F)), { rw cauchy_seq_iff_le_tendsto_0, -- splits into three goals let b := λ n:ℕ, (8 * δ * (1/(n+1)) + 4 * (1/(n+1)) * (1/(n+1))), use (λn, sqrt (b n)), split, -- first goal : `∀ (n : ℕ), 0 ≤ sqrt (b n)` assume n, exact sqrt_nonneg _, split, -- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ sqrt (b N)` assume p q N hp hq, let wp := ((w p):F), let wq := ((w q):F), let a := u - wq, let b := u - wp, let half := 1 / (2:ℝ), let div := 1 / ((N:ℝ) + 1), have : 4 * ∥u - half • (wq + wp)∥ * ∥u - half • (wq + wp)∥ + ∥wp - wq∥ * ∥wp - wq∥ = 2 * (∥a∥ * ∥a∥ + ∥b∥ * ∥b∥) := calc 4 * ∥u - half•(wq + wp)∥ * ∥u - half•(wq + wp)∥ + ∥wp - wq∥ * ∥wp - wq∥ = (2*∥u - half•(wq + wp)∥) * (2 * ∥u - half•(wq + wp)∥) + ∥wp-wq∥*∥wp-wq∥ : by ring ... = (absR ((2:ℝ)) * ∥u - half•(wq + wp)∥) * (absR ((2:ℝ)) * ∥u - half•(wq+wp)∥) + ∥wp-wq∥*∥wp-wq∥ : by { rw _root_.abs_of_nonneg, exact zero_le_two } ... = ∥(2:ℝ) • (u - half • (wq + wp))∥ * ∥(2:ℝ) • (u - half • (wq + wp))∥ + ∥wp-wq∥ * ∥wp-wq∥ : by simp [norm_smul] ... = ∥a + b∥ * ∥a + b∥ + ∥a - b∥ * ∥a - b∥ : begin rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ← one_add_one_eq_two, add_smul], simp only [one_smul], have eq₁ : wp - wq = a - b, from (sub_sub_sub_cancel_left _ _ _).symm, have eq₂ : u + u - (wq + wp) = a + b, show u + u - (wq + wp) = (u - wq) + (u - wp), abel, rw [eq₁, eq₂], end ... = 2 * (∥a∥ * ∥a∥ + ∥b∥ * ∥b∥) : parallelogram_law_with_norm, have eq : δ ≤ ∥u - half • (wq + wp)∥, { rw smul_add, apply δ_le', apply h₂, repeat {exact subtype.mem _}, repeat {exact le_of_lt one_half_pos}, exact add_halves 1 }, have eq₁ : 4 * δ * δ ≤ 4 * ∥u - half • (wq + wp)∥ * ∥u - half • (wq + wp)∥, { mono, mono, norm_num, apply mul_nonneg, norm_num, exact norm_nonneg _ }, have eq₂ : ∥a∥ * ∥a∥ ≤ (δ + div) * (δ + div) := mul_self_le_mul_self (norm_nonneg _) (le_trans (le_of_lt $ hw q) (add_le_add_left (nat.one_div_le_one_div hq) _)), have eq₂' : ∥b∥ * ∥b∥ ≤ (δ + div) * (δ + div) := mul_self_le_mul_self (norm_nonneg _) (le_trans (le_of_lt $ hw p) (add_le_add_left (nat.one_div_le_one_div hp) _)), rw dist_eq_norm, apply nonneg_le_nonneg_of_sq_le_sq, { exact sqrt_nonneg _ }, rw mul_self_sqrt, calc ∥wp - wq∥ * ∥wp - wq∥ = 2 * (∥a∥*∥a∥ + ∥b∥*∥b∥) - 4 * ∥u - half • (wq+wp)∥ * ∥u - half • (wq+wp)∥ : by { rw ← this, simp } ... ≤ 2 * (∥a∥ * ∥a∥ + ∥b∥ * ∥b∥) - 4 * δ * δ : sub_le_sub_left eq₁ _ ... ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ : sub_le_sub_right (mul_le_mul_of_nonneg_left (add_le_add eq₂ eq₂') (by norm_num)) _ ... = 8 * δ * div + 4 * div * div : by ring, exact add_nonneg (mul_nonneg (mul_nonneg (by norm_num) zero_le_δ) (le_of_lt nat.one_div_pos_of_nat)) (mul_nonneg (mul_nonneg (by norm_num) nat.one_div_pos_of_nat.le) nat.one_div_pos_of_nat.le), -- third goal : `tendsto (λ (n : ℕ), sqrt (b n)) at_top (𝓝 0)` apply tendsto.comp, { convert continuous_sqrt.continuous_at, exact sqrt_zero.symm }, have eq₁ : tendsto (λ (n : ℕ), 8 * δ * (1 / (n + 1))) at_top (nhds (0:ℝ)), { convert (@tendsto_const_nhds _ _ _ (8 * δ) _).mul tendsto_one_div_add_at_top_nhds_0_nat, simp only [mul_zero] }, have : tendsto (λ (n : ℕ), (4:ℝ) * (1 / (n + 1))) at_top (nhds (0:ℝ)), { convert (@tendsto_const_nhds _ _ _ (4:ℝ) _).mul tendsto_one_div_add_at_top_nhds_0_nat, simp only [mul_zero] }, have eq₂ : tendsto (λ (n : ℕ), (4:ℝ) * (1 / (n + 1)) * (1 / (n + 1))) at_top (nhds (0:ℝ)), { convert this.mul tendsto_one_div_add_at_top_nhds_0_nat, simp only [mul_zero] }, convert eq₁.add eq₂, simp only [add_zero] }, -- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`. -- Prove that it satisfies all requirements. rcases cauchy_seq_tendsto_of_is_complete h₁ (λ n, _) seq_is_cauchy with ⟨v, hv, w_tendsto⟩, use v, use hv, have h_cont : continuous (λ v, ∥u - v∥) := continuous.comp continuous_norm (continuous.sub continuous_const continuous_id), have : tendsto (λ n, ∥u - w n∥) at_top (nhds ∥u - v∥), convert (tendsto.comp h_cont.continuous_at w_tendsto), exact tendsto_nhds_unique this norm_tendsto, exact subtype.mem _ end /-- Characterization of minimizers for the projection on a convex set in a real inner product space. -/ theorem norm_eq_infi_iff_real_inner_le_zero {K : set F} (h : convex ℝ K) {u : F} {v : F} (hv : v ∈ K) : ∥u - v∥ = (⨅ w : K, ∥u - w∥) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := iff.intro begin assume eq w hw, let δ := ⨅ w : K, ∥u - w∥, let p := ⟪u - v, w - v⟫_ℝ, let q := ∥w - v∥^2, letI : nonempty K := ⟨⟨v, hv⟩⟩, have zero_le_δ : 0 ≤ δ, apply le_cinfi, intro, exact norm_nonneg _, have δ_le : ∀ w : K, δ ≤ ∥u - w∥, assume w, apply cinfi_le, use (0:ℝ), rintros _ ⟨_, rfl⟩, exact norm_nonneg _, have δ_le' : ∀ w ∈ K, δ ≤ ∥u - w∥ := assume w hw, δ_le ⟨w, hw⟩, have : ∀θ:ℝ, 0 < θ → θ ≤ 1 → 2 * p ≤ θ * q, assume θ hθ₁ hθ₂, have : ∥u - v∥^2 ≤ ∥u - v∥^2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ*θ*∥w - v∥^2 := calc ∥u - v∥^2 ≤ ∥u - (θ•w + (1-θ)•v)∥^2 : begin simp only [sq], apply mul_self_le_mul_self (norm_nonneg _), rw [eq], apply δ_le', apply h hw hv, exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel'_right _ _], end ... = ∥(u - v) - θ • (w - v)∥^2 : begin have : u - (θ•w + (1-θ)•v) = (u - v) - θ • (w - v), { rw [smul_sub, sub_smul, one_smul], simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev] }, rw this end ... = ∥u - v∥^2 - 2 * θ * inner (u - v) (w - v) + θ*θ*∥w - v∥^2 : begin rw [norm_sub_sq, inner_smul_right, norm_smul], simp only [sq], show ∥u-v∥*∥u-v∥-2*(θ*inner(u-v)(w-v))+absR (θ)*∥w-v∥*(absR (θ)*∥w-v∥)= ∥u-v∥*∥u-v∥-2*θ*inner(u-v)(w-v)+θ*θ*(∥w-v∥*∥w-v∥), rw abs_of_pos hθ₁, ring end, have eq₁ : ∥u-v∥^2-2*θ*inner(u-v)(w-v)+θ*θ*∥w-v∥^2=∥u-v∥^2+(θ*θ*∥w-v∥^2-2*θ*inner(u-v)(w-v)), by abel, rw [eq₁, le_add_iff_nonneg_right] at this, have eq₂ : θ*θ*∥w-v∥^2-2*θ*inner(u-v)(w-v)=θ*(θ*∥w-v∥^2-2*inner(u-v)(w-v)), ring, rw eq₂ at this, have := le_of_sub_nonneg (nonneg_of_mul_nonneg_left this hθ₁), exact this, by_cases hq : q = 0, { rw hq at this, have : p ≤ 0, have := this (1:ℝ) (by norm_num) (by norm_num), linarith, exact this }, { have q_pos : 0 < q, apply lt_of_le_of_ne, exact sq_nonneg _, intro h, exact hq h.symm, by_contradiction hp, rw not_le at hp, let θ := min (1:ℝ) (p / q), have eq₁ : θ*q ≤ p := calc θ*q ≤ (p/q) * q : mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _) ... = p : div_mul_cancel _ hq, have : 2 * p ≤ p := calc 2 * p ≤ θ*q : by { refine this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num) } ... ≤ p : eq₁, linarith } end begin assume h, letI : nonempty K := ⟨⟨v, hv⟩⟩, apply le_antisymm, { apply le_cinfi, assume w, apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _), have := h w w.2, calc ∥u - v∥ * ∥u - v∥ ≤ ∥u - v∥ * ∥u - v∥ - 2 * inner (u - v) ((w:F) - v) : by linarith ... ≤ ∥u - v∥^2 - 2 * inner (u - v) ((w:F) - v) + ∥(w:F) - v∥^2 : by { rw sq, refine le_add_of_nonneg_right _, exact sq_nonneg _ } ... = ∥(u - v) - (w - v)∥^2 : norm_sub_sq.symm ... = ∥u - w∥ * ∥u - w∥ : by { have : (u - v) - (w - v) = u - w, abel, rw [this, sq] } }, { show (⨅ (w : K), ∥u - w∥) ≤ (λw:K, ∥u - w∥) ⟨v, hv⟩, apply cinfi_le, use 0, rintros y ⟨z, rfl⟩, exact norm_nonneg _ } end variables (K : submodule 𝕜 E) /-- Existence of projections on complete subspaces. Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace. Then there exists a (unique) `v` in `K` that minimizes the distance `∥u - v∥` to `u`. This point `v` is usually called the orthogonal projection of `u` onto `K`. -/ theorem exists_norm_eq_infi_of_complete_subspace (h : is_complete (↑K : set E)) : ∀ u : E, ∃ v ∈ K, ∥u - v∥ = ⨅ w : (K : set E), ∥u - w∥ := begin letI : inner_product_space ℝ E := inner_product_space.is_R_or_C_to_real 𝕜 E, letI : module ℝ E := restrict_scalars.module ℝ 𝕜 E, letI : is_scalar_tower ℝ 𝕜 E := restrict_scalars.is_scalar_tower _ _ _, let K' : submodule ℝ E := submodule.restrict_scalars ℝ K, exact exists_norm_eq_infi_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex end /-- Characterization of minimizers in the projection on a subspace, in the real case. Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `∥u - v∥` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`). This is superceded by `norm_eq_infi_iff_inner_eq_zero` that gives the same conclusion over any `is_R_or_C` field. -/ theorem norm_eq_infi_iff_real_inner_eq_zero (K : submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) : ∥u - v∥ = (⨅ w : (↑K : set F), ∥u - w∥) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 := iff.intro begin assume h, have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0, { rwa [norm_eq_infi_iff_real_inner_le_zero] at h, exacts [K.convex, hv] }, assume w hw, have le : ⟪u - v, w⟫_ℝ ≤ 0, let w' := w + v, have : w' ∈ K := submodule.add_mem _ hw hv, have h₁ := h w' this, have h₂ : w' - v = w, simp only [add_neg_cancel_right, sub_eq_add_neg], rw h₂ at h₁, exact h₁, have ge : ⟪u - v, w⟫_ℝ ≥ 0, let w'' := -w + v, have : w'' ∈ K := submodule.add_mem _ (submodule.neg_mem _ hw) hv, have h₁ := h w'' this, have h₂ : w'' - v = -w, simp only [neg_inj, add_neg_cancel_right, sub_eq_add_neg], rw [h₂, inner_neg_right] at h₁, linarith, exact le_antisymm le ge end begin assume h, have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0, assume w hw, let w' := w - v, have : w' ∈ K := submodule.sub_mem _ hw hv, have h₁ := h w' this, exact le_of_eq h₁, rwa norm_eq_infi_iff_real_inner_le_zero, exacts [submodule.convex _, hv] end /-- Characterization of minimizers in the projection on a subspace. Let `u` be a point in an inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `∥u - v∥` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`) -/ theorem norm_eq_infi_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) : ∥u - v∥ = (⨅ w : (↑K : set E), ∥u - w∥) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := begin letI : inner_product_space ℝ E := inner_product_space.is_R_or_C_to_real 𝕜 E, letI : module ℝ E := restrict_scalars.module ℝ 𝕜 E, letI : is_scalar_tower ℝ 𝕜 E := restrict_scalars.is_scalar_tower _ _ _, let K' : submodule ℝ E := K.restrict_scalars ℝ, split, { assume H, have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (norm_eq_infi_iff_real_inner_eq_zero K' hv).1 H, assume w hw, apply ext, { simp [A w hw] }, { symmetry, calc im (0 : 𝕜) = 0 : im.map_zero ... = re ⟪u - v, (-I) • w⟫ : (A _ (K.smul_mem (-I) hw)).symm ... = re ((-I) * ⟪u - v, w⟫) : by rw inner_smul_right ... = im ⟪u - v, w⟫ : by simp } }, { assume H, have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0, { assume w hw, rw [real_inner_eq_re_inner, H w hw], exact zero_re' }, exact (norm_eq_infi_iff_real_inner_eq_zero K' hv).2 this } end section orthogonal_projection variables [complete_space K] /-- The orthogonal projection onto a complete subspace, as an unbundled function. This definition is only intended for use in setting up the bundled version `orthogonal_projection` and should not be used once that is defined. -/ def orthogonal_projection_fn (v : E) := (exists_norm_eq_infi_of_complete_subspace K (complete_space_coe_iff_is_complete.mp ‹_›) v).some variables {K} /-- The unbundled orthogonal projection is in the given subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ lemma orthogonal_projection_fn_mem (v : E) : orthogonal_projection_fn K v ∈ K := (exists_norm_eq_infi_of_complete_subspace K (complete_space_coe_iff_is_complete.mp ‹_›) v).some_spec.some /-- The characterization of the unbundled orthogonal projection. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ lemma orthogonal_projection_fn_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonal_projection_fn K v, w⟫ = 0 := begin rw ←norm_eq_infi_iff_inner_eq_zero K (orthogonal_projection_fn_mem v), exact (exists_norm_eq_infi_of_complete_subspace K (complete_space_coe_iff_is_complete.mp ‹_›) v).some_spec.some_spec end /-- The unbundled orthogonal projection is the unique point in `K` with the orthogonality property. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ lemma eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : orthogonal_projection_fn K u = v := begin rw [←sub_eq_zero, ←inner_self_eq_zero], have hvs : orthogonal_projection_fn K u - v ∈ K := submodule.sub_mem K (orthogonal_projection_fn_mem u) hvm, have huo : ⟪u - orthogonal_projection_fn K u, orthogonal_projection_fn K u - v⟫ = 0 := orthogonal_projection_fn_inner_eq_zero u _ hvs, have huv : ⟪u - v, orthogonal_projection_fn K u - v⟫ = 0 := hvo _ hvs, have houv : ⟪(u - v) - (u - orthogonal_projection_fn K u), orthogonal_projection_fn K u - v⟫ = 0, { rw [inner_sub_left, huo, huv, sub_zero] }, rwa sub_sub_sub_cancel_left at houv end variables (K) lemma orthogonal_projection_fn_norm_sq (v : E) : ∥v∥ * ∥v∥ = ∥v - (orthogonal_projection_fn K v)∥ * ∥v - (orthogonal_projection_fn K v)∥ + ∥orthogonal_projection_fn K v∥ * ∥orthogonal_projection_fn K v∥ := begin set p := orthogonal_projection_fn K v, have h' : ⟪v - p, p⟫ = 0, { exact orthogonal_projection_fn_inner_eq_zero _ _ (orthogonal_projection_fn_mem v) }, convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2; simp, end /-- The orthogonal projection onto a complete subspace. -/ def orthogonal_projection : E →L[𝕜] K := linear_map.mk_continuous { to_fun := λ v, ⟨orthogonal_projection_fn K v, orthogonal_projection_fn_mem v⟩, map_add' := λ x y, begin have hm : orthogonal_projection_fn K x + orthogonal_projection_fn K y ∈ K := submodule.add_mem K (orthogonal_projection_fn_mem x) (orthogonal_projection_fn_mem y), have ho : ∀ w ∈ K, ⟪x + y - (orthogonal_projection_fn K x + orthogonal_projection_fn K y), w⟫ = 0, { intros w hw, rw [add_sub_comm, inner_add_left, orthogonal_projection_fn_inner_eq_zero _ w hw, orthogonal_projection_fn_inner_eq_zero _ w hw, add_zero] }, ext, simp [eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hm ho] end, map_smul' := λ c x, begin have hm : c • orthogonal_projection_fn K x ∈ K := submodule.smul_mem K _ (orthogonal_projection_fn_mem x), have ho : ∀ w ∈ K, ⟪c • x - c • orthogonal_projection_fn K x, w⟫ = 0, { intros w hw, rw [←smul_sub, inner_smul_left, orthogonal_projection_fn_inner_eq_zero _ w hw, mul_zero] }, ext, simp [eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hm ho] end } 1 (λ x, begin simp only [one_mul, linear_map.coe_mk], refine le_of_pow_le_pow 2 (norm_nonneg _) (by norm_num) _, change ∥orthogonal_projection_fn K x∥ ^ 2 ≤ ∥x∥ ^ 2, nlinarith [orthogonal_projection_fn_norm_sq K x] end) variables {K} @[simp] lemma orthogonal_projection_fn_eq (v : E) : orthogonal_projection_fn K v = (orthogonal_projection K v : E) := rfl /-- The characterization of the orthogonal projection. -/ @[simp] lemma orthogonal_projection_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonal_projection K v, w⟫ = 0 := orthogonal_projection_fn_inner_eq_zero v /-- The orthogonal projection is the unique point in `K` with the orthogonality property. -/ lemma eq_orthogonal_projection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (orthogonal_projection K u : E) = v := eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hvm hvo /-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/ lemma eq_orthogonal_projection_of_eq_submodule {K' : submodule 𝕜 E} [complete_space K'] (h : K = K') (u : E) : (orthogonal_projection K u : E) = (orthogonal_projection K' u : E) := begin change orthogonal_projection_fn K u = orthogonal_projection_fn K' u, congr, exact h end /-- The orthogonal projection sends elements of `K` to themselves. -/ @[simp] lemma orthogonal_projection_mem_subspace_eq_self (v : K) : orthogonal_projection K v = v := by { ext, apply eq_orthogonal_projection_of_mem_of_inner_eq_zero; simp } /-- A point equals its orthogonal projection if and only if it lies in the subspace. -/ lemma orthogonal_projection_eq_self_iff {v : E} : (orthogonal_projection K v : E) = v ↔ v ∈ K := begin refine ⟨λ h, _, λ h, eq_orthogonal_projection_of_mem_of_inner_eq_zero h _⟩, { rw ← h, simp }, { simp } end /-- Orthogonal projection onto the `submodule.map` of a subspace. -/ lemma orthogonal_projection_map_apply {E E' : Type*} [inner_product_space 𝕜 E] [inner_product_space 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (p : submodule 𝕜 E) [finite_dimensional 𝕜 p] (x : E') : (orthogonal_projection (p.map (f.to_linear_equiv : E →ₗ[𝕜] E')) x : E') = f (orthogonal_projection p (f.symm x)) := begin apply eq_orthogonal_projection_of_mem_of_inner_eq_zero, { exact ⟨orthogonal_projection p (f.symm x), submodule.coe_mem _, by simp⟩, }, rintros w ⟨a, ha, rfl⟩, suffices : inner (f (f.symm x - orthogonal_projection p (f.symm x))) (f a) = (0:𝕜), { simpa using this }, rw f.inner_map_map, exact orthogonal_projection_inner_eq_zero _ _ ha, end /-- The orthogonal projection onto the trivial submodule is the zero map. -/ @[simp] lemma orthogonal_projection_bot : orthogonal_projection (⊥ : submodule 𝕜 E) = 0 := by ext variables (K) /-- The orthogonal projection has norm `≤ 1`. -/ lemma orthogonal_projection_norm_le : ∥orthogonal_projection K∥ ≤ 1 := linear_map.mk_continuous_norm_le _ (by norm_num) _ variables (𝕜) lemma smul_orthogonal_projection_singleton {v : E} (w : E) : (∥v∥ ^ 2 : 𝕜) • (orthogonal_projection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := begin suffices : ↑(orthogonal_projection (𝕜 ∙ v) ((∥v∥ ^ 2 : 𝕜) • w)) = ⟪v, w⟫ • v, { simpa using this }, apply eq_orthogonal_projection_of_mem_of_inner_eq_zero, { rw submodule.mem_span_singleton, use ⟪v, w⟫ }, { intros x hx, obtain ⟨c, rfl⟩ := submodule.mem_span_singleton.mp hx, have hv : ↑∥v∥ ^ 2 = ⟪v, v⟫ := by { norm_cast, simp [norm_sq_eq_inner] }, simp [inner_sub_left, inner_smul_left, inner_smul_right, ring_equiv.map_div, mul_comm, hv, inner_product_space.conj_sym, hv] } end /-- Formula for orthogonal projection onto a single vector. -/ lemma orthogonal_projection_singleton {v : E} (w : E) : (orthogonal_projection (𝕜 ∙ v) w : E) = (⟪v, w⟫ / ∥v∥ ^ 2) • v := begin by_cases hv : v = 0, { rw [hv, eq_orthogonal_projection_of_eq_submodule submodule.span_zero_singleton], { simp }, { apply_instance } }, have hv' : ∥v∥ ≠ 0 := ne_of_gt (norm_pos_iff.mpr hv), have key : ((∥v∥ ^ 2 : 𝕜)⁻¹ * ∥v∥ ^ 2) • ↑(orthogonal_projection (𝕜 ∙ v) w) = ((∥v∥ ^ 2 : 𝕜)⁻¹ * ⟪v, w⟫) • v, { simp [mul_smul, smul_orthogonal_projection_singleton 𝕜 w] }, convert key; field_simp [hv'] end /-- Formula for orthogonal projection onto a single unit vector. -/ lemma orthogonal_projection_unit_singleton {v : E} (hv : ∥v∥ = 1) (w : E) : (orthogonal_projection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := by { rw ← smul_orthogonal_projection_singleton 𝕜 w, simp [hv] } end orthogonal_projection section reflection variables {𝕜} (K) [complete_space K] /-- Auxiliary definition for `reflection`: the reflection as a linear equivalence. -/ def reflection_linear_equiv : E ≃ₗ[𝕜] E := linear_equiv.of_involutive (bit0 (K.subtype.comp (orthogonal_projection K).to_linear_map) - linear_map.id) (λ x, by simp [bit0]) /-- Reflection in a complete subspace of an inner product space. The word "reflection" is sometimes understood to mean specifically reflection in a codimension-one subspace, and sometimes more generally to cover operations such as reflection in a point. The definition here, of reflection in a subspace, is a more general sense of the word that includes both those common cases. -/ def reflection : E ≃ₗᵢ[𝕜] E := { norm_map' := begin intros x, let w : K := orthogonal_projection K x, let v := x - w, have : ⟪v, w⟫ = 0 := orthogonal_projection_inner_eq_zero x w w.2, convert norm_sub_eq_norm_add this using 2, { rw [linear_equiv.coe_mk, reflection_linear_equiv, linear_equiv.to_fun_eq_coe, linear_equiv.coe_of_involutive, linear_map.sub_apply, linear_map.id_apply, bit0, linear_map.add_apply, linear_map.comp_apply, submodule.subtype_apply, continuous_linear_map.to_linear_map_eq_coe, continuous_linear_map.coe_coe], dsimp [w, v], abel, }, { simp only [add_sub_cancel'_right, eq_self_iff_true], } end, ..reflection_linear_equiv K } variables {K} /-- The result of reflecting. -/ lemma reflection_apply (p : E) : reflection K p = bit0 ↑(orthogonal_projection K p) - p := rfl /-- Reflection is its own inverse. -/ @[simp] lemma reflection_symm : (reflection K).symm = reflection K := rfl variables (K) /-- Reflecting twice in the same subspace. -/ @[simp] lemma reflection_reflection (p : E) : reflection K (reflection K p) = p := (reflection K).left_inv p /-- Reflection is involutive. -/ lemma reflection_involutive : function.involutive (reflection K) := reflection_reflection K variables {K} /-- A point is its own reflection if and only if it is in the subspace. -/ lemma reflection_eq_self_iff (x : E) : reflection K x = x ↔ x ∈ K := begin rw [←orthogonal_projection_eq_self_iff, reflection_apply, sub_eq_iff_eq_add', ← two_smul 𝕜, ← two_smul' 𝕜], refine (smul_right_injective E _).eq_iff, exact two_ne_zero end lemma reflection_mem_subspace_eq_self {x : E} (hx : x ∈ K) : reflection K x = x := (reflection_eq_self_iff x).mpr hx /-- Reflection in the `submodule.map` of a subspace. -/ lemma reflection_map_apply {E E' : Type*} [inner_product_space 𝕜 E] [inner_product_space 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : submodule 𝕜 E) [finite_dimensional 𝕜 K] (x : E') : reflection (K.map (f.to_linear_equiv : E →ₗ[𝕜] E')) x = f (reflection K (f.symm x)) := by simp [bit0, reflection_apply, orthogonal_projection_map_apply f K x] /-- Reflection in the `submodule.map` of a subspace. -/ lemma reflection_map {E E' : Type*} [inner_product_space 𝕜 E] [inner_product_space 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : submodule 𝕜 E) [finite_dimensional 𝕜 K] : reflection (K.map (f.to_linear_equiv : E →ₗ[𝕜] E')) = f.symm.trans ((reflection K).trans f) := linear_isometry_equiv.ext $ reflection_map_apply f K /-- Reflection through the trivial subspace {0} is just negation. -/ @[simp] lemma reflection_bot : reflection (⊥ : submodule 𝕜 E) = linear_isometry_equiv.neg 𝕜 := by ext; simp [reflection_apply] end reflection section orthogonal /-- If `K₁` is complete and contained in `K₂`, `K₁` and `K₁ᗮ ⊓ K₂` span `K₂`. -/ lemma submodule.sup_orthogonal_inf_of_is_complete {K₁ K₂ : submodule 𝕜 E} (h : K₁ ≤ K₂) (hc : is_complete (K₁ : set E)) : K₁ ⊔ (K₁ᗮ ⊓ K₂) = K₂ := begin ext x, rw submodule.mem_sup, rcases exists_norm_eq_infi_of_complete_subspace K₁ hc x with ⟨v, hv, hvm⟩, rw norm_eq_infi_iff_inner_eq_zero K₁ hv at hvm, split, { rintro ⟨y, hy, z, hz, rfl⟩, exact K₂.add_mem (h hy) hz.2 }, { exact λ hx, ⟨v, hv, x - v, ⟨(K₁.mem_orthogonal' _).2 hvm, K₂.sub_mem hx (h hv)⟩, add_sub_cancel'_right _ _⟩ } end variables {K} /-- If `K` is complete, `K` and `Kᗮ` span the whole space. -/ lemma submodule.sup_orthogonal_of_is_complete (h : is_complete (K : set E)) : K ⊔ Kᗮ = ⊤ := begin convert submodule.sup_orthogonal_inf_of_is_complete (le_top : K ≤ ⊤) h, simp end /-- If `K` is complete, `K` and `Kᗮ` span the whole space. Version using `complete_space`. -/ lemma submodule.sup_orthogonal_of_complete_space [complete_space K] : K ⊔ Kᗮ = ⊤ := submodule.sup_orthogonal_of_is_complete (complete_space_coe_iff_is_complete.mp ‹_›) variables (K) /-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `Kᗮ`. -/ lemma submodule.exists_sum_mem_mem_orthogonal [complete_space K] (v : E) : ∃ (y ∈ K) (z ∈ Kᗮ), v = y + z := begin have h_mem : v ∈ K ⊔ Kᗮ := by simp [submodule.sup_orthogonal_of_complete_space], obtain ⟨y, hy, z, hz, hyz⟩ := submodule.mem_sup.mp h_mem, exact ⟨y, hy, z, hz, hyz.symm⟩ end /-- If `K` is complete, then the orthogonal complement of its orthogonal complement is itself. -/ @[simp] lemma submodule.orthogonal_orthogonal [complete_space K] : Kᗮᗮ = K := begin ext v, split, { obtain ⟨y, hy, z, hz, rfl⟩ := K.exists_sum_mem_mem_orthogonal v, intros hv, have hz' : z = 0, { have hyz : ⟪z, y⟫ = 0 := by simp [hz y hy, inner_eq_zero_sym], simpa [inner_add_right, hyz] using hv z hz }, simp [hy, hz'] }, { intros hv w hw, rw inner_eq_zero_sym, exact hw v hv } end lemma submodule.orthogonal_orthogonal_eq_closure [complete_space E] : Kᗮᗮ = K.topological_closure := begin refine le_antisymm _ _, { convert submodule.orthogonal_orthogonal_monotone K.submodule_topological_closure, haveI : complete_space K.topological_closure := K.is_closed_topological_closure.complete_space_coe, rw K.topological_closure.orthogonal_orthogonal }, { exact K.topological_closure_minimal K.le_orthogonal_orthogonal Kᗮ.is_closed_orthogonal } end variables {K} /-- If `K` is complete, `K` and `Kᗮ` are complements of each other. -/ lemma submodule.is_compl_orthogonal_of_is_complete (h : is_complete (K : set E)) : is_compl K Kᗮ := ⟨K.orthogonal_disjoint, le_of_eq (submodule.sup_orthogonal_of_is_complete h).symm⟩ @[simp] lemma submodule.orthogonal_eq_bot_iff (hK : is_complete (K : set E)) : Kᗮ = ⊥ ↔ K = ⊤ := begin refine ⟨_, by { rintro rfl, exact submodule.top_orthogonal_eq_bot }⟩, intro h, have : K ⊔ Kᗮ = ⊤ := submodule.sup_orthogonal_of_is_complete hK, rwa [h, sup_comm, bot_sup_eq] at this, end /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ lemma eq_orthogonal_projection_of_mem_orthogonal [complete_space K] {u v : E} (hv : v ∈ K) (hvo : u - v ∈ Kᗮ) : (orthogonal_projection K u : E) = v := eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hv (λ w, inner_eq_zero_sym.mp ∘ (hvo w)) /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ lemma eq_orthogonal_projection_of_mem_orthogonal' [complete_space K] {u v z : E} (hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (orthogonal_projection K u : E) = v := eq_orthogonal_projection_of_mem_orthogonal hv (by simpa [hu]) /-- The orthogonal projection onto `K` of an element of `Kᗮ` is zero. -/ lemma orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero [complete_space K] {v : E} (hv : v ∈ Kᗮ) : orthogonal_projection K v = 0 := by { ext, convert eq_orthogonal_projection_of_mem_orthogonal _ _; simp [hv] } /-- The reflection in `K` of an element of `Kᗮ` is its negation. -/ lemma reflection_mem_subspace_orthogonal_complement_eq_neg [complete_space K] {v : E} (hv : v ∈ Kᗮ) : reflection K v = - v := by simp [reflection_apply, orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero hv] /-- The orthogonal projection onto `Kᗮ` of an element of `K` is zero. -/ lemma orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero [complete_space E] {v : E} (hv : v ∈ K) : orthogonal_projection Kᗮ v = 0 := orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero (K.le_orthogonal_orthogonal hv) /-- The reflection in `Kᗮ` of an element of `K` is its negation. -/ lemma reflection_mem_subspace_orthogonal_precomplement_eq_neg [complete_space E] {v : E} (hv : v ∈ K) : reflection Kᗮ v = -v := reflection_mem_subspace_orthogonal_complement_eq_neg (K.le_orthogonal_orthogonal hv) /-- The orthogonal projection onto `(𝕜 ∙ v)ᗮ` of `v` is zero. -/ lemma orthogonal_projection_orthogonal_complement_singleton_eq_zero [complete_space E] (v : E) : orthogonal_projection (𝕜 ∙ v)ᗮ v = 0 := orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero (submodule.mem_span_singleton_self v) /-- The reflection in `(𝕜 ∙ v)ᗮ` of `v` is `-v`. -/ lemma reflection_orthogonal_complement_singleton_eq_neg [complete_space E] (v : E) : reflection (𝕜 ∙ v)ᗮ v = -v := reflection_mem_subspace_orthogonal_precomplement_eq_neg (submodule.mem_span_singleton_self v) variables (K) /-- In a complete space `E`, a vector splits as the sum of its orthogonal projections onto a complete submodule `K` and onto the orthogonal complement of `K`.-/ lemma eq_sum_orthogonal_projection_self_orthogonal_complement [complete_space E] [complete_space K] (w : E) : w = (orthogonal_projection K w : E) + (orthogonal_projection Kᗮ w : E) := begin obtain ⟨y, hy, z, hz, hwyz⟩ := K.exists_sum_mem_mem_orthogonal w, convert hwyz, { exact eq_orthogonal_projection_of_mem_orthogonal' hy hz hwyz }, { rw add_comm at hwyz, refine eq_orthogonal_projection_of_mem_orthogonal' hz _ hwyz, simp [hy] } end /-- In a complete space `E`, the projection maps onto a complete subspace `K` and its orthogonal complement sum to the identity. -/ lemma id_eq_sum_orthogonal_projection_self_orthogonal_complement [complete_space E] [complete_space K] : continuous_linear_map.id 𝕜 E = K.subtypeL.comp (orthogonal_projection K) + Kᗮ.subtypeL.comp (orthogonal_projection Kᗮ) := by { ext w, exact eq_sum_orthogonal_projection_self_orthogonal_complement K w } /-- The orthogonal projection is self-adjoint. -/ lemma inner_orthogonal_projection_left_eq_right [complete_space E] [complete_space K] (u v : E) : ⟪↑(orthogonal_projection K u), v⟫ = ⟪u, orthogonal_projection K v⟫ := begin nth_rewrite 0 eq_sum_orthogonal_projection_self_orthogonal_complement K v, nth_rewrite 1 eq_sum_orthogonal_projection_self_orthogonal_complement K u, rw [inner_add_left, inner_add_right, submodule.inner_right_of_mem_orthogonal (submodule.coe_mem (orthogonal_projection K u)) (submodule.coe_mem (orthogonal_projection Kᗮ v)), submodule.inner_left_of_mem_orthogonal (submodule.coe_mem (orthogonal_projection K v)) (submodule.coe_mem (orthogonal_projection Kᗮ u))], end open finite_dimensional /-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁` containined in it, the dimensions of `K₁` and the intersection of its orthogonal subspace with `K₂` add to that of `K₂`. -/ lemma submodule.finrank_add_inf_finrank_orthogonal {K₁ K₂ : submodule 𝕜 E} [finite_dimensional 𝕜 K₂] (h : K₁ ≤ K₂) : finrank 𝕜 K₁ + finrank 𝕜 (K₁ᗮ ⊓ K₂ : submodule 𝕜 E) = finrank 𝕜 K₂ := begin haveI := submodule.finite_dimensional_of_le h, have hd := submodule.dim_sup_add_dim_inf_eq K₁ (K₁ᗮ ⊓ K₂), rw [←inf_assoc, (submodule.orthogonal_disjoint K₁).eq_bot, bot_inf_eq, finrank_bot, submodule.sup_orthogonal_inf_of_is_complete h (submodule.complete_of_finite_dimensional _)] at hd, rw add_zero at hd, exact hd.symm end /-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁` containined in it, the dimensions of `K₁` and the intersection of its orthogonal subspace with `K₂` add to that of `K₂`. -/ lemma submodule.finrank_add_inf_finrank_orthogonal' {K₁ K₂ : submodule 𝕜 E} [finite_dimensional 𝕜 K₂] (h : K₁ ≤ K₂) {n : ℕ} (h_dim : finrank 𝕜 K₁ + n = finrank 𝕜 K₂) : finrank 𝕜 (K₁ᗮ ⊓ K₂ : submodule 𝕜 E) = n := by { rw ← add_right_inj (finrank 𝕜 K₁), simp [submodule.finrank_add_inf_finrank_orthogonal h, h_dim] } /-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `Kᗮ` add to that of `E`. -/ lemma submodule.finrank_add_finrank_orthogonal [finite_dimensional 𝕜 E] {K : submodule 𝕜 E} : finrank 𝕜 K + finrank 𝕜 Kᗮ = finrank 𝕜 E := begin convert submodule.finrank_add_inf_finrank_orthogonal (le_top : K ≤ ⊤) using 1, { rw inf_top_eq }, { simp } end /-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `Kᗮ` add to that of `E`. -/ lemma submodule.finrank_add_finrank_orthogonal' [finite_dimensional 𝕜 E] {K : submodule 𝕜 E} {n : ℕ} (h_dim : finrank 𝕜 K + n = finrank 𝕜 E) : finrank 𝕜 Kᗮ = n := by { rw ← add_right_inj (finrank 𝕜 K), simp [submodule.finrank_add_finrank_orthogonal, h_dim] } local attribute [instance] fact_finite_dimensional_of_finrank_eq_succ /-- In a finite-dimensional inner product space, the dimension of the orthogonal complement of the span of a nonzero vector is one less than the dimension of the space. -/ lemma finrank_orthogonal_span_singleton {n : ℕ} [_i : fact (finrank 𝕜 E = n + 1)] {v : E} (hv : v ≠ 0) : finrank 𝕜 (𝕜 ∙ v)ᗮ = n := submodule.finrank_add_finrank_orthogonal' $ by simp [finrank_span_singleton hv, _i.elim, add_comm] end orthogonal section orthogonal_family variables {ι : Type*} /-- An orthogonal family of subspaces of `E` satisfies `direct_sum.submodule_is_internal` (that is, they provide an internal direct sum decomposition of `E`) if and only if their span has trivial orthogonal complement. -/ lemma orthogonal_family.submodule_is_internal_iff [finite_dimensional 𝕜 E] {V : ι → submodule 𝕜 E} (hV : orthogonal_family 𝕜 V) : direct_sum.submodule_is_internal V ↔ (supr V)ᗮ = ⊥ := by simp only [direct_sum.submodule_is_internal_iff_independent_and_supr_eq_top, hV.independent, true_and, submodule.orthogonal_eq_bot_iff (supr V).complete_of_finite_dimensional] end orthogonal_family section orthonormal_basis /-! ### Existence of Hilbert basis, orthonormal basis, etc. -/ variables {𝕜 E} {v : set E} open finite_dimensional submodule set /-- An orthonormal set in an `inner_product_space` is maximal, if and only if the orthogonal complement of its span is empty. -/ lemma maximal_orthonormal_iff_orthogonal_complement_eq_bot (hv : orthonormal 𝕜 (coe : v → E)) : (∀ u ⊇ v, orthonormal 𝕜 (coe : u → E) → u = v) ↔ (span 𝕜 v)ᗮ = ⊥ := begin rw submodule.eq_bot_iff, split, { contrapose!, -- ** direction 1: nonempty orthogonal complement implies nonmaximal rintros ⟨x, hx', hx⟩, -- take a nonzero vector and normalize it let e := (∥x∥⁻¹ : 𝕜) • x, have he : ∥e∥ = 1 := by simp [e, norm_smul_inv_norm hx], have he' : e ∈ (span 𝕜 v)ᗮ := smul_mem' _ _ hx', have he'' : e ∉ v, { intros hev, have : e = 0, { have : e ∈ (span 𝕜 v) ⊓ (span 𝕜 v)ᗮ := ⟨subset_span hev, he'⟩, simpa [(span 𝕜 v).inf_orthogonal_eq_bot] using this }, have : e ≠ 0 := hv.ne_zero ⟨e, hev⟩, contradiction }, -- put this together with `v` to provide a candidate orthonormal basis for the whole space refine ⟨v.insert e, v.subset_insert e, ⟨_, _⟩, (v.ne_insert_of_not_mem he'').symm⟩, { -- show that the elements of `v.insert e` have unit length rintros ⟨a, ha'⟩, cases eq_or_mem_of_mem_insert ha' with ha ha, { simp [ha, he] }, { exact hv.1 ⟨a, ha⟩ } }, { -- show that the elements of `v.insert e` are orthogonal have h_end : ∀ a ∈ v, ⟪a, e⟫ = 0, { intros a ha, exact he' a (submodule.subset_span ha) }, rintros ⟨a, ha'⟩, cases eq_or_mem_of_mem_insert ha' with ha ha, { rintros ⟨b, hb'⟩ hab', have hb : b ∈ v, { refine mem_of_mem_insert_of_ne hb' _, intros hbe', apply hab', simp [ha, hbe'] }, rw inner_eq_zero_sym, simpa [ha] using h_end b hb }, rintros ⟨b, hb'⟩ hab', cases eq_or_mem_of_mem_insert hb' with hb hb, { simpa [hb] using h_end a ha }, have : (⟨a, ha⟩ : v) ≠ ⟨b, hb⟩, { intros hab'', apply hab', simpa using hab'' }, exact hv.2 this } }, { -- ** direction 2: empty orthogonal complement implies maximal simp only [subset.antisymm_iff], rintros h u (huv : v ⊆ u) hu, refine ⟨_, huv⟩, intros x hxu, refine ((mt (h x)) (hu.ne_zero ⟨x, hxu⟩)).imp_symm _, intros hxv y hy, have hxv' : (⟨x, hxu⟩ : u) ∉ (coe ⁻¹' v : set u) := by simp [huv, hxv], obtain ⟨l, hl, rfl⟩ : ∃ l ∈ finsupp.supported 𝕜 𝕜 (coe ⁻¹' v : set u), (finsupp.total ↥u E 𝕜 coe) l = y, { rw ← finsupp.mem_span_image_iff_total, simp [huv, inter_eq_self_of_subset_left, hy] }, exact hu.inner_finsupp_eq_zero hxv' hl } end /-- An orthonormal set in an `inner_product_space` is maximal, if and only if the closure of its span is the whole space. -/ lemma maximal_orthonormal_iff_dense_span [complete_space E] (hv : orthonormal 𝕜 (coe : v → E)) : (∀ u ⊇ v, orthonormal 𝕜 (coe : u → E) → u = v) ↔ (span 𝕜 v).topological_closure = ⊤ := by rw [maximal_orthonormal_iff_orthogonal_complement_eq_bot hv, ← submodule.orthogonal_eq_top_iff, (span 𝕜 v).orthogonal_orthogonal_eq_closure] /-- Any orthonormal subset can be extended to an orthonormal set whose span is dense. -/ lemma exists_subset_is_orthonormal_dense_span [complete_space E] (hv : orthonormal 𝕜 (coe : v → E)) : ∃ u ⊇ v, orthonormal 𝕜 (coe : u → E) ∧ (span 𝕜 u).topological_closure = ⊤ := begin obtain ⟨u, hus, hu, hu_max⟩ := exists_maximal_orthonormal hv, rw maximal_orthonormal_iff_dense_span hu at hu_max, exact ⟨u, hus, hu, hu_max⟩ end variables (𝕜 E) /-- An inner product space admits an orthonormal set whose span is dense. -/ lemma exists_is_orthonormal_dense_span [complete_space E] : ∃ u : set E, orthonormal 𝕜 (coe : u → E) ∧ (span 𝕜 u).topological_closure = ⊤ := let ⟨u, hus, hu, hu_max⟩ := exists_subset_is_orthonormal_dense_span (orthonormal_empty 𝕜 E) in ⟨u, hu, hu_max⟩ variables {𝕜 E} /-- An orthonormal set in a finite-dimensional `inner_product_space` is maximal, if and only if it is a basis. -/ lemma maximal_orthonormal_iff_basis_of_finite_dimensional [finite_dimensional 𝕜 E] (hv : orthonormal 𝕜 (coe : v → E)) : (∀ u ⊇ v, orthonormal 𝕜 (coe : u → E) → u = v) ↔ ∃ b : basis v 𝕜 E, ⇑b = coe := begin rw maximal_orthonormal_iff_orthogonal_complement_eq_bot hv, have hv_compl : is_complete (span 𝕜 v : set E) := (span 𝕜 v).complete_of_finite_dimensional, rw submodule.orthogonal_eq_bot_iff hv_compl, have hv_coe : range (coe : v → E) = v := by simp, split, { refine λ h, ⟨basis.mk hv.linear_independent _, basis.coe_mk _ _⟩, convert h }, { rintros ⟨h, coe_h⟩, rw [← h.span_eq, coe_h, hv_coe] } end /-- In a finite-dimensional `inner_product_space`, any orthonormal subset can be extended to an orthonormal basis. -/ lemma exists_subset_is_orthonormal_basis [finite_dimensional 𝕜 E] (hv : orthonormal 𝕜 (coe : v → E)) : ∃ (u ⊇ v) (b : basis u 𝕜 E), orthonormal 𝕜 b ∧ ⇑b = coe := begin obtain ⟨u, hus, hu, hu_max⟩ := exists_maximal_orthonormal hv, obtain ⟨b, hb⟩ := (maximal_orthonormal_iff_basis_of_finite_dimensional hu).mp hu_max, exact ⟨u, hus, b, by rwa hb, hb⟩ end variables (𝕜 E) /-- Index for an arbitrary orthonormal basis on a finite-dimensional `inner_product_space`. -/ def orthonormal_basis_index [finite_dimensional 𝕜 E] : set E := classical.some (exists_subset_is_orthonormal_basis (orthonormal_empty 𝕜 E)) /-- A finite-dimensional `inner_product_space` has an orthonormal basis. -/ def orthonormal_basis [finite_dimensional 𝕜 E] : basis (orthonormal_basis_index 𝕜 E) 𝕜 E := (exists_subset_is_orthonormal_basis (orthonormal_empty 𝕜 E)).some_spec.some_spec.some lemma orthonormal_basis_orthonormal [finite_dimensional 𝕜 E] : orthonormal 𝕜 (orthonormal_basis 𝕜 E) := (exists_subset_is_orthonormal_basis (orthonormal_empty 𝕜 E)).some_spec.some_spec.some_spec.1 @[simp] lemma coe_orthonormal_basis [finite_dimensional 𝕜 E] : ⇑(orthonormal_basis 𝕜 E) = coe := (exists_subset_is_orthonormal_basis (orthonormal_empty 𝕜 E)).some_spec.some_spec.some_spec.2 instance [finite_dimensional 𝕜 E] : fintype (orthonormal_basis_index 𝕜 E) := @is_noetherian.fintype_basis_index _ _ _ _ _ _ _ (is_noetherian.iff_fg.2 infer_instance) (orthonormal_basis 𝕜 E) variables {𝕜 E} /-- An `n`-dimensional `inner_product_space` has an orthonormal basis indexed by `fin n`. -/ def fin_orthonormal_basis [finite_dimensional 𝕜 E] {n : ℕ} (hn : finrank 𝕜 E = n) : basis (fin n) 𝕜 E := have h : fintype.card (orthonormal_basis_index 𝕜 E) = n, by rw [← finrank_eq_card_basis (orthonormal_basis 𝕜 E), hn], (orthonormal_basis 𝕜 E).reindex (fintype.equiv_fin_of_card_eq h) lemma fin_orthonormal_basis_orthonormal [finite_dimensional 𝕜 E] {n : ℕ} (hn : finrank 𝕜 E = n) : orthonormal 𝕜 (fin_orthonormal_basis hn) := suffices orthonormal 𝕜 (orthonormal_basis _ _ ∘ equiv.symm _), by { simp only [fin_orthonormal_basis, basis.coe_reindex], assumption }, -- why doesn't simpa work? (orthonormal_basis_orthonormal 𝕜 E).comp _ (equiv.injective _) end orthonormal_basis
d1c9b2be233f04d8862a9d7f03ecb4a8e5e61cb1
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/topology/uniform_space/separation.lean
aff8310e801ef3a5215b07c63f3fba0d43344c8c
[ "Apache-2.0" ]
permissive
fpvandoorn/mathlib
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
refs/heads/master
1,624,791,089,608
1,556,715,231,000
1,556,715,231,000
165,722,980
5
0
Apache-2.0
1,552,657,455,000
1,547,494,646,000
Lean
UTF-8
Lean
false
false
13,591
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot Hausdorff properties of uniform spaces. Separation quotient. -/ import topology.uniform_space.basic open filter topological_space lattice set classical local attribute [instance, priority 0] prop_decidable noncomputable theory set_option eqn_compiler.zeta true universes u v w variables {α : Type u} {β : Type v} {γ : Type w} variables [uniform_space α] [uniform_space β] [uniform_space γ] local notation `𝓤` := uniformity /- separated uniformity -/ /-- The separation relation is the intersection of all entourages. Two points which are related by the separation relation are "indistinguishable" according to the uniform structure. -/ protected def separation_rel (α : Type u) [u : uniform_space α] := ⋂₀ (𝓤 α).sets lemma separated_equiv : equivalence (λx y, (x, y) ∈ separation_rel α) := ⟨assume x, assume s, refl_mem_uniformity, assume x y, assume h (s : set (α×α)) hs, have preimage prod.swap s ∈ 𝓤 α, from symm_le_uniformity hs, h _ this, assume x y z (hxy : (x, y) ∈ separation_rel α) (hyz : (y, z) ∈ separation_rel α) s (hs : s ∈ 𝓤 α), let ⟨t, ht, (h_ts : comp_rel t t ⊆ s)⟩ := comp_mem_uniformity_sets hs in h_ts $ show (x, z) ∈ comp_rel t t, from ⟨y, hxy t ht, hyz t ht⟩⟩ @[class] def separated (α : Type u) [uniform_space α] := separation_rel α = id_rel theorem separated_def {α : Type u} [uniform_space α] : separated α ↔ ∀ x y, (∀ r ∈ 𝓤 α, (x, y) ∈ r) → x = y := by simp [separated, id_rel_subset.2 separated_equiv.1, subset.antisymm_iff]; simp [subset_def, separation_rel] theorem separated_def' {α : Type u} [uniform_space α] : separated α ↔ ∀ x y, x ≠ y → ∃ r ∈ 𝓤 α, (x, y) ∉ r := separated_def.trans $ forall_congr $ λ x, forall_congr $ λ y, by rw ← not_imp_not; simp [classical.not_forall] instance separated_t2 [s : separated α] : t2_space α := ⟨assume x y, assume h : x ≠ y, let ⟨d, hd, (hxy : (x, y) ∉ d)⟩ := separated_def'.1 s x y h in let ⟨d', hd', (hd'd' : comp_rel d' d' ⊆ d)⟩ := comp_mem_uniformity_sets hd in have {y | (x, y) ∈ d'} ∈ nhds x, from mem_nhds_left x hd', let ⟨u, hu₁, hu₂, hu₃⟩ := mem_nhds_sets_iff.mp this in have {x | (x, y) ∈ d'} ∈ nhds y, from mem_nhds_right y hd', let ⟨v, hv₁, hv₂, hv₃⟩ := mem_nhds_sets_iff.mp this in have u ∩ v = ∅, from eq_empty_of_subset_empty $ assume z ⟨(h₁ : z ∈ u), (h₂ : z ∈ v)⟩, have (x, y) ∈ comp_rel d' d', from ⟨z, hu₁ h₁, hv₁ h₂⟩, hxy $ hd'd' this, ⟨u, v, hu₂, hv₂, hu₃, hv₃, this⟩⟩ instance separated_regular [separated α] : regular_space α := { regular := λs a hs ha, have -s ∈ nhds a, from mem_nhds_sets hs ha, have {p : α × α | p.1 = a → p.2 ∈ -s} ∈ 𝓤 α, from mem_nhds_uniformity_iff.mp this, let ⟨d, hd, h⟩ := comp_mem_uniformity_sets this in let e := {y:α| (a, y) ∈ d} in have hae : a ∈ closure e, from subset_closure $ refl_mem_uniformity hd, have set.prod (closure e) (closure e) ⊆ comp_rel d (comp_rel (set.prod e e) d), begin rw [←closure_prod_eq, closure_eq_inter_uniformity], change (⨅d' ∈ 𝓤 α, _) ≤ comp_rel d (comp_rel _ d), exact (infi_le_of_le d $ infi_le_of_le hd $ le_refl _) end, have e_subset : closure e ⊆ -s, from assume a' ha', let ⟨x, (hx : (a, x) ∈ d), y, ⟨hx₁, hx₂⟩, (hy : (y, _) ∈ d)⟩ := @this ⟨a, a'⟩ ⟨hae, ha'⟩ in have (a, a') ∈ comp_rel d d, from ⟨y, hx₂, hy⟩, h this rfl, have closure e ∈ nhds a, from (nhds a).sets_of_superset (mem_nhds_left a hd) subset_closure, have nhds a ⊓ principal (-closure e) = ⊥, from (@inf_eq_bot_iff_le_compl _ _ _ (principal (- closure e)) (principal (closure e)) (by simp [principal_univ, union_comm]) (by simp)).mpr (by simp [this]), ⟨- closure e, is_closed_closure, assume x h₁ h₂, @e_subset x h₂ h₁, this⟩, ..separated_t2 } /- separation space -/ namespace uniform_space def separation_setoid (α : Type u) [uniform_space α] : setoid α := ⟨λx y, (x, y) ∈ separation_rel α, separated_equiv⟩ local attribute [instance] separation_setoid instance {α : Type u} [u : uniform_space α] : uniform_space (quotient (separation_setoid α)) := { to_topological_space := u.to_topological_space.coinduced (λx, ⟦x⟧), uniformity := map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) u.uniformity, refl := le_trans (by simp [quotient.exists_rep]) (filter.map_mono refl_le_uniformity), symm := tendsto_map' $ by simp [prod.swap, (∘)]; exact tendsto_swap_uniformity.comp tendsto_map, comp := calc (map (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) u.uniformity).lift' (λs, comp_rel s s) = u.uniformity.lift' ((λs, comp_rel s s) ∘ image (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧))) : map_lift'_eq2 $ monotone_comp_rel monotone_id monotone_id ... ≤ u.uniformity.lift' (image (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) ∘ (λs:set (α×α), comp_rel s (comp_rel s s))) : lift'_mono' $ assume s hs ⟨a, b⟩ ⟨c, ⟨⟨a₁, a₂⟩, ha, a_eq⟩, ⟨⟨b₁, b₂⟩, hb, b_eq⟩⟩, begin simp at a_eq, simp at b_eq, have h : ⟦a₂⟧ = ⟦b₁⟧, { rw [a_eq.right, b_eq.left] }, have h : (a₂, b₁) ∈ separation_rel α := quotient.exact h, simp [function.comp, set.image, comp_rel, and.comm, and.left_comm, and.assoc], exact ⟨a₁, a_eq.left, b₂, b_eq.right, a₂, ha, b₁, h s hs, hb⟩ end ... = map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) (u.uniformity.lift' (λs:set (α×α), comp_rel s (comp_rel s s))) : by rw [map_lift'_eq]; exact monotone_comp_rel monotone_id (monotone_comp_rel monotone_id monotone_id) ... ≤ map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) u.uniformity : map_mono comp_le_uniformity3, is_open_uniformity := assume s, have ∀a, ⟦a⟧ ∈ s → ({p:α×α | p.1 = a → ⟦p.2⟧ ∈ s} ∈ 𝓤 α ↔ {p:α×α | p.1 ≈ a → ⟦p.2⟧ ∈ s} ∈ 𝓤 α), from assume a ha, ⟨assume h, let ⟨t, ht, hts⟩ := comp_mem_uniformity_sets h in have hts : ∀{a₁ a₂}, (a, a₁) ∈ t → (a₁, a₂) ∈ t → ⟦a₂⟧ ∈ s, from assume a₁ a₂ ha₁ ha₂, @hts (a, a₂) ⟨a₁, ha₁, ha₂⟩ rfl, have ht' : ∀{a₁ a₂}, a₁ ≈ a₂ → (a₁, a₂) ∈ t, from assume a₁ a₂ h, sInter_subset_of_mem ht h, u.uniformity.sets_of_superset ht $ assume ⟨a₁, a₂⟩ h₁ h₂, hts (ht' $ setoid.symm h₂) h₁, assume h, u.uniformity.sets_of_superset h $ by simp {contextual := tt}⟩, begin simp [topological_space.coinduced, u.is_open_uniformity, uniformity, forall_quotient_iff], exact ⟨λh a ha, (this a ha).mp $ h a ha, λh a ha, (this a ha).mpr $ h a ha⟩ end } lemma uniformity_quotient : 𝓤 (quotient (separation_setoid α)) = (𝓤 α).map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) := rfl lemma uniform_continuous_quotient_mk : uniform_continuous (quotient.mk : α → quotient (separation_setoid α)) := le_refl _ lemma uniform_continuous_quotient {f : quotient (separation_setoid α) → β} (hf : uniform_continuous (λx, f ⟦x⟧)) : uniform_continuous f := hf lemma uniform_continuous_quotient_lift {f : α → β} {h : ∀a b, (a, b) ∈ separation_rel α → f a = f b} (hf : uniform_continuous f) : uniform_continuous (λa, quotient.lift f h a) := uniform_continuous_quotient hf lemma uniform_continuous_quotient_lift₂ [uniform_space γ] {f : α → β → γ} {h : ∀a c b d, (a, b) ∈ separation_rel α → (c, d) ∈ separation_rel β → f a c = f b d} (hf : uniform_continuous (λp:α×β, f p.1 p.2)) : uniform_continuous (λp:_×_, quotient.lift₂ f h p.1 p.2) := begin rw [uniform_continuous, uniformity_prod_eq_prod, uniformity_quotient, uniformity_quotient, filter.prod_map_map_eq, filter.tendsto_map'_iff, filter.tendsto_map'_iff], rwa [uniform_continuous, uniformity_prod_eq_prod, filter.tendsto_map'_iff] at hf end lemma comap_quotient_le_uniformity : (𝓤 $ quotient $ separation_setoid α).comap (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) ≤ (𝓤 α) := assume t' ht', let ⟨t, ht, tt_t'⟩ := comp_mem_uniformity_sets ht' in let ⟨s, hs, ss_t⟩ := comp_mem_uniformity_sets ht in ⟨(λp:α×α, (⟦p.1⟧, ⟦p.2⟧)) '' s, (𝓤 α).sets_of_superset hs $ assume x hx, ⟨x, hx, rfl⟩, assume ⟨a₁, a₂⟩ ⟨⟨b₁, b₂⟩, hb, ab_eq⟩, have ⟦b₁⟧ = ⟦a₁⟧ ∧ ⟦b₂⟧ = ⟦a₂⟧, from prod.mk.inj ab_eq, have b₁ ≈ a₁ ∧ b₂ ≈ a₂, from and.imp quotient.exact quotient.exact this, have ab₁ : (a₁, b₁) ∈ t, from (setoid.symm this.left) t ht, have ba₂ : (b₂, a₂) ∈ s, from this.right s hs, tt_t' ⟨b₁, show ((a₁, a₂).1, b₁) ∈ t, from ab₁, ss_t ⟨b₂, show ((b₁, a₂).1, b₂) ∈ s, from hb, ba₂⟩⟩⟩ lemma comap_quotient_eq_uniformity : (𝓤 $ quotient $ separation_setoid α).comap (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) = 𝓤 α := le_antisymm comap_quotient_le_uniformity le_comap_map instance separated_separation : separated (quotient (separation_setoid α)) := set.ext $ assume ⟨a, b⟩, quotient.induction_on₂ a b $ assume a b, ⟨assume h, have a ≈ b, from assume s hs, have s ∈ (𝓤 $ quotient $ separation_setoid α).comap (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)), from comap_quotient_le_uniformity hs, let ⟨t, ht, hts⟩ := this in hts begin dsimp, exact h t ht end, show ⟦a⟧ = ⟦b⟧, from quotient.sound this, assume heq : ⟦a⟧ = ⟦b⟧, assume h hs, heq ▸ refl_mem_uniformity hs⟩ lemma separated_of_uniform_continuous {f : α → β} {x y : α} (H : uniform_continuous f) (h : x ≈ y) : f x ≈ f y := assume _ h', h _ (H h') lemma eq_of_separated_of_uniform_continuous [separated β] {f : α → β} {x y : α} (H : uniform_continuous f) (h : x ≈ y) : f x = f y := separated_def.1 (by apply_instance) _ _ $ separated_of_uniform_continuous H h def separation_quotient (α : Type*) [uniform_space α] := quotient (separation_setoid α) namespace separation_quotient instance : uniform_space (separation_quotient α) := by dunfold separation_quotient ; apply_instance instance : separated (separation_quotient α) := by dunfold separation_quotient ; apply_instance def lift [separated β] (f : α → β) : (separation_quotient α → β) := if h : uniform_continuous f then quotient.lift f (λ x y, eq_of_separated_of_uniform_continuous h) else λ x, f (classical.inhabited_of_nonempty $ (nonempty_quotient_iff $ separation_setoid α).1 ⟨x⟩).default lemma lift_mk [separated β] {f : α → β} (h : uniform_continuous f) (a : α) : lift f ⟦a⟧ = f a := by rw [lift, dif_pos h]; refl lemma uniform_continuous_lift [separated β] (f : α → β) : uniform_continuous (lift f) := begin by_cases hf : uniform_continuous f, { rw [lift, dif_pos hf], exact uniform_continuous_quotient_lift hf }, { rw [lift, dif_neg hf], exact uniform_continuous_of_const (assume a b, rfl) } end def map (f : α → β) : separation_quotient α → separation_quotient β := lift (quotient.mk ∘ f) lemma map_mk {f : α → β} (h : uniform_continuous f) (a : α) : map f ⟦a⟧ = ⟦f a⟧ := by rw [map, lift_mk (h.comp uniform_continuous_quotient_mk)] lemma uniform_continuous_map (f : α → β): uniform_continuous (map f) := uniform_continuous_lift (quotient.mk ∘ f) lemma map_unique {f : α → β} (hf : uniform_continuous f) {g : separation_quotient α → separation_quotient β} (comm : quotient.mk ∘ f = g ∘ quotient.mk) : map f = g := by ext ⟨a⟩; calc map f ⟦a⟧ = ⟦f a⟧ : map_mk hf a ... = g ⟦a⟧ : congr_fun comm a lemma map_id : map (@id α) = id := map_unique uniform_continuous_id rfl lemma map_comp {f : α → β} {g : β → γ} (hf : uniform_continuous f) (hg : uniform_continuous g) : map g ∘ map f = map (g ∘ f) := (map_unique (hf.comp hg) $ by simp only [(∘), map_mk, hf, hg]).symm end separation_quotient lemma separation_prod {a₁ a₂ : α} {b₁ b₂ : β} : (a₁, b₁) ≈ (a₂, b₂) ↔ a₁ ≈ a₂ ∧ b₁ ≈ b₂ := begin split, { assume h, exact ⟨separated_of_uniform_continuous uniform_continuous_fst h, separated_of_uniform_continuous uniform_continuous_snd h⟩ }, { rintros ⟨eqv_α, eqv_β⟩ r r_in, rw uniformity_prod at r_in, rcases r_in with ⟨t_α, ⟨r_α, r_α_in, h_α⟩, t_β, ⟨r_β, r_β_in, h_β⟩, H⟩, let p_α := λ(p : (α × β) × (α × β)), (p.1.1, p.2.1), let p_β := λ(p : (α × β) × (α × β)), (p.1.2, p.2.2), have key_α : p_α ((a₁, b₁), (a₂, b₂)) ∈ r_α, { simp [p_α, eqv_α r_α r_α_in] }, have key_β : p_β ((a₁, b₁), (a₂, b₂)) ∈ r_β, { simp [p_β, eqv_β r_β r_β_in] }, exact H ⟨h_α key_α, h_β key_β⟩ }, end instance separated.prod [separated α] [separated β] : separated (α × β) := separated_def.2 $ assume x y H, prod.ext (eq_of_separated_of_uniform_continuous uniform_continuous_fst H) (eq_of_separated_of_uniform_continuous uniform_continuous_snd H) end uniform_space
0f5d3cf73322074c5a0889f61d387031768f5edb
94e33a31faa76775069b071adea97e86e218a8ee
/src/algebraic_geometry/projective_spectrum/structure_sheaf.lean
0e0ef27f638d37b82bd09b6e6512716deebcd0bf
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
17,735
lean
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import algebraic_geometry.projective_spectrum.topology import topology.sheaves.local_predicate import ring_theory.graded_algebra.homogeneous_localization import algebraic_geometry.locally_ringed_space /-! # The structure sheaf on `projective_spectrum 𝒜`. In `src/algebraic_geometry/topology.lean`, we have given a topology on `projective_spectrum 𝒜`; in this file we will construct a sheaf on `projective_spectrum 𝒜`. ## Notation - `R` is a commutative semiring; - `A` is a commutative ring and an `R`-algebra; - `𝒜 : ℕ → submodule R A` is the grading of `A`; - `U` is opposite object of some open subset of `projective_spectrum.Top`. ## Main definitions and results We define the structure sheaf as the subsheaf of all dependent function `f : Π x : U, homogeneous_localization 𝒜 x` such that `f` is locally expressible as ratio of two elements of the *same grading*, i.e. `∀ y ∈ U, ∃ (V ⊆ U) (i : ℕ) (a b ∈ 𝒜 i), ∀ z ∈ V, f z = a / b`. * `algebraic_geometry.projective_spectrum.structure_sheaf.is_locally_fraction`: the predicate that a dependent function is locally expressible as a ratio of two elements of the same grading. * `algebraic_geometry.projective_spectrum.structure_sheaf.sections_subring`: the dependent functions satisfying the above local property forms a subring of all dependent functions `Π x : U, homogeneous_localization 𝒜 x`. * `algebraic_geometry.Proj.structure_sheaf`: the sheaf with `U ↦ sections_subring U` and natural restriction map. Then we establish that `Proj 𝒜` is a `LocallyRingedSpace`: * `algebraic_geometry.Proj.stalk_iso'`: for any `x : projective_spectrum 𝒜`, the stalk of `Proj.structure_sheaf` at `x` is isomorphic to `homogeneous_localization 𝒜 x`. * `algebraic_geometry.Proj.to_LocallyRingedSpace`: `Proj` as a locally ringed space. ## References * [Robin Hartshorne, *Algebraic Geometry*][Har77] -/ noncomputable theory namespace algebraic_geometry open_locale direct_sum big_operators pointwise open direct_sum set_like localization Top topological_space category_theory opposite variables {R A: Type*} variables [comm_ring R] [comm_ring A] [algebra R A] variables (𝒜 : ℕ → submodule R A) [graded_algebra 𝒜] local notation `at ` x := homogeneous_localization 𝒜 x.as_homogeneous_ideal.to_ideal namespace projective_spectrum.structure_sheaf variables {𝒜} /-- The predicate saying that a dependent function on an open `U` is realised as a fixed fraction `r / s` of *same grading* in each of the stalks (which are localizations at various prime ideals). -/ def is_fraction {U : opens (projective_spectrum.Top 𝒜)} (f : Π x : U, at x.1) : Prop := ∃ (i : ℕ) (r s : 𝒜 i), ∀ x : U, ∃ (s_nin : s.1 ∉ x.1.as_homogeneous_ideal), (f x) = quotient.mk' ⟨i, r, s, s_nin⟩ variables (𝒜) /-- The predicate `is_fraction` is "prelocal", in the sense that if it holds on `U` it holds on any open subset `V` of `U`. -/ def is_fraction_prelocal : prelocal_predicate (λ (x : projective_spectrum.Top 𝒜), at x) := { pred := λ U f, is_fraction f, res := by rintros V U i f ⟨j, r, s, w⟩; exact ⟨j, r, s, λ y, w (i y)⟩ } /-- We will define the structure sheaf as the subsheaf of all dependent functions in `Π x : U, homogeneous_localization 𝒜 x` consisting of those functions which can locally be expressed as a ratio of `A` of same grading.-/ def is_locally_fraction : local_predicate (λ (x : projective_spectrum.Top 𝒜), at x) := (is_fraction_prelocal 𝒜).sheafify namespace section_subring variable {𝒜} open submodule set_like.graded_monoid homogeneous_localization lemma zero_mem' (U : (opens (projective_spectrum.Top 𝒜))ᵒᵖ) : (is_locally_fraction 𝒜).pred (0 : Π x : unop U, at x.1) := λ x, ⟨unop U, x.2, 𝟙 (unop U), ⟨0, ⟨0, zero_mem _⟩, ⟨1, one_mem⟩, λ y, ⟨_, rfl⟩⟩⟩ lemma one_mem' (U : (opens (projective_spectrum.Top 𝒜))ᵒᵖ) : (is_locally_fraction 𝒜).pred (1 : Π x : unop U, at x.1) := λ x, ⟨unop U, x.2, 𝟙 (unop U), ⟨0, ⟨1, one_mem⟩, ⟨1, one_mem⟩, λ y, ⟨_, rfl⟩⟩⟩ lemma add_mem' (U : (opens (projective_spectrum.Top 𝒜))ᵒᵖ) (a b : Π x : unop U, at x.1) (ha : (is_locally_fraction 𝒜).pred a) (hb : (is_locally_fraction 𝒜).pred b) : (is_locally_fraction 𝒜).pred (a + b) := λ x, begin rcases ha x with ⟨Va, ma, ia, ja, ⟨ra, ra_mem⟩, ⟨sa, sa_mem⟩, wa⟩, rcases hb x with ⟨Vb, mb, ib, jb, ⟨rb, rb_mem⟩, ⟨sb, sb_mem⟩, wb⟩, refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, opens.inf_le_left _ _ ≫ ia, ja + jb, ⟨sb * ra + sa * rb, add_mem (add_comm jb ja ▸ mul_mem sb_mem ra_mem : sb * ra ∈ 𝒜 (ja + jb)) (mul_mem sa_mem rb_mem)⟩, ⟨sa * sb, mul_mem sa_mem sb_mem⟩, λ y, ⟨λ h, _, _⟩⟩, { cases (y : projective_spectrum.Top 𝒜).is_prime.mem_or_mem h with h h, { obtain ⟨nin, -⟩ := (wa ⟨y, (opens.inf_le_left Va Vb y).2⟩), exact nin h }, { obtain ⟨nin, -⟩ := (wb ⟨y, (opens.inf_le_right Va Vb y).2⟩), exact nin h } }, { simp only [add_mul, map_add, pi.add_apply, ring_hom.map_mul, ext_iff_val, add_val], obtain ⟨nin1, hy1⟩ := (wa (opens.inf_le_left Va Vb y)), obtain ⟨nin2, hy2⟩ := (wb (opens.inf_le_right Va Vb y)), dsimp only at hy1 hy2, erw [hy1, hy2], simpa only [val_mk', add_mk, ← subtype.val_eq_coe, add_comm], } end lemma neg_mem' (U : (opens (projective_spectrum.Top 𝒜))ᵒᵖ) (a : Π x : unop U, at x.1) (ha : (is_locally_fraction 𝒜).pred a) : (is_locally_fraction 𝒜).pred (-a) := λ x, begin rcases ha x with ⟨V, m, i, j, ⟨r, r_mem⟩, ⟨s, s_mem⟩, w⟩, choose nin hy using w, refine ⟨V, m, i, j, ⟨-r, submodule.neg_mem _ r_mem⟩, ⟨s, s_mem⟩, λ y, ⟨nin y, _⟩⟩, simp only [ext_iff_val, val_mk', ←subtype.val_eq_coe] at hy, simp only [pi.neg_apply, ext_iff_val, neg_val, hy, val_mk', ←subtype.val_eq_coe, neg_mk], end lemma mul_mem' (U : (opens (projective_spectrum.Top 𝒜))ᵒᵖ) (a b : Π x : unop U, at x.1) (ha : (is_locally_fraction 𝒜).pred a) (hb : (is_locally_fraction 𝒜).pred b) : (is_locally_fraction 𝒜).pred (a * b) := λ x, begin rcases ha x with ⟨Va, ma, ia, ja, ⟨ra, ra_mem⟩, ⟨sa, sa_mem⟩, wa⟩, rcases hb x with ⟨Vb, mb, ib, jb, ⟨rb, rb_mem⟩, ⟨sb, sb_mem⟩, wb⟩, refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, opens.inf_le_left _ _ ≫ ia, ja + jb, ⟨ra * rb, set_like.graded_monoid.mul_mem ra_mem rb_mem⟩, ⟨sa * sb, set_like.graded_monoid.mul_mem sa_mem sb_mem⟩, λ y, ⟨λ h, _, _⟩⟩, { cases (y : projective_spectrum.Top 𝒜).is_prime.mem_or_mem h with h h, { choose nin hy using wa ⟨y, (opens.inf_le_left Va Vb y).2⟩, exact nin h }, { choose nin hy using wb ⟨y, (opens.inf_le_right Va Vb y).2⟩, exact nin h }, }, { simp only [pi.mul_apply, ring_hom.map_mul], choose nin1 hy1 using wa (opens.inf_le_left Va Vb y), choose nin2 hy2 using wb (opens.inf_le_right Va Vb y), rw ext_iff_val at hy1 hy2 ⊢, erw [mul_val, hy1, hy2], simpa only [val_mk', mk_mul, ← subtype.val_eq_coe] } end end section_subring section open section_subring variable {𝒜} /--The functions satisfying `is_locally_fraction` form a subring of all dependent functions `Π x : U, homogeneous_localization 𝒜 x`.-/ def sections_subring (U : (opens (projective_spectrum.Top 𝒜))ᵒᵖ) : subring (Π x : unop U, at x.1) := { carrier := { f | (is_locally_fraction 𝒜).pred f }, zero_mem' := zero_mem' U, one_mem' := one_mem' U, add_mem' := add_mem' U, neg_mem' := neg_mem' U, mul_mem' := mul_mem' U } end /--The structure sheaf (valued in `Type`, not yet `CommRing`) is the subsheaf consisting of functions satisfying `is_locally_fraction`.-/ def structure_sheaf_in_Type : sheaf Type* (projective_spectrum.Top 𝒜):= subsheaf_to_Types (is_locally_fraction 𝒜) instance comm_ring_structure_sheaf_in_Type_obj (U : (opens (projective_spectrum.Top 𝒜))ᵒᵖ) : comm_ring ((structure_sheaf_in_Type 𝒜).1.obj U) := (sections_subring U).to_comm_ring /--The structure presheaf, valued in `CommRing`, constructed by dressing up the `Type` valued structure presheaf.-/ @[simps] def structure_presheaf_in_CommRing : presheaf CommRing (projective_spectrum.Top 𝒜) := { obj := λ U, CommRing.of ((structure_sheaf_in_Type 𝒜).1.obj U), map := λ U V i, { to_fun := ((structure_sheaf_in_Type 𝒜).1.map i), map_zero' := rfl, map_add' := λ x y, rfl, map_one' := rfl, map_mul' := λ x y, rfl, }, } /--Some glue, verifying that that structure presheaf valued in `CommRing` agrees with the `Type` valued structure presheaf.-/ def structure_presheaf_comp_forget : structure_presheaf_in_CommRing 𝒜 ⋙ (forget CommRing) ≅ (structure_sheaf_in_Type 𝒜).1 := nat_iso.of_components (λ U, iso.refl _) (by tidy) end projective_spectrum.structure_sheaf namespace projective_spectrum open Top.presheaf projective_spectrum.structure_sheaf opens /--The structure sheaf on `Proj` 𝒜, valued in `CommRing`.-/ def Proj.structure_sheaf : sheaf CommRing (projective_spectrum.Top 𝒜) := ⟨structure_presheaf_in_CommRing 𝒜, -- We check the sheaf condition under `forget CommRing`. (is_sheaf_iff_is_sheaf_comp _ _).mpr (is_sheaf_of_iso (structure_presheaf_comp_forget 𝒜).symm (structure_sheaf_in_Type 𝒜).property)⟩ end projective_spectrum section open projective_spectrum projective_spectrum.structure_sheaf opens @[simp] lemma res_apply (U V : opens (projective_spectrum.Top 𝒜)) (i : V ⟶ U) (s : (Proj.structure_sheaf 𝒜).1.obj (op U)) (x : V) : ((Proj.structure_sheaf 𝒜).1.map i.op s).1 x = (s.1 (i x) : _) := rfl /--`Proj` of a graded ring as a `SheafedSpace`-/ def Proj.to_SheafedSpace : SheafedSpace CommRing := { carrier := Top.of (projective_spectrum 𝒜), presheaf := (Proj.structure_sheaf 𝒜).1, is_sheaf := (Proj.structure_sheaf 𝒜).2 } /-- The ring homomorphism that takes a section of the structure sheaf of `Proj` on the open set `U`, implemented as a subtype of dependent functions to localizations at homogeneous prime ideals, and evaluates the section on the point corresponding to a given homogeneous prime ideal. -/ def open_to_localization (U : opens (projective_spectrum.Top 𝒜)) (x : projective_spectrum.Top 𝒜) (hx : x ∈ U) : (Proj.structure_sheaf 𝒜).1.obj (op U) ⟶ CommRing.of (at x) := { to_fun := λ s, (s.1 ⟨x, hx⟩ : _), map_one' := rfl, map_mul' := λ _ _, rfl, map_zero' := rfl, map_add' := λ _ _, rfl } /-- The ring homomorphism from the stalk of the structure sheaf of `Proj` at a point corresponding to a homogeneous prime ideal `x` to the *homogeneous localization* at `x`, formed by gluing the `open_to_localization` maps. -/ def stalk_to_fiber_ring_hom (x : projective_spectrum.Top 𝒜) : (Proj.structure_sheaf 𝒜).1.stalk x ⟶ CommRing.of (at x) := limits.colimit.desc (((open_nhds.inclusion x).op) ⋙ (Proj.structure_sheaf 𝒜).1) { X := _, ι := { app := λ U, open_to_localization 𝒜 ((open_nhds.inclusion _).obj (unop U)) x (unop U).2, } } @[simp] lemma germ_comp_stalk_to_fiber_ring_hom (U : opens (projective_spectrum.Top 𝒜)) (x : U) : (Proj.structure_sheaf 𝒜).1.germ x ≫ stalk_to_fiber_ring_hom 𝒜 x = open_to_localization 𝒜 U x x.2 := limits.colimit.ι_desc _ _ @[simp] lemma stalk_to_fiber_ring_hom_germ' (U : opens (projective_spectrum.Top 𝒜)) (x : projective_spectrum.Top 𝒜) (hx : x ∈ U) (s : (Proj.structure_sheaf 𝒜).1.obj (op U)) : stalk_to_fiber_ring_hom 𝒜 x ((Proj.structure_sheaf 𝒜).1.germ ⟨x, hx⟩ s) = (s.1 ⟨x, hx⟩ : _) := ring_hom.ext_iff.1 (germ_comp_stalk_to_fiber_ring_hom 𝒜 U ⟨x, hx⟩ : _) s @[simp] lemma stalk_to_fiber_ring_hom_germ (U : opens (projective_spectrum.Top 𝒜)) (x : U) (s : (Proj.structure_sheaf 𝒜).1.obj (op U)) : stalk_to_fiber_ring_hom 𝒜 x ((Proj.structure_sheaf 𝒜).1.germ x s) = s.1 x := by { cases x, exact stalk_to_fiber_ring_hom_germ' 𝒜 U _ _ _ } lemma homogeneous_localization.mem_basic_open (x : projective_spectrum.Top 𝒜) (f : at x) : x ∈ projective_spectrum.basic_open 𝒜 f.denom := begin rw projective_spectrum.mem_basic_open, exact homogeneous_localization.denom_not_mem _, end variable (𝒜) /--Given a point `x` corresponding to a homogeneous prime ideal, there is a (dependent) function such that, for any `f` in the homogeneous localization at `x`, it returns the obvious section in the basic open set `D(f.denom)`-/ def section_in_basic_open (x : projective_spectrum.Top 𝒜) : Π (f : at x), (Proj.structure_sheaf 𝒜).1.obj (op (projective_spectrum.basic_open 𝒜 f.denom)) := λ f, ⟨λ y, quotient.mk' ⟨f.deg, ⟨f.num, f.num_mem⟩, ⟨f.denom, f.denom_mem⟩, y.2⟩, λ y, ⟨projective_spectrum.basic_open 𝒜 f.denom, y.2, ⟨𝟙 _, ⟨f.deg, ⟨⟨f.num, f.num_mem⟩, ⟨f.denom, f.denom_mem⟩, λ z, ⟨z.2, rfl⟩⟩⟩⟩⟩⟩ /--Given any point `x` and `f` in the homogeneous localization at `x`, there is an element in the stalk at `x` obtained by `section_in_basic_open`. This is the inverse of `stalk_to_fiber_ring_hom`. -/ def homogeneous_localization_to_stalk (x : projective_spectrum.Top 𝒜) : (at x) → (Proj.structure_sheaf 𝒜).1.stalk x := λ f, (Proj.structure_sheaf 𝒜).1.germ (⟨x, homogeneous_localization.mem_basic_open _ x f⟩ : projective_spectrum.basic_open _ f.denom) (section_in_basic_open _ x f) /--Using `homogeneous_localization_to_stalk`, we construct a ring isomorphism between stalk at `x` and homogeneous localization at `x` for any point `x` in `Proj`.-/ def Proj.stalk_iso' (x : projective_spectrum.Top 𝒜) : (Proj.structure_sheaf 𝒜).1.stalk x ≃+* CommRing.of (at x) := ring_equiv.of_bijective (stalk_to_fiber_ring_hom _ x) ⟨λ z1 z2 eq1, begin obtain ⟨u1, memu1, s1, rfl⟩ := (Proj.structure_sheaf 𝒜).1.germ_exist x z1, obtain ⟨u2, memu2, s2, rfl⟩ := (Proj.structure_sheaf 𝒜).1.germ_exist x z2, obtain ⟨v1, memv1, i1, ⟨j1, ⟨a1, a1_mem⟩, ⟨b1, b1_mem⟩, hs1⟩⟩ := s1.2 ⟨x, memu1⟩, obtain ⟨v2, memv2, i2, ⟨j2, ⟨a2, a2_mem⟩, ⟨b2, b2_mem⟩, hs2⟩⟩ := s2.2 ⟨x, memu2⟩, obtain ⟨b1_nin_x, eq2⟩ := hs1 ⟨x, memv1⟩, obtain ⟨b2_nin_x, eq3⟩ := hs2 ⟨x, memv2⟩, dsimp only at eq1 eq2 eq3, erw [stalk_to_fiber_ring_hom_germ 𝒜 u1 ⟨x, memu1⟩ s1, stalk_to_fiber_ring_hom_germ 𝒜 u2 ⟨x, memu2⟩ s2] at eq1, erw eq1 at eq2, erw [eq2, quotient.eq] at eq3, change localization.mk _ _ = localization.mk _ _ at eq3, rw [localization.mk_eq_mk', is_localization.eq] at eq3, obtain ⟨⟨c, hc⟩, eq3⟩ := eq3, simp only [← subtype.val_eq_coe] at eq3, have eq3' : ∀ (y : projective_spectrum.Top 𝒜) (hy : y ∈ projective_spectrum.basic_open 𝒜 b1 ⊓ projective_spectrum.basic_open 𝒜 b2 ⊓ projective_spectrum.basic_open 𝒜 c), (localization.mk a1 ⟨b1, show b1 ∉ y.as_homogeneous_ideal, by rw ←projective_spectrum.mem_basic_open; exact le_of_hom (opens.inf_le_left _ _ ≫ opens.inf_le_left _ _) hy⟩ : localization.at_prime y.1.to_ideal) = localization.mk a2 ⟨b2, show b2 ∉ y.as_homogeneous_ideal, by rw ←projective_spectrum.mem_basic_open; exact le_of_hom (opens.inf_le_left _ _ ≫ opens.inf_le_right _ _) hy⟩, { intros y hy, rw [localization.mk_eq_mk', is_localization.eq], exact ⟨⟨c, show c ∉ y.as_homogeneous_ideal, by rw ←projective_spectrum.mem_basic_open; exact le_of_hom (opens.inf_le_right _ _) hy⟩, eq3⟩ }, refine presheaf.germ_ext (Proj.structure_sheaf 𝒜).1 (projective_spectrum.basic_open _ b1 ⊓ projective_spectrum.basic_open _ b2 ⊓ projective_spectrum.basic_open _ c ⊓ v1 ⊓ v2) ⟨⟨⟨⟨b1_nin_x, b2_nin_x⟩, hc⟩, memv1⟩, memv2⟩ (opens.inf_le_left _ _ ≫ opens.inf_le_right _ _ ≫ i1) (opens.inf_le_right _ _ ≫ i2) _, rw subtype.ext_iff_val, ext1 y, simp only [res_apply], obtain ⟨b1_nin_y, eq6⟩ := hs1 ⟨_, le_of_hom (opens.inf_le_left _ _ ≫ opens.inf_le_right _ _) y.2⟩, obtain ⟨b2_nin_y, eq7⟩ := hs2 ⟨_, le_of_hom (opens.inf_le_right _ _) y.2⟩, simp only at eq6 eq7, erw [eq6, eq7, quotient.eq], change localization.mk _ _ = localization.mk _ _, exact eq3' _ ⟨⟨le_of_hom (opens.inf_le_left _ _ ≫ opens.inf_le_left _ _ ≫ opens.inf_le_left _ _ ≫ opens.inf_le_left _ _) y.2, le_of_hom (opens.inf_le_left _ _ ≫ opens.inf_le_left _ _ ≫ opens.inf_le_left _ _ ≫ opens.inf_le_right _ _) y.2⟩, le_of_hom (opens.inf_le_left _ _ ≫ opens.inf_le_left _ _ ≫ opens.inf_le_right _ _) y.2⟩, end, function.surjective_iff_has_right_inverse.mpr ⟨homogeneous_localization_to_stalk 𝒜 x, λ f, begin rw homogeneous_localization_to_stalk, erw stalk_to_fiber_ring_hom_germ 𝒜 (projective_spectrum.basic_open 𝒜 f.denom) ⟨x, _⟩ (section_in_basic_open _ x f), simp only [section_in_basic_open, subtype.ext_iff_val, homogeneous_localization.ext_iff_val, homogeneous_localization.val_mk', f.eq_num_div_denom], refl, end⟩⟩ /--`Proj` of a graded ring as a `LocallyRingedSpace`-/ def Proj.to_LocallyRingedSpace : LocallyRingedSpace := { local_ring := λ x, @@ring_equiv.local_ring _ (show local_ring (at x), from infer_instance) _ (Proj.stalk_iso' 𝒜 x).symm, ..(Proj.to_SheafedSpace 𝒜) } end end algebraic_geometry
589f97d2ce2e51a4f2783b674691e0680fd277b4
491068d2ad28831e7dade8d6dff871c3e49d9431
/library/data/stream.lean
0091bb758ee3d4069ada0f04af30ba10b8f0d2a2
[ "Apache-2.0" ]
permissive
davidmueller13/lean
65a3ed141b4088cd0a268e4de80eb6778b21a0e9
c626e2e3c6f3771e07c32e82ee5b9e030de5b050
refs/heads/master
1,611,278,313,401
1,444,021,177,000
1,444,021,177,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
22,500
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. 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 definition stream (A : Type) := nat → A namespace stream variables {A B C : Type} definition cons (a : A) (s : stream A) : stream A := λ i, match i with | 0 := a | succ n := s n end notation h :: t := cons h t definition head [reducible] (s : stream A) : A := s 0 definition tail (s : stream A) : stream A := λ i, s (i+1) definition drop (n : nat) (s : stream A) : stream A := λ i, s (i+n) definition nth [reducible] (n : nat) (s : stream A) : A := s n protected theorem eta (s : stream A) : head s :: tail s = s := funext (λ i, begin cases i, repeat reflexivity end) theorem nth_zero_cons (a : A) (s : stream A) : nth 0 (a :: s) = a := rfl theorem head_cons (a : A) (s : stream A) : head (a :: s) = a := rfl theorem tail_cons (a : A) (s : stream A) : tail (a :: s) = s := rfl theorem tail_drop (n : nat) (s : stream A) : tail (drop n s) = drop n (tail s) := funext (λ i, begin esimp [tail, drop], congruence, rewrite add.right_comm end) theorem nth_drop (n m : nat) (s : stream A) : nth n (drop m s) = nth (n+m) s := rfl theorem tail_eq_drop (s : stream A) : tail s = drop 1 s := rfl theorem drop_drop (n m : nat) (s : stream A) : drop n (drop m s) = drop (n+m) s := funext (λ i, begin esimp [drop], rewrite add.assoc end) theorem nth_succ (n : nat) (s : stream A) : nth (succ n) s = nth n (tail s) := rfl theorem drop_succ (n : nat) (s : stream A) : drop (succ n) s = drop n (tail s) := rfl protected theorem ext {s₁ s₂ : stream A} : (∀ n, nth n s₁ = nth n s₂) → s₁ = s₂ := assume h, funext h definition all (p : A → Prop) (s : stream A) := ∀ n, p (nth n s) definition any (p : A → Prop) (s : stream A) := ∃ n, p (nth n s) theorem all_def (p : A → Prop) (s : stream A) : all p s = ∀ n, p (nth n s) := rfl theorem any_def (p : A → Prop) (s : stream A) : any p s = ∃ n, p (nth n s) := rfl definition mem (a : A) (s : stream A) := any (λ b, a = b) s notation e ∈ s := mem e s theorem mem_cons (a : A) (s : stream A) : a ∈ (a::s) := exists.intro 0 rfl theorem mem_cons_of_mem {a : A} {s : stream A} (b : A) : a ∈ s → a ∈ b :: s := assume ains, obtain n (h : a = nth n s), from ains, exists.intro (succ n) (by rewrite [nth_succ, tail_cons, h]) theorem eq_or_mem_of_mem_cons {a b : A} {s : stream A} : a ∈ b::s → a = b ∨ a ∈ s := assume ainbs, obtain n (h : a = nth n (b::s)), from ainbs, begin cases n with n', {left, exact h}, {right, rewrite [nth_succ at h, tail_cons at h], existsi n', exact h} end theorem mem_of_nth_eq {n : nat} {s : stream A} {a : A} : a = nth n s → a ∈ s := assume h, exists.intro n h section map variable (f : A → B) definition map (s : stream A) : stream B := λ n, f (nth n s) theorem drop_map (n : nat) (s : stream A) : drop n (map f s) = map f (drop n s) := stream.ext (λ i, rfl) theorem nth_map (n : nat) (s : stream A) : nth n (map f s) = f (nth n s) := rfl theorem tail_map (s : stream A) : tail (map f s) = map f (tail s) := begin rewrite tail_eq_drop end theorem head_map (s : stream A) : head (map f s) = f (head s) := rfl theorem map_eq (s : stream A) : map f s = f (head s) :: map f (tail s) := by rewrite [-stream.eta, tail_map, head_map] theorem map_cons (a : A) (s : stream A) : map f (a :: s) = f a :: map f s := by rewrite [-stream.eta, map_eq] theorem map_id (s : stream A) : map id s = s := rfl theorem map_map (g : B → C) (f : A → B) (s : stream A) : map g (map f s) = map (g ∘ f) s := rfl theorem mem_map {a : A} {s : stream A} : a ∈ s → f a ∈ map f s := assume ains, obtain n (h : a = nth n s), from ains, exists.intro n (by rewrite [nth_map, h]) end map section zip variable (f : A → B → C) definition zip (s₁ : stream A) (s₂ : stream B) : stream C := λ n, f (nth n s₁) (nth n s₂) theorem drop_zip (n : nat) (s₁ : stream A) (s₂ : stream B) : drop n (zip f s₁ s₂) = zip f (drop n s₁) (drop n s₂) := stream.ext (λ i, rfl) theorem nth_zip (n : nat) (s₁ : stream A) (s₂ : stream B) : nth n (zip f s₁ s₂) = f (nth n s₁) (nth n s₂) := rfl theorem head_zip (s₁ : stream A) (s₂ : stream B) : head (zip f s₁ s₂) = f (head s₁) (head s₂) := rfl theorem tail_zip (s₁ : stream A) (s₂ : stream B) : tail (zip f s₁ s₂) = zip f (tail s₁) (tail s₂) := rfl theorem zip_eq (s₁ : stream A) (s₂ : stream B) : zip f s₁ s₂ = f (head s₁) (head s₂) :: zip f (tail s₁) (tail s₂) := by rewrite [-stream.eta] end zip definition const (a : A) : stream A := λ n, a theorem mem_const (a : A) : a ∈ const a := exists.intro 0 rfl theorem const_eq (a : A) : const a = a :: const a := begin apply stream.ext, intro n, cases n, repeat reflexivity end theorem tail_const (a : A) : tail (const a) = const a := by rewrite [const_eq at {1}] theorem map_const (f : A → B) (a : A) : map f (const a) = const (f a) := rfl theorem nth_const (n : nat) (a : A) : nth n (const a) = a := rfl theorem drop_const (n : nat) (a : A) : drop n (const a) = const a := stream.ext (λ i, rfl) definition iterate (f : A → A) (a : A) : stream A := λ n, nat.rec_on n a (λ n r, f r) theorem head_iterate (f : A → A) (a : A) : head (iterate f a) = a := rfl theorem tail_iterate (f : A → A) (a : A) : tail (iterate f a) = iterate f (f a) := begin apply funext, intro n, induction n with n' IH, {reflexivity}, {esimp [tail, iterate] at *, rewrite add_one at *, esimp at *, rewrite IH} end theorem iterate_eq (f : A → A) (a : A) : iterate f a = a :: iterate f (f a) := begin rewrite [-stream.eta], congruence, exact !tail_iterate end theorem nth_zero_iterate (f : A → A) (a : A) : nth 0 (iterate f a) = a := rfl theorem nth_succ_iterate (n : nat) (f : A → A) (a : A) : nth (succ n) (iterate f a) = nth n (iterate f (f a)) := by rewrite [nth_succ, tail_iterate] section bisim variable (R : stream A → stream A → Prop) local infix ~ := R definition is_bisimulation := ∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → head s₁ = head s₂ ∧ tail s₁ ~ tail s₂ lemma nth_of_bisim (bisim : is_bisimulation R) : ∀ {s₁ s₂} n, s₁ ~ s₂ → nth n s₁ = nth n s₂ ∧ drop (n+1) s₁ ~ drop (n+1) s₂ | s₁ s₂ 0 h := bisim h | s₁ s₂ (n+1) h := obtain h₁ (trel : tail s₁ ~ tail s₂), from bisim h, nth_of_bisim n trel -- If two streams are bisimilar, then they are equal theorem eq_of_bisim (bisim : is_bisimulation R) : ∀ {s₁ s₂}, s₁ ~ s₂ → s₁ = s₂ := λ s₁ s₂ r, stream.ext (λ n, and.elim_left (nth_of_bisim R bisim n r)) end bisim theorem bisim_simple (s₁ s₂ : stream A) : head s₁ = head s₂ → s₁ = tail s₁ → s₂ = tail s₂ → s₁ = s₂ := assume hh ht₁ ht₂, eq_of_bisim (λ s₁ s₂, head s₁ = head s₂ ∧ s₁ = tail s₁ ∧ s₂ = tail s₂) (λ s₁ s₂ h, obtain h₁ h₂ h₃, from h, begin constructor, exact h₁, rewrite [-h₂, -h₃], exact h end) (and.intro hh (and.intro ht₁ ht₂)) -- AKA coinduction freeze theorem coinduction.{l} {A : Type.{l}} {s₁ s₂ : stream A} : head s₁ = head s₂ → (∀ (B : Type.{l}) (fr : stream A → B), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂ := assume hh ht, eq_of_bisim (λ s₁ s₂, head s₁ = head s₂ ∧ ∀ (B : Type) (fr : stream A → B), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) (λ s₁ s₂ h, have h₁ : head s₁ = head s₂, from and.elim_left h, have h₂ : head (tail s₁) = head (tail s₂), from and.elim_right h A (@head A) h₁, have h₃ : ∀ (B : Type) (fr : stream A → B), fr (tail s₁) = fr (tail s₂) → fr (tail (tail s₁)) = fr (tail (tail s₂)), from λ B fr, and.elim_right h B (λ s, fr (tail s)), and.intro h₁ (and.intro h₂ h₃)) (and.intro hh ht) theorem iterate_id (a : A) : iterate id a = const a := coinduction rfl (λ B fr ch, by rewrite [tail_iterate, tail_const]; exact ch) local attribute stream [reducible] theorem map_iterate (f : A → A) (a : A) : iterate f (f a) = map f (iterate f a) := begin apply funext, intro n, induction n with n' IH, {reflexivity}, { esimp [map, iterate, nth] at *, rewrite IH } end section corec definition corec (f : A → B) (g : A → A) : A → stream B := λ a, map f (iterate g a) theorem corec_def (f : A → B) (g : A → A) (a : A) : corec f g a = map f (iterate g a) := rfl theorem corec_eq (f : A → B) (g : A → A) (a : A) : corec f g a = f a :: corec f g (g a) := by rewrite [corec_def, map_eq, head_iterate, tail_iterate] theorem corec_id_id_eq_const (a : A) : corec id id a = const a := by rewrite [corec_def, map_id, iterate_id] theorem corec_id_f_eq_iterate (f : A → A) (a : A) : corec id f a = iterate f a := rfl end corec -- corec is also known as unfold definition unfolds (g : A → B) (f : A → A) (a : A) : stream B := corec g f a theorem unfolds_eq (g : A → B) (f : A → A) (a : A) : unfolds g f a = g a :: unfolds g f (f a) := by esimp [ unfolds ]; rewrite [corec_eq] theorem nth_unfolds_head_tail : ∀ (n : nat) (s : stream A), nth n (unfolds head tail s) = nth n s := begin intro n, induction n with n' ih, {intro s, reflexivity}, {intro s, rewrite [*nth_succ, unfolds_eq, tail_cons, ih]} end theorem unfolds_head_eq : ∀ (s : stream A), unfolds head tail s = s := λ s, stream.ext (λ n, nth_unfolds_head_tail n s) definition interleave (s₁ s₂ : stream A) : stream A := corec (λ p, obtain s₁ s₂, from p, head s₁) (λ p, obtain s₁ s₂, from p, (s₂, tail s₁)) (s₁, s₂) infix `⋈`:65 := interleave theorem interleave_eq (s₁ s₂ : stream A) : s₁ ⋈ s₂ = head s₁ :: head s₂ :: (tail s₁ ⋈ tail s₂) := begin esimp [interleave], rewrite corec_eq, esimp, congruence, rewrite corec_eq end theorem tail_interleave (s₁ s₂ : stream A) : tail (s₁ ⋈ s₂) = s₂ ⋈ (tail s₁) := by esimp [interleave]; rewrite corec_eq theorem interleave_tail_tail (s₁ s₂ : stream A) : tail s₁ ⋈ tail s₂ = tail (tail (s₁ ⋈ s₂)) := by rewrite [interleave_eq s₁ s₂] theorem nth_interleave_left : ∀ (n : nat) (s₁ s₂ : stream A), nth (2*n) (s₁ ⋈ s₂) = nth n s₁ | 0 s₁ s₂ := rfl | (succ n) s₁ s₂ := begin change nth (succ (succ (2*n))) (s₁ ⋈ s₂) = nth (succ n) s₁, rewrite [*nth_succ, interleave_eq, *tail_cons, nth_interleave_left] end theorem nth_interleave_right : ∀ (n : nat) (s₁ s₂ : stream A), nth (2*n+1) (s₁ ⋈ s₂) = nth n s₂ | 0 s₁ s₂ := rfl | (succ n) s₁ s₂ := begin change nth (succ (succ (2*n+1))) (s₁ ⋈ s₂) = nth (succ n) s₂, rewrite [*nth_succ, interleave_eq, *tail_cons, nth_interleave_right] end theorem mem_interleave_left {a : A} {s₁ : stream A} (s₂ : stream A) : a ∈ s₁ → a ∈ s₁ ⋈ s₂ := assume ains₁, obtain n h, from ains₁, exists.intro (2*n) (by rewrite [h, nth_interleave_left]) theorem mem_interleave_right {a : A} {s₁ : stream A} (s₂ : stream A) : a ∈ s₂ → a ∈ s₁ ⋈ s₂ := assume ains₂, obtain n h, from ains₂, exists.intro (2*n+1) (by rewrite [h, nth_interleave_right]) definition even (s : stream A) : stream A := corec (λ s, head s) (λ s, tail (tail s)) s definition odd (s : stream A) : stream A := even (tail s) theorem odd_eq (s : stream A) : odd s = even (tail s) := rfl theorem head_even (s : stream A) : head (even s) = head s := rfl theorem tail_even (s : stream A) : tail (even s) = even (tail (tail s)) := by esimp [even]; rewrite corec_eq theorem even_cons_cons (a₁ a₂ : A) (s : stream A) : even (a₁ :: a₂ :: s) = a₁ :: even s := by esimp [even]; rewrite corec_eq theorem even_tail (s : stream A) : even (tail s) = odd s := rfl theorem even_interleave (s₁ s₂ : stream A) : even (s₁ ⋈ s₂) = s₁ := eq_of_bisim (λ s₁' s₁, ∃ s₂, s₁' = even (s₁ ⋈ s₂)) (λ s₁' s₁ h, obtain s₂ (h₁ : s₁' = even (s₁ ⋈ s₂)), from h, begin rewrite h₁, constructor, {reflexivity}, {existsi (tail s₂), rewrite [interleave_eq, even_cons_cons, tail_cons]} end) (exists.intro s₂ rfl) theorem interleave_even_odd (s₁ : stream A) : even s₁ ⋈ odd s₁ = s₁ := eq_of_bisim (λ s' s, s' = even s ⋈ odd s) (λ s' s (h : s' = even s ⋈ odd s), begin rewrite h, constructor, {reflexivity}, {esimp, rewrite [*odd_eq, tail_interleave, tail_even]} end) rfl theorem nth_even : ∀ (n : nat) (s : stream A), nth n (even s) = nth (2*n) s | 0 s := rfl | (succ n) s := begin change nth (succ n) (even s) = nth (succ (succ (2 * n))) s, rewrite [+nth_succ, tail_even, nth_even] end theorem nth_odd : ∀ (n : nat) (s : stream A), nth n (odd s) = nth (2*n + 1) s := λ n s, by rewrite [odd_eq, nth_even] theorem mem_of_mem_even (a : A) (s : stream A) : a ∈ even s → a ∈ s := assume aines, obtain n h, from aines, exists.intro (2*n) (by rewrite [h, nth_even]) theorem mem_of_mem_odd (a : A) (s : stream A) : a ∈ odd s → a ∈ s := assume ainos, obtain n h, from ainos, exists.intro (2*n+1) (by rewrite [h, nth_odd]) open list definition append : list A → stream A → stream A | [] s := s | (a::l) s := a :: append l s theorem nil_append (s : stream A) : append [] s = s := rfl theorem cons_append (a : A) (l : list A) (s : stream A) : append (a::l) s = a :: append l s := rfl infix ++ := append -- the following local notation is used just to make the following theorem clear local infix `++ₛ`:65 := append theorem append_append : ∀ (l₁ l₂ : list A) (s : stream A), (l₁ ++ l₂) ++ₛ s = l₁ ++ (l₂ ++ₛ s) | [] l₂ s := rfl | (a::l₁) l₂ s := by rewrite [list.append_cons, *cons_append, append_append] theorem map_append (f : A → B) : ∀ (l : list A) (s : stream A), map f (l ++ s) = list.map f l ++ map f s | [] s := rfl | (a::l) s := by rewrite [cons_append, list.map_cons, map_cons, cons_append, map_append] theorem drop_append : ∀ (l : list A) (s : stream A), drop (length l) (l ++ s) = s | [] s := by esimp | (a::l) s := by rewrite [length_cons, add_one, drop_succ, cons_append, tail_cons, drop_append] theorem append_head_tail (s : stream A) : [head s] ++ tail s = s := by rewrite [cons_append, nil_append, stream.eta] theorem mem_append_right : ∀ {a : A} (l : list A) {s : stream A}, a ∈ s → a ∈ l ++ s | a [] s h := h | a (b::l) s h := have ih : a ∈ l ++ s, from mem_append_right l h, !mem_cons_of_mem ih theorem mem_append_left : ∀ {a : A} {l : list A} (s : stream A), a ∈ l → a ∈ l ++ s | a [] s h := absurd h !not_mem_nil | a (b::l) s h := or.elim (list.eq_or_mem_of_mem_cons h) (λ (aeqb : a = b), exists.intro 0 aeqb) (λ (ainl : a ∈ l), mem_cons_of_mem b (mem_append_left s ainl)) definition approx : nat → stream A → list A | 0 s := [] | (n+1) s := head s :: approx n (tail s) theorem approx_zero (s : stream A) : approx 0 s = [] := rfl theorem approx_succ (n : nat) (s : stream A) : approx (succ n) s = head s :: approx n (tail s) := rfl theorem nth_approx : ∀ (n : nat) (s : stream A), list.nth (approx (succ n) s) n = some (nth n s) | 0 s := rfl | (n+1) s := begin rewrite [approx_succ, add_one, list.nth_succ, nth_approx] end theorem append_approx_drop : ∀ (n : nat) (s : stream A), append (approx n s) (drop n s) = s := begin intro n, induction n with n' ih, {intro s, reflexivity}, {intro s, rewrite [approx_succ, drop_succ, cons_append, ih (tail s), stream.eta]} end -- Take lemma reduces a proof of equality of infinite streams to an -- induction over all their finite approximations. theorem take_lemma (s₁ s₂ : stream A) : (∀ (n : nat), approx n s₁ = approx n s₂) → s₁ = s₂ := begin intro h, apply stream.ext, intro n, induction n with n ih, {injection (h 1), assumption}, {have h₁ : some (nth (succ n) s₁) = some (nth (succ n) s₂), by rewrite [-*nth_approx, h (succ (succ n))], injection h₁, assumption} end -- auxiliary definition for cycle corecursive definition private definition cycle_f : A × list A × A × list A → A | (v, _, _, _) := v -- auxiliary definition for cycle corecursive definition private definition cycle_g : A × list A × A × list A → A × list A × A × list A | (v₁, [], v₀, l₀) := (v₀, l₀, v₀, l₀) | (v₁, v₂::l₂, v₀, l₀) := (v₂, l₂, v₀, l₀) private lemma cycle_g_cons (a : A) (a₁ : A) (l₁ : list A) (a₀ : A) (l₀ : list A) : cycle_g (a, a₁::l₁, a₀, l₀) = (a₁, l₁, a₀, l₀) := rfl definition cycle : Π (l : list A), l ≠ nil → stream A | [] h := absurd rfl h | (a::l) h := corec cycle_f cycle_g (a, l, a, l) theorem cycle_eq : ∀ (l : list A) (h : l ≠ nil), cycle l h = l ++ cycle l h | [] h := absurd rfl h | (a::l) h := have gen : ∀ l' a', corec cycle_f cycle_g (a', l', a, l) = (a' :: l') ++ₛ corec cycle_f cycle_g (a, l, a, l), begin intro l', induction l' with a₁ l₁ ih, {intro a', rewrite [corec_eq]}, {intro a', rewrite [corec_eq, cycle_g_cons, ih a₁]} end, gen l a theorem mem_cycle {a : A} {l : list A} : ∀ (h : l ≠ []), a ∈ l → a ∈ cycle l h := assume h ainl, by rewrite [cycle_eq]; exact !mem_append_left ainl theorem cycle_singleton (a : A) (h : [a] ≠ nil) : cycle [a] h = const a := coinduction rfl (λ B fr ch, by rewrite [cycle_eq, const_eq]; exact ch) definition tails (s : stream A) : stream (stream A) := corec id tail (tail s) theorem tails_eq (s : stream A) : tails s = tail s :: tails (tail s) := by esimp [tails]; rewrite [corec_eq] theorem nth_tails : ∀ (n : nat) (s : stream A), nth n (tails s) = drop n (tail s) := begin intro n, induction n with n' ih, {intros, reflexivity}, {intro s, rewrite [nth_succ, drop_succ, tails_eq, tail_cons, ih]} end theorem tails_eq_iterate (s : stream A) : tails s = iterate tail (tail s) := rfl definition inits_core (l : list A) (s : stream A) : stream (list A) := corec prod.pr1 (λ p, match p with (l', s') := (l' ++ [head s'], tail s') end) (l, s) definition inits (s : stream A) : stream (list A) := inits_core [head s] (tail s) theorem inits_core_eq (l : list A) (s : stream A) : inits_core l s = l :: inits_core (l ++ [head s]) (tail s) := by esimp [inits_core]; rewrite [corec_eq] theorem tail_inits (s : stream A) : tail (inits s) = inits_core [head s, head (tail s)] (tail (tail s)) := by esimp [inits]; rewrite inits_core_eq theorem inits_tail (s : stream A) : inits (tail s) = inits_core [head (tail s)] (tail (tail s)) := rfl theorem cons_nth_inits_core : ∀ (a : A) (n : nat) (l : list A) (s : stream A), a :: nth n (inits_core l s) = nth n (inits_core (a::l) s) := begin intro a n, induction n with n' ih, {intros, reflexivity}, {intro l s, rewrite [*nth_succ, inits_core_eq, +tail_cons, ih, inits_core_eq (a::l) s] } end theorem nth_inits : ∀ (n : nat) (s : stream A), nth n (inits s) = approx (succ n) s := begin intro n, induction n with n' ih, {intros, reflexivity}, {intros, rewrite [nth_succ, approx_succ, -ih, tail_inits, inits_tail, cons_nth_inits_core]} end theorem inits_eq (s : stream A) : inits s = [head s] :: map (list.cons (head s)) (inits (tail s)) := begin apply stream.ext, intro n, cases n, {reflexivity}, {rewrite [nth_inits, nth_succ, tail_cons, nth_map, nth_inits]} end theorem zip_inits_tails (s : stream A) : zip append (inits s) (tails s) = const s := begin apply stream.ext, intro n, rewrite [nth_zip, nth_inits, nth_tails, nth_const, approx_succ, cons_append, append_approx_drop, stream.eta] end definition pure (a : A) : stream A := const a definition apply (f : stream (A → B)) (s : stream A) : stream B := λ n, (nth n f) (nth n s) infix `⊛`:75 := apply -- input as \o* theorem identity (s : stream A) : pure id ⊛ s = s := rfl theorem composition (g : stream (B → C)) (f : stream (A → B)) (s : stream A) : pure compose ⊛ g ⊛ f ⊛ s = g ⊛ (f ⊛ s) := rfl theorem homomorphism (f : A → B) (a : A) : pure f ⊛ pure a = pure (f a) := rfl theorem interchange (fs : stream (A → B)) (a : A) : fs ⊛ pure a = pure (λ f, f a) ⊛ fs := rfl theorem map_eq_apply (f : A → B) (s : stream A) : map f s = pure f ⊛ s := rfl definition nats : stream nat := λ n, n theorem nth_nats (n : nat) : nth n nats = n := rfl theorem nats_eq : nats = 0 :: map succ nats := begin apply stream.ext, intro n, cases n, reflexivity, rewrite [nth_succ] end section open equiv lemma stream_equiv_of_equiv {A B : Type} : A ≃ B → stream A ≃ stream B | (mk f g l r) := mk (map f) (map g) begin intros, rewrite [map_map, id_of_left_inverse l, map_id] end begin intros, rewrite [map_map, id_of_righ_inverse r, map_id] end end definition lex (lt : A → A → Prop) (s₁ s₂ : stream A) : Prop := ∃ i, lt (nth i s₁) (nth i s₂) ∧ ∀ j, j < i → nth j s₁ = nth j s₂ definition lex.trans {s₁ s₂ s₃} {lt : A → A → Prop} : transitive lt → lex lt s₁ s₂ → lex lt s₂ s₃ → lex lt s₁ s₃ := assume htrans h₁ h₂, obtain i₁ hlt₁ he₁, from h₁, obtain i₂ hlt₂ he₂, from h₂, lt.by_cases (λ i₁lti₂ : i₁ < i₂, assert aux : nth i₁ s₂ = nth i₁ s₃, from he₂ _ i₁lti₂, begin existsi i₁, split, {rewrite -aux, exact hlt₁}, {intro j jlti₁, transitivity nth j s₂, exact !he₁ jlti₁, exact !he₂ (lt.trans jlti₁ i₁lti₂)} end) (λ i₁eqi₂ : i₁ = i₂, begin subst i₂, existsi i₁, split, exact htrans hlt₁ hlt₂, intro j jlti₁, transitivity nth j s₂, exact !he₁ jlti₁; exact !he₂ jlti₁ end) (λ i₂lti₁ : i₂ < i₁, assert nth i₂ s₁ = nth i₂ s₂, from he₁ _ i₂lti₁, begin existsi i₂, split, {rewrite this, exact hlt₂}, {intro j jlti₂, transitivity nth j s₂, exact !he₁ (lt.trans jlti₂ i₂lti₁), exact !he₂ jlti₂} end) end stream
633178f0f5966c0b0d8993d6a6160238663b9dd5
5ec8f5218a7c8e87dd0d70dc6b715b36d61a8d61
/cop.lean
74e73a72826e5521c660b52ad39326c782c159ac
[]
no_license
mbrodersen/kremlin
f9f2f9dd77b9744fe0ffd5f70d9fa0f1f8bd8cec
d4665929ce9012e93a0b05fc7063b96256bab86f
refs/heads/master
1,624,057,268,130
1,496,957,084,000
1,496,957,084,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
43,740
lean
/- Arithmetic and logical operators for the Compcert C and Clight languages -/ import .ctypes .memory namespace cop open ast integers floats values memory ctypes word ctypes.intsize ctypes.floatsize ctypes.signedness /- * Syntax of operators. -/ inductive unary_operation : Type | Onotbool /- boolean negation ([!] in C) -/ | Onotint /- integer complement ([~] in C) -/ | Oneg /- opposite (unary [-]) -/ | Oabsfloat /- floating-point absolute value -/ open unary_operation inductive binary_operation : Type | Oadd /- addition (binary [+]) -/ | Osub /- subtraction (binary [-]) -/ | Omul /- multiplication (binary [*]) -/ | Odiv /- division ([/]) -/ | Omod /- remainder ([%]) -/ | Oand /- bitwise and ([&]) -/ | Oor /- bitwise or ([|]) -/ | Oxor /- bitwise xor ([^]) -/ | Oshl /- left shift ([<<]) -/ | Oshr /- right shift ([>>]) -/ | Oeq /- comparison ([==]) -/ | One /- comparison ([!=]) -/ | Olt /- comparison ([<]) -/ | Ogt /- comparison ([>]) -/ | Ole /- comparison ([<=]) -/ | Oge /- comparison ([>=]) -/ open binary_operation inductive incr_or_decr : Type | Incr | Decr open incr_or_decr /- * Type classification and semantics of operators. -/ /- Most C operators are overloaded (they apply to arguments of various types) and their semantics depend on the types of their arguments. The following [classify_*] functions take as arguments the types of the arguments of an operation. They return enough information to resolve overloading for this operator applications, such as ``both arguments are floats'', or ``the first is a pointer and the second is an integer''. This classification is used in the compiler (module [Cshmgen]) to resolve overloading statically. The [sem_*] functions below compute the result of an operator application. Since operators are overloaded, the result depends both on the static types of the arguments and on their run-time values. The corresponding [classify_*] function is first called on the types of the arguments to resolve static overloading. It is then followed by a case analysis on the values of the arguments. -/ /- ** Casts and truth values -/ inductive classify_cast_cases : Type | cast_case_pointer /- between pointer types or intptr_t types -/ | cast_case_i2i (sz2 : intsize) (si2 : signedness) /- int -> int -/ | cast_case_f2f /- double -> double -/ | cast_case_s2s /- single -> single -/ | cast_case_f2s /- double -> single -/ | cast_case_s2f /- single -> double -/ | cast_case_i2f (si1 : signedness) /- int -> double -/ | cast_case_i2s (si1 : signedness) /- int -> single -/ | cast_case_f2i (sz2 : intsize) (si2 : signedness) /- double -> int -/ | cast_case_s2i (sz2 : intsize) (si2 : signedness) /- single -> int -/ | cast_case_l2l /- long -> long -/ | cast_case_i2l (si1 : signedness) /- int -> long -/ | cast_case_l2i (sz2 : intsize) (si2 : signedness) /- long -> int -/ | cast_case_l2f (si1 : signedness) /- long -> double -/ | cast_case_l2s (si1 : signedness) /- long -> single -/ | cast_case_f2l (si2 : signedness) /- double -> long -/ | cast_case_s2l (si2 : signedness) /- single -> long -/ | cast_case_i2bool /- int -> bool -/ | cast_case_l2bool /- long -> bool -/ | cast_case_f2bool /- double -> bool -/ | cast_case_s2bool /- single -> bool -/ | cast_case_struct (id1 id2 : ident) /- struct -> struct -/ | cast_case_union (id1 id2 : ident) /- union -> union -/ | cast_case_void /- any -> void -/ | cast_case_default open classify_cast_cases def classify_cast (tfrom tto : type) : classify_cast_cases := match tto, tfrom with /- To [void] -/ | Tvoid, _ := cast_case_void /- To [_Bool] -/ | Tint IBool _ _, Tint _ _ _ := cast_case_i2bool | Tint IBool _ _, Tlong _ _ := cast_case_l2bool | Tint IBool _ _, Tfloat F64 _ := cast_case_f2bool | Tint IBool _ _, Tfloat F32 _ := cast_case_s2bool | Tint IBool _ _, Tpointer _ _ := if archi.ptr64 then cast_case_l2bool else cast_case_i2bool | Tint IBool _ _, Tarray _ _ _ := if archi.ptr64 then cast_case_l2bool else cast_case_i2bool | Tint IBool _ _, Tfunction _ _ _ := if archi.ptr64 then cast_case_l2bool else cast_case_i2bool /- To [int] other than [_Bool] -/ | Tint sz2 si2 _, Tint _ _ _ := if archi.ptr64 then cast_case_i2i sz2 si2 else if sz2 = I32 then cast_case_pointer else cast_case_i2i sz2 si2 | Tint sz2 si2 _, Tlong _ _ := cast_case_l2i sz2 si2 | Tint sz2 si2 _, Tfloat F64 _ := cast_case_f2i sz2 si2 | Tint sz2 si2 _, Tfloat F32 _ := cast_case_s2i sz2 si2 | Tint sz2 si2 _, Tpointer _ _ := if archi.ptr64 then cast_case_l2i sz2 si2 else if sz2 = I32 then cast_case_pointer else cast_case_i2i sz2 si2 | Tint sz2 si2 _, Tarray _ _ _ := if archi.ptr64 then cast_case_l2i sz2 si2 else if sz2 = I32 then cast_case_pointer else cast_case_i2i sz2 si2 | Tint sz2 si2 _, Tfunction _ _ _ := if archi.ptr64 then cast_case_l2i sz2 si2 else if sz2 = I32 then cast_case_pointer else cast_case_i2i sz2 si2 /- To [long] -/ | Tlong _ _, Tlong _ _ := if archi.ptr64 then cast_case_pointer else cast_case_l2l | Tlong _ _, Tint sz1 si1 _ := cast_case_i2l si1 | Tlong si2 _, Tfloat F64 _ := cast_case_f2l si2 | Tlong si2 _, Tfloat F32 _ := cast_case_s2l si2 | Tlong si2 _, Tpointer _ _ := if archi.ptr64 then cast_case_pointer else cast_case_i2l si2 | Tlong si2 _, Tarray _ _ _ := if archi.ptr64 then cast_case_pointer else cast_case_i2l si2 | Tlong si2 _, Tfunction _ _ _ := if archi.ptr64 then cast_case_pointer else cast_case_i2l si2 /- To [float] -/ | Tfloat F64 _, Tint sz1 si1 _ := cast_case_i2f si1 | Tfloat F32 _, Tint sz1 si1 _ := cast_case_i2s si1 | Tfloat F64 _, Tlong si1 _ := cast_case_l2f si1 | Tfloat F32 _, Tlong si1 _ := cast_case_l2s si1 | Tfloat F64 _, Tfloat F64 _ := cast_case_f2f | Tfloat F32 _, Tfloat F32 _ := cast_case_s2s | Tfloat F64 _, Tfloat F32 _ := cast_case_s2f | Tfloat F32 _, Tfloat F64 _ := cast_case_f2s /- To pointer types -/ | Tpointer _ _, Tint _ _ _ := if archi.ptr64 then cast_case_i2l Unsigned else cast_case_pointer | Tpointer _ _, Tlong _ _ := if archi.ptr64 then cast_case_pointer else cast_case_l2i I32 Unsigned | Tpointer _ _, Tpointer _ _ := cast_case_pointer | Tpointer _ _, Tarray _ _ _ := cast_case_pointer | Tpointer _ _, Tfunction _ _ _ := cast_case_pointer /- To struct or union types -/ | Tstruct id2 _, Tstruct id1 _ := cast_case_struct id1 id2 | Tunion id2 _, Tunion id1 _ := cast_case_union id1 id2 /- Catch-all -/ | _, _ := cast_case_default end /- Semantics of casts. [sem_cast v1 t1 t2 m = Some v2] if value [v1], viewed with static type [t1], can be converted to type [t2], resulting in value [v2]. -/ def cast_int_int : intsize → signedness → int32 → int32 | I8 Signed i := sign_ext W8 i | I8 Unsigned i := zero_ext 8 i | I16 Signed i := sign_ext W16 i | I16 Unsigned i := zero_ext 16 i | I32 _ i := i | IBool _ i := if i = 0 then 0 else 1 def cast_int_float : signedness → int32 → float | Signed := float.of_int | Unsigned := float.of_intu def cast_float_int : signedness → float → option int32 | Signed := float.to_int | Unsigned := float.to_intu def cast_int_single : signedness → int32 → float32 | Signed := float32.of_int | Unsigned := float32.of_intu def cast_single_int : signedness → float32 → option int32 | Signed := float32.to_int | Unsigned := float32.to_intu def cast_int_long : signedness → int32 → int64 | Signed := scoe | Unsigned := ucoe def cast_long_float : signedness → int64 → float | Signed := float.of_long | Unsigned := float.of_longu def cast_long_single : signedness → int64 → float32 | Signed := float32.of_long | Unsigned := float32.of_longu def cast_float_long : signedness → float → option int64 | Signed := float.to_long | Unsigned := float.to_longu def cast_single_long : signedness → float32 → option int64 | Signed := float32.to_long | Unsigned := float32.to_longu def sem_cast (m : mem) (v : val) (t1 t2 : type) : option val := match classify_cast t1 t2, v with | cast_case_pointer, Vptr _ _ := some v | cast_case_pointer, Vint _ := if archi.ptr64 then none else some v | cast_case_pointer, Vlong _ := if archi.ptr64 then some v else none | cast_case_i2i sz2 si2, Vint i := some (Vint (cast_int_int sz2 si2 i)) | cast_case_f2f, Vfloat f := some (Vfloat f) | cast_case_s2s, Vsingle f := some (Vsingle f) | cast_case_s2f, Vsingle f := some (Vfloat (float.of_single f)) | cast_case_f2s, Vfloat f := some (Vsingle (float.to_single f)) | cast_case_i2f si1, Vint i := some (Vfloat (cast_int_float si1 i)) | cast_case_i2s si1, Vint i := some (Vsingle (cast_int_single si1 i)) | cast_case_f2i sz2 si2, Vfloat f := (λi, Vint (cast_int_int sz2 si2 i)) <$> cast_float_int si2 f | cast_case_s2i sz2 si2, Vsingle f := (λi, Vint (cast_int_int sz2 si2 i)) <$> cast_single_int si2 f | cast_case_i2bool, Vint n := some (Vint (if n = 0 then 0 else 1)) | cast_case_i2bool, Vptr b ofs := if ¬ archi.ptr64 ∧ weak_valid_pointer m b (unsigned ofs) then some Vone else none | cast_case_l2bool, Vlong n := some (Vint (if n = 0 then 0 else 1)) | cast_case_l2bool, Vptr b ofs := if archi.ptr64 ∧ weak_valid_pointer m b (unsigned ofs) then some Vone else none | cast_case_f2bool, Vfloat f := some (Vint (if float.cmp Ceq f 0 then 0 else 1)) | cast_case_s2bool, Vsingle f := some (Vint (if float32.cmp Ceq f 0 then 0 else 1)) | cast_case_l2l, Vlong n := some (Vlong n) | cast_case_i2l si, Vint n := some (Vlong (cast_int_long si n)) | cast_case_l2i sz si, Vlong n := some (Vint (cast_int_int sz si (ucoe n))) | cast_case_l2f si1, Vlong i := some (Vfloat (cast_long_float si1 i)) | cast_case_l2s si1, Vlong i := some (Vsingle (cast_long_single si1 i)) | cast_case_f2l si2, Vfloat f := Vlong <$> cast_float_long si2 f | cast_case_s2l si2, Vsingle f := Vlong <$> cast_single_long si2 f | cast_case_struct id1 id2, Vptr b ofs := if id1 = id2 then some v else none | cast_case_union id1 id2, Vptr b ofs := if id1 = id2 then some v else none | cast_case_void, v := some v | _, _ := none end /- The following describes types that can be interpreted as a boolean: integers, floats, pointers. It is used for the semantics of the [!] and [?] operators, as well as the [if], [while], and [for] statements. -/ inductive classify_bool_cases : Type | bool_case_i /- integer -/ | bool_case_l /- long -/ | bool_case_f /- double float -/ | bool_case_s /- single float -/ | bool_default open classify_bool_cases def classify_bool (ty : type) : classify_bool_cases := match typeconv ty with | Tint _ _ _ := bool_case_i | Tpointer _ _ := if archi.ptr64 then bool_case_l else bool_case_i | Tfloat F64 _ := bool_case_f | Tfloat F32 _ := bool_case_s | Tlong _ _ := bool_case_l | _ := bool_default end /- Interpretation of values as truth values. Non-zero integers, non-zero floats and non-null pointers are considered as true. The integer zero (which also represents the null pointer) and the float 0.0 are false. -/ def bool_val (m : mem) (v : val) (t : type) : option bool := match classify_bool t, v with | bool_case_i, Vint n := some (n ≠ 0) | bool_case_i, Vptr b ofs := if archi.ptr64 then none else if weak_valid_pointer m b (unsigned ofs) then some tt else none | bool_case_l, Vlong n := some (n ≠ 0) | bool_case_l, Vptr b ofs := if ¬ archi.ptr64 then none else if weak_valid_pointer m b (unsigned ofs) then some tt else none | bool_case_f, Vfloat f := some (bnot (float.cmp Ceq f 0)) | bool_case_s, Vsingle f := some (bnot (float32.cmp Ceq f 0)) | _, _ := none end /- ** Unary operators -/ /- *** Boolean negation -/ def sem_notbool (m : mem) (v : val) (ty : type) : option val := (λ b, val.of_bool (bnot b)) <$> bool_val m v ty /- *** Opposite and absolute value -/ inductive classify_neg_cases : Type | neg_case_i (s : signedness) /- int -/ | neg_case_f /- double float -/ | neg_case_s /- single float -/ | neg_case_l (s : signedness) /- long -/ | neg_default open classify_neg_cases def classify_neg : type → classify_neg_cases | (Tint I32 Unsigned _) := neg_case_i Unsigned | (Tint _ _ _) := neg_case_i Signed | (Tfloat F64 _) := neg_case_f | (Tfloat F32 _) := neg_case_s | (Tlong si _) := neg_case_l si | _ := neg_default def sem_neg (v : val) (ty : type) : option val := match classify_neg ty, v with | neg_case_i sg, Vint n := some (Vint (-n)) | neg_case_f, Vfloat f := some (Vfloat (-f)) | neg_case_s, Vsingle f := some (Vsingle (-f)) | neg_case_l sg, Vlong n := some (Vlong (-n)) | _, _ := none end def sem_absfloat (v : val) (ty : type) : option val := match classify_neg ty, v with | neg_case_i sg, Vint n := some (Vfloat (float.abs (cast_int_float sg n))) | neg_case_f, Vfloat f := some (Vfloat (float.abs f)) | neg_case_s, Vsingle f := some (Vfloat (float.abs (float.of_single f))) | neg_case_l sg, Vlong n := some (Vfloat (float.abs (cast_long_float sg n))) | _, _ := none end /- *** Bitwise complement -/ inductive classify_notint_cases : Type | notint_case_i (s : signedness) /- int -/ | notint_case_l (s : signedness) /- long -/ | notint_default open classify_notint_cases def classify_notint : type → classify_notint_cases | (Tint I32 Unsigned _) := notint_case_i Unsigned | (Tint _ _ _) := notint_case_i Signed | (Tlong si _) := notint_case_l si | _ := notint_default def sem_notint (v : val) (ty : type) : option val := match classify_notint ty, v with | notint_case_i sg, Vint n := some (Vint (word.not n)) | notint_case_l sg, Vlong n := some (Vlong (word.not n)) | _, _ := none end /- ** Binary operators -/ /- For binary operations, the "usual binary conversions" consist in - determining the type at which the operation is to be performed (a form of least upper bound of the types of the two arguments); - casting the two arguments to this common type; - performing the operation at that type. -/ inductive binarith_cases : Type | bin_case_i (s : signedness) /- at int type -/ | bin_case_l (s : signedness) /- at long int type -/ | bin_case_f /- at double float type -/ | bin_case_s /- at single float type -/ | bin_default /- error -/ open binarith_cases def classify_binarith : type → type → binarith_cases | (Tint I32 Unsigned _) (Tint _ _ _) := bin_case_i Unsigned | (Tint _ _ _) (Tint I32 Unsigned _) := bin_case_i Unsigned | (Tint _ _ _) (Tint _ _ _) := bin_case_i Signed | (Tlong Signed _) (Tlong Signed _) := bin_case_l Signed | (Tlong _ _) (Tlong _ _) := bin_case_l Unsigned | (Tlong sg _) (Tint _ _ _) := bin_case_l sg | (Tint _ _ _) (Tlong sg _) := bin_case_l sg | (Tfloat F32 _) (Tfloat F32 _) := bin_case_s | (Tfloat _ _) (Tfloat _ _) := bin_case_f | (Tfloat F64 _) (Tint _ _ _) := bin_case_f | (Tfloat F64 _) (Tlong _ _) := bin_case_f | (Tint _ _ _) (Tfloat F64 _) := bin_case_f | (Tlong _ _) (Tfloat F64 _) := bin_case_f | (Tfloat F32 _) (Tint _ _ _) := bin_case_s | (Tfloat F32 _) (Tlong _ _) := bin_case_s | (Tint _ _ _) (Tfloat F32 _) := bin_case_s | (Tlong _ _) (Tfloat F32 _) := bin_case_s | _ _ := bin_default /- The static type of the result. Both arguments are converted to this type before the actual computation. -/ def binarith_type : binarith_cases → type | (bin_case_i sg) := Tint I32 sg noattr | (bin_case_l sg) := Tlong sg noattr | bin_case_f := Tfloat F64 noattr | bin_case_s := Tfloat F32 noattr | bin_default := Tvoid def sem_binarith (sem_int : signedness → int32 → int32 → option val) (sem_long : signedness → int64 → int64 → option val) (sem_float : float → float → option val) (sem_single : float32 → float32 → option val) (m : mem) (v1 : val) (t1 : type) (v2 : val) (t2 : type) : option val := let c := classify_binarith t1 t2, t := binarith_type c in match sem_cast m v1 t1 t, sem_cast m v2 t2 t, c with | some (Vint n1), some (Vint n2), bin_case_i sg := sem_int sg n1 n2 | some (Vfloat n1), some (Vfloat n2), bin_case_f := sem_float n1 n2 | some (Vsingle n1), some (Vsingle n2), bin_case_s := sem_single n1 n2 | some (Vlong n1), some (Vlong n2), bin_case_l sg := sem_long sg n1 n2 | _, _, _ := none end /- *** Addition -/ inductive classify_add_cases : Type | add_case_pi (ty : type) (si : signedness) /- pointer, int -/ | add_case_pl (ty : type) /- pointer, long -/ | add_case_ip (si : signedness) (ty : type) /- int, pointer -/ | add_case_lp (ty : type) /- long, pointer -/ | add_default /- numerical type, numerical type -/ open classify_add_cases def classify_add (ty1 : type) (ty2 : type) := match typeconv ty1, typeconv ty2 with | Tpointer ty _, Tint _ si _ := add_case_pi ty si | Tpointer ty _, Tlong _ _ := add_case_pl ty | Tint _ si _, Tpointer ty _ := add_case_ip si ty | Tlong _ _, Tpointer ty _ := add_case_lp ty | _, _ := add_default end def ptrofs_of_int : signedness → int32 → ptrofs | Signed := ptrofs.of_ints | Unsigned := ptrofs.of_intu def sem_add_ptr_int (cenv : composite_env) (ty : type) (si : signedness) : val → val → option val | (Vptr b1 ofs1) (Vint n2) := let n2 := ptrofs_of_int si n2 in some (Vptr b1 (ofs1 + repr (sizeof cenv ty) * n2)) | (Vint n1) (Vint n2) := if archi.ptr64 then none else some (Vint (n1 + repr (sizeof cenv ty) * n2)) | (Vlong n1) (Vint n2) := let n2 := cast_int_long si n2 in if ¬ archi.ptr64 then none else some (Vlong (n1 + repr (sizeof cenv ty) * n2)) | _ _ := none def sem_add_ptr_long (cenv : composite_env) (ty : type) : val → val → option val | (Vptr b1 ofs1) (Vlong n2) := let n2 := ptrofs.of_int64 n2 in some (Vptr b1 (ofs1 + repr (sizeof cenv ty) * n2)) | (Vint n1) (Vlong n2) := let n2 : int32 := ucoe n2 in if archi.ptr64 then none else some (Vint (n1 + repr (sizeof cenv ty) * n2)) | (Vlong n1) (Vlong n2) := if ¬ archi.ptr64 then none else some (Vlong (n1 + repr (sizeof cenv ty) * n2)) | _ _ := none def sem_add (cenv : composite_env) (m : mem) (v1 : val) (t1 : type) (v2 : val) (t2 : type) : option val := match classify_add t1 t2 with | add_case_pi ty si := sem_add_ptr_int cenv ty si v1 v2 /- pointer plus integer -/ | add_case_pl ty := sem_add_ptr_long cenv ty v1 v2 /- pointer plus long -/ | add_case_ip si ty := sem_add_ptr_int cenv ty si v2 v1 /- integer plus pointer -/ | add_case_lp ty := sem_add_ptr_long cenv ty v2 v1 /- long plus pointer -/ | add_default := sem_binarith (λ sg n1 n2, some (Vint (n1 + n2))) (λ sg n1 n2, some (Vlong (n1 + n2))) (λ n1 n2, some (Vfloat (n1 + n2))) (λ n1 n2, some (Vsingle (n1 + n2))) m v1 t1 v2 t2 end /- *** Subtraction -/ inductive classify_sub_cases : Type | sub_case_pi (ty : type) (si : signedness) /- pointer, int -/ | sub_case_pp (ty : type) /- pointer, pointer -/ | sub_case_pl (ty : type) /- pointer, long -/ | sub_default /- numerical type, numerical type -/ open classify_sub_cases def classify_sub (ty1 : type) (ty2 : type) := match typeconv ty1, typeconv ty2 with | Tpointer ty _, Tint _ si _ := sub_case_pi ty si | Tpointer ty _ , Tpointer _ _ := sub_case_pp ty | Tpointer ty _, Tlong _ _ := sub_case_pl ty | _, _ := sub_default end def sem_sub (cenv : composite_env) (m : mem) (v1 : val) (t1 : type) (v2 : val) (t2 : type) : option val := match classify_sub t1 t2, v1, v2 with | sub_case_pi ty si, Vptr b1 ofs1, Vint n2 := let n2 := ptrofs_of_int si n2 in some (Vptr b1 (ofs1 - repr (sizeof cenv ty) * n2)) | sub_case_pi ty si, Vint n1, Vint n2 := if archi.ptr64 then none else some (Vint (n1 - repr (sizeof cenv ty) * n2)) | sub_case_pi ty si, Vlong n1, Vint n2 := let n2 := cast_int_long si n2 in if archi.ptr64 then some (Vlong (n1 - repr (sizeof cenv ty) * n2)) else none | sub_case_pl ty, Vptr b1 ofs1, Vlong n2 := let n2 := ptrofs.of_int64 n2 in some (Vptr b1 (ofs1 - repr (sizeof cenv ty) * n2)) | sub_case_pl ty, Vint n1, Vlong n2 := if archi.ptr64 then none else some (Vint (n1 - repr (sizeof cenv ty) * ucoe n2)) | sub_case_pl ty, Vlong n1, Vlong n2 := if archi.ptr64 then some (Vlong (n1 - repr (sizeof cenv ty) * n2)) else none | sub_case_pp ty, Vptr b1 ofs1, Vptr b2 ofs2 := if b1 = b2 then let sz := sizeof cenv ty in if 0 < sz ∧ sz ≤ max_signed ptrofs.wordsize then some (Vptrofs ((ofs1 - ofs2) / repr sz : word _)) else none else none | sub_default, _, _ := sem_binarith (λ sg n1 n2, some (Vint (n1 - n2))) (λ sg n1 n2, some (Vlong (n1 - n2))) (λ n1 n2, some (Vfloat (n1 - n2))) (λ n1 n2, some (Vsingle (n1 - n2))) m v1 t1 v2 t2 | _, _, _ := none end /- *** Multiplication, division, modulus -/ def sem_mul : mem → val → type → val → type → option val := sem_binarith (λ sg n1 n2, some (Vint (n1 * n2))) (λ sg n1 n2, some (Vlong (n1 * n2))) (λ n1 n2, some (Vfloat (n1 * n2))) (λ n1 n2, some (Vsingle (n1 * n2))) def sem_div : mem → val → type → val → type → option val := sem_binarith (λ sg n1 n2, match sg with | Signed := if n2 = 0 ∨ n1 = repr (min_signed W32) ∧ n2 = -1 then none else some (Vint (n1 / n2 : word _)) | Unsigned := if n2 = 0 then none else some (Vint (n1 / n2 : uword _)) end) (λ sg n1 n2, match sg with | Signed := if n2 = 0 ∨ n1 = repr (min_signed W64) ∧ n2 = -1 then none else some (Vlong (n1 / n2 : word _)) | Unsigned := if n2 = 0 then none else some (Vlong (n1 / n2 : uword _)) end) (λ n1 n2, some (Vfloat (n1 / n2))) (λ n1 n2, some (Vsingle (n1 / n2))) def sem_mod : mem → val → type → val → type → option val := sem_binarith (λ sg n1 n2, match sg with | Signed := if n2 = 0 ∨ n1 = repr (min_signed W32) ∧ n2 = -1 then none else some (Vint (n1 % n2 : word _)) | Unsigned := if n2 = 0 then none else some (Vint (n1 % n2 : uword _)) end) (λ sg n1 n2, match sg with | Signed := if n2 = 0 ∨ n1 = repr (min_signed W64) ∧ n2 = -1 then none else some (Vlong (n1 % n2 : word _)) | Unsigned := if n2 = 0 then none else some (Vlong (n1 % n2 : uword _)) end) (λ n1 n2, none) (λ n1 n2, none) def sem_and : mem → val → type → val → type → option val := sem_binarith (λ sg n1 n2, some (Vint (word.and n1 n2))) (λ sg n1 n2, some (Vlong (word.and n1 n2))) (λ n1 n2, none) (λ n1 n2, none) def sem_or : mem → val → type → val → type → option val := sem_binarith (λ sg n1 n2, some (Vint (word.or n1 n2))) (λ sg n1 n2, some (Vlong (word.or n1 n2))) (λ n1 n2, none) (λ n1 n2, none) def sem_xor : mem → val → type → val → type → option val := sem_binarith (λ sg n1 n2, some (Vint (word.xor n1 n2))) (λ sg n1 n2, some (Vlong (word.xor n1 n2))) (λ n1 n2, none) (λ n1 n2, none) /- *** Shifts -/ /- Shifts do not perform the usual binary conversions. Instead, each argument is converted independently, and the signedness of the result is always that of the first argument. -/ inductive classify_shift_cases : Type | shift_case_ii (s : signedness) /- int , int -/ | shift_case_ll (s : signedness) /- long, long -/ | shift_case_il (s : signedness) /- int, long -/ | shift_case_li (s : signedness) /- long, int -/ | shift_default open classify_shift_cases def classify_shift (ty1 : type) (ty2 : type) := match typeconv ty1, typeconv ty2 with | Tint I32 Unsigned _, Tint _ _ _ := shift_case_ii Unsigned | Tint _ _ _, Tint _ _ _ := shift_case_ii Signed | Tint I32 Unsigned _, Tlong _ _ := shift_case_il Unsigned | Tint _ _ _, Tlong _ _ := shift_case_il Signed | Tlong s _, Tint _ _ _ := shift_case_li s | Tlong s _, Tlong _ _ := shift_case_ll s | _, _ := shift_default end def sem_shift (sem_int : signedness → int32 → int32 → int32) (sem_long : signedness → int64 → int64 → int64) (v1 : val) (t1 : type) (v2 : val) (t2 : type) : option val := match classify_shift t1 t2, v1, v2 with | shift_case_ii sg, Vint n1, Vint n2 := if ltu n2 iwordsize then some (Vint (sem_int sg n1 n2)) else none | shift_case_il sg, Vint n1, Vlong n2 := if ltu n2 (repr 32) then some (Vint (sem_int sg n1 n2.loword)) else none | shift_case_li sg, Vlong n1, Vint n2 := if ltu n2 (repr 64) then some (Vlong (sem_long sg n1 (ucoe n2))) else none | shift_case_ll sg, Vlong n1, Vlong n2 := if ltu n2 iwordsize then some (Vlong (sem_long sg n1 n2)) else none | _, _, _ := none end def sem_shl : val → type → val → type → option val := sem_shift (λ sg n1 n2, word.shl n1 n2) (λ sg n1 n2, word.shl n1 n2) def sem_shr : val → type → val → type → option val := sem_shift (λ sg n1 n2, match sg with Signed := word.shr n1 n2 | Unsigned := word.shru n1 n2 end) (λ sg n1 n2, match sg with Signed := word.shr n1 n2 | Unsigned := word.shru n1 n2 end) /- *** Comparisons -/ inductive classify_cmp_cases : Type | cmp_case_pp /- pointer, pointer -/ | cmp_case_pi (si : signedness) /- pointer, int -/ | cmp_case_ip (si : signedness) /- int, pointer -/ | cmp_case_pl /- pointer, long -/ | cmp_case_lp /- long, pointer -/ | cmp_default /- numerical, numerical -/ open classify_cmp_cases def classify_cmp (ty1 : type) (ty2 : type) := match typeconv ty1, typeconv ty2 with | Tpointer _ _ , Tpointer _ _ := cmp_case_pp | Tpointer _ _ , Tint _ si _ := cmp_case_pi si | Tint _ si _, Tpointer _ _ := cmp_case_ip si | Tpointer _ _ , Tlong _ _ := cmp_case_pl | Tlong _ _ , Tpointer _ _ := cmp_case_lp | _, _ := cmp_default end def cmp_ptr (m : mem) (c : comparison) (v1 v2 : val) : option val := val.of_bool <$> (if archi.ptr64 then cmplu_bool else cmpu_bool) (valid_pointer m) c v1 v2 def sem_cmp (c : comparison) (m : mem) (v1 : val) (t1 : type) (v2 : val) (t2 : type) : option val := match classify_cmp t1 t2, v1, v2 with | cmp_case_pp, v1, v2 := cmp_ptr m c v1 v2 | cmp_case_pi si, v1, Vint n2 := cmp_ptr m c v1 (Vptrofs (ptrofs_of_int si n2)) | cmp_case_pi si, v1, Vptr b ofs := if archi.ptr64 then none else cmp_ptr m c v1 v2 | cmp_case_ip si, Vint n1, v2 := cmp_ptr m c (Vptrofs (ptrofs_of_int si n1)) v2 | cmp_case_ip si, Vptr b ofs, v2 := if archi.ptr64 then none else cmp_ptr m c (Vptr b ofs) v2 | cmp_case_pl, v1, Vlong n2 := cmp_ptr m c v1 (Vptrofs (ptrofs.of_int64 n2)) | cmp_case_pl, v1, Vptr b ofs := if archi.ptr64 then cmp_ptr m c v1 (Vptr b ofs) else none | cmp_case_lp, Vlong n1, v2 := cmp_ptr m c (Vptrofs (ptrofs.of_int64 n1)) v2 | cmp_case_lp, Vptr b ofs, v2 := if archi.ptr64 then cmp_ptr m c v1 v2 else none | cmp_default, v1, v2 := sem_binarith (λ sg n1 n2, some (val.of_bool ((match sg with Signed := word.cmp | Unsigned := word.cmpu end) c n1 n2))) (λ sg n1 n2, some (val.of_bool ((match sg with Signed := word.cmp | Unsigned := word.cmpu end) c n1 n2))) (λ n1 n2, some (val.of_bool (float.cmp c n1 n2))) (λ n1 n2, some (val.of_bool (float32.cmp c n1 n2))) m v1 t1 v2 t2 | _, _, _ := none end /- ** Function applications -/ inductive classify_fun_cases : Type | fun_case_f (targs : list type) (tres : type) (cc : calling_convention) /- (pointer to) function -/ | fun_default open classify_fun_cases def classify_fun : type → classify_fun_cases | (Tfunction args res cc) := fun_case_f args res cc | (Tpointer (Tfunction args res cc) _) := fun_case_f args res cc | _ := fun_default /- ** Argument of a [switch] statement -/ inductive classify_switch_cases : Type | switch_case_i | switch_case_l | switch_default open classify_switch_cases def classify_switch : type → classify_switch_cases | (Tint _ _ _) := switch_case_i | (Tlong _ _) := switch_case_l | _ := switch_default def sem_switch_arg (v : val) (ty : type) : option ℤ := match classify_switch ty, v with | switch_case_i, Vint n := some (unsigned n) | switch_case_l, Vlong n := some (unsigned n) | _, _ := none end /- * Combined semantics of unary and binary operators -/ def sem_unary_operation : unary_operation → mem → val → type → option val | Onotbool := sem_notbool | Onotint := λ_, sem_notint | Oneg := λ_, sem_neg | Oabsfloat := λ_, sem_absfloat def sem_binary_operation (cenv : composite_env) : binary_operation → mem → val → type → val → type → option val | Oadd := sem_add cenv | Osub := sem_sub cenv | Omul := sem_mul | Omod := sem_mod | Odiv := sem_div | Oand := sem_and | Oor := sem_or | Oxor := sem_xor | Oshl := λ_, sem_shl | Oshr := λ_, sem_shr | Oeq := sem_cmp Ceq | One := sem_cmp Cne | Olt := sem_cmp Clt | Ogt := sem_cmp Cgt | Ole := sem_cmp Cle | Oge := sem_cmp Cge def sem_incrdecr (cenv : composite_env) (id : incr_or_decr) (m : mem) (v : val) (ty : type) := match id with | Incr := sem_add cenv m v ty 1 type_int32s | Decr := sem_sub cenv m v ty 1 type_int32s end def incrdecr_type (ty : type) := match typeconv ty with | Tpointer ty a := Tpointer ty a | Tint sz sg a := Tint sz sg noattr | Tlong sg a := Tlong sg noattr | Tfloat sz a := Tfloat sz noattr | _ := Tvoid end /- * Compatibility with extensions and injections -/ section generic_injection parameters {f : meminj} {m m' : mem} parameter (valid_pointer_inj : ∀ b1 (ofs : ptrofs) b2 delta, f b1 = some (b2, delta) → valid_pointer m b1 (unsigned ofs) → valid_pointer m' b2 (unsigned (ofs + repr delta))) parameter (weak_valid_pointer_inj : ∀ b1 (ofs : ptrofs) b2 delta, f b1 = some (b2, delta) → weak_valid_pointer m b1 (unsigned ofs) → weak_valid_pointer m' b2 (unsigned (ofs + repr delta))) parameter (weak_valid_pointer_no_overflow : ∀ b1 (ofs : ptrofs) b2 delta, f b1 = some (b2, delta) → weak_valid_pointer m b1 (unsigned ofs) → unsigned ofs + unsigned (repr delta : ptrofs) ≤ max_unsigned ptrofs.wordsize) parameter (valid_different_pointers_inj : ∀ b1 b2 (ofs1 ofs2 : ptrofs) b1' delta1 b2' delta2, b1 ≠ b2 → valid_pointer m b1 (unsigned ofs1) → valid_pointer m b2 (unsigned ofs2) → f b1 = some (b1', delta1) → f b2 = some (b2', delta2) → b1' = b2' → unsigned (ofs1 + repr delta1) ≠ unsigned (ofs2 + repr delta2)) theorem val_inject_vtrue (f) : inject f Vtrue Vtrue := sorry' theorem val_inject_vfalse (f) : inject f Vfalse Vfalse := sorry' theorem val_inject_of_bool (f b) : inject f (val.of_bool b) (val.of_bool b) := sorry' theorem val_inject_vptrofs (n) : inject f (Vptrofs n) (Vptrofs n) := sorry' lemma sem_cast_inj {v1 ty1 ty v tv1} : sem_cast m v1 ty1 ty = some v → inject f v1 tv1 → ∃ tv, sem_cast m' tv1 ty1 ty = some tv ∧ inject f v tv := sorry' lemma bool_val_inj {v ty b tv} : bool_val m v ty = some b → inject f v tv → bool_val m' tv ty = some b := sorry' lemma sem_unary_operation_inj {op v1 ty v tv1} : sem_unary_operation op m v1 ty = some v → inject f v1 tv1 → ∃ tv, sem_unary_operation op m' tv1 ty = some tv ∧ inject f v tv := sorry' def optval_self_injects : option val → bool | (some (Vptr b ofs)) := ff | _ := tt theorem sem_binarith_inject {sem_int sem_long sem_float sem_single v1 t1 v2 t2 v v1' v2'} : sem_binarith sem_int sem_long sem_float sem_single m v1 t1 v2 t2 = some v → inject f v1 v1' → inject f v2 v2' → (∀ sg n1 n2, optval_self_injects (sem_int sg n1 n2)) → (∀ sg n1 n2, optval_self_injects (sem_long sg n1 n2)) → (∀ n1 n2, optval_self_injects (sem_float n1 n2)) → (∀ n1 n2, optval_self_injects (sem_single n1 n2)) → ∃ v', sem_binarith sem_int sem_long sem_float sem_single m' v1' t1 v2' t2 = some v' ∧ inject f v v' := sorry' theorem sem_shift_inject {sem_int sem_long v1 t1 v2 t2 v v1' v2'} : sem_shift sem_int sem_long v1 t1 v2 t2 = some v → inject f v1 v1' → inject f v2 v2' → ∃ v', sem_shift sem_int sem_long v1' t1 v2' t2 = some v' ∧ inject f v v' := sorry' theorem sem_cmp_ptr_inj {c v1 v2 v tv1 tv2} : cmp_ptr m c v1 v2 = some v → inject f v1 tv1 → inject f v2 tv2 → ∃ tv, cmp_ptr m' c tv1 tv2 = some tv ∧ inject f v tv := sorry' theorem sem_cmp_inj {cmp v1 tv1 ty1 v2 tv2 ty2 v} : sem_cmp cmp m v1 ty1 v2 ty2 = some v → inject f v1 tv1 → inject f v2 tv2 → ∃ tv, sem_cmp cmp m' tv1 ty1 tv2 ty2 = some tv ∧ inject f v tv := sorry' lemma sem_binary_operation_inj {cenv op v1 ty1 v2 ty2 v tv1 tv2} : sem_binary_operation cenv op m v1 ty1 v2 ty2 = some v → inject f v1 tv1 → inject f v2 tv2 → ∃ tv, sem_binary_operation cenv op m' tv1 ty1 tv2 ty2 = some tv ∧ inject f v tv := sorry' end generic_injection lemma sem_cast_inject {f v1 ty1 ty m v tv1 tm} : sem_cast m v1 ty1 ty = some v → inject f v1 tv1 → inject f m tm → ∃ tv, sem_cast tm tv1 ty1 ty = some tv ∧ inject f v tv := sorry' lemma sem_unary_operation_inject {f m m' op v1 ty1 v tv1} : sem_unary_operation op m v1 ty1 = some v → inject f v1 tv1 → inject f m m' → ∃ tv, sem_unary_operation op m' tv1 ty1 = some tv ∧ inject f v tv := sorry' lemma sem_binary_operation_inject {f m m' cenv op v1 ty1 v2 ty2 v tv1 tv2} : sem_binary_operation cenv op m v1 ty1 v2 ty2 = some v → inject f v1 tv1 → inject f v2 tv2 → inject f m m' → ∃ tv, sem_binary_operation cenv op m' tv1 ty1 tv2 ty2 = some tv ∧ inject f v tv := sorry' lemma bool_val_inject {f m m' v ty b tv} : bool_val m v ty = some b → inject f v tv → inject f m m' → bool_val m' tv ty = some b := sorry' /- * Some properties of operator semantics -/ /- This section collects some common-sense properties about the type classification and semantic functions above. Some properties are used in the CompCert semantics preservation proofs. Others are not, but increase confidence in the specification and its relation with the ISO C99 standard. -/ /- Relation between Boolean value and casting to [_Bool] type. -/ lemma cast_bool_bool_val {v t m} : sem_cast m v t (Tint IBool Signed noattr) = val.of_bool <$> bool_val m v t := sorry' /- Relation between Boolean value and Boolean negation. -/ lemma notbool_bool_val {v t m} : sem_notbool m v t = val.of_bool <$> bnot <$> bool_val m v t := sorry' /- Properties of values obtained by casting to a given type. -/ section val_casted inductive val_casted : val → type → Prop | int (sz si attr n) : cast_int_int sz si n = n → val_casted (Vint n) (Tint sz si attr) | float (attr n) : val_casted (Vfloat n) (Tfloat F64 attr) | single (attr n) : val_casted (Vsingle n) (Tfloat F32 attr) | long (si attr n) : val_casted (Vlong n) (Tlong si attr) | ptr_ptr (b ofs ty attr) : val_casted (Vptr b ofs) (Tpointer ty attr) | int_ptr (n ty attr) : ¬ archi.ptr64 → val_casted (Vint n) (Tpointer ty attr) | ptr_int (b ofs si attr) : ¬ archi.ptr64 → val_casted (Vptr b ofs) (Tint I32 si attr) | long_ptr (n ty attr) : archi.ptr64 → val_casted (Vlong n) (Tpointer ty attr) | ptr_long (b ofs si attr) : archi.ptr64 → val_casted (Vptr b ofs) (Tlong si attr) | struct (id attr b ofs) : val_casted (Vptr b ofs) (Tstruct id attr) | union (id attr b ofs) : val_casted (Vptr b ofs) (Tunion id attr) | void (v) : val_casted v Tvoid theorem cast_int_int_idem (sz sg i) : cast_int_int sz sg (cast_int_int sz sg i) = cast_int_int sz sg i := sorry' lemma cast_val_is_casted {v ty ty' v' m} : sem_cast v ty ty' m = some v' → val_casted v' ty' := sorry' end val_casted /- As a consequence, casting twice is equivalent to casting once. -/ lemma cast_val_casted {m v ty} : val_casted v ty → sem_cast m v ty ty = some v := sorry' lemma cast_idempotent {m v ty ty' v'} : sem_cast m v ty ty' = some v' → sem_cast m v' ty' ty' = some v' := sorry' /- Relation with the arithmetic conversions of ISO C99, section 6.3.1 -/ section arith_conv /- This is the ISO C algebra of arithmetic types, without qualifiers. [S] stands for "signed" and [U] for "unsigned". -/ inductive int_type : Type | Bool | Char | SChar | UChar | Short | UShort | Int | UInt | Long | ULong | Longlong | ULonglong open int_type inductive arith_type : Type | I (it : int_type) | Float | Double | Longdouble open arith_type instance eq_int_type : decidable_eq int_type := by tactic.mk_dec_eq_instance def is_unsigned : int_type → bool | Bool := tt | UChar := tt | UShort := tt | UInt := tt | ULong := tt | ULonglong := tt | _ := ff def unsigned_type : int_type → int_type | Char := UChar | SChar := UChar | Short := UShort | Int := UInt | Long := ULong | Longlong := ULonglong | t := t def int_sizeof : int_type → ℕ | Bool := 1 | Char := 1 | SChar := 1 | UChar := 1 | Short := 2 | UShort := 2 | Int := 4 | UInt := 4 | Long := 4 | ULong := 4 | Longlong := 8 | ULonglong := 8 /- 6.3.1.1 para 1: integer conversion rank -/ def rank : int_type → ℕ | Bool := 1 | Char := 2 | SChar := 2 | UChar := 2 | Short := 3 | UShort := 3 | Int := 4 | UInt := 4 | Long := 5 | ULong := 5 | Longlong := 6 | ULonglong := 6 /- 6.3.1.1 para 2: integer promotions, a.k.a. usual unary conversions -/ def integer_promotion (t : int_type) : int_type := if rank t < rank Int then Int else t /- 6.3.1.8: Usual arithmetic conversions, a.k.a. binary conversions. This function returns the type to which the two operands must be converted. -/ def usual_arithmetic_conversion : arith_type → arith_type → arith_type /- First, if the corresponding real type of either operand is long double, the other operand is converted, without change of type domain, to a type whose corresponding real type is long double. -/ | Longdouble _ := Longdouble | _ Longdouble := Longdouble /- Otherwise, if the corresponding real type of either operand is double, the other operand is converted, without change of type domain, to a type whose corresponding real type is double. -/ | Double _ := Double | _ Double := Double /- Otherwise, if the corresponding real type of either operand is float, the other operand is converted, without change of type domain, to a type whose corresponding real type is float. -/ | Float _ := Float | _ Float := Float /- Otherwise, the integer promotions are performed on both operands. -/ | (I i1) (I i2) := let j1 := integer_promotion i1, j2 := integer_promotion i2 in /- Then the following rules are applied to the promoted operands: If both operands have the same type, then no further conversion is needed. -/ if j1 = j2 then I j1 else match is_unsigned j1, is_unsigned j2 with /- Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank is converted to the type of the operand with greater rank. -/ | tt, tt := if rank j1 < rank j2 then I j2 else I j1 | ff, ff := if rank j1 < rank j2 then I j2 else I j1 | tt, ff := /- Otherwise, if the operand that has unsigned integer type has rank greater or equal to the rank of the type of the other operand, then the operand with signed integer type is converted to the type of the operand with unsigned integer type. -/ if rank j2 ≤ rank j1 then I j1 else /- Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, then the operand with unsigned integer type is converted to the type of the operand with signed integer type. -/ if int_sizeof j1 < int_sizeof j2 then I j2 else /- Otherwise, both operands are converted to the unsigned integer type corresponding to the type of the operand with signed integer type. -/ I (unsigned_type j2) | ff, tt := /- Same logic as above, swapping the roles of j1 and j2 -/ if rank j1 ≤ rank j2 then I j2 else if int_sizeof j2 < int_sizeof j1 then I j1 else I (unsigned_type j1) end /- Mapping ISO arithmetic types to CompCert types -/ def proj_type : arith_type → type | (I Bool) := Tint IBool Unsigned noattr | (I Char) := Tint I8 Unsigned noattr | (I SChar) := Tint I8 Signed noattr | (I UChar) := Tint I8 Unsigned noattr | (I Short) := Tint I16 Signed noattr | (I UShort) := Tint I16 Unsigned noattr | (I Int) := Tint I32 Signed noattr | (I UInt) := Tint I32 Unsigned noattr | (I Long) := Tint I32 Signed noattr | (I ULong) := Tint I32 Unsigned noattr | (I Longlong) := Tlong Signed noattr | (I ULonglong) := Tlong Unsigned noattr | Float := Tfloat F32 noattr | Double := Tfloat F64 noattr | Longdouble := Tfloat F64 noattr /- Relation between [typeconv] and integer promotion. -/ lemma typeconv_integer_promotion (i) : typeconv (proj_type (I i)) = proj_type (I (integer_promotion i)) := sorry' /- Relation between [classify_binarith] and arithmetic conversion. -/ lemma classify_binarith_arithmetic_conversion (t1 t2) : binarith_type (classify_binarith (proj_type t1) (proj_type t2)) = proj_type (usual_arithmetic_conversion t1 t2) := sorry' end arith_conv end cop
76818fb20a39d8cb42215b4741e335e4836aa7f8
618003631150032a5676f229d13a079ac875ff77
/src/data/real/irrational.lean
e8b361750c2f165fa1519f3fb11af14d6acbbdc4
[ "Apache-2.0" ]
permissive
awainverse/mathlib
939b68c8486df66cfda64d327ad3d9165248c777
ea76bd8f3ca0a8bf0a166a06a475b10663dec44a
refs/heads/master
1,659,592,962,036
1,590,987,592,000
1,590,987,592,000
268,436,019
1
0
Apache-2.0
1,590,990,500,000
1,590,990,500,000
null
UTF-8
Lean
false
false
8,234
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Yury Kudryashov. -/ import data.real.basic import algebra.gcd_domain import ring_theory.multiplicity /-! # Irrational real numbers In this file we define a predicate `irrational` on `ℝ`, prove that the `n`-th root of an integer number is irrational if it is not integer, and that `sqrt q` is irrational if and only if `rat.sqrt q * rat.sqrt q ≠ q ∧ 0 ≤ q`. We also provide dot-style constructors like `irrational.add_rat`, `irrational.rat_sub` etc. -/ open rat real multiplicity /-- A real number is irrational if it is not equal to any rational number. -/ def irrational (x : ℝ) := x ∉ set.range (coe : ℚ → ℝ) /-! ### Irrationality of roots of integer and rational numbers -/ /-- If `x^n`, `n > 0`, is integer and is not the `n`-th power of an integer, then `x` is irrational. -/ theorem irrational_nrt_of_notint_nrt {x : ℝ} (n : ℕ) (m : ℤ) (hxr : x ^ n = m) (hv : ¬ ∃ y : ℤ, x = y) (hnpos : 0 < n) : irrational x := begin rintros ⟨⟨N, D, P, C⟩, rfl⟩, rw [← cast_pow] at hxr, have c1 : ((D : ℤ) : ℝ) ≠ 0, { rw [int.cast_ne_zero, int.coe_nat_ne_zero], exact ne_of_gt P }, have c2 : ((D : ℤ) : ℝ) ^ n ≠ 0 := pow_ne_zero _ c1, rw [num_denom', cast_pow, cast_mk, div_pow, div_eq_iff_mul_eq c2, ← int.cast_pow, ← int.cast_pow, ← int.cast_mul, int.cast_inj] at hxr, have hdivn : ↑D ^ n ∣ N ^ n := dvd.intro_left m hxr, rw [← int.dvd_nat_abs, ← int.coe_nat_pow, int.coe_nat_dvd, int.nat_abs_pow, nat.pow_dvd_pow_iff hnpos] at hdivn, have hD : D = 1 := by rw [← nat.gcd_eq_right hdivn, C.gcd_eq_one], subst D, refine hv ⟨N, _⟩, rw [num_denom', int.coe_nat_one, mk_eq_div, int.cast_one, div_one, cast_coe_int] end /-- If `x^n = m` is an integer and `n` does not divide the `multiplicity p m`, then `x` is irrational. -/ theorem irrational_nrt_of_n_not_dvd_multiplicity {x : ℝ} (n : ℕ) {m : ℤ} (hm : m ≠ 0) (p : ℕ) [hp : fact p.prime] (hxr : x ^ n = m) (hv : (multiplicity (p : ℤ) m).get (finite_int_iff.2 ⟨hp.ne_one, hm⟩) % n ≠ 0) : irrational x := begin rcases nat.eq_zero_or_pos n with rfl | hnpos, { rw [eq_comm, pow_zero, ← int.cast_one, int.cast_inj] at hxr, simpa [hxr, multiplicity.one_right (mt is_unit_iff_dvd_one.1 (mt int.coe_nat_dvd.1 hp.not_dvd_one)), nat.zero_mod] using hv }, refine irrational_nrt_of_notint_nrt _ _ hxr _ hnpos, rintro ⟨y, rfl⟩, rw [← int.cast_pow, int.cast_inj] at hxr, subst m, have : y ≠ 0, { rintro rfl, rw zero_pow hnpos at hm, exact hm rfl }, erw [multiplicity.pow' (nat.prime_iff_prime_int.1 hp) (finite_int_iff.2 ⟨hp.ne_one, this⟩), nat.mul_mod_right] at hv, exact hv rfl end theorem irrational_sqrt_of_multiplicity_odd (m : ℤ) (hm : 0 < m) (p : ℕ) [hp : fact p.prime] (Hpv : (multiplicity (p : ℤ) m).get (finite_int_iff.2 ⟨hp.ne_one, (ne_of_lt hm).symm⟩) % 2 = 1) : irrational (sqrt m) := @irrational_nrt_of_n_not_dvd_multiplicity _ 2 _ (ne.symm (ne_of_lt hm)) p hp (sqr_sqrt (int.cast_nonneg.2 $ le_of_lt hm)) (by rw Hpv; exact one_ne_zero) theorem nat.prime.irrational_sqrt {p : ℕ} (hp : nat.prime p) : irrational (sqrt p) := @irrational_sqrt_of_multiplicity_odd p (int.coe_nat_pos.2 hp.pos) p hp $ by simp [multiplicity_self (mt is_unit_iff_dvd_one.1 (mt int.coe_nat_dvd.1 hp.not_dvd_one) : _)]; refl theorem irrational_sqrt_two : irrational (sqrt 2) := by simpa using nat.prime_two.irrational_sqrt theorem irrational_sqrt_rat_iff (q : ℚ) : irrational (sqrt q) ↔ rat.sqrt q * rat.sqrt q ≠ q ∧ 0 ≤ q := if H1 : rat.sqrt q * rat.sqrt q = q then iff_of_false (not_not_intro ⟨rat.sqrt q, by rw [← H1, cast_mul, sqrt_mul_self (cast_nonneg.2 $ rat.sqrt_nonneg q), sqrt_eq, abs_of_nonneg (rat.sqrt_nonneg q)]⟩) (λ h, h.1 H1) else if H2 : 0 ≤ q then iff_of_true (λ ⟨r, hr⟩, H1 $ (exists_mul_self _).1 ⟨r, by rwa [eq_comm, sqrt_eq_iff_mul_self_eq (cast_nonneg.2 H2), ← cast_mul, cast_inj] at hr; rw [← hr]; exact real.sqrt_nonneg _⟩) ⟨H1, H2⟩ else iff_of_false (not_not_intro ⟨0, by rw cast_zero; exact (sqrt_eq_zero_of_nonpos (rat.cast_nonpos.2 $ le_of_not_le H2)).symm⟩) (λ h, H2 h.2) instance (q : ℚ) : decidable (irrational (sqrt q)) := decidable_of_iff' _ (irrational_sqrt_rat_iff q) /-! ### Adding/subtracting/multiplying by rational numbers -/ lemma rat.not_irrational (q : ℚ) : ¬irrational q := λ h, h ⟨q, rfl⟩ namespace irrational variables (q : ℚ) {x y : ℝ} open_locale classical theorem add_cases : irrational (x + y) → irrational x ∨ irrational y := begin delta irrational, contrapose!, rintros ⟨⟨rx, rfl⟩, ⟨ry, rfl⟩⟩, exact ⟨rx + ry, cast_add rx ry⟩ end theorem of_rat_add (h : irrational (q + x)) : irrational x := h.add_cases.elim (λ h, absurd h q.not_irrational) id theorem rat_add (h : irrational x) : irrational (q + x) := of_rat_add (-q) $ by rwa [cast_neg, neg_add_cancel_left] theorem of_add_rat : irrational (x + q) → irrational x := add_comm ↑q x ▸ of_rat_add q theorem add_rat (h : irrational x) : irrational (x + q) := add_comm ↑q x ▸ h.rat_add q theorem of_neg (h : irrational (-x)) : irrational x := λ ⟨q, hx⟩, h ⟨-q, by rw [cast_neg, hx]⟩ protected theorem neg (h : irrational x) : irrational (-x) := of_neg $ by rwa neg_neg theorem sub_rat (h : irrational x) : irrational (x - q) := by simpa only [cast_neg] using h.add_rat (-q) theorem rat_sub (h : irrational x) : irrational (q - x) := h.neg.rat_add q theorem of_sub_rat (h : irrational (x - q)) : irrational x := of_add_rat (-q) $ by simpa only [cast_neg] theorem of_rat_sub (h : irrational (q - x)) : irrational x := (h.of_rat_add _).of_neg theorem mul_cases : irrational (x * y) → irrational x ∨ irrational y := begin delta irrational, contrapose!, rintros ⟨⟨rx, rfl⟩, ⟨ry, rfl⟩⟩, exact ⟨rx * ry, cast_mul rx ry⟩ end theorem of_mul_rat (h : irrational (x * q)) : irrational x := h.mul_cases.elim id (λ h, absurd h q.not_irrational) theorem mul_rat (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (x * q) := of_mul_rat q⁻¹ $ by rwa [mul_assoc, ← cast_mul, mul_inv_cancel hq, cast_one, mul_one] theorem of_rat_mul : irrational (q * x) → irrational x := mul_comm x q ▸ of_mul_rat q theorem rat_mul (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (q * x) := mul_comm x q ▸ h.mul_rat hq theorem of_mul_self (h : irrational (x * x)) : irrational x := h.mul_cases.elim id id theorem of_inv (h : irrational x⁻¹) : irrational x := λ ⟨q, hq⟩, h $ hq ▸ ⟨q⁻¹, q.cast_inv⟩ protected theorem inv (h : irrational x) : irrational x⁻¹ := of_inv $ by rwa inv_inv' theorem div_cases (h : irrational (x / y)) : irrational x ∨ irrational y := h.mul_cases.imp id of_inv theorem of_rat_div (h : irrational (q / x)) : irrational x := (h.of_rat_mul q).of_inv theorem of_one_div (h : irrational (1 / x)) : irrational x := of_rat_div 1 $ by rwa [cast_one] theorem of_pow : ∀ n : ℕ, irrational (x^n) → irrational x | 0 := λ h, (h ⟨1, cast_one⟩).elim | (n+1) := λ h, h.mul_cases.elim id (of_pow n) theorem of_fpow : ∀ m : ℤ, irrational (x^m) → irrational x | (n:ℕ) := of_pow n | -[1+n] := λ h, by { rw fpow_neg_succ_of_nat at h, exact h.of_inv.of_pow _ } end irrational section variables {q : ℚ} {x : ℝ} open irrational @[simp] theorem irrational_rat_add_iff : irrational (q + x) ↔ irrational x := ⟨of_rat_add q, rat_add q⟩ @[simp] theorem irrational_add_rat_iff : irrational (x + q) ↔ irrational x := ⟨of_add_rat q, add_rat q⟩ @[simp] theorem irrational_rat_sub_iff : irrational (q - x) ↔ irrational x := ⟨of_rat_sub q, rat_sub q⟩ @[simp] theorem irrational_sub_rat_iff : irrational (x - q) ↔ irrational x := ⟨of_sub_rat q, sub_rat q⟩ @[simp] theorem irrational_neg_iff : irrational (-x) ↔ irrational x := ⟨of_neg, irrational.neg⟩ @[simp] theorem irrational_inv_iff : irrational x⁻¹ ↔ irrational x := ⟨of_inv, irrational.inv⟩ end
35ee8d9b6f9e455de84da9e8d2e50850c64713f0
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/data/int/absolute_value.lean
745c78c96b006721f6bae5a1ebba5106f6636312
[ "Apache-2.0" ]
permissive
alreadydone/mathlib
dc0be621c6c8208c581f5170a8216c5ba6721927
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
refs/heads/master
1,685,523,275,196
1,670,184,141,000
1,670,184,141,000
287,574,545
0
0
Apache-2.0
1,670,290,714,000
1,597,421,623,000
Lean
UTF-8
Lean
false
false
1,409
lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import algebra.module.basic import algebra.order.absolute_value import data.int.cast.lemmas import data.int.units import group_theory.group_action.units /-! # Absolute values and the integers This file contains some results on absolute values applied to integers. ## Main results * `absolute_value.map_units_int`: an absolute value sends all units of `ℤ` to `1` * `int.nat_abs_hom`: `int.nat_abs` bundled as a `monoid_with_zero_hom` -/ variables {R S : Type*} [ring R] [linear_ordered_comm_ring S] @[simp] lemma absolute_value.map_units_int (abv : absolute_value ℤ S) (x : ℤˣ) : abv x = 1 := by rcases int.units_eq_one_or x with (rfl | rfl); simp @[simp] lemma absolute_value.map_units_int_cast [nontrivial R] (abv : absolute_value R S) (x : ℤˣ) : abv ((x : ℤ) : R) = 1 := by rcases int.units_eq_one_or x with (rfl | rfl); simp @[simp] lemma absolute_value.map_units_int_smul (abv : absolute_value R S) (x : ℤˣ) (y : R) : abv (x • y) = abv y := by rcases int.units_eq_one_or x with (rfl | rfl); simp /-- `int.nat_abs` as a bundled monoid with zero hom. -/ @[simps] def int.nat_abs_hom : ℤ →*₀ ℕ := { to_fun := int.nat_abs, map_mul' := int.nat_abs_mul, map_one' := int.nat_abs_one, map_zero' := int.nat_abs_zero }
608d9899698c0f87411e837400a618909de006de
eb9357a70318e50e095b58730bebfe0cffee457f
/lean/love08_operational_semantics_demo.lean
0da711cf2d2ee7fcb04009018a0fbfacb4c4b74f
[]
no_license
Vierkantor/logical_verification_2021
7485dd916953131d501760f023d5b30fbb74d36a
9500b9c194e22a9ab4067321cfed7a1f445afcfc
refs/heads/main
1,692,560,845,086
1,624,721,275,000
1,624,721,275,000
416,354,079
0
0
null
null
null
null
UTF-8
Lean
false
false
22,102
lean
import .lovelib /-! # LoVe Demo 8: Operational Semantics In this and the next two lectures, we will see how to use Lean to specify the syntax and semantics of programming languages and to reason about the semantics. -/ set_option pp.beta true set_option pp.generalized_field_notation false namespace LoVe /-! ## Formal Semantics A formal semantics helps specify and reason about the programming language itself, and about individual programs. It can form the basis of verified compilers, interpreters, verifiers, static analyzers, type checkers, etc. Without formal proofs, these tools are **almost always wrong**. In this area, proof assistants are widely used. Every year, about 10-20% of POPL papers are partially or totally formalized. Reasons for this success: * Little machinery (background libraries, tactics) is needed to get started, beyond inductive types and predicates and recursive functions. * The proofs tend to have lots of cases, which is a good match for computers. * Proof assistants keep track of what needs to be changed when as extend the programming language with more features. Case in point: WebAssembly. To quote Conrad Watt (with some abbreviations): We have produced a full Isabelle mechanisation of the core execution semantics and type system of the WebAssembly language. To complete this proof, **several deficiencies** in the official WebAssembly specification, uncovered by our proof and modelling work, needed to be corrected. In some cases, these meant that the type system was **originally unsound**. We have maintained a constructive dialogue with the working group, verifying new features as they are added. In particular, the mechanism by which a WebAssembly implementation interfaces with its host environment was not formally specified in the working group's original paper. Extending our mechanisation to model this feature revealed a deficiency in the WebAssembly specification that **sabotaged the soundness** of the type system. ## A Minimalistic Imperative Language A state `s` is a function from variable names to values (`string → ℕ`). __WHILE__ is a minimalistic imperative language with the following grammar: S ::= skip -- no-op | x := a -- assignment | S ; S -- sequential composition | if b then S else S -- conditional statement | while b do S -- while loop where `S` stands for a statement (also called command or program), `x` for a variable, `a` for an arithmetic expression, and `b` for a Boolean expression. -/ #check state inductive stmt : Type | skip : stmt | assign : string → (state → ℕ) → stmt | seq : stmt → stmt → stmt | ite : (state → Prop) → stmt → stmt → stmt | while : (state → Prop) → stmt → stmt infixr ` ;; ` : 90 := stmt.seq /-! In our grammar, we deliberately leave the syntax of arithmetic and Boolean expressions unspecified. In Lean, we have the choice: * We could use a type such as `aexp` from lecture 1 and similarly for Boolean expressions. * We could decide that an arithmetic expression is simply a function from states to natural numbers (`state → ℕ`) and a Boolean expression is a predicate (`state → Prop` or `state → bool`). This corresponds to the difference between deep and shallow embeddings: * A __deep embedding__ of some syntax (expression, formula, program, etc.) consists of an abstract syntax tree specified in the proof assistant (e.g., `aexp`) with a semantics (e.g., `eval`). * In contrast, a __shallow embedding__ simply reuses the corresponding mechanisms from the logic (e.g., λ-terms, functions and predicate types). A deep embedding allows us to reason about the syntax (and its semantics). A shallow embedding is more lightweight, because we can use it directly, without having to define a semantics. We will use a deep embedding of programs (which we find interesting), and shallow embeddings of assignments and Boolean expressions (which we find boring). -/ def silly_loop : stmt := stmt.while (λs, s "x" > s "y") (stmt.skip ;; stmt.assign "x" (λs, s "x" - 1)) /-! ## Big-Step Semantics An __operational semantics__ corresponds to an idealized interpreter (specified in a Prolog-like language). Two main variants: * big-step semantics; * small-step semantics. In a __big-step semantics__ (also called __natural semantics__), judgments have the form `(S, s) ⟹ t`: Starting in a state `s`, executing `S` terminates in the state `t`. Example: `(x := x + y; y := 0, [x ↦ 3, y ↦ 5]) ⟹ [x ↦ 8, y ↦ 0]` Derivation rules: ——————————————— Skip (skip, s) ⟹ s ——————————————————————————— Asn (x := a, s) ⟹ s[x ↦ s(a)] (S, s) ⟹ t (T, t) ⟹ u ——————————————————————————— Seq (S; T, s) ⟹ u (S, s) ⟹ t ————————————————————————————— If-True if s(b) is true (if b then S else T, s) ⟹ t (T, s) ⟹ t ————————————————————————————— If-False if s(b) is false (if b then S else T, s) ⟹ t (S, s) ⟹ t (while b do S, t) ⟹ u —————————————————————————————————————— While-True if s(b) is true (while b do S, s) ⟹ u ————————————————————————— While-False if s(b) is false (while b do S, s) ⟹ s Above, `s(e)` denotes the value of expression `e` in state `s`. In Lean, the judgment corresponds to an inductive predicate, and the derivation rules correspond to the predicate's introduction rules. Using an inductive predicate as opposed to a recursive function allows us to cope with nontermination (e.g., a diverging `while`) and nondeterminism (e.g., multithreading). -/ inductive big_step : stmt × state → state → Prop | skip {s} : big_step (stmt.skip, s) s | assign {x a s} : big_step (stmt.assign x a, s) (s{x ↦ a s}) | seq {S T s t u} (hS : big_step (S, s) t) (hT : big_step (T, t) u) : big_step (S ;; T, s) u | ite_true {b : state → Prop} {S T s t} (hcond : b s) (hbody : big_step (S, s) t) : big_step (stmt.ite b S T, s) t | ite_false {b : state → Prop} {S T s t} (hcond : ¬ b s) (hbody : big_step (T, s) t) : big_step (stmt.ite b S T, s) t | while_true {b : state → Prop} {S s t u} (hcond : b s) (hbody : big_step (S, s) t) (hrest : big_step (stmt.while b S, t) u) : big_step (stmt.while b S, s) u | while_false {b : state → Prop} {S s} (hcond : ¬ b s) : big_step (stmt.while b S, s) s infix ` ⟹ ` : 110 := big_step lemma silly_loop_from_1_big_step : (silly_loop, (λ_, 0){"x" ↦ 1}) ⟹ (λ_, 0) := begin rw silly_loop, apply big_step.while_true, { simp }, { apply big_step.seq, { apply big_step.skip }, { apply big_step.assign } }, { simp, apply big_step.while_false, linarith } end /-! ## Properties of the Big-Step Semantics Equipped with a big-step semantics, we can * prove properties of the programming language, such as **equivalence proofs** between programs and **determinism**; * reason about **concrete programs**, proving theorems relating final states `t` with initial states `s`. -/ lemma big_step_deterministic {S s l r} (hl : (S, s) ⟹ l) (hr : (S, s) ⟹ r) : l = r := begin induction' hl, case skip { cases' hr, refl }, case assign { cases' hr, refl }, case seq : S T s t l hS hT ihS ihT { cases' hr with _ _ _ _ _ _ _ t' _ hS' hT', cases' ihS hS', cases' ihT hT', refl }, case ite_true : b S T s t hb hS ih { cases' hr, { apply ih hr }, { cc } }, case ite_false : b S T s t hb hT ih { cases' hr, { cc }, { apply ih hr } }, case while_true : b S s t u hb hS hw ihS ihw { cases' hr, { cases' ihS hr, cases' ihw hr_1, refl }, { cc } }, { cases' hr, { cc }, { refl } } end lemma big_step_terminates {S s} : ∃t, (S, s) ⟹ t := sorry -- unprovable lemma big_step_doesnt_terminate {S s t} : ¬ (stmt.while (λ_, true) S, s) ⟹ t := begin intro hw, induction' hw, case while_true { assumption }, case while_false { cc } end /-! We can define inversion rules about the big-step semantics: -/ @[simp] lemma big_step_skip_iff {s t} : (stmt.skip, s) ⟹ t ↔ t = s := begin apply iff.intro, { intro h, cases' h, refl }, { intro h, rw h, exact big_step.skip } end @[simp] lemma big_step_assign_iff {x a s t} : (stmt.assign x a, s) ⟹ t ↔ t = s{x ↦ a s} := begin apply iff.intro, { intro h, cases' h, refl }, { intro h, rw h, exact big_step.assign } end @[simp] lemma big_step_seq_iff {S T s t} : (S ;; T, s) ⟹ t ↔ (∃u, (S, s) ⟹ u ∧ (T, u) ⟹ t) := begin apply iff.intro, { intro h, cases' h, apply exists.intro, apply and.intro; assumption }, { intro h, cases' h, cases' h, apply big_step.seq; assumption } end @[simp] lemma big_step_ite_iff {b S T s t} : (stmt.ite b S T, s) ⟹ t ↔ (b s ∧ (S, s) ⟹ t) ∨ (¬ b s ∧ (T, s) ⟹ t) := begin apply iff.intro, { intro h, cases' h, { apply or.intro_left, cc }, { apply or.intro_right, cc } }, { intro h, cases' h; cases' h, { apply big_step.ite_true; assumption }, { apply big_step.ite_false; assumption } } end lemma big_step_while_iff {b S s u} : (stmt.while b S, s) ⟹ u ↔ (∃t, b s ∧ (S, s) ⟹ t ∧ (stmt.while b S, t) ⟹ u) ∨ (¬ b s ∧ u = s) := begin apply iff.intro, { intro h, cases' h, { apply or.intro_left, apply exists.intro t, cc }, { apply or.intro_right, cc } }, { intro h, cases' h, case inl { cases' h with t h, cases' h with hb h, cases' h with hS hwhile, exact big_step.while_true hb hS hwhile }, case inr { cases' h with hb hus, rw hus, exact big_step.while_false hb } } end lemma big_step_while_true_iff {b : state → Prop} {S s u} (hcond : b s) : (stmt.while b S, s) ⟹ u ↔ (∃t, (S, s) ⟹ t ∧ (stmt.while b S, t) ⟹ u) := by rw big_step_while_iff; simp [hcond] @[simp] lemma big_step_while_false_iff {b : state → Prop} {S s t} (hcond : ¬ b s) : (stmt.while b S, s) ⟹ t ↔ t = s := by rw big_step_while_iff; simp [hcond] /-! ## Small-Step Semantics A big-step semantics * does not let us reason about intermediate states; * does not let us express nontermination or interleaving (for multithreading). __Small-step semantics__ (also called __structural operational semantics__) solve the above issues. A judgment has the form `(S, s) ⇒ (T, t)`: Starting in a state `s`, executing one step of `S` leaves us in the state `t`, with the program `T` remaining to be executed. An execution is a finite or infinite chain `(S₀, s₀) ⇒ (S₁, s₁) ⇒ …`. A pair `(S, s)` is called a __configuration__. It is __final__ if no transition of the form `(S, s) ⇒ _` is possible. Example: `(x := x + y; y := 0, [x ↦ 3, y ↦ 5])` `⇒ (skip; y := 0, [x ↦ 8, y ↦ 5])` `⇒ (y := 0, [x ↦ 8, y ↦ 5])` `⇒ (skip, [x ↦ 8, y ↦ 0])` Derivation rules: ————————————————————————————————— Asn (x := a, s) ⇒ (skip, s[x ↦ s(a)]) (S, s) ⇒ (S', s') ———-————————————————————— Seq-Step (S ; T, s) ⇒ (S' ; T, s') —————————————————————— Seq-Skip (skip ; S, s) ⇒ (S, s) ———————————————————————————————— If-True if s(b) is true (if b then S else T, s) ⇒ (S, s) ———————————————————————————————— If-False if s(b) is false (if b then S else T, s) ⇒ (T, s) ——————————————————————————————————————————————————————————————— While (while b do S, s) ⇒ (if b then (S ; while b do S) else skip, s) There is no rule for `skip` (why?). -/ inductive small_step : stmt × state → stmt × state → Prop | assign {x a s} : small_step (stmt.assign x a, s) (stmt.skip, s{x ↦ a s}) | seq_step {S S' T s s'} (hS : small_step (S, s) (S', s')) : small_step (S ;; T, s) (S' ;; T, s') | seq_skip {T s} : small_step (stmt.skip ;; T, s) (T, s) | ite_true {b : state → Prop} {S T s} (hcond : b s) : small_step (stmt.ite b S T, s) (S, s) | ite_false {b : state → Prop} {S T s} (hcond : ¬ b s) : small_step (stmt.ite b S T, s) (T, s) | while {b : state → Prop} {S s} : small_step (stmt.while b S, s) (stmt.ite b (S ;; stmt.while b S) stmt.skip, s) infixr ` ⇒ ` := small_step infixr ` ⇒* ` : 100 := star small_step lemma silly_loop_from_1_small_step : (silly_loop, (λ_, 0){"x" ↦ 1}) ⇒* (stmt.skip, ((λ_, 0) : state)) := begin rw silly_loop, apply star.head, { apply small_step.while }, { apply star.head, { apply small_step.ite_true, simp }, { apply star.head, { apply small_step.seq_step, apply small_step.seq_skip }, { apply star.head, { apply small_step.seq_step, apply small_step.assign }, { apply star.head, { apply small_step.seq_skip }, { apply star.head, { apply small_step.while }, { apply star.head, { apply small_step.ite_false, simp }, { simp } } } } } } } end /-! Equipped with a small-step semantics, we can **define** a big-step semantics: `(S, s) ⟹ t` if and only if `(S, s) ⇒* (skip, t)` where `r*` denotes the reflexive transitive closure of a relation `r`. Alternatively, if we have already defined a big-step semantics, we can **prove** the above equivalence theorem to validate our definitions. The main disadvantage of small-step semantics is that we now have two relations, `⇒` and `⇒*`, and reasoning tends to be more complicated. ## Properties of the Small-Step Semantics We can prove that a configuration `(S, s)` is final if and only if `S = skip`. This ensures that we have not forgotten a derivation rule. -/ lemma small_step_final (S s) : (¬ ∃T t, (S, s) ⇒ (T, t)) ↔ S = stmt.skip := begin induction' S, case skip { simp, intros T t hstep, cases' hstep }, case assign : x a { simp, apply exists.intro stmt.skip, apply exists.intro (s{x ↦ a s}), exact small_step.assign }, case seq : S T ihS ihT { simp, cases' classical.em (S = stmt.skip), case inl { rw h, apply exists.intro T, apply exists.intro s, exact small_step.seq_skip }, case inr { simp [h, auto.not_forall_eq, auto.not_not_eq] at ihS, cases' ihS s with S' hS', cases' hS' with s' hs', apply exists.intro (S' ;; T), apply exists.intro s', exact small_step.seq_step hs' } }, case ite : b S T ihS ihT { simp, cases' classical.em (b s), case inl { apply exists.intro S, apply exists.intro s, exact small_step.ite_true h }, case inr { apply exists.intro T, apply exists.intro s, exact small_step.ite_false h } }, case while : b S ih { simp, apply exists.intro (stmt.ite b (S ;; stmt.while b S) stmt.skip), apply exists.intro s, exact small_step.while } end lemma small_step_deterministic {S s Ll Rr} (hl : (S, s) ⇒ Ll) (hr : (S, s) ⇒ Rr) : Ll = Rr := begin induction' hl, case assign : x a s { cases' hr, refl }, case seq_step : S S₁ T s s₁ hS₁ ih { cases' hr, case seq_step : S S₂ _ _ s₂ hS₂ { have hSs₁₂ := ih hS₂, cc }, case seq_skip { cases' hS₁ } }, case seq_skip : T s { cases' hr, case seq_step { cases' hr }, case seq_skip { refl } }, case ite_true : b S T s hcond { cases' hr, case ite_true { refl }, case ite_false { cc } }, case ite_false : b S T s hcond { cases' hr, case ite_true { cc }, case ite_false { refl } }, case while : b S s { cases' hr, refl } end /-! We can define inversion rules also about the small-step semantics. Here are three examples: -/ lemma small_step_skip {S s t} : ¬ ((stmt.skip, s) ⇒ (S, t)) := by intro h; cases' h @[simp] lemma small_step_seq_iff {S T s Ut} : (S ;; T, s) ⇒ Ut ↔ (∃S' t, (S, s) ⇒ (S', t) ∧ Ut = (S' ;; T, t)) ∨ (S = stmt.skip ∧ Ut = (T, s)) := begin apply iff.intro, { intro h, cases' h, { apply or.intro_left, apply exists.intro S', apply exists.intro s', cc }, { apply or.intro_right, cc } }, { intro h, cases' h, { cases' h, cases' h, cases' h, rw right, apply small_step.seq_step, assumption }, { cases' h, rw left, rw right, apply small_step.seq_skip } } end @[simp] lemma small_step_ite_iff {b S T s Us} : (stmt.ite b S T, s) ⇒ Us ↔ (b s ∧ Us = (S, s)) ∨ (¬ b s ∧ Us = (T, s)) := begin apply iff.intro, { intro h, cases' h, { apply or.intro_left, cc }, { apply or.intro_right, cc } }, { intro h, cases' h, { cases' h, rw right, apply small_step.ite_true, assumption }, { cases' h, rw right, apply small_step.ite_false, assumption } } end /-! ### Equivalence of the Big-Step and the Small-Step Semantics (**optional**) A more important result is the connection between the big-step and the small-step semantics: `(S, s) ⟹ t ↔ (S, s) ⇒* (stmt.skip, t)` Its proof, given below, is beyond the scope of this course. -/ lemma star_small_step_seq {S T s u} (h : (S, s) ⇒* (stmt.skip, u)) : (S ;; T, s) ⇒* (stmt.skip ;; T, u) := begin apply star.lift (λSs, (prod.fst Ss ;; T, prod.snd Ss)) _ h, intros Ss Ss' h, cases' Ss, cases' Ss', apply small_step.seq_step, assumption end lemma star_small_step_of_big_step {S s t} (h : (S, s) ⟹ t) : (S, s) ⇒* (stmt.skip, t) := begin induction' h, case skip { refl }, case assign { exact star.single small_step.assign }, case seq : S T s t u hS hT ihS ihT { transitivity, exact star_small_step_seq ihS, apply star.head small_step.seq_skip ihT }, case ite_true : b S T s t hs hst ih { exact star.head (small_step.ite_true hs) ih }, case ite_false : b S T s t hs hst ih { exact star.head (small_step.ite_false hs) ih }, case while_true : b S s t u hb hS hw ihS ihw { exact (star.head small_step.while (star.head (small_step.ite_true hb) (star.trans (star_small_step_seq ihS) (star.head small_step.seq_skip ihw)))) }, case while_false : b S s hb { exact star.tail (star.single small_step.while) (small_step.ite_false hb) } end lemma big_step_of_small_step_of_big_step {S₀ S₁ s₀ s₁ s₂} (h₁ : (S₀, s₀) ⇒ (S₁, s₁)) : (S₁, s₁) ⟹ s₂ → (S₀, s₀) ⟹ s₂ := begin induction' h₁; simp [*, big_step_while_true_iff] {contextual := tt}, case seq_step { intros u hS' hT, apply exists.intro u, exact and.intro (ih hS') hT } end lemma big_step_of_star_small_step {S s t} : (S, s) ⇒* (stmt.skip, t) → (S, s) ⟹ t := begin generalize hSs : (S, s) = Ss, intro h, induction h using LoVe.rtc.star.head_induction_on with _ S's' h h' ih generalizing S s; cases' hSs, { exact big_step.skip }, { cases' S's' with S' s', apply big_step_of_small_step_of_big_step h, apply ih, refl } end lemma big_step_iff_star_small_step {S s t} : (S, s) ⟹ t ↔ (S, s) ⇒* (stmt.skip, t) := iff.intro star_small_step_of_big_step big_step_of_star_small_step /-! ## Parallelism (**optional**) -/ inductive par_step : nat → list stmt × state → list stmt × state → Prop | intro {Ss Ss' S S' s s' i} (hi : i < list.length Ss) (hS : S = list.nth_le Ss i hi) (hs : (S, s) ⇒ (S', s')) (hS' : Ss' = list.update_nth Ss i S') : par_step i (Ss, s) (Ss', s') lemma par_step_diamond {i j Ss Ts Ts' s t t'} (hi : i < list.length Ss) (hj : j < list.length Ss) (hij : i ≠ j) (hT : par_step i (Ss, s) (Ts, t)) (hT' : par_step j (Ss, s) (Ts', t')) : ∃u Us, par_step j (Ts, t) (Us, u) ∧ par_step i (Ts', t') (Us, u) := sorry -- unprovable def stmt.W : stmt → set string | stmt.skip := ∅ | (stmt.assign x _) := {x} | (stmt.seq S T) := stmt.W S ∪ stmt.W T | (stmt.ite _ S T) := stmt.W S ∪ stmt.W T | (stmt.while _ S) := stmt.W S def exp.R {α : Type} : (state → α) → set string | f := {x | ∀s n, f (s{x ↦ n}) ≠ f s} def stmt.R : stmt → set string | stmt.skip := ∅ | (stmt.assign _ a) := exp.R a | (stmt.seq S T) := stmt.R S ∪ stmt.R T | (stmt.ite b S T) := exp.R b ∪ stmt.R S ∪ stmt.R T | (stmt.while b S) := exp.R b ∪ stmt.R S def stmt.V : stmt → set string | S := stmt.W S ∪ stmt.R S lemma par_step_diamond_VW_disjoint {i j Ss Ts Ts' s t t'} (hiS : i < list.length Ss) (hjT : j < list.length Ts) (hij : i ≠ j) (hT : par_step i (Ss, s) (Ts, t)) (hT' : par_step j (Ss, s) (Ts', t')) (hWV : stmt.W (list.nth_le Ss i hiS) ∩ stmt.V (list.nth_le Ts j hjT) = ∅) (hVW : stmt.V (list.nth_le Ss i hiS) ∩ stmt.W (list.nth_le Ts j hjT) = ∅) : ∃u Us, par_step j (Ts, t) (Us, u) ∧ par_step i (Ts', t') (Us, u) := sorry -- this should be provable end LoVe
e7fa2a4925ea516d2ad09489609f1acadc27c12f
968e2f50b755d3048175f176376eff7139e9df70
/examples/prop_logic_theory/unnamed_601.lean
fb85cf8fad7cd4d72d173f54afcc6fa59f60ce2c
[]
no_license
gihanmarasingha/mth1001_sphinx
190a003269ba5e54717b448302a27ca26e31d491
05126586cbf5786e521be1ea2ef5b4ba3c44e74a
refs/heads/master
1,672,913,933,677
1,604,516,583,000
1,604,516,583,000
309,245,750
1
0
null
null
null
null
UTF-8
Lean
false
false
140
lean
variables p q r : Prop -- BEGIN example (h₁ : p → q) (h₂ : q → r) (h₃ : p) : r := begin show r, from h₂ (h₁ h₃) end -- END
de10365672ca3c44ea1177549c6ebe68adaed394
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/eq5.lean
77f9f9a7a8924423c173f9129e5ffe8f9a0e5a39
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
261
lean
open nat definition fib : nat → nat | 0 := 1 | 1 := 1 | (x+2) := fib x + fib (x+1) theorem fib0 : fib 0 = 1 := rfl theorem fib1 : fib 1 = 1 := rfl theorem fib_succ_succ (a : nat) : fib (a+2) = fib a + fib (a+1) := rfl example : fib 8 = 34 := rfl
d30096efef9f2eb63435f02e428fba1a045c9568
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/data/polynomial/degree/trailing_degree.lean
b78c13868af37a7bc454ad5792977991cd91497a
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
16,150
lean
/- Copyright (c) 2020 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import data.enat.basic import data.polynomial.degree.definitions /-! # Trailing degree of univariate polynomials > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. ## Main definitions * `trailing_degree p`: the multiplicity of `X` in the polynomial `p` * `nat_trailing_degree`: a variant of `trailing_degree` that takes values in the natural numbers * `trailing_coeff`: the coefficient at index `nat_trailing_degree p` Converts most results about `degree`, `nat_degree` and `leading_coeff` to results about the bottom end of a polynomial -/ noncomputable theory open function polynomial finsupp finset open_locale big_operators classical polynomial namespace polynomial universes u v variables {R : Type u} {S : Type v} {a b : R} {n m : ℕ} section semiring variables [semiring R] {p q r : R[X]} /-- `trailing_degree p` is the multiplicity of `x` in the polynomial `p`, i.e. the smallest `X`-exponent in `p`. `trailing_degree p = some n` when `p ≠ 0` and `n` is the smallest power of `X` that appears in `p`, otherwise `trailing_degree 0 = ⊤`. -/ def trailing_degree (p : R[X]) : ℕ∞ := p.support.min lemma trailing_degree_lt_wf : well_founded (λp q : R[X], trailing_degree p < trailing_degree q) := inv_image.wf trailing_degree (with_top.well_founded_lt nat.lt_wf) /-- `nat_trailing_degree p` forces `trailing_degree p` to `ℕ`, by defining `nat_trailing_degree ⊤ = 0`. -/ def nat_trailing_degree (p : R[X]) : ℕ := (trailing_degree p).get_or_else 0 /-- `trailing_coeff p` gives the coefficient of the smallest power of `X` in `p`-/ def trailing_coeff (p : R[X]) : R := coeff p (nat_trailing_degree p) /-- a polynomial is `monic_at` if its trailing coefficient is 1 -/ def trailing_monic (p : R[X]) := trailing_coeff p = (1 : R) lemma trailing_monic.def : trailing_monic p ↔ trailing_coeff p = 1 := iff.rfl instance trailing_monic.decidable [decidable_eq R] : decidable (trailing_monic p) := by unfold trailing_monic; apply_instance @[simp] lemma trailing_monic.trailing_coeff {p : R[X]} (hp : p.trailing_monic) : trailing_coeff p = 1 := hp @[simp] lemma trailing_degree_zero : trailing_degree (0 : R[X]) = ⊤ := rfl @[simp] lemma trailing_coeff_zero : trailing_coeff (0 : R[X]) = 0 := rfl @[simp] lemma nat_trailing_degree_zero : nat_trailing_degree (0 : R[X]) = 0 := rfl lemma trailing_degree_eq_top : trailing_degree p = ⊤ ↔ p = 0 := ⟨λ h, support_eq_empty.1 (finset.min_eq_top.1 h), λ h, by simp [h]⟩ lemma trailing_degree_eq_nat_trailing_degree (hp : p ≠ 0) : trailing_degree p = (nat_trailing_degree p : ℕ∞) := let ⟨n, hn⟩ := not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt trailing_degree_eq_top.1 hp)) in have hn : trailing_degree p = n := not_not.1 hn, by rw [nat_trailing_degree, hn]; refl lemma trailing_degree_eq_iff_nat_trailing_degree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) : p.trailing_degree = n ↔ p.nat_trailing_degree = n := by rw [trailing_degree_eq_nat_trailing_degree hp, with_top.coe_eq_coe] lemma trailing_degree_eq_iff_nat_trailing_degree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) : p.trailing_degree = n ↔ p.nat_trailing_degree = n := begin split, { intro H, rwa ← trailing_degree_eq_iff_nat_trailing_degree_eq, rintro rfl, rw trailing_degree_zero at H, exact option.no_confusion H }, { intro H, rwa trailing_degree_eq_iff_nat_trailing_degree_eq, rintro rfl, rw nat_trailing_degree_zero at H, rw H at hn, exact lt_irrefl _ hn } end lemma nat_trailing_degree_eq_of_trailing_degree_eq_some {p : R[X]} {n : ℕ} (h : trailing_degree p = n) : nat_trailing_degree p = n := have hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h, option.some_inj.1 $ show (nat_trailing_degree p : ℕ∞) = n, by rwa [← trailing_degree_eq_nat_trailing_degree hp0] @[simp] lemma nat_trailing_degree_le_trailing_degree : ↑(nat_trailing_degree p) ≤ trailing_degree p := begin by_cases hp : p = 0, { rw [hp, trailing_degree_zero], exact le_top }, rw [trailing_degree_eq_nat_trailing_degree hp], exact le_rfl end lemma nat_trailing_degree_eq_of_trailing_degree_eq [semiring S] {q : S[X]} (h : trailing_degree p = trailing_degree q) : nat_trailing_degree p = nat_trailing_degree q := by unfold nat_trailing_degree; rw h lemma le_trailing_degree_of_ne_zero (h : coeff p n ≠ 0) : trailing_degree p ≤ n := show @has_le.le ℕ∞ _ p.support.min n, from min_le (mem_support_iff.2 h) lemma nat_trailing_degree_le_of_ne_zero (h : coeff p n ≠ 0) : nat_trailing_degree p ≤ n := begin rw [← with_top.coe_le_coe, ← trailing_degree_eq_nat_trailing_degree], { exact le_trailing_degree_of_ne_zero h, }, { assume h, subst h, exact h rfl } end lemma trailing_degree_le_trailing_degree (h : coeff q (nat_trailing_degree p) ≠ 0) : trailing_degree q ≤ trailing_degree p := begin by_cases hp : p = 0, { rw hp, exact le_top }, { rw trailing_degree_eq_nat_trailing_degree hp, exact le_trailing_degree_of_ne_zero h } end lemma trailing_degree_ne_of_nat_trailing_degree_ne {n : ℕ} : p.nat_trailing_degree ≠ n → trailing_degree p ≠ n := mt $ λ h, by rw [nat_trailing_degree, h, option.get_or_else_coe] theorem nat_trailing_degree_le_of_trailing_degree_le {n : ℕ} {hp : p ≠ 0} (H : (n : ℕ∞) ≤ trailing_degree p) : n ≤ nat_trailing_degree p := begin rw trailing_degree_eq_nat_trailing_degree hp at H, exact with_top.coe_le_coe.mp H, end lemma nat_trailing_degree_le_nat_trailing_degree {hq : q ≠ 0} (hpq : p.trailing_degree ≤ q.trailing_degree) : p.nat_trailing_degree ≤ q.nat_trailing_degree := begin by_cases hp : p = 0, { rw [hp, nat_trailing_degree_zero], exact zero_le _ }, rwa [trailing_degree_eq_nat_trailing_degree hp, trailing_degree_eq_nat_trailing_degree hq, with_top.coe_le_coe] at hpq end @[simp] lemma trailing_degree_monomial (ha : a ≠ 0) : trailing_degree (monomial n a) = n := by rw [trailing_degree, support_monomial n ha, min_singleton] lemma nat_trailing_degree_monomial (ha : a ≠ 0) : nat_trailing_degree (monomial n a) = n := by rw [nat_trailing_degree, trailing_degree_monomial ha]; refl lemma nat_trailing_degree_monomial_le : nat_trailing_degree (monomial n a) ≤ n := if ha : a = 0 then by simp [ha] else (nat_trailing_degree_monomial ha).le lemma le_trailing_degree_monomial : ↑n ≤ trailing_degree (monomial n a) := if ha : a = 0 then by simp [ha] else (trailing_degree_monomial ha).ge @[simp] lemma trailing_degree_C (ha : a ≠ 0) : trailing_degree (C a) = (0 : ℕ∞) := trailing_degree_monomial ha lemma le_trailing_degree_C : (0 : ℕ∞) ≤ trailing_degree (C a) := le_trailing_degree_monomial lemma trailing_degree_one_le : (0 : ℕ∞) ≤ trailing_degree (1 : R[X]) := by rw [← C_1]; exact le_trailing_degree_C @[simp] lemma nat_trailing_degree_C (a : R) : nat_trailing_degree (C a) = 0 := nonpos_iff_eq_zero.1 nat_trailing_degree_monomial_le @[simp] lemma nat_trailing_degree_one : nat_trailing_degree (1 : R[X]) = 0 := nat_trailing_degree_C 1 @[simp] lemma nat_trailing_degree_nat_cast (n : ℕ) : nat_trailing_degree (n : R[X]) = 0 := by simp only [←C_eq_nat_cast, nat_trailing_degree_C] @[simp] lemma trailing_degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : trailing_degree (C a * X ^ n) = n := by rw [C_mul_X_pow_eq_monomial, trailing_degree_monomial ha] lemma le_trailing_degree_C_mul_X_pow (n : ℕ) (a : R) : (n : ℕ∞) ≤ trailing_degree (C a * X ^ n) := by { rw C_mul_X_pow_eq_monomial, exact le_trailing_degree_monomial } lemma coeff_eq_zero_of_trailing_degree_lt (h : (n : ℕ∞) < trailing_degree p) : coeff p n = 0 := not_not.1 (mt le_trailing_degree_of_ne_zero (not_le_of_gt h)) lemma coeff_eq_zero_of_lt_nat_trailing_degree {p : R[X]} {n : ℕ} (h : n < p.nat_trailing_degree) : p.coeff n = 0 := begin apply coeff_eq_zero_of_trailing_degree_lt, by_cases hp : p = 0, { rw [hp, trailing_degree_zero], exact with_top.coe_lt_top n, }, { rwa [trailing_degree_eq_nat_trailing_degree hp, with_top.coe_lt_coe] }, end @[simp] lemma coeff_nat_trailing_degree_pred_eq_zero {p : R[X]} {hp : (0 : ℕ∞) < nat_trailing_degree p} : p.coeff (p.nat_trailing_degree - 1) = 0 := coeff_eq_zero_of_lt_nat_trailing_degree $ nat.sub_lt ((with_top.zero_lt_coe (nat_trailing_degree p)).mp hp) nat.one_pos theorem le_trailing_degree_X_pow (n : ℕ) : (n : ℕ∞) ≤ trailing_degree (X^n : R[X]) := by simpa only [C_1, one_mul] using le_trailing_degree_C_mul_X_pow n (1:R) theorem le_trailing_degree_X : (1 : ℕ∞) ≤ trailing_degree (X : R[X]) := le_trailing_degree_monomial lemma nat_trailing_degree_X_le : (X : R[X]).nat_trailing_degree ≤ 1 := nat_trailing_degree_monomial_le @[simp] lemma trailing_coeff_eq_zero : trailing_coeff p = 0 ↔ p = 0 := ⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1 (not_not.2 h) (mem_of_min (trailing_degree_eq_nat_trailing_degree hp)), λ h, h.symm ▸ leading_coeff_zero⟩ lemma trailing_coeff_nonzero_iff_nonzero : trailing_coeff p ≠ 0 ↔ p ≠ 0 := not_congr trailing_coeff_eq_zero lemma nat_trailing_degree_mem_support_of_nonzero : p ≠ 0 → nat_trailing_degree p ∈ p.support := (mem_support_iff.mpr ∘ trailing_coeff_nonzero_iff_nonzero.mpr) lemma nat_trailing_degree_le_of_mem_supp (a : ℕ) : a ∈ p.support → nat_trailing_degree p ≤ a:= nat_trailing_degree_le_of_ne_zero ∘ mem_support_iff.mp lemma nat_trailing_degree_eq_support_min' (h : p ≠ 0) : nat_trailing_degree p = p.support.min' (nonempty_support_iff.mpr h) := begin apply le_antisymm, { apply le_min', intros y hy, exact nat_trailing_degree_le_of_mem_supp y hy }, { apply finset.min'_le, exact mem_support_iff.mpr (trailing_coeff_nonzero_iff_nonzero.mpr h), }, end lemma le_nat_trailing_degree (hp : p ≠ 0) (hn : ∀ m < n, p.coeff m = 0) : n ≤ p.nat_trailing_degree := begin rw nat_trailing_degree_eq_support_min' hp, exact finset.le_min' _ _ _ (λ m hm, not_lt.1 $ λ hmn, mem_support_iff.1 hm $ hn _ hmn), end lemma nat_trailing_degree_le_nat_degree (p : R[X]) : p.nat_trailing_degree ≤ p.nat_degree := begin by_cases hp : p = 0, { rw [hp, nat_degree_zero, nat_trailing_degree_zero] }, { exact le_nat_degree_of_ne_zero (mt trailing_coeff_eq_zero.mp hp) }, end lemma nat_trailing_degree_mul_X_pow {p : R[X]} (hp : p ≠ 0) (n : ℕ) : (p * X ^ n).nat_trailing_degree = p.nat_trailing_degree + n := begin apply le_antisymm, { refine nat_trailing_degree_le_of_ne_zero (λ h, mt trailing_coeff_eq_zero.mp hp _), rwa [trailing_coeff, ←coeff_mul_X_pow] }, { rw [nat_trailing_degree_eq_support_min' (λ h, hp (mul_X_pow_eq_zero h)), finset.le_min'_iff], intros y hy, have key : n ≤ y, { rw [mem_support_iff, coeff_mul_X_pow'] at hy, exact by_contra (λ h, hy (if_neg h)) }, rw [mem_support_iff, coeff_mul_X_pow', if_pos key] at hy, exact (le_tsub_iff_right key).mp (nat_trailing_degree_le_of_ne_zero hy) }, end lemma le_trailing_degree_mul : p.trailing_degree + q.trailing_degree ≤ (p * q).trailing_degree := begin refine finset.le_min (λ n hn, _), rw [mem_support_iff, coeff_mul] at hn, obtain ⟨⟨i, j⟩, hij, hpq⟩ := exists_ne_zero_of_sum_ne_zero hn, refine (add_le_add (min_le (mem_support_iff.mpr (left_ne_zero_of_mul hpq))) (min_le (mem_support_iff.mpr (right_ne_zero_of_mul hpq)))).trans (le_of_eq _), rwa [← with_top.coe_add, with_top.coe_eq_coe, ←nat.mem_antidiagonal], end lemma le_nat_trailing_degree_mul (h : p * q ≠ 0) : p.nat_trailing_degree + q.nat_trailing_degree ≤ (p * q).nat_trailing_degree := begin have hp : p ≠ 0 := λ hp, h (by rw [hp, zero_mul]), have hq : q ≠ 0 := λ hq, h (by rw [hq, mul_zero]), rw [←with_top.coe_le_coe, with_top.coe_add, ←trailing_degree_eq_nat_trailing_degree hp, ←trailing_degree_eq_nat_trailing_degree hq, ←trailing_degree_eq_nat_trailing_degree h], exact le_trailing_degree_mul, end lemma coeff_mul_nat_trailing_degree_add_nat_trailing_degree : (p * q).coeff (p.nat_trailing_degree + q.nat_trailing_degree) = p.trailing_coeff * q.trailing_coeff := begin rw coeff_mul, refine finset.sum_eq_single (p.nat_trailing_degree, q.nat_trailing_degree) _ (λ h, (h (nat.mem_antidiagonal.mpr rfl)).elim), rintro ⟨i, j⟩ h₁ h₂, rw nat.mem_antidiagonal at h₁, by_cases hi : i < p.nat_trailing_degree, { rw [coeff_eq_zero_of_lt_nat_trailing_degree hi, zero_mul] }, by_cases hj : j < q.nat_trailing_degree, { rw [coeff_eq_zero_of_lt_nat_trailing_degree hj, mul_zero] }, rw not_lt at hi hj, refine (h₂ (prod.ext_iff.mpr _).symm).elim, exact (add_eq_add_iff_eq_and_eq hi hj).mp h₁.symm, end lemma trailing_degree_mul' (h : p.trailing_coeff * q.trailing_coeff ≠ 0) : (p * q).trailing_degree = p.trailing_degree + q.trailing_degree := begin have hp : p ≠ 0 := λ hp, h (by rw [hp, trailing_coeff_zero, zero_mul]), have hq : q ≠ 0 := λ hq, h (by rw [hq, trailing_coeff_zero, mul_zero]), refine le_antisymm _ le_trailing_degree_mul, rw [trailing_degree_eq_nat_trailing_degree hp, trailing_degree_eq_nat_trailing_degree hq, ← enat.coe_add], apply le_trailing_degree_of_ne_zero, rwa coeff_mul_nat_trailing_degree_add_nat_trailing_degree, end lemma nat_trailing_degree_mul' (h : p.trailing_coeff * q.trailing_coeff ≠ 0) : (p * q).nat_trailing_degree = p.nat_trailing_degree + q.nat_trailing_degree := begin have hp : p ≠ 0 := λ hp, h (by rw [hp, trailing_coeff_zero, zero_mul]), have hq : q ≠ 0 := λ hq, h (by rw [hq, trailing_coeff_zero, mul_zero]), apply nat_trailing_degree_eq_of_trailing_degree_eq_some, rw [trailing_degree_mul' h, with_top.coe_add, ←trailing_degree_eq_nat_trailing_degree hp, ←trailing_degree_eq_nat_trailing_degree hq], end lemma nat_trailing_degree_mul [no_zero_divisors R] (hp : p ≠ 0) (hq : q ≠ 0) : (p * q).nat_trailing_degree = p.nat_trailing_degree + q.nat_trailing_degree := nat_trailing_degree_mul' (mul_ne_zero (mt trailing_coeff_eq_zero.mp hp) (mt trailing_coeff_eq_zero.mp hq)) end semiring section nonzero_semiring variables [semiring R] [nontrivial R] {p q : R[X]} @[simp] lemma trailing_degree_one : trailing_degree (1 : R[X]) = (0 : ℕ∞) := trailing_degree_C one_ne_zero @[simp] lemma trailing_degree_X : trailing_degree (X : R[X]) = 1 := trailing_degree_monomial one_ne_zero @[simp] lemma nat_trailing_degree_X : (X : R[X]).nat_trailing_degree = 1 := nat_trailing_degree_monomial one_ne_zero end nonzero_semiring section ring variables [ring R] @[simp] lemma trailing_degree_neg (p : R[X]) : trailing_degree (-p) = trailing_degree p := by unfold trailing_degree; rw support_neg @[simp] lemma nat_trailing_degree_neg (p : R[X]) : nat_trailing_degree (-p) = nat_trailing_degree p := by simp [nat_trailing_degree] @[simp] lemma nat_trailing_degree_int_cast (n : ℤ) : nat_trailing_degree (n : R[X]) = 0 := by simp only [←C_eq_int_cast, nat_trailing_degree_C] end ring section semiring variables [semiring R] /-- The second-lowest coefficient, or 0 for constants -/ def next_coeff_up (p : R[X]) : R := if p.nat_trailing_degree = 0 then 0 else p.coeff (p.nat_trailing_degree + 1) @[simp] lemma next_coeff_up_C_eq_zero (c : R) : next_coeff_up (C c) = 0 := by { rw next_coeff_up, simp } lemma next_coeff_up_of_pos_nat_trailing_degree (p : R[X]) (hp : 0 < p.nat_trailing_degree) : next_coeff_up p = p.coeff (p.nat_trailing_degree + 1) := by { rw [next_coeff_up, if_neg], contrapose! hp, simpa } end semiring section semiring variables [semiring R] {p q : R[X]} {ι : Type*} lemma coeff_nat_trailing_degree_eq_zero_of_trailing_degree_lt (h : trailing_degree p < trailing_degree q) : coeff q (nat_trailing_degree p) = 0 := coeff_eq_zero_of_trailing_degree_lt $ nat_trailing_degree_le_trailing_degree.trans_lt h lemma ne_zero_of_trailing_degree_lt {n : ℕ∞} (h : trailing_degree p < n) : p ≠ 0 := λ h₀, h.not_le (by simp [h₀]) end semiring end polynomial
2c29ffbb64b1ab16ca0e3b1132740d36ebee5dfe
b392eb79fb36952401156496daa60628ccb07438
/Lib4/Examples/Asymptotics.lean
685573fef94c1be2cc344bb0948786ecada67597
[ "Apache-2.0" ]
permissive
AurelienSaue/mathportsource
d9eabe74e3ab7774baa6a10a6dc8d4855ff92266
1a164e4fff7204c522c1f4ecc5024fd909be3b0b
refs/heads/master
1,685,214,377,305
1,623,621,223,000
1,623,621,223,000
364,191,042
0
0
null
null
null
null
UTF-8
Lean
false
false
2,822
lean
import Mathlib.analysis.normed_space.basic import Mathlib.topology.local_homeomorph namespace Mathlib open filter open set namespace asymptotics -- TODO: Type* syntax variable {α : Type} {β : Type} {E : Type} {F : Type} {G : Type} {E' : Type} {F' : Type} {G' : Type} {R : Type} {R' : Type} variable [has_norm E] [has_norm F] [has_norm G] [normed_group E'] [normed_group F'] [normed_group G'] [normed_ring R] [normed_ring R'] {c c' : ℝ} {f : α → E} {g : α → F} {k : α → G} {f' : α → E'} {g' : α → F'} {k' : α → G'} {l l' : filter α} section defs def is_O_with (c : ℝ) (f : α → E) (g : α → F) (l : filter α) : Prop := filter.eventually (fun (x : α) => norm (f x) ≤ c * norm (g x)) l theorem is_O_with_iff {c : real} {f : α → E} {g : α → F} {l : filter α} : is_O_with c f g l ↔ filter.eventually (fun (x : α) => norm (f x) ≤ c * norm (g x)) l := iff.rfl theorem is_O_with.of_bound {c : real} {f : α → E} {g : α → F} {l : filter α} : filter.eventually (λ (x : α) => norm (f x) ≤ c * norm (g x)) l → is_O_with c f g l := λ (h : filter.eventually (fun (x : α) => norm (f x) ≤ c * norm (g x)) l) => h def is_O (f : α → E) (g : α → F) (l : filter α) : Prop := ∃ c : ℝ, is_O_with c f g l theorem is_O_iff_is_O_with {f : α → E} {g : α → F} {l : filter α} : is_O f g l ↔ ∃ c : ℝ, is_O_with c f g l := iff.rfl theorem is_O_iff {f : α → E} {g : α → F} {l : filter α} : is_O f g l ↔ ∃ c : ℝ, filter.eventually (λ x => norm (f x) ≤ c * norm (g x)) l := iff.rfl theorem is_O.of_bound (c : ℝ) {f : α → E} {g : α → F} {l : filter α} (h : filter.eventually (λ x => norm (f x) ≤ c * norm (g x)) l) : is_O f g l := ⟨c, h⟩ def is_o (f : α → E) (g : α → F) (l : filter α) : Prop := ∀ (c : ℝ), 0 < c → is_O_with c f g l theorem is_o_iff_forall_is_O_with {f : α → E} {g : α → F} {l : filter α} : is_o f g l ↔ ∀ (c : ℝ), 0 < c → is_O_with c f g l := iff.rfl theorem is_o_iff {f : α → E} {g : α → F} {l : filter α} : is_o f g l ↔ ∀ (c : ℝ), 0 < c → filter.eventually (λ x => norm (f x) ≤ c * norm (g x)) l := iff.rfl theorem is_o.def {f : α → E} {g : α → F} {l : filter α} (h : is_o f g l) {c : ℝ} (hc : 0 < c) : filter.eventually (λ x => norm (f x) ≤ c * norm (g x)) l := h _ hc theorem is_o.def' {f : α → E} {g : α → F} {l : filter α} (h : is_o f g l) {c : ℝ} (hc : 0 < c) : is_O_with c f g l := h _ hc end defs theorem is_O_with.is_O (h : is_O_with c f g l) : is_O f g l := ⟨c, h⟩ theorem is_o.is_O_with (hgf : is_o f g l) : is_O_with 1 f g l := hgf _ zero_lt_one theorem is_o.is_O (hgf : is_o f g l) : is_O f g l := hgf.is_O_with.is_O end asymptotics end Mathlib
dc18626f2308c2820c4f4695d267ae699f1b2540
8b9f17008684d796c8022dab552e42f0cb6fb347
/library/algebra/bundled.lean
ea41110d5eea5541e2601bdb75423a41ae1a1e30
[ "Apache-2.0" ]
permissive
chubbymaggie/lean
0d06ae25f9dd396306fb02190e89422ea94afd7b
d2c7b5c31928c98f545b16420d37842c43b4ae9a
refs/heads/master
1,611,313,622,901
1,430,266,839,000
1,430,267,083,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,092
lean
/- Copyright (c) 2015 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Module: algebra.bundled Authors: Jeremy Avigad Bundled structures -/ import algebra.group namespace algebra structure Semigroup := (carrier : Type) (struct : semigroup carrier) attribute Semigroup.carrier [coercion] attribute Semigroup.struct [instance] structure CommSemigroup := (carrier : Type) (struct : comm_semigroup carrier) attribute CommSemigroup.carrier [coercion] attribute CommSemigroup.struct [instance] structure Monoid := (carrier : Type) (struct : monoid carrier) attribute Monoid.carrier [coercion] attribute Monoid.struct [instance] structure CommMonoid := (carrier : Type) (struct : comm_monoid carrier) attribute CommMonoid.carrier [coercion] attribute CommMonoid.struct [instance] structure Group := (carrier : Type) (struct : group carrier) attribute Group.carrier [coercion] attribute Group.struct [instance] structure CommGroup := (carrier : Type) (struct : comm_group carrier) attribute CommGroup.carrier [coercion] attribute CommGroup.struct [instance] structure AddSemigroup := (carrier : Type) (struct : add_semigroup carrier) attribute AddSemigroup.carrier [coercion] attribute AddSemigroup.struct [instance] structure AddCommSemigroup := (carrier : Type) (struct : add_comm_semigroup carrier) attribute AddCommSemigroup.carrier [coercion] attribute AddCommSemigroup.struct [instance] structure AddMonoid := (carrier : Type) (struct : add_monoid carrier) attribute AddMonoid.carrier [coercion] attribute AddMonoid.struct [instance] structure AddCommMonoid := (carrier : Type) (struct : add_comm_monoid carrier) attribute AddCommMonoid.carrier [coercion] attribute AddCommMonoid.struct [instance] structure AddGroup := (carrier : Type) (struct : add_group carrier) attribute AddGroup.carrier [coercion] attribute AddGroup.struct [instance] structure AddCommGroup := (carrier : Type) (struct : add_comm_group carrier) attribute AddCommGroup.carrier [coercion] attribute AddCommGroup.struct [instance] end algebra
88bcd8de74dab09a4b456d539ac8c1ca888ce82d
9a0b1b3a653ea926b03d1495fef64da1d14b3174
/tidy/rewrite_search/discovery/collector/common.lean
9af8e8640ddd53745a08ff117ce95e69d7b669dd
[ "Apache-2.0" ]
permissive
khoek/mathlib-tidy
8623b27b4e04e7d598164e7eaf248610d58f768b
866afa6ab597c47f1b72e8fe2b82b97fff5b980f
refs/heads/master
1,585,598,975,772
1,538,659,544,000
1,538,659,544,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
614
lean
import tidy.rewrite_all_wrappers import ..screening open tactic namespace tidy.rewrite_search.discovery meta def are_promising_rewrites (rws : list (expr × bool)) : list expr → tactic bool | [] := return false | (s :: rest) := do -- TODO alternative (and probably better) condition: -- tt if the rewrite list contains an expression not seen in the rewrite_search -- instance, ff otherwise. Maybe too harsh/coarse? mllist.empty <$> (all_rewrites_mllist rws s) meta def is_promising_rewrite (rw : expr × bool) : list expr → tactic bool := are_promising_rewrites [rw] end tidy.rewrite_search.discovery
e9995ed4550040e98410d68aa7f500648ba747f7
b392eb79fb36952401156496daa60628ccb07438
/Lib4/PostPort/Coe.lean
421e9609549f3dfd774132b1b498260969f98384
[ "Apache-2.0" ]
permissive
AurelienSaue/mathportsource
d9eabe74e3ab7774baa6a10a6dc8d4855ff92266
1a164e4fff7204c522c1f4ecc5024fd909be3b0b
refs/heads/master
1,685,214,377,305
1,623,621,223,000
1,623,621,223,000
364,191,042
0
0
null
null
null
null
UTF-8
Lean
false
false
869
lean
import Lean3Lib.init.coe universes u v variable {α : Sort u} {β : Sort v} noncomputable instance hasCoe [inst : Mathlib.has_coe α β] : Coe α β := { coe := @Mathlib.has_coe.coe _ _ inst } -- TODO: why does mathlib declare these instances directly? -- topology/algebra/open_subgroup.lean:42:instance has_coe_set : has_coe_t (open_subgroup G) (set G) := ⟨λ U, U.1⟩ noncomputable instance hasCoeT [inst : Mathlib.has_coe_t α β] : CoeTC α β := { coe := @Mathlib.has_coe_t.coe _ _ inst } noncomputable instance hasCoeToFun [inst : Mathlib.has_coe_to_fun α] : CoeFun α (no_index (@Mathlib.has_coe_to_fun.F _ inst)) := { coe := @Mathlib.has_coe_to_fun.coe _ inst } noncomputable instance hasCoeToSort [inst : Mathlib.has_coe_to_sort α] : CoeSort α (no_index (@Mathlib.has_coe_to_sort.S _ inst)) := { coe := @Mathlib.has_coe_to_sort.coe _ inst }
b03a630aceb799e31902e8a4b1f4b8d434c5636f
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/group_theory/submonoid/default.lean
da25bc98ded11455a6ebed7a7bdcc44350f99588
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
41
lean
import group_theory.submonoid.membership
102127d7b0bd5c152864660cabb582d503e39757
c6da0300d417abe3464e750ab51a63502b93acfa
/src/struct_tact/traversals.lean
b0787afdfa51319d27a2bf939567227ffb550bff
[ "Apache-2.0" ]
permissive
uwplse/struct_tact
55bc1d260fac498cff83a4d71461041f8ed74bd6
22188ea2e97705d1185f75dde24e6bab88054ab0
refs/heads/master
1,630,670,592,496
1,515,453,299,000
1,515,453,299,000
104,603,771
0
0
null
null
null
null
UTF-8
Lean
false
false
1,585
lean
open tactic def for_m {m : Type → Type} {α β : Type} [monad_m : monad m] (action : list α) (f : α → m β) : m (list β) := monad.mapm f action private meta def until_first_hyp_aux (f : expr → tactic unit) : list expr → tactic unit | [] := tactic.fail "until_first_hyp: provided tactic did not succed on any hypotheses" | (h :: hs) := f h <|> until_first_hyp_aux hs meta def until_first_hyp (action : expr → tactic unit) : tactic unit := do ls ← local_context, until_first_hyp_aux action ls def subterm_err_msg := "subterms: only provides subterms of applications; i.e terms of the form (f x_1 ... x_n) found" meta def subterms : expr → (expr → list expr → tactic unit) → tactic unit | (expr.app f g) action := let head := expr.get_app_fn (expr.app f g), args := expr.get_app_args (expr.app f g) in action head args <|> list.foldl (<|>) (tactic.fail subterm_err_msg) (args.map (fun e, subterms e action)) | term _ := tactic.fail (subterm_err_msg ++ to_string term) meta def tree_repeat_inner (t2 : tactic unit) : tactic unit := do seq t2 tree_repeat_inner, return () meta def fix_aux : ℕ → tactic unit → tactic unit | last tac := do n ← num_goals, if n = last then return () else do all_goals tac, fix_aux n tac meta def fix (tac : tactic unit) : tactic unit := fix_aux 0 tac meta def tree_repeat (t1 : tactic unit) (t2 : tactic unit) : tactic unit := do (target :: targets) ← get_goals, set_goals [target], t1, fix t2, new ← get_goals, set_goals (new ++ targets), return ()
f825c0c89f6064987314c8e1451bafdd18dd60b3
fe25de614feb5587799621c41487aaee0d083b08
/stage0/src/Lean/Parser/Term.lean
fc382501c8d1689bc136b57ed343e2800d159664
[ "Apache-2.0" ]
permissive
pollend/lean4
e8469c2f5fb8779b773618c3267883cf21fb9fac
c913886938c4b3b83238a3f99673c6c5a9cec270
refs/heads/master
1,687,973,251,481
1,628,039,739,000
1,628,039,739,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
18,069
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Sebastian Ullrich -/ import Lean.Parser.Attr import Lean.Parser.Level namespace Lean namespace Parser namespace Command def commentBody : Parser := { fn := rawFn (finishCommentBlock 1) (trailingWs := true) } @[combinatorParenthesizer Lean.Parser.Command.commentBody] def commentBody.parenthesizer := PrettyPrinter.Parenthesizer.visitToken @[combinatorFormatter Lean.Parser.Command.commentBody] def commentBody.formatter := PrettyPrinter.Formatter.visitAtom Name.anonymous def docComment := leading_parser ppDedent $ "/--" >> commentBody >> ppLine end Command builtin_initialize registerBuiltinParserAttribute `builtinTacticParser `tactic LeadingIdentBehavior.both registerBuiltinDynamicParserAttribute `tacticParser `tactic @[inline] def tacticParser (rbp : Nat := 0) : Parser := categoryParser `tactic rbp namespace Tactic def tacticSeq1Indented : Parser := leading_parser many1Indent (group (ppLine >> tacticParser >> optional ";")) def tacticSeqBracketed : Parser := leading_parser "{" >> many (group (ppLine >> tacticParser >> optional ";")) >> ppDedent (ppLine >> "}") def tacticSeq := nodeWithAntiquot "tacticSeq" `Lean.Parser.Tactic.tacticSeq (tacticSeqBracketed <|> tacticSeq1Indented) /- Raw sequence for quotation and grouping -/ def seq1 := node `Lean.Parser.Tactic.seq1 $ sepBy1 tacticParser ";\n" (allowTrailingSep := true) end Tactic def darrow : Parser := " => " namespace Term /- Built-in parsers -/ @[builtinTermParser] def byTactic := leading_parser:leadPrec "by " >> Tactic.tacticSeq def optSemicolon (p : Parser) : Parser := ppDedent $ optional ";" >> ppLine >> p -- `checkPrec` necessary for the pretty printer @[builtinTermParser] def ident := checkPrec maxPrec >> Parser.ident @[builtinTermParser] def num : Parser := checkPrec maxPrec >> numLit @[builtinTermParser] def scientific : Parser := checkPrec maxPrec >> scientificLit @[builtinTermParser] def str : Parser := checkPrec maxPrec >> strLit @[builtinTermParser] def char : Parser := checkPrec maxPrec >> charLit @[builtinTermParser] def type := leading_parser "Type" >> optional (checkWsBefore "" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec) @[builtinTermParser] def sort := leading_parser "Sort" >> optional (checkWsBefore "" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec) @[builtinTermParser] def prop := leading_parser "Prop" @[builtinTermParser] def hole := leading_parser "_" @[builtinTermParser] def syntheticHole := leading_parser "?" >> (ident <|> hole) @[builtinTermParser] def «sorry» := leading_parser "sorry" @[builtinTermParser] def cdot := leading_parser symbol "·" <|> "." def typeAscription := leading_parser " : " >> termParser def tupleTail := leading_parser ", " >> sepBy1 termParser ", " def parenSpecial : Parser := optional (tupleTail <|> typeAscription) @[builtinTermParser] def paren := leading_parser "(" >> ppDedent (withoutPosition (withoutForbidden (optional (termParser >> parenSpecial)))) >> ")" @[builtinTermParser] def anonymousCtor := leading_parser "⟨" >> sepBy termParser ", " >> "⟩" def optIdent : Parser := optional (atomic (ident >> " : ")) def fromTerm := leading_parser " from " >> termParser def sufficesDecl := leading_parser optIdent >> termParser >> (fromTerm <|> byTactic) @[builtinTermParser] def «suffices» := leading_parser:leadPrec withPosition ("suffices " >> sufficesDecl) >> optSemicolon termParser @[builtinTermParser] def «show» := leading_parser:leadPrec "show " >> termParser >> (fromTerm <|> byTactic) def structInstArrayRef := leading_parser "[" >> termParser >>"]" def structInstLVal := leading_parser (ident <|> fieldIdx <|> structInstArrayRef) >> many (group ("." >> (ident <|> fieldIdx)) <|> structInstArrayRef) def structInstField := ppGroup $ leading_parser structInstLVal >> " := " >> termParser def structInstFieldAbbrev := leading_parser atomic (ident >> notFollowedBy ("." <|> ":=" <|> symbol "[") "invalid field abbreviation") -- `x` is an abbreviation for `x := x` def optEllipsis := leading_parser optional ".." @[builtinTermParser] def structInst := leading_parser "{" >> ppHardSpace >> optional (atomic (termParser >> " with ")) >> manyIndent (group ((structInstFieldAbbrev <|> structInstField) >> optional ", ")) >> optEllipsis >> optional (" : " >> termParser) >> " }" def typeSpec := leading_parser " : " >> termParser def optType : Parser := optional typeSpec @[builtinTermParser] def explicit := leading_parser "@" >> termParser maxPrec @[builtinTermParser] def inaccessible := leading_parser ".(" >> termParser >> ")" def binderIdent : Parser := ident <|> hole def binderType (requireType := false) : Parser := if requireType then node nullKind (" : " >> termParser) else optional (" : " >> termParser) def binderTactic := leading_parser atomic (symbol " := " >> " by ") >> Tactic.tacticSeq def binderDefault := leading_parser " := " >> termParser def explicitBinder (requireType := false) := ppGroup $ leading_parser "(" >> many1 binderIdent >> binderType requireType >> optional (binderTactic <|> binderDefault) >> ")" def implicitBinder (requireType := false) := ppGroup $ leading_parser "{" >> many1 binderIdent >> binderType requireType >> "}" def instBinder := ppGroup $ leading_parser "[" >> optIdent >> termParser >> "]" def bracketedBinder (requireType := false) := withAntiquot (mkAntiquot "bracketedBinder" none (anonymous := false)) <| explicitBinder requireType <|> implicitBinder requireType <|> instBinder /- It is feasible to support dependent arrows such as `{α} → α → α` without sacrificing the quality of the error messages for the longer case. `{α} → α → α` would be short for `{α : Type} → α → α` Here is the encoding: ``` def implicitShortBinder := node `Lean.Parser.Term.implicitBinder $ "{" >> many1 binderIdent >> pushNone >> "}" def depArrowShortPrefix := try (implicitShortBinder >> unicodeSymbol " → " " -> ") def depArrowLongPrefix := bracketedBinder true >> unicodeSymbol " → " " -> " def depArrowPrefix := depArrowShortPrefix <|> depArrowLongPrefix @[builtinTermParser] def depArrow := leading_parser depArrowPrefix >> termParser ``` Note that no changes in the elaborator are needed. We decided to not use it because terms such as `{α} → α → α` may look too cryptic. Note that we did not add a `explicitShortBinder` parser since `(α) → α → α` is really cryptic as a short for `(α : Type) → α → α`. -/ @[builtinTermParser] def depArrow := leading_parser:25 bracketedBinder true >> unicodeSymbol " → " " -> " >> termParser def simpleBinder := leading_parser many1 binderIdent >> optType @[builtinTermParser] def «forall» := leading_parser:leadPrec unicodeSymbol "∀" "forall" >> many1 (ppSpace >> (simpleBinder <|> bracketedBinder)) >> ", " >> termParser def matchAlt (rhsParser : Parser := termParser) : Parser := nodeWithAntiquot "matchAlt" `Lean.Parser.Term.matchAlt $ "| " >> ppIndent (sepBy1 termParser ", " >> darrow >> checkColGe "alternative right-hand-side to start in a column greater than or equal to the corresponding '|'" >> rhsParser) /-- Useful for syntax quotations. Note that generic patterns such as `` `(matchAltExpr| | ... => $rhs) `` should also work with other `rhsParser`s (of arity 1). -/ def matchAltExpr := matchAlt def matchAlts (rhsParser : Parser := termParser) : Parser := leading_parser ppDedent $ withPosition $ many1Indent (ppLine >> matchAlt rhsParser) def matchDiscr := leading_parser optional (atomic (ident >> checkNoWsBefore "no space before ':'" >> ":")) >> termParser def trueVal := leading_parser nonReservedSymbol "true" def falseVal := leading_parser nonReservedSymbol "false" def generalizingParam := leading_parser atomic ("(" >> nonReservedSymbol "generalizing") >> " := " >> (trueVal <|> falseVal) >> ")" @[builtinTermParser] def «match» := leading_parser:leadPrec "match " >> optional generalizingParam >> sepBy1 matchDiscr ", " >> optType >> " with " >> matchAlts @[builtinTermParser] def «nomatch» := leading_parser:leadPrec "nomatch " >> termParser def funImplicitBinder := atomic (lookahead ("{" >> many1 binderIdent >> (symbol " : " <|> "}"))) >> implicitBinder def funSimpleBinder := atomic (lookahead (many1 binderIdent >> " : ")) >> simpleBinder def funBinder : Parser := funImplicitBinder <|> instBinder <|> funSimpleBinder <|> termParser maxPrec -- NOTE: we use `nodeWithAntiquot` to ensure that `fun $b => ...` remains a `term` antiquotation def basicFun : Parser := nodeWithAntiquot "basicFun" `Lean.Parser.Term.basicFun (many1 (ppSpace >> funBinder) >> darrow >> termParser) @[builtinTermParser] def «fun» := leading_parser:maxPrec unicodeSymbol "λ" "fun" >> (basicFun <|> matchAlts) def optExprPrecedence := optional (atomic ":" >> termParser maxPrec) @[builtinTermParser] def «leading_parser» := leading_parser:leadPrec "leading_parser " >> optExprPrecedence >> termParser @[builtinTermParser] def «trailing_parser» := leading_parser:leadPrec "trailing_parser " >> optExprPrecedence >> optExprPrecedence >> termParser @[builtinTermParser] def borrowed := leading_parser "@&" >> termParser leadPrec @[builtinTermParser] def quotedName := leading_parser nameLit -- use `rawCh` because ``"`" >> ident`` overlaps with `nameLit`, with the latter being preferred by the tokenizer -- note that we cannot use ```"``"``` as a new token either because it would break `precheckedQuot` @[builtinTermParser] def doubleQuotedName := leading_parser "`" >> checkNoWsBefore >> rawCh '`' (trailingWs := false) >> ident def simpleBinderWithoutType := nodeWithAntiquot "simpleBinder" `Lean.Parser.Term.simpleBinder (anonymous := true) (many1 binderIdent >> pushNone) /- Remark: we use `checkWsBefore` to ensure `let x[i] := e; b` is not parsed as `let x [i] := e; b` where `[i]` is an `instBinder`. -/ def letIdLhs : Parser := ident >> checkWsBefore "expected space before binders" >> many (ppSpace >> (simpleBinderWithoutType <|> bracketedBinder)) >> optType def letIdDecl := nodeWithAntiquot "letIdDecl" `Lean.Parser.Term.letIdDecl $ atomic (letIdLhs >> " := ") >> termParser def letPatDecl := nodeWithAntiquot "letPatDecl" `Lean.Parser.Term.letPatDecl $ atomic (termParser >> pushNone >> optType >> " := ") >> termParser def letEqnsDecl := nodeWithAntiquot "letEqnsDecl" `Lean.Parser.Term.letEqnsDecl $ letIdLhs >> matchAlts -- Remark: we use `nodeWithAntiquot` here to make sure anonymous antiquotations (e.g., `$x`) are not `letDecl` def letDecl := nodeWithAntiquot "letDecl" `Lean.Parser.Term.letDecl (notFollowedBy (nonReservedSymbol "rec") "rec" >> (letIdDecl <|> letPatDecl <|> letEqnsDecl)) @[builtinTermParser] def «let» := leading_parser:leadPrec withPosition ("let " >> letDecl) >> optSemicolon termParser @[builtinTermParser] def «let_fun» := leading_parser:leadPrec withPosition ((symbol "let_fun " <|> "let_λ") >> letDecl) >> optSemicolon termParser @[builtinTermParser] def «let_delayed» := leading_parser:leadPrec withPosition ("let_delayed " >> letDecl) >> optSemicolon termParser -- like `let_fun` but with optional name def haveIdLhs := optional (ident >> many (ppSpace >> (simpleBinderWithoutType <|> bracketedBinder))) >> optType def haveIdDecl := nodeWithAntiquot "haveIdDecl" `Lean.Parser.Term.haveIdDecl $ atomic (haveIdLhs >> " := ") >> termParser def haveEqnsDecl := nodeWithAntiquot "haveEqnsDecl" `Lean.Parser.Term.haveEqnsDecl $ haveIdLhs >> matchAlts def haveDecl := nodeWithAntiquot "haveDecl" `Lean.Parser.Term.haveDecl (haveIdDecl <|> letPatDecl <|> haveEqnsDecl) @[builtinTermParser] def «have» := leading_parser:leadPrec withPosition ("have " >> haveDecl) >> optSemicolon termParser def «scoped» := leading_parser "scoped " def «local» := leading_parser "local " def attrKind := leading_parser optional («scoped» <|> «local») def attrInstance := ppGroup $ leading_parser attrKind >> attrParser def attributes := leading_parser "@[" >> sepBy1 attrInstance ", " >> "]" def letRecDecl := leading_parser optional Command.docComment >> optional «attributes» >> letDecl def letRecDecls := leading_parser sepBy1 letRecDecl ", " @[builtinTermParser] def «letrec» := leading_parser:leadPrec withPosition (group ("let " >> nonReservedSymbol "rec ") >> letRecDecls) >> optSemicolon termParser @[runBuiltinParserAttributeHooks] def whereDecls := leading_parser "where " >> many1Indent (group (letRecDecl >> optional ";")) @[runBuiltinParserAttributeHooks] def matchAltsWhereDecls := leading_parser matchAlts >> optional whereDecls @[builtinTermParser] def noindex := leading_parser "no_index " >> termParser maxPrec @[builtinTermParser] def binrel := leading_parser "binrel% " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec @[builtinTermParser] def binop := leading_parser "binop% " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec @[builtinTermParser] def forInMacro := leading_parser "forIn% " >> termParser maxPrec >> termParser maxPrec >> termParser maxPrec @[builtinTermParser] def typeOf := leading_parser "typeOf% " >> termParser maxPrec @[builtinTermParser] def ensureTypeOf := leading_parser "ensureTypeOf% " >> termParser maxPrec >> strLit >> termParser @[builtinTermParser] def ensureExpectedType := leading_parser "ensureExpectedType% " >> strLit >> termParser maxPrec @[builtinTermParser] def noImplicitLambda := leading_parser "noImplicitLambda% " >> termParser maxPrec def namedArgument := leading_parser atomic ("(" >> ident >> " := ") >> termParser >> ")" def ellipsis := leading_parser ".." def argument := checkWsBefore "expected space" >> checkColGt "expected to be indented" >> (namedArgument <|> ellipsis <|> termParser argPrec) -- `app` precedence is `lead` (cannot be used as argument) -- `lhs` precedence is `max` (i.e. does not accept `arg` precedence) -- argument precedence is `arg` (i.e. does not accept `lead` precedence) @[builtinTermParser] def app := trailing_parser:leadPrec:maxPrec many1 argument @[builtinTermParser] def proj := trailing_parser checkNoWsBefore >> "." >> checkNoWsBefore >> (fieldIdx <|> ident) @[builtinTermParser] def completion := trailing_parser checkNoWsBefore >> "." @[builtinTermParser] def arrayRef := trailing_parser checkNoWsBefore >> "[" >> termParser >>"]" @[builtinTermParser] def arrow := trailing_parser checkPrec 25 >> unicodeSymbol " → " " -> " >> termParser 25 def isIdent (stx : Syntax) : Bool := -- antiquotations should also be allowed where an identifier is expected stx.isAntiquot || stx.isIdent @[builtinTermParser] def explicitUniv : TrailingParser := trailing_parser checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '.{'" >> ".{" >> sepBy1 levelParser ", " >> "}" @[builtinTermParser] def namedPattern : TrailingParser := trailing_parser checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '@'" >> "@" >> termParser maxPrec @[builtinTermParser] def pipeProj := trailing_parser:minPrec " |>." >> checkNoWsBefore >> (fieldIdx <|> ident) >> many argument @[builtinTermParser] def pipeCompletion := trailing_parser:minPrec " |>." @[builtinTermParser] def subst := trailing_parser:75 " ▸ " >> sepBy1 (termParser 75) " ▸ " -- NOTE: Doesn't call `categoryParser` directly in contrast to most other "static" quotations, so call `evalInsideQuot` explicitly @[builtinTermParser] def funBinder.quot : Parser := leading_parser "`(funBinder|" >> incQuotDepth (evalInsideQuot ``funBinder funBinder) >> ")" def bracketedBinderF := bracketedBinder -- no default arg @[builtinTermParser] def bracketedBinder.quot : Parser := leading_parser "`(bracketedBinder|" >> incQuotDepth (evalInsideQuot ``bracketedBinderF bracketedBinder) >> ")" @[builtinTermParser] def matchDiscr.quot : Parser := leading_parser "`(matchDiscr|" >> incQuotDepth (evalInsideQuot ``matchDiscr matchDiscr) >> ")" @[builtinTermParser] def attr.quot : Parser := leading_parser "`(attr|" >> incQuotDepth attrParser >> ")" @[builtinTermParser] def panic := leading_parser:leadPrec "panic! " >> termParser @[builtinTermParser] def unreachable := leading_parser:leadPrec "unreachable!" @[builtinTermParser] def dbgTrace := leading_parser:leadPrec withPosition ("dbg_trace" >> ((interpolatedStr termParser) <|> termParser)) >> optSemicolon termParser @[builtinTermParser] def assert := leading_parser:leadPrec withPosition ("assert! " >> termParser) >> optSemicolon termParser def macroArg := termParser maxPrec def macroDollarArg := leading_parser "$" >> termParser 10 def macroLastArg := macroDollarArg <|> macroArg -- Macro for avoiding exponentially big terms when using `STWorld` @[builtinTermParser] def stateRefT := leading_parser "StateRefT" >> macroArg >> macroLastArg @[builtinTermParser] def dynamicQuot := leading_parser "`(" >> ident >> "|" >> incQuotDepth (parserOfStack 1) >> ")" end Term @[builtinTermParser default+1] def Tactic.quot : Parser := leading_parser "`(tactic|" >> incQuotDepth tacticParser >> ")" @[builtinTermParser] def Tactic.quotSeq : Parser := leading_parser "`(tactic|" >> incQuotDepth Tactic.seq1 >> ")" @[builtinTermParser] def Level.quot : Parser := leading_parser "`(level|" >> incQuotDepth levelParser >> ")" builtin_initialize register_parser_alias "letDecl" Term.letDecl register_parser_alias "haveDecl" Term.haveDecl register_parser_alias "sufficesDecl" Term.sufficesDecl register_parser_alias "letRecDecls" Term.letRecDecls register_parser_alias "hole" Term.hole register_parser_alias "syntheticHole" Term.syntheticHole register_parser_alias "matchDiscr" Term.matchDiscr register_parser_alias "bracketedBinder" Term.bracketedBinder register_parser_alias "attrKind" Term.attrKind end Parser end Lean
1a3df664b7f79c86fb3c52565eb11484f79e8a2c
ebbdcbd7ddc89a9ef7c3b397b301d5f5272a918f
/qp/p1_categories/c2_limits/s2_products.lean
4d37ffb3c0bb9940bb984c9270c6aeac0ff30a8d
[]
no_license
intoverflow/qvr
34b9ef23604738381ca20b7d622fd0399d88f2dd
0cfcd33fe4bf8d93851a00cec5bfd21e77105d74
refs/heads/master
1,616,591,570,371
1,492,575,772,000
1,492,575,772,000
80,061,627
0
0
null
null
null
null
UTF-8
Lean
false
false
46,643
lean
/- ----------------------------------------------------------------------- Products and co-products. ----------------------------------------------------------------------- -/ import .s1_limits namespace qp open stdaux universe variables ℓ ℓobj ℓhom ℓobj₁ ℓhom₁ ℓobj₂ ℓhom₂ /- ----------------------------------------------------------------------- Products. ----------------------------------------------------------------------- -/ /-! #brief The product diagram. -/ definition ProductDrgm (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) : Fun (ObjCat A) C := { obj := λ a, factor a , hom := λ a₁ a₂ f, begin cases f, exact C^.id (factor a₁) end , hom_id := λ a, rfl , hom_circ := λ a₁ a₂ a₃ g f , begin cases g, cases f, exact eq.symm C^.circ_id_left end } /-! #brief The product diagram turns heterogeneous equality into natural isomorphisms. -/ definition ProductDrgm.heq (C : Cat.{ℓobj ℓhom}) : ∀ {A₁ A₂ : Type ℓ} (ωA : A₁ = A₂) {factor₁ : A₁ → C^.obj} {factor₂ : A₂ → C^.obj} (ωfactor : factor₁ == factor₂) , ProductDrgm C factor₁ == ProductDrgm C factor₂ | A .(A) (eq.refl .(A)) factor .(factor) (heq.refl .(factor)) := heq.refl _ /-! #brief A handy identity. -/ theorem ProductDrgm.on_Fun {C : Cat.{ℓobj ℓhom}} {A : Type ℓ} (F : Fun (ObjCat A) C) : ProductDrgm C F^.obj = F := Fun.eq (λ x, rfl) (λ ω x y f , begin dsimp [ObjCat, PreorderCat] at f, subst f, apply heq_of_eq, apply eq.symm, apply F^.hom_id end) /-! #brief A cone over a product. -/ definition ProductCone (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) : Type (max ℓ ℓobj ℓhom) := Cone (ProductDrgm C factor) /-! #brief Helper for making a product cone. -/ definition ProductCone.mk {C : Cat.{ℓobj ℓhom}} {A : Type ℓ} {factor : A → C^.obj} (c : C^.obj) (proj : ∀ (a : A), C^.hom c (factor a)) : ProductCone C factor := { obj := c , hom := proj , comm := λ a₁ a₂ f, begin cases f, exact eq.symm C^.circ_id_left end } /-! #brief A product in a category. -/ @[class] definition HasProduct (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) := HasLimit (ProductDrgm C factor) instance HasProduct.HasLimit {C : Cat.{ℓobj ℓhom}} {A : Type ℓ} (factor : A → C^.obj) [factor_HasProduct : HasProduct C factor] : HasLimit (ProductDrgm C factor) := factor_HasProduct /-! #brief A category with all products. -/ class HasAllProducts (C : Cat.{ℓobj ℓhom}) := (has_product : ∀ {A : Type ℓ} (factor : A → C^.obj) , HasProduct C factor) instance HasAllProducts.HasProduct (C : Cat.{ℓobj ℓhom}) [C_HasAllProducts : HasAllProducts.{ℓ} C] {A : Type ℓ} (factor : A → C^.obj) : HasProduct C factor := HasAllProducts.has_product factor instance HasAllProducts.HasAllLimitsFrom.ObjCat (C : Cat.{ℓobj ℓhom}) [C_HasAllProducts : HasAllProducts.{ℓ} C] (A : Type ℓ) : HasAllLimitsFrom C (ObjCat A) := { has_limit := λ L, let l := HasAllProducts.HasProduct C L^.obj in cast (congr_arg HasLimit (ProductDrgm.on_Fun L)) l } /-! #brief Helper for showing a category has a product. -/ definition HasProduct.show (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) (p : C^.obj) (proj : ∀ (a : A), C^.hom p (factor a)) (univ : ∀ (c : C^.obj) (hom : ∀ (a : A), C^.hom c (factor a)) , C^.hom c p) (ωuniv : ∀ (c : C^.obj) (hom : ∀ (a : A), C^.hom c (factor a)) (a : A) , hom a = C^.circ (proj a) (univ c hom)) (ωuniq : ∀ (c : C^.obj) (hom : ∀ (a : A), C^.hom c (factor a)) (h : C^.hom c p) (ωh : ∀ {a : A}, hom a = C^.circ (proj a) h) , h = univ c hom) : HasProduct C factor := HasLimit.show p proj (λ x₁ x₂ f, begin cases f, exact eq.symm C^.circ_id_left end) (λ c hom ωcomm, univ c hom) (λ c hom ωcomm a, ωuniv c hom a) (λ c hom ωcomm h ωh, ωuniq c hom h @ωh) /-! #brief Products are cones. -/ definition product.cone (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) [factor_HasProduct : HasProduct C factor] : ProductCone C factor := limit.cone (ProductDrgm C factor) /-! #brief The product of a collection of objects. -/ definition product (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) [factor_HasProduct : HasProduct C factor] : C^.obj := limit (ProductDrgm C factor) /-! #brief Projection out of a product. -/ definition product.π (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) [factor_HasProduct : HasProduct C factor] (a : A) : C^.hom (product C factor) (factor a) := limit.out (ProductDrgm C factor) a /-! #brief Every cone is mediated through the product. -/ definition product.univ (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) [factor_HasProduct : HasProduct C factor] (c : ProductCone C factor) : C^.hom c^.obj (product C factor) := limit.univ _ c /-! #brief Every cone is mediated through the product. -/ definition product.univ.mediates (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) {factor_HasProduct : HasProduct C factor} (c : ProductCone C factor) (a : A) : c^.hom a = C^.circ (@product.π C A factor factor_HasProduct a) (product.univ C factor c) := limit.univ.mediates c a /-! #brief The mediating map from the cone to the product is unique. -/ definition product.univ.uniq (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) {factor_HasProduct : HasProduct C factor} (c : ProductCone C factor) (m : C^.hom c^.obj (product C factor)) (ω : ∀ (a : A), c^.hom a = (@product.π C A factor factor_HasProduct a) ∘∘ m) : m = product.univ C factor c := limit.univ.uniq c m ω /-! #brief The unique iso between two products of the same factors. -/ definition product.iso {C : Cat.{ℓobj ℓhom}} {A : Type ℓ} {factor : A → C^.obj} (factor_HasProduct₁ factor_HasProduct₂ : HasProduct C factor) : C^.hom (@product C A factor factor_HasProduct₁) (@product C A factor factor_HasProduct₂) := limit.iso factor_HasProduct₁ factor_HasProduct₂ /-! #brief Products are unique up-to unique isomorphism. -/ definition product.uniq {C : Cat.{ℓobj ℓhom}} {A : Type ℓ} {factor : A → C^.obj} (factor_HasProduct₁ factor_HasProduct₂ : HasProduct C factor) : Iso (product.iso factor_HasProduct₁ factor_HasProduct₂) (product.iso factor_HasProduct₂ factor_HasProduct₁) := limit.uniq factor_HasProduct₁ factor_HasProduct₂ /- ----------------------------------------------------------------------- Products in functor categories. ----------------------------------------------------------------------- -/ /-! #brief Products in functor categories can be computed pointwise. -/ instance FunCat.HasProduct {C : Cat.{ℓobj₁ ℓhom₁}} {D : Cat.{ℓobj₂ ℓhom₂}} [D_HasAllProducts : HasAllProducts.{ℓ} D] {A : Type ℓ} (factor : A → Fun C D) : HasProduct (FunCat C D) factor := FunCat.HasLimit (ProductDrgm _ factor) /-! #brief Products in functor categories can be computed pointwise. -/ instance FunCat.HasAllProducts {C : Cat.{ℓobj₁ ℓhom₁}} {D : Cat.{ℓobj₂ ℓhom₂}} [D_HasAllProducts : HasAllProducts.{ℓ} D] : HasAllProducts.{ℓ} (FunCat C D) := { has_product := λ A factor, FunCat.HasProduct factor } /- ----------------------------------------------------------------------- Finite products. ----------------------------------------------------------------------- -/ /-! #brief A cone over a finite product. -/ definition FinProductCone (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) : Type (max ℓobj ℓhom) := ProductCone C (list.get factor) /-! #brief Every finite product cone comes with projections. -/ definition FinProductCone.Proj {C : Cat.{ℓobj ℓhom}} {factor : list C^.obj} (c : FinProductCone C factor) : HomsOut c^.obj factor := dlist.enum (Cone.hom c) /-! #brief Helper for making a finite product cone. -/ definition FinProductCone.mk {C : Cat.{ℓobj ℓhom}} {factor : list C^.obj} (c : C^.obj) (proj : HomsOut c factor) : FinProductCone C factor := ProductCone.mk c (HomsOut.get proj) /-! #brief A finite product in a category. -/ @[class] definition HasFinProduct (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) := HasProduct C (list.get factor) instance HasFinProduct.HasProduct (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasProduct : HasFinProduct C factor] : HasProduct C (list.get factor) := factor_HasProduct /-! #brief A category with all finite products. -/ class HasAllFinProducts (C : Cat.{ℓobj ℓhom}) := (has_product : ∀ (factor : list C^.obj), HasFinProduct C factor) instance HasAllFinProducts.HasFinProduct (C : Cat.{ℓobj ℓhom}) [C_HasAllFinProducts : HasAllFinProducts C] (factor : list C^.obj) : HasFinProduct C factor := HasAllFinProducts.has_product factor instance HasAllFinProducts.HasAllLimitsFrom.ObjCat (C : Cat.{ℓobj ℓhom}) [C_HasAllFinProducts : HasAllFinProducts C] (N : ℕ) : HasAllLimitsFrom C (ObjCat (fin N)) := { has_limit := λ L, let l := HasAllFinProducts.HasFinProduct C (fin.enum L^.obj) in let ω₁ : ObjCat (fin (list.length (fin.enum (L^.obj)))) = ObjCat (fin N) := by rw list.length_enum in let ω₂ : ProductDrgm C (list.get (fin.enum L^.obj)) == L := by calc ProductDrgm C (list.get (fin.enum L^.obj)) == ProductDrgm C L^.obj : ProductDrgm.heq _ (congr_arg fin (list.length_enum _)) list.get_enum' ... = L : ProductDrgm.on_Fun L in cast (HasLimit.heq (by rw list.length_enum) rfl ω₂) l } /-! #brief Helper for showing a category has a finite product. -/ definition HasFinProduct.show {C : Cat.{ℓobj ℓhom}} (factor : list C^.obj) (p : C^.obj) (proj : HomsOut p factor) (univ : ∀ (c : C^.obj) (hom : HomsOut c factor) , C^.hom c p) (ωuniv : ∀ (c : C^.obj) (hom : HomsOut c factor) , hom = HomsOut.comp proj (univ c hom)) (ωuniq : ∀ (c : C^.obj) (hom : HomsOut c factor) (h : C^.hom c p) (ωcomm : hom = HomsOut.comp proj h) , h = univ c hom) : HasFinProduct C factor := HasProduct.show C _ p (HomsOut.get proj) (λ c hom, univ c (HomsOut.enum hom)) (λ c hom n, let hom' : HomsOut c factor := HomsOut.enum hom in let f := (λ a j, @Cat.circ C _ _ a j (univ c hom')) in begin refine eq.trans (eq.symm (dlist.get_enum hom n)) _, refine eq.trans _ (dlist.get_map f proj n), exact congr_arg (λ bb, HomsOut.get bb n) (ωuniv c _) end) (λ c hom h ωcomm, let hom' : HomsOut c factor := HomsOut.enum hom in let f := (λ a j, @Cat.circ C _ _ a j h) in ωuniq c _ h (dlist.enum_eq_map f proj hom @ωcomm)) /-! #brief Finite products are cones. -/ definition finproduct.cone (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinProduct : HasFinProduct C factor] : FinProductCone C factor := product.cone C (list.get factor) /-! #brief The product of a finite collection of objects. -/ definition finproduct (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinProduct : HasFinProduct C factor] : C^.obj := (finproduct.cone C factor)^.obj /-! #brief Projection out of a product. -/ definition finproduct.π (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinProduct : HasFinProduct C factor] (n : fin (list.length factor)) : C^.hom (finproduct C factor) (list.get factor n) := product.π C (list.get factor) n /-! #brief Every cone is mediated through the product. -/ definition finproduct.univ (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinProduct : HasFinProduct C factor] {c : C^.obj} (hom : HomsOut c factor) : C^.hom c (finproduct C factor) := product.univ C (list.get factor) (FinProductCone.mk c hom) /-! #brief Every cone is mediated through the product. -/ definition finproduct.univ.mediates (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinProduct : HasFinProduct C factor] {c : C^.obj} (hom : HomsOut c factor) (n : fin (list.length factor)) : HomsOut.get hom n = C^.circ (finproduct.π C factor n) (finproduct.univ C factor hom) := product.univ.mediates C (list.get factor) (FinProductCone.mk c hom) n /-! #brief The mediating map from the cone to the product is unique. -/ definition finproduct.univ.uniq (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinProduct : HasFinProduct C factor] {c : C^.obj} (hom : HomsOut c factor) (m : C^.hom c (finproduct C factor)) (ω : hom = HomsOut.comp (finproduct.cone C factor)^.Proj m) : m = finproduct.univ C factor hom := product.univ.uniq C (list.get factor) (FinProductCone.mk c hom) m begin intro n, rw ω, refine eq.trans (dlist.get_map _ _ n) _, apply congr_arg (λ j, C^.circ j m), apply dlist.get_enum end /-! #brief The unique iso between two products of the same factors. -/ definition finproduct.iso {C : Cat.{ℓobj ℓhom}} {factor : list C^.obj} (factor_HasFinProduct₁ factor_HasFinProduct₂ : HasFinProduct C factor) : C^.hom (@finproduct C factor factor_HasFinProduct₁) (@finproduct C factor factor_HasFinProduct₂) := product.iso factor_HasFinProduct₁ factor_HasFinProduct₂ /-! #brief Finite products are unique up-to unique isomorphism. -/ definition finproduct.uniq {C : Cat.{ℓobj ℓhom}} {factor : list C^.obj} (factor_HasFinProduct₁ factor_HasFinProduct₂ : HasFinProduct C factor) : Iso (finproduct.iso factor_HasFinProduct₁ factor_HasFinProduct₂) (finproduct.iso factor_HasFinProduct₂ factor_HasFinProduct₁) := product.uniq factor_HasFinProduct₁ factor_HasFinProduct₂ /- ----------------------------------------------------------------------- Finite products in functor categories. ----------------------------------------------------------------------- -/ /-! #brief Finite products in functor categories can be computed pointwise. -/ definition FunCat.HasFinProduct {C : Cat.{ℓobj₁ ℓhom₁}} {D : Cat.{ℓobj₂ ℓhom₂}} [D_HasAllFinProducts : HasAllFinProducts D] (factor : list (Fun C D)) : HasFinProduct (FunCat C D) factor := FunCat.HasLimit (ProductDrgm _ (list.get factor)) /-! #brief Finite products in functor categories can be computed pointwise. -/ instance FunCat.HasAllFinProducts {C : Cat.{ℓobj₁ ℓhom₁}} {D : Cat.{ℓobj₂ ℓhom₂}} [D_HasAllFinProducts : HasAllFinProducts D] : HasAllFinProducts (FunCat C D) := { has_product := λ factor, FunCat.HasFinProduct factor } /- ----------------------------------------------------------------------- Finite products of homs. ----------------------------------------------------------------------- -/ /-! #brief The product of a list of homs. -/ definition finproduct.hom {C : Cat.{ℓobj ℓhom}} {ccs : list (prod C^.obj C^.obj)} (fns : HomsList C ccs) [ccs_domFinProduct : HasFinProduct C (list.map prod.fst ccs)] [ccs_codomFinProduct : HasFinProduct C (list.map prod.snd ccs)] : C^.hom (finproduct C (list.map prod.fst ccs)) (finproduct C (list.map prod.snd ccs)) := finproduct.univ _ _ (homs_comp_out fns (finproduct.cone C (list.map prod.fst ccs))^.Proj) example (C : Cat) {x₁ x₂ y₁ y₂ : ⟦C⟧} [x_HasFinProduct : HasFinProduct C [x₁, x₂] ] [y_HasFinProduct : HasFinProduct C [y₁, y₂] ] (f₁ : ⟦C: x₁ →→ y₁⟧) (f₂ : ⟦C: x₂ →→ y₂⟧) : ⟦C: finproduct C [x₁, x₂] →→ finproduct C [y₁, y₂] ⟧ := finproduct.hom (f₁ ↗ f₂ ↗↗) theorem finproduct.hom₂.id {C : Cat} {x₁ x₂ : ⟦C⟧} [x_HasFinProduct : HasFinProduct C [x₁, x₂] ] : @finproduct.hom _ _ (⟨⟨x₁⟩⟩ ↗ ⟨⟨x₂⟩⟩ ↗↗) x_HasFinProduct x_HasFinProduct = C^.id (finproduct C [x₁, x₂]) := sorry theorem finproduct.hom₂.circ {C : Cat} {x₁ x₂ y₁ y₂ z₁ z₂ : ⟦C⟧} [x_HasFinProduct : HasFinProduct C [x₁, x₂] ] [y_HasFinProduct : HasFinProduct C [y₁, y₂] ] [z_HasFinProduct : HasFinProduct C [z₁, z₂] ] (g₁ : C^.hom y₁ z₁) (g₂ : C^.hom y₂ z₂) (f₁ : C^.hom x₁ y₁) (f₂ : C^.hom x₂ y₂) : @finproduct.hom _ _ ((g₁ ∘∘ f₁) ↗ (g₂ ∘∘ f₂) ↗↗) x_HasFinProduct z_HasFinProduct = @finproduct.hom _ _ (g₁ ↗ g₂ ↗↗) y_HasFinProduct z_HasFinProduct ∘∘ @finproduct.hom _ _ (f₁ ↗ f₂ ↗↗) x_HasFinProduct y_HasFinProduct := sorry /- ----------------------------------------------------------------------- Isos between finite products. ----------------------------------------------------------------------- -/ /-! #brief Singleton products are trivial. -/ instance HasFinProduct.singleton {C : Cat.{ℓobj ℓhom}} (c : C^.obj) : HasFinProduct C [c] := HasFinProduct.show _ c (dlist.cons c (C^.id c) [] (dlist.nil _)) (λ c' proj, begin cases proj, exact b end) (λ c' hom, begin cases hom, apply dlist.eq, { exact eq.symm C^.circ_id_left }, cases bb, trivial end) (λ c' hom h ωh, begin cases hom, cases ωh, exact eq.symm C^.circ_id_left end) definition finproduct.singleton.un {C : Cat.{ℓobj ℓhom}} (c : C^.obj) [c_HasFinProduct : HasFinProduct C [c]] : C^.hom (finproduct C [c]) c := finproduct.iso c_HasFinProduct (HasFinProduct.singleton c) definition finproduct.singleton.to {C : Cat.{ℓobj ℓhom}} (c : C^.obj) [c_HasFinProduct : HasFinProduct C [c]] : C^.hom c (finproduct C [c]) := finproduct.iso (HasFinProduct.singleton c) c_HasFinProduct definition finproduct.singleton.Iso {C : Cat.{ℓobj ℓhom}} (c : C^.obj) [c_HasFinProduct : HasFinProduct C [c]] : Iso (finproduct.singleton.to c) (finproduct.singleton.un c) := finproduct.uniq (HasFinProduct.singleton c) c_HasFinProduct /-! #brief Projections for the (right) flattened product. -/ definition HasFinProduct.flatten_right.Proj {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂])] : HomsOut (finproduct C (factor₁ ++ [finproduct C factor₂])) (factor₁ ++ factor₂) := let prj₁₂ : HomsOut (finproduct C (factor₁ ++ [finproduct C factor₂])) (factor₁ ++ [finproduct C factor₂]) := (@finproduct.cone _ _ factor₁₂_HasFinProduct)^.Proj in let f₁ : HomsOut (finproduct C (factor₁ ++ [finproduct C factor₂])) factor₁ := HomsOut.split_left prj₁₂ in let f₂ : HomsOut (finproduct C (factor₁ ++ [finproduct C factor₂])) [finproduct C factor₂] := HomsOut.split_right prj₁₂ in let f₂' := HomsOut.comp (@finproduct.cone _ _ factor₂_HasFinProduct)^.Proj (HomsOut.get f₂ fin.zero) in HomsOut.append f₁ f₂' /-! #brief The projections used by the universal map for the (right) flattened product. -/ definition HasFinProduct.flatten_right.univ.Proj {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂])] (c : C^.obj) (homs : HomsOut c (factor₁ ++ factor₂)) : HomsOut c (factor₁ ++ [finproduct C factor₂]) := let f₁ : HomsOut c factor₁ := HomsOut.split_left homs in let f₂ : HomsOut c [finproduct C factor₂] := dlist.cons _ (finproduct.univ C factor₂ (HomsOut.split_right homs)) _ (dlist.nil _) in HomsOut.append f₁ f₂ /-! #brief Universal map for the (right) flattened product. -/ definition HasFinProduct.flatten_right.univ {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂])] (c : C^.obj) (hom : HomsOut c (factor₁ ++ factor₂)) : C^.hom c (finproduct C (factor₁ ++ [finproduct C factor₂])) := finproduct.univ C (factor₁ ++ [finproduct C factor₂]) (HasFinProduct.flatten_right.univ.Proj factor₁ factor₂ c hom) /-! #brief Flattening of products on the right. -/ definition HasFinProduct.flatten_right {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂])] : HasFinProduct C (factor₁ ++ factor₂) := HasFinProduct.show _ (finproduct C (factor₁ ++ [finproduct C factor₂])) (HasFinProduct.flatten_right.Proj factor₁ factor₂) (HasFinProduct.flatten_right.univ factor₁ factor₂) sorry sorry definition finproduct.flatten_right {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂])] [factor₁₂_flat_HasFinProduct : HasFinProduct C (factor₁ ++ factor₂)] : C^.hom (finproduct C (factor₁ ++ [finproduct C factor₂])) (finproduct C (factor₁ ++ factor₂)) := finproduct.iso (HasFinProduct.flatten_right factor₁ factor₂) factor₁₂_flat_HasFinProduct definition finproduct.unflatten_right {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂])] [factor₁₂_flat_HasFinProduct : HasFinProduct C (factor₁ ++ factor₂)] : C^.hom (finproduct C (factor₁ ++ factor₂)) (finproduct C (factor₁ ++ [finproduct C factor₂])) := finproduct.iso factor₁₂_flat_HasFinProduct (HasFinProduct.flatten_right factor₁ factor₂) definition finproduct.flatten_right.Iso {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂])] [factor₁₂_flat_HasFinProduct : HasFinProduct C (factor₁ ++ factor₂)] : Iso (finproduct.flatten_right factor₁ factor₂) (finproduct.unflatten_right factor₁ factor₂) := finproduct.uniq (HasFinProduct.flatten_right factor₁ factor₂) factor₁₂_flat_HasFinProduct /-! #brief Projections for the flattened product. -/ definition HasFinProduct.flatten.Proj {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ factor₃ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂₃_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)] : HomsOut (finproduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)) (factor₁ ++ factor₂ ++ factor₃) := let prj₁₂₃ : HomsOut (finproduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)) (factor₁ ++ [finproduct C factor₂] ++ factor₃) := (@finproduct.cone _ _ factor₁₂₃_HasFinProduct)^.Proj in let f₁ : HomsOut (finproduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)) factor₁ := HomsOut.split_left (HomsOut.split_left prj₁₂₃) in let f₂ : HomsOut (finproduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)) [finproduct C factor₂] := HomsOut.split_right (HomsOut.split_left prj₁₂₃) in let f₂' := HomsOut.comp (@finproduct.cone _ _ factor₂_HasFinProduct)^.Proj (HomsOut.get f₂ fin.zero) in let f₃ : HomsOut (finproduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)) factor₃ := HomsOut.split_right prj₁₂₃ in HomsOut.append (HomsOut.append f₁ f₂') f₃ /-! #brief The projections used by the universal map for the flattened product. -/ definition HasFinProduct.flatten.univ.Proj {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ factor₃ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂₃_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)] (c : C^.obj) (hom : HomsOut c (factor₁ ++ factor₂ ++ factor₃)) : HomsOut c (factor₁ ++ [finproduct C factor₂] ++ factor₃) := let f₁ : HomsOut c factor₁ := HomsOut.split_left (HomsOut.split_left hom) in let f₂ : HomsOut c [finproduct C factor₂] := dlist.cons _ (finproduct.univ C factor₂ (HomsOut.split_right (HomsOut.split_left hom))) _ (dlist.nil _) in let f₃ : HomsOut c factor₃ := HomsOut.split_right hom in HomsOut.append (HomsOut.append f₁ f₂) f₃ /-! #brief Universal map for the flattened product. -/ definition HasFinProduct.flatten.univ {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ factor₃ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂₃_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)] (c : C^.obj) (hom : HomsOut c (factor₁ ++ factor₂ ++ factor₃)) : C^.hom c (finproduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)) := finproduct.univ C (factor₁ ++ [finproduct C factor₂] ++ factor₃) (HasFinProduct.flatten.univ.Proj factor₁ factor₂ factor₃ c hom) /-! #brief Flattening of products. -/ definition HasFinProduct.flatten {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ factor₃ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂₃_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)] : HasFinProduct C (factor₁ ++ factor₂ ++ factor₃) := HasFinProduct.show _ (finproduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)) (HasFinProduct.flatten.Proj factor₁ factor₂ factor₃) (HasFinProduct.flatten.univ factor₁ factor₂ factor₃) begin intros c hom, apply HomsOut.append_eq, apply HomsOut.append_eq, { repeat { rw HomsOut.split_left_comp }, unfold HasFinProduct.flatten.Proj, repeat { rw HomsOut.split_left_append }, apply HomsOut.get.inj, apply funext, intro n, cases n with n ωn, rw HomsOut.get_comp, repeat { rw HomsOut.get_split_left }, repeat { rw C^.circ_assoc }, repeat { rw cast_hom.circ }, rw -C^.circ_assoc, apply cast_hom.circ.congr_right, unfold HasFinProduct.flatten.univ, refine heq.trans _ (heq_of_eq (Cat.circ.congr_left (eq.symm (HomsOut.get_enum _ _)))), refine heq.trans _ (heq_of_eq (finproduct.univ.mediates C (factor₁ ++ [finproduct C factor₂] ++ factor₃) (HasFinProduct.flatten.univ.Proj factor₁ factor₂ factor₃ c hom) {val := n, is_lt := list.length.grow_left (list.length.grow_left ωn)})), unfold HasFinProduct.flatten.univ.Proj, refine heq.trans _ (heq.symm (HomsOut.get_append _ _ _ _)), refine heq.trans _ (heq.symm (HomsOut.get_append _ _ _ _)), repeat { rw HomsOut.get_split_left }, rw [C^.circ_assoc, cast_hom.circ], refine heq.trans _ (heq.symm (cast_hom.circ_left_heq _ _)), apply heq.refl }, { exact sorry }, { exact sorry } end begin intros c hom h ωh, exact sorry end definition finproduct.unflatten {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ factor₃ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂₃_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)] [factor₁₂₃_flat_HasFinProduct : HasFinProduct C (factor₁ ++ factor₂ ++ factor₃)] : C^.hom (finproduct C (factor₁ ++ factor₂ ++ factor₃)) (finproduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)) := finproduct.iso factor₁₂₃_flat_HasFinProduct (HasFinProduct.flatten factor₁ factor₂ factor₃) definition finproduct.flatten {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ factor₃ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂₃_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)] [factor₁₂₃_flat_HasFinProduct : HasFinProduct C (factor₁ ++ factor₂ ++ factor₃)] : C^.hom (finproduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)) (finproduct C (factor₁ ++ factor₂ ++ factor₃)) := finproduct.iso (HasFinProduct.flatten factor₁ factor₂ factor₃) factor₁₂₃_flat_HasFinProduct definition finproduct.flatten.Iso {C : Cat.{ℓobj ℓhom}} (factor₁ factor₂ factor₃ : list C^.obj) [factor₂_HasFinProduct : HasFinProduct C factor₂] [factor₁₂₃_HasFinProduct : HasFinProduct C (factor₁ ++ [finproduct C factor₂] ++ factor₃)] [factor₁₂₃_flat_HasFinProduct : HasFinProduct C (factor₁ ++ factor₂ ++ factor₃)] : Iso (finproduct.flatten factor₁ factor₂ factor₃) (finproduct.unflatten factor₁ factor₂ factor₃) := finproduct.uniq (HasFinProduct.flatten factor₁ factor₂ factor₃) factor₁₂₃_flat_HasFinProduct example (C : Cat) (x y z : ⟦C⟧) [xy_HasFinProduct : HasFinProduct C [x, y]] [xy_z_HasFinProduct : HasFinProduct C [finproduct C [x, y], z]] [yz_HasFinProduct : HasFinProduct C [y, z]] [x_yz_HasFinProduct : HasFinProduct C [x, finproduct C [y, z]]] : ⟦C : finproduct C [finproduct C [x, y], z] →→ finproduct C [x, finproduct C [y, z]]⟧ := finproduct.iso (@HasFinProduct.flatten C [] [x, y] [z] xy_HasFinProduct xy_z_HasFinProduct) (@HasFinProduct.flatten C [x] [y,z] [] yz_HasFinProduct x_yz_HasFinProduct) /- ----------------------------------------------------------------------- Co-products. ----------------------------------------------------------------------- -/ /-! #brief A cone over a co-product. -/ definition CoProductCone (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) : Type (max ℓ ℓobj ℓhom) := CoCone (ProductDrgm C factor) /-! #brief Helper for making a product cone. -/ definition CoProductCone.mk {C : Cat.{ℓobj ℓhom}} {A : Type ℓ} {factor : A → C^.obj} (c : C^.obj) (incl : ∀ (a : A), C^.hom (factor a) c) : CoProductCone C factor := CoCone.mk c incl (λ a₁ a₂ f, begin cases f, exact eq.symm C^.circ_id_right end) /-! #brief A co-product in a category. -/ @[class] definition HasCoProduct (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) := HasCoLimit (ProductDrgm C factor) instance HasCoProduct.HasCoLimit {C : Cat.{ℓobj ℓhom}} {A : Type ℓ} (factor : A → C^.obj) [factor_HasCoProduct : HasCoProduct C factor] : HasCoLimit (ProductDrgm C factor) := factor_HasCoProduct /-! #brief A category with all co-products. -/ class HasAllCoProducts (C : Cat.{ℓobj ℓhom}) := (has_coproduct : ∀ {A : Type ℓ} (factor : A → C^.obj) , HasCoProduct C factor) instance HasAllCoProducts.HasCoProduct (C : Cat.{ℓobj ℓhom}) [C_HasAllCoProducts : HasAllCoProducts.{ℓ} C] {A : Type ℓ} (factor : A → C^.obj) : HasCoProduct C factor := HasAllCoProducts.has_coproduct factor instance HasAllCoProducts.HasAllCoLimitsFrom.ObjCat (C : Cat.{ℓobj ℓhom}) [C_HasAllCoProducts : HasAllCoProducts.{ℓ} C] (A : Type ℓ) : HasAllCoLimitsFrom C (ObjCat A) := { has_colimit := λ L, let l := HasAllCoProducts.HasCoProduct C L^.obj in cast (congr_arg HasCoLimit (ProductDrgm.on_Fun L)) l } /-! #brief Helper for showing a category has a co-product. -/ definition HasCoProduct.show (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) (p : C^.obj) (incl : ∀ (a : A), C^.hom (factor a) p) (univ : ∀ (c : C^.obj) (hom : ∀ (a : A), C^.hom (factor a) c) , C^.hom p c) (ωuniv : ∀ (c : C^.obj) (hom : ∀ (a : A), C^.hom (factor a) c) (a : A) , hom a = C^.circ (univ c hom) (incl a)) (ωuniq : ∀ (c : C^.obj) (hom : ∀ (a : A), C^.hom (factor a) c) (h : C^.hom p c) (ωh : ∀ {a : A}, hom a = C^.circ h (incl a)) , h = univ c hom) : HasCoProduct C factor := HasCoLimit.show p incl (λ a₁ a₂ f, begin cases f, exact eq.symm C^.circ_id_right end) (λ c hom ωhom, univ c hom) (λ c hom ωhom a, ωuniv c hom a) (λ c hom ωhom h ωh, ωuniq c hom h ωh) /-! #brief Co-products are cones. -/ definition coproduct.cone (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) [factor_HasCoProduct : HasCoProduct C factor] : CoProductCone C factor := colimit.cocone (ProductDrgm C factor) /-! #brief The co-product of a collection of objects. -/ definition coproduct (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) [factor_HasCoProduct : HasCoProduct C factor] : C^.obj := (coproduct.cone C factor)^.obj /-! #brief Inclusion into a co-product. -/ definition coproduct.ι (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) [factor_HasCoProduct : HasCoProduct C factor] (a : A) : C^.hom (factor a) (coproduct C factor) := colimit.in (ProductDrgm C factor) a /-! #brief Every cone is mediated through the co-product. -/ definition coproduct.univ (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) [factor_HasCoProduct : HasCoProduct C factor] (c : CoProductCone C factor) : C^.hom (coproduct C factor) c^.obj := colimit.univ (ProductDrgm C factor) c /-! #brief Every cone is mediated through the co-product. -/ definition coproduct.univ.mediates (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) {factor_HasCoProduct : HasCoProduct C factor} (c : CoProductCone C factor) (a : A) : c^.hom a = C^.circ (coproduct.univ C factor c) (@coproduct.ι C A factor factor_HasCoProduct a) := colimit.univ.mediates c a /-! #brief The mediating map from the co-product to the cone unique. -/ definition coproduct.univ.uniq (C : Cat.{ℓobj ℓhom}) {A : Type ℓ} (factor : A → C^.obj) {factor_HasCoProduct : HasCoProduct C factor} (c : CoProductCone C factor) (m : C^.hom (coproduct C factor) c^.obj) (ω : ∀ (a : A), c^.hom a = m ∘∘ (@coproduct.ι C A factor factor_HasCoProduct a)) : m = coproduct.univ C factor c := colimit.univ.uniq c m ω /-! #brief The unique iso between two coproducts of the same factors. -/ definition coproduct.iso {C : Cat.{ℓobj ℓhom}} {A : Type ℓ} {factor : A → C^.obj} (factor_HasCoProduct₁ factor_HasCoProduct₂ : HasCoProduct C factor) : C^.hom (@coproduct C A factor factor_HasCoProduct₁) (@coproduct C A factor factor_HasCoProduct₂) := colimit.iso factor_HasCoProduct₁ factor_HasCoProduct₂ /-! #brief Co-products are unique up-to unique isomorphism. -/ definition coproduct.uniq {C : Cat.{ℓobj ℓhom}} {A : Type ℓ} {factor : A → C^.obj} (factor_HasCoProduct₁ factor_HasCoProduct₂ : HasCoProduct C factor) : Iso (coproduct.iso factor_HasCoProduct₁ factor_HasCoProduct₂) (coproduct.iso factor_HasCoProduct₂ factor_HasCoProduct₁) := { id₁ := (colimit.uniq factor_HasCoProduct₂ factor_HasCoProduct₁)^.id₂ , id₂ := (colimit.uniq factor_HasCoProduct₂ factor_HasCoProduct₁)^.id₁ } /-! #brief Factor-projection out of a certain kind of coproduct. -/ definition coproduct.factor_out {C : Cat.{ℓobj (ℓhom + 1)}} [C_HasFinal : HasFinal C] {A : C^.obj} (factor : C^.hom (final C) A → C^.obj) [factor_HasCoProduct : HasCoProduct C factor] : C^.hom (coproduct C factor) A := coproduct.univ C factor (CoProductCone.mk A (λ a, C^.circ a (final_hom (factor a)))) /- ----------------------------------------------------------------------- Co-products in functor categories. ----------------------------------------------------------------------- -/ /-! #brief Co-products in functor categories can be computed pointwise. -/ instance FunCat.HasCoProduct {C : Cat.{ℓobj₁ ℓhom₁}} {D : Cat.{ℓobj₂ ℓhom₂}} [D_HasAllCoProducts : HasAllCoProducts.{ℓ} D] {A : Type ℓ} (factor : A → Fun C D) : HasCoProduct (FunCat C D) factor := @FunCat.HasCoLimit C D _ (HasAllCoProducts.HasAllCoLimitsFrom.ObjCat D A) (ProductDrgm (FunCat C D) factor) /-! #brief Co-products in functor categories can be computed pointwise. -/ instance FunCat.HasAllCoProducts {C : Cat.{ℓobj₁ ℓhom₁}} {D : Cat.{ℓobj₂ ℓhom₂}} [D_HasAllCoProducts : HasAllCoProducts.{ℓ} D] : HasAllCoProducts.{ℓ} (FunCat C D) := { has_coproduct := λ A factor, FunCat.HasCoProduct factor } /- ----------------------------------------------------------------------- Finite co-products. ----------------------------------------------------------------------- -/ /-! #brief A cone over a finite co-product. -/ definition FinCoProductCone (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) : Type (max ℓobj ℓhom) := CoProductCone C (list.get factor) /-! #brief Every finite co-product cone comes with inclusions. -/ definition FinCoProductCone.Proj {C : Cat.{ℓobj ℓhom}} {factor : list C^.obj} (c : FinCoProductCone C factor) : HomsIn factor c^.obj := dlist.enum (Cone.hom c) /-! #brief Helper for making a finite co-product cone. -/ definition FinCoProductCone.mk {C : Cat.{ℓobj ℓhom}} {factor : list C^.obj} (c : C^.obj) (incl : HomsIn factor c) : FinCoProductCone C factor := CoProductCone.mk c (HomsIn.get incl) /-! #brief A finite co-product in a category. -/ @[class] definition HasFinCoProduct (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) := HasCoProduct C (list.get factor) instance HasFinCoProduct.HasCoProduct (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasCoProduct : HasFinCoProduct C factor] : HasCoProduct C (list.get factor) := factor_HasCoProduct /-! #brief A category with all finite co-products. -/ class HasAllFinCoProducts (C : Cat.{ℓobj ℓhom}) := (has_coproduct : ∀ (factor : list C^.obj), HasFinCoProduct C factor) instance HasAllFinCoProducts.HasFinCoProduct (C : Cat.{ℓobj ℓhom}) [C_HasAllFinCoProducts : HasAllFinCoProducts C] (factor : list C^.obj) : HasFinCoProduct C factor := HasAllFinCoProducts.has_coproduct factor instance HasAllFinCoProducts.HasAllCoLimitsFrom.ObjCat (C : Cat.{ℓobj ℓhom}) [C_HasAllFinCoProducts : HasAllFinCoProducts C] (N : ℕ) : HasAllCoLimitsFrom C (ObjCat (fin N)) := { has_colimit := λ L, let l := HasAllFinCoProducts.HasFinCoProduct C (fin.enum L^.obj) in let ω₁ : ObjCat (fin (list.length (fin.enum (L^.obj)))) = ObjCat (fin N) := by rw list.length_enum in let ω₂ : ProductDrgm C (list.get (fin.enum L^.obj)) == L := by calc ProductDrgm C (list.get (fin.enum L^.obj)) == ProductDrgm C L^.obj : ProductDrgm.heq _ (congr_arg fin (list.length_enum _)) list.get_enum' ... = L : ProductDrgm.on_Fun L in cast (HasCoLimit.heq (by rw list.length_enum) rfl ω₂) l } /-! #brief Helper for showing a category has a finite co-product. -/ definition HasFinCoProduct.show {C : Cat.{ℓobj ℓhom}} (factor : list C^.obj) (p : C^.obj) (incl : HomsIn factor p) (univ : ∀ (c : C^.obj) (hom : HomsIn factor c) , C^.hom p c) (ωuniv : ∀ (c : C^.obj) (hom : HomsIn factor c) , hom = HomsIn.comp (univ c hom) incl) (ωuniq : ∀ (c : C^.obj) (hom : HomsIn factor c) (h : C^.hom p c) (ωcomm : hom = HomsIn.comp h incl) , h = univ c hom) : HasFinCoProduct C factor := HasCoProduct.show C _ p (HomsIn.get incl) (λ c homs, univ c (HomsIn.enum homs)) (λ c homs n, sorry) (λ c homs h ωh, sorry) /-! #brief Finite co-products are cones. -/ definition fincoproduct.cone (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinCoProduct : HasFinCoProduct C factor] : FinCoProductCone C factor := coproduct.cone C (list.get factor) /-! #brief The co-product of a finite collection of objects. -/ definition fincoproduct (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinCoProduct : HasFinCoProduct C factor] : C^.obj := (fincoproduct.cone C factor)^.obj /-! #brief An esoteric but useful equality helper. -/ theorem fincoproduct.eq {C : Cat.{ℓobj ℓhom}} [C_HasAllFinCoProducts : HasAllFinCoProducts C] : ∀ (factor₁ factor₂ : list C^.obj) (ωfactor : factor₁ = factor₂) , @fincoproduct C factor₁ (HasAllFinCoProducts.HasFinCoProduct C factor₁) = @fincoproduct C factor₂ (HasAllFinCoProducts.HasFinCoProduct C factor₂) | factor .(factor) (eq.refl .(factor)) := rfl /-! #brief Inclusion into a finite co-product. -/ definition fincoproduct.ι (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinCoProduct : HasFinCoProduct C factor] (n : fin (list.length factor)) : C^.hom (list.get factor n) (fincoproduct C factor) := coproduct.ι C (list.get factor) n /-! #brief Every cone is mediated through the co-product. -/ definition fincoproduct.univ (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinCoProduct : HasFinCoProduct C factor] {c : C^.obj} (hom : HomsIn factor c) : C^.hom (fincoproduct C factor) c := coproduct.univ C (list.get factor) (FinCoProductCone.mk c hom) /-! #brief Every cone is mediated through the co-product. -/ definition fincoproduct.univ.mediates (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinCoProduct : HasFinCoProduct C factor] {c : C^.obj} (hom : HomsIn factor c) (n : fin (list.length factor)) : HomsIn.get hom n = C^.circ (fincoproduct.univ C factor hom) (fincoproduct.ι C factor n) := coproduct.univ.mediates C (list.get factor) (FinCoProductCone.mk c hom) n /-! #brief The mediating map from the cone to the product is unique. -/ definition fincoproduct.univ.uniq (C : Cat.{ℓobj ℓhom}) (factor : list C^.obj) [factor_HasFinCoProduct : HasFinCoProduct C factor] {c : C^.obj} (hom : HomsIn factor c) (m : C^.hom (fincoproduct C factor) c) (ω : hom = HomsIn.comp m (fincoproduct.cone C factor)^.Proj) : m = fincoproduct.univ C factor hom := coproduct.univ.uniq C (list.get factor) (CoProductCone.mk c (HomsIn.get hom)) m (λ n, sorry) /-! #brief The unique iso between two co-products of the same factors. -/ definition fincoproduct.iso {C : Cat.{ℓobj ℓhom}} {factor : list C^.obj} (factor_HasFinCoProduct₁ factor_HasFinCoProduct₂ : HasFinCoProduct C factor) : C^.hom (@fincoproduct C factor factor_HasFinCoProduct₁) (@fincoproduct C factor factor_HasFinCoProduct₂) := coproduct.iso factor_HasFinCoProduct₁ factor_HasFinCoProduct₂ /-! #brief Finite products are unique up-to unique isomorphism. -/ definition fincoproduct.uniq {C : Cat.{ℓobj ℓhom}} {factor : list C^.obj} (factor_HasFinCoProduct₁ factor_HasFinCoProduct₂ : HasFinCoProduct C factor) : Iso (fincoproduct.iso factor_HasFinCoProduct₁ factor_HasFinCoProduct₂) (fincoproduct.iso factor_HasFinCoProduct₂ factor_HasFinCoProduct₁) := coproduct.uniq factor_HasFinCoProduct₁ factor_HasFinCoProduct₂ /- ----------------------------------------------------------------------- Finite co-products in functor categories. ----------------------------------------------------------------------- -/ /-! #brief Finite co-products in functor categories can be computed pointwise. -/ instance FunCat.HasFinCoProduct {C : Cat.{ℓobj₁ ℓhom₁}} {D : Cat.{ℓobj₂ ℓhom₂}} [D_HasAllFinCoProducts : HasAllFinCoProducts D] (factor : list (Fun C D)) : HasFinCoProduct (FunCat C D) factor := @FunCat.HasCoLimit C D _ (HasAllFinCoProducts.HasAllCoLimitsFrom.ObjCat D _) (ProductDrgm (FunCat C D) (list.get factor)) /-! #brief Co-products in functor categories can be computed pointwise. -/ instance FunCat.HasAllCoFinProducts {C : Cat.{ℓobj₁ ℓhom₁}} {D : Cat.{ℓobj₂ ℓhom₂}} [D_HasAllFinCoProducts : HasAllFinCoProducts D] : HasAllFinCoProducts (FunCat C D) := { has_coproduct := λ factor, FunCat.HasFinCoProduct factor } /- ----------------------------------------------------------------------- Finite co-products of homs. ----------------------------------------------------------------------- -/ /-! #brief The product of a list of homs. -/ definition fincoproduct.hom {C : Cat.{ℓobj ℓhom}} {ccs : list (prod C^.obj C^.obj)} (fns : HomsList C ccs) [ccs_domFinCoProduct : HasFinCoProduct C (list.map prod.fst ccs)] [ccs_codomFinCoProduct : HasFinCoProduct C (list.map prod.snd ccs)] : C^.hom (fincoproduct C (list.map prod.fst ccs)) (fincoproduct C (list.map prod.snd ccs)) := fincoproduct.univ _ _ (homs_comp_in (fincoproduct.cone C (list.map prod.snd ccs))^.Proj fns) end qp
cca935c381146a0ec93c4a048d93ba493ef538ac
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/tactic1.lean
d50e4cfbc3cae046b562955c9223f159065b8e47
[ "Apache-2.0" ]
permissive
soonhokong/lean
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
38607e3eb57f57f77c0ac114ad169e9e4262e24f
refs/heads/master
1,611,187,284,081
1,450,766,737,000
1,476,122,547,000
11,513,992
2
0
null
1,401,763,102,000
1,374,182,235,000
C++
UTF-8
Lean
false
false
78
lean
import logic theorem tst {A B : Prop} (H1 : A) (H2 : B) : A := by assumption
b22233c22796b8d1795d0a389a15f9c130d67c62
928e43dd755d83a0986ba91420df8ad05b8d7c9f
/4_equality.lean
4dff52ee970a87d935784636061ac54e369b1851
[]
no_license
zmactep/llfgg
ea222b377095a42e0de5cf8d4846aff806ce0f31
ed684ae69b94a4a042615c412fef68bdec8fc80c
refs/heads/master
1,585,131,334,279
1,533,894,322,000
1,533,894,322,000
143,688,771
1
0
null
null
null
null
UTF-8
Lean
false
false
13,529
lean
-- Отношения universe u variables α β : Type u -- Рассмотрим некоторый произвольный тип α variable r : α → α → Prop -- Введем на нем бинарное отноешние r variable trans_r : ∀ {x y z : α}, -- мы можем объявить его транзитивным, указав следующий факт r x y → r y z → r x z variables a b c : α -- тогда имея набор переменных типа α variables (hab : r a b) (hbc : r b c) -- и утверждений о связи их отношениями #check trans_r hab hbc -- r a c -- мы можем вывести новое отношение r a c variable refl_r : ∀ {x : α}, r x x -- рефлексивность r variable symm_r : ∀ {x y : α}, r x y → r y x -- симметричность r -- теперь r — отношение эквивалентности example (a b c d : α) (hab : r a b) -- данными утверждениями можно воспользоваться, чтоб (hcb : r c b) (hcd : r c d) : r a d := -- доказать наличие r-отношения между a и d trans_r (trans_r hab (symm_r hcb)) hcd -- Эквивалентность #check @eq.refl -- ∀ {α : Type u}, α = α -- эквивалентность, конечно, есть в стандартной библиотеке #check @eq.symm -- ∀ {α : Type u} {a b : α}, -- a = b → b = a #check @eq.trans -- ∀ {α : Type u} {a b c : α}, -- a = b → b = c → a = c example (a b c d : α) (hab : a = b) -- тот же пример можно вывести из стандартной библиотеки (hcb : c = b) (hcd : c = d) : a = d := eq.trans (eq.trans hab (eq.symm hcb)) hcd example (a b c d : α) (hab : a = b) -- тот же пример в projection notation (нечитаемо) (hcb : c = b) (hcd : c = d) : a = d := (hab.trans hcb.symm).trans hcd example (f : α → β) (a : α) : (λ x, f x) a = f a := -- благодаря выполнению редукции такая штука может быть доказана автоматом eq.refl _ example (a : α) (b : β) : (a, b).1 = a := -- и такая тоже eq.refl _ example : 39 + 3 = 42 := eq.refl _ -- и даже такая #check @rfl -- ∀ {α : Type u}, {a : α}, a = a -- для этого даже вводят специальную функцию rfl == eq.refl _ -- все примеры выше можно переписать через нее example (a : α) (b : β) : (a, b).1 = a := rfl #check @eq.subst -- ∀ {a : Type u} {a b : α} {p : α → Prop}, -- a = b → p a = p b -- важное утверждение, что мы можем менять равные элементы -- внутри любого предиката variable p : α → Prop example (h₁ : a = b) (h₂ : p a) : p b := -- пример использования eq.subst eq.subst h₁ h₂ example (h₁ : a = b) (h₂ : p a) : p b := h₁ ▸ h₂ -- альтернативный синтаксис для eq.subst (▸ получается через \t) #check @congr_arg -- ∀ {α : Type u} {β : Type v} -- аналогично предикатам, замена аргумента может производиться и -- {a₁ a₂ : α} (f : α → β), -- внутри функции над элементами произвольных вселенных -- a₁ = a₂ → f a₁ = f a₂ -- это называется конгруэнтностью по аргументу #check @congr_fun -- ∀ {α : Type u} {β : α → Type v}-- при этом заменяться может и сама функцию -- {f g : Π (x : α), β x}, -- f = g → ∀ x : α, f a = g a #check @congr -- ∀ {α : Type u} {β : Type v} -- или даже функцию и аргумент одновременно -- {f₁ f₂ : α → β} -- {a₁ a₂ : α}, -- f₁ = f₂ → a₁ = a₂ → f₁ a₁ = f₂ a₂ example (h : a = b) (f : α → β) : f a = f b := -- примеры использования функций congr_arg f h example (f g : α → β) (h : f = g) : f a = g a := congr_fun h a example (f g : α → β) (h₁ : f = g) (h₂ : a = b) : f a = g b := congr h₁ h₂ -- Доказательства равенства example (a b c d e : ℕ) -- рассмотрим пример, когда имея несколько утверждений о равенстве (h₁ : a = b) (h₂ : b = c + 1) -- требуется установить новое равенство (h₃ : c = d) (h₄ : e = 1 + d) : a = e := have h₅ : a = c + 1, from eq.trans h₁ h₂, -- a = b = c + 1 можно получить из транзитивности равенства have h₆ : c + 1 = d + 1, from congr_arg _ h₃, -- чтоб перейти из a = c + 1 в a = d + 1 путем замены c на d, -- докажем из c = d равенство c + 1 = d + 1 через рассмотренный выше congr_arg have h₇ : a = d + 1, from eq.trans h₅ h₆, -- теперь можем показать a = c + 1 = d + 1 из транзитивности have h₈ : 1 + d = d + 1, from nat.add_comm 1 d, -- чтоб перейти из a = d + 1 в a = e путем замены e на d + 1, -- докажем из коммунтативности сложения (nat.add_comm) 1 + d = d + 1 have h₉ : e = d + 1, from eq.trans h₄ h₈, -- теперь можем показать e = 1 + d = d + 1 из транзитивности show a = e, from eq.trans h₇ (eq.symm h₉) -- так как цифры кончились, склеим два пункта в один :) -- из симметрии заменим e = d + 1 на d + 1 = e, а далее -- можем показать a = d + 1 = e из транзитивности example (a b c d e : ℕ) -- можем доказать то же через удобную и наглядную конструкцию calc, (h₁ : a = b) (h₂ : b = c + 1) -- придуманную специально для этих случаев; она заменяет обычные (h₃ : c = d) (h₄ : e = 1 + d) : a = e := -- в таких доказательствах цепочки транзитивности calc a = b : h₁ -- утверждение о равенстве : доказательство (тут тривиально) ... = c + 1 : h₂ -- три точки говорят, что мы пользуемся транзитивностью равенства ... = d + 1 : congr_arg _ h₃ -- как и раньше равенство достигается из конгруэнтности аргументов функции λ x, x + 1 ... = 1 + d : nat.add_comm d (1 : ℕ) -- аналогично получаем из коммутативности сложения ... = e : eq.symm h₄ -- результат -- обощенный синтаксис calc: -- calc -- expr₀ op₁ expr₁ : proof₁ -- ... op₂ expr₂ : proof₂ -- {еще много строк} -- ... opn exprn : proofn example (a b c d e : ℕ) -- еще раз то же можно доказать с помощью тактики rw (h₁ : a = b) (h₂ : b = c + 1) -- подробнее тактики мы рассмотрим далее, здесь же ограничимся тем, что (h₃ : c = d) (h₄ : e = 1 + d) : a = e := -- такая тактика позволяет переписать кусок выражения с правой стороны calc -- от равества, что избавляет нас от необходимости пользоваться конгруэнтностью a = b : by rw h₁ ... = c + 1 : by rw h₂ -- применение тактики: by {tactic} {argumets} ... = d + 1 : by rw h₃ -- в данном случае: by rw {равенство, на основании которого переписывается правая часть} ... = 1 + d : by rw nat.add_comm ... = e : by rw h₄ example (a b c d e : ℕ) -- несколько последовательных переписываний можно схлопнуть (h₁ : a = b) (h₂ : b = c + 1) -- передав тактике rw в качестве аргумента список равенств (h₃ : c = d) (h₄ : e = 1 + d) : a = e := calc a = d + 1 : by rw [h₁, h₂, h₃] ... = 1 + d : by rw nat.add_comm ... = e : by rw h₄ example (a b c d e : ℕ) -- или даже вот так (h₁ : a = b) (h₂ : b = c + 1) (h₃ : c = d) (h₄ : e = 1 + d) : a = e := by rw [h₁, h₂, h₃, nat.add_comm, h₄] example (a b c d e : ℕ) -- для самых ленивых существует тактика simp (h₁ : a = b) (h₂ : b = c + 1) -- она перебирает все переданные ей в качестве аргумента (h₃ : c = d) (h₄ : e = 1 + d) : a = e := -- равенства, а также пробует пользоваться ассоциативностью by simp [h₁, h₂, h₃, h₄] -- пока что-нибудь не выведет theorem T1 (a b c d e : ℕ) -- прелесть в том, что построив такое доказательство, (h₁ : a = b) (h₂ : b = c + 1) -- мы даже сможем его распечатать и понять, как оно было осуществлено (h₃ : c = d) (h₄ : e = 1 + d) : a = e := by simp [h₄, h₂, h₁, h₃] #print T1 example (x y : ℕ) : -- напоследок докажем формулу квадрата суммы (x + y) * (x + y) = x * x + y * x + x * y + y * y := calc (x + y) * (x + y) = (x + y) * x + (x + y) * y : by rw mul_add ... = x * x + y * x + (x + y) * y : by rw add_mul ... = x * x + y * x + (x * y + y * y) : by rw add_mul ... = x * x + y * x + x * y + y * y : by rw ←add_assoc -- стрелочка ← (\l) показывает, что -- применяемое равенство требуется -- переписать в обратную сторону #check @add_assoc -- ∀ {α : Type u} (a b c : α) [_ : add_semigroup α] (a b c : α), a + b + c = a + (b + c) -- во-первых, пока опустим add_semigroup α, на это посмотрим позже, но вообще это просто typeclass -- во-вторых, утверждение гласит, что a + b + c = a + (b + c), а нам нужно переписать наоборот: -- формулу со скобками представить без скобок, потому и нужна стрелка ← lemma T2 (x y : ℕ) : -- и так тоже сработает (ассоциативность применится сама) (x + y) * (x + y) = x * x + y * x + x * y + y * y := by simp [mul_add, add_mul] #print T2 example (f : ℕ → ℕ) -- теми же способами можно доказывать неравества (h : ∀ x : ℕ, f x ≤ f (x + 1)) : f 0 ≤ f 3 := calc f 0 ≤ f 1 : h 0 ... ≤ f 2 : h 1 ... ≤ f 3 : h 2
143ee6e56bc1991091c7806cd079af0ea25baa6a
d9d511f37a523cd7659d6f573f990e2a0af93c6f
/src/linear_algebra/matrix/to_linear_equiv.lean
6e63a780885efb1d1cd695932754bd9f03fb3c78
[ "Apache-2.0" ]
permissive
hikari0108/mathlib
b7ea2b7350497ab1a0b87a09d093ecc025a50dfa
a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901
refs/heads/master
1,690,483,608,260
1,631,541,580,000
1,631,541,580,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
7,095
lean
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen -/ import linear_algebra.matrix.nonsingular_inverse import linear_algebra.matrix.to_lin import ring_theory.localization /-! # Matrices and linear equivalences This file gives the map `matrix.to_linear_equiv` from matrices with invertible determinant, to linear equivs. ## Main definitions * `matrix.to_linear_equiv`: a matrix with an invertible determinant forms a linear equiv ## Main results * `matrix.exists_mul_vec_eq_zero_iff`: `M` maps some `v ≠ 0` to zero iff `det M = 0` ## Tags matrix, linear_equiv, determinant, inverse -/ namespace matrix open linear_map variables {R M : Type*} [comm_ring R] [add_comm_group M] [module R M] variables {n : Type*} [fintype n] section to_linear_equiv' variables [decidable_eq n] /-- An invertible matrix yields a linear equivalence from the free module to itself. See `matrix.to_linear_equiv` for the same map on arbitrary modules. -/ noncomputable def to_linear_equiv' (P : matrix n n R) (h : is_unit P) : (n → R) ≃ₗ[R] (n → R) := have h' : is_unit P.det := P.is_unit_iff_is_unit_det.mp h, { inv_fun := P⁻¹.to_lin', left_inv := λ v, show (P⁻¹.to_lin'.comp P.to_lin') v = v, by rw [← matrix.to_lin'_mul, P.nonsing_inv_mul h', matrix.to_lin'_one, linear_map.id_apply], right_inv := λ v, show (P.to_lin'.comp P⁻¹.to_lin') v = v, by rw [← matrix.to_lin'_mul, P.mul_nonsing_inv h', matrix.to_lin'_one, linear_map.id_apply], ..P.to_lin' } @[simp] lemma to_linear_equiv'_apply (P : matrix n n R) (h : is_unit P) : (↑(P.to_linear_equiv' h) : module.End R (n → R)) = P.to_lin' := rfl @[simp] lemma to_linear_equiv'_symm_apply (P : matrix n n R) (h : is_unit P) : (↑(P.to_linear_equiv' h).symm : module.End R (n → R)) = P⁻¹.to_lin' := rfl end to_linear_equiv' section to_linear_equiv variables (b : basis n R M) include b /-- Given `hA : is_unit A.det` and `b : basis R b`, `A.to_linear_equiv b hA` is the `linear_equiv` arising from `to_lin b b A`. See `matrix.to_linear_equiv'` for this result on `n → R`. -/ @[simps apply] noncomputable def to_linear_equiv [decidable_eq n] (A : matrix n n R) (hA : is_unit A.det) : M ≃ₗ[R] M := begin refine { to_fun := to_lin b b A, inv_fun := to_lin b b A⁻¹, left_inv := λ x, _, right_inv := λ x, _, .. to_lin b b A }; simp only [← linear_map.comp_apply, ← matrix.to_lin_mul b b b, matrix.nonsing_inv_mul _ hA, matrix.mul_nonsing_inv _ hA, to_lin_one, linear_map.id_apply] end lemma ker_to_lin_eq_bot [decidable_eq n] (A : matrix n n R) (hA : is_unit A.det) : (to_lin b b A).ker = ⊥ := ker_eq_bot.mpr (to_linear_equiv b A hA).injective lemma range_to_lin_eq_top [decidable_eq n] (A : matrix n n R) (hA : is_unit A.det) : (to_lin b b A).range = ⊤ := range_eq_top.mpr (to_linear_equiv b A hA).surjective end to_linear_equiv section nondegenerate open_locale matrix /-- This holds for all integral domains (see `matrix.exists_mul_vec_eq_zero_iff`), not just fields, but it's easier to prove it for the field of fractions first. -/ lemma exists_mul_vec_eq_zero_iff_aux {K : Type*} [decidable_eq n] [field K] {M : matrix n n K} : (∃ (v ≠ 0), M.mul_vec v = 0) ↔ M.det = 0 := begin split, { rintros ⟨v, hv, mul_eq⟩, contrapose! hv, exact eq_zero_of_mul_vec_eq_zero hv mul_eq }, { contrapose!, intros h, have : function.injective M.to_lin', { simpa only [← linear_map.ker_eq_bot, ker_to_lin'_eq_bot_iff, not_imp_not] using h }, have : M ⬝ linear_map.to_matrix' ((linear_equiv.of_injective_endo M.to_lin' this).symm : (n → K) →ₗ[K] (n → K)) = 1, { refine matrix.to_lin'.injective (linear_map.ext $ λ v, _), rw [matrix.to_lin'_mul, matrix.to_lin'_one, matrix.to_lin'_to_matrix', linear_map.comp_apply], exact (linear_equiv.of_injective_endo M.to_lin' this).apply_symm_apply v }, exact matrix.det_ne_zero_of_right_inverse this } end lemma exists_mul_vec_eq_zero_iff {A : Type*} [decidable_eq n] [integral_domain A] {M : matrix n n A} : (∃ (v ≠ 0), M.mul_vec v = 0) ↔ M.det = 0 := begin have : (∃ (v ≠ 0), mul_vec ((algebra_map A (fraction_ring A)).map_matrix M) v = 0) ↔ _ := exists_mul_vec_eq_zero_iff_aux, rw [← ring_hom.map_det, is_fraction_ring.to_map_eq_zero_iff] at this, refine iff.trans _ this, split; rintro ⟨v, hv, mul_eq⟩, { refine ⟨λ i, algebra_map _ _ (v i), mt (λ h, funext $ λ i, _) hv, _⟩, { exact is_fraction_ring.injective A (fraction_ring A) (congr_fun h i) }, { ext i, refine (ring_hom.map_mul_vec _ _ _ i).symm.trans _, rw [mul_eq, pi.zero_apply, ring_hom.map_zero, pi.zero_apply] } }, { letI := classical.dec_eq (fraction_ring A), obtain ⟨⟨b, hb⟩, ba_eq⟩ := is_localization.exist_integer_multiples_of_finset (non_zero_divisors A) (finset.univ.image v), choose f hf using ba_eq, refine ⟨λ i, f _ (finset.mem_image.mpr ⟨i, finset.mem_univ i, rfl⟩), mt (λ h, funext $ λ i, _) hv, _⟩, { have := congr_arg (algebra_map A (fraction_ring A)) (congr_fun h i), rw [hf, subtype.coe_mk, pi.zero_apply, ring_hom.map_zero, algebra.smul_def, mul_eq_zero, is_fraction_ring.to_map_eq_zero_iff] at this, exact this.resolve_left (mem_non_zero_divisors_iff_ne_zero.mp hb), }, { ext i, refine is_fraction_ring.injective A (fraction_ring A) _, calc algebra_map A (fraction_ring A) (M.mul_vec (λ (i : n), f (v i) _) i) = ((algebra_map A (fraction_ring A)).map_matrix M).mul_vec (algebra_map _ (fraction_ring A) b • v) i : _ ... = 0 : _, { simp_rw [ring_hom.map_mul_vec, mul_vec, dot_product, function.comp_app, hf, subtype.coe_mk, ring_hom.map_matrix_apply, pi.smul_apply, smul_eq_mul, algebra.smul_def] }, { rw [mul_vec_smul, mul_eq, pi.smul_apply, pi.zero_apply, smul_zero] } } }, end lemma exists_vec_mul_eq_zero_iff {A : Type*} [decidable_eq n] [integral_domain A] {M : matrix n n A} : (∃ (v ≠ 0), M.vec_mul v = 0) ↔ M.det = 0 := by simpa only [← M.det_transpose, ← mul_vec_transpose] using exists_mul_vec_eq_zero_iff theorem nondegenerate_iff_det_ne_zero {A : Type*} [decidable_eq n] [integral_domain A] {M : matrix n n A} : nondegenerate M ↔ M.det ≠ 0 := begin refine iff.trans _ (not_iff_not.mpr exists_vec_mul_eq_zero_iff), simp only [not_exists], split, { intros hM v hv hMv, obtain ⟨w, hwMv⟩ := hM.exists_not_ortho_of_ne_zero hv, simpa only [dot_product_mul_vec, hMv, zero_dot_product] using hwMv }, { intros h v hv, refine not_imp_not.mp (h v) (funext $ λ i, _), simpa only [dot_product_mul_vec, dot_product_single, mul_one] using hv (pi.single i 1) } end alias nondegenerate_iff_det_ne_zero ↔ matrix.nondegenerate.det_ne_zero matrix.nondegenerate.of_det_ne_zero end nondegenerate end matrix
0c04a14152ec10e5e349d0a8f94b5ffe658d42fc
6096e76aa1d83b3f250d2c69eeda5b692d6bd3e2
/src/norms.lean
945c250b1a93083587587359d9d384bf3b608385
[]
no_license
ChrisHughes24/lean-differential-topology
3782f1841e5205f76a122b7e8ceb9c65ace06088
0abdf5a61414459fb0833f39b4d04c3528404454
refs/heads/master
1,584,570,674,323
1,527,526,729,000
1,527,526,729,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
12,169
lean
import analysis.real import linear_algebra.prod_module import algebra.pi_instances import metric_space_fintype_pi noncomputable theory local notation f `→_{`:50 a `}`:0 b := filter.tendsto f (nhds a) (nhds b) class normed_group (α : Type*) extends add_comm_group α, metric_space α := (norm : α → ℝ) (dist_eq : ∀ x y, dist x y = norm (x - y)) def norm {G : Type*} [normed_group G] : G → ℝ := normed_group.norm notation `∥` e `∥` := norm e section normed_group variables {G : Type*} [normed_group G] {H : Type*} [normed_group H] lemma norm_dist' { g h : G} : dist g h = ∥g - h∥ := normed_group.dist_eq _ _ @[simp] lemma norm_dist { g : G} : dist g 0 = ∥g∥ := by { rw[norm_dist'], simp } lemma norm_triangle (g h : G) : ∥g + h∥ ≤ ∥g∥ + ∥h∥ := calc ∥g + h∥ = ∥g - (-h)∥ : by simp ... = dist g (-h) : by simp[norm_dist'] ... ≤ dist g 0 + dist 0 (-h) : by apply dist_triangle ... = ∥g∥ + ∥h∥ : by simp[norm_dist'] @[simp] lemma norm_nonneg {g : G} : 0 ≤ ∥g∥ := by { rw[←norm_dist], exact dist_nonneg } lemma norm_zero_iff_zero {g : G} : ∥g∥ = 0 ↔ g = 0 := by { rw[←norm_dist], exact dist_eq_zero } @[simp] lemma zero_norm_zero : ∥(0:G)∥ = 0 := norm_zero_iff_zero.2 (by simp) lemma norm_pos_iff {g : G} : ∥ g ∥ > 0 ↔ g ≠ 0 := begin split ; intro h ; rw[←norm_dist] at *, { exact dist_pos.1 h }, { exact dist_pos.2 h } end lemma norm_le_zero_iff {g : G} : ∥g∥ ≤ 0 ↔ g = 0 := by { rw[←norm_dist], exact dist_le_zero } @[simp] lemma norm_neg {g : G} : ∥-g∥ = ∥g∥ := calc ∥-g∥ = ∥0 - g∥ : by simp ... = dist 0 g : norm_dist'.symm ... = dist g 0 : dist_comm _ _ ... = ∥g - 0∥ : norm_dist' ... = ∥g∥ : by simp lemma norm_triangle' (g h : G) : abs(∥g∥ - ∥h∥) ≤ ∥g - h∥ := begin have ng := calc ∥g∥ = ∥g - h + h∥ : by simp ... ≤ ∥g-h∥ + ∥h∥ : norm_triangle _ _, replace ng := sub_right_le_of_le_add ng, have nh := calc ∥h∥ = ∥h - g + g∥ : by simp ... ≤ ∥h - g∥ + ∥g∥ : norm_triangle _ _ ... = ∥-(g - h)∥ + ∥g∥ : by simp ... = ∥g - h∥ + ∥g∥ : by { rw [show ∥-(g - h)∥ = ∥g-h∥, from norm_neg] }, replace nh := sub_right_le_of_le_add nh, replace nh : -(∥g∥ - ∥h∥) ≤ ∥g - h∥ := by simpa using nh, replace nh : -∥g - h∥ ≤ ∥g∥ - ∥h∥ := by simpa using neg_le_neg nh, exact abs_le.2 ⟨nh, ng⟩ end instance prod.normed_group {F : Type*} [normed_group F] : normed_group (G × F) := { norm := λ x, max ∥x.1∥ ∥x.2∥, dist_eq := assume x y, by { simp, repeat {rw norm_dist'}, simp } } lemma norm_proj1_le (x : G × H) : ∥x.1∥ ≤ ∥x∥ := begin have : ∥x∥ = max (∥x.fst∥) ( ∥x.snd∥) := rfl, rw this, simp[le_max_left], end lemma norm_proj2_le (x : G × H) : ∥x.2∥ ≤ ∥x∥ := begin have : ∥x∥ = max (∥x.fst∥) ( ∥x.snd∥) := rfl, rw this, simp[le_max_right], end instance fintype.normed_group {ι : Type*} {α : ι → Type*} [fintype ι] [∀i, normed_group (α i)] : normed_group (Πb, α b) := { norm := λf, finset.maxi finset.univ (λ b, ∥f b∥), dist_eq := assume x y, by finish [norm_dist'] } lemma tendsto_iff_norm_tendsto_zero {f : G → H} {a : G} {b : H} : (f →_{a} b) ↔ ((λ e, ∥ f e - b ∥) →_{a} 0) := begin simp only [norm_dist'.symm], exact tendsto_iff_dist_tendsto_zero end lemma lim_norm (x: G) : ((λ g, ∥g-x∥) : G → ℝ) →_{x} 0 := begin apply tendsto_iff_norm_tendsto_zero.1, apply continuous_iff_tendsto.1, simp[show (λ e : G , e) = id, from rfl, continuous_id] end lemma lim_norm_zero : ((λ g, ∥g∥) : G → ℝ) →_{0} 0 := by simpa using lim_norm (0:G) lemma squeeze_zero {T : Type*} [metric_space T] (f g : T → ℝ) (t₀ : T) : (∀ t : T, 0 ≤ f t) → (∀ t : T, f t ≤ g t) → (g →_{t₀} 0) → (f →_{t₀} 0) := begin intros _ _ g0, apply tendsto_of_tendsto_of_tendsto_of_le_of_le (tendsto_const_nhds) g0; simp [*]; exact filter.univ_mem_sets end lemma norm_continuous {G : Type*} [normed_group G]: continuous ((λ g, ∥g∥) : G → ℝ) := begin apply continuous_iff_tendsto.2, intro x, have : (λ (g : G), dist ∥g∥ ∥x∥) →_{x} 0 := squeeze_zero (λ g, dist ∥g∥ ∥x∥) _ x (λ t, abs_nonneg _) (λ t, norm_triangle' _ _) (lim_norm x), exact tendsto_iff_dist_tendsto_zero.2 this end instance normed_top_monoid : topological_add_monoid G := ⟨begin apply continuous_iff_tendsto.2 _, intro x, apply tendsto_iff_norm_tendsto_zero.2, simp, have ineq := λ e: G × G, calc ∥e.fst + (e.snd + (-x.fst + -x.snd))∥ = ∥(e.fst-x.fst) + (e.snd - x.snd)∥ : by simp ... ≤ ∥e.fst - x.fst∥ + ∥ e.snd - x.snd ∥ : norm_triangle (e.fst-x.fst) (e.snd - x.snd), apply squeeze_zero _ _ x (by simp) ineq, have ineq1 : ∀ e : G × G, ∥ e.fst - x.fst∥ ≤ ∥e - x∥ := assume e, norm_proj1_le (e-x), have lim1 : (λ e : G × G, ∥ e.fst - x.fst∥) →_{x} 0 := squeeze_zero _ _ x (by simp) ineq1 _, clear ineq1, have ineq2 : ∀ e : G × G, ∥ e.snd - x.snd∥ ≤ ∥e - x∥ := assume e, norm_proj2_le (e-x), have lim2 : (λ e : G × G, ∥ e.snd - x.snd∥) →_{x} 0 := squeeze_zero _ _ x (by simp) ineq2 _, clear ineq2, have := tendsto_add lim1 lim2, simpa using this, exact lim_norm x, exact lim_norm x, end⟩ instance normed_top_group : topological_add_group G := { continuous_neg := begin apply continuous_iff_tendsto.2, intro x, apply tendsto_iff_norm_tendsto_zero.2, simp, have neg := λ (e : G), calc ∥ x + -e∥ = ∥ -(e -x)∥ : by simp ... = ∥e - x∥ : norm_neg, conv in _ {rw [neg]}, have lim_negx : (λ (e : G), -x )→_{x} -x:= tendsto_const_nhds, have lim_e : (λ (e : G), e )→_{x} x := continuous_iff_tendsto.1 continuous_id x, have := tendsto_add lim_negx lim_e, simp at this, simpa using filter.tendsto.comp this lim_norm_zero end } end normed_group section normed_ring class normed_ring (α : Type*) extends ring α, metric_space α := (norm : α → ℝ) (dist_eq : ∀ x y, dist x y = norm (x - y)) (norm_mul : ∀ a b, norm (a * b) ≤ norm a * norm b) variables {α : Type*} {β : Type*} instance normed_ring.to_normed_group [H : normed_ring α] : normed_group α := { ..H } lemma norm_mul {α : Type*} [normed_ring α] (a b : α) : (∥a*b∥) ≤ (∥a∥) * (∥b∥) := normed_ring.norm_mul _ _ instance prod.ring [ring α] [ring β] : ring (α × β) := { left_distrib := assume x y z, calc x*(y+z) = (x.1, x.2) * (y.1 + z.1, y.2 + z.2) : rfl ... = (x.1*(y.1 + z.1), x.2*(y.2 + z.2)) : rfl ... = (x.1*y.1 + x.1*z.1, x.2*y.2 + x.2*z.2) : by simp[left_distrib], right_distrib := assume x y z, calc (x+y)*z = (x.1 + y.1, x.2 + y.2)*(z.1, z.2) : rfl ... = ((x.1 + y.1)*z.1, (x.2 + y.2)*z.2) : rfl ... = (x.1*z.1 + y.1*z.1, x.2*z.2 + y.2*z.2) : by simp[right_distrib], ..prod.monoid, ..prod.add_comm_group} instance prod.normed_ring [normed_ring α] [normed_ring β] : normed_ring (α × β) := { norm_mul := assume x y, calc ∥x * y∥ = ∥(x.1*y.1, x.2*y.2)∥ : rfl ... = (max ∥x.1*y.1∥ ∥x.2*y.2∥) : rfl ... ≤ (max (∥x.1∥*∥y.1∥) (∥x.2∥*∥y.2∥)) : max_le_max (norm_mul (x.1) (y.1)) (norm_mul (x.2) (y.2)) ... = (max (∥x.1∥*∥y.1∥) (∥y.2∥*∥x.2∥)) : by simp[mul_comm] ... ≤ (max (∥x.1∥) (∥x.2∥)) * (max (∥y.2∥) (∥y.1∥)) : by { apply max_mul_mul_le_max_mul_max; simp [norm_nonneg] } ... = (max (∥x.1∥) (∥x.2∥)) * (max (∥y.1∥) (∥y.2∥)) : by simp[max_comm] ... = (∥x∥*∥y∥) : rfl, ..prod.normed_group } /- instance fintype.normed_ring {ι : Type*} {α : ι → Type*} [fintype ι] [∀i, normed_ring (α i)] : normed_ring (Πb, α b) := { norm_mul := assume x y, begin sorry end, ..fintype.normed_group } -/ end normed_ring section normed_field variables {α : Type*} class normed_field (α : Type*) extends discrete_field α, metric_space α := (norm : α → ℝ) (dist_eq : ∀ x y, dist x y = norm (x - y)) (norm_mul : ∀ a b, norm (a * b) = norm a * norm b) instance normed_field.to_normed_ring [H : normed_field α] : normed_ring α := { norm_mul := by finish[H.norm_mul], ..H } instance : normed_field ℝ := { norm := λ x, abs x, dist_eq := assume x y, rfl, norm_mul := abs_mul} end normed_field section normed_space class normed_space (α : out_param $ Type*) (β : Type*) [out_param $ normed_field α] extends vector_space α β, metric_space β := (norm : β → ℝ) (dist_eq : ∀ x y, dist x y = norm (x - y)) (norm_smul : ∀ a b, norm (a • b) = normed_field.norm a * norm b) variables {α : Type*} [normed_field α] {β : Type*} instance normed_space.to_normed_group [H : normed_space α β] : normed_group β := by refine { add := (+), dist_eq := normed_space.dist_eq, zero := 0, neg := λ x, -x, ..H, .. }; simp variable [normed_space α β] lemma norm_smul (s : α) (x : β) : ∥s • x∥ = ∥s∥ * ∥x∥ := normed_space.norm_smul _ _ variables {E : Type*} {F : Type*} [normed_space α E] [normed_space α F] lemma tendsto_smul {f : E → α} { g : E → F} {e : E} {s : α} {b : F} : (f →_{e} s) → (g →_{e} b) → ((λ e, (f e) • (g e)) →_{e} s • b) := begin intros limf limg, apply tendsto_iff_norm_tendsto_zero.2, have ineq := λ x : E, calc ∥f x • g x - s • b∥ = ∥(f x • g x - s • g x) + (s • g x - s • b)∥ : by simp[add_assoc] ... ≤ ∥f x • g x - s • g x∥ + ∥s • g x - s • b∥ : norm_triangle (f x • g x - s • g x) (s • g x - s • b) ... ≤ ∥f x - s∥*∥g x∥ + ∥s∥*∥g x - b∥ : by { rw [←smul_sub, ←sub_smul, norm_smul, norm_smul] }, apply squeeze_zero, { intro t, exact norm_nonneg }, { exact ineq }, { clear ineq, have limf': (λ (x : E), ∥f x - s∥)→_{e}0 := tendsto_iff_norm_tendsto_zero.1 limf, have limg' := filter.tendsto.comp limg (continuous_iff_tendsto.1 norm_continuous _), have limg'' : (λ (x : E), ∥g x∥)→_{e} ∥b∥, simp[limg'], clear limg', have lim1 := tendsto_mul limf' limg'', simp at lim1, have limg3 := tendsto_iff_norm_tendsto_zero.1 limg, have lim2 := tendsto_mul tendsto_const_nhds limg3, swap, exact ∥s∥, simp at lim2, have := tendsto_add lim1 lim2, rw [show (0:ℝ) + 0 = 0, by simp] at this, exact this } end /- Do we want the following? I have difficulties with instances to set it up class topological_vector_space (E : Type*) [topological_space E] [vector_space α E] extends topological_add_group E : Prop := (continuous_smul : continuous (λ x : α×E, x.1• x.2)) -/ instance product_normed_space : normed_space α (E × F) := { norm_smul := begin intros s x, cases x with x₁ x₂, exact calc ∥s • (x₁, x₂)∥ = ∥ (s • x₁, s• x₂)∥ : rfl ... = max (∥s • x₁∥) (∥ s• x₂∥) : rfl ... = max (∥s∥ * ∥x₁∥) (∥s∥ * ∥x₂∥) : by simp[norm_smul s x₁, norm_smul s x₂] ... = ∥s∥ * max (∥x₁∥) (∥x₂∥) : by simp[mul_max_of_nonneg] end, add_smul := by simp[add_smul], -- I have no idea why by simp[smul_add] is not enough for the next goal smul_add := assume r x y, show (r•(x+y).fst, r•(x+y).snd) = (r•x.fst+r•y.fst, r•x.snd+r•y.snd), by simp[smul_add], ..prod.normed_group, ..prod.vector_space } set_option trace.class_instances true example {ι : Type*} {E : ι → Type*} [fintype ι] [∀i, vector_space α (E i)] : vector_space α (Πi, E i) := by apply_instance instance fintype.normed_space {ι : Type*} {E : ι → Type*} [fintype ι] [∀i, normed_space α (E i)] : normed_space α (Πi, E i) := { norm_smul := λ s x, begin sorry end, ..fintype.normed_group, } end normed_space
72f966bb5c5bb15214613e7ff29f1600106d44d4
7cef822f3b952965621309e88eadf618da0c8ae9
/src/topology/metric_space/closeds.lean
1bfc5f88f691e101bef8434d1b77b791b6a726f5
[ "Apache-2.0" ]
permissive
rmitta/mathlib
8d90aee30b4db2b013e01f62c33f297d7e64a43d
883d974b608845bad30ae19e27e33c285200bf84
refs/heads/master
1,585,776,832,544
1,576,874,096,000
1,576,874,096,000
153,663,165
0
2
Apache-2.0
1,544,806,490,000
1,539,884,365,000
Lean
UTF-8
Lean
false
false
22,426
lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Sébastien Gouëzel -/ import topology.metric_space.hausdorff_distance topology.opens /-! # Closed subsets This file defines the metric and emetric space structure on the types of closed subsets and nonempty compact subsets of a metric or emetric space. The Hausdorff distance induces an emetric space structure on the type of closed subsets of an emetric space, called `closeds`. Its completeness, resp. compactness, resp. second-countability, follow from the corresponding properties of the original space. In a metric space, the type of nonempty compact subsets (called `nonempty_compacts`) also inherits a metric space structure from the Hausdorff distance, as the Hausdorff edistance is always finite in this context. -/ noncomputable theory open_locale classical open_locale topological_space universe u open classical lattice set function topological_space filter namespace emetric section variables {α : Type u} [emetric_space α] {s : set α} /-- In emetric spaces, the Hausdorff edistance defines an emetric space structure on the type of closed subsets -/ instance closeds.emetric_space : emetric_space (closeds α) := { edist := λs t, Hausdorff_edist s.val t.val, edist_self := λs, Hausdorff_edist_self, edist_comm := λs t, Hausdorff_edist_comm, edist_triangle := λs t u, Hausdorff_edist_triangle, eq_of_edist_eq_zero := λs t h, subtype.eq ((Hausdorff_edist_zero_iff_eq_of_closed s.property t.property).1 h) } /-- The edistance to a closed set depends continuously on the point and the set -/ lemma continuous_inf_edist_Hausdorff_edist : continuous (λp : α × (closeds α), inf_edist p.1 (p.2).val) := begin refine continuous_of_le_add_edist 2 (by simp) _, rintros ⟨x, s⟩ ⟨y, t⟩, calc inf_edist x (s.val) ≤ inf_edist x (t.val) + Hausdorff_edist (t.val) (s.val) : inf_edist_le_inf_edist_add_Hausdorff_edist ... ≤ (inf_edist y (t.val) + edist x y) + Hausdorff_edist (t.val) (s.val) : add_le_add_right' inf_edist_le_inf_edist_add_edist ... = inf_edist y (t.val) + (edist x y + Hausdorff_edist (s.val) (t.val)) : by simp [add_comm, Hausdorff_edist_comm] ... ≤ inf_edist y (t.val) + (edist (x, s) (y, t) + edist (x, s) (y, t)) : add_le_add_left' (add_le_add' (by simp [edist, le_refl]) (by simp [edist, le_refl])) ... = inf_edist y (t.val) + 2 * edist (x, s) (y, t) : by rw [← mul_two, mul_comm] end /-- Subsets of a given closed subset form a closed set -/ lemma is_closed_subsets_of_is_closed (hs : is_closed s) : is_closed {t : closeds α | t.val ⊆ s} := begin refine is_closed_of_closure_subset (λt ht x hx, _), -- t : closeds α, ht : t ∈ closure {t : closeds α | t.val ⊆ s}, -- x : α, hx : x ∈ t.val -- goal : x ∈ s have : x ∈ closure s, { refine mem_closure_iff'.2 (λε εpos, _), rcases mem_closure_iff'.1 ht ε εpos with ⟨u, hu, Dtu⟩, -- u : closeds α, hu : u ∈ {t : closeds α | t.val ⊆ s}, hu' : edist t u < ε rcases exists_edist_lt_of_Hausdorff_edist_lt hx Dtu with ⟨y, hy, Dxy⟩, -- y : α, hy : y ∈ u.val, Dxy : edist x y < ε exact ⟨y, hu hy, Dxy⟩ }, rwa closure_eq_of_is_closed hs at this, end /-- By definition, the edistance on `closeds α` is given by the Hausdorff edistance -/ lemma closeds.edist_eq {s t : closeds α} : edist s t = Hausdorff_edist s.val t.val := rfl /-- In a complete space, the type of closed subsets is complete for the Hausdorff edistance. -/ instance closeds.complete_space [complete_space α] : complete_space (closeds α) := begin /- We will show that, if a sequence of sets `s n` satisfies `edist (s n) (s (n+1)) < 2^{-n}`, then it converges. This is enough to guarantee completeness, by a standard completeness criterion. We use the shorthand `B n = 2^{-n}` in ennreal. -/ let B : ℕ → ennreal := λ n, (2⁻¹)^n, have B_pos : ∀ n, (0:ennreal) < B n, by simp [B, ennreal.pow_pos], have B_ne_top : ∀ n, B n ≠ ⊤, by simp [B, ennreal.div_def, ennreal.pow_ne_top], /- Consider a sequence of closed sets `s n` with `edist (s n) (s (n+1)) < B n`. We will show that it converges. The limit set is t0 = ⋂n, closure (⋃m≥n, s m). We will have to show that a point in `s n` is close to a point in `t0`, and a point in `t0` is close to a point in `s n`. The completeness then follows from a standard criterion. -/ refine complete_of_convergent_controlled_sequences B B_pos (λs hs, _), let t0 := ⋂n, closure (⋃m≥n, (s m).val), let t : closeds α := ⟨t0, is_closed_Inter (λ_, is_closed_closure)⟩, use t, -- The inequality is written this way to agree with `edist_le_of_edist_le_geometric_of_tendsto₀` have I1 : ∀n:ℕ, ∀x ∈ (s n).val, ∃y ∈ t0, edist x y ≤ 2 * B n, { /- This is the main difficulty of the proof. Starting from `x ∈ s n`, we want to find a point in `t0` which is close to `x`. Define inductively a sequence of points `z m` with `z n = x` and `z m ∈ s m` and `edist (z m) (z (m+1)) ≤ B m`. This is possible since the Hausdorff distance between `s m` and `s (m+1)` is at most `B m`. This sequence is a Cauchy sequence, therefore converging as the space is complete, to a limit which satisfies the required properties. -/ assume n x hx, obtain ⟨z, hz₀, hz⟩ : ∃ z : Π l, (s (n+l)).val, (z 0:α) = x ∧ ∀ k, edist (z k:α) (z (k+1):α) ≤ B n / 2^k, { -- We prove existence of the sequence by induction. have : ∀ (l : ℕ) (z : (s (n+l)).val), ∃ z' : (s (n+l+1)).val, edist (z:α) z' ≤ B n / 2^l, { assume l z, obtain ⟨z', z'_mem, hz'⟩ : ∃ z' ∈ (s (n+l+1)).val, edist (z:α) z' < B n / 2^l, { apply exists_edist_lt_of_Hausdorff_edist_lt z.2, simp only [B, ennreal.div_def, ennreal.inv_pow'], rw [← pow_add], apply hs; simp }, exact ⟨⟨z', z'_mem⟩, le_of_lt hz'⟩ }, use [λ k, nat.rec_on k ⟨x, hx⟩ (λl z, some (this l z)), rfl], exact λ k, some_spec (this k _) }, -- it follows from the previous bound that `z` is a Cauchy sequence have : cauchy_seq (λ k, ((z k):α)), from cauchy_seq_of_edist_le_geometric_two (B n) (B_ne_top n) hz, -- therefore, it converges rcases cauchy_seq_tendsto_of_complete this with ⟨y, y_lim⟩, use y, -- the limit point `y` will be the desired point, in `t0` and close to our initial point `x`. -- First, we check it belongs to `t0`. have : y ∈ t0 := mem_Inter.2 (λk, mem_closure_of_tendsto (by simp) y_lim begin simp only [exists_prop, set.mem_Union, filter.mem_at_top_sets, set.mem_preimage, set.preimage_Union], exact ⟨k, λ m hm, ⟨n+m, zero_add k ▸ add_le_add (zero_le n) hm, (z m).2⟩⟩ end), use this, -- Then, we check that `y` is close to `x = z n`. This follows from the fact that `y` -- is the limit of `z k`, and the distance between `z n` and `z k` has already been estimated. rw [← hz₀], exact edist_le_of_edist_le_geometric_two_of_tendsto₀ (B n) hz y_lim }, have I2 : ∀n:ℕ, ∀x ∈ t0, ∃y ∈ (s n).val, edist x y ≤ 2 * B n, { /- For the (much easier) reverse inequality, we start from a point `x ∈ t0` and we want to find a point `y ∈ s n` which is close to `x`. `x` belongs to `t0`, the intersection of the closures. In particular, it is well approximated by a point `z` in `⋃m≥n, s m`, say in `s m`. Since `s m` and `s n` are close, this point is itself well approximated by a point `y` in `s n`, as required. -/ assume n x xt0, have : x ∈ closure (⋃m≥n, (s m).val), by apply mem_Inter.1 xt0 n, rcases mem_closure_iff'.1 this (B n) (B_pos n) with ⟨z, hz, Dxz⟩, -- z : α, Dxz : edist x z < B n, simp only [exists_prop, set.mem_Union] at hz, rcases hz with ⟨m, ⟨m_ge_n, hm⟩⟩, -- m : ℕ, m_ge_n : m ≥ n, hm : z ∈ (s m).val have : Hausdorff_edist (s m).val (s n).val < B n := hs n m n m_ge_n (le_refl n), rcases exists_edist_lt_of_Hausdorff_edist_lt hm this with ⟨y, hy, Dzy⟩, -- y : α, hy : y ∈ (s n).val, Dzy : edist z y < B n exact ⟨y, hy, calc edist x y ≤ edist x z + edist z y : edist_triangle _ _ _ ... ≤ B n + B n : add_le_add' (le_of_lt Dxz) (le_of_lt Dzy) ... = 2 * B n : (two_mul _).symm ⟩ }, -- Deduce from the above inequalities that the distance between `s n` and `t0` is at most `2 B n`. have main : ∀n:ℕ, edist (s n) t ≤ 2 * B n := λn, Hausdorff_edist_le_of_mem_edist (I1 n) (I2 n), -- from this, the convergence of `s n` to `t0` follows. refine (tendsto_at_top _).2 (λε εpos, _), have : tendsto (λn, 2 * B n) at_top (𝓝 (2 * 0)), from ennreal.tendsto.mul_right (ennreal.tendsto_pow_at_top_nhds_0_of_lt_1 $ by simp [ennreal.one_lt_two]) (or.inr $ by simp), rw mul_zero at this, have Z := (tendsto_orderable.1 this).2 ε εpos, simp only [filter.mem_at_top_sets, set.mem_set_of_eq] at Z, rcases Z with ⟨N, hN⟩, -- ∀ (b : ℕ), b ≥ N → ε > 2 * B b exact ⟨N, λn hn, lt_of_le_of_lt (main n) (hN n hn)⟩ end /-- In a compact space, the type of closed subsets is compact. -/ instance closeds.compact_space [compact_space α] : compact_space (closeds α) := ⟨begin /- by completeness, it suffices to show that it is totally bounded, i.e., for all ε>0, there is a finite set which is ε-dense. start from a set `s` which is ε-dense in α. Then the subsets of `s` are finitely many, and ε-dense for the Hausdorff distance. -/ refine compact_of_totally_bounded_is_closed (emetric.totally_bounded_iff.2 (λε εpos, _)) is_closed_univ, rcases dense εpos with ⟨δ, δpos, δlt⟩, rcases emetric.totally_bounded_iff.1 (compact_iff_totally_bounded_complete.1 (@compact_univ α _ _)).1 δ δpos with ⟨s, fs, hs⟩, -- s : set α, fs : finite s, hs : univ ⊆ ⋃ (y : α) (H : y ∈ s), eball y δ -- we first show that any set is well approximated by a subset of `s`. have main : ∀ u : set α, ∃v ⊆ s, Hausdorff_edist u v ≤ δ, { assume u, let v := {x : α | x ∈ s ∧ ∃y∈u, edist x y < δ}, existsi [v, ((λx hx, hx.1) : v ⊆ s)], refine Hausdorff_edist_le_of_mem_edist _ _, { assume x hx, have : x ∈ ⋃y ∈ s, ball y δ := hs (by simp), rcases mem_bUnion_iff.1 this with ⟨y, ⟨ys, dy⟩⟩, have : edist y x < δ := by simp at dy; rwa [edist_comm] at dy, exact ⟨y, ⟨ys, ⟨x, hx, this⟩⟩, le_of_lt dy⟩ }, { rintros x ⟨hx1, ⟨y, yu, hy⟩⟩, exact ⟨y, yu, le_of_lt hy⟩ }}, -- introduce the set F of all subsets of `s` (seen as members of `closeds α`). let F := {f : closeds α | f.val ⊆ s}, use F, split, -- `F` is finite { apply @finite_of_finite_image _ _ F (λf, f.val), { apply set.inj_on_of_injective, simp [subtype.val_injective] }, { refine finite_subset (finite_subsets_of_finite fs) (λb, _), simp only [and_imp, set.mem_image, set.mem_set_of_eq, exists_imp_distrib], assume x hx hx', rwa hx' at hx }}, -- `F` is ε-dense { assume u _, rcases main u.val with ⟨t0, t0s, Dut0⟩, have : is_closed t0 := closed_of_compact _ (finite_subset fs t0s).compact, let t : closeds α := ⟨t0, this⟩, have : t ∈ F := t0s, have : edist u t < ε := lt_of_le_of_lt Dut0 δlt, apply mem_bUnion_iff.2, exact ⟨t, ‹t ∈ F›, this⟩ } end⟩ /-- In an emetric space, the type of non-empty compact subsets is an emetric space, where the edistance is the Hausdorff edistance -/ instance nonempty_compacts.emetric_space : emetric_space (nonempty_compacts α) := { edist := λs t, Hausdorff_edist s.val t.val, edist_self := λs, Hausdorff_edist_self, edist_comm := λs t, Hausdorff_edist_comm, edist_triangle := λs t u, Hausdorff_edist_triangle, eq_of_edist_eq_zero := λs t h, subtype.eq $ begin have : closure (s.val) = closure (t.val) := Hausdorff_edist_zero_iff_closure_eq_closure.1 h, rwa [closure_eq_iff_is_closed.2 (closed_of_compact _ s.property.2), closure_eq_iff_is_closed.2 (closed_of_compact _ t.property.2)] at this, end } /-- `nonempty_compacts.to_closeds` is a uniform embedding (as it is an isometry) -/ lemma nonempty_compacts.to_closeds.uniform_embedding : uniform_embedding (@nonempty_compacts.to_closeds α _ _) := isometry.uniform_embedding $ λx y, rfl /-- The range of `nonempty_compacts.to_closeds` is closed in a complete space -/ lemma nonempty_compacts.is_closed_in_closeds [complete_space α] : is_closed (nonempty_compacts.to_closeds '' (univ : set (nonempty_compacts α))) := begin have : nonempty_compacts.to_closeds '' univ = {s : closeds α | s.val ≠ ∅ ∧ compact s.val}, { ext, simp only [set.image_univ, set.mem_range, ne.def, set.mem_set_of_eq], split, { rintros ⟨y, hy⟩, have : x.val = y.val := by rcases hy; simp, rw this, exact y.property }, { rintros ⟨hx1, hx2⟩, existsi (⟨x.val, ⟨hx1, hx2⟩⟩ : nonempty_compacts α), apply subtype.eq, refl }}, rw this, refine is_closed_of_closure_subset (λs hs, _), split, { -- take a set set t which is nonempty and at distance at most 1 of s rcases mem_closure_iff'.1 hs 1 ennreal.zero_lt_one with ⟨t, ht, Dst⟩, rw edist_comm at Dst, -- this set t contains a point x rcases ne_empty_iff_exists_mem.1 ht.1 with ⟨x, hx⟩, -- by the Hausdorff distance control, this point x is at distance at most 1 -- of a point y in s rcases exists_edist_lt_of_Hausdorff_edist_lt hx Dst with ⟨y, hy, _⟩, -- this shows that s is not empty exact ne_empty_of_mem hy }, { refine compact_iff_totally_bounded_complete.2 ⟨_, is_complete_of_is_closed s.property⟩, refine totally_bounded_iff.2 (λε εpos, _), -- we have to show that s is covered by finitely many eballs of radius ε -- pick a nonempty compact set t at distance at most ε/2 of s rcases mem_closure_iff'.1 hs (ε/2) (ennreal.half_pos εpos) with ⟨t, ht, Dst⟩, -- cover this space with finitely many balls of radius ε/2 rcases totally_bounded_iff.1 (compact_iff_totally_bounded_complete.1 ht.2).1 (ε/2) (ennreal.half_pos εpos) with ⟨u, fu, ut⟩, refine ⟨u, ⟨fu, λx hx, _⟩⟩, -- u : set α, fu : finite u, ut : t.val ⊆ ⋃ (y : α) (H : y ∈ u), eball y (ε / 2) -- then s is covered by the union of the balls centered at u of radius ε rcases exists_edist_lt_of_Hausdorff_edist_lt hx Dst with ⟨z, hz, Dxz⟩, rcases mem_bUnion_iff.1 (ut hz) with ⟨y, hy, Dzy⟩, have : edist x y < ε := calc edist x y ≤ edist x z + edist z y : edist_triangle _ _ _ ... < ε/2 + ε/2 : ennreal.add_lt_add Dxz Dzy ... = ε : ennreal.add_halves _, exact mem_bUnion hy this }, end /-- In a complete space, the type of nonempty compact subsets is complete. This follows from the same statement for closed subsets -/ instance nonempty_compacts.complete_space [complete_space α] : complete_space (nonempty_compacts α) := begin apply complete_space_of_is_complete_univ, apply (is_complete_image_iff nonempty_compacts.to_closeds.uniform_embedding).1, apply is_complete_of_is_closed, exact nonempty_compacts.is_closed_in_closeds end /-- In a compact space, the type of nonempty compact subsets is compact. This follows from the same statement for closed subsets -/ instance nonempty_compacts.compact_space [compact_space α] : compact_space (nonempty_compacts α) := ⟨begin rw embedding.compact_iff_compact_image nonempty_compacts.to_closeds.uniform_embedding.embedding, exact nonempty_compacts.is_closed_in_closeds.compact end⟩ /-- In a second countable space, the type of nonempty compact subsets is second countable -/ instance nonempty_compacts.second_countable_topology [second_countable_topology α] : second_countable_topology (nonempty_compacts α) := begin haveI : separable_space (nonempty_compacts α) := begin /- To obtain a countable dense subset of `nonempty_compacts α`, start from a countable dense subset `s` of α, and then consider all its finite nonempty subsets. This set is countable and made of nonempty compact sets. It turns out to be dense: by total boundedness, any compact set `t` can be covered by finitely many small balls, and approximations in `s` of the centers of these balls give the required finite approximation of `t`. -/ have : separable_space α := by apply_instance, rcases this.exists_countable_closure_eq_univ with ⟨s, cs, s_dense⟩, let v0 := {t : set α | finite t ∧ t ⊆ s}, let v : set (nonempty_compacts α) := {t : nonempty_compacts α | t.val ∈ v0}, refine ⟨⟨v, ⟨_, _⟩⟩⟩, { have : countable (subtype.val '' v), { refine countable_subset (λx hx, _) (countable_set_of_finite_subset cs), rcases (mem_image _ _ _).1 hx with ⟨y, ⟨hy, yx⟩⟩, rw ← yx, exact hy }, apply countable_of_injective_of_countable_image _ this, apply inj_on_of_inj_on_of_subset (injective_iff_inj_on_univ.1 subtype.val_injective) (subset_univ _) }, { refine subset.antisymm (subset_univ _) (λt ht, mem_closure_iff'.2 (λε εpos, _)), -- t is a compact nonempty set, that we have to approximate uniformly by a a set in `v`. rcases dense εpos with ⟨δ, δpos, δlt⟩, -- construct a map F associating to a point in α an approximating point in s, up to δ/2. have Exy : ∀x, ∃y, y ∈ s ∧ edist x y < δ/2, { assume x, have : x ∈ closure s := by rw s_dense; exact mem_univ _, rcases mem_closure_iff'.1 this (δ/2) (ennreal.half_pos δpos) with ⟨y, ys, hy⟩, exact ⟨y, ⟨ys, hy⟩⟩ }, let F := λx, some (Exy x), have Fspec : ∀x, F x ∈ s ∧ edist x (F x) < δ/2 := λx, some_spec (Exy x), -- cover `t` with finitely many balls. Their centers form a set `a` have : totally_bounded t.val := (compact_iff_totally_bounded_complete.1 t.property.2).1, rcases totally_bounded_iff.1 this (δ/2) (ennreal.half_pos δpos) with ⟨a, af, ta⟩, -- a : set α, af : finite a, ta : t.val ⊆ ⋃ (y : α) (H : y ∈ a), eball y (δ / 2) -- replace each center by a nearby approximation in `s`, giving a new set `b` let b := F '' a, have : finite b := finite_image _ af, have tb : ∀x ∈ t.val, ∃y ∈ b, edist x y < δ, { assume x hx, rcases mem_bUnion_iff.1 (ta hx) with ⟨z, za, Dxz⟩, existsi [F z, mem_image_of_mem _ za], calc edist x (F z) ≤ edist x z + edist z (F z) : edist_triangle _ _ _ ... < δ/2 + δ/2 : ennreal.add_lt_add Dxz (Fspec z).2 ... = δ : ennreal.add_halves _ }, -- keep only the points in `b` that are close to point in `t`, yielding a new set `c` let c := {y ∈ b | ∃x∈t.val, edist x y < δ}, have : finite c := finite_subset ‹finite b› (λx hx, hx.1), -- points in `t` are well approximated by points in `c` have tc : ∀x ∈ t.val, ∃y ∈ c, edist x y ≤ δ, { assume x hx, rcases tb x hx with ⟨y, yv, Dxy⟩, have : y ∈ c := by simp [c, -mem_image]; exact ⟨yv, ⟨x, hx, Dxy⟩⟩, exact ⟨y, this, le_of_lt Dxy⟩ }, -- points in `c` are well approximated by points in `t` have ct : ∀y ∈ c, ∃x ∈ t.val, edist y x ≤ δ, { rintros y ⟨hy1, ⟨x, xt, Dyx⟩⟩, have : edist y x ≤ δ := calc edist y x = edist x y : edist_comm _ _ ... ≤ δ : le_of_lt Dyx, exact ⟨x, xt, this⟩ }, -- it follows that their Hausdorff distance is small have : Hausdorff_edist t.val c ≤ δ := Hausdorff_edist_le_of_mem_edist tc ct, have Dtc : Hausdorff_edist t.val c < ε := lt_of_le_of_lt this δlt, -- the set `c` is not empty, as it is well approximated by a nonempty set have : c ≠ ∅, { by_contradiction h, simp only [not_not, ne.def] at h, rw [h, Hausdorff_edist_empty t.property.1] at Dtc, exact not_top_lt Dtc }, -- let `d` be the version of `c` in the type `nonempty_compacts α` let d : nonempty_compacts α := ⟨c, ⟨‹c ≠ ∅›, ‹finite c›.compact⟩⟩, have : c ⊆ s, { assume x hx, rcases (mem_image _ _ _).1 hx.1 with ⟨y, ⟨ya, yx⟩⟩, rw ← yx, exact (Fspec y).1 }, have : d ∈ v := ⟨‹finite c›, this⟩, -- we have proved that `d` is a good approximation of `t` as requested exact ⟨d, ‹d ∈ v›, Dtc⟩ }, end, apply second_countable_of_separable, end end --section end emetric --namespace namespace metric section variables {α : Type u} [metric_space α] /-- `nonempty_compacts α` inherits a metric space structure, as the Hausdorff edistance between two such sets is finite. -/ instance nonempty_compacts.metric_space : metric_space (nonempty_compacts α) := emetric_space.to_metric_space $ λx y, Hausdorff_edist_ne_top_of_ne_empty_of_bounded x.2.1 y.2.1 (bounded_of_compact x.2.2) (bounded_of_compact y.2.2) /-- The distance on `nonempty_compacts α` is the Hausdorff distance, by construction -/ lemma nonempty_compacts.dist_eq {x y : nonempty_compacts α} : dist x y = Hausdorff_dist x.val y.val := rfl lemma lipschitz_inf_dist_set (x : α) : lipschitz_with 1 (λ s : nonempty_compacts α, inf_dist x s.val) := lipschitz_with.one_of_le_add $ assume s t, by { rw dist_comm, exact inf_dist_le_inf_dist_add_Hausdorff_dist (edist_ne_top t s) } lemma lipschitz_inf_dist : lipschitz_with 2 (λ p : α × (nonempty_compacts α), inf_dist p.1 p.2.val) := @lipschitz_with.uncurry' _ _ _ _ _ _ (λ (x : α) (s : nonempty_compacts α), inf_dist x s.val) 1 1 (λ s, lipschitz_inf_dist_pt s.val) lipschitz_inf_dist_set lemma uniform_continuous_inf_dist_Hausdorff_dist : uniform_continuous (λp : α × (nonempty_compacts α), inf_dist p.1 (p.2).val) := lipschitz_inf_dist.to_uniform_continuous end --section end metric --namespace
56110f789e3a86361125464b81b4d09ad0a1b6d7
4727251e0cd73359b15b664c3170e5d754078599
/src/order/monovary.lean
e9f9d840555e4cf552bb2415e447df4bfc8bf81b
[ "Apache-2.0" ]
permissive
Vierkantor/mathlib
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
refs/heads/master
1,658,323,012,449
1,652,256,003,000
1,652,256,003,000
209,296,341
0
1
Apache-2.0
1,568,807,655,000
1,568,807,655,000
null
UTF-8
Lean
false
false
11,192
lean
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import data.set.basic /-! # Monovariance of functions Two functions *vary together* if a strict change in the first implies a change in the second. This is in some sense a way to say that two functions `f : ι → α`, `g : ι → β` are "monotone together", without actually having an order on `ι`. This condition comes up in the rearrangement inequality. See `algebra.order.rearrangement`. ## Main declarations * `monovary f g`: `f` monovaries with `g`. If `g i < g j`, then `f i ≤ f j`. * `antivary f g`: `f` antivaries with `g`. If `g i < g j`, then `f j ≤ f i`. * `monovary_on f g s`: `f` monovaries with `g` on `s`. * `monovary_on f g s`: `f` antivaries with `g` on `s`. -/ open function set variables {ι ι' α β γ : Type*} section preorder variables [preorder α] [preorder β] [preorder γ] {f : ι → α} {f' : α → γ} {g : ι → β} {g' : β → γ} {s t : set ι} /-- `f` monovaries with `g` if `g i < g j` implies `f i ≤ f j`. -/ def monovary (f : ι → α) (g : ι → β) : Prop := ∀ ⦃i j⦄, g i < g j → f i ≤ f j /-- `f` antivaries with `g` if `g i < g j` implies `f j ≤ f i`. -/ def antivary (f : ι → α) (g : ι → β) : Prop := ∀ ⦃i j⦄, g i < g j → f j ≤ f i /-- `f` monovaries with `g` on `s` if `g i < g j` implies `f i ≤ f j` for all `i, j ∈ s`. -/ def monovary_on (f : ι → α) (g : ι → β) (s : set ι) : Prop := ∀ ⦃i⦄ (hi : i ∈ s) ⦃j⦄ (hj : j ∈ s), g i < g j → f i ≤ f j /-- `f` antivaries with `g` on `s` if `g i < g j` implies `f j ≤ f i` for all `i, j ∈ s`. -/ def antivary_on (f : ι → α) (g : ι → β) (s : set ι) : Prop := ∀ ⦃i⦄ (hi : i ∈ s) ⦃j⦄ (hj : j ∈ s), g i < g j → f j ≤ f i protected lemma monovary.monovary_on (h : monovary f g) (s : set ι) : monovary_on f g s := λ i _ j _ hij, h hij protected lemma antivary.antivary_on (h : antivary f g) (s : set ι) : antivary_on f g s := λ i _ j _ hij, h hij @[simp] lemma monovary_on.empty : monovary_on f g ∅ := λ i, false.elim @[simp] lemma antivary_on.empty : antivary_on f g ∅ := λ i, false.elim @[simp] lemma monovary_on_univ : monovary_on f g univ ↔ monovary f g := ⟨λ h i j, h trivial trivial, λ h i _ j _ hij, h hij⟩ @[simp] lemma antivary_on_univ : antivary_on f g univ ↔ antivary f g := ⟨λ h i j, h trivial trivial, λ h i _ j _ hij, h hij⟩ protected lemma monovary_on.subset (hst : s ⊆ t) (h : monovary_on f g t) : monovary_on f g s := λ i hi j hj, h (hst hi) (hst hj) protected lemma antivary_on.subset (hst : s ⊆ t) (h : antivary_on f g t) : antivary_on f g s := λ i hi j hj, h (hst hi) (hst hj) lemma monovary_const_left (g : ι → β) (a : α) : monovary (const ι a) g := λ i j _, le_rfl lemma antivary_const_left (g : ι → β) (a : α) : antivary (const ι a) g := λ i j _, le_rfl lemma monovary_const_right (f : ι → α) (b : β) : monovary f (const ι b) := λ i j h, (h.ne rfl).elim lemma antivary_const_right (f : ι → α) (b : β) : antivary f (const ι b) := λ i j h, (h.ne rfl).elim lemma monovary_self (f : ι → α) : monovary f f := λ i j, le_of_lt lemma monovary_on_self (f : ι → α) (s : set ι) : monovary_on f f s := λ i _ j _, le_of_lt protected lemma subsingleton.monovary [subsingleton ι] (f : ι → α) (g : ι → β) : monovary f g := λ i j h, (ne_of_apply_ne _ h.ne $ subsingleton.elim _ _).elim protected lemma subsingleton.antivary [subsingleton ι] (f : ι → α) (g : ι → β) : antivary f g := λ i j h, (ne_of_apply_ne _ h.ne $ subsingleton.elim _ _).elim protected lemma subsingleton.monovary_on [subsingleton ι] (f : ι → α) (g : ι → β) (s : set ι) : monovary_on f g s := λ i _ j _ h, (ne_of_apply_ne _ h.ne $ subsingleton.elim _ _).elim protected lemma subsingleton.antivary_on [subsingleton ι] (f : ι → α) (g : ι → β) (s : set ι) : antivary_on f g s := λ i _ j _ h, (ne_of_apply_ne _ h.ne $ subsingleton.elim _ _).elim lemma monovary_on_const_left (g : ι → β) (a : α) (s : set ι) : monovary_on (const ι a) g s := λ i _ j _ _, le_rfl lemma antivary_on_const_left (g : ι → β) (a : α) (s : set ι) : antivary_on (const ι a) g s := λ i _ j _ _, le_rfl lemma monovary_on_const_right (f : ι → α) (b : β) (s : set ι) : monovary_on f (const ι b) s := λ i _ j _ h, (h.ne rfl).elim lemma antivary_on_const_right (f : ι → α) (b : β) (s : set ι) : antivary_on f (const ι b) s := λ i _ j _ h, (h.ne rfl).elim lemma monovary.comp_right (h : monovary f g) (k : ι' → ι) : monovary (f ∘ k) (g ∘ k) := λ i j hij, h hij lemma antivary.comp_right (h : antivary f g) (k : ι' → ι) : antivary (f ∘ k) (g ∘ k) := λ i j hij, h hij lemma monovary_on.comp_right (h : monovary_on f g s) (k : ι' → ι) : monovary_on (f ∘ k) (g ∘ k) (k ⁻¹' s) := λ i hi j hj, h hi hj lemma antivary_on.comp_right (h : antivary_on f g s) (k : ι' → ι) : antivary_on (f ∘ k) (g ∘ k) (k ⁻¹' s) := λ i hi j hj, h hi hj lemma monovary.comp_monotone_left (h : monovary f g) (hf : monotone f') : monovary (f' ∘ f) g := λ i j hij, hf $ h hij lemma monovary.comp_antitone_left (h : monovary f g) (hf : antitone f') : antivary (f' ∘ f) g := λ i j hij, hf $ h hij lemma antivary.comp_monotone_left (h : antivary f g) (hf : monotone f') : antivary (f' ∘ f) g := λ i j hij, hf $ h hij lemma antivary.comp_antitone_left (h : antivary f g) (hf : antitone f') : monovary (f' ∘ f) g := λ i j hij, hf $ h hij lemma monovary_on.comp_monotone_on_left (h : monovary_on f g s) (hf : monotone f') : monovary_on (f' ∘ f) g s := λ i hi j hj hij, hf $ h hi hj hij lemma monovary_on.comp_antitone_on_left (h : monovary_on f g s) (hf : antitone f') : antivary_on (f' ∘ f) g s := λ i hi j hj hij, hf $ h hi hj hij lemma antivary_on.comp_monotone_on_left (h : antivary_on f g s) (hf : monotone f') : antivary_on (f' ∘ f) g s := λ i hi j hj hij, hf $ h hi hj hij lemma antivary_on.comp_antitone_on_left (h : antivary_on f g s) (hf : antitone f') : monovary_on (f' ∘ f) g s := λ i hi j hj hij, hf $ h hi hj hij section order_dual open order_dual lemma monovary.dual : monovary f g → monovary (to_dual ∘ f) (to_dual ∘ g) := swap lemma antivary.dual : antivary f g → antivary (to_dual ∘ f) (to_dual ∘ g) := swap lemma monovary.dual_left : monovary f g → antivary (to_dual ∘ f) g := id lemma antivary.dual_left : antivary f g → monovary (to_dual ∘ f) g := id lemma monovary.dual_right : monovary f g → antivary f (to_dual ∘ g) := swap lemma antivary.dual_right : antivary f g → monovary f (to_dual ∘ g) := swap lemma monovary_on.dual : monovary_on f g s → monovary_on (to_dual ∘ f) (to_dual ∘ g) s := swap₂ lemma antivary_on.dual : antivary_on f g s → antivary_on (to_dual ∘ f) (to_dual ∘ g) s := swap₂ lemma monovary_on.dual_left : monovary_on f g s → antivary_on (to_dual ∘ f) g s := id lemma antivary_on.dual_left : antivary_on f g s → monovary_on (to_dual ∘ f) g s := id lemma monovary_on.dual_right : monovary_on f g s → antivary_on f (to_dual ∘ g) s := swap₂ lemma antivary_on.dual_right : antivary_on f g s → monovary_on f (to_dual ∘ g) s := swap₂ end order_dual section partial_order variables [partial_order ι] @[simp] lemma monovary_id_iff : monovary f id ↔ monotone f := monotone_iff_forall_lt.symm @[simp] lemma antivary_id_iff : antivary f id ↔ antitone f := antitone_iff_forall_lt.symm @[simp] lemma monovary_on_id_iff : monovary_on f id s ↔ monotone_on f s := monotone_on_iff_forall_lt.symm @[simp] lemma antivary_on_id_iff : antivary_on f id s ↔ antitone_on f s := antitone_on_iff_forall_lt.symm end partial_order variables [linear_order ι] protected lemma monotone.monovary (hf : monotone f) (hg : monotone g) : monovary f g := λ i j hij, hf (hg.reflect_lt hij).le protected lemma monotone.antivary (hf : monotone f) (hg : antitone g) : antivary f g := (hf.monovary hg.dual_right).dual_right protected lemma antitone.monovary (hf : antitone f) (hg : antitone g) : monovary f g := (hf.dual_right.antivary hg).dual_left protected lemma antitone.antivary (hf : antitone f) (hg : monotone g) : antivary f g := (hf.monovary hg.dual_right).dual_right protected lemma monotone_on.monovary_on (hf : monotone_on f s) (hg : monotone_on g s) : monovary_on f g s := λ i hi j hj hij, hf hi hj (hg.reflect_lt hi hj hij).le protected lemma monotone_on.antivary_on (hf : monotone_on f s) (hg : antitone_on g s) : antivary_on f g s := (hf.monovary_on hg.dual_right).dual_right protected lemma antitone_on.monovary_on (hf : antitone_on f s) (hg : antitone_on g s) : monovary_on f g s := (hf.dual_right.antivary_on hg).dual_left protected lemma antitone_on.antivary_on (hf : antitone_on f s) (hg : monotone_on g s) : antivary_on f g s := (hf.monovary_on hg.dual_right).dual_right end preorder section linear_order variables [preorder α] [linear_order β] [preorder γ] {f : ι → α} {f' : α → γ} {g : ι → β} {g' : β → γ} {s : set ι} lemma monovary_on.comp_monotone_on_right (h : monovary_on f g s) (hg : monotone_on g' (g '' s)) : monovary_on f (g' ∘ g) s := λ i hi j hj hij, h hi hj $ hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij lemma monovary_on.comp_antitone_on_right (h : monovary_on f g s) (hg : antitone_on g' (g '' s)) : antivary_on f (g' ∘ g) s := λ i hi j hj hij, h hj hi $ hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij lemma antivary_on.comp_monotone_on_right (h : antivary_on f g s) (hg : monotone_on g' (g '' s)) : antivary_on f (g' ∘ g) s := λ i hi j hj hij, h hi hj $ hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij lemma antivary_on.comp_antitone_on_right (h : antivary_on f g s) (hg : antitone_on g' (g '' s)) : monovary_on f (g' ∘ g) s := λ i hi j hj hij, h hj hi $ hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij protected lemma monovary.symm (h : monovary f g) : monovary g f := λ i j hf, le_of_not_lt $ λ hg, hf.not_le $ h hg protected lemma antivary.symm (h : antivary f g) : antivary g f := λ i j hf, le_of_not_lt $ λ hg, hf.not_le $ h hg protected lemma monovary_on.symm (h : monovary_on f g s) : monovary_on g f s := λ i hi j hj hf, le_of_not_lt $ λ hg, hf.not_le $ h hj hi hg protected lemma antivary_on.symm (h : antivary_on f g s) : antivary_on g f s := λ i hi j hj hf, le_of_not_lt $ λ hg, hf.not_le $ h hi hj hg end linear_order section linear_order variables [linear_order α] [linear_order β] {f : ι → α} {g : ι → β} {s : set ι} protected lemma monovary_comm : monovary f g ↔ monovary g f := ⟨monovary.symm, monovary.symm⟩ protected lemma antivary_comm : antivary f g ↔ antivary g f := ⟨antivary.symm, antivary.symm⟩ protected lemma monovary_on_comm : monovary_on f g s ↔ monovary_on g f s := ⟨monovary_on.symm, monovary_on.symm⟩ protected lemma antivary_on_comm : antivary_on f g s ↔ antivary_on g f s := ⟨antivary_on.symm, antivary_on.symm⟩ end linear_order
b9b92823f130804008a3993924da55cd23433383
367134ba5a65885e863bdc4507601606690974c1
/src/category_theory/monad/basic.lean
241833a1a3052cedbe6231d22b552b6540ff22c4
[ "Apache-2.0" ]
permissive
kodyvajjha/mathlib
9bead00e90f68269a313f45f5561766cfd8d5cad
b98af5dd79e13a38d84438b850a2e8858ec21284
refs/heads/master
1,624,350,366,310
1,615,563,062,000
1,615,563,062,000
162,666,963
0
0
Apache-2.0
1,545,367,651,000
1,545,367,651,000
null
UTF-8
Lean
false
false
8,305
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta, Adam Topaz -/ import category_theory.functor_category import category_theory.fully_faithful namespace category_theory open category universes v₁ u₁ -- declare the `v`'s first; see `category_theory.category` for an explanation variables (C : Type u₁) [category.{v₁} C] /-- The data of a monad on C consists of an endofunctor T together with natural transformations η : 𝟭 C ⟶ T and μ : T ⋙ T ⟶ T satisfying three equations: - T μ_X ≫ μ_X = μ_(TX) ≫ μ_X (associativity) - η_(TX) ≫ μ_X = 1_X (left unit) - Tη_X ≫ μ_X = 1_X (right unit) -/ structure monad extends C ⥤ C := (η' [] : 𝟭 _ ⟶ to_functor) (μ' [] : to_functor ⋙ to_functor ⟶ to_functor) (assoc' : ∀ X, to_functor.map (nat_trans.app μ' X) ≫ μ'.app _ = μ'.app _ ≫ μ'.app _ . obviously) (left_unit' : ∀ X : C, η'.app (to_functor.obj X) ≫ μ'.app _ = 𝟙 _ . obviously) (right_unit' : ∀ X : C, to_functor.map (η'.app X) ≫ μ'.app _ = 𝟙 _ . obviously) /-- The data of a comonad on C consists of an endofunctor G together with natural transformations ε : G ⟶ 𝟭 C and δ : G ⟶ G ⋙ G satisfying three equations: - δ_X ≫ G δ_X = δ_X ≫ δ_(GX) (coassociativity) - δ_X ≫ ε_(GX) = 1_X (left counit) - δ_X ≫ G ε_X = 1_X (right counit) -/ structure comonad extends C ⥤ C := (ε' [] : to_functor ⟶ 𝟭 _) (δ' [] : to_functor ⟶ to_functor ⋙ to_functor) (coassoc' : ∀ X, nat_trans.app δ' _ ≫ to_functor.map (δ'.app X) = δ'.app _ ≫ δ'.app _ . obviously) (left_counit' : ∀ X : C, δ'.app X ≫ ε'.app (to_functor.obj X) = 𝟙 _ . obviously) (right_counit' : ∀ X : C, δ'.app X ≫ to_functor.map (ε'.app X) = 𝟙 _ . obviously) variables {C} (T : monad C) (G : comonad C) instance coe_monad : has_coe (monad C) (C ⥤ C) := ⟨λ T, T.to_functor⟩ instance coe_comonad : has_coe (comonad C) (C ⥤ C) := ⟨λ G, G.to_functor⟩ @[simp] lemma monad_to_functor_eq_coe : T.to_functor = T := rfl @[simp] lemma comonad_to_functor_eq_coe : G.to_functor = G := rfl /-- The unit for the monad `T`. -/ def monad.η : 𝟭 _ ⟶ (T : C ⥤ C) := T.η' /-- The multiplication for the monad `T`. -/ def monad.μ : (T : C ⥤ C) ⋙ (T : C ⥤ C) ⟶ T := T.μ' /-- The counit for the comonad `G`. -/ def comonad.ε : (G : C ⥤ C) ⟶ 𝟭 _ := G.ε' /-- The comultiplication for the comonad `G`. -/ def comonad.δ : (G : C ⥤ C) ⟶ (G : C ⥤ C) ⋙ G := G.δ' /-- A custom simps projection for the functor part of a monad, as a coercion. -/ def monad.simps.to_functor := (T : C ⥤ C) /-- A custom simps projection for the unit of a monad, in simp normal form. -/ def monad.simps.η' : 𝟭 _ ⟶ (T : C ⥤ C) := T.η /-- A custom simps projection for the multiplication of a monad, in simp normal form. -/ def monad.simps.μ' : (T : C ⥤ C) ⋙ (T : C ⥤ C) ⟶ (T : C ⥤ C) := T.μ /-- A custom simps projection for the functor part of a comonad, as a coercion. -/ def comonad.simps.to_functor := (G : C ⥤ C) /-- A custom simps projection for the counit of a comonad, in simp normal form. -/ def comonad.simps.ε' : (G : C ⥤ C) ⟶ 𝟭 _ := G.ε /-- A custom simps projection for the comultiplication of a comonad, in simp normal form. -/ def comonad.simps.δ' : (G : C ⥤ C) ⟶ (G : C ⥤ C) ⋙ (G : C ⥤ C) := G.δ initialize_simps_projections category_theory.monad (to_functor → coe, η' → η, μ' → μ) initialize_simps_projections category_theory.comonad (to_functor → coe, ε' → ε, δ' → δ) @[reassoc] lemma monad.assoc (T : monad C) (X : C) : (T : C ⥤ C).map (T.μ.app X) ≫ T.μ.app _ = T.μ.app _ ≫ T.μ.app _ := T.assoc' X @[simp, reassoc] lemma monad.left_unit (T : monad C) (X : C) : T.η.app ((T : C ⥤ C).obj X) ≫ T.μ.app X = 𝟙 ((T : C ⥤ C).obj X) := T.left_unit' X @[simp, reassoc] lemma monad.right_unit (T : monad C) (X : C) : (T : C ⥤ C).map (T.η.app X) ≫ T.μ.app X = 𝟙 ((T : C ⥤ C).obj X) := T.right_unit' X @[reassoc] lemma comonad.coassoc (G : comonad C) (X : C) : G.δ.app _ ≫ (G : C ⥤ C).map (G.δ.app X) = G.δ.app _ ≫ G.δ.app _ := G.coassoc' X @[simp, reassoc] lemma comonad.left_counit (G : comonad C) (X : C) : G.δ.app X ≫ G.ε.app ((G : C ⥤ C).obj X) = 𝟙 ((G : C ⥤ C).obj X) := G.left_counit' X @[simp, reassoc] lemma comonad.right_counit (G : comonad C) (X : C) : G.δ.app X ≫ (G : C ⥤ C).map (G.ε.app X) = 𝟙 ((G : C ⥤ C).obj X) := G.right_counit' X /-- A morphism of monads is a natural transformation compatible with η and μ. -/ @[ext] structure monad_hom (T₁ T₂ : monad C) extends nat_trans (T₁ : C ⥤ C) T₂ := (app_η' : ∀ {X}, T₁.η.app X ≫ app X = T₂.η.app X . obviously) (app_μ' : ∀ {X}, T₁.μ.app X ≫ app X = ((T₁ : C ⥤ C).map (app X) ≫ app _) ≫ T₂.μ.app X . obviously) /-- A morphism of comonads is a natural transformation compatible with ε and δ. -/ @[ext] structure comonad_hom (M N : comonad C) extends nat_trans (M : C ⥤ C) N := (app_ε' : ∀ {X}, app X ≫ N.ε.app X = M.ε.app X . obviously) (app_δ' : ∀ {X}, app X ≫ N.δ.app X = M.δ.app X ≫ app (M.obj X) ≫ N.map (app X) . obviously) restate_axiom monad_hom.app_η' restate_axiom monad_hom.app_μ' attribute [simp, reassoc] monad_hom.app_η monad_hom.app_μ restate_axiom comonad_hom.app_ε' restate_axiom comonad_hom.app_δ' attribute [simp, reassoc] comonad_hom.app_ε comonad_hom.app_δ instance : category (monad C) := { hom := monad_hom, id := λ M, { to_nat_trans := 𝟙 (M : C ⥤ C) }, comp := λ _ _ _ f g, { to_nat_trans := { app := λ X, f.app X ≫ g.app X } } } instance : category (comonad C) := { hom := comonad_hom, id := λ M, { to_nat_trans := 𝟙 (M : C ⥤ C) }, comp := λ M N L f g, { to_nat_trans := { app := λ X, f.app X ≫ g.app X } } } instance {T : monad C} : inhabited (monad_hom T T) := ⟨𝟙 T⟩ @[simp] lemma monad_hom.id_to_nat_trans (T : monad C) : (𝟙 T : T ⟶ T).to_nat_trans = 𝟙 (T : C ⥤ C) := rfl @[simp] lemma monad_hom.comp_to_nat_trans {T₁ T₂ T₃ : monad C} (f : T₁ ⟶ T₂) (g : T₂ ⟶ T₃) : (f ≫ g).to_nat_trans = ((f.to_nat_trans : _ ⟶ (T₂ : C ⥤ C)) ≫ g.to_nat_trans : (T₁ : C ⥤ C) ⟶ T₃) := rfl instance {G : comonad C} : inhabited (comonad_hom G G) := ⟨𝟙 G⟩ @[simp] lemma comonad_hom.id_to_nat_trans (T : comonad C) : (𝟙 T : T ⟶ T).to_nat_trans = 𝟙 (T : C ⥤ C) := rfl @[simp] lemma comp_to_nat_trans {T₁ T₂ T₃ : comonad C} (f : T₁ ⟶ T₂) (g : T₂ ⟶ T₃) : (f ≫ g).to_nat_trans = ((f.to_nat_trans : _ ⟶ (T₂ : C ⥤ C)) ≫ g.to_nat_trans : (T₁ : C ⥤ C) ⟶ T₃) := rfl variable (C) /-- The forgetful functor from the category of monads to the category of endofunctors. -/ @[simps] def monad_to_functor : monad C ⥤ (C ⥤ C) := { obj := λ T, T, map := λ M N f, f.to_nat_trans } instance : faithful (monad_to_functor C) := {}. /-- The forgetful functor from the category of comonads to the category of endofunctors. -/ @[simps] def comonad_to_functor : comonad C ⥤ (C ⥤ C) := { obj := λ G, G, map := λ M N f, f.to_nat_trans } instance : faithful (comonad_to_functor C) := {}. variable {C} /-- An isomorphism of monads gives a natural isomorphism of the underlying functors. -/ @[simps {rhs_md := semireducible}] def monad_iso.to_nat_iso {M N : monad C} (h : M ≅ N) : (M : C ⥤ C) ≅ N := (monad_to_functor C).map_iso h /-- An isomorphism of comonads gives a natural isomorphism of the underlying functors. -/ @[simps {rhs_md := semireducible}] def comonad_iso.to_nat_iso {M N : comonad C} (h : M ≅ N) : (M : C ⥤ C) ≅ N := (comonad_to_functor C).map_iso h variable (C) namespace monad /-- The identity monad. -/ @[simps] def id : monad C := { to_functor := 𝟭 C, η' := 𝟙 (𝟭 C), μ' := 𝟙 (𝟭 C) } instance : inhabited (monad C) := ⟨monad.id C⟩ end monad namespace comonad /-- The identity comonad. -/ @[simps] def id : comonad C := { to_functor := 𝟭 _, ε' := 𝟙 (𝟭 C), δ' := 𝟙 (𝟭 C) } instance : inhabited (comonad C) := ⟨comonad.id C⟩ end comonad end category_theory
3d54b3fd8deefc39f9e159013af5bcca8369af81
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/tactic/lift.lean
525f972f60d7ae2930c9cfd9e880c159476d5088
[ "Apache-2.0" ]
permissive
dupuisf/mathlib
62de4ec6544bf3b79086afd27b6529acfaf2c1bb
8582b06b0a5d06c33ee07d0bdf7c646cae22cf36
refs/heads/master
1,669,494,854,016
1,595,692,409,000
1,595,692,409,000
272,046,630
0
0
Apache-2.0
1,592,066,143,000
1,592,066,142,000
null
UTF-8
Lean
false
false
9,242
lean
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import tactic.rcases /-! # lift tactic This file defines the lift tactic, allowing the user to lift elements from one type to another under a specified condition. ## Tags lift, tactic -/ universe variables u v w /-- A class specifying that you can lift elements from `α` to `β` assuming `cond` is true. Used by the tactic `lift`. -/ class can_lift (α : Type u) (β : Type v) : Type (max u v) := (coe : β → α) (cond : α → Prop) (prf : ∀(x : α), cond x → ∃(y : β), coe y = x) open tactic @[user_attribute] meta def can_lift_attr : user_attribute (list name) := { name := "_can_lift", descr := "internal attribute used by the lift tactic", cache_cfg := { mk_cache := λ _, do { ls ← attribute.get_instances `instance, ls.mfilter $ λ l, do { (_,t) ← mk_const l >>= infer_type >>= mk_local_pis, return $ t.is_app_of `can_lift } }, dependencies := [`instance] } } instance : can_lift ℤ ℕ := ⟨coe, λ n, 0 ≤ n, λ n hn, ⟨n.nat_abs, int.nat_abs_of_nonneg hn⟩⟩ /-- Enable automatic handling of pi types in `can_lift`. -/ instance pi.can_lift (ι : Type u) (α : Π i : ι, Type v) (β : Π i : ι, Type w) [Π i : ι, can_lift (α i) (β i)] : can_lift (Π i : ι, α i) (Π i : ι, β i) := { coe := λ f i, can_lift.coe (f i), cond := λ f, ∀ i, can_lift.cond (β i) (f i), prf := λ f hf, ⟨λ i, classical.some (can_lift.prf (f i) (hf i)), funext $ λ i, classical.some_spec (can_lift.prf (f i) (hf i))⟩ } namespace tactic /- Construct the proof of `cond x` in the lift tactic. `e` is the expression being lifted and `h` is the specified proof of `can_lift.cond e`. `old_tp` and `new_tp` are the arguments to `can_lift` and `inst` is the `can_lift`-instance. `s` and `to_unfold` contain the information of the simp set used to simplify. If the proof was specified, we check whether it has the correct type. If it doesn't have the correct type, we display an error message (but first call dsimp on the expression in the message). If the proof was not specified, we create assert it as a local constant. (The name of this local constant doesn't matter, since `lift` will remove it from the context) -/ meta def get_lift_prf (h : option pexpr) (old_tp new_tp inst e : expr) (s : simp_lemmas) (to_unfold : list name) : tactic expr := if h_some : h.is_some then (do prf ← i_to_expr (option.get h_some), prf_ty ← infer_type prf, expected_prf_ty ← mk_app `can_lift.cond [old_tp, new_tp, inst, e], unify prf_ty expected_prf_ty <|> (do expected_prf_ty2 ← s.dsimplify to_unfold expected_prf_ty, pformat!"lift tactic failed. The type of\n {prf}\nis\n {prf_ty}\nbut it is expected to be\n {expected_prf_ty2}" >>= fail), return prf) else (do prf_nm ← get_unused_name, prf ← mk_app `can_lift.cond [old_tp, new_tp, inst, e] >>= assert prf_nm, dsimp_target s to_unfold {}, swap, return prf) /-- Lift the expression `p` to the type `t`, with proof obligation given by `h`. The list `n` is used for the two newly generated names, and to specify whether `h` should remain in the local context. See the doc string of `tactic.interactive.lift` for more information. -/ meta def lift (p : pexpr) (t : pexpr) (h : option pexpr) (n : list name) : tactic unit := do propositional_goal <|> fail "lift tactic failed. Tactic is only applicable when the target is a proposition.", e ← i_to_expr p, old_tp ← infer_type e, new_tp ← i_to_expr t, inst_type ← mk_app ``can_lift [old_tp, new_tp], inst ← mk_instance inst_type <|> pformat!"Failed to find a lift from {old_tp} to {new_tp}. Provide an instance of\n {inst_type}" >>= fail, /- make the simp set to get rid of `can_lift` projections -/ can_lift_instances ← can_lift_attr.get_cache >>= λ l, l.mmap resolve_name, (s, to_unfold) ← mk_simp_set tt [] $ can_lift_instances.map simp_arg_type.expr, prf_cond ← get_lift_prf h old_tp new_tp inst e s to_unfold, let prf_nm := if prf_cond.is_local_constant then some prf_cond.local_pp_name else none, /- We use mk_mapp to apply `can_lift.prf` to all but one argument, and then just use expr.app for the last argument. For some reason we get an error when applying mk_mapp it to all arguments. -/ prf_ex0 ← mk_mapp `can_lift.prf [old_tp, new_tp, inst, e], let prf_ex := prf_ex0 prf_cond, /- Find the name of the new variable -/ new_nm ← if n ≠ [] then return n.head else if e.is_local_constant then return e.local_pp_name else get_unused_name, /- Find the name of the proof of the equation -/ eq_nm ← if hn : 1 < n.length then return (n.nth_le 1 hn) else if e.is_local_constant then return `rfl else get_unused_name `h, /- We add the proof of the existential statement to the context and then apply `dsimp` to it, unfolding all `can_lift` instances. -/ temp_nm ← get_unused_name, temp_e ← note temp_nm none prf_ex, dsimp_hyp temp_e s to_unfold {}, /- We case on the existential. We use `rcases` because `eq_nm` could be `rfl`. -/ rcases none (pexpr.of_expr temp_e) [[rcases_patt.one new_nm, rcases_patt.one eq_nm]], /- If the lifted variable is not a local constant, try to rewrite it away using the new equality-/ when (¬ e.is_local_constant) (get_local eq_nm >>= λ e, interactive.rw ⟨[⟨⟨0, 0⟩, tt, (pexpr.of_expr e)⟩], none⟩ interactive.loc.wildcard), /- If the proof `prf_cond` is a local constant, remove it from the context, unless `n` specifies to keep it. -/ if h_prf_nm : prf_nm.is_some ∧ n.nth 2 ≠ prf_nm then get_local (option.get h_prf_nm.1) >>= clear else skip open lean.parser interactive interactive.types local postfix `?`:9001 := optional meta def using_texpr := (tk "using" *> texpr)? reserve notation `to` meta def to_texpr := (tk "to" *> texpr) namespace interactive /-- Lift an expression to another type. Lift an expression to another type. * Usage: `'lift' expr 'to' expr ('using' expr)? ('with' id (id id?)?)?`. * If `n : ℤ` and `hn : n ≥ 0` then the tactic `lift n to ℕ using hn` creates a new constant of type `ℕ`, also named `n` and replaces all occurrences of the old variable `(n : ℤ)` with `↑n` (where `n` in the new variable). It will remove `n` and `hn` from the context. + So for example the tactic `lift n to ℕ using hn` transforms the goal `n : ℤ, hn : n ≥ 0, h : P n ⊢ n = 3` to `n : ℕ, h : P ↑n ⊢ ↑n = 3` (here `P` is some term of type `ℤ → Prop`). * The argument `using hn` is optional, the tactic `lift n to ℕ` does the same, but also creates a new subgoal that `n ≥ 0` (where `n` is the old variable). + So for example the tactic `lift n to ℕ` transforms the goal `n : ℤ, h : P n ⊢ n = 3` to two goals `n : ℕ, h : P ↑n ⊢ ↑n = 3` and `n : ℤ, h : P n ⊢ n ≥ 0`. * You can also use `lift n to ℕ using e` where `e` is any expression of type `n ≥ 0`. * Use `lift n to ℕ with k` to specify the name of the new variable. * Use `lift n to ℕ with k hk` to also specify the name of the equality `↑k = n`. In this case, `n` will remain in the context. You can use `rfl` for the name of `hk` to substitute `n` away (i.e. the default behavior). * You can also use `lift e to ℕ with k hk` where `e` is any expression of type `ℤ`. In this case, the `hk` will always stay in the context, but it will be used to rewrite `e` in all hypotheses and the target. + So for example the tactic `lift n + 3 to ℕ using hn with k hk` transforms the goal `n : ℤ, hn : n + 3 ≥ 0, h : P (n + 3) ⊢ n + 3 = 2 * n` to the goal `n : ℤ, k : ℕ, hk : ↑k = n + 3, h : P ↑k ⊢ ↑k = 2 * n`. * The tactic `lift n to ℕ using h` will remove `h` from the context. If you want to keep it, specify it again as the third argument to `with`, like this: `lift n to ℕ using h with n rfl h`. * More generally, this can lift an expression from `α` to `β` assuming that there is an instance of `can_lift α β`. In this case the proof obligation is specified by `can_lift.cond`. * Given an instance `can_lift β γ`, it can also lift `α → β` to `α → γ`; more generally, given `β : Π a : α, Type*`, `γ : Π a : α, Type*`, and `[Π a : α, can_lift (β a) (γ a)]`, it automatically generates an instance `can_lift (Π a, β a) (Π a, γ a)`. `lift` is in some sense dual to the `zify` tactic. `lift (z : ℤ) to ℕ` will change the type of an integer `z` (in the supertype) to `ℕ` (the subtype), given a proof that `z ≥ 0`; propositions concerning `z` will still be over `ℤ`. `zify` changes propositions about `ℕ` (the subtype) to propositions about `ℤ` (the supertype), without changing the type of any variable. -/ meta def lift (p : parse texpr) (t : parse to_texpr) (h : parse using_texpr) (n : parse with_ident_list) : tactic unit := tactic.lift p t h n add_tactic_doc { name := "lift", category := doc_category.tactic, decl_names := [`tactic.interactive.lift], tags := ["coercions"] } end interactive end tactic
20233da4173b2979a9948ba4eb57b4c9010d2b49
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/init/control/reader.lean
d5b8b3df112b8d4a7ddbd6032bf5f90b9b5bab5b
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
6,206
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sebastian Ullrich The reader monad transformer for passing immutable state. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.control.lift import Mathlib.Lean3Lib.init.control.id import Mathlib.Lean3Lib.init.control.alternative import Mathlib.Lean3Lib.init.control.except universes u v l u_1 u_2 u_3 w namespace Mathlib /-- An implementation of [ReaderT](https://hackage.haskell.org/package/transformers-0.5.5.0/docs/Control-Monad-Trans-Reader.html#t:ReaderT) -/ structure reader_t (ρ : Type u) (m : Type u → Type v) (α : Type u) where run : ρ → m α def reader (ρ : Type u) (α : Type u) := reader_t ρ id namespace reader_t protected def read {ρ : Type u} {m : Type u → Type v} [Monad m] : reader_t ρ m ρ := mk pure protected def pure {ρ : Type u} {m : Type u → Type v} [Monad m] {α : Type u} (a : α) : reader_t ρ m α := mk fun (r : ρ) => pure a protected def bind {ρ : Type u} {m : Type u → Type v} [Monad m] {α : Type u} {β : Type u} (x : reader_t ρ m α) (f : α → reader_t ρ m β) : reader_t ρ m β := mk fun (r : ρ) => do let a ← run x r run (f a) r protected instance monad {ρ : Type u} {m : Type u → Type v} [Monad m] : Monad (reader_t ρ m) := sorry protected def lift {ρ : Type u} {m : Type u → Type v} [Monad m] {α : Type u} (a : m α) : reader_t ρ m α := mk fun (r : ρ) => a protected instance has_monad_lift {ρ : Type u} (m : Type u → Type u_1) [Monad m] : has_monad_lift m (reader_t ρ m) := has_monad_lift.mk reader_t.lift protected def monad_map {ρ : Type u_1} {m : Type u_1 → Type u_2} {m' : Type u_1 → Type u_3} [Monad m] [Monad m'] {α : Type u_1} (f : {α : Type u_1} → m α → m' α) : reader_t ρ m α → reader_t ρ m' α := fun (x : reader_t ρ m α) => mk fun (r : ρ) => f (run x r) protected instance monad_functor (ρ : Type u_1) (m : Type u_1 → Type u_2) (m' : Type u_1 → Type u_2) [Monad m] [Monad m'] : monad_functor m m' (reader_t ρ m) (reader_t ρ m') := monad_functor.mk reader_t.monad_map protected def adapt {ρ : Type u} {m : Type u → Type v} [Monad m] {ρ' : Type u} [Monad m] {α : Type u} (f : ρ' → ρ) : reader_t ρ m α → reader_t ρ' m α := fun (x : reader_t ρ m α) => mk fun (r : ρ') => run x (f r) protected def orelse {ρ : Type u} {m : Type u → Type v} [Monad m] [alternative m] {α : Type u} (x₁ : reader_t ρ m α) (x₂ : reader_t ρ m α) : reader_t ρ m α := mk fun (s : ρ) => run x₁ s <|> run x₂ s protected def failure {ρ : Type u} {m : Type u → Type v} [Monad m] [alternative m] {α : Type u} : reader_t ρ m α := mk fun (s : ρ) => failure protected instance alternative {ρ : Type u} {m : Type u → Type v} [Monad m] [alternative m] : alternative (reader_t ρ m) := alternative.mk reader_t.failure protected instance monad_except {ρ : Type u} {m : Type u → Type v} [Monad m] (ε : outParam (Type u_1)) [Monad m] [monad_except ε m] : monad_except ε (reader_t ρ m) := monad_except.mk (fun (α : Type u) => reader_t.lift ∘ throw) fun (α : Type u) (x : reader_t ρ m α) (c : ε → reader_t ρ m α) => mk fun (r : ρ) => catch (run x r) fun (e : ε) => run (c e) r end reader_t /-- An implementation of [MonadReader](https://hackage.haskell.org/package/mtl-2.2.2/docs/Control-Monad-Reader-Class.html#t:MonadReader). It does not contain `local` because this function cannot be lifted using `monad_lift`. Instead, the `monad_reader_adapter` class provides the more general `adapt_reader` function. Note: This class can be seen as a simplification of the more "principled" definition ``` class monad_reader (ρ : out_param (Type u)) (n : Type u → Type u) := (lift {α : Type u} : (∀ {m : Type u → Type u} [monad m], reader_t ρ m α) → n α) ``` -/ class monad_reader (ρ : outParam (Type u)) (m : Type u → Type v) where read : m ρ protected instance monad_reader_trans {ρ : Type u} {m : Type u → Type v} {n : Type u → Type w} [monad_reader ρ m] [has_monad_lift m n] : monad_reader ρ n := monad_reader.mk (monad_lift read) protected instance reader_t.monad_reader {ρ : Type u} {m : Type u → Type v} [Monad m] : monad_reader ρ (reader_t ρ m) := monad_reader.mk reader_t.read /-- Adapt a monad stack, changing the type of its top-most environment. This class is comparable to [Control.Lens.Magnify](https://hackage.haskell.org/package/lens-4.15.4/docs/Control-Lens-Zoom.html#t:Magnify), but does not use lenses (why would it), and is derived automatically for any transformer implementing `monad_functor`. Note: This class can be seen as a simplification of the more "principled" definition ``` class monad_reader_functor (ρ ρ' : out_param (Type u)) (n n' : Type u → Type u) := (map {α : Type u} : (∀ {m : Type u → Type u} [monad m], reader_t ρ m α → reader_t ρ' m α) → n α → n' α) ``` -/ class monad_reader_adapter (ρ : outParam (Type u)) (ρ' : outParam (Type u)) (m : Type u → Type v) (m' : Type u → Type v) where adapt_reader : {α : Type u} → (ρ' → ρ) → m α → m' α protected instance monad_reader_adapter_trans {ρ : Type u} {ρ' : Type u} {m : Type u → Type v} {m' : Type u → Type v} {n : Type u → Type v} {n' : Type u → Type v} [monad_functor m m' n n'] [monad_reader_adapter ρ ρ' m m'] : monad_reader_adapter ρ ρ' n n' := monad_reader_adapter.mk fun (α : Type u) (f : ρ' → ρ) => monad_map fun (α : Type u) => adapt_reader f protected instance reader_t.monad_reader_adapter {ρ : Type u} {ρ' : Type u} {m : Type u → Type v} [Monad m] : monad_reader_adapter ρ ρ' (reader_t ρ m) (reader_t ρ' m) := monad_reader_adapter.mk fun (α : Type u) => reader_t.adapt protected instance reader_t.monad_run (ρ : Type u) (m : Type u → Type u_1) (out : outParam (Type u → Type u_1)) [monad_run out m] : monad_run (fun (α : Type u) => ρ → out α) (reader_t ρ m) := monad_run.mk fun (α : Type u) (x : reader_t ρ m α) => run ∘ reader_t.run x
88c077d3b8cbedb3224982e18ed2f03a1cfdb8cb
92b50235facfbc08dfe7f334827d47281471333b
/library/data/bool.lean
65a43a79f06ad8fc971ce08ab7165b86e4be57d4
[ "Apache-2.0" ]
permissive
htzh/lean
24f6ed7510ab637379ec31af406d12584d31792c
d70c79f4e30aafecdfc4a60b5d3512199200ab6e
refs/heads/master
1,607,677,731,270
1,437,089,952,000
1,437,089,952,000
37,078,816
0
0
null
1,433,780,956,000
1,433,780,955,000
null
UTF-8
Lean
false
false
3,500
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ import logic.eq open eq eq.ops decidable namespace bool local attribute bor [reducible] local attribute band [reducible] theorem dichotomy (b : bool) : b = ff ∨ b = tt := bool.cases_on b (or.inl rfl) (or.inr rfl) theorem cond_ff {A : Type} (t e : A) : cond ff t e = e := rfl theorem cond_tt {A : Type} (t e : A) : cond tt t e = t := rfl theorem eq_tt_of_ne_ff : ∀ {a : bool}, a ≠ ff → a = tt | @eq_tt_of_ne_ff tt H := rfl | @eq_tt_of_ne_ff ff H := absurd rfl H theorem eq_ff_of_ne_tt : ∀ {a : bool}, a ≠ tt → a = ff | @eq_ff_of_ne_tt tt H := absurd rfl H | @eq_ff_of_ne_tt ff H := rfl theorem absurd_of_eq_ff_of_eq_tt {B : Prop} {a : bool} (H₁ : a = ff) (H₂ : a = tt) : B := absurd (H₁⁻¹ ⬝ H₂) ff_ne_tt theorem tt_bor (a : bool) : bor tt a = tt := rfl notation a || b := bor a b theorem bor_tt (a : bool) : a || tt = tt := bool.cases_on a rfl rfl theorem ff_bor (a : bool) : ff || a = a := bool.cases_on a rfl rfl theorem bor_ff (a : bool) : a || ff = a := bool.cases_on a rfl rfl theorem bor_self (a : bool) : a || a = a := bool.cases_on a rfl rfl theorem bor.comm (a b : bool) : a || b = b || a := by cases a; repeat (cases b | reflexivity) theorem bor.assoc (a b c : bool) : (a || b) || c = a || (b || c) := match a with | ff := by rewrite *ff_bor | tt := by rewrite *tt_bor end theorem or_of_bor_eq {a b : bool} : a || b = tt → a = tt ∨ b = tt := bool.rec_on a (assume H : ff || b = tt, have Hb : b = tt, from !ff_bor ▸ H, or.inr Hb) (assume H, or.inl rfl) theorem bor_inl {a b : bool} (H : a = tt) : a || b = tt := by rewrite H theorem bor_inr {a b : bool} (H : b = tt) : a || b = tt := bool.rec_on a (by rewrite H) (by rewrite H) theorem ff_band (a : bool) : ff && a = ff := rfl theorem tt_band (a : bool) : tt && a = a := bool.cases_on a rfl rfl theorem band_ff (a : bool) : a && ff = ff := bool.cases_on a rfl rfl theorem band_tt (a : bool) : a && tt = a := bool.cases_on a rfl rfl theorem band_self (a : bool) : a && a = a := bool.cases_on a rfl rfl theorem band.comm (a b : bool) : a && b = b && a := bool.cases_on a (bool.cases_on b rfl rfl) (bool.cases_on b rfl rfl) theorem band.assoc (a b c : bool) : (a && b) && c = a && (b && c) := match a with | ff := by rewrite *ff_band | tt := by rewrite *tt_band end theorem band_elim_left {a b : bool} (H : a && b = tt) : a = tt := or.elim (dichotomy a) (assume H0 : a = ff, absurd (calc ff = ff && b : ff_band ... = a && b : H0 ... = tt : H) ff_ne_tt) (assume H1 : a = tt, H1) theorem band_intro {a b : bool} (H₁ : a = tt) (H₂ : b = tt) : a && b = tt := by rewrite [H₁, H₂] theorem band_elim_right {a b : bool} (H : a && b = tt) : b = tt := band_elim_left (!band.comm ⬝ H) theorem bnot_bnot (a : bool) : bnot (bnot a) = a := bool.cases_on a rfl rfl theorem bnot_false : bnot ff = tt := rfl theorem bnot_true : bnot tt = ff := rfl theorem eq_tt_of_bnot_eq_ff {a : bool} : bnot a = ff → a = tt := bool.cases_on a (by contradiction) (λ h, rfl) theorem eq_ff_of_bnot_eq_tt {a : bool} : bnot a = tt → a = ff := bool.cases_on a (λ h, rfl) (by contradiction) end bool
14773e8c3b6b8600d615aa418355b5da91b5c43e
febba19712b2aefe4d6c7fb0230b8d7e272c98c4
/src/proof.lean
77bb3008e6cd36370b8b4c67f67f920dc84f56f4
[]
no_license
hcheval/formalized-proof-mining
e6eb980feb644ae269f43d9af93ac584b7a47a17
216cc73fccd84900a1ba7eaae5f73732496d6afe
refs/heads/master
1,689,621,410,792
1,629,912,272,000
1,629,912,272,000
399,855,572
0
0
null
null
null
null
UTF-8
Lean
false
false
6,645
lean
import formula import dialectica import utils section basics variables {ι : Type} {gri : ground_interpretation ι} local notation `𝔽` := formula ι gri local notation `𝕋` := type ι gri variables (greq : Π {i : ι}, ∥𝕏 i // gri ∥ → ∥𝕏 i // gri ∥ → 𝔽) local infixr `≅` : 35 := formula.eqext @greq structure principles := (with_lem : bool := ff) (with_markov : bool := ff) (with_ip : bool := ff) (with_ac : bool := ff) @[reducible] def plain : principles := {} -- structure premises (ι : Type) (gri : ground_interpretation ι) := -- (formulas : list $ formula ι gri) -- (realizable : Π {γ : formula ι gri}, γ ∈ formulas → dia.realizer γ) @[reducible] def premises (ι : Type) (gri : ground_interpretation ι) := list $ formula ι gri @[reducible] def premises' {ι : Type} {gri : ground_interpretation ι} := premises ι gri -- instance : has_mem (formula ι gri) (premises ι gri) := ⟨λ A Γ, A ∈ Γ.formulas⟩ open formula inductive proof (extra : principles) (Γ : list $ formula ι gri) : 𝔽 → Type -- `id` bug | qfer (σ : 𝕋) (x y : ∥σ∥) (A : ∥σ∥ → 𝔽) : proof (x ≅ y) → proof (A (id x) ⟹ A (id y)) | and_contr (A : 𝔽) : proof (A ⟹ A ⋀ A) | or_contr (A : 𝔽) : proof (A ⋁ A ⟹ A) | and_weak (A B : 𝔽) : proof (A ⋀ B ⟹ A) | or_weak (A B : 𝔽) : proof (A ⟹ A ⋁ B) | and_perm (A B : 𝔽) : proof (A ⋀ B ⟹ B ⋀ A) | or_perm (A B : 𝔽) : proof (A ⋁ B ⟹ B ⋁ A) | exfalso (A : 𝔽) : proof (prime false ⟹ A) | univ_ax {σ : 𝕋} (A : ∥σ∥ → 𝔽) : Π x, proof (universal' σ A ⟹ A x) | exist_ax {σ : 𝕋} (A : ∥σ∥ → 𝔽) : Π x, proof (A x ⟹ existential' σ A) | mp {A B : 𝔽} : proof A → proof (A ⟹ B) → proof B | syl {A B C : 𝔽} : proof (A ⟹ B) → proof (B ⟹ C) → proof (A ⟹ C) | importation {A B C : 𝔽} : proof (A ⟹ B ⟹ C) → proof (A ⋀ B ⟹ C) | exportation {A B C : 𝔽} : proof (A ⋀ B ⟹ C) → proof (A ⟹ B ⟹ C) | expansion {A B C : 𝔽} : proof (A ⟹ B) → proof (C ⋁ A ⟹ C ⋁ B) | univ_rule {σ : 𝕋} {A : 𝔽} {B : ∥σ∥ → 𝔽} : (Π x : ∥σ∥, proof (A ⟹ B x)) → proof (A ⟹ universal' σ B) | exist_rule {σ : 𝕋} {A : 𝔽} {B : ∥σ∥ → 𝔽} : (Π x : ∥σ∥, proof (B x ⟹ A)) → proof (existential' σ B ⟹ A) | ir {A : ∥𝕆 // gri∥ → 𝔽} (m : ℕ) : proof (A 0) → (Π (n : ℕ), proof (A n ⟹ A n.succ)) → proof (A m) | lem (A : 𝔽) : extra.with_lem → proof (A ⋁ ∼A) | markov {σ : 𝕋} {A : ∥σ∥ → 𝔽} [∀ x, subsingleton (A x).𝕎] [∀ x, subsingleton (A x).ℂ] : extra.with_markov → proof (∼(∀∀ (x : ∥σ∥) , ∼(A x)) ⟹ (∃∃ (x : ∥σ∥) , A x)) | ip {σ τ : 𝕋} {A : ∥σ∥ → 𝔽} {B : ∥τ∥ → 𝔽} [∀ x : ∥σ∥, subsingleton (A x).𝕎] [∀ y : ∥τ∥, subsingleton (B y).ℂ] : extra.with_ip → proof (((∀∀ (x : ∥σ∥) , A x) ⟹ (∃∃ (y : ∥τ∥) , B y)) ⟹ ∃∃ (y : ∥τ∥) , ((∀∀ (x : ∥σ∥) , A x) ⟹ B y)) | ac {σ τ : 𝕋} (A : ∥σ∥ → ∥τ∥ → 𝔽) : extra.with_ac → proof ((∀∀ (x : ∥σ∥) , (∃∃ (y : ∥τ∥) , A x y)) ⟹ ∃∃ (Y : ∥σ ↣ τ∥) , ∀∀ (x : ∥σ∥) , A x (Y x)) | premise (A : 𝔽) : A ∈ Γ → proof A | of_prime_true {p : Prop} [decidable p] : p → proof (prime p) end basics section basics variables {ι : Type} {gri : ground_interpretation ι} local notation `𝔽` := formula ι gri local notation `𝕋` := type ι gri variables {greq : Π {i : ι}, ∥𝕏 i // gri ∥ → ∥𝕏 i // gri ∥ → 𝔽} local infixr `≅` : 35 := formula.eqext @greq variables {extra : principles} {Γ : premises ι gri} {A B : 𝔽} namespace proof @[reducible, simp] def and_contr' {A : 𝔽} := @and_contr ι gri @greq extra Γ A @[reducible, simp] def or_contr' {A : 𝔽} := @or_contr ι gri @greq extra Γ A @[reducible, simp] def and_weak' {A B : 𝔽} := @and_weak ι gri @greq extra Γ A B @[reducible, simp] def or_weak' {A B : 𝔽} := @or_weak ι gri @greq extra Γ A B @[reducible, simp] def and_perm' {A B : 𝔽} := @and_perm ι gri @greq extra Γ A B @[reducible, simp] def or_perm' {A B : 𝔽} := @or_perm ι gri @greq extra Γ A B @[reducible, simp] def exfalso' {A : 𝔽} := @exfalso ι gri @greq extra Γ A @[reducible, simp] def univ_ax' {σ : 𝕋} {A : ∥σ∥ → 𝔽} {x : ∥σ∥} := @univ_ax ι gri @greq extra Γ σ A x @[reducible, simp] def exist_ax' {σ : 𝕋} {A : ∥σ∥ → 𝔽} {x : ∥σ∥} := @exist_ax ι gri @greq extra Γ σ A x end proof end basics section schemata variables {ι : Type} [decidable_eq ι] {gri : ground_interpretation ι} local notation `𝔽` := formula ι gri local notation `𝕋` := type ι gri variables {greq : Π {i : ι}, ∥𝕏 i // gri ∥ → ∥𝕏 i // gri ∥ → 𝔽} local infixr `≅` : 35 := formula.eqext @greq variables {Γ : premises ι gri} namespace proof local infix `⊢` : 10 := proof @greq plain section substitution_of_equivalents -- variables {A B P : 𝔽} -- def subst_equiv (i : ℕ) : (Γ ⊢ A ⇔ B) → (Γ ⊢ P.substitute i A ⇔ P.substitute i A) variables {A B : 𝔽} {P : 𝔽 → 𝔽} def subst_equiv (i : ℕ) : (Γ ⊢ A ⇔ B) → (Γ ⊢ P A ⇔ P B) := sorry end substitution_of_equivalents section propositional variables {A B : 𝔽} def A_imp_A : (Γ ⊢ A ⟹ A) := syl and_contr' and_weak' def A_imp_B_imp_A : (Γ ⊢ A ⟹ (B ⟹ A)) := exportation and_weak' section double_negation def qf_lem (qfA : A.is_qf) : (Γ ⊢ A ⋁ ∼A) := begin end def A_imp_neg_neg_A : (Γ ⊢ A ⟹ ∼∼A) := sorry def neg_neg_lem : (Γ ⊢ ∼∼(A ⋁ ∼A)) := sorry def neg_neg_conj : (Γ ⊢ ∼∼(A ⋀ B) ⇔ ∼∼A ⋀ ∼∼B) := sorry def neg_neg_imp : (Γ ⊢ ∼∼(A ⟹ B) ⇔ ∼∼A ⟹ ∼∼B) := sorry end double_negation end propositional section first_order open formula variables {σ τ : 𝕋} {A : ∥σ∥ → 𝔽} {B : ∥σ∥ → 𝔽} def univ_imp_exist : (Γ ⊢ universal A ⟹ existential A) := syl univ_ax' (exist_ax _ σ.inh) -- we need an inhabitant -- remark, when doing this proof on paper you actually assume an inhabitant to exist end first_order end proof end schemata
4e476b441308db7d2c359683660a246737b854cb
3b1abba731363bfec018d9d2cfee7fd90e1dc93c
/lemmas_for_RT_n_m.lean
d62b154f2f958bea856b0e272cd7848bade655af
[]
no_license
minchaowu/Ramsey.lean
dcf4e0845cca6dc02ef898f3fd9123c079c5a1a9
8ebbead4869bdf3f4788137411c5f36f2e72943a
refs/heads/master
1,610,462,544,433
1,488,596,497,000
1,488,596,497,000
72,063,527
0
0
null
null
null
null
UTF-8
Lean
false
false
7,229
lean
import definitions open classical set nat decidable prod subtype section -- the least number principle. lemma alt_of_wf {A : set ℕ}: ∀ n, n ∈ A → ∃₀ a ∈ A, ∀₀ b ∈ A, a ≤ b := take n, nat.strong_induction_on n (take n, assume IH, assume ninA, by_cases (suppose ∃₀ m ∈ A, m < n, obtain m (Hm : m ∈ A ∧ m < n), from this, IH m (and.right Hm) (and.left Hm)) (suppose ¬ ∃₀ m ∈ A, m < n, have ∀₀ m ∈ A, ¬ m < n, by+ rewrite not_bounded_exists at this ; exact this, have ∀ m, m ∈ A → n ≤ m, from λ m, λ HmA, le_of_not_gt (this HmA), exists.intro n (and.intro ninA this))) theorem wf_of_le (S : set ℕ) (H : S ≠ ∅) : ∃₀ a ∈ S, ∀₀ b ∈ S, a ≤ b := have ∃ x, x ∈ S, from exists_mem_of_ne_empty H, obtain n (Hn : n ∈ S), from this, alt_of_wf n Hn noncomputable definition chooseleast (S : set ℕ) (H : S ≠ ∅) : ℕ := have ∃₀ a ∈ S, ∀₀ b ∈ S, a ≤ b, from wf_of_le S H, some this theorem least_is_mem (S : set ℕ) (H : S ≠ ∅) : chooseleast S H ∈ S := have H1 : ∃₀ a ∈ S, ∀₀ b ∈ S, a ≤ b, from wf_of_le S H, have inS : some H1 ∈ S, from proof and.left (some_spec H1) qed, have chooseleast S H = some H1, from rfl, by+ rewrite -this at inS ; exact inS theorem minimality {S : set ℕ} {a : ℕ} {H0 : S ≠ ∅} (H : a = chooseleast S H0): ∀₀ x ∈ S, a ≤ x := take b, assume Hb, have H1 : ∃₀ n ∈ S, ∀₀ m ∈ S, n ≤ m, from wf_of_le S H0, have chooseleast S H0 = some H1, from rfl, have eq : a = some H1, by+ rewrite this at H;exact H, have ∀₀ m ∈ S, some H1 ≤ m, from proof and.right (some_spec H1) qed, have some H1 ≤ b, from this Hb, by+ simp end section lemma infset_neq_empty {A : Type} {S : set A} (H : infinite S) : S ≠ ∅ := assume H1, have finemp : finite (∅ : set A), from finite_empty, have finite S, by+ rewrite -H1 at finemp;exact finemp, H this lemma nonzero_card_of_finite {A : Type} {S : set A} (H : card S ≠ 0) : finite S := by_contradiction (suppose ¬ finite S, have card S = 0, from card_of_not_finite this, H this) lemma mem_not_in_diff {A : Type} {S : set A} {a : A} : a ∉ S \ '{a} := assume H, have a ∉ '{a}, from not_mem_of_mem_diff H, this (mem_singleton a) lemma insert_of_diff_singleton {A : Type} {S : set A} {a : A} (H : a ∈ S) : insert a (S \ '{a}) = S := begin apply eq_of_subset_of_subset, intros x h, apply or.elim h, intro, simp, intro hr, apply and.left hr, intro x h', cases (decidable.em (x ∈ '{a})), apply or.inl, apply eq_of_mem_singleton, simp, apply or.inr, apply and.intro, repeat simp end lemma union_of_diff_singleton {A : Type} {S : set A} {a : A} (H : a ∈ S) : S \ '{a} ∪ '{a} = S := begin apply eq_of_subset_of_subset, intros x h, apply or.elim h, intro hl, apply and.left hl, intro hr, have x = a, from (and.left (mem_singleton_iff x a)) hr, rewrite this, simp, intros x h', cases (decidable.em (x ∈ '{a})), apply or.inr, simp, apply or.inl, apply and.intro, repeat simp end lemma finite_singleton {A : Type} {a : A} : finite '{a} := have carda : card '{a} = 1, from card_singleton a, have (1:ℕ) ≠ 0, from dec_trivial, have card '{a} ≠ 0, by+ rewrite -carda at this;exact this, nonzero_card_of_finite this lemma diff_of_infset_singleton {A : Type} (S : set A) (a : A) (H : infinite S): infinite (S \ '{a}) := by_contradiction (suppose ¬ infinite (S \ '{a}), have fin : finite (S \ '{a}), from dne this, by_cases (suppose a ∈ S, have eq : S \ '{a} ∪ '{a} = S, from union_of_diff_singleton this, have finite '{a}, from finite_singleton, have finite (S \ '{a} ∪ '{a}), from @finite_union _ _ _ fin this, have finite S, by+ rewrite eq at this;exact this, H this) (suppose Hneg : a ∉ S, have S ⊆ S \ '{a}, from take x, assume Hx, have x ∉ '{a}, from by_contradiction (suppose ¬ x ∉ '{a}, have x ∈ '{a}, from dne this, have x = a, from (and.left (mem_singleton_iff x a)) this, have a ∈ S, by+ rewrite this at Hx ; exact Hx, Hneg this), and.intro Hx this, have finite S, from @finite_subset _ _ _ fin this, H this) ) lemma sub_of_eq {A : Type} {S T: set A} (H : S = T) : S ⊆ T := have T ⊆ T, from subset.refl T, by+ rewrite -H at this{1};exact this theorem ne_empty_of_mem' {X : Type} {s : set X} {x : X} (H : x ∈ s) : s ≠ ∅ := begin intro Hs, rewrite Hs at H, apply not_mem_empty _ H end --this is on github lemma mem_of_infset {S S': set ℕ} (H1 : infinite S) (H2 : S' ⊆ S) (H3 : finite S') : ∃₀ x ∈ S, x ∉ S' := by_contradiction (suppose ¬ ∃₀ x ∈ S, x ∉ S', have ∀₀ x ∈ S, ¬ x ∉ S', by+ rewrite not_bounded_exists at this;exact this, have S ⊆ S', from take s, assume Hs, have ¬ s ∉ S', from this Hs, dne this, have finite S, from finite_subset this, H1 this) lemma tuples_of_infset_is_nonemp {S : set ℕ} (H : infinite S) (n : ℕ) : tuples S n ≠ ∅ := nat.induction_on n (have sub : ∅ ⊆ S, from empty_subset S, have finemp : finite ∅, from finite_empty, have card (∅ : set ℕ) = 0, from card_empty, have ∅ ∈ tuples S 0, from and.intro sub (and.intro this finemp), ne_empty_of_mem' this) (take a, assume indhyp, have ∃ y, y ∈ tuples S a, from exists_mem_of_ne_empty indhyp, obtain s h, from this, have sub : s ⊆ S, from and.left h, have card s = a, from and.left (and.right h), have fins : finite s, from and.right (and.right h), have ∃₀ x ∈ S, x ∉ s, from mem_of_infset H sub fins, obtain k h, from this, have sub' : insert k s ⊆ S, from take k', assume Hk', or.elim Hk' (λ H1, have k ∈ S, from and.left h, by+ rewrite -H1 at this;exact this) (λ H2, sub H2), have k ∉ s, from and.right h, have card (insert k s) = card s + 1, from @card_insert_of_not_mem _ _ _ fins this, have fin : finite (insert k s), from @finite_insert _ _ _ fins, have card (insert k s) = a+1, by+ simp, have insert k s ∈ tuples S (a+1), from and.intro sub' (and.intro this fin), ne_empty_of_mem' this) noncomputable definition color_of_n_tuples (c : set ℕ → ℕ) (n : ℕ) (S : set ℕ) (H : infinite S): ℕ := have tuples S n ≠ ∅, from tuples_of_infset_is_nonemp H n, have H1 : ∃ H0, H0 ∈ tuples S n, from exists_mem_of_ne_empty this, c (some H1) theorem eq_of_le_ge {a b : ℕ} (H1 : a ≤ b) (H2 : b ≤ a) : a = b := by_contradiction (suppose a ≠ b, have a < b, from lt_of_le_of_ne H1 this, le_lt_antisymm H2 this) theorem lt_or_eq_of_not_le {a b : ℕ} (H : ¬ a < b) : b < a ∨ b = a := have b ≤ a, from le_of_not_gt H, lt_or_eq_of_le this theorem succ_lt_or_eq_of_le {a b : ℕ} (H : a < b) : a+1 < b ∨ a+1 = b := have a+1 ≤ b, from (and.left (lt_iff_succ_le a b)) H, lt_or_eq_of_le this theorem lt_2_eq_0_or_1 {a : ℕ} (H : a < 2) : a = 0 ∨ a = 1 := have a ≤ 1, from (and.left (lt_succ_iff_le a 1)) H, have a < 1 ∨ a = 1, from (and.left le_iff_lt_or_eq) this, or.elim this (λ Hl, have a ≤ 0, from (and.left (lt_succ_iff_le a 0)) Hl, have Hl1 : a < 0 ∨ a = 0, from (and.left le_iff_lt_or_eq) this, have ¬ a < 0, from dec_trivial, have a = 0, from or_resolve_right Hl1 this, or.intro_left (a = 1) this) (λ Hr, or.intro_right (a = 0) Hr) end
14a7fd7f15b60c5fdd8af5ea93851a59143603c5
9dd3f3912f7321eb58ee9aa8f21778ad6221f87c
/tests/lean/run/overload2.lean
ce4c9fc8676e7d7a9f37a602c6dbbe61550dba33
[ "Apache-2.0" ]
permissive
bre7k30/lean
de893411bcfa7b3c5572e61b9e1c52951b310aa4
5a924699d076dab1bd5af23a8f910b433e598d7a
refs/heads/master
1,610,900,145,817
1,488,006,845,000
1,488,006,845,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
739
lean
import standard inductive F2 : Type | O : F2 | I : F2 namespace F2 definition add : F2 → F2 → F2 | O O := O | O I := I | I O := I | I I := O infix + := F2.add end F2 open F2 nat eval (1 : nat) + 1 eval (1 : nat) + (1 : nat) example : true := begin assert H : (1 : nat) + (1 : nat) = 2, reflexivity, constructor end example : true := begin assert H : 1 + 1 = 2, reflexivity, constructor end example : true := begin assert H : (1:nat) + 1 = 2, reflexivity, constructor end example : true := begin assert H : I + O = I, reflexivity, constructor end example : true := begin assert H1 : I + O = I, reflexivity, assert H2 : 1 + 0 = 1, reflexivity, assert H3 : (1:int) + 0 = 1, reflexivity, constructor end
57e70bf079114e9326e6348ae04287d8ac402d1e
957a80ea22c5abb4f4670b250d55534d9db99108
/tests/lean/extra/lt_rec.lean
36393c402d95591a2a4796141b33776af83eb62e
[ "Apache-2.0" ]
permissive
GaloisInc/lean
aa1e64d604051e602fcf4610061314b9a37ab8cd
f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0
refs/heads/master
1,592,202,909,807
1,504,624,387,000
1,504,624,387,000
75,319,626
2
1
Apache-2.0
1,539,290,164,000
1,480,616,104,000
C++
UTF-8
Lean
false
false
589
lean
open nat set_option pp.implicit true set_option pp.notation false definition lt_trans : ∀ {a b c : nat}, a < b → b < c → a < c, lt_trans h (lt.base _) := lt.step h, lt_trans h₁ (lt.step h₂) := lt.step (lt_trans h₁ h₂) definition lt_succ : ∀ {a b : nat}, a < b → succ a < succ b, lt_succ (lt.base a) := lt.base (succ a), lt_succ (lt.step h) := lt.step (lt_succ h) definition lt_of_succ : ∀ {a b : nat}, succ a < b → a < b, lt_of_succ (lt.base (succ a)) := lt.trans (lt.base a) (lt.base (succ a)), lt_of_succ (lt.step h₂) := lt.step (lt_of_succ h₂)
9f8791ce1db87baa3103a20c13589d168f7c7d1e
63abd62053d479eae5abf4951554e1064a4c45b4
/src/topology/algebra/continuous_functions.lean
e2e2ec485f7a3d54d0a74876b7e20b05e2fcc038
[ "Apache-2.0" ]
permissive
Lix0120/mathlib
0020745240315ed0e517cbf32e738d8f9811dd80
e14c37827456fc6707f31b4d1d16f1f3a3205e91
refs/heads/master
1,673,102,855,024
1,604,151,044,000
1,604,151,044,000
308,930,245
0
0
Apache-2.0
1,604,164,710,000
1,604,163,547,000
null
UTF-8
Lean
false
false
14,515
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Nicolò Cavalleri -/ import topology.algebra.module import topology.continuous_map /-! # Algebraic structures over continuous functions In this file we define instances of algebraic sturctures over continuous functions. Instances are present both in the case of the subtype of continuous functions and the type of continuous bundled functions. Both implementations have advantages and disadvantages, but many experienced people in Zulip have expressed a preference towards continuous bundled maps, so when there is no particular reason to use the subtype, continuous bundled functions should be used for the sake of uniformity. -/ local attribute [elab_simple] continuous.comp namespace continuous_functions variables {α : Type*} {β : Type*} [topological_space α] [topological_space β] variables {f g : {f : α → β | continuous f }} instance : has_coe_to_fun {f : α → β | continuous f } := ⟨_, subtype.val⟩ end continuous_functions namespace continuous_map @[to_additive] instance has_mul {α : Type*} {β : Type*} [topological_space α] [topological_space β] [has_mul β] [has_continuous_mul β] : has_mul C(α, β) := ⟨λ f g, ⟨f * g, continuous_mul.comp (f.continuous.prod_mk g.continuous)⟩⟩ @[to_additive] instance {α : Type*} {β : Type*} [topological_space α] [topological_space β] [has_one β] : has_one C(α, β) := ⟨const (1 : β)⟩ end continuous_map section group_structure /-! ### Group stucture In this section we show that continuous functions valued in a topological group inherit the structure of a group. -/ section subtype @[to_additive] instance continuous_submonoid (α : Type*) (β : Type*) [topological_space α] [topological_space β] [monoid β] [has_continuous_mul β] : is_submonoid { f : α → β | continuous f } := { one_mem := @continuous_const _ _ _ _ 1, mul_mem := λ f g fc gc, continuous.comp has_continuous_mul.continuous_mul (continuous.prod_mk fc gc) }. @[to_additive] instance continuous_subgroup (α : Type*) (β : Type*) [topological_space α] [topological_space β] [group β] [topological_group β] : is_subgroup { f : α → β | continuous f } := { inv_mem := λ f fc, continuous.comp topological_group.continuous_inv fc, ..continuous_submonoid α β, }. @[to_additive] instance continuous_monoid {α : Type*} {β : Type*} [topological_space α] [topological_space β] [monoid β] [has_continuous_mul β] : monoid { f : α → β | continuous f } := subtype.monoid @[to_additive] instance continuous_group {α : Type*} {β : Type*} [topological_space α] [topological_space β] [group β] [topological_group β] : group { f : α → β | continuous f } := subtype.group @[to_additive] instance continuous_comm_group {α : Type*} {β : Type*} [topological_space α] [topological_space β] [comm_group β] [topological_group β] : comm_group { f : α → β | continuous f } := @subtype.comm_group _ _ _ (continuous_subgroup α β) -- infer_instance doesn't work?! end subtype section continuous_map @[to_additive] instance continuous_map_semigroup {α : Type*} {β : Type*} [topological_space α] [topological_space β] [semigroup β] [has_continuous_mul β] : semigroup C(α, β) := { mul_assoc := λ a b c, by ext; exact mul_assoc _ _ _, ..continuous_map.has_mul} @[to_additive] instance continuous_map_monoid {α : Type*} {β : Type*} [topological_space α] [topological_space β] [monoid β] [has_continuous_mul β] : monoid C(α, β) := { one_mul := λ a, by ext; exact one_mul _, mul_one := λ a, by ext; exact mul_one _, ..continuous_map_semigroup, ..continuous_map.has_one } @[to_additive] instance continuous_map_comm_monoid {α : Type*} {β : Type*} [topological_space α] [topological_space β] [comm_monoid β] [has_continuous_mul β] : comm_monoid C(α, β) := { one_mul := λ a, by ext; exact one_mul _, mul_one := λ a, by ext; exact mul_one _, mul_comm := λ a b, by ext; exact mul_comm _ _, ..continuous_map_semigroup, ..continuous_map.has_one } @[to_additive] instance continuous_map_group {α : Type*} {β : Type*} [topological_space α] [topological_space β] [group β] [topological_group β] : group C(α, β) := { inv := λ f, ⟨λ x, (f x)⁻¹, continuous_inv.comp f.continuous⟩, mul_left_inv := λ a, by ext; exact mul_left_inv _, ..continuous_map_monoid } @[to_additive] instance continuous_map_comm_group {α : Type*} {β : Type*} [topological_space α] [topological_space β] [comm_group β] [topological_group β] : comm_group C(α, β) := { ..continuous_map_group, ..continuous_map_comm_monoid } end continuous_map end group_structure section ring_structure /-! ### Ring stucture In this section we show that continuous functions valued in a topological ring `R` inherit the structure of a ring. -/ section subtype instance continuous_subring (α : Type*) (R : Type*) [topological_space α] [topological_space R] [ring R] [topological_ring R] : is_subring { f : α → R | continuous f } := { ..continuous_add_subgroup α R, ..continuous_submonoid α R }. instance continuous_ring {α : Type*} {R : Type*} [topological_space α] [topological_space R] [ring R] [topological_ring R] : ring { f : α → R | continuous f } := @subtype.ring _ _ _ (continuous_subring α R) -- infer_instance doesn't work?! instance continuous_comm_ring {α : Type*} {R : Type*} [topological_space α] [topological_space R] [comm_ring R] [topological_ring R] : comm_ring { f : α → R | continuous f } := @subtype.comm_ring _ _ _ (continuous_subring α R) -- infer_instance doesn't work?! end subtype section continuous_map instance continuous_map_semiring {α : Type*} {β : Type*} [topological_space α] [topological_space β] [semiring β] [topological_semiring β] : semiring C(α, β) := { left_distrib := λ a b c, by ext; exact left_distrib _ _ _, right_distrib := λ a b c, by ext; exact right_distrib _ _ _, zero_mul := λ a, by ext; exact zero_mul _, mul_zero := λ a, by ext; exact mul_zero _, ..continuous_map_add_comm_monoid, ..continuous_map_monoid } instance continuous_map_ring {α : Type*} {β : Type*} [topological_space α] [topological_space β] [ring β] [topological_ring β] : ring C(α, β) := { ..continuous_map_semiring, ..continuous_map_add_comm_group, } instance continuous_map_comm_ring {α : Type*} {β : Type*} [topological_space α] [topological_space β] [comm_ring β] [topological_ring β] : comm_ring C(α, β) := { ..continuous_map_semiring, ..continuous_map_add_comm_group, ..continuous_map_comm_monoid,} end continuous_map end ring_structure local attribute [ext] subtype.eq section semimodule_structure /-! ### Semiodule stucture In this section we show that continuous functions valued in a topological semimodule `M` over a topological semiring `R` inherit the structure of a semimodule. -/ section subtype instance continuous_has_scalar {α : Type*} [topological_space α] {R : Type*} [semiring R] [topological_space R] {M : Type*} [topological_space M] [add_comm_group M] [semimodule R M] [topological_semimodule R M] : has_scalar R { f : α → M | continuous f } := ⟨λ r f, ⟨r • f, continuous_const.smul f.property⟩⟩ instance continuous_semimodule {α : Type*} [topological_space α] {R : Type*} [semiring R] [topological_space R] {M : Type*} [topological_space M] [add_comm_group M] [topological_add_group M] [semimodule R M] [topological_semimodule R M] : semimodule R { f : α → M | continuous f } := semimodule.of_core $ { smul := (•), smul_add := λ c f g, by ext x; exact smul_add c (f x) (g x), add_smul := λ c₁ c₂ f, by ext x; exact add_smul c₁ c₂ (f x), mul_smul := λ c₁ c₂ f, by ext x; exact mul_smul c₁ c₂ (f x), one_smul := λ f, by ext x; exact one_smul R (f x) } end subtype section continuous_map instance continuous_map_has_scalar {α : Type*} [topological_space α] {R : Type*} [semiring R] [topological_space R] {M : Type*} [topological_space M] [add_comm_monoid M] [semimodule R M] [topological_semimodule R M] : has_scalar R C(α, M) := ⟨λ r f, ⟨r • f, continuous_const.smul f.continuous⟩⟩ instance continuous_map_semimodule {α : Type*} [topological_space α] {R : Type*} [semiring R] [topological_space R] {M : Type*} [topological_space M] [add_comm_monoid M] [has_continuous_add M] [semimodule R M] [topological_semimodule R M] : semimodule R C(α, M) := { smul := (•), smul_add := λ c f g, by { ext, exact smul_add c (f x) (g x) }, add_smul := λ c₁ c₂ f, by { ext, exact add_smul c₁ c₂ (f x) }, mul_smul := λ c₁ c₂ f, by { ext, exact mul_smul c₁ c₂ (f x) }, one_smul := λ f, by { ext, exact one_smul R (f x) }, zero_smul := λ f, by { ext, exact zero_smul _ _ }, smul_zero := λ r, by { ext, exact smul_zero _ } } end continuous_map end semimodule_structure section algebra_structure /-! ### Algebra structure In this section we show that continuous functions valued in a topological algebra `A` over a ring `R` inherit the structure of an algebra. Note that the hypothesis that `A` is a topological algebra is obtained by requiring that `A` be both a `topological_semimodule` and a `topological_semiring` (by now we require `topological_ring`: see TODO below).-/ section subtype variables {α : Type*} [topological_space α] {R : Type*} [comm_semiring R] {A : Type*} [topological_space A] [ring A] [algebra R A] [topological_ring A] /-- Continuous constant functions as a `ring_hom`. -/ def continuous.C : R →+* { f : α → A | continuous f } := { to_fun := λ c : R, ⟨λ x: α, ((algebra_map R A) c), continuous_const⟩, map_one' := by ext x; exact (algebra_map R A).map_one, map_mul' := λ c₁ c₂, by ext x; exact (algebra_map R A).map_mul _ _, map_zero' := by ext x; exact (algebra_map R A).map_zero, map_add' := λ c₁ c₂, by ext x; exact (algebra_map R A).map_add _ _ } variables [topological_space R] [topological_semimodule R A] instance : algebra R { f : α → A | continuous f } := { to_ring_hom := continuous.C, commutes' := λ c f, by ext x; exact algebra.commutes' _ _, smul_def' := λ c f, by ext x; exact algebra.smul_def' _ _, ..continuous_semimodule, ..continuous_ring } /- TODO: We are assuming `A` to be a ring and not a semiring just because there is not yet an instance of semiring. In turn, we do not want to define yet an instance of semiring because there is no `is_subsemiring` but only `subsemiring`, and it will make sense to change this when the whole file will have no more `is_subobject`s but only `subobject`s. It does not make sense to change it yet in this direction as `subring` does not exist yet, so everything is being blocked by `subring`: afterwards everything will need to be updated to the new conventions of Mathlib. Then the instance of `topological_ring` can also be removed, as it is below for `continuous_map`. -/ end subtype section continuous_map variables {α : Type*} [topological_space α] {R : Type*} [comm_semiring R] {A : Type*} [topological_space A] [semiring A] [algebra R A] [topological_semiring A] /-- Continuous constant functions as a `ring_hom`. -/ def continuous_map.C : R →+* C(α, A) := { to_fun := λ c : R, ⟨λ x: α, ((algebra_map R A) c), continuous_const⟩, map_one' := by ext x; exact (algebra_map R A).map_one, map_mul' := λ c₁ c₂, by ext x; exact (algebra_map R A).map_mul _ _, map_zero' := by ext x; exact (algebra_map R A).map_zero, map_add' := λ c₁ c₂, by ext x; exact (algebra_map R A).map_add _ _ } variables [topological_space R] [topological_semimodule R A] instance continuous_map_algebra : algebra R C(α, A) := { to_ring_hom := continuous_map.C, commutes' := λ c f, by ext x; exact algebra.commutes' _ _, smul_def' := λ c f, by ext x; exact algebra.smul_def' _ _, ..continuous_map_semiring } end continuous_map end algebra_structure section module_over_continuous_functions /-! ### Structure as module over scalar functions If `M` is a module over `R`, then we show that the space of continuous functions from `α` to `M` is naturally a module over the ring of continuous functions from `α` to `M`. -/ section subtype instance continuous_has_scalar' {α : Type*} [topological_space α] {R : Type*} [semiring R] [topological_space R] {M : Type*} [topological_space M] [add_comm_group M] [semimodule R M] [topological_semimodule R M] : has_scalar { f : α → R | continuous f } { f : α → M | continuous f } := ⟨λ f g, ⟨λ x, (f x) • (g x), (continuous.smul f.2 g.2)⟩⟩ instance continuous_module' {α : Type*} [topological_space α] (R : Type*) [ring R] [topological_space R] [topological_ring R] (M : Type*) [topological_space M] [add_comm_group M] [topological_add_group M] [module R M] [topological_module R M] : module { f : α → R | continuous f } { f : α → M | continuous f } := semimodule.of_core $ { smul := (•), smul_add := λ c f g, by ext x; exact smul_add (c x) (f x) (g x), add_smul := λ c₁ c₂ f, by ext x; exact add_smul (c₁ x) (c₂ x) (f x), mul_smul := λ c₁ c₂ f, by ext x; exact mul_smul (c₁ x) (c₂ x) (f x), one_smul := λ f, by ext x; exact one_smul R (f x) } end subtype section continuous_map instance continuous_map_has_scalar' {α : Type*} [topological_space α] {R : Type*} [semiring R] [topological_space R] {M : Type*} [topological_space M] [add_comm_monoid M] [semimodule R M] [topological_semimodule R M] : has_scalar C(α, R) C(α, M) := ⟨λ f g, ⟨λ x, (f x) • (g x), (continuous.smul f.2 g.2)⟩⟩ instance continuous_map_module' {α : Type*} [topological_space α] (R : Type*) [ring R] [topological_space R] [topological_ring R] (M : Type*) [topological_space M] [add_comm_monoid M] [has_continuous_add M] [semimodule R M] [topological_semimodule R M] : semimodule C(α, R) C(α, M) := { smul := (•), smul_add := λ c f g, by ext x; exact smul_add (c x) (f x) (g x), add_smul := λ c₁ c₂ f, by ext x; exact add_smul (c₁ x) (c₂ x) (f x), mul_smul := λ c₁ c₂ f, by ext x; exact mul_smul (c₁ x) (c₂ x) (f x), one_smul := λ f, by ext x; exact one_smul R (f x), zero_smul := λ f, by ext x; exact zero_smul _ _, smul_zero := λ r, by ext x; exact smul_zero _, } end continuous_map end module_over_continuous_functions
038ffe2ab859d7516e5c826a2f8e71d44011bae9
75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2
/tests/lean/extra/755.hlean
193156c89e68b9acf2d70d33a033d4a06b81760a
[ "Apache-2.0" ]
permissive
jroesch/lean
30ef0860fa905d35b9ad6f76de1a4f65c9af6871
3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2
refs/heads/master
1,586,090,835,348
1,455,142,203,000
1,455,142,277,000
51,536,958
1
0
null
1,455,215,811,000
1,455,215,811,000
null
UTF-8
Lean
false
false
1,735
hlean
import types.eq types.pi hit.colimit open eq is_trunc unit quotient seq_colim equiv axiom mysorry : ∀ {A : Type}, A namespace one_step_tr section parameters {A : Type} variables (a a' : A) protected definition R (a a' : A) : Type₀ := unit parameter (A) definition one_step_tr : Type := quotient R parameter {A} definition tr : one_step_tr := class_of R a definition tr_eq : tr a = tr a' := eq_of_rel _ star protected definition rec {P : one_step_tr → Type} (Pt : Π(a : A), P (tr a)) (Pe : Π(a a' : A), Pt a =[tr_eq a a'] Pt a') (x : one_step_tr) : P x := begin fapply (quotient.rec_on x), { intro a, apply Pt}, { intro a a' H, cases H, apply Pe} end protected definition elim {P : Type} (Pt : A → P) (Pe : Π(a a' : A), Pt a = Pt a') (x : one_step_tr) : P := rec Pt (λa a', pathover_of_eq (Pe a a')) x theorem rec_tr_eq {P : one_step_tr → Type} (Pt : Π(a : A), P (tr a)) (Pe : Π(a a' : A), Pt a =[tr_eq a a'] Pt a') (a a' : A) : apdo (rec Pt Pe) (tr_eq a a') = Pe a a' := !rec_eq_of_rel theorem elim_tr_eq {P : Type} (Pt : A → P) (Pe : Π(a a' : A), Pt a = Pt a') (a a' : A) : ap (elim Pt Pe) (tr_eq a a') = Pe a a' := begin apply eq_of_fn_eq_fn_inv !(pathover_constant (tr_eq a a')), rewrite [▸*,-apdo_eq_pathover_of_eq_ap,↑elim,rec_tr_eq], end end end one_step_tr attribute one_step_tr.rec one_step_tr.elim [recursor 5] open one_step_tr definition one_step_tr_up (A B : Type) : (one_step_tr A → B) ≃ Σ(f : A → B), Π(x y : A), f x = f y := begin fapply equiv.MK, { intro f, fconstructor, intro a, exact f (tr a), intros, exact ap f !tr_eq}, { exact mysorry}, { exact mysorry}, { exact mysorry}, end
f0ebe8952b2e943230e338a0dc414d13bfcbc77f
cc060cf567f81c404a13ee79bf21f2e720fa6db0
/lean/20170212-problem-with-sigma-types.lean
bd35edcad840e1bfa79f903b452cdb591b5d5bec
[ "Apache-2.0" ]
permissive
semorrison/proof
cf0a8c6957153bdb206fd5d5a762a75958a82bca
5ee398aa239a379a431190edbb6022b1a0aa2c70
refs/heads/master
1,610,414,502,842
1,518,696,851,000
1,518,696,851,000
78,375,937
2
1
null
null
null
null
UTF-8
Lean
false
false
785
lean
universe variables u v structure Category := (Obj : Type u) (Hom : Obj → Obj → Type v) (compose : Π { X Y Z : Obj }, Hom X Y → Hom Y Z → Hom X Z) universe variables u1 v1 u2 v2 structure Functor (C : Category.{ u1 v1 }) (D : Category.{ u2 v2 }) := (onObjects : C^.Obj → D^.Obj) (onMorphisms : Π { X Y : C^.Obj }, C^.Hom X Y → D^.Hom (onObjects X) (onObjects Y)) definition CommaCategory { A B C : Category} ( S : Functor A C ) ( T : Functor B C ) : Category := { Obj := Σ a : A^.Obj, Σ b : B^.Obj, (C^.Hom (S^.onObjects a) (T^.onObjects b)), Hom := λ p q, subtype (λ gh : (A^.Hom p.1 q.1) × (B^.Hom p.2.1 q.2.1), C^.compose (S^.onMorphisms gh.1) q.2.1 = C^.compose p.2.2 (T^.onMorphisms gh.2) ), compose := sorry }
3c8516eadf628e93c0d35733bb09ef42cec276e7
969dbdfed67fda40a6f5a2b4f8c4a3c7dc01e0fb
/src/ring_theory/discrete_valuation_ring.lean
43dc5b3b0e6a64bc8a4145ba51b4008e1a322fcd
[ "Apache-2.0" ]
permissive
SAAluthwela/mathlib
62044349d72dd63983a8500214736aa7779634d3
83a4b8b990907291421de54a78988c024dc8a552
refs/heads/master
1,679,433,873,417
1,615,998,031,000
1,615,998,031,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
16,257
lean
/- Copyright (c) 2020 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard -/ import ring_theory.principal_ideal_domain import order.conditionally_complete_lattice import ring_theory.multiplicity import ring_theory.valuation.basic /-! # Discrete valuation rings This file defines discrete valuation rings (DVRs) and develops a basic interface for them. ## Important definitions There are various definitions of a DVR in the literature; we define a DVR to be a local PID which is not a field (the first definition in Wikipedia) and prove that this is equivalent to being a PID with a unique non-zero prime ideal (the definition in Serre's book "Local Fields"). Let R be an integral domain, assumed to be a principal ideal ring and a local ring. * `discrete_valuation_ring R` : a predicate expressing that R is a DVR ### Definitions * `add_val R : add_valuation R enat` : the additive valuation on a DVR. ## Implementation notes It's a theorem that an element of a DVR is a uniformizer if and only if it's irreducible. We do not hence define `uniformizer` at all, because we can use `irreducible` instead. ## Tags discrete valuation ring -/ open_locale classical universe u open ideal local_ring /-- An integral domain is a *discrete valuation ring* (DVR) if it's a local PID which is not a field. -/ class discrete_valuation_ring (R : Type u) [integral_domain R] extends is_principal_ideal_ring R, local_ring R : Prop := (not_a_field' : maximal_ideal R ≠ ⊥) namespace discrete_valuation_ring variables (R : Type u) [integral_domain R] [discrete_valuation_ring R] lemma not_a_field : maximal_ideal R ≠ ⊥ := not_a_field' variable {R} open principal_ideal_ring /-- An element of a DVR is irreducible iff it is a uniformizer, that is, generates the maximal ideal of R -/ theorem irreducible_iff_uniformizer (ϖ : R) : irreducible ϖ ↔ maximal_ideal R = ideal.span {ϖ} := ⟨λ hϖ, (eq_maximal_ideal (is_maximal_of_irreducible hϖ)).symm, begin intro h, have h2 : ¬(is_unit ϖ) := show ϖ ∈ maximal_ideal R, from h.symm ▸ submodule.mem_span_singleton_self ϖ, refine ⟨h2, _⟩, intros a b hab, by_contra h, push_neg at h, obtain ⟨ha : a ∈ maximal_ideal R, hb : b ∈ maximal_ideal R⟩ := h, rw h at ha hb, rw mem_span_singleton' at ha hb, rcases ha with ⟨a, rfl⟩, rcases hb with ⟨b, rfl⟩, rw (show a * ϖ * (b * ϖ) = ϖ * (ϖ * (a * b)), by ring) at hab, have h3 := eq_zero_of_mul_eq_self_right _ hab.symm, { apply not_a_field R, simp [h, h3] }, { intro hh, apply h2, refine is_unit_of_dvd_one ϖ _, use a * b, exact hh.symm } end⟩ variable (R) /-- Uniformisers exist in a DVR -/ theorem exists_irreducible : ∃ ϖ : R, irreducible ϖ := by {simp_rw [irreducible_iff_uniformizer], exact (is_principal_ideal_ring.principal $ maximal_ideal R).principal} /-- Uniformisers exist in a DVR -/ theorem exists_prime : ∃ ϖ : R, prime ϖ := (exists_irreducible R).imp (λ _, principal_ideal_ring.irreducible_iff_prime.1) /-- an integral domain is a DVR iff it's a PID with a unique non-zero prime ideal -/ theorem iff_pid_with_one_nonzero_prime (R : Type u) [integral_domain R] : discrete_valuation_ring R ↔ is_principal_ideal_ring R ∧ ∃! P : ideal R, P ≠ ⊥ ∧ is_prime P := begin split, { intro RDVR, rcases id RDVR with ⟨RPID, Rlocal, Rnotafield⟩, split, assumption, resetI, use local_ring.maximal_ideal R, split, split, { assumption }, { apply_instance } , { rintro Q ⟨hQ1, hQ2⟩, obtain ⟨q, rfl⟩ := (is_principal_ideal_ring.principal Q).1, have hq : q ≠ 0, { rintro rfl, apply hQ1, simp }, erw span_singleton_prime hq at hQ2, replace hQ2 := irreducible_of_prime hQ2, rw irreducible_iff_uniformizer at hQ2, exact hQ2.symm } }, { rintro ⟨RPID, Punique⟩, haveI : local_ring R := local_of_unique_nonzero_prime R Punique, refine {not_a_field' := _}, rcases Punique with ⟨P, ⟨hP1, hP2⟩, hP3⟩, have hPM : P ≤ maximal_ideal R := le_maximal_ideal (hP2.1), intro h, rw [h, le_bot_iff] at hPM, exact hP1 hPM } end lemma associated_of_irreducible {a b : R} (ha : irreducible a) (hb : irreducible b) : associated a b := begin rw irreducible_iff_uniformizer at ha hb, rw [←span_singleton_eq_span_singleton, ←ha, hb], end end discrete_valuation_ring namespace discrete_valuation_ring variable (R : Type*) /-- Alternative characterisation of discrete valuation rings. -/ def has_unit_mul_pow_irreducible_factorization [integral_domain R] : Prop := ∃ p : R, irreducible p ∧ ∀ {x : R}, x ≠ 0 → ∃ (n : ℕ), associated (p ^ n) x namespace has_unit_mul_pow_irreducible_factorization variables {R} [integral_domain R] (hR : has_unit_mul_pow_irreducible_factorization R) include hR lemma unique_irreducible ⦃p q : R⦄ (hp : irreducible p) (hq : irreducible q) : associated p q := begin rcases hR with ⟨ϖ, hϖ, hR⟩, suffices : ∀ {p : R} (hp : irreducible p), associated p ϖ, { apply associated.trans (this hp) (this hq).symm, }, clear hp hq p q, intros p hp, obtain ⟨n, hn⟩ := hR hp.ne_zero, have : irreducible (ϖ ^ n) := irreducible_of_associated hn.symm hp, rcases lt_trichotomy n 1 with (H|rfl|H), { obtain rfl : n = 0, { clear hn this, revert H n, exact dec_trivial }, simpa only [not_irreducible_one, pow_zero] using this, }, { simpa only [pow_one] using hn.symm, }, { obtain ⟨n, rfl⟩ : ∃ k, n = 1 + k + 1 := nat.exists_eq_add_of_lt H, rw pow_succ at this, rcases this.is_unit_or_is_unit rfl with H0|H0, { exact (hϖ.not_unit H0).elim, }, { rw [add_comm, pow_succ] at H0, exact (hϖ.not_unit (is_unit_of_mul_is_unit_left H0)).elim } } end /-- An integral domain in which there is an irreducible element `p` such that every nonzero element is associated to a power of `p` is a unique factorization domain. See `discrete_valuation_ring.of_has_unit_mul_pow_irreducible_factorization`. -/ theorem to_unique_factorization_monoid : unique_factorization_monoid R := let p := classical.some hR in let spec := classical.some_spec hR in unique_factorization_monoid.of_exists_prime_factors $ λ x hx, begin use multiset.repeat p (classical.some (spec.2 hx)), split, { intros q hq, have hpq := multiset.eq_of_mem_repeat hq, rw hpq, refine ⟨spec.1.ne_zero, spec.1.not_unit, _⟩, intros a b h, by_cases ha : a = 0, { rw ha, simp only [true_or, dvd_zero], }, by_cases hb : b = 0, { rw hb, simp only [or_true, dvd_zero], }, obtain ⟨m, u, rfl⟩ := spec.2 ha, rw [mul_assoc, mul_left_comm, is_unit.dvd_mul_left _ _ _ (is_unit_unit _)] at h, rw is_unit.dvd_mul_right (is_unit_unit _), by_cases hm : m = 0, { simp only [hm, one_mul, pow_zero] at h ⊢, right, exact h }, left, obtain ⟨m, rfl⟩ := nat.exists_eq_succ_of_ne_zero hm, apply dvd_mul_of_dvd_left (dvd_refl _) _ }, { rw [multiset.prod_repeat], exact (classical.some_spec (spec.2 hx)), } end omit hR lemma of_ufd_of_unique_irreducible [unique_factorization_monoid R] (h₁ : ∃ p : R, irreducible p) (h₂ : ∀ ⦃p q : R⦄, irreducible p → irreducible q → associated p q) : has_unit_mul_pow_irreducible_factorization R := begin obtain ⟨p, hp⟩ := h₁, refine ⟨p, hp, _⟩, intros x hx, cases wf_dvd_monoid.exists_factors x hx with fx hfx, refine ⟨fx.card, _⟩, have H := hfx.2, rw ← associates.mk_eq_mk_iff_associated at H ⊢, rw [← H, ← associates.prod_mk, associates.mk_pow, ← multiset.prod_repeat], congr' 1, symmetry, rw multiset.eq_repeat, simp only [true_and, and_imp, multiset.card_map, eq_self_iff_true, multiset.mem_map, exists_imp_distrib], rintros _ q hq rfl, rw associates.mk_eq_mk_iff_associated, apply h₂ (hfx.1 _ hq) hp, end end has_unit_mul_pow_irreducible_factorization lemma aux_pid_of_ufd_of_unique_irreducible (R : Type u) [integral_domain R] [unique_factorization_monoid R] (h₁ : ∃ p : R, irreducible p) (h₂ : ∀ ⦃p q : R⦄, irreducible p → irreducible q → associated p q) : is_principal_ideal_ring R := begin constructor, intro I, by_cases I0 : I = ⊥, { rw I0, use 0, simp only [set.singleton_zero, submodule.span_zero], }, obtain ⟨x, hxI, hx0⟩ : ∃ x ∈ I, x ≠ (0:R) := I.ne_bot_iff.mp I0, obtain ⟨p, hp, H⟩ := has_unit_mul_pow_irreducible_factorization.of_ufd_of_unique_irreducible h₁ h₂, have ex : ∃ n : ℕ, p ^ n ∈ I, { obtain ⟨n, u, rfl⟩ := H hx0, refine ⟨n, _⟩, simpa only [units.mul_inv_cancel_right] using I.mul_mem_right ↑u⁻¹ hxI, }, constructor, use p ^ (nat.find ex), show I = ideal.span _, apply le_antisymm, { intros r hr, by_cases hr0 : r = 0, { simp only [hr0, submodule.zero_mem], }, obtain ⟨n, u, rfl⟩ := H hr0, simp only [mem_span_singleton, is_unit_unit, is_unit.dvd_mul_right], apply pow_dvd_pow, apply nat.find_min', simpa only [units.mul_inv_cancel_right] using I.mul_mem_right ↑u⁻¹ hr, }, { erw submodule.span_singleton_le_iff_mem, exact nat.find_spec ex, }, end /-- A unique factorization domain with at least one irreducible element in which all irreducible elements are associated is a discrete valuation ring. -/ lemma of_ufd_of_unique_irreducible {R : Type u} [integral_domain R] [unique_factorization_monoid R] (h₁ : ∃ p : R, irreducible p) (h₂ : ∀ ⦃p q : R⦄, irreducible p → irreducible q → associated p q) : discrete_valuation_ring R := begin rw iff_pid_with_one_nonzero_prime, haveI PID : is_principal_ideal_ring R := aux_pid_of_ufd_of_unique_irreducible R h₁ h₂, obtain ⟨p, hp⟩ := h₁, refine ⟨PID, ⟨ideal.span {p}, ⟨_, _⟩, _⟩⟩, { rw submodule.ne_bot_iff, refine ⟨p, ideal.mem_span_singleton.mpr (dvd_refl p), hp.ne_zero⟩, }, { rwa [ideal.span_singleton_prime hp.ne_zero, ← unique_factorization_monoid.irreducible_iff_prime], }, { intro I, rw ← submodule.is_principal.span_singleton_generator I, rintro ⟨I0, hI⟩, apply span_singleton_eq_span_singleton.mpr, apply h₂ _ hp, erw [ne.def, span_singleton_eq_bot] at I0, rwa [unique_factorization_monoid.irreducible_iff_prime, ← ideal.span_singleton_prime I0], }, end /-- An integral domain in which there is an irreducible element `p` such that every nonzero element is associated to a power of `p` is a discrete valuation ring. -/ lemma of_has_unit_mul_pow_irreducible_factorization {R : Type u} [integral_domain R] (hR : has_unit_mul_pow_irreducible_factorization R) : discrete_valuation_ring R := begin letI : unique_factorization_monoid R := hR.to_unique_factorization_monoid, apply of_ufd_of_unique_irreducible _ hR.unique_irreducible, unfreezingI { obtain ⟨p, hp, H⟩ := hR, exact ⟨p, hp⟩, }, end section variables [integral_domain R] [discrete_valuation_ring R] variable {R} lemma associated_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : irreducible ϖ) : ∃ (n : ℕ), associated x (ϖ ^ n) := begin have : wf_dvd_monoid R := is_noetherian_ring.wf_dvd_monoid, cases wf_dvd_monoid.exists_factors x hx with fx hfx, unfreezingI { use fx.card }, have H := hfx.2, rw ← associates.mk_eq_mk_iff_associated at H ⊢, rw [← H, ← associates.prod_mk, associates.mk_pow, ← multiset.prod_repeat], congr' 1, rw multiset.eq_repeat, simp only [true_and, and_imp, multiset.card_map, eq_self_iff_true, multiset.mem_map, exists_imp_distrib], rintros _ _ _ rfl, rw associates.mk_eq_mk_iff_associated, refine associated_of_irreducible _ _ hirr, apply hfx.1, assumption end lemma eq_unit_mul_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : irreducible ϖ) : ∃ (n : ℕ) (u : units R), x = u * ϖ ^ n := begin obtain ⟨n, hn⟩ := associated_pow_irreducible hx hirr, obtain ⟨u, rfl⟩ := hn.symm, use [n, u], apply mul_comm, end open submodule.is_principal lemma ideal_eq_span_pow_irreducible {s : ideal R} (hs : s ≠ ⊥) {ϖ : R} (hirr : irreducible ϖ) : ∃ n : ℕ, s = ideal.span {ϖ ^ n} := begin have gen_ne_zero : generator s ≠ 0, { rw [ne.def, ← eq_bot_iff_generator_eq_zero], assumption }, rcases associated_pow_irreducible gen_ne_zero hirr with ⟨n, u, hnu⟩, use n, have : span _ = _ := span_singleton_generator s, rw [← this, ← hnu, span_singleton_eq_span_singleton], use u end lemma unit_mul_pow_congr_pow {p q : R} (hp : irreducible p) (hq : irreducible q) (u v : units R) (m n : ℕ) (h : ↑u * p ^ m = v * q ^ n) : m = n := begin have key : associated (multiset.repeat p m).prod (multiset.repeat q n).prod, { rw [multiset.prod_repeat, multiset.prod_repeat, associated], refine ⟨u * v⁻¹, _⟩, simp only [units.coe_mul], rw [mul_left_comm, ← mul_assoc, h, mul_right_comm, units.mul_inv, one_mul], }, have := multiset.card_eq_card_of_rel (unique_factorization_monoid.factors_unique _ _ key), { simpa only [multiset.card_repeat] }, all_goals { intros x hx, replace hx := multiset.eq_of_mem_repeat hx, unfreezingI { subst hx, assumption } }, end lemma unit_mul_pow_congr_unit {ϖ : R} (hirr : irreducible ϖ) (u v : units R) (m n : ℕ) (h : ↑u * ϖ ^ m = v * ϖ ^ n) : u = v := begin obtain rfl : m = n := unit_mul_pow_congr_pow hirr hirr u v m n h, rw ← sub_eq_zero at h, rw [← sub_mul, mul_eq_zero] at h, cases h, { rw sub_eq_zero at h, exact_mod_cast h }, { apply (hirr.ne_zero (pow_eq_zero h)).elim, } end /-! ## The additive valuation on a DVR -/ open multiplicity /-- The `enat`-valued additive valuation on a DVR -/ noncomputable def add_val (R : Type u) [integral_domain R] [discrete_valuation_ring R] : add_valuation R enat := add_valuation (classical.some_spec (exists_prime R)) lemma add_val_def (r : R) (u : units R) {ϖ : R} (hϖ : irreducible ϖ) (n : ℕ) (hr : r = u * ϖ ^ n) : add_val R r = n := by rw [add_val, add_valuation_apply, hr, eq_of_associated_left (associated_of_irreducible R hϖ (irreducible_of_prime (classical.some_spec (exists_prime R)))), eq_of_associated_right (associated.symm ⟨u, mul_comm _ _⟩), multiplicity_pow_self_of_prime (principal_ideal_ring.irreducible_iff_prime.1 hϖ)] lemma add_val_def' (u : units R) {ϖ : R} (hϖ : irreducible ϖ) (n : ℕ) : add_val R ((u : R) * ϖ ^ n) = n := add_val_def _ u hϖ n rfl @[simp] lemma add_val_zero : add_val R 0 = ⊤ := (add_val R).map_zero @[simp] lemma add_val_one : add_val R 1 = 0 := (add_val R).map_one @[simp] lemma add_val_uniformizer {ϖ : R} (hϖ : irreducible ϖ) : add_val R ϖ = 1 := add_val_def ϖ 1 hϖ 1 (by simp) @[simp] lemma add_val_mul {a b : R} : add_val R (a * b) = add_val R a + add_val R b := (add_val R).map_mul _ _ lemma add_val_pow (a : R) (n : ℕ) : add_val R (a ^ n) = n • add_val R a := (add_val R).map_pow _ _ lemma add_val_eq_top_iff {a : R} : add_val R a = ⊤ ↔ a = 0 := begin have hi := (irreducible_of_prime (classical.some_spec (exists_prime R))), split, { contrapose, intro h, obtain ⟨n, ha⟩ := associated_pow_irreducible h hi, obtain ⟨u, rfl⟩ := ha.symm, rw [mul_comm, add_val_def' u hi n], exact enat.coe_ne_top _ }, { rintro rfl, exact add_val_zero } end lemma add_val_le_iff_dvd {a b : R} : add_val R a ≤ add_val R b ↔ a ∣ b := begin have hp := classical.some_spec (exists_prime R), split; intro h, { by_cases ha0 : a = 0, { rw [ha0, add_val_zero, top_le_iff, add_val_eq_top_iff] at h, rw h, apply dvd_zero }, obtain ⟨n, ha⟩ := associated_pow_irreducible ha0 (irreducible_of_prime hp), rw [add_val, add_valuation_apply, add_valuation_apply, multiplicity_le_multiplicity_iff] at h, exact dvd.trans (dvd_of_associated ha) (h n (dvd_of_associated ha.symm)), }, { rw [add_val, add_valuation_apply, add_valuation_apply], exact multiplicity_le_multiplicity_of_dvd_right h } end lemma add_val_add {a b : R} : min (add_val R a) (add_val R b) ≤ add_val R (a + b) := (add_val R).map_add _ _ end end discrete_valuation_ring
913996c6bd48bf1e300adb22a765664408ff79e4
8cb37a089cdb4af3af9d8bf1002b417e407a8e9e
/library/init/cc_lemmas.lean
25b276c849a53afa6231e65415f4f4cdfc2826a7
[ "Apache-2.0" ]
permissive
kbuzzard/lean
ae3c3db4bb462d750dbf7419b28bafb3ec983ef7
ed1788fd674bb8991acffc8fca585ec746711928
refs/heads/master
1,620,983,366,617
1,618,937,600,000
1,618,937,600,000
359,886,396
1
0
Apache-2.0
1,618,936,987,000
1,618,936,987,000
null
UTF-8
Lean
false
false
4,653
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import init.propext init.classical /- Lemmas use by the congruence closure module -/ lemma iff_eq_of_eq_true_left {a b : Prop} (h : a = true) : (a ↔ b) = b := h.symm ▸ propext (true_iff _) lemma iff_eq_of_eq_true_right {a b : Prop} (h : b = true) : (a ↔ b) = a := h.symm ▸ propext (iff_true _) lemma iff_eq_true_of_eq {a b : Prop} (h : a = b) : (a ↔ b) = true := h ▸ propext (iff_self _) lemma and_eq_of_eq_true_left {a b : Prop} (h : a = true) : (a ∧ b) = b := h.symm ▸ propext (true_and _) lemma and_eq_of_eq_true_right {a b : Prop} (h : b = true) : (a ∧ b) = a := h.symm ▸ propext (and_true _) lemma and_eq_of_eq_false_left {a b : Prop} (h : a = false) : (a ∧ b) = false := h.symm ▸ propext (false_and _) lemma and_eq_of_eq_false_right {a b : Prop} (h : b = false) : (a ∧ b) = false := h.symm ▸ propext (and_false _) lemma and_eq_of_eq {a b : Prop} (h : a = b) : (a ∧ b) = a := h ▸ propext (and_self _) lemma or_eq_of_eq_true_left {a b : Prop} (h : a = true) : (a ∨ b) = true := h.symm ▸ propext (true_or _) lemma or_eq_of_eq_true_right {a b : Prop} (h : b = true) : (a ∨ b) = true := h.symm ▸ propext (or_true _) lemma or_eq_of_eq_false_left {a b : Prop} (h : a = false) : (a ∨ b) = b := h.symm ▸ propext (false_or _) lemma or_eq_of_eq_false_right {a b : Prop} (h : b = false) : (a ∨ b) = a := h.symm ▸ propext (or_false _) lemma or_eq_of_eq {a b : Prop} (h : a = b) : (a ∨ b) = a := h ▸ propext (or_self _) lemma imp_eq_of_eq_true_left {a b : Prop} (h : a = true) : (a → b) = b := h.symm ▸ propext (iff.intro (λ h, h trivial) (λ h₁ h₂, h₁)) lemma imp_eq_of_eq_true_right {a b : Prop} (h : b = true) : (a → b) = true := h.symm ▸ propext (iff.intro (λ h, trivial) (λ h₁ h₂, h₁)) lemma imp_eq_of_eq_false_left {a b : Prop} (h : a = false) : (a → b) = true := h.symm ▸ propext (iff.intro (λ h, trivial) (λ h₁ h₂, false.elim h₂)) lemma imp_eq_of_eq_false_right {a b : Prop} (h : b = false) : (a → b) = not a := h.symm ▸ propext (iff.intro (λ h, h) (λ hna ha, hna ha)) /- Remark: the congruence closure module will only use the following lemma is cc_config.em is tt. -/ lemma not_imp_eq_of_eq_false_right {a b : Prop} (h : b = false) : (not a → b) = a := h.symm ▸ propext (iff.intro (λ h', classical.by_contradiction (λ hna, h' hna)) (λ ha hna, hna ha)) lemma imp_eq_true_of_eq {a b : Prop} (h : a = b) : (a → b) = true := h ▸ propext (iff.intro (λ h, trivial) (λ h ha, ha)) lemma not_eq_of_eq_true {a : Prop} (h : a = true) : (not a) = false := h.symm ▸ propext not_true lemma not_eq_of_eq_false {a : Prop} (h : a = false) : (not a) = true := h.symm ▸ propext not_false_iff lemma false_of_a_eq_not_a {a : Prop} (h : a = not a) : false := have not a, from λ ha, absurd ha (eq.mp h ha), absurd (eq.mpr h this) this universes u lemma if_eq_of_eq_true {c : Prop} [d : decidable c] {α : Sort u} (t e : α) (h : c = true) : (@ite α c d t e) = t := if_pos (of_eq_true h) lemma if_eq_of_eq_false {c : Prop} [d : decidable c] {α : Sort u} (t e : α) (h : c = false) : (@ite α c d t e) = e := if_neg (not_of_eq_false h) lemma if_eq_of_eq (c : Prop) [d : decidable c] {α : Sort u} {t e : α} (h : t = e) : (@ite α c d t e) = t := match d with | (is_true hc) := rfl | (is_false hnc) := eq.symm h end lemma eq_true_of_and_eq_true_left {a b : Prop} (h : (a ∧ b) = true) : a = true := eq_true_intro (and.left (of_eq_true h)) lemma eq_true_of_and_eq_true_right {a b : Prop} (h : (a ∧ b) = true) : b = true := eq_true_intro (and.right (of_eq_true h)) lemma eq_false_of_or_eq_false_left {a b : Prop} (h : (a ∨ b) = false) : a = false := eq_false_intro (λ ha, false.elim (eq.mp h (or.inl ha))) lemma eq_false_of_or_eq_false_right {a b : Prop} (h : (a ∨ b) = false) : b = false := eq_false_intro (λ hb, false.elim (eq.mp h (or.inr hb))) lemma eq_false_of_not_eq_true {a : Prop} (h : (not a) = true) : a = false := eq_false_intro (λ ha, absurd ha (eq.mpr h trivial)) /- Remark: the congruence closure module will only use the following lemma is cc_config.em is tt. -/ lemma eq_true_of_not_eq_false {a : Prop} (h : (not a) = false) : a = true := eq_true_intro (classical.by_contradiction (λ hna, eq.mp h hna)) lemma ne_of_eq_of_ne {α : Sort u} {a b c : α} (h₁ : a = b) (h₂ : b ≠ c) : a ≠ c := h₁.symm ▸ h₂ lemma ne_of_ne_of_eq {α : Sort u} {a b c : α} (h₁ : a ≠ b) (h₂ : b = c) : a ≠ c := h₂ ▸ h₁
d2153bc80c106e90d25671b52b4f2b4f999e7902
ac89c256db07448984849346288e0eeffe8b20d0
/src/Lean/Elab/DeclModifiers.lean
e241a6de6b5a7ea518bb2f465fd14a24d3e7b54e
[ "Apache-2.0" ]
permissive
chepinzhang/lean4
002cc667f35417a418f0ebc9cb4a44559bb0ccac
24fe2875c68549b5481f07c57eab4ad4a0ae5305
refs/heads/master
1,688,942,838,326
1,628,801,942,000
1,628,801,995,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
7,050
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Sebastian Ullrich -/ import Lean.Modifiers import Lean.DocString import Lean.Elab.Attributes import Lean.Elab.Exception import Lean.Elab.DeclUtil namespace Lean.Elab def checkNotAlreadyDeclared {m} [Monad m] [MonadEnv m] [MonadError m] (declName : Name) : m Unit := do let env ← getEnv if env.contains declName then match privateToUserName? declName with | none => throwError "'{declName}' has already been declared" | some declName => throwError "private declaration '{declName}' has already been declared" if env.contains (mkPrivateName env declName) then throwError "a private declaration '{declName}' has already been declared" match privateToUserName? declName with | none => pure () | some declName => if env.contains declName then throwError "a non-private declaration '{declName}' has already been declared" inductive Visibility where | regular | «protected» | «private» deriving Inhabited instance : ToString Visibility := ⟨fun | Visibility.regular => "regular" | Visibility.«private» => "private" | Visibility.«protected» => "protected"⟩ structure Modifiers where docString? : Option String := none visibility : Visibility := Visibility.regular isNoncomputable : Bool := false isPartial : Bool := false isUnsafe : Bool := false attrs : Array Attribute := #[] deriving Inhabited def Modifiers.isPrivate : Modifiers → Bool | { visibility := Visibility.private, .. } => true | _ => false def Modifiers.isProtected : Modifiers → Bool | { visibility := Visibility.protected, .. } => true | _ => false def Modifiers.addAttribute (modifiers : Modifiers) (attr : Attribute) : Modifiers := { modifiers with attrs := modifiers.attrs.push attr } instance : ToFormat Modifiers := ⟨fun m => let components : List Format := (match m.docString? with | some str => [f!"/--{str}-/"] | none => []) ++ (match m.visibility with | Visibility.regular => [] | Visibility.protected => [f!"protected"] | Visibility.private => [f!"private"]) ++ (if m.isNoncomputable then [f!"noncomputable"] else []) ++ (if m.isPartial then [f!"partial"] else []) ++ (if m.isUnsafe then [f!"unsafe"] else []) ++ m.attrs.toList.map (fun attr => format attr) Format.bracket "{" (Format.joinSep components ("," ++ Format.line)) "}"⟩ instance : ToString Modifiers := ⟨toString ∘ format⟩ def expandOptDocComment? [Monad m] [MonadError m] (optDocComment : Syntax) : m (Option String) := match optDocComment.getOptional? with | none => pure none | some s => match s[1] with | Syntax.atom _ val => pure (some (val.extract 0 (val.bsize - 2))) | _ => throwErrorAt s "unexpected doc string{indentD s[1]}" section Methods variable [Monad m] [MonadEnv m] [MonadResolveName m] [MonadError m] [MonadMacroAdapter m] [MonadRecDepth m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] def elabModifiers (stx : Syntax) : m Modifiers := do let docCommentStx := stx[0] let attrsStx := stx[1] let visibilityStx := stx[2] let noncompStx := stx[3] let unsafeStx := stx[4] let partialStx := stx[5] let docString? ← match docCommentStx.getOptional? with | none => pure none | some s => match s[1] with | Syntax.atom _ val => pure (some (val.extract 0 (val.bsize - 2))) | _ => throwErrorAt s "unexpected doc string{indentD s[1]}" let visibility ← match visibilityStx.getOptional? with | none => pure Visibility.regular | some v => let kind := v.getKind if kind == `Lean.Parser.Command.private then pure Visibility.private else if kind == `Lean.Parser.Command.protected then pure Visibility.protected else throwErrorAt v "unexpected visibility modifier" let attrs ← match attrsStx.getOptional? with | none => pure #[] | some attrs => elabDeclAttrs attrs pure { docString? := docString?, visibility := visibility, isPartial := !partialStx.isNone, isUnsafe := !unsafeStx.isNone, isNoncomputable := !noncompStx.isNone, attrs := attrs } def applyVisibility (visibility : Visibility) (declName : Name) : m Name := do match visibility with | Visibility.private => let env ← getEnv let declName := mkPrivateName env declName checkNotAlreadyDeclared declName pure declName | Visibility.protected => checkNotAlreadyDeclared declName let env ← getEnv let env := addProtected env declName setEnv env pure declName | _ => checkNotAlreadyDeclared declName pure declName def mkDeclName (currNamespace : Name) (modifiers : Modifiers) (shortName : Name) : m (Name × Name) := do let name := (extractMacroScopes shortName).name unless name.isAtomic || isFreshInstanceName name do throwError "atomic identifier expected '{shortName}'" let declName := currNamespace ++ shortName let declName ← applyVisibility modifiers.visibility declName match modifiers.visibility with | Visibility.protected => match currNamespace with | Name.str _ s _ => pure (declName, Name.mkSimple s ++ shortName) | _ => throwError "protected declarations must be in a namespace" | _ => pure (declName, shortName) /- `declId` is of the form ``` leading_parser ident >> optional (".{" >> sepBy1 ident ", " >> "}") ``` but we also accept a single identifier to users to make macro writing more convenient . -/ def expandDeclIdCore (declId : Syntax) : Name × Syntax := if declId.isIdent then (declId.getId, mkNullNode) else let id := declId[0].getId let optUnivDeclStx := declId[1] (id, optUnivDeclStx) structure ExpandDeclIdResult where shortName : Name declName : Name levelNames : List Name def expandDeclId (currNamespace : Name) (currLevelNames : List Name) (declId : Syntax) (modifiers : Modifiers) : m ExpandDeclIdResult := do -- ident >> optional (".{" >> sepBy1 ident ", " >> "}") let (shortName, optUnivDeclStx) := expandDeclIdCore declId let levelNames ← if optUnivDeclStx.isNone then pure currLevelNames else let extraLevels := optUnivDeclStx[1].getArgs.getEvenElems extraLevels.foldlM (fun levelNames idStx => let id := idStx.getId if levelNames.elem id then withRef idStx $ throwAlreadyDeclaredUniverseLevel id else pure (id :: levelNames)) currLevelNames let (declName, shortName) ← withRef declId $ mkDeclName currNamespace modifiers shortName addDocString' declName modifiers.docString? pure { shortName := shortName, declName := declName, levelNames := levelNames } end Methods end Lean.Elab
ea188f9b6a820788f35555145827ead55bb800d8
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/src/Lean/Meta/Match.lean
676da5b6b7e8a39923fe17bf498a73b4662f4fe8
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
leanprover/lean4
4bdf9790294964627eb9be79f5e8f6157780b4cc
f1f9dc0f2f531af3312398999d8b8303fa5f096b
refs/heads/master
1,693,360,665,786
1,693,350,868,000
1,693,350,868,000
129,571,436
2,827
311
Apache-2.0
1,694,716,156,000
1,523,760,560,000
Lean
UTF-8
Lean
false
false
414
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Meta.Match.MatchPatternAttr import Lean.Meta.Match.Match import Lean.Meta.Match.CaseValues import Lean.Meta.Match.CaseArraySizes import Lean.Meta.Match.MatchEqs namespace Lean builtin_initialize registerTraceClass `Meta.Match end Lean
46d0dff5e78fce0192b953decc3f84c117736218
22e97a5d648fc451e25a06c668dc03ac7ed7bc25
/src/ring_theory/polynomial.lean
acb707d31a442519e6b2baa82bd16c58378b9e6e
[ "Apache-2.0" ]
permissive
keeferrowan/mathlib
f2818da875dbc7780830d09bd4c526b0764a4e50
aad2dfc40e8e6a7e258287a7c1580318e865817e
refs/heads/master
1,661,736,426,952
1,590,438,032,000
1,590,438,032,000
266,892,663
0
0
Apache-2.0
1,590,445,835,000
1,590,445,835,000
null
UTF-8
Lean
false
false
17,126
lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau Ring-theoretic supplement of data.polynomial. Main result: Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring. -/ import data.mv_polynomial import ring_theory.noetherian noncomputable theory local attribute [instance, priority 100] classical.prop_decidable universes u v w namespace polynomial variables (R : Type u) [comm_ring R] /-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/ def degree_le (n : with_bot ℕ) : submodule R (polynomial R) := ⨅ k : ℕ, ⨅ h : ↑k > n, (lcoeff R k).ker variable {R} theorem mem_degree_le {n : with_bot ℕ} {f : polynomial R} : f ∈ degree_le R n ↔ degree f ≤ n := by simp only [degree_le, submodule.mem_infi, degree_le_iff_coeff_zero, linear_map.mem_ker]; refl theorem degree_le_mono {m n : with_bot ℕ} (H : m ≤ n) : degree_le R m ≤ degree_le R n := λ f hf, mem_degree_le.2 (le_trans (mem_degree_le.1 hf) H) theorem degree_le_eq_span_X_pow {n : ℕ} : degree_le R n = submodule.span R ↑((finset.range (n+1)).image (λ n, X^n) : finset (polynomial R)) := begin apply le_antisymm, { intros p hp, replace hp := mem_degree_le.1 hp, rw [← finsupp.sum_single p, finsupp.sum], refine submodule.sum_mem _ (λ k hk, _), show monomial _ _ ∈ _, have := with_bot.coe_le_coe.1 (finset.sup_le_iff.1 hp k hk), rw [single_eq_C_mul_X, C_mul'], refine submodule.smul_mem _ _ (submodule.subset_span $ finset.mem_coe.2 $ finset.mem_image.2 ⟨_, finset.mem_range.2 (nat.lt_succ_of_le this), rfl⟩) }, rw [submodule.span_le, finset.coe_image, set.image_subset_iff], intros k hk, apply mem_degree_le.2, apply le_trans (degree_X_pow_le _) (with_bot.coe_le_coe.2 $ nat.le_of_lt_succ $ finset.mem_range.1 hk) end /-- Given a polynomial, return the polynomial whose coefficients are in the ring closure of the original coefficients. -/ def restriction (p : polynomial R) : polynomial (ring.closure (↑p.frange : set R)) := ⟨p.support, λ i, ⟨p.to_fun i, if H : p.to_fun i = 0 then H.symm ▸ is_add_submonoid.zero_mem else ring.subset_closure $ finsupp.mem_frange.2 ⟨H, i, rfl⟩⟩, λ i, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ H, subtype.eq H, subtype.mk.inj⟩)⟩ @[simp] theorem coeff_restriction {p : polynomial R} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := rfl @[simp] theorem coeff_restriction' {p : polynomial R} {n : ℕ} : (coeff (restriction p) n).1 = coeff p n := rfl @[simp] theorem degree_restriction {p : polynomial R} : (restriction p).degree = p.degree := rfl @[simp] theorem nat_degree_restriction {p : polynomial R} : (restriction p).nat_degree = p.nat_degree := rfl @[simp] theorem monic_restriction {p : polynomial R} : monic (restriction p) ↔ monic p := ⟨λ H, congr_arg subtype.val H, λ H, subtype.eq H⟩ @[simp] theorem restriction_zero : restriction (0 : polynomial R) = 0 := rfl @[simp] theorem restriction_one : restriction (1 : polynomial R) = 1 := ext $ λ i, subtype.eq $ by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs; refl variables {S : Type v} [comm_ring S] {f : R → S} {x : S} theorem eval₂_restriction {p : polynomial R} : eval₂ f x p = eval₂ (f ∘ subtype.val) x p.restriction := rfl section to_subring variables (p : polynomial R) (T : set R) [is_subring T] /-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`, return the corresponding polynomial whose coefficients are in `T. -/ def to_subring (hp : ↑p.frange ⊆ T) : polynomial T := ⟨p.support, λ i, ⟨p.to_fun i, if H : p.to_fun i = 0 then H.symm ▸ is_add_submonoid.zero_mem else hp $ finsupp.mem_frange.2 ⟨H, i, rfl⟩⟩, λ i, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ H, subtype.eq H, subtype.mk.inj⟩)⟩ variables (hp : ↑p.frange ⊆ T) include hp @[simp] theorem coeff_to_subring {n : ℕ} : ↑(coeff (to_subring p T hp) n) = coeff p n := rfl @[simp] theorem coeff_to_subring' {n : ℕ} : (coeff (to_subring p T hp) n).1 = coeff p n := rfl @[simp] theorem degree_to_subring : (to_subring p T hp).degree = p.degree := rfl @[simp] theorem nat_degree_to_subring : (to_subring p T hp).nat_degree = p.nat_degree := rfl @[simp] theorem monic_to_subring : monic (to_subring p T hp) ↔ monic p := ⟨λ H, congr_arg subtype.val H, λ H, subtype.eq H⟩ omit hp @[simp] theorem to_subring_zero : to_subring (0 : polynomial R) T (set.empty_subset _) = 0 := rfl @[simp] theorem to_subring_one : to_subring (1 : polynomial R) T (set.subset.trans (finset.coe_subset.2 finsupp.frange_single) (finset.singleton_subset_set_iff.2 is_submonoid.one_mem)) = 1 := ext $ λ i, subtype.eq $ by rw [coeff_to_subring', coeff_one, coeff_one]; split_ifs; refl end to_subring variables (T : set R) [is_subring T] /-- Given a polynomial whose coefficients are in some subring, return the corresponding polynomial whose coefificents are in the ambient ring. -/ def of_subring (p : polynomial T) : polynomial R := ⟨p.support, subtype.val ∘ p.to_fun, λ n, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ h, congr_arg subtype.val h, λ h, subtype.eq h⟩)⟩ @[simp] theorem frange_of_subring {p : polynomial T} : ↑(p.of_subring T).frange ⊆ T := λ y H, let ⟨hy, x, hx⟩ := finsupp.mem_frange.1 H in hx ▸ (p.to_fun x).2 end polynomial variables {R : Type u} {σ : Type v} [comm_ring R] namespace ideal open polynomial /-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/ def of_polynomial (I : ideal (polynomial R)) : submodule R (polynomial R) := { carrier := I.carrier, zero := I.zero_mem, add := λ _ _, I.add_mem, smul := λ c x H, by rw [← C_mul']; exact submodule.smul_mem _ _ H } variables {I : ideal (polynomial R)} theorem mem_of_polynomial (x) : x ∈ I.of_polynomial ↔ x ∈ I := iff.rfl variables (I) /-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I` consisting of polynomials of degree ≤ `n`. -/ def degree_le (n : with_bot ℕ) : submodule R (polynomial R) := degree_le R n ⊓ I.of_polynomial /-- Given an ideal `I` of `R[X]`, make the ideal in `R` of leading coefficients of polynomials in `I` with degree ≤ `n`. -/ def leading_coeff_nth (n : ℕ) : ideal R := (I.degree_le n).map $ lcoeff R n theorem mem_leading_coeff_nth (n : ℕ) (x) : x ∈ I.leading_coeff_nth n ↔ ∃ p ∈ I, degree p ≤ n ∧ leading_coeff p = x := begin simp only [leading_coeff_nth, degree_le, submodule.mem_map, lcoeff_apply, submodule.mem_inf, mem_degree_le], split, { rintro ⟨p, ⟨hpdeg, hpI⟩, rfl⟩, cases lt_or_eq_of_le hpdeg with hpdeg hpdeg, { refine ⟨0, I.zero_mem, bot_le, _⟩, rw [leading_coeff_zero, eq_comm], exact coeff_eq_zero_of_degree_lt hpdeg }, { refine ⟨p, hpI, le_of_eq hpdeg, _⟩, rw [leading_coeff, nat_degree, hpdeg], refl } }, { rintro ⟨p, hpI, hpdeg, rfl⟩, have : nat_degree p + (n - nat_degree p) = n, { exact nat.add_sub_cancel' (nat_degree_le_of_degree_le hpdeg) }, refine ⟨p * X ^ (n - nat_degree p), ⟨_, I.mul_mem_right hpI⟩, _⟩, { apply le_trans (degree_mul_le _ _) _, apply le_trans (add_le_add' (degree_le_nat_degree) (degree_X_pow_le _)) _, rw [← with_bot.coe_add, this], exact le_refl _ }, { rw [leading_coeff, ← coeff_mul_X_pow p (n - nat_degree p), this] } } end theorem mem_leading_coeff_nth_zero (x) : x ∈ I.leading_coeff_nth 0 ↔ C x ∈ I := (mem_leading_coeff_nth _ _ _).trans ⟨λ ⟨p, hpI, hpdeg, hpx⟩, by rwa [← hpx, leading_coeff, nat.eq_zero_of_le_zero (nat_degree_le_of_degree_le hpdeg), ← eq_C_of_degree_le_zero hpdeg], λ hx, ⟨C x, hx, degree_C_le, leading_coeff_C x⟩⟩ theorem leading_coeff_nth_mono {m n : ℕ} (H : m ≤ n) : I.leading_coeff_nth m ≤ I.leading_coeff_nth n := begin intros r hr, simp only [submodule.mem_coe, mem_leading_coeff_nth] at hr ⊢, rcases hr with ⟨p, hpI, hpdeg, rfl⟩, refine ⟨p * X ^ (n - m), I.mul_mem_right hpI, _, leading_coeff_mul_X_pow⟩, refine le_trans (degree_mul_le _ _) _, refine le_trans (add_le_add' hpdeg (degree_X_pow_le _)) _, rw [← with_bot.coe_add, nat.add_sub_cancel' H], exact le_refl _ end /-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the leading coefficients in `I`. -/ def leading_coeff : ideal R := ⨆ n : ℕ, I.leading_coeff_nth n theorem mem_leading_coeff (x) : x ∈ I.leading_coeff ↔ ∃ p ∈ I, polynomial.leading_coeff p = x := begin rw [leading_coeff, submodule.mem_supr_of_directed], simp only [mem_leading_coeff_nth], { split, { rintro ⟨i, p, hpI, hpdeg, rfl⟩, exact ⟨p, hpI, rfl⟩ }, rintro ⟨p, hpI, rfl⟩, exact ⟨nat_degree p, p, hpI, degree_le_nat_degree, rfl⟩ }, intros i j, exact ⟨i + j, I.leading_coeff_nth_mono (nat.le_add_right _ _), I.leading_coeff_nth_mono (nat.le_add_left _ _)⟩ end theorem is_fg_degree_le [is_noetherian_ring R] (n : ℕ) : submodule.fg (I.degree_le n) := is_noetherian_submodule_left.1 (is_noetherian_of_fg_of_noetherian _ ⟨_, degree_le_eq_span_X_pow.symm⟩) _ end ideal /-- Hilbert basis theorem: a polynomial ring over a noetherian ring is a noetherian ring. -/ protected theorem polynomial.is_noetherian_ring [is_noetherian_ring R] : is_noetherian_ring (polynomial R) := ⟨assume I : ideal (polynomial R), let L := I.leading_coeff in let M := well_founded.min (is_noetherian_iff_well_founded.1 (by apply_instance)) (set.range I.leading_coeff_nth) ⟨_, ⟨0, rfl⟩⟩ in have hm : M ∈ set.range I.leading_coeff_nth := well_founded.min_mem _ _ _, let ⟨N, HN⟩ := hm, ⟨s, hs⟩ := I.is_fg_degree_le N in have hm2 : ∀ k, I.leading_coeff_nth k ≤ M := λ k, or.cases_on (le_or_lt k N) (λ h, HN ▸ I.leading_coeff_nth_mono h) (λ h x hx, classical.by_contradiction $ λ hxm, have ¬M < I.leading_coeff_nth k, by refine well_founded.not_lt_min (well_founded_submodule_gt _ _) _ _ _; exact ⟨k, rfl⟩, this ⟨HN ▸ I.leading_coeff_nth_mono (le_of_lt h), λ H, hxm (H hx)⟩), have hs2 : ∀ {x}, x ∈ I.degree_le N → x ∈ ideal.span (↑s : set (polynomial R)), from hs ▸ λ x hx, submodule.span_induction hx (λ _ hx, ideal.subset_span hx) (ideal.zero_mem _) (λ _ _, ideal.add_mem _) (λ c f hf, f.C_mul' c ▸ ideal.mul_mem_left _ hf), ⟨s, le_antisymm (ideal.span_le.2 $ λ x hx, have x ∈ I.degree_le N, from hs ▸ submodule.subset_span hx, this.2) $ begin change I ≤ ideal.span ↑s, intros p hp, generalize hn : p.nat_degree = k, induction k using nat.strong_induction_on with k ih generalizing p, cases le_or_lt k N, { subst k, refine hs2 ⟨polynomial.mem_degree_le.2 (le_trans polynomial.degree_le_nat_degree $ with_bot.coe_le_coe.2 h), hp⟩ }, { have hp0 : p ≠ 0, { rintro rfl, cases hn, exact nat.not_lt_zero _ h }, have : (0 : R) ≠ 1, { intro h, apply hp0, ext i, refine (mul_one _).symm.trans _, rw [← h, mul_zero], refl }, letI : nonzero_comm_ring R := { zero_ne_one := this, ..(infer_instance : comm_ring R) }, have : p.leading_coeff ∈ I.leading_coeff_nth N, { rw HN, exact hm2 k ((I.mem_leading_coeff_nth _ _).2 ⟨_, hp, hn ▸ polynomial.degree_le_nat_degree, rfl⟩) }, rw I.mem_leading_coeff_nth at this, rcases this with ⟨q, hq, hdq, hlqp⟩, have hq0 : q ≠ 0, { intro H, rw [← polynomial.leading_coeff_eq_zero] at H, rw [hlqp, polynomial.leading_coeff_eq_zero] at H, exact hp0 H }, have h1 : p.degree = (q * polynomial.X ^ (k - q.nat_degree)).degree, { rw [polynomial.degree_mul_eq', polynomial.degree_X_pow], rw [polynomial.degree_eq_nat_degree hp0, polynomial.degree_eq_nat_degree hq0], rw [← with_bot.coe_add, nat.add_sub_cancel', hn], { refine le_trans (polynomial.nat_degree_le_of_degree_le hdq) (le_of_lt h) }, rw [polynomial.leading_coeff_X_pow, mul_one], exact mt polynomial.leading_coeff_eq_zero.1 hq0 }, have h2 : p.leading_coeff = (q * polynomial.X ^ (k - q.nat_degree)).leading_coeff, { rw [← hlqp, polynomial.leading_coeff_mul_X_pow] }, have := polynomial.degree_sub_lt h1 hp0 h2, rw [polynomial.degree_eq_nat_degree hp0] at this, rw ← sub_add_cancel p (q * polynomial.X ^ (k - q.nat_degree)), refine (ideal.span ↑s).add_mem _ ((ideal.span ↑s).mul_mem_right _), { by_cases hpq : p - q * polynomial.X ^ (k - q.nat_degree) = 0, { rw hpq, exact ideal.zero_mem _ }, refine ih _ _ (I.sub_mem hp (I.mul_mem_right hq)) rfl, rwa [polynomial.degree_eq_nat_degree hpq, with_bot.coe_lt_coe, hn] at this }, exact hs2 ⟨polynomial.mem_degree_le.2 hdq, hq⟩ } end⟩⟩ attribute [instance] polynomial.is_noetherian_ring namespace mv_polynomial lemma is_noetherian_ring_fin_0 [is_noetherian_ring R] : is_noetherian_ring (mv_polynomial (fin 0) R) := is_noetherian_ring_of_ring_equiv R ((mv_polynomial.pempty_ring_equiv R).symm.trans (mv_polynomial.ring_equiv_of_equiv _ fin_zero_equiv'.symm)) theorem is_noetherian_ring_fin [is_noetherian_ring R] : ∀ {n : ℕ}, is_noetherian_ring (mv_polynomial (fin n) R) | 0 := is_noetherian_ring_fin_0 | (n+1) := @is_noetherian_ring_of_ring_equiv (polynomial (mv_polynomial (fin n) R)) _ _ _ (mv_polynomial.fin_succ_equiv _ n).symm (@polynomial.is_noetherian_ring (mv_polynomial (fin n) R) _ (is_noetherian_ring_fin)) /-- The multivariate polynomial ring in finitely many variables over a noetherian ring is itself a noetherian ring. -/ instance is_noetherian_ring [fintype σ] [is_noetherian_ring R] : is_noetherian_ring (mv_polynomial σ R) := trunc.induction_on (fintype.equiv_fin σ) $ λ e, @is_noetherian_ring_of_ring_equiv (mv_polynomial (fin (fintype.card σ)) R) _ _ _ (mv_polynomial.ring_equiv_of_equiv _ e.symm) is_noetherian_ring_fin lemma is_integral_domain_fin_zero (R : Type u) [comm_ring R] (hR : is_integral_domain R) : is_integral_domain (mv_polynomial (fin 0) R) := ring_equiv.is_integral_domain R hR ((ring_equiv_of_equiv R fin_zero_equiv').trans (mv_polynomial.pempty_ring_equiv R)) /-- Auxilliary lemma: Multivariate polynomials over an integral domain with variables indexed by `fin n` form an integral domain. This fact is proven inductively, and then used to prove the general case without any finiteness hypotheses. See `mv_polynomial.integral_domain` for the general case. -/ lemma is_integral_domain_fin (R : Type u) [comm_ring R] (hR : is_integral_domain R) : ∀ (n : ℕ), is_integral_domain (mv_polynomial (fin n) R) | 0 := is_integral_domain_fin_zero R hR | (n+1) := ring_equiv.is_integral_domain (polynomial (mv_polynomial (fin n) R)) (is_integral_domain_fin n).polynomial (mv_polynomial.fin_succ_equiv _ n) lemma is_integral_domain_fintype (R : Type u) (σ : Type v) [comm_ring R] [fintype σ] (hR : is_integral_domain R) : is_integral_domain (mv_polynomial σ R) := trunc.induction_on (fintype.equiv_fin σ) $ λ e, @ring_equiv.is_integral_domain _ (mv_polynomial (fin $ fintype.card σ) R) _ _ (mv_polynomial.is_integral_domain_fin _ hR _) (ring_equiv_of_equiv R e) /-- Auxilliary definition: Multivariate polynomials in finitely many variables over an integral domain form an integral domain. This fact is proven by transport of structure from the `mv_polynomial.integral_domain_fin`, and then used to prove the general case without finiteness hypotheses. See `mv_polynomial.integral_domain` for the general case. -/ def integral_domain_fintype (R : Type u) (σ : Type v) [integral_domain R] [fintype σ] : integral_domain (mv_polynomial σ R) := @is_integral_domain.to_integral_domain _ _ $ mv_polynomial.is_integral_domain_fintype R σ $ integral_domain.to_is_integral_domain R protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {R : Type u} [integral_domain R] {σ : Type v} (p q : mv_polynomial σ R) (h : p * q = 0) : p = 0 ∨ q = 0 := begin obtain ⟨s, p, rfl⟩ := exists_finset_rename p, obtain ⟨t, q, rfl⟩ := exists_finset_rename q, have : p.rename (subtype.map id (finset.subset_union_left s t) : {x // x ∈ s} → {x // x ∈ s ∪ t}) * q.rename (subtype.map id (finset.subset_union_right s t)) = 0, { apply injective_rename _ subtype.val_injective, simpa using h }, letI := mv_polynomial.integral_domain_fintype R {x // x ∈ (s ∪ t)}, rw mul_eq_zero at this, cases this; [left, right], all_goals { simpa using congr_arg (rename subtype.val) this } end /-- The multivariate polynomial ring over an integral domain is an integral domain. -/ instance {R : Type u} {σ : Type v} [integral_domain R] : integral_domain (mv_polynomial σ R) := { eq_zero_or_eq_zero_of_mul_eq_zero := mv_polynomial.eq_zero_or_eq_zero_of_mul_eq_zero, zero_ne_one := begin intro H, have : eval₂ id (λ s, (0:R)) (0 : mv_polynomial σ R) = eval₂ id (λ s, (0:R)) (1 : mv_polynomial σ R), { congr, exact H }, simpa, end, .. (by apply_instance : comm_ring (mv_polynomial σ R)) } end mv_polynomial
4384bc7eabea5f0cd3dc07a01d1110a600baba9c
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/data/matrix/pequiv.lean
4ff339d17176f44c01c92f68946c88241dae1d07
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
5,699
lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import data.matrix.basic import data.pequiv /-! # partial equivalences for matrices Using partial equivalences to represent matrices. This file introduces the function `pequiv.to_matrix`, which returns a matrix containing ones and zeros. For any partial equivalence `f`, `f.to_matrix i j = 1 ↔ f i = some j`. The following important properties of this function are proved `to_matrix_trans : (f.trans g).to_matrix = f.to_matrix ⬝ g.to_matrix` `to_matrix_symm : f.symm.to_matrix = f.to_matrixᵀ` `to_matrix_refl : (pequiv.refl n).to_matrix = 1` `to_matrix_bot : ⊥.to_matrix = 0` This theory gives the matrix representation of projection linear maps, and their right inverses. For example, the matrix `(single (0 : fin 1) (i : fin n)).to_matrix` corresponds to the the ith projection map from R^n to R. Any injective function `fin m → fin n` gives rise to a `pequiv`, whose matrix is the projection map from R^m → R^n represented by the same function. The transpose of this matrix is the right inverse of this map, sending anything not in the image to zero. ## notations This file uses the notation ` ⬝ ` for `matrix.mul` and `ᵀ` for `matrix.transpose`. -/ namespace pequiv open matrix universes u v variables {k l m n : Type*} variables [fintype k] [fintype l] [fintype m] [fintype n] variables {α : Type v} open_locale matrix /-- `to_matrix` returns a matrix containing ones and zeros. `f.to_matrix i j` is `1` if `f i = some j` and `0` otherwise -/ def to_matrix [decidable_eq n] [has_zero α] [has_one α] (f : m ≃. n) : matrix m n α | i j := if j ∈ f i then 1 else 0 lemma mul_matrix_apply [decidable_eq m] [semiring α] (f : l ≃. m) (M : matrix m n α) (i j) : (f.to_matrix ⬝ M) i j = option.cases_on (f i) 0 (λ fi, M fi j) := begin dsimp [to_matrix, matrix.mul_apply], cases h : f i with fi, { simp [h] }, { rw finset.sum_eq_single fi; simp [h, eq_comm] {contextual := tt} } end lemma to_matrix_symm [decidable_eq m] [decidable_eq n] [has_zero α] [has_one α] (f : m ≃. n) : (f.symm.to_matrix : matrix n m α) = f.to_matrixᵀ := by ext; simp only [transpose, mem_iff_mem f, to_matrix]; congr @[simp] lemma to_matrix_refl [decidable_eq n] [has_zero α] [has_one α] : ((pequiv.refl n).to_matrix : matrix n n α) = 1 := by ext; simp [to_matrix, one_apply]; congr lemma matrix_mul_apply [semiring α] [decidable_eq n] (M : matrix l m α) (f : m ≃. n) (i j) : (M ⬝ f.to_matrix) i j = option.cases_on (f.symm j) 0 (λ fj, M i fj) := begin dsimp [to_matrix, matrix.mul_apply], cases h : f.symm j with fj, { simp [h, ← f.eq_some_iff] }, { rw finset.sum_eq_single fj, { simp [h, ← f.eq_some_iff], }, { intros b H n, simp [h, ← f.eq_some_iff, n.symm], }, { simp, } } end lemma to_pequiv_mul_matrix [decidable_eq m] [semiring α] (f : m ≃ m) (M : matrix m n α) : (f.to_pequiv.to_matrix ⬝ M) = λ i, M (f i) := by { ext i j, rw [mul_matrix_apply, equiv.to_pequiv_apply] } lemma to_matrix_trans [decidable_eq m] [decidable_eq n] [semiring α] (f : l ≃. m) (g : m ≃. n) : ((f.trans g).to_matrix : matrix l n α) = f.to_matrix ⬝ g.to_matrix := begin ext i j, rw [mul_matrix_apply], dsimp [to_matrix, pequiv.trans], cases f i; simp end @[simp] lemma to_matrix_bot [decidable_eq n] [has_zero α] [has_one α] : ((⊥ : pequiv m n).to_matrix : matrix m n α) = 0 := rfl lemma to_matrix_injective [decidable_eq n] [monoid_with_zero α] [nontrivial α] : function.injective (@to_matrix m n _ _ α _ _ _) := begin classical, assume f g, refine not_imp_not.1 _, simp only [matrix.ext_iff.symm, to_matrix, pequiv.ext_iff, not_forall, exists_imp_distrib], assume i hi, use i, cases hf : f i with fi, { cases hg : g i with gi, { cc }, { use gi, simp, } }, { use fi, simp [hf.symm, ne.symm hi] } end lemma to_matrix_swap [decidable_eq n] [ring α] (i j : n) : (equiv.swap i j).to_pequiv.to_matrix = (1 : matrix n n α) - (single i i).to_matrix - (single j j).to_matrix + (single i j).to_matrix + (single j i).to_matrix := begin ext, dsimp [to_matrix, single, equiv.swap_apply_def, equiv.to_pequiv, one_apply], split_ifs; simp * at * end @[simp] lemma single_mul_single [decidable_eq k] [decidable_eq m] [decidable_eq n] [semiring α] (a : m) (b : n) (c : k) : ((single a b).to_matrix : matrix _ _ α) ⬝ (single b c).to_matrix = (single a c).to_matrix := by rw [← to_matrix_trans, single_trans_single] lemma single_mul_single_of_ne [decidable_eq k] [decidable_eq m] [decidable_eq n] [semiring α] {b₁ b₂ : n} (hb : b₁ ≠ b₂) (a : m) (c : k) : ((single a b₁).to_matrix : matrix _ _ α) ⬝ (single b₂ c).to_matrix = 0 := by rw [← to_matrix_trans, single_trans_single_of_ne hb, to_matrix_bot] /-- Restatement of `single_mul_single`, which will simplify expressions in `simp` normal form, when associativity may otherwise need to be carefully applied. -/ @[simp] lemma single_mul_single_right [decidable_eq k] [decidable_eq m] [decidable_eq n] [semiring α] (a : m) (b : n) (c : k) (M : matrix k l α) : (single a b).to_matrix ⬝ ((single b c).to_matrix ⬝ M) = (single a c).to_matrix ⬝ M := by rw [← matrix.mul_assoc, single_mul_single] /-- We can also define permutation matrices by permuting the rows of the identity matrix. -/ lemma equiv_to_pequiv_to_matrix [decidable_eq n] [has_zero α] [has_one α] (σ : equiv n n) (i j : n) : σ.to_pequiv.to_matrix i j = (1 : matrix n n α) (σ i) j := if_congr option.some_inj rfl rfl end pequiv
8bed00217d8e19d94f513a9eb43ba23636a2edf9
a4673261e60b025e2c8c825dfa4ab9108246c32e
/src/Lean/MetavarContext.lean
8747a98ee14142bcc0843d8b54e79fa0a18dfbc7
[ "Apache-2.0" ]
permissive
jcommelin/lean4
c02dec0cc32c4bccab009285475f265f17d73228
2909313475588cc20ac0436e55548a4502050d0a
refs/heads/master
1,674,129,550,893
1,606,415,348,000
1,606,415,348,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
52,080
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Util.MonadCache import Lean.LocalContext namespace Lean /- The metavariable context stores metavariable declarations and their assignments. It is used in the elaborator, tactic framework, unifier (aka `isDefEq`), and type class resolution (TC). First, we list all the requirements imposed by these modules. - We may invoke TC while executing `isDefEq`. We need this feature to be able to solve unification problems such as: ``` f ?a (ringAdd ?s) ?x ?y =?= f Int intAdd n m ``` where `(?a : Type) (?s : Ring ?a) (?x ?y : ?a)` During `isDefEq` (i.e., unification), it will need to solve the constrain ``` ringAdd ?s =?= intAdd ``` We say `ringAdd ?s` is stuck because it cannot be reduced until we synthesize the term `?s : Ring ?a` using TC. This can be done since we have assigned `?a := Int` when solving `?a =?= Int`. - TC uses `isDefEq`, and `isDefEq` may create TC problems as shown aaa. Thus, we may have nested TC problems. - `isDefEq` extends the local context when going inside binders. Thus, the local context for nested TC may be an extension of the local context for outer TC. - TC should not assign metavariables created by the elaborator, simp, tactic framework, and outer TC problems. Reason: TC commits to the first solution it finds. Consider the TC problem `Coe Nat ?x`, where `?x` is a metavariable created by the caller. There are many solutions to this problem (e.g., `?x := Int`, `?x := Real`, ...), and it doesn’t make sense to commit to the first one since TC does not know the the constraints the caller may impose on `?x` after the TC problem is solved. Remark: we claim it is not feasible to make the whole system backtrackable, and allow the caller to backtrack back to TC and ask it for another solution if the first one found did not work. We claim it would be too inefficient. - TC metavariables should not leak outside of TC. Reason: we want to get rid of them after we synthesize the instance. - `simp` invokes `isDefEq` for matching the left-hand-side of equations to terms in our goal. Thus, it may invoke TC indirectly. - In Lean3, we didn’t have to create a fresh pattern for trying to match the left-hand-side of equations when executing `simp`. We had a mechanism called tmp metavariables. It avoided this overhead, but it created many problems since `simp` may indirectly call TC which may recursively call TC. Moreover, we want to allow TC to invoke tactics. Thus, when `simp` invokes `isDefEq`, it may indirectly invoke a tactic and `simp` itself. The Lean3 approach assumed that metavariables were short-lived, this is not true in Lean4, and to some extent was also not true in Lean3 since `simp`, in principle, could trigger an arbitrary number of nested TC problems. - Here are some possible call stack traces we could have in Lean3 (and Lean4). ``` Elaborator (-> TC -> isDefEq)+ Elaborator -> isDefEq (-> TC -> isDefEq)* Elaborator -> simp -> isDefEq (-> TC -> isDefEq)* ``` In Lean4, TC may also invoke tactics. - In Lean3 and Lean4, TC metavariables are not really short-lived. We solve an arbitrary number of unification problems, and we may have nested TC invocations. - TC metavariables do not share the same local context even in the same invocation. In the C++ and Lean implementations we use a trick to ensure they do: https://github.com/leanprover/lean/blob/92826917a252a6092cffaf5fc5f1acb1f8cef379/src/library/type_context.cpp#L3583-L3594 - Metavariables may be natural, synthetic or syntheticOpaque. a) Natural metavariables may be assigned by unification (i.e., `isDefEq`). b) Synthetic metavariables may still be assigned by unification, but whenever possible `isDefEq` will avoid the assignment. For example, if we have the unification constaint `?m =?= ?n`, where `?m` is synthetic, but `?n` is not, `isDefEq` solves it by using the assignment `?n := ?m`. We use synthetic metavariables for type class resolution. Any module that creates synthetic metavariables, must also check whether they have been assigned by `isDefEq`, and then still synthesize them, and check whether the sythesized result is compatible with the one assigned by `isDefEq`. c) SyntheticOpaque metavariables are never assigned by `isDefEq`. That is, the constraint `?n =?= Nat.succ Nat.zero` always fail if `?n` is a syntheticOpaque metavariable. This kind of metavariable is created by tactics such as `intro`. Reason: in the tactic framework, subgoals as represented as metavariables, and a subgoal `?n` is considered as solved whenever the metavariable is assigned. This distinction was not precise in Lean3 and produced counterintuitive behavior. For example, the following hack was added in Lean3 to work around one of these issues: https://github.com/leanprover/lean/blob/92826917a252a6092cffaf5fc5f1acb1f8cef379/src/library/type_context.cpp#L2751 - When creating lambda/forall expressions, we need to convert/abstract free variables and convert them to bound variables. Now, suppose we a trying to create a lambda/forall expression by abstracting free variables `xs` and a term `t[?m]` which contains a metavariable `?m`, and the local context of `?m` contains `xs`. The term ``` fun xs => t[?m] ``` will be ill-formed if we later assign a term `s` to `?m`, and `s` contains free variables in `xs`. We address this issue by changing the free variable abstraction procedure. We consider two cases: `?m` is natural, `?m` is synthetic. Assume the type of `?m` is `A[xs]`. Then, in both cases we create an auxiliary metavariable `?n` with type `forall xs => A[xs]`, and local context := local context of `?m` - `xs`. In both cases, we produce the term `fun xs => t[?n xs]` 1- If `?m` is natural or synthetic, then we assign `?m := ?n xs`, and we produce the term `fun xs => t[?n xs]` 2- If `?m` is syntheticOpaque, then we mark `?n` as a syntheticOpaque variable. However, `?n` is managed by the metavariable context itself. We say we have a "delayed assignment" `?n xs := ?m`. That is, after a term `s` is assigned to `?m`, and `s` does not contain metavariables, we replace any occurrence `?n ts` with `s[xs := ts]`. Gruesome details: - When we create the type `forall xs => A` for `?n`, we may encounter the same issue if `A` contains metavariables. So, the process above is recursive. We claim it terminates because we keep creating new metavariables with smaller local contexts. - Suppose, we have `t[?m]` and we want to create a let-expression by abstracting a let-decl free variable `x`, and the local context of `?m` contatins `x`. Similarly to the previous case ``` let x : T := v; t[?m] ``` will be ill-formed if we later assign a term `s` to `?m`, and `s` contains free variable `x`. Again, assume the type of `?m` is `A[x]`. 1- If `?m` is natural or synthetic, then we create `?n : (let x : T := v; A[x])` with and local context := local context of `?m` - `x`, we assign `?m := ?n`, and produce the term `let x : T := v; t[?n]`. That is, we are just making sure `?n` must never be assigned to a term containing `x`. 2- If `?m` is syntheticOpaque, we create a fresh syntheticOpaque `?n` with type `?n : T -> (let x : T := v; A[x])` and local context := local context of `?m` - `x`, create the delayed assignment `?n #[x] := ?m`, and produce the term `let x : T := v; t[?n x]`. Now suppose we assign `s` to `?m`. We do not assign the term `fun (x : T) => s` to `?n`, since `fun (x : T) => s` may not even be type correct. Instead, we just replace applications `?n r` with `s[x/r]`. The term `r` may not necessarily be a bound variable. For example, a tactic may have reduced `let x : T := v; t[?n x]` into `t[?n v]`. We are essentially using the pair "delayed assignment + application" to implement a delayed substitution. - We use TC for implementing coercions. Both Joe Hendrix and Reid Barton reported a nasty limitation. In Lean3, TC will not be used if there are metavariables in the TC problem. For example, the elaborator will not try to synthesize `Coe Nat ?x`. This is good, but this constraint is too strict for problems such as `Coe (Vector Bool ?n) (BV ?n)`. The coercion exists independently of `?n`. Thus, during TC, we want `isDefEq` to throw an exception instead of return `false` whenever it tries to assign a metavariable owned by its caller. The idea is to sign to the caller that it cannot solve the TC problem at this point, and more information is needed. That is, the caller must make progress an assign its metavariables before trying to invoke TC again. In Lean4, we are using a simpler design for the `MetavarContext`. - No distinction betwen temporary and regular metavariables. - Metavariables have a `depth` Nat field. - MetavarContext also has a `depth` field. - We bump the `MetavarContext` depth when we create a nested problem. Example: Elaborator (depth = 0) -> Simplifier matcher (depth = 1) -> TC (level = 2) -> TC (level = 3) -> ... - When `MetavarContext` is at depth N, `isDefEq` does not assign variables from `depth < N`. - Metavariables from depth N+1 must be fully assigned before we return to level N. - New design even allows us to invoke tactics from TC. * Main concern We don't have tmp metavariables anymore in Lean4. Thus, before trying to match the left-hand-side of an equation in `simp`. We first must bump the level of the `MetavarContext`, create fresh metavariables, then create a new pattern by replacing the free variable on the left-hand-side with these metavariables. We are hoping to minimize this overhead by - Using better indexing data structures in `simp`. They should reduce the number of time `simp` must invoke `isDefEq`. - Implementing `isDefEqApprox` which ignores metavariables and returns only `false` or `undef`. It is a quick filter that allows us to fail quickly and avoid the creation of new fresh metavariables, and a new pattern. - Adding built-in support for arithmetic, Logical connectives, etc. Thus, we avoid a bunch of lemmas in the simp set. - Adding support for AC-rewriting. In Lean3, users use AC lemmas as rewriting rules for "sorting" terms. This is inefficient, requires a quadratic number of rewrite steps, and does not preserve the structure of the goal. The temporary metavariables were also used in the "app builder" module used in Lean3. The app builder uses `isDefEq`. So, it could, in principle, invoke an arbitrary number of nested TC problems. However, in Lean3, all app builder uses are controlled. That is, it is mainly used to synthesize implicit arguments using very simple unification and/or non-nested TC. So, if the "app builder" becomes a bottleneck without tmp metavars, we may solve the issue by implementing `isDefEqCheap` that never invokes TC and uses tmp metavars. -/ structure LocalInstance := (className : Name) (fvar : Expr) abbrev LocalInstances := Array LocalInstance def LocalInstance.beq (i₁ i₂ : LocalInstance) : Bool := i₁.fvar == i₂.fvar instance : BEq LocalInstance := ⟨LocalInstance.beq⟩ /-- Remove local instance with the given `fvarId`. Do nothing if `localInsts` does not contain any free variable with id `fvarId`. -/ def LocalInstances.erase (localInsts : LocalInstances) (fvarId : FVarId) : LocalInstances := match localInsts.findIdx? (fun inst => inst.fvar.fvarId! == fvarId) with | some idx => localInsts.eraseIdx idx | _ => localInsts inductive MetavarKind := | natural | synthetic | syntheticOpaque def MetavarKind.isSyntheticOpaque : MetavarKind → Bool | MetavarKind.syntheticOpaque => true | _ => false def MetavarKind.isNatural : MetavarKind → Bool | MetavarKind.natural => true | _ => false structure MetavarDecl := (userName : Name := Name.anonymous) (lctx : LocalContext) (type : Expr) (depth : Nat) (localInstances : LocalInstances) (kind : MetavarKind) (numScopeArgs : Nat := 0) -- See comment at `CheckAssignment` `Meta/ExprDefEq.lean` @[export lean_mk_metavar_decl] def mkMetavarDeclEx (userName : Name) (lctx : LocalContext) (type : Expr) (depth : Nat) (localInstances : LocalInstances) (kind : MetavarKind) : MetavarDecl := { userName := userName, lctx := lctx, type := type, depth := depth, localInstances := localInstances, kind := kind } instance : Inhabited MetavarDecl := ⟨{ lctx := arbitrary, type := arbitrary, depth := 0, localInstances := #[], kind := MetavarKind.natural }⟩ /-- A delayed assignment for a metavariable `?m`. It represents an assignment of the form `?m := (fun fvars => val)`. The local context `lctx` provides the declarations for `fvars`. Note that `fvars` may not be defined in the local context for `?m`. - TODO: after we delete the old frontend, we can remove the field `lctx`. This field is only used in old C++ implementation. -/ structure DelayedMetavarAssignment := (lctx : LocalContext) (fvars : Array Expr) (val : Expr) open Std (HashMap PersistentHashMap) structure MetavarContext := (depth : Nat := 0) (lDepth : PersistentHashMap MVarId Nat := {}) (decls : PersistentHashMap MVarId MetavarDecl := {}) (lAssignment : PersistentHashMap MVarId Level := {}) (eAssignment : PersistentHashMap MVarId Expr := {}) (dAssignment : PersistentHashMap MVarId DelayedMetavarAssignment := {}) class MonadMCtx (m : Type → Type) := (getMCtx : m MetavarContext) (modifyMCtx : (MetavarContext → MetavarContext) → m Unit) export MonadMCtx (getMCtx modifyMCtx) instance (m n) [MonadMCtx m] [MonadLift m n] : MonadMCtx n := { getMCtx := liftM (getMCtx : m _), modifyMCtx := fun f => liftM (modifyMCtx f : m _) } namespace MetavarContext instance : Inhabited MetavarContext := ⟨{}⟩ @[export lean_mk_metavar_ctx] def mkMetavarContext : Unit → MetavarContext := fun _ => {} /- Low level API for adding/declaring metavariable declarations. It is used to implement actions in the monads `MetaM`, `ElabM` and `TacticM`. It should not be used directly since the argument `(mvarId : MVarId)` is assumed to be "unique". -/ def addExprMVarDecl (mctx : MetavarContext) (mvarId : MVarId) (userName : Name) (lctx : LocalContext) (localInstances : LocalInstances) (type : Expr) (kind : MetavarKind := MetavarKind.natural) (numScopeArgs : Nat := 0) : MetavarContext := { mctx with decls := mctx.decls.insert mvarId { userName := userName, lctx := lctx, localInstances := localInstances, type := type, depth := mctx.depth, kind := kind, numScopeArgs := numScopeArgs } } @[export lean_metavar_ctx_mk_decl] def addExprMVarDeclExp (mctx : MetavarContext) (mvarId : MVarId) (userName : Name) (lctx : LocalContext) (localInstances : LocalInstances) (type : Expr) (kind : MetavarKind) : MetavarContext := addExprMVarDecl mctx mvarId userName lctx localInstances type kind /- Low level API for adding/declaring universe level metavariable declarations. It is used to implement actions in the monads `MetaM`, `ElabM` and `TacticM`. It should not be used directly since the argument `(mvarId : MVarId)` is assumed to be "unique". -/ def addLevelMVarDecl (mctx : MetavarContext) (mvarId : MVarId) : MetavarContext := { mctx with lDepth := mctx.lDepth.insert mvarId mctx.depth } @[export lean_metavar_ctx_find_decl] def findDecl? (mctx : MetavarContext) (mvarId : MVarId) : Option MetavarDecl := mctx.decls.find? mvarId def getDecl (mctx : MetavarContext) (mvarId : MVarId) : MetavarDecl := match mctx.decls.find? mvarId with | some decl => decl | none => panic! "unknown metavariable" def findUserName? (mctx : MetavarContext) (userName : Name) : Option MVarId := let search : Except MVarId Unit := mctx.decls.forM fun mvarId decl => if decl.userName == userName then throw mvarId else pure () match search with | Except.ok _ => none | Except.error mvarId => some mvarId def setMVarKind (mctx : MetavarContext) (mvarId : MVarId) (kind : MetavarKind) : MetavarContext := let decl := mctx.getDecl mvarId { mctx with decls := mctx.decls.insert mvarId { decl with kind := kind } } def setMVarUserName (mctx : MetavarContext) (mvarId : MVarId) (userName : Name) : MetavarContext := let decl := mctx.getDecl mvarId { mctx with decls := mctx.decls.insert mvarId { decl with userName := userName } } /- Update the type of the given metavariable. This function assumes the new type is definitionally equal to the current one -/ def setMVarType (mctx : MetavarContext) (mvarId : MVarId) (type : Expr) : MetavarContext := let decl := mctx.getDecl mvarId { mctx with decls := mctx.decls.insert mvarId { decl with type := type } } def findLevelDepth? (mctx : MetavarContext) (mvarId : MVarId) : Option Nat := mctx.lDepth.find? mvarId def getLevelDepth (mctx : MetavarContext) (mvarId : MVarId) : Nat := match mctx.findLevelDepth? mvarId with | some d => d | none => panic! "unknown metavariable" def isAnonymousMVar (mctx : MetavarContext) (mvarId : MVarId) : Bool := match mctx.findDecl? mvarId with | none => false | some mvarDecl => mvarDecl.userName.isAnonymous def renameMVar (mctx : MetavarContext) (mvarId : MVarId) (newUserName : Name) : MetavarContext := match mctx.findDecl? mvarId with | none => panic! "unknown metavariable" | some mvarDecl => { mctx with decls := mctx.decls.insert mvarId { mvarDecl with userName := newUserName } } @[export lean_metavar_ctx_assign_level] def assignLevel (m : MetavarContext) (mvarId : MVarId) (val : Level) : MetavarContext := { m with lAssignment := m.lAssignment.insert mvarId val } @[export lean_metavar_ctx_assign_expr] def assignExprCore (m : MetavarContext) (mvarId : MVarId) (val : Expr) : MetavarContext := { m with eAssignment := m.eAssignment.insert mvarId val } def assignExpr (m : MetavarContext) (mvarId : MVarId) (val : Expr) : MetavarContext := { m with eAssignment := m.eAssignment.insert mvarId val } @[export lean_metavar_ctx_assign_delayed] def assignDelayed (m : MetavarContext) (mvarId : MVarId) (lctx : LocalContext) (fvars : Array Expr) (val : Expr) : MetavarContext := { m with dAssignment := m.dAssignment.insert mvarId { lctx := lctx, fvars := fvars, val := val } } @[export lean_metavar_ctx_get_level_assignment] def getLevelAssignment? (m : MetavarContext) (mvarId : MVarId) : Option Level := m.lAssignment.find? mvarId @[export lean_metavar_ctx_get_expr_assignment] def getExprAssignment? (m : MetavarContext) (mvarId : MVarId) : Option Expr := m.eAssignment.find? mvarId @[export lean_metavar_ctx_get_delayed_assignment] def getDelayedAssignment? (m : MetavarContext) (mvarId : MVarId) : Option DelayedMetavarAssignment := m.dAssignment.find? mvarId @[export lean_metavar_ctx_is_level_assigned] def isLevelAssigned (m : MetavarContext) (mvarId : MVarId) : Bool := m.lAssignment.contains mvarId @[export lean_metavar_ctx_is_expr_assigned] def isExprAssigned (m : MetavarContext) (mvarId : MVarId) : Bool := m.eAssignment.contains mvarId @[export lean_metavar_ctx_is_delayed_assigned] def isDelayedAssigned (m : MetavarContext) (mvarId : MVarId) : Bool := m.dAssignment.contains mvarId @[export lean_metavar_ctx_erase_delayed] def eraseDelayed (m : MetavarContext) (mvarId : MVarId) : MetavarContext := { m with dAssignment := m.dAssignment.erase mvarId } /- Given a sequence of delayed assignments ``` mvarId₁ := mvarId₂ ...; ... mvarIdₙ := mvarId_root ... -- where `mvarId_root` is not delayed assigned ``` in `mctx`, `getDelayedRoot mctx mvarId₁` return `mvarId_root`. If `mvarId₁` is not delayed assigned then return `mvarId₁` -/ partial def getDelayedRoot (m : MetavarContext) : MVarId → MVarId | mvarId => match getDelayedAssignment? m mvarId with | some d => match d.val.getAppFn with | Expr.mvar mvarId _ => getDelayedRoot m mvarId | _ => mvarId | none => mvarId def isLevelAssignable (mctx : MetavarContext) (mvarId : MVarId) : Bool := match mctx.lDepth.find? mvarId with | some d => d == mctx.depth | _ => panic! "unknown universe metavariable" def isExprAssignable (mctx : MetavarContext) (mvarId : MVarId) : Bool := let decl := mctx.getDecl mvarId decl.depth == mctx.depth def incDepth (mctx : MetavarContext) : MetavarContext := { mctx with depth := mctx.depth + 1 } /-- Return true iff the given level contains an assigned metavariable. -/ def hasAssignedLevelMVar (mctx : MetavarContext) : Level → Bool | Level.succ lvl _ => lvl.hasMVar && hasAssignedLevelMVar mctx lvl | Level.max lvl₁ lvl₂ _ => (lvl₁.hasMVar && hasAssignedLevelMVar mctx lvl₁) || (lvl₂.hasMVar && hasAssignedLevelMVar mctx lvl₂) | Level.imax lvl₁ lvl₂ _ => (lvl₁.hasMVar && hasAssignedLevelMVar mctx lvl₁) || (lvl₂.hasMVar && hasAssignedLevelMVar mctx lvl₂) | Level.mvar mvarId _ => mctx.isLevelAssigned mvarId | Level.zero _ => false | Level.param _ _ => false /-- Return `true` iff expression contains assigned (level/expr) metavariables or delayed assigned mvars -/ def hasAssignedMVar (mctx : MetavarContext) : Expr → Bool | Expr.const _ lvls _ => lvls.any (hasAssignedLevelMVar mctx) | Expr.sort lvl _ => hasAssignedLevelMVar mctx lvl | Expr.app f a _ => (f.hasMVar && hasAssignedMVar mctx f) || (a.hasMVar && hasAssignedMVar mctx a) | Expr.letE _ t v b _ => (t.hasMVar && hasAssignedMVar mctx t) || (v.hasMVar && hasAssignedMVar mctx v) || (b.hasMVar && hasAssignedMVar mctx b) | Expr.forallE _ d b _ => (d.hasMVar && hasAssignedMVar mctx d) || (b.hasMVar && hasAssignedMVar mctx b) | Expr.lam _ d b _ => (d.hasMVar && hasAssignedMVar mctx d) || (b.hasMVar && hasAssignedMVar mctx b) | Expr.fvar _ _ => false | Expr.bvar _ _ => false | Expr.lit _ _ => false | Expr.mdata _ e _ => e.hasMVar && hasAssignedMVar mctx e | Expr.proj _ _ e _ => e.hasMVar && hasAssignedMVar mctx e | Expr.mvar mvarId _ => mctx.isExprAssigned mvarId || mctx.isDelayedAssigned mvarId /-- Return true iff the given level contains a metavariable that can be assigned. -/ def hasAssignableLevelMVar (mctx : MetavarContext) : Level → Bool | Level.succ lvl _ => lvl.hasMVar && hasAssignableLevelMVar mctx lvl | Level.max lvl₁ lvl₂ _ => (lvl₁.hasMVar && hasAssignableLevelMVar mctx lvl₁) || (lvl₂.hasMVar && hasAssignableLevelMVar mctx lvl₂) | Level.imax lvl₁ lvl₂ _ => (lvl₁.hasMVar && hasAssignableLevelMVar mctx lvl₁) || (lvl₂.hasMVar && hasAssignableLevelMVar mctx lvl₂) | Level.mvar mvarId _ => mctx.isLevelAssignable mvarId | Level.zero _ => false | Level.param _ _ => false /-- Return `true` iff expression contains a metavariable that can be assigned. -/ def hasAssignableMVar (mctx : MetavarContext) : Expr → Bool | Expr.const _ lvls _ => lvls.any (hasAssignableLevelMVar mctx) | Expr.sort lvl _ => hasAssignableLevelMVar mctx lvl | Expr.app f a _ => (f.hasMVar && hasAssignableMVar mctx f) || (a.hasMVar && hasAssignableMVar mctx a) | Expr.letE _ t v b _ => (t.hasMVar && hasAssignableMVar mctx t) || (v.hasMVar && hasAssignableMVar mctx v) || (b.hasMVar && hasAssignableMVar mctx b) | Expr.forallE _ d b _ => (d.hasMVar && hasAssignableMVar mctx d) || (b.hasMVar && hasAssignableMVar mctx b) | Expr.lam _ d b _ => (d.hasMVar && hasAssignableMVar mctx d) || (b.hasMVar && hasAssignableMVar mctx b) | Expr.fvar _ _ => false | Expr.bvar _ _ => false | Expr.lit _ _ => false | Expr.mdata _ e _ => e.hasMVar && hasAssignableMVar mctx e | Expr.proj _ _ e _ => e.hasMVar && hasAssignableMVar mctx e | Expr.mvar mvarId _ => mctx.isExprAssignable mvarId partial def instantiateLevelMVars {m} [Monad m] [MonadMCtx m] : Level → m Level | lvl@(Level.succ lvl₁ _) => return Level.updateSucc! lvl (← instantiateLevelMVars lvl₁) | lvl@(Level.max lvl₁ lvl₂ _) => return Level.updateMax! lvl (← instantiateLevelMVars lvl₁) (← instantiateLevelMVars lvl₂) | lvl@(Level.imax lvl₁ lvl₂ _) => return Level.updateIMax! lvl (← instantiateLevelMVars lvl₁) (← instantiateLevelMVars lvl₂) | lvl@(Level.mvar mvarId _) => do match getLevelAssignment? (← getMCtx) mvarId with | some newLvl => if !newLvl.hasMVar then pure newLvl else do let newLvl' ← instantiateLevelMVars newLvl modifyMCtx fun mctx => mctx.assignLevel mvarId newLvl' pure newLvl' | none => pure lvl | lvl => pure lvl /-- instantiateExprMVars main function -/ partial def instantiateExprMVars {m ω} [Monad m] [MonadMCtx m] [STWorld ω m] [MonadLiftT (ST ω) m] (e : Expr) : MonadCacheT Expr Expr m Expr := if !e.hasMVar then pure e else checkCache e fun e => do match e with | Expr.proj _ _ s _ => return e.updateProj! (← instantiateExprMVars s) | Expr.forallE _ d b _ => return e.updateForallE! (← instantiateExprMVars d) (← instantiateExprMVars b) | Expr.lam _ d b _ => return e.updateLambdaE! (← instantiateExprMVars d) (← instantiateExprMVars b) | Expr.letE _ t v b _ => return e.updateLet! (← instantiateExprMVars t) (← instantiateExprMVars v) (← instantiateExprMVars b) | Expr.const _ lvls _ => return e.updateConst! (← lvls.mapM instantiateLevelMVars) | Expr.sort lvl _ => return e.updateSort! (← instantiateLevelMVars lvl) | Expr.mdata _ b _ => return e.updateMData! (← instantiateExprMVars b) | Expr.app _ _ _ => e.withApp fun f args => do let instArgs (f : Expr) : MonadCacheT Expr Expr m Expr := do let args ← args.mapM instantiateExprMVars pure (mkAppN f args) let instApp : MonadCacheT Expr Expr m Expr := do let wasMVar := f.isMVar let f ← instantiateExprMVars f if wasMVar && f.isLambda then /- Some of the arguments in args are irrelevant after we beta reduce. -/ instantiateExprMVars (f.betaRev args.reverse) else instArgs f match f with | Expr.mvar mvarId _ => let mctx ← getMCtx match mctx.getDelayedAssignment? mvarId with | none => instApp | some { fvars := fvars, val := val, .. } => /- Apply "delayed substitution" (i.e., delayed assignment + application). That is, `f` is some metavariable `?m`, that is delayed assigned to `val`. If after instantiating `val`, we obtain `newVal`, and `newVal` does not contain metavariables, we replace the free variables `fvars` in `newVal` with the first `fvars.size` elements of `args`. -/ if fvars.size > args.size then /- We don't have sufficient arguments for instantiating the free variables `fvars`. This can only happy if a tactic or elaboration function is not implemented correctly. We decided to not use `panic!` here and report it as an error in the frontend when we are checking for unassigned metavariables in an elaborated term. -/ instArgs f else let newVal ← instantiateExprMVars val if newVal.hasExprMVar then instArgs f else do let args ← args.mapM instantiateExprMVars /- Example: suppose we have `?m t1 t2 t3` That is, `f := ?m` and `args := #[t1, t2, t3]` Morever, `?m` is delayed assigned `?m #[x, y] := f x y` where, `fvars := #[x, y]` and `newVal := f x y`. After abstracting `newVal`, we have `f (Expr.bvar 0) (Expr.bvar 1)`. After `instantiaterRevRange 0 2 args`, we have `f t1 t2`. After `mkAppRange 2 3`, we have `f t1 t2 t3` -/ let newVal := newVal.abstract fvars let result := newVal.instantiateRevRange 0 fvars.size args let result := mkAppRange result fvars.size args.size args pure $ result | _ => instApp | e@(Expr.mvar mvarId _) => checkCache e fun e => do let mctx ← getMCtx match mctx.getExprAssignment? mvarId with | some newE => do let newE' ← instantiateExprMVars newE modifyMCtx fun mctx => mctx.assignExpr mvarId newE' pure newE' | none => pure e | e => pure e instance {ω} : MonadMCtx (StateRefT MetavarContext (ST ω)) := { getMCtx := get, modifyMCtx := modify } def instantiateMVars (mctx : MetavarContext) (e : Expr) : Expr × MetavarContext := if !e.hasMVar then (e, mctx) else let instantiate {ω} (e : Expr) : (MonadCacheT Expr Expr $ StateRefT MetavarContext $ ST ω) Expr := instantiateExprMVars e runST fun _ => instantiate e |>.run |>.run mctx def instantiateLCtxMVars (mctx : MetavarContext) (lctx : LocalContext) : LocalContext × MetavarContext := lctx.foldl (fun (result : LocalContext × MetavarContext) ldecl => let (lctx, mctx) := result; match ldecl with | LocalDecl.cdecl _ fvarId userName type bi => let (type, mctx) := mctx.instantiateMVars type (lctx.mkLocalDecl fvarId userName type bi, mctx) | LocalDecl.ldecl _ fvarId userName type value nonDep => let (type, mctx) := mctx.instantiateMVars type let (value, mctx) := mctx.instantiateMVars value (lctx.mkLetDecl fvarId userName type value nonDep, mctx)) ({}, mctx) def instantiateMVarDeclMVars (mctx : MetavarContext) (mvarId : MVarId) : MetavarContext := let mvarDecl := mctx.getDecl mvarId let (lctx, mctx) := mctx.instantiateLCtxMVars mvarDecl.lctx let (type, mctx) := mctx.instantiateMVars mvarDecl.type { mctx with decls := mctx.decls.insert mvarId { mvarDecl with lctx := lctx, type := type } } namespace DependsOn private abbrev M := StateM ExprSet private def shouldVisit (e : Expr) : M Bool := if !e.hasMVar && !e.hasFVar then pure false else do let s ← get if s.contains e then pure false else do modify fun s => s.insert e pure true @[specialize] private partial def dep (mctx : MetavarContext) (p : FVarId → Bool) (e : Expr) : M Bool := let rec visit (e : Expr) : M Bool := do if !(← shouldVisit e) then pure false else visitMain e, visitMain : Expr → M Bool | Expr.proj _ _ s _ => visit s | Expr.forallE _ d b _ => visit d <||> visit b | Expr.lam _ d b _ => visit d <||> visit b | Expr.letE _ t v b _ => visit t <||> visit v <||> visit b | Expr.mdata _ b _ => visit b | Expr.app f a _ => visit a <||> if f.isApp then visitMain f else visit f | Expr.mvar mvarId _ => match mctx.getExprAssignment? mvarId with | some a => visit a | none => let lctx := (mctx.getDecl mvarId).lctx pure $ lctx.any $ fun decl => p decl.fvarId | Expr.fvar fvarId _ => pure $ p fvarId | e => pure false visit e @[inline] partial def main (mctx : MetavarContext) (p : FVarId → Bool) (e : Expr) : M Bool := if !e.hasFVar && !e.hasMVar then pure false else dep mctx p e end DependsOn /-- Return `true` iff `e` depends on a free variable `x` s.t. `p x` is `true`. For each metavariable `?m` occurring in `x` 1- If `?m := t`, then we visit `t` looking for `x` 2- If `?m` is unassigned, then we consider the worst case and check whether `x` is in the local context of `?m`. This case is a "may dependency". That is, we may assign a term `t` to `?m` s.t. `t` contains `x`. -/ @[inline] def findExprDependsOn (mctx : MetavarContext) (e : Expr) (p : FVarId → Bool) : Bool := (DependsOn.main mctx p e).run' {} /-- Similar to `findExprDependsOn`, but checks the expressions in the given local declaration depends on a free variable `x` s.t. `p x` is `true`. -/ @[inline] def findLocalDeclDependsOn (mctx : MetavarContext) (localDecl : LocalDecl) (p : FVarId → Bool) : Bool := match localDecl with | LocalDecl.cdecl _ _ _ type _ => findExprDependsOn mctx type p | LocalDecl.ldecl _ _ _ type value _ => (DependsOn.main mctx p type <||> DependsOn.main mctx p value).run' {} def exprDependsOn (mctx : MetavarContext) (e : Expr) (fvarId : FVarId) : Bool := findExprDependsOn mctx e $ fun fvarId' => fvarId == fvarId' def localDeclDependsOn (mctx : MetavarContext) (localDecl : LocalDecl) (fvarId : FVarId) : Bool := findLocalDeclDependsOn mctx localDecl $ fun fvarId' => fvarId == fvarId' namespace MkBinding inductive Exception := | revertFailure (mctx : MetavarContext) (lctx : LocalContext) (toRevert : Array Expr) (decl : LocalDecl) protected def Exception.toString : Exception → String | Exception.revertFailure _ lctx toRevert decl => "failed to revert " ++ toString (toRevert.map (fun x => "'" ++ toString (lctx.getFVar! x).userName ++ "'")) ++ ", '" ++ toString decl.userName ++ "' depends on them, and it is an auxiliary declaration created by the elaborator" ++ " (possible solution: use tactic 'clear' to remove '" ++ toString decl.userName ++ "' from local context)" instance : ToString Exception := ⟨Exception.toString⟩ /-- `MkBinding` and `elimMVarDepsAux` are mutually recursive, but `cache` is only used at `elimMVarDepsAux`. We use a single state object for convenience. We have a `NameGenerator` because we need to generate fresh auxiliary metavariables. -/ structure State := (mctx : MetavarContext) (ngen : NameGenerator) (cache : HashMap Expr Expr := {}) -- abbrev MCore := EStateM Exception State abbrev M := ReaderT Bool (EStateM Exception State) def preserveOrder : M Bool := read instance : MonadHashMapCacheAdapter Expr Expr M := { getCache := do let s ← get; pure s.cache, modifyCache := fun f => modify fun s => { s with cache := f s.cache } } /-- Return the local declaration of the free variable `x` in `xs` with the smallest index -/ private def getLocalDeclWithSmallestIdx (lctx : LocalContext) (xs : Array Expr) : LocalDecl := do let mut d : LocalDecl := lctx.getFVar! xs[0] for i in [1:xs.size] do let curr := lctx.getFVar! xs[i] if curr.index < d.index then d := curr return d /-- Given `toRevert` an array of free variables s.t. `lctx` contains their declarations, return a new array of free variables that contains `toRevert` and all free variables in `lctx` that may depend on `toRevert`. Remark: the result is sorted by `LocalDecl` indices. Remark: We used to throw an `Exception.revertFailure` exception when an auxiliary declaration had to be reversed. Recall that auxiliary declarations are created when compiling (mutually) recursive definitions. The `revertFailure` due to auxiliary declaration dependency was originally introduced in Lean3 to address issue https://github.com/leanprover/lean/issues/1258. In Lean4, this solution is not satisfactory because all definitions/theorems are potentially recursive. So, even an simple (incomplete) definition such as ``` variables {α : Type} in def f (a : α) : List α := _ ``` would trigger the `Exception.revertFailure` exception. In the definition above, the elaborator creates the auxiliary definition `f : {α : Type} → List α`. The `_` is elaborated as a new fresh variable `?m` that contains `α : Type`, `a : α`, and `f : α → List α` in its context, When we try to create the lambda `fun {α : Type} (a : α) => ?m`, we first need to create an auxiliary `?n` which do not contain `α` and `a` in its context. That is, we create the metavariable `?n : {α : Type} → (a : α) → (f : α → List α) → List α`, add the delayed assignment `?n #[α, a, f] := ?m α a f`, and create the lambda `fun {α : Type} (a : α) => ?n α a f`. See `elimMVarDeps` for more information. If we kept using the Lean3 approach, we would get the `Exception.revertFailure` exception because we are reverting the auxiliary definition `f`. Note that https://github.com/leanprover/lean/issues/1258 is not an issue in Lean4 because we have changed how we compile recursive definitions. -/ private def collectDeps (mctx : MetavarContext) (lctx : LocalContext) (toRevert : Array Expr) (preserveOrder : Bool) : Except Exception (Array Expr) := do if toRevert.size == 0 then pure toRevert else if preserveOrder then -- Make sure none of `toRevert` is an AuxDecl -- Make sure toRevert[j] does not depend on toRevert[i] for j > i toRevert.size.forM fun i => do let fvar := toRevert[i] let decl := lctx.getFVar! fvar i.forM fun j => do let prevFVar := toRevert[j] let prevDecl := lctx.getFVar! prevFVar if localDeclDependsOn mctx prevDecl fvar.fvarId! then throw (Exception.revertFailure mctx lctx toRevert prevDecl) let newToRevert := if preserveOrder then toRevert else Array.mkEmpty toRevert.size let firstDeclToVisit := getLocalDeclWithSmallestIdx lctx toRevert let initSize := newToRevert.size lctx.foldlM (init := newToRevert) (start := firstDeclToVisit.index) fun (newToRevert : Array Expr) decl => if initSize.any $ fun i => decl.fvarId == (newToRevert.get! i).fvarId! then pure newToRevert else if toRevert.any (fun x => decl.fvarId == x.fvarId!) then pure (newToRevert.push decl.toExpr) else if findLocalDeclDependsOn mctx decl (fun fvarId => newToRevert.any $ fun x => x.fvarId! == fvarId) then pure (newToRevert.push decl.toExpr) else pure newToRevert /-- Create a new `LocalContext` by removing the free variables in `toRevert` from `lctx`. We use this function when we create auxiliary metavariables at `elimMVarDepsAux`. -/ private def reduceLocalContext (lctx : LocalContext) (toRevert : Array Expr) : LocalContext := toRevert.foldr (fun x lctx => lctx.erase x.fvarId!) lctx @[inline] private def getMCtx : M MetavarContext := do let s ← get; pure s.mctx /-- Return free variables in `xs` that are in the local context `lctx` -/ private def getInScope (lctx : LocalContext) (xs : Array Expr) : Array Expr := xs.foldl (fun scope x => if lctx.contains x.fvarId! then scope.push x else scope) #[] /-- Execute `x` with an empty cache, and then restore the original cache. -/ @[inline] private def withFreshCache {α} (x : M α) : M α := do let cache ← modifyGet $ fun s => (s.cache, { s with cache := {} }) let a ← x modify fun s => { s with cache := cache } pure a /-- Create an application `mvar ys` where `ys` are the free variables. See "Gruesome details" in the beginning of the file for understanding how let-decl free variables are handled. -/ private def mkMVarApp (lctx : LocalContext) (mvar : Expr) (xs : Array Expr) (kind : MetavarKind) : Expr := xs.foldl (fun e x => match kind with | MetavarKind.syntheticOpaque => mkApp e x | _ => if (lctx.getFVar! x).isLet then e else mkApp e x) mvar /-- Return true iff some `e` in `es` depends on `fvarId` -/ private def anyDependsOn (mctx : MetavarContext) (es : Array Expr) (fvarId : FVarId) : Bool := es.any fun e => exprDependsOn mctx e fvarId private partial def elimMVarDepsAux (xs : Array Expr) (e : Expr) : M Expr := let rec visit (e : Expr) : M Expr := if !e.hasMVar then pure e else checkCache e elim, elim (e : Expr) : M Expr := do match e with | Expr.proj _ _ s _ => return e.updateProj! (← visit s) | Expr.forallE _ d b _ => return e.updateForallE! (← visit d) (← visit b) | Expr.lam _ d b _ => return e.updateLambdaE! (← visit d) (← visit b) | Expr.letE _ t v b _ => return e.updateLet! (← visit t) (← visit v) (← visit b) | Expr.mdata _ b _ => return e.updateMData! (← visit b) | Expr.app _ _ _ => e.withApp fun f args => elimApp f args | Expr.mvar mvarId _ => elimApp e #[] | e => return e, abstractRangeAux (xs : Array Expr) (i : Nat) (e : Expr) : M Expr := do let e ← elim e pure (e.abstractRange i xs), mkAuxMVarType (lctx : LocalContext) (xs : Array Expr) (kind : MetavarKind) (e : Expr) : M Expr := do let e ← abstractRangeAux xs xs.size e xs.size.foldRevM (fun i e => let x := xs[i] match lctx.getFVar! x with | LocalDecl.cdecl _ _ n type bi => do let type := type.headBeta let type ← abstractRangeAux xs i type pure $ Lean.mkForall n bi type e | LocalDecl.ldecl _ _ n type value nonDep => do let type := type.headBeta let type ← abstractRangeAux xs i type let value ← abstractRangeAux xs i value let e := mkLet n type value e nonDep match kind with | MetavarKind.syntheticOpaque => -- See "Gruesome details" section in the beginning of the file let e := e.liftLooseBVars 0 1 pure $ mkForall n BinderInfo.default type e | _ => pure e) e, elimApp (f : Expr) (args : Array Expr) : M Expr := do match f with | Expr.mvar mvarId _ => let processDefault (newF : Expr) : M Expr := do if newF.isLambda then let args ← args.mapM visit elim $ newF.betaRev args.reverse else if newF == f then let args ← args.mapM visit pure $ mkAppN newF args else elimApp newF args let mctx ← getMCtx match mctx.getExprAssignment? mvarId with | some val => processDefault val | _ => let mvarDecl := mctx.getDecl mvarId let mvarLCtx := mvarDecl.lctx let toRevert := getInScope mvarLCtx xs if toRevert.size == 0 then processDefault f else let newMVarKind := if !mctx.isExprAssignable mvarId then MetavarKind.syntheticOpaque else mvarDecl.kind /- If `mvarId` is the lhs of a delayed assignment `?m #[x_1, ... x_n] := val`, then `nestedFVars` is `#[x_1, ..., x_n]`. In this case, we produce a new `syntheticOpaque` metavariable `?n` and a delayed assignment ``` ?n #[y_1, ..., y_m, x_1, ... x_n] := ?m x_1 ... x_n ``` where `#[y_1, ..., y_m]` is `toRevert` after `collectDeps`. Remark: `newMVarKind != MetavarKind.syntheticOpaque ==> nestedFVars == #[]` -/ let cont (nestedFVars : Array Expr) : M Expr := do let args ← args.mapM visit let preserve ← preserveOrder match collectDeps mctx mvarLCtx toRevert preserve with | Except.error ex => throw ex | Except.ok toRevert => let newMVarLCtx := reduceLocalContext mvarLCtx toRevert let newLocalInsts := mvarDecl.localInstances.filter fun inst => toRevert.all fun x => inst.fvar != x let newMVarType ← mkAuxMVarType mvarLCtx toRevert newMVarKind mvarDecl.type let newMVarId ← get >>= fun s => pure s.ngen.curr let newMVar := mkMVar newMVarId let result := mkMVarApp mvarLCtx newMVar toRevert newMVarKind let numScopeArgs := mvarDecl.numScopeArgs + result.getAppNumArgs modify fun s => { s with mctx := s.mctx.addExprMVarDecl newMVarId Name.anonymous newMVarLCtx newLocalInsts newMVarType newMVarKind numScopeArgs, ngen := s.ngen.next } match newMVarKind with | MetavarKind.syntheticOpaque => modify fun s => { s with mctx := assignDelayed s.mctx newMVarId mvarLCtx (toRevert ++ nestedFVars) (mkAppN f nestedFVars) } | _ => modify fun s => { s with mctx := assignExpr s.mctx mvarId result } pure (mkAppN result args) if !mvarDecl.kind.isSyntheticOpaque then cont #[] else match mctx.getDelayedAssignment? mvarId with | none => cont #[] | some { fvars := fvars, .. } => cont fvars | _ => let f ← visit f let args ← args.mapM visit pure (mkAppN f args) elim e partial def elimMVarDeps (xs : Array Expr) (e : Expr) : M Expr := if !e.hasMVar then pure e else withFreshCache $ elimMVarDepsAux xs e /-- Similar to `Expr.abstractRange`, but handles metavariables correctly. It uses `elimMVarDeps` to ensure `e` and the type of the free variables `xs` do not contain a metavariable `?m` s.t. local context of `?m` contains a free variable in `xs`. `elimMVarDeps` is defined later in this file. -/ @[inline] private def abstractRange (xs : Array Expr) (i : Nat) (e : Expr) : M Expr := do let e ← elimMVarDeps xs e pure (e.abstractRange i xs) /-- Similar to `LocalContext.mkBinding`, but handles metavariables correctly. If `usedOnly == false` then `forall` and `lambda` are created only for used variables. -/ @[specialize] def mkBinding (isLambda : Bool) (lctx : LocalContext) (xs : Array Expr) (e : Expr) (usedOnly : Bool := false) : M (Expr × Nat) := do let e ← abstractRange xs xs.size e xs.size.foldRevM (fun i (p : Expr × Nat) => do let (e, num) := p; let x := xs[i] match lctx.getFVar! x with | LocalDecl.cdecl _ _ n type bi => if !usedOnly || e.hasLooseBVar 0 then let type := type.headBeta; let type ← abstractRange xs i type if isLambda then pure (Lean.mkLambda n bi type e, num + 1) else pure (Lean.mkForall n bi type e, num + 1) else pure (e.lowerLooseBVars 1 1, num) | LocalDecl.ldecl _ _ n type value nonDep => if e.hasLooseBVar 0 then let type ← abstractRange xs i type let value ← abstractRange xs i value pure (mkLet n type value e nonDep, num + 1) else pure (e.lowerLooseBVars 1 1, num)) (e, 0) end MkBinding abbrev MkBindingM := ReaderT LocalContext MkBinding.MCore def elimMVarDeps (xs : Array Expr) (e : Expr) (preserveOrder : Bool) : MkBindingM Expr := fun _ => MkBinding.elimMVarDeps xs e preserveOrder def mkBinding (isLambda : Bool) (xs : Array Expr) (e : Expr) (usedOnly : Bool := false) : MkBindingM (Expr × Nat) := fun lctx => MkBinding.mkBinding isLambda lctx xs e usedOnly false @[inline] def mkLambda (xs : Array Expr) (e : Expr) : MkBindingM Expr := do let (e, _) ← mkBinding true xs e pure e @[inline] def mkForall (xs : Array Expr) (e : Expr) : MkBindingM Expr := do let (e, _) ← mkBinding false xs e pure e @[inline] def mkForallUsedOnly (xs : Array Expr) (e : Expr) : MkBindingM (Expr × Nat) := do mkBinding false xs e true /-- `isWellFormed mctx lctx e` return true if - All locals in `e` are declared in `lctx` - All metavariables `?m` in `e` have a local context which is a subprefix of `lctx` or are assigned, and the assignment is well-formed. -/ partial def isWellFormed (mctx : MetavarContext) (lctx : LocalContext) : Expr → Bool | Expr.mdata _ e _ => isWellFormed mctx lctx e | Expr.proj _ _ e _ => isWellFormed mctx lctx e | e@(Expr.app f a _) => (!e.hasExprMVar && !e.hasFVar) || (isWellFormed mctx lctx f && isWellFormed mctx lctx a) | e@(Expr.lam _ d b _) => (!e.hasExprMVar && !e.hasFVar) || (isWellFormed mctx lctx d && isWellFormed mctx lctx b) | e@(Expr.forallE _ d b _) => (!e.hasExprMVar && !e.hasFVar) || (isWellFormed mctx lctx d && isWellFormed mctx lctx b) | e@(Expr.letE _ t v b _) => (!e.hasExprMVar && !e.hasFVar) || (isWellFormed mctx lctx t && isWellFormed mctx lctx v && isWellFormed mctx lctx b) | Expr.const _ _ _ => true | Expr.bvar _ _ => true | Expr.sort _ _ => true | Expr.lit _ _ => true | Expr.mvar mvarId _ => let mvarDecl := mctx.getDecl mvarId; if mvarDecl.lctx.isSubPrefixOf lctx then true else match mctx.getExprAssignment? mvarId with | none => false | some v => isWellFormed mctx lctx v | Expr.fvar fvarId _ => lctx.contains fvarId namespace LevelMVarToParam structure Context := (paramNamePrefix : Name) (alreadyUsedPred : Name → Bool) structure State := (mctx : MetavarContext) (paramNames : Array Name := #[]) (nextParamIdx : Nat) abbrev M := ReaderT Context $ StateM State partial def mkParamName : M Name := do let ctx ← read let s ← get let newParamName := ctx.paramNamePrefix.appendIndexAfter s.nextParamIdx if ctx.alreadyUsedPred newParamName then modify fun s => { s with nextParamIdx := s.nextParamIdx + 1 } mkParamName else do modify fun s => { s with nextParamIdx := s.nextParamIdx + 1, paramNames := s.paramNames.push newParamName } pure newParamName partial def visitLevel (u : Level) : M Level := do match u with | Level.succ v _ => return u.updateSucc! (← visitLevel v) | Level.max v₁ v₂ _ => return u.updateMax! (← visitLevel v₁) (← visitLevel v₂) | Level.imax v₁ v₂ _ => return u.updateIMax! (← visitLevel v₁) (← visitLevel v₂) | Level.zero _ => pure u | Level.param _ _ => pure u | Level.mvar mvarId _ => let s ← get match s.mctx.getLevelAssignment? mvarId with | some v => visitLevel v | none => let p ← mkParamName let p := mkLevelParam p modify fun s => { s with mctx := s.mctx.assignLevel mvarId p } pure p partial def main (e : Expr) : M Expr := do if !e.hasMVar then pure e else match e with | Expr.proj _ _ s _ => return e.updateProj! (← main s) | Expr.forallE _ d b _ => return e.updateForallE! (← main d) (← main b) | Expr.lam _ d b _ => return e.updateLambdaE! (← main d) (← main b) | Expr.letE _ t v b _ => return e.updateLet! (← main t) (← main v) (← main b) | Expr.app f a _ => return e.updateApp! (← main f) (← main a) | Expr.mdata _ b _ => return e.updateMData! (← main b) | Expr.const _ us _ => return e.updateConst! (← us.mapM visitLevel) | Expr.sort u _ => return e.updateSort! (← visitLevel u) | Expr.mvar mvarId _ => let s ← get match s.mctx.getExprAssignment? mvarId with | some v => main v | none => pure e | e => pure e end LevelMVarToParam structure UnivMVarParamResult := (mctx : MetavarContext) (newParamNames : Array Name) (nextParamIdx : Nat) (expr : Expr) def levelMVarToParam (mctx : MetavarContext) (alreadyUsedPred : Name → Bool) (e : Expr) (paramNamePrefix : Name := `u) (nextParamIdx : Nat := 1) : UnivMVarParamResult := let (e, s) := LevelMVarToParam.main e { paramNamePrefix := paramNamePrefix, alreadyUsedPred := alreadyUsedPred } { mctx := mctx, nextParamIdx := nextParamIdx } { mctx := s.mctx, newParamNames := s.paramNames, nextParamIdx := s.nextParamIdx, expr := e } def getExprAssignmentDomain (mctx : MetavarContext) : Array MVarId := mctx.eAssignment.foldl (fun a mvarId _ => Array.push a mvarId) #[] end MetavarContext end Lean
08af41d11581e82392b8a4175555adf447f9636e
2a70b774d16dbdf5a533432ee0ebab6838df0948
/_target/deps/mathlib/src/set_theory/cofinality.lean
6e3cc4761f1d606f0b0c092efd2e266bebb6255f
[ "Apache-2.0" ]
permissive
hjvromen/lewis
40b035973df7c77ebf927afab7878c76d05ff758
105b675f73630f028ad5d890897a51b3c1146fb0
refs/heads/master
1,677,944,636,343
1,676,555,301,000
1,676,555,301,000
327,553,599
0
0
null
null
null
null
UTF-8
Lean
false
false
22,078
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro -/ import set_theory.cardinal_ordinal /-! # Cofinality on ordinals, regular cardinals -/ noncomputable theory open function cardinal set open_locale classical universes u v w variables {α : Type*} {r : α → α → Prop} namespace order /-- Cofinality of a reflexive order `≼`. This is the smallest cardinality of a subset `S : set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/ def cof (r : α → α → Prop) [is_refl α r] : cardinal := @cardinal.min {S : set α // ∀ a, ∃ b ∈ S, r a b} ⟨⟨set.univ, λ a, ⟨a, ⟨⟩, refl _⟩⟩⟩ (λ S, mk S) lemma cof_le (r : α → α → Prop) [is_refl α r] {S : set α} (h : ∀a, ∃(b ∈ S), r a b) : order.cof r ≤ mk S := le_trans (cardinal.min_le _ ⟨S, h⟩) (le_refl _) lemma le_cof {r : α → α → Prop} [is_refl α r] (c : cardinal) : c ≤ order.cof r ↔ ∀ {S : set α} (h : ∀a, ∃(b ∈ S), r a b) , c ≤ mk S := by { rw [order.cof, cardinal.le_min], exact ⟨λ H S h, H ⟨S, h⟩, λ H ⟨S, h⟩, H h ⟩ } end order theorem rel_iso.cof.aux {α : Type u} {β : Type v} {r s} [is_refl α r] [is_refl β s] (f : r ≃r s) : cardinal.lift.{u (max u v)} (order.cof r) ≤ cardinal.lift.{v (max u v)} (order.cof s) := begin rw [order.cof, order.cof, lift_min, lift_min, cardinal.le_min], intro S, cases S with S H, simp [(∘)], refine le_trans (min_le _ _) _, { exact ⟨f ⁻¹' S, λ a, let ⟨b, bS, h⟩ := H (f a) in ⟨f.symm b, by simp [bS, ← f.map_rel_iff, h, -coe_fn_coe_base, -coe_fn_coe_trans, principal_seg.coe_coe_fn', initial_seg.coe_coe_fn]⟩⟩ }, { exact lift_mk_le.{u v (max u v)}.2 ⟨⟨λ ⟨x, h⟩, ⟨f x, h⟩, λ ⟨x, h₁⟩ ⟨y, h₂⟩ h₃, by congr; injection h₃ with h'; exact f.to_equiv.injective h'⟩⟩ } end theorem rel_iso.cof {α : Type u} {β : Type v} {r s} [is_refl α r] [is_refl β s] (f : r ≃r s) : cardinal.lift.{u (max u v)} (order.cof r) = cardinal.lift.{v (max u v)} (order.cof s) := le_antisymm (rel_iso.cof.aux f) (rel_iso.cof.aux f.symm) def strict_order.cof (r : α → α → Prop) [h : is_irrefl α r] : cardinal := @order.cof α (λ x y, ¬ r y x) ⟨h.1⟩ namespace ordinal /-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is unbounded, in the sense `∀ a, ∃ b ∈ S, ¬(b > a)`. It is defined for all ordinals, but `cof 0 = 0` and `cof (succ o) = 1`, so it is only really interesting on limit ordinals (when it is an infinite cardinal). -/ def cof (o : ordinal.{u}) : cardinal.{u} := quot.lift_on o (λ ⟨α, r, _⟩, by exactI strict_order.cof r) begin rintros ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨⟨f, hf⟩⟩, rw ← cardinal.lift_inj, apply rel_iso.cof ⟨f, _⟩, simp [hf] end lemma cof_type (r : α → α → Prop) [is_well_order α r] : (type r).cof = strict_order.cof r := rfl theorem le_cof_type [is_well_order α r] {c} : c ≤ cof (type r) ↔ ∀ S : set α, (∀ a, ∃ b ∈ S, ¬ r b a) → c ≤ mk S := by dsimp [cof, strict_order.cof, order.cof, type, quotient.mk, quot.lift_on]; rw [cardinal.le_min, subtype.forall]; refl theorem cof_type_le [is_well_order α r] (S : set α) (h : ∀ a, ∃ b ∈ S, ¬ r b a) : cof (type r) ≤ mk S := le_cof_type.1 (le_refl _) S h theorem lt_cof_type [is_well_order α r] (S : set α) (hl : mk S < cof (type r)) : ∃ a, ∀ b ∈ S, r b a := not_forall_not.1 $ λ h, not_le_of_lt hl $ cof_type_le S (λ a, not_ball.1 (h a)) theorem cof_eq (r : α → α → Prop) [is_well_order α r] : ∃ S : set α, (∀ a, ∃ b ∈ S, ¬ r b a) ∧ mk S = cof (type r) := begin have : ∃ i, cof (type r) = _, { dsimp [cof, order.cof, type, quotient.mk, quot.lift_on], apply cardinal.min_eq }, exact let ⟨⟨S, hl⟩, e⟩ := this in ⟨S, hl, e.symm⟩, end theorem ord_cof_eq (r : α → α → Prop) [is_well_order α r] : ∃ S : set α, (∀ a, ∃ b ∈ S, ¬ r b a) ∧ type (subrel r S) = (cof (type r)).ord := let ⟨S, hS, e⟩ := cof_eq r, ⟨s, _, e'⟩ := cardinal.ord_eq S, T : set α := {a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a} in begin resetI, suffices, { refine ⟨T, this, le_antisymm _ (cardinal.ord_le.2 $ cof_type_le T this)⟩, rw [← e, e'], refine type_le'.2 ⟨rel_embedding.of_monotone (λ a, ⟨a, let ⟨aS, _⟩ := a.2 in aS⟩) (λ a b h, _)⟩, rcases a with ⟨a, aS, ha⟩, rcases b with ⟨b, bS, hb⟩, change s ⟨a, _⟩ ⟨b, _⟩, refine ((trichotomous_of s _ _).resolve_left (λ hn, _)).resolve_left _, { exact asymm h (ha _ hn) }, { intro e, injection e with e, subst b, exact irrefl _ h } }, { intro a, have : {b : S | ¬ r b a}.nonempty := let ⟨b, bS, ba⟩ := hS a in ⟨⟨b, bS⟩, ba⟩, let b := (is_well_order.wf).min _ this, have ba : ¬r b a := (is_well_order.wf).min_mem _ this, refine ⟨b, ⟨b.2, λ c, not_imp_not.1 $ λ h, _⟩, ba⟩, rw [show ∀b:S, (⟨b, b.2⟩:S) = b, by intro b; cases b; refl], exact (is_well_order.wf).not_lt_min _ this (is_order_connected.neg_trans h ba) } end theorem lift_cof (o) : (cof o).lift = cof o.lift := induction_on o $ begin introsI α r _, cases lift_type r with _ e, rw e, apply le_antisymm, { unfreezingI { refine le_cof_type.2 (λ S H, _) }, have : (mk (ulift.up ⁻¹' S)).lift ≤ mk S := ⟨⟨λ ⟨⟨x, h⟩⟩, ⟨⟨x⟩, h⟩, λ ⟨⟨x, h₁⟩⟩ ⟨⟨y, h₂⟩⟩ e, by simp at e; congr; injection e⟩⟩, refine le_trans (cardinal.lift_le.2 $ cof_type_le _ _) this, exact λ a, let ⟨⟨b⟩, bs, br⟩ := H ⟨a⟩ in ⟨b, bs, br⟩ }, { rcases cof_eq r with ⟨S, H, e'⟩, have : mk (ulift.down ⁻¹' S) ≤ (mk S).lift := ⟨⟨λ ⟨⟨x⟩, h⟩, ⟨⟨x, h⟩⟩, λ ⟨⟨x⟩, h₁⟩ ⟨⟨y⟩, h₂⟩ e, by simp at e; congr; injections⟩⟩, rw e' at this, unfreezingI { refine le_trans (cof_type_le _ _) this }, exact λ ⟨a⟩, let ⟨b, bs, br⟩ := H a in ⟨⟨b⟩, bs, br⟩ } end theorem cof_le_card (o) : cof o ≤ card o := induction_on o $ λ α r _, begin resetI, have : mk (@set.univ α) = card (type r) := quotient.sound ⟨equiv.set.univ _⟩, rw ← this, exact cof_type_le set.univ (λ a, ⟨a, ⟨⟩, irrefl a⟩) end theorem cof_ord_le (c : cardinal) : cof c.ord ≤ c := by simpa using cof_le_card c.ord @[simp] theorem cof_zero : cof 0 = 0 := le_antisymm (by simpa using cof_le_card 0) (cardinal.zero_le _) @[simp] theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 := ⟨induction_on o $ λ α r _ z, by exactI let ⟨S, hl, e⟩ := cof_eq r in type_eq_zero_iff_empty.2 $ λ ⟨a⟩, let ⟨b, h, _⟩ := hl a in ne_zero_iff_nonempty.2 (by exact ⟨⟨_, h⟩⟩) (e.trans z), λ e, by simp [e]⟩ @[simp] theorem cof_succ (o) : cof (succ o) = 1 := begin apply le_antisymm, { refine induction_on o (λ α r _, _), change cof (type _) ≤ _, rw [← (_ : mk _ = 1)], apply cof_type_le, { refine λ a, ⟨sum.inr punit.star, set.mem_singleton _, _⟩, rcases a with a|⟨⟨⟨⟩⟩⟩; simp [empty_relation] }, { rw [cardinal.fintype_card, set.card_singleton], simp } }, { rw [← cardinal.succ_zero, cardinal.succ_le], simpa [lt_iff_le_and_ne, cardinal.zero_le] using λ h, succ_ne_zero o (cof_eq_zero.1 (eq.symm h)) } end @[simp] theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a := ⟨induction_on o $ λ α r _ z, begin resetI, rcases cof_eq r with ⟨S, hl, e⟩, rw z at e, cases ne_zero_iff_nonempty.1 (by rw e; exact one_ne_zero) with a, refine ⟨typein r a, eq.symm $ quotient.sound ⟨rel_iso.of_surjective (rel_embedding.of_monotone _ (λ x y, _)) (λ x, _)⟩⟩, { apply sum.rec; [exact subtype.val, exact λ _, a] }, { rcases x with x|⟨⟨⟨⟩⟩⟩; rcases y with y|⟨⟨⟨⟩⟩⟩; simp [subrel, order.preimage, empty_relation], exact x.2 }, { suffices : r x a ∨ ∃ (b : punit), ↑a = x, {simpa}, rcases trichotomous_of r x a with h|h|h, { exact or.inl h }, { exact or.inr ⟨punit.star, h.symm⟩ }, { rcases hl x with ⟨a', aS, hn⟩, rw (_ : ↑a = a') at h, {exact absurd h hn}, refine congr_arg subtype.val (_ : a = ⟨a', aS⟩), haveI := le_one_iff_subsingleton.1 (le_of_eq e), apply subsingleton.elim } } end, λ ⟨a, e⟩, by simp [e]⟩ @[simp] theorem cof_add (a b : ordinal) : b ≠ 0 → cof (a + b) = cof b := induction_on a $ λ α r _, induction_on b $ λ β s _ b0, begin resetI, change cof (type _) = _, refine eq_of_forall_le_iff (λ c, _), rw [le_cof_type, le_cof_type], split; intros H S hS, { refine le_trans (H {a | sum.rec_on a (∅:set α) S} (λ a, _)) ⟨⟨_, _⟩⟩, { cases a with a b, { cases type_ne_zero_iff_nonempty.1 b0 with b, rcases hS b with ⟨b', bs, _⟩, exact ⟨sum.inr b', bs, by simp⟩ }, { rcases hS b with ⟨b', bs, h⟩, exact ⟨sum.inr b', bs, by simp [h]⟩ } }, { exact λ a, match a with ⟨sum.inr b, h⟩ := ⟨b, h⟩ end }, { exact λ a b, match a, b with ⟨sum.inr a, h₁⟩, ⟨sum.inr b, h₂⟩, h := by congr; injection h end } }, { refine le_trans (H (sum.inr ⁻¹' S) (λ a, _)) ⟨⟨_, _⟩⟩, { rcases hS (sum.inr a) with ⟨a'|b', bs, h⟩; simp at h, { cases h }, { exact ⟨b', bs, h⟩ } }, { exact λ ⟨a, h⟩, ⟨_, h⟩ }, { exact λ ⟨a, h₁⟩ ⟨b, h₂⟩ h, by injection h with h; congr; injection h } } end @[simp] theorem cof_cof (o : ordinal) : cof (cof o).ord= cof o := le_antisymm (le_trans (cof_le_card _) (by simp)) $ induction_on o $ λ α r _, by exactI let ⟨S, hS, e₁⟩ := ord_cof_eq r, ⟨T, hT, e₂⟩ := cof_eq (subrel r S) in begin rw e₁ at e₂, rw ← e₂, refine le_trans (cof_type_le {a | ∃ h, (subtype.mk a h : S) ∈ T} (λ a, _)) ⟨⟨_, _⟩⟩, { rcases hS a with ⟨b, bS, br⟩, rcases hT ⟨b, bS⟩ with ⟨⟨c, cS⟩, cT, cs⟩, exact ⟨c, ⟨cS, cT⟩, is_order_connected.neg_trans cs br⟩ }, { exact λ ⟨a, h⟩, ⟨⟨a, h.fst⟩, h.snd⟩ }, { exact λ ⟨a, ha⟩ ⟨b, hb⟩ h, by injection h with h; congr; injection h }, end theorem omega_le_cof {o} : cardinal.omega ≤ cof o ↔ is_limit o := begin rcases zero_or_succ_or_limit o with rfl|⟨o,rfl⟩|l, { simp [not_zero_is_limit, cardinal.omega_ne_zero] }, { simp [not_succ_is_limit, cardinal.one_lt_omega] }, { simp [l], refine le_of_not_lt (λ h, _), cases cardinal.lt_omega.1 h with n e, have := cof_cof o, rw [e, ord_nat] at this, cases n, { simp at e, simpa [e, not_zero_is_limit] using l }, { rw [← nat_cast_succ, cof_succ] at this, rw [← this, cof_eq_one_iff_is_succ] at e, rcases e with ⟨a, rfl⟩, exact not_succ_is_limit _ l } } end @[simp] theorem cof_omega : cof omega = cardinal.omega := le_antisymm (by rw ← card_omega; apply cof_le_card) (omega_le_cof.2 omega_is_limit) theorem cof_eq' (r : α → α → Prop) [is_well_order α r] (h : is_limit (type r)) : ∃ S : set α, (∀ a, ∃ b ∈ S, r a b) ∧ mk S = cof (type r) := let ⟨S, H, e⟩ := cof_eq r in ⟨S, λ a, let a' := enum r _ (h.2 _ (typein_lt_type r a)) in let ⟨b, h, ab⟩ := H a' in ⟨b, h, (is_order_connected.conn a b a' $ (typein_lt_typein r).1 (by rw typein_enum; apply ordinal.lt_succ_self)).resolve_right ab⟩, e⟩ theorem cof_sup_le_lift {ι} (f : ι → ordinal) (H : ∀ i, f i < sup f) : cof (sup f) ≤ (mk ι).lift := begin generalize e : sup f = o, refine ordinal.induction_on o _ e, introsI α r _ e', rw e' at H, refine le_trans (cof_type_le (set.range (λ i, enum r _ (H i))) _) ⟨embedding.of_surjective _ _⟩, { intro a, by_contra h, apply not_le_of_lt (typein_lt_type r a), rw [← e', sup_le], intro i, have h : ∀ (x : ι), r (enum r (f x) _) a, { simpa using h }, simpa only [typein_enum] using le_of_lt ((typein_lt_typein r).2 (h i)) }, { exact λ i, ⟨_, set.mem_range_self i.1⟩ }, { intro a, rcases a with ⟨_, i, rfl⟩, exact ⟨⟨i⟩, by simp⟩ } end theorem cof_sup_le {ι} (f : ι → ordinal) (H : ∀ i, f i < sup.{u u} f) : cof (sup.{u u} f) ≤ mk ι := by simpa using cof_sup_le_lift.{u u} f H theorem cof_bsup_le_lift {o : ordinal} : ∀ (f : Π a < o, ordinal), (∀ i h, f i h < bsup o f) → cof (bsup o f) ≤ o.card.lift := induction_on o $ λ α r _ f H, by rw bsup_type; refine cof_sup_le_lift _ _; rw ← bsup_type; intro a; apply H theorem cof_bsup_le {o : ordinal} : ∀ (f : Π a < o, ordinal), (∀ i h, f i h < bsup.{u u} o f) → cof (bsup.{u u} o f) ≤ o.card := induction_on o $ λ α r _ f H, by simpa using cof_bsup_le_lift.{u u} f H @[simp] theorem cof_univ : cof univ.{u v} = cardinal.univ := le_antisymm (cof_le_card _) begin refine le_of_forall_lt (λ c h, _), rcases lt_univ'.1 h with ⟨c, rfl⟩, rcases @cof_eq ordinal.{u} (<) _ with ⟨S, H, Se⟩, rw [univ, ← lift_cof, ← cardinal.lift_lift, cardinal.lift_lt, ← Se], refine lt_of_not_ge (λ h, _), cases cardinal.lift_down h with a e, refine quotient.induction_on a (λ α e, _) e, cases quotient.exact e with f, have f := equiv.ulift.symm.trans f, let g := λ a, (f a).1, let o := succ (sup.{u u} g), rcases H o with ⟨b, h, l⟩, refine l (lt_succ.2 _), rw ← show g (f.symm ⟨b, h⟩) = b, by dsimp [g]; simp, apply le_sup end theorem sup_lt_ord {ι} (f : ι → ordinal) {c : ordinal} (H1 : cardinal.mk ι < c.cof) (H2 : ∀ i, f i < c) : sup.{u u} f < c := begin apply lt_of_le_of_ne, { rw [sup_le], exact λ i, le_of_lt (H2 i) }, rintro h, apply not_le_of_lt H1, simpa [sup_ord, H2, h] using cof_sup_le.{u} f end theorem sup_lt {ι} (f : ι → cardinal) {c : cardinal} (H1 : cardinal.mk ι < c.ord.cof) (H2 : ∀ i, f i < c) : cardinal.sup.{u u} f < c := by { rw [←ord_lt_ord, ←sup_ord], apply sup_lt_ord _ H1, intro i, rw ord_lt_ord, apply H2 } /-- If the union of s is unbounded and s is smaller than the cofinality, then s has an unbounded member -/ theorem unbounded_of_unbounded_sUnion (r : α → α → Prop) [wo : is_well_order α r] {s : set (set α)} (h₁ : unbounded r $ ⋃₀ s) (h₂ : mk s < strict_order.cof r) : ∃(x ∈ s), unbounded r x := begin by_contra h, simp only [not_exists, exists_prop, not_and, not_unbounded_iff] at h, apply not_le_of_lt h₂, let f : s → α := λ x : s, wo.wf.sup x (h x.1 x.2), let t : set α := range f, have : mk t ≤ mk s, exact mk_range_le, refine le_trans _ this, have : unbounded r t, { intro x, rcases h₁ x with ⟨y, ⟨c, hc, hy⟩, hxy⟩, refine ⟨f ⟨c, hc⟩, mem_range_self _, _⟩, intro hxz, apply hxy, refine trans (wo.wf.lt_sup _ hy) hxz }, exact cardinal.min_le _ (subtype.mk t this) end /-- If the union of s is unbounded and s is smaller than the cofinality, then s has an unbounded member -/ theorem unbounded_of_unbounded_Union {α β : Type u} (r : α → α → Prop) [wo : is_well_order α r] (s : β → set α) (h₁ : unbounded r $ ⋃x, s x) (h₂ : mk β < strict_order.cof r) : ∃x : β, unbounded r (s x) := begin rw [← sUnion_range] at h₁, have : mk ↥(range (λ (i : β), s i)) < strict_order.cof r := lt_of_le_of_lt mk_range_le h₂, rcases unbounded_of_unbounded_sUnion r h₁ this with ⟨_, ⟨x, rfl⟩, u⟩, exact ⟨x, u⟩ end /-- The infinite pigeonhole principle-/ theorem infinite_pigeonhole {β α : Type u} (f : β → α) (h₁ : cardinal.omega ≤ mk β) (h₂ : mk α < (mk β).ord.cof) : ∃a : α, mk (f ⁻¹' {a}) = mk β := begin have : ¬∀a, mk (f ⁻¹' {a}) < mk β, { intro h, apply not_lt_of_ge (ge_of_eq $ mk_univ), rw [←@preimage_univ _ _ f, ←Union_of_singleton, preimage_Union], apply lt_of_le_of_lt mk_Union_le_sum_mk, apply lt_of_le_of_lt (sum_le_sup _), apply mul_lt_of_lt h₁ (lt_of_lt_of_le h₂ $ cof_ord_le _), exact sup_lt _ h₂ h }, rw [not_forall] at this, cases this with x h, use x, apply le_antisymm _ (le_of_not_gt h), rw [le_mk_iff_exists_set], exact ⟨_, rfl⟩ end /-- pigeonhole principle for a cardinality below the cardinality of the domain -/ theorem infinite_pigeonhole_card {β α : Type u} (f : β → α) (θ : cardinal) (hθ : θ ≤ mk β) (h₁ : cardinal.omega ≤ θ) (h₂ : mk α < θ.ord.cof) : ∃a : α, θ ≤ mk (f ⁻¹' {a}) := begin rcases le_mk_iff_exists_set.1 hθ with ⟨s, rfl⟩, cases infinite_pigeonhole (f ∘ subtype.val : s → α) h₁ h₂ with a ha, use a, rw [←ha, @preimage_comp _ _ _ subtype.val f], apply mk_preimage_of_injective _ _ subtype.val_injective end theorem infinite_pigeonhole_set {β α : Type u} {s : set β} (f : s → α) (θ : cardinal) (hθ : θ ≤ mk s) (h₁ : cardinal.omega ≤ θ) (h₂ : mk α < θ.ord.cof) : ∃(a : α) (t : set β) (h : t ⊆ s), θ ≤ mk t ∧ ∀{{x}} (hx : x ∈ t), f ⟨x, h hx⟩ = a := begin cases infinite_pigeonhole_card f θ hθ h₁ h₂ with a ha, refine ⟨a, {x | ∃(h : x ∈ s), f ⟨x, h⟩ = a}, _, _, _⟩, { rintro x ⟨hx, hx'⟩, exact hx }, { refine le_trans ha _, apply ge_of_eq, apply quotient.sound, constructor, refine equiv.trans _ (equiv.subtype_subtype_equiv_subtype_exists _ _).symm, simp only [set_coe_eq_subtype, mem_singleton_iff, mem_preimage, mem_set_of_eq] }, rintro x ⟨hx, hx'⟩, exact hx' end end ordinal namespace cardinal open ordinal local infixr ^ := @pow cardinal.{u} cardinal cardinal.has_pow /-- A cardinal is a limit if it is not zero or a successor cardinal. Note that `ω` is a limit cardinal by this definition. -/ def is_limit (c : cardinal) : Prop := c ≠ 0 ∧ ∀ x < c, succ x < c /-- A cardinal is a strong limit if it is not zero and it is closed under powersets. Note that `ω` is a strong limit by this definition. -/ def is_strong_limit (c : cardinal) : Prop := c ≠ 0 ∧ ∀ x < c, 2 ^ x < c theorem is_strong_limit.is_limit {c} (H : is_strong_limit c) : is_limit c := ⟨H.1, λ x h, lt_of_le_of_lt (succ_le.2 $ cantor _) (H.2 _ h)⟩ /-- A cardinal is regular if it is infinite and it equals its own cofinality. -/ def is_regular (c : cardinal) : Prop := omega ≤ c ∧ c.ord.cof = c theorem cof_is_regular {o : ordinal} (h : o.is_limit) : is_regular o.cof := ⟨omega_le_cof.2 h, cof_cof _⟩ theorem omega_is_regular : is_regular omega := ⟨le_refl _, by simp⟩ theorem succ_is_regular {c : cardinal.{u}} (h : omega ≤ c) : is_regular (succ c) := ⟨le_trans h (le_of_lt $ lt_succ_self _), begin refine le_antisymm (cof_ord_le _) (succ_le.2 _), cases quotient.exists_rep (succ c) with α αe, simp at αe, rcases ord_eq α with ⟨r, wo, re⟩, resetI, have := ord_is_limit (le_trans h $ le_of_lt $ lt_succ_self _), rw [← αe, re] at this ⊢, rcases cof_eq' r this with ⟨S, H, Se⟩, rw [← Se], apply lt_imp_lt_of_le_imp_le (λ (h : mk S ≤ c), canonically_ordered_semiring.mul_le_mul_right' h c), rw [mul_eq_self h, ← succ_le, ← αe, ← sum_const], refine le_trans _ (sum_le_sum (λ x:S, card (typein r x)) _ _), { simp [typein, sum_mk (λ x:S, {a//r a x})], refine ⟨embedding.of_surjective _ _⟩, { exact λ x, x.2.1 }, { exact λ a, let ⟨b, h, ab⟩ := H a in ⟨⟨⟨_, h⟩, _, ab⟩, rfl⟩ } }, { intro i, rw [← lt_succ, ← lt_ord, ← αe, re], apply typein_lt_type } end⟩ theorem sup_lt_ord_of_is_regular {ι} (f : ι → ordinal) {c} (hc : is_regular c) (H1 : cardinal.mk ι < c) (H2 : ∀ i, f i < c.ord) : ordinal.sup.{u u} f < c.ord := by { apply sup_lt_ord _ _ H2, rw [hc.2], exact H1 } theorem sup_lt_of_is_regular {ι} (f : ι → cardinal) {c} (hc : is_regular c) (H1 : cardinal.mk ι < c) (H2 : ∀ i, f i < c) : sup.{u u} f < c := by { apply sup_lt _ _ H2, rwa [hc.2] } theorem sum_lt_of_is_regular {ι} (f : ι → cardinal) {c} (hc : is_regular c) (H1 : cardinal.mk ι < c) (H2 : ∀ i, f i < c) : sum.{u u} f < c := lt_of_le_of_lt (sum_le_sup _) $ mul_lt_of_lt hc.1 H1 $ sup_lt_of_is_regular f hc H1 H2 /-- A cardinal is inaccessible if it is an uncountable regular strong limit cardinal. -/ def is_inaccessible (c : cardinal) := omega < c ∧ is_regular c ∧ is_strong_limit c theorem is_inaccessible.mk {c} (h₁ : omega < c) (h₂ : c ≤ c.ord.cof) (h₃ : ∀ x < c, 2 ^ x < c) : is_inaccessible c := ⟨h₁, ⟨le_of_lt h₁, le_antisymm (cof_ord_le _) h₂⟩, ne_of_gt (lt_trans omega_pos h₁), h₃⟩ /- Lean's foundations prove the existence of ω many inaccessible cardinals -/ theorem univ_inaccessible : is_inaccessible (univ.{u v}) := is_inaccessible.mk (by simpa using lift_lt_univ' omega) (by simp) (λ c h, begin rcases lt_univ'.1 h with ⟨c, rfl⟩, rw ← lift_two_power.{u (max (u+1) v)}, apply lift_lt_univ' end) theorem lt_power_cof {c : cardinal.{u}} : omega ≤ c → c < c ^ cof c.ord := quotient.induction_on c $ λ α h, begin rcases ord_eq α with ⟨r, wo, re⟩, resetI, have := ord_is_limit h, rw [mk_def, re] at this ⊢, rcases cof_eq' r this with ⟨S, H, Se⟩, have := sum_lt_prod (λ a:S, mk {x // r x a}) (λ _, mk α) (λ i, _), { simp [Se.symm] at this ⊢, refine lt_of_le_of_lt _ this, refine ⟨embedding.of_surjective _ _⟩, { exact λ x, x.2.1 }, { exact λ a, let ⟨b, h, ab⟩ := H a in ⟨⟨⟨_, h⟩, _, ab⟩, rfl⟩ } }, { have := typein_lt_type r i, rwa [← re, lt_ord] at this } end theorem lt_cof_power {a b : cardinal} (ha : omega ≤ a) (b1 : 1 < b) : a < cof (b ^ a).ord := begin have b0 : b ≠ 0 := ne_of_gt (lt_trans zero_lt_one b1), apply lt_imp_lt_of_le_imp_le (power_le_power_left $ power_ne_zero a b0), rw [power_mul, mul_eq_self ha], exact lt_power_cof (le_trans ha $ le_of_lt $ cantor' _ b1), end end cardinal
48fb38b042ebe5804fcb8c62622712cc97a9b266
0c1546a496eccfb56620165cad015f88d56190c5
/tests/lean/interactive/my_tac_class.lean
99814a66e7f8d98ca02cddf11d62589d076a973a
[ "Apache-2.0" ]
permissive
Solertis/lean
491e0939957486f664498fbfb02546e042699958
84188c5aa1673fdf37a082b2de8562dddf53df3f
refs/heads/master
1,610,174,257,606
1,486,263,620,000
1,486,263,620,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,654
lean
meta def mytac := state_t nat tactic meta instance : monad mytac := state_t.monad _ _ meta instance : monad.has_monad_lift tactic mytac := monad.monad_transformer_lift (state_t nat) tactic meta instance (α : Type) : has_coe (tactic α) (mytac α) := ⟨monad.monad_lift⟩ namespace mytac meta def step {α : Type} (t : mytac α) : mytac unit := t >> return () meta def rstep {α : Type} (line : nat) (col : nat) (t : mytac α) : mytac unit := λ v s, tactic_result.cases_on (@scope_trace _ line col (t v s)) (λ ⟨a, v⟩ new_s, tactic_result.success ((), v) new_s) (λ msg_thunk e new_s, let msg := msg_thunk () ++ format.line ++ to_fmt "value: " ++ to_fmt v ++ format.line ++ to_fmt "state:" ++ format.line ++ new_s^.to_format in (tactic.report_error line col msg >> tactic.failed) new_s) meta def execute (tac : mytac unit) : tactic unit := tac 0 >> return () meta def save_info (line col : nat) : mytac unit := do v ← state_t.read, s ← tactic.read, tactic.save_info_thunk line col (λ _, to_fmt "Custom state: " ++ to_fmt v ++ format.line ++ tactic_state.to_format s) namespace interactive meta def intros : mytac unit := tactic.intros >> return () meta def constructor : mytac unit := tactic.constructor meta def trace (s : string) : mytac unit := tactic.trace s meta def assumption : mytac unit := tactic.assumption meta def inc : mytac unit := do v ← state_t.read, state_t.write (v+1) end interactive end mytac example (p q : Prop) : p → q → p ∧ q := begin [mytac] intros, inc, trace "test", constructor, inc, assumption, --^ "command": "info" assumption end
7cfc8cbec4bd5ce7cf9948fe8df781d0fa2ee232
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/491.lean
a4fa2f8a12753387036ba2e9c0b0d0c670cee9ee
[ "Apache-2.0" ]
permissive
soonhokong/lean
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
38607e3eb57f57f77c0ac114ad169e9e4262e24f
refs/heads/master
1,611,187,284,081
1,450,766,737,000
1,476,122,547,000
11,513,992
2
0
null
1,401,763,102,000
1,374,182,235,000
C++
UTF-8
Lean
false
false
134
lean
import data.int open eq.ops int variable A : Type variables a b : A variable H : a = b check H⁻¹ check -(1:int) check (1:int) + -2
718ee3fcb5e9eb83906d1398355f2e39a0014c28
c777c32c8e484e195053731103c5e52af26a25d1
/src/algebra/order/upper_lower.lean
3f36d91f00fa137120bd1d9a16f2c34f2352b743
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib
2ff9e85dfe2a46f4b291927f983afec17e946eb8
58537299e922f9c77df76cb613910914a479c1f7
refs/heads/master
1,685,313,702,744
1,683,974,212,000
1,683,974,212,000
128,185,277
1
0
null
1,522,920,600,000
1,522,920,600,000
null
UTF-8
Lean
false
false
7,787
lean
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import algebra.order.group.defs import data.set.pointwise.smul import order.upper_lower.basic /-! # Algebraic operations on upper/lower sets > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Upper/lower sets are preserved under pointwise algebraic operations in ordered groups. -/ open function set open_locale pointwise section ordered_comm_monoid variables {α : Type*} [ordered_comm_monoid α] {s : set α} {x : α} @[to_additive] lemma is_upper_set.smul_subset (hs : is_upper_set s) (hx : 1 ≤ x) : x • s ⊆ s := smul_set_subset_iff.2 $ λ y, hs $ le_mul_of_one_le_left' hx @[to_additive] lemma is_lower_set.smul_subset (hs : is_lower_set s) (hx : x ≤ 1) : x • s ⊆ s := smul_set_subset_iff.2 $ λ y, hs $ mul_le_of_le_one_left' hx end ordered_comm_monoid section ordered_comm_group variables {α : Type*} [ordered_comm_group α] {s t : set α} {a : α} @[to_additive] lemma is_upper_set.smul (hs : is_upper_set s) : is_upper_set (a • s) := begin rintro _ y hxy ⟨x, hx, rfl⟩, exact mem_smul_set_iff_inv_smul_mem.2 (hs (le_inv_mul_iff_mul_le.2 hxy) hx), end @[to_additive] lemma is_lower_set.smul (hs : is_lower_set s) : is_lower_set (a • s) := hs.of_dual.smul @[to_additive] lemma set.ord_connected.smul (hs : s.ord_connected) : (a • s).ord_connected := begin rw [←hs.upper_closure_inter_lower_closure, smul_set_inter], exact (upper_closure _).upper.smul.ord_connected.inter (lower_closure _).lower.smul.ord_connected, end @[to_additive] lemma is_upper_set.mul_left (ht : is_upper_set t) : is_upper_set (s * t) := by { rw [←smul_eq_mul, ←bUnion_smul_set], exact is_upper_set_Union₂ (λ x hx, ht.smul) } @[to_additive] lemma is_upper_set.mul_right (hs : is_upper_set s) : is_upper_set (s * t) := by { rw mul_comm, exact hs.mul_left } @[to_additive] lemma is_lower_set.mul_left (ht : is_lower_set t) : is_lower_set (s * t) := ht.of_dual.mul_left @[to_additive] lemma is_lower_set.mul_right (hs : is_lower_set s) : is_lower_set (s * t) := hs.of_dual.mul_right @[to_additive] lemma is_upper_set.inv (hs : is_upper_set s) : is_lower_set s⁻¹ := λ x y h, hs $ inv_le_inv' h @[to_additive] lemma is_lower_set.inv (hs : is_lower_set s) : is_upper_set s⁻¹ := λ x y h, hs $ inv_le_inv' h @[to_additive] lemma is_upper_set.div_left (ht : is_upper_set t) : is_lower_set (s / t) := by { rw div_eq_mul_inv, exact ht.inv.mul_left } @[to_additive] lemma is_upper_set.div_right (hs : is_upper_set s) : is_upper_set (s / t) := by { rw div_eq_mul_inv, exact hs.mul_right } @[to_additive] lemma is_lower_set.div_left (ht : is_lower_set t) : is_upper_set (s / t) := ht.of_dual.div_left @[to_additive] lemma is_lower_set.div_right (hs : is_lower_set s) : is_lower_set (s / t) := hs.of_dual.div_right namespace upper_set @[to_additive] instance : has_one (upper_set α) := ⟨Ici 1⟩ @[to_additive] instance : has_mul (upper_set α) := ⟨λ s t, ⟨image2 (*) s t, s.2.mul_right⟩⟩ @[to_additive] instance : has_div (upper_set α) := ⟨λ s t, ⟨image2 (/) s t, s.2.div_right⟩⟩ @[to_additive] instance : has_smul α (upper_set α) := ⟨λ a s, ⟨(•) a '' s, s.2.smul⟩⟩ @[simp, norm_cast, to_additive] lemma coe_one : ((1 : upper_set α) : set α) = set.Ici 1 := rfl @[simp, norm_cast, to_additive] lemma coe_smul (a : α) (s : upper_set α) : (↑(a • s) : set α) = a • s := rfl @[simp, norm_cast, to_additive] lemma coe_mul (s t : upper_set α) : (↑(s * t) : set α) = s * t := rfl @[simp, norm_cast, to_additive] lemma coe_div (s t : upper_set α) : (↑(s / t) : set α) = s / t := rfl @[simp, to_additive] lemma Ici_one : Ici (1 : α) = 1 := rfl @[to_additive] instance : mul_action α (upper_set α) := set_like.coe_injective.mul_action _ coe_smul @[to_additive] instance : comm_semigroup (upper_set α) := { mul := (*), ..(set_like.coe_injective.comm_semigroup _ coe_mul : comm_semigroup (upper_set α)) } @[to_additive] private lemma one_mul (s : upper_set α) : 1 * s = s := set_like.coe_injective $ (subset_mul_right _ left_mem_Ici).antisymm' $ by { rw [←smul_eq_mul, ←bUnion_smul_set], exact Union₂_subset (λ _, s.upper.smul_subset) } @[to_additive] instance : comm_monoid (upper_set α) := { one := 1, one_mul := one_mul, mul_one := λ s, by { rw mul_comm, exact one_mul _ }, ..upper_set.comm_semigroup } end upper_set namespace lower_set @[to_additive] instance : has_one (lower_set α) := ⟨Iic 1⟩ @[to_additive] instance : has_mul (lower_set α) := ⟨λ s t, ⟨image2 (*) s t, s.2.mul_right⟩⟩ @[to_additive] instance : has_div (lower_set α) := ⟨λ s t, ⟨image2 (/) s t, s.2.div_right⟩⟩ @[to_additive] instance : has_smul α (lower_set α) := ⟨λ a s, ⟨(•) a '' s, s.2.smul⟩⟩ @[simp, norm_cast, to_additive] lemma coe_smul (a : α) (s : lower_set α) : (↑(a • s) : set α) = a • s := rfl @[simp, norm_cast, to_additive] lemma coe_mul (s t : lower_set α) : (↑(s * t) : set α) = s * t := rfl @[simp, norm_cast, to_additive] lemma coe_div (s t : lower_set α) : (↑(s / t) : set α) = s / t := rfl @[simp, to_additive] lemma Iic_one : Iic (1 : α) = 1 := rfl @[to_additive] instance : mul_action α (lower_set α) := set_like.coe_injective.mul_action _ coe_smul @[to_additive] instance : comm_semigroup (lower_set α) := { mul := (*), ..(set_like.coe_injective.comm_semigroup _ coe_mul : comm_semigroup (lower_set α)) } @[to_additive] private lemma one_mul (s : lower_set α) : 1 * s = s := set_like.coe_injective $ (subset_mul_right _ right_mem_Iic).antisymm' $ by { rw [←smul_eq_mul, ←bUnion_smul_set], exact Union₂_subset (λ _, s.lower.smul_subset) } @[to_additive] instance : comm_monoid (lower_set α) := { one := 1, one_mul := one_mul, mul_one := λ s, by { rw mul_comm, exact one_mul _ }, ..lower_set.comm_semigroup } end lower_set variables (a s t) @[simp, to_additive] lemma upper_closure_one : upper_closure (1 : set α) = 1 := upper_closure_singleton _ @[simp, to_additive] lemma lower_closure_one : lower_closure (1 : set α) = 1 := lower_closure_singleton _ @[simp, to_additive] lemma upper_closure_smul : upper_closure (a • s) = a • upper_closure s := upper_closure_image $ order_iso.mul_left a @[simp, to_additive] lemma lower_closure_smul : lower_closure (a • s) = a • lower_closure s := lower_closure_image $ order_iso.mul_left a @[to_additive] lemma mul_upper_closure : s * upper_closure t = upper_closure (s * t) := by simp_rw [←smul_eq_mul, ←bUnion_smul_set, upper_closure_Union, upper_closure_smul, upper_set.coe_infi₂, upper_set.coe_smul] @[to_additive] lemma mul_lower_closure : s * lower_closure t = lower_closure (s * t) := by simp_rw [←smul_eq_mul, ←bUnion_smul_set, lower_closure_Union, lower_closure_smul, lower_set.coe_supr₂, lower_set.coe_smul] @[to_additive] lemma upper_closure_mul : ↑(upper_closure s) * t = upper_closure (s * t) := by { simp_rw mul_comm _ t, exact mul_upper_closure _ _ } @[to_additive] lemma lower_closure_mul : ↑(lower_closure s) * t = lower_closure (s * t) := by { simp_rw mul_comm _ t, exact mul_lower_closure _ _ } @[simp, to_additive] lemma upper_closure_mul_distrib : upper_closure (s * t) = upper_closure s * upper_closure t := set_like.coe_injective $ by rw [upper_set.coe_mul, mul_upper_closure, upper_closure_mul, upper_set.upper_closure] @[simp, to_additive] lemma lower_closure_mul_distrib : lower_closure (s * t) = lower_closure s * lower_closure t := set_like.coe_injective $ by rw [lower_set.coe_mul, mul_lower_closure, lower_closure_mul, lower_set.lower_closure] end ordered_comm_group
1cbcaa9ed049f1eeb2f9db1cd32e47c99837cb7b
79cc757e5e5b09c7a522f717a6c490d321d36469
/src/mywork/sep_13_2021.lean
1ddf1be24c5b36523afaa575108ec5ea82f3c3de
[]
no_license
LukeMathe/cs2120f21
534c3b8868dcfdea98a9d22513180c8a062794c6
d51940b174569a8782e62ae027b108b5f099a9aa
refs/heads/main
1,693,418,664,935
1,634,585,653,000
1,634,585,653,000
403,762,076
0
0
null
1,630,963,485,000
1,630,963,485,000
null
UTF-8
Lean
false
false
284
lean
axioms (P Q : Prop) def if_P_is_true_then_so_is_Q : Prop := P → Q axiom p : P -- assume P is true -- assume we have a proof of P (p) axiom pq : P → Q -- assume that we have a proof pq of P implies Q --intro for assume premise show conclusion -- elimination rule for implies:
4612916313a150354338f0f79676249812a39119
a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7
/src/group_theory/perm/sign.lean
f52e0406e33f64c75cd07ff26cb31ce3141db0c0
[ "Apache-2.0" ]
permissive
kmill/mathlib
ea5a007b67ae4e9e18dd50d31d8aa60f650425ee
1a419a9fea7b959317eddd556e1bb9639f4dcc05
refs/heads/master
1,668,578,197,719
1,593,629,163,000
1,593,629,163,000
276,482,939
0
0
null
1,593,637,960,000
1,593,637,959,000
null
UTF-8
Lean
false
false
32,214
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import data.fintype.basic import algebra.big_operators universes u v open equiv function fintype finset open_locale big_operators variables {α : Type u} {β : Type v} namespace equiv.perm def subtype_perm (f : perm α) {p : α → Prop} (h : ∀ x, p x ↔ p (f x)) : perm {x // p x} := ⟨λ x, ⟨f x, (h _).1 x.2⟩, λ x, ⟨f⁻¹ x, (h (f⁻¹ x)).2 $ by simpa using x.2⟩, λ _, by simp, λ _, by simp⟩ @[simp] lemma subtype_perm_one (p : α → Prop) (h : ∀ x, p x ↔ p ((1 : perm α) x)) : @subtype_perm α 1 p h = 1 := equiv.ext $ λ ⟨_, _⟩, rfl def of_subtype {p : α → Prop} [decidable_pred p] : perm (subtype p) →* perm α := { to_fun := λ f, ⟨λ x, if h : p x then f ⟨x, h⟩ else x, λ x, if h : p x then f⁻¹ ⟨x, h⟩ else x, λ x, have h : ∀ h : p x, p (f ⟨x, h⟩), from λ h, (f ⟨x, h⟩).2, by simp; split_ifs at *; simp * at *, λ x, have h : ∀ h : p x, p (f⁻¹ ⟨x, h⟩), from λ h, (f⁻¹ ⟨x, h⟩).2, by simp; split_ifs at *; simp * at *⟩, map_one' := begin ext, dsimp, split_ifs; refl, end, map_mul' := λ f g, equiv.ext $ λ x, begin by_cases h : p x, { have h₁ : p (f (g ⟨x, h⟩)), from (f (g ⟨x, h⟩)).2, have h₂ : p (g ⟨x, h⟩), from (g ⟨x, h⟩).2, simp [h, h₁, h₂] }, { simp [h] } end } lemma eq_inv_iff_eq {f : perm α} {x y : α} : x = f⁻¹ y ↔ f x = y := by conv {to_lhs, rw [← injective.eq_iff f.injective, apply_inv_self]} lemma inv_eq_iff_eq {f : perm α} {x y : α} : f⁻¹ x = y ↔ x = f y := by rw [eq_comm, eq_inv_iff_eq, eq_comm] /-- Two permutations `f` and `g` are `disjoint` if their supports are disjoint, i.e., every element is fixed either by `f`, or by `g`. -/ def disjoint (f g : perm α) := ∀ x, f x = x ∨ g x = x @[symm] lemma disjoint.symm {f g : perm α} : disjoint f g → disjoint g f := by simp [disjoint, or.comm] lemma disjoint_comm {f g : perm α} : disjoint f g ↔ disjoint g f := ⟨disjoint.symm, disjoint.symm⟩ lemma disjoint_mul_comm {f g : perm α} (h : disjoint f g) : f * g = g * f := equiv.ext $ λ x, (h x).elim (λ hf, (h (g x)).elim (λ hg, by simp [mul_apply, hf, hg]) (λ hg, by simp [mul_apply, hf, g.injective hg])) (λ hg, (h (f x)).elim (λ hf, by simp [mul_apply, f.injective hf, hg]) (λ hf, by simp [mul_apply, hf, hg])) @[simp] lemma disjoint_one_left (f : perm α) : disjoint 1 f := λ _, or.inl rfl @[simp] lemma disjoint_one_right (f : perm α) : disjoint f 1 := λ _, or.inr rfl lemma disjoint_mul_left {f g h : perm α} (H1 : disjoint f h) (H2 : disjoint g h) : disjoint (f * g) h := λ x, by cases H1 x; cases H2 x; simp * lemma disjoint_mul_right {f g h : perm α} (H1 : disjoint f g) (H2 : disjoint f h) : disjoint f (g * h) := by rw disjoint_comm; exact disjoint_mul_left H1.symm H2.symm lemma disjoint_prod_right {f : perm α} (l : list (perm α)) (h : ∀ g ∈ l, disjoint f g) : disjoint f l.prod := begin induction l with g l ih, { exact disjoint_one_right _ }, { rw list.prod_cons; exact disjoint_mul_right (h _ (list.mem_cons_self _ _)) (ih (λ g hg, h g (list.mem_cons_of_mem _ hg))) } end lemma disjoint_prod_perm {l₁ l₂ : list (perm α)} (hl : l₁.pairwise disjoint) (hp : l₁ ~ l₂) : l₁.prod = l₂.prod := hp.prod_eq' $ hl.imp $ λ f g, disjoint_mul_comm lemma of_subtype_subtype_perm {f : perm α} {p : α → Prop} [decidable_pred p] (h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) : of_subtype (subtype_perm f h₁) = f := equiv.ext $ λ x, begin rw [of_subtype, subtype_perm], by_cases hx : p x, { simp [hx] }, { haveI := classical.prop_decidable, simp [hx, not_not.1 (mt (h₂ x) hx)] } end lemma of_subtype_apply_of_not_mem {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) {x : α} (hx : ¬ p x) : of_subtype f x = x := dif_neg hx lemma mem_iff_of_subtype_apply_mem {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) (x : α) : p x ↔ p ((of_subtype f : α → α) x) := if h : p x then by dsimp [of_subtype]; simpa [h] using (f ⟨x, h⟩).2 else by simp [h, of_subtype_apply_of_not_mem f h] @[simp] lemma subtype_perm_of_subtype {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) : subtype_perm (of_subtype f) (mem_iff_of_subtype_apply_mem f) = f := equiv.ext $ λ ⟨x, hx⟩, by dsimp [subtype_perm, of_subtype]; simp [show p x, from hx] lemma pow_apply_eq_self_of_apply_eq_self {f : perm α} {x : α} (hfx : f x = x) : ∀ n : ℕ, (f ^ n) x = x | 0 := rfl | (n+1) := by rw [pow_succ', mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self] lemma gpow_apply_eq_self_of_apply_eq_self {f : perm α} {x : α} (hfx : f x = x) : ∀ n : ℤ, (f ^ n) x = x | (n : ℕ) := pow_apply_eq_self_of_apply_eq_self hfx n | -[1+ n] := by rw [gpow_neg_succ_of_nat, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx] lemma pow_apply_eq_of_apply_apply_eq_self {f : perm α} {x : α} (hffx : f (f x) = x) : ∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x | 0 := or.inl rfl | (n+1) := (pow_apply_eq_of_apply_apply_eq_self n).elim (λ h, or.inr (by rw [pow_succ, mul_apply, h])) (λ h, or.inl (by rw [pow_succ, mul_apply, h, hffx])) lemma gpow_apply_eq_of_apply_apply_eq_self {f : perm α} {x : α} (hffx : f (f x) = x) : ∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x | (n : ℕ) := pow_apply_eq_of_apply_apply_eq_self hffx n | -[1+ n] := by rw [gpow_neg_succ_of_nat, inv_eq_iff_eq, ← injective.eq_iff f.injective, ← mul_apply, ← pow_succ, eq_comm, inv_eq_iff_eq, ← mul_apply, ← pow_succ', @eq_comm _ x, or.comm]; exact pow_apply_eq_of_apply_apply_eq_self hffx _ variable [decidable_eq α] def support [fintype α] (f : perm α) := univ.filter (λ x, f x ≠ x) @[simp] lemma mem_support [fintype α] {f : perm α} {x : α} : x ∈ f.support ↔ f x ≠ x := by simp [support] def is_swap (f : perm α) := ∃ x y, x ≠ y ∧ f = swap x y lemma swap_mul_eq_mul_swap (f : perm α) (x y : α) : swap x y * f = f * swap (f⁻¹ x) (f⁻¹ y) := equiv.ext $ λ z, begin simp [mul_apply, swap_apply_def], split_ifs; simp [*, eq_inv_iff_eq] at * <|> cc end lemma mul_swap_eq_swap_mul (f : perm α) (x y : α) : f * swap x y = swap (f x) (f y) * f := by rw [swap_mul_eq_mul_swap, inv_apply_self, inv_apply_self] /-- Multiplying a permutation with `swap i j` twice gives the original permutation. This specialization of `swap_mul_self` is useful when using cosets of permutations. -/ @[simp] lemma swap_mul_self_mul (i j : α) (σ : perm α) : equiv.swap i j * (equiv.swap i j * σ) = σ := by rw [←mul_assoc (swap i j) (swap i j) σ, equiv.swap_mul_self, one_mul] lemma swap_mul_eq_iff {i j : α} {σ : perm α} : swap i j * σ = σ ↔ i = j := ⟨(assume h, have swap_id : swap i j = 1 := mul_right_cancel (trans h (one_mul σ).symm), by {rw [←swap_apply_right i j, swap_id], refl}), (assume h, by erw [h, swap_self, one_mul])⟩ lemma is_swap_of_subtype {p : α → Prop} [decidable_pred p] {f : perm (subtype p)} (h : is_swap f) : is_swap (of_subtype f) := let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h in ⟨x, y, by simp at hxy; tauto, equiv.ext $ λ z, begin rw [hxy.2, of_subtype], simp [swap_apply_def], split_ifs; cc <|> simp * at * end⟩ lemma ne_and_ne_of_swap_mul_apply_ne_self {f : perm α} {x y : α} (hy : (swap x (f x) * f) y ≠ y) : f y ≠ y ∧ y ≠ x := begin simp only [swap_apply_def, mul_apply, injective.eq_iff f.injective] at *, by_cases h : f y = x, { split; intro; simp * at * }, { split_ifs at hy; cc } end lemma support_swap_mul_eq [fintype α] {f : perm α} {x : α} (hffx : f (f x) ≠ x) : (swap x (f x) * f).support = f.support.erase x := have hfx : f x ≠ x, from λ hfx, by simpa [hfx] using hffx, finset.ext $ λ y, ⟨λ hy, have hy' : (swap x (f x) * f) y ≠ y, from mem_support.1 hy, mem_erase.2 ⟨λ hyx, by simp [hyx, mul_apply, *] at *, mem_support.2 $ λ hfy, by simp only [mul_apply, swap_apply_def, hfy] at hy'; split_ifs at hy'; simp * at *⟩, λ hy, by simp only [mem_erase, mem_support, swap_apply_def, mul_apply] at *; intro; split_ifs at *; simp * at *⟩ lemma card_support_swap_mul [fintype α] {f : perm α} {x : α} (hx : f x ≠ x) : (swap x (f x) * f).support.card < f.support.card := finset.card_lt_card ⟨λ z hz, mem_support.2 (ne_and_ne_of_swap_mul_apply_ne_self (mem_support.1 hz)).1, λ h, absurd (h (mem_support.2 hx)) (mt mem_support.1 (by simp))⟩ def swap_factors_aux : Π (l : list α) (f : perm α), (∀ {x}, f x ≠ x → x ∈ l) → {l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g} | [] := λ f h, ⟨[], equiv.ext $ λ x, by rw [list.prod_nil]; exact eq.symm (not_not.1 (mt h (list.not_mem_nil _))), by simp⟩ | (x :: l) := λ f h, if hfx : x = f x then swap_factors_aux l f (λ y hy, list.mem_of_ne_of_mem (λ h : y = x, by simpa [h, hfx.symm] using hy) (h hy)) else let m := swap_factors_aux l (swap x (f x) * f) (λ y hy, have f y ≠ y ∧ y ≠ x, from ne_and_ne_of_swap_mul_apply_ne_self hy, list.mem_of_ne_of_mem this.2 (h this.1)) in ⟨swap x (f x) :: m.1, by rw [list.prod_cons, m.2.1, ← mul_assoc, mul_def (swap x (f x)), swap_swap, ← one_def, one_mul], λ g hg, ((list.mem_cons_iff _ _ _).1 hg).elim (λ h, ⟨x, f x, hfx, h⟩) (m.2.2 _)⟩ /-- `swap_factors` represents a permutation as a product of a list of transpositions. The representation is non unique and depends on the linear order structure. For types without linear order `trunc_swap_factors` can be used -/ def swap_factors [fintype α] [decidable_linear_order α] (f : perm α) : {l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g} := swap_factors_aux ((@univ α _).sort (≤)) f (λ _ _, (mem_sort _).2 (mem_univ _)) def trunc_swap_factors [fintype α] (f : perm α) : trunc {l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g} := quotient.rec_on_subsingleton (@univ α _).1 (λ l h, trunc.mk (swap_factors_aux l f h)) (show ∀ x, f x ≠ x → x ∈ (@univ α _).1, from λ _ _, mem_univ _) @[elab_as_eliminator] lemma swap_induction_on [fintype α] {P : perm α → Prop} (f : perm α) : P 1 → (∀ f x y, x ≠ y → P f → P (swap x y * f)) → P f := begin cases trunc.out (trunc_swap_factors f) with l hl, induction l with g l ih generalizing f, { simp [hl.1.symm] {contextual := tt} }, { assume h1 hmul_swap, rcases hl.2 g (by simp) with ⟨x, y, hxy⟩, rw [← hl.1, list.prod_cons, hxy.2], exact hmul_swap _ _ _ hxy.1 (ih _ ⟨rfl, λ v hv, hl.2 _ (list.mem_cons_of_mem _ hv)⟩ h1 hmul_swap) } end lemma swap_mul_swap_mul_swap {x y z : α} (hwz: x ≠ y) (hxz : x ≠ z) : swap y z * swap x y * swap y z = swap z x := equiv.ext $ λ n, by simp only [swap_apply_def, mul_apply]; split_ifs; cc lemma is_conj_swap {w x y z : α} (hwx : w ≠ x) (hyz : y ≠ z) : is_conj (swap w x) (swap y z) := have h : ∀ {y z : α}, y ≠ z → w ≠ z → (swap w y * swap x z) * swap w x * (swap w y * swap x z)⁻¹ = swap y z := λ y z hyz hwz, by rw [mul_inv_rev, swap_inv, swap_inv, mul_assoc (swap w y), mul_assoc (swap w y), ← mul_assoc _ (swap x z), swap_mul_swap_mul_swap hwx hwz, ← mul_assoc, swap_mul_swap_mul_swap hwz.symm hyz.symm], if hwz : w = z then have hwy : w ≠ y, by cc, ⟨swap w z * swap x y, by rw [swap_comm y z, h hyz.symm hwy]⟩ else ⟨swap w y * swap x z, h hyz hwz⟩ /-- set of all pairs (⟨a, b⟩ : Σ a : fin n, fin n) such that b < a -/ def fin_pairs_lt (n : ℕ) : finset (Σ a : fin n, fin n) := (univ : finset (fin n)).sigma (λ a, (range a.1).attach_fin (λ m hm, lt_trans (mem_range.1 hm) a.2)) lemma mem_fin_pairs_lt {n : ℕ} {a : Σ a : fin n, fin n} : a ∈ fin_pairs_lt n ↔ a.2 < a.1 := by simp [fin_pairs_lt, fin.lt_def] def sign_aux {n : ℕ} (a : perm (fin n)) : units ℤ := ∏ x in fin_pairs_lt n, if a x.1 ≤ a x.2 then -1 else 1 @[simp] lemma sign_aux_one (n : ℕ) : sign_aux (1 : perm (fin n)) = 1 := begin unfold sign_aux, conv { to_rhs, rw ← @finset.prod_const_one _ (units ℤ) (fin_pairs_lt n) }, exact finset.prod_congr rfl (λ a ha, if_neg (not_le_of_gt (mem_fin_pairs_lt.1 ha))) end def sign_bij_aux {n : ℕ} (f : perm (fin n)) (a : Σ a : fin n, fin n) : Σ a : fin n, fin n := if hxa : f a.2 < f a.1 then ⟨f a.1, f a.2⟩ else ⟨f a.2, f a.1⟩ lemma sign_bij_aux_inj {n : ℕ} {f : perm (fin n)} : ∀ a b : Σ a : fin n, fin n, a ∈ fin_pairs_lt n → b ∈ fin_pairs_lt n → sign_bij_aux f a = sign_bij_aux f b → a = b := λ ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ ha hb h, begin unfold sign_bij_aux at h, rw mem_fin_pairs_lt at *, have : ¬b₁ < b₂ := not_lt_of_ge (le_of_lt hb), split_ifs at h; simp [*, injective.eq_iff f.injective, sigma.mk.inj_eq] at * end lemma sign_bij_aux_surj {n : ℕ} {f : perm (fin n)} : ∀ a ∈ fin_pairs_lt n, ∃ b ∈ fin_pairs_lt n, a = sign_bij_aux f b := λ ⟨a₁, a₂⟩ ha, if hxa : f⁻¹ a₂ < f⁻¹ a₁ then ⟨⟨f⁻¹ a₁, f⁻¹ a₂⟩, mem_fin_pairs_lt.2 hxa, by dsimp [sign_bij_aux]; rw [apply_inv_self, apply_inv_self, dif_pos (mem_fin_pairs_lt.1 ha)]⟩ else ⟨⟨f⁻¹ a₂, f⁻¹ a₁⟩, mem_fin_pairs_lt.2 $ lt_of_le_of_ne (le_of_not_gt hxa) $ λ h, by simpa [mem_fin_pairs_lt, (f⁻¹).injective h, lt_irrefl] using ha, by dsimp [sign_bij_aux]; rw [apply_inv_self, apply_inv_self, dif_neg (not_lt_of_ge (le_of_lt (mem_fin_pairs_lt.1 ha)))]⟩ lemma sign_bij_aux_mem {n : ℕ} {f : perm (fin n)}: ∀ a : Σ a : fin n, fin n, a ∈ fin_pairs_lt n → sign_bij_aux f a ∈ fin_pairs_lt n := λ ⟨a₁, a₂⟩ ha, begin unfold sign_bij_aux, split_ifs with h, { exact mem_fin_pairs_lt.2 h }, { exact mem_fin_pairs_lt.2 (lt_of_le_of_ne (le_of_not_gt h) (λ h, ne_of_lt (mem_fin_pairs_lt.1 ha) (f.injective h.symm))) } end @[simp] lemma sign_aux_inv {n : ℕ} (f : perm (fin n)) : sign_aux f⁻¹ = sign_aux f := prod_bij (λ a ha, sign_bij_aux f⁻¹ a) sign_bij_aux_mem (λ ⟨a, b⟩ hab, if h : f⁻¹ b < f⁻¹ a then by rw [sign_bij_aux, dif_pos h, if_neg (not_le_of_gt h), apply_inv_self, apply_inv_self, if_neg (not_le_of_gt $ mem_fin_pairs_lt.1 hab)] else by rw [sign_bij_aux, if_pos (le_of_not_gt h), dif_neg h, apply_inv_self, apply_inv_self, if_pos (le_of_lt $ mem_fin_pairs_lt.1 hab)]) sign_bij_aux_inj sign_bij_aux_surj lemma sign_aux_mul {n : ℕ} (f g : perm (fin n)) : sign_aux (f * g) = sign_aux f * sign_aux g := begin rw ← sign_aux_inv g, unfold sign_aux, rw ← prod_mul_distrib, refine prod_bij (λ a ha, sign_bij_aux g a) sign_bij_aux_mem _ sign_bij_aux_inj sign_bij_aux_surj, rintros ⟨a, b⟩ hab, rw [sign_bij_aux, mul_apply, mul_apply], rw mem_fin_pairs_lt at hab, by_cases h : g b < g a, { rw dif_pos h, simp [not_le_of_gt hab]; congr }, { rw [dif_neg h, inv_apply_self, inv_apply_self, if_pos (le_of_lt hab)], by_cases h₁ : f (g b) ≤ f (g a), { have : f (g b) ≠ f (g a), { rw [ne.def, injective.eq_iff f.injective, injective.eq_iff g.injective]; exact ne_of_lt hab }, rw [if_pos h₁, if_neg (not_le_of_gt (lt_of_le_of_ne h₁ this))], refl }, { rw [if_neg h₁, if_pos (le_of_lt (lt_of_not_ge h₁))], refl } } end private lemma sign_aux_swap_zero_one {n : ℕ} (hn : 2 ≤ n) : sign_aux (swap (⟨0, lt_of_lt_of_le dec_trivial hn⟩ : fin n) ⟨1, lt_of_lt_of_le dec_trivial hn⟩) = -1 := let zero : fin n := ⟨0, lt_of_lt_of_le dec_trivial hn⟩ in let one : fin n := ⟨1, lt_of_lt_of_le dec_trivial hn⟩ in have hzo : zero < one := dec_trivial, show _ = ∏ x : Σ a : fin n, fin n in {(⟨one, zero⟩ : Σ a : fin n, fin n)}, if (equiv.swap zero one) x.1 ≤ swap zero one x.2 then (-1 : units ℤ) else 1, begin refine eq.symm (prod_subset (λ ⟨x₁, x₂⟩, by simp [mem_fin_pairs_lt, hzo] {contextual := tt}) (λ a ha₁ ha₂, _)), rcases a with ⟨⟨a₁, ha₁⟩, ⟨a₂, ha₂⟩⟩, replace ha₁ : a₂ < a₁ := mem_fin_pairs_lt.1 ha₁, simp only [swap_apply_def], have : ¬ 1 ≤ a₂ → a₂ = 0, from λ h, nat.le_zero_iff.1 (nat.le_of_lt_succ (lt_of_not_ge h)), have : a₁ ≤ 1 → a₁ = 0 ∨ a₁ = 1, from nat.cases_on a₁ (λ _, or.inl rfl) (λ a₁, nat.cases_on a₁ (λ _, or.inr rfl) (λ _ h, absurd h dec_trivial)), split_ifs; simp [*, lt_irrefl, -not_lt, not_le.symm, -not_le, le_refl, fin.lt_def, fin.le_def, nat.zero_le, zero, one, iff.intro fin.veq_of_eq fin.eq_of_veq, nat.le_zero_iff] at *, end lemma sign_aux_swap : ∀ {n : ℕ} {x y : fin n} (hxy : x ≠ y), sign_aux (swap x y) = -1 | 0 := dec_trivial | 1 := dec_trivial | (n+2) := λ x y hxy, have h2n : 2 ≤ n + 2 := dec_trivial, by rw [← is_conj_iff_eq, ← sign_aux_swap_zero_one h2n]; exact (monoid_hom.mk' sign_aux sign_aux_mul).map_is_conj (is_conj_swap hxy dec_trivial) def sign_aux2 : list α → perm α → units ℤ | [] f := 1 | (x::l) f := if x = f x then sign_aux2 l f else -sign_aux2 l (swap x (f x) * f) lemma sign_aux_eq_sign_aux2 {n : ℕ} : ∀ (l : list α) (f : perm α) (e : α ≃ fin n) (h : ∀ x, f x ≠ x → x ∈ l), sign_aux ((e.symm.trans f).trans e) = sign_aux2 l f | [] f e h := have f = 1, from equiv.ext $ λ y, not_not.1 (mt (h y) (list.not_mem_nil _)), by rw [this, one_def, equiv.trans_refl, equiv.symm_trans, ← one_def, sign_aux_one, sign_aux2] | (x::l) f e h := begin rw sign_aux2, by_cases hfx : x = f x, { rw if_pos hfx, exact sign_aux_eq_sign_aux2 l f _ (λ y (hy : f y ≠ y), list.mem_of_ne_of_mem (λ h : y = x, by simpa [h, hfx.symm] using hy) (h y hy) ) }, { have hy : ∀ y : α, (swap x (f x) * f) y ≠ y → y ∈ l, from λ y hy, have f y ≠ y ∧ y ≠ x, from ne_and_ne_of_swap_mul_apply_ne_self hy, list.mem_of_ne_of_mem this.2 (h _ this.1), have : (e.symm.trans (swap x (f x) * f)).trans e = (swap (e x) (e (f x))) * (e.symm.trans f).trans e, by ext; simp [← equiv.symm_trans_swap_trans, mul_def], have hefx : e x ≠ e (f x), from mt (injective.eq_iff e.injective).1 hfx, rw [if_neg hfx, ← sign_aux_eq_sign_aux2 _ _ e hy, this, sign_aux_mul, sign_aux_swap hefx], simp } end def sign_aux3 [fintype α] (f : perm α) {s : multiset α} : (∀ x, x ∈ s) → units ℤ := quotient.hrec_on s (λ l h, sign_aux2 l f) (trunc.induction_on (equiv_fin α) (λ e l₁ l₂ h, function.hfunext (show (∀ x, x ∈ l₁) = ∀ x, x ∈ l₂, by simp only [h.mem_iff]) (λ h₁ h₂ _, by rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, h₁ _), ← sign_aux_eq_sign_aux2 _ _ e (λ _ _, h₂ _)]))) lemma sign_aux3_mul_and_swap [fintype α] (f g : perm α) (s : multiset α) (hs : ∀ x, x ∈ s) : sign_aux3 (f * g) hs = sign_aux3 f hs * sign_aux3 g hs ∧ ∀ x y, x ≠ y → sign_aux3 (swap x y) hs = -1 := let ⟨l, hl⟩ := quotient.exists_rep s in let ⟨e, _⟩ := trunc.exists_rep (equiv_fin α) in begin clear _let_match _let_match, subst hl, show sign_aux2 l (f * g) = sign_aux2 l f * sign_aux2 l g ∧ ∀ x y, x ≠ y → sign_aux2 l (swap x y) = -1, have hfg : (e.symm.trans (f * g)).trans e = (e.symm.trans f).trans e * (e.symm.trans g).trans e, from equiv.ext (λ h, by simp [mul_apply]), split, { rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), ← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), ← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), hfg, sign_aux_mul] }, { assume x y hxy, have hexy : e x ≠ e y, from mt (injective.eq_iff e.injective).1 hxy, rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), equiv.symm_trans_swap_trans, sign_aux_swap hexy] } end /-- `sign` of a permutation returns the signature or parity of a permutation, `1` for even permutations, `-1` for odd permutations. It is the unique surjective group homomorphism from `perm α` to the group with two elements.-/ def sign [fintype α] : perm α →* units ℤ := monoid_hom.mk' (λ f, sign_aux3 f mem_univ) (λ f g, (sign_aux3_mul_and_swap f g _ mem_univ).1) section sign variable [fintype α] @[simp] lemma sign_mul (f g : perm α) : sign (f * g) = sign f * sign g := monoid_hom.map_mul sign f g @[simp] lemma sign_one : (sign (1 : perm α)) = 1 := monoid_hom.map_one sign @[simp] lemma sign_refl : sign (equiv.refl α) = 1 := monoid_hom.map_one sign @[simp] lemma sign_inv (f : perm α) : sign f⁻¹ = sign f := by rw [monoid_hom.map_inv sign f, int.units_inv_eq_self] lemma sign_swap {x y : α} (h : x ≠ y) : sign (swap x y) = -1 := (sign_aux3_mul_and_swap 1 1 _ mem_univ).2 x y h @[simp] lemma sign_swap' {x y : α} : (swap x y).sign = if x = y then 1 else -1 := if H : x = y then by simp [H, swap_self] else by simp [sign_swap H, H] lemma sign_eq_of_is_swap {f : perm α} (h : is_swap f) : sign f = -1 := let ⟨x, y, hxy⟩ := h in hxy.2.symm ▸ sign_swap hxy.1 lemma sign_aux3_symm_trans_trans [decidable_eq β] [fintype β] (f : perm α) (e : α ≃ β) {s : multiset α} {t : multiset β} (hs : ∀ x, x ∈ s) (ht : ∀ x, x ∈ t) : sign_aux3 ((e.symm.trans f).trans e) ht = sign_aux3 f hs := quotient.induction_on₂ t s (λ l₁ l₂ h₁ h₂, show sign_aux2 _ _ = sign_aux2 _ _, from let n := trunc.out (equiv_fin β) in by rw [← sign_aux_eq_sign_aux2 _ _ n (λ _ _, h₁ _), ← sign_aux_eq_sign_aux2 _ _ (e.trans n) (λ _ _, h₂ _)]; exact congr_arg sign_aux (equiv.ext (λ x, by simp))) ht hs lemma sign_symm_trans_trans [decidable_eq β] [fintype β] (f : perm α) (e : α ≃ β) : sign ((e.symm.trans f).trans e) = sign f := sign_aux3_symm_trans_trans f e mem_univ mem_univ lemma sign_prod_list_swap {l : list (perm α)} (hl : ∀ g ∈ l, is_swap g) : sign l.prod = (-1) ^ l.length := have h₁ : l.map sign = list.repeat (-1) l.length := list.eq_repeat.2 ⟨by simp, λ u hu, let ⟨g, hg⟩ := list.mem_map.1 hu in hg.2 ▸ sign_eq_of_is_swap (hl _ hg.1)⟩, by rw [← list.prod_repeat, ← h₁, list.prod_hom _ (@sign α _ _)] lemma sign_surjective (hα : 1 < fintype.card α) : function.surjective (sign : perm α → units ℤ) := λ a, (int.units_eq_one_or a).elim (λ h, ⟨1, by simp [h]⟩) (λ h, let ⟨x⟩ := fintype.card_pos_iff.1 (lt_trans zero_lt_one hα) in let ⟨y, hxy⟩ := fintype.exists_ne_of_one_lt_card hα x in ⟨swap y x, by rw [sign_swap hxy, h]⟩ ) lemma eq_sign_of_surjective_hom {s : perm α →* units ℤ} (hs : surjective s) : s = sign := have ∀ {f}, is_swap f → s f = -1 := λ f ⟨x, y, hxy, hxy'⟩, hxy'.symm ▸ by_contradiction (λ h, have ∀ f, is_swap f → s f = 1 := λ f ⟨a, b, hab, hab'⟩, by rw [← is_conj_iff_eq, ← or.resolve_right (int.units_eq_one_or _) h, hab']; exact (monoid_hom.of s).map_is_conj (is_conj_swap hab hxy), let ⟨g, hg⟩ := hs (-1) in let ⟨l, hl⟩ := trunc.out (trunc_swap_factors g) in have ∀ a ∈ l.map s, a = (1 : units ℤ) := λ a ha, let ⟨g, hg⟩ := list.mem_map.1 ha in hg.2 ▸ this _ (hl.2 _ hg.1), have s l.prod = 1, by rw [← l.prod_hom s, list.eq_repeat'.2 this, list.prod_repeat, one_pow], by rw [hl.1, hg] at this; exact absurd this dec_trivial), monoid_hom.ext $ λ f, let ⟨l, hl₁, hl₂⟩ := trunc.out (trunc_swap_factors f) in have hsl : ∀ a ∈ l.map s, a = (-1 : units ℤ) := λ a ha, let ⟨g, hg⟩ := list.mem_map.1 ha in hg.2 ▸ this (hl₂ _ hg.1), by rw [← hl₁, ← l.prod_hom s, list.eq_repeat'.2 hsl, list.length_map, list.prod_repeat, sign_prod_list_swap hl₂] lemma sign_subtype_perm (f : perm α) {p : α → Prop} [decidable_pred p] (h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) : sign (subtype_perm f h₁) = sign f := let l := trunc.out (trunc_swap_factors (subtype_perm f h₁)) in have hl' : ∀ g' ∈ l.1.map of_subtype, is_swap g' := λ g' hg', let ⟨g, hg⟩ := list.mem_map.1 hg' in hg.2 ▸ is_swap_of_subtype (l.2.2 _ hg.1), have hl'₂ : (l.1.map of_subtype).prod = f, by rw [l.1.prod_hom of_subtype, l.2.1, of_subtype_subtype_perm _ h₂], by conv {congr, rw ← l.2.1, skip, rw ← hl'₂}; rw [sign_prod_list_swap l.2.2, sign_prod_list_swap hl', list.length_map] @[simp] lemma sign_of_subtype {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) : sign (of_subtype f) = sign f := have ∀ x, of_subtype f x ≠ x → p x, from λ x, not_imp_comm.1 (of_subtype_apply_of_not_mem f), by conv {to_rhs, rw [← subtype_perm_of_subtype f, sign_subtype_perm _ _ this]} lemma sign_eq_sign_of_equiv [decidable_eq β] [fintype β] (f : perm α) (g : perm β) (e : α ≃ β) (h : ∀ x, e (f x) = g (e x)) : sign f = sign g := have hg : g = (e.symm.trans f).trans e, from equiv.ext $ by simp [h], by rw [hg, sign_symm_trans_trans] lemma sign_bij [decidable_eq β] [fintype β] {f : perm α} {g : perm β} (i : Π x : α, f x ≠ x → β) (h : ∀ x hx hx', i (f x) hx' = g (i x hx)) (hi : ∀ x₁ x₂ hx₁ hx₂, i x₁ hx₁ = i x₂ hx₂ → x₁ = x₂) (hg : ∀ y, g y ≠ y → ∃ x hx, i x hx = y) : sign f = sign g := calc sign f = sign (@subtype_perm _ f (λ x, f x ≠ x) (by simp)) : eq.symm (sign_subtype_perm _ _ (λ _, id)) ... = sign (@subtype_perm _ g (λ x, g x ≠ x) (by simp)) : sign_eq_sign_of_equiv _ _ (equiv.of_bijective (λ x : {x // f x ≠ x}, (⟨i x.1 x.2, have f (f x) ≠ f x, from mt (λ h, f.injective h) x.2, by rw [← h _ x.2 this]; exact mt (hi _ _ this x.2) x.2⟩ : {y // g y ≠ y})) ⟨λ ⟨x, hx⟩ ⟨y, hy⟩ h, subtype.eq (hi _ _ _ _ (subtype.mk.inj h)), λ ⟨y, hy⟩, let ⟨x, hfx, hx⟩ := hg y hy in ⟨⟨x, hfx⟩, subtype.eq hx⟩⟩) (λ ⟨x, _⟩, subtype.eq (h x _ _)) ... = sign g : sign_subtype_perm _ _ (λ _, id) def is_cycle (f : perm β) := ∃ x, f x ≠ x ∧ ∀ y, f y ≠ y → ∃ i : ℤ, (f ^ i) x = y lemma is_cycle_swap {x y : α} (hxy : x ≠ y) : is_cycle (swap x y) := ⟨y, by rwa swap_apply_right, λ a (ha : ite (a = x) y (ite (a = y) x a) ≠ a), if hya : y = a then ⟨0, hya⟩ else ⟨1, by rw [gpow_one, swap_apply_def]; split_ifs at *; cc⟩⟩ lemma is_cycle_inv {f : perm β} (hf : is_cycle f) : is_cycle (f⁻¹) := let ⟨x, hx⟩ := hf in ⟨x, by simp [eq_inv_iff_eq, inv_eq_iff_eq, *] at *; cc, λ y hy, let ⟨i, hi⟩ := hx.2 y (by simp [eq_inv_iff_eq, inv_eq_iff_eq, *] at *; cc) in ⟨-i, by rwa [gpow_neg, inv_gpow, inv_inv]⟩⟩ lemma exists_gpow_eq_of_is_cycle {f : perm β} (hf : is_cycle f) {x y : β} (hx : f x ≠ x) (hy : f y ≠ y) : ∃ i : ℤ, (f ^ i) x = y := let ⟨g, hg⟩ := hf in let ⟨a, ha⟩ := hg.2 x hx in let ⟨b, hb⟩ := hg.2 y hy in ⟨b - a, by rw [← ha, ← mul_apply, ← gpow_add, sub_add_cancel, hb]⟩ lemma is_cycle_swap_mul_aux₁ : ∀ (n : ℕ) {b x : α} {f : perm α} (hb : (swap x (f x) * f) b ≠ b) (h : (f ^ n) (f x) = b), ∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b | 0 := λ b x f hb h, ⟨0, h⟩ | (n+1 : ℕ) := λ b x f hb h, if hfbx : f x = b then ⟨0, hfbx⟩ else have f b ≠ b ∧ b ≠ x, from ne_and_ne_of_swap_mul_apply_ne_self hb, have hb' : (swap x (f x) * f) (f⁻¹ b) ≠ f⁻¹ b, by rw [mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (ne.symm hfbx), ne.def, ← injective.eq_iff f.injective, apply_inv_self]; exact this.1, let ⟨i, hi⟩ := is_cycle_swap_mul_aux₁ n hb' (f.injective $ by rw [apply_inv_self]; rwa [pow_succ, mul_apply] at h) in ⟨i + 1, by rw [add_comm, gpow_add, mul_apply, hi, gpow_one, mul_apply, apply_inv_self, swap_apply_of_ne_of_ne (ne_and_ne_of_swap_mul_apply_ne_self hb).2 (ne.symm hfbx)]⟩ lemma is_cycle_swap_mul_aux₂ : ∀ (n : ℤ) {b x : α} {f : perm α} (hb : (swap x (f x) * f) b ≠ b) (h : (f ^ n) (f x) = b), ∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b | (n : ℕ) := λ b x f, is_cycle_swap_mul_aux₁ n | -[1+ n] := λ b x f hb h, if hfbx : f⁻¹ x = b then ⟨-1, by rwa [gpow_neg, gpow_one, mul_inv_rev, mul_apply, swap_inv, swap_apply_right]⟩ else if hfbx' : f x = b then ⟨0, hfbx'⟩ else have f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb, have hb : (swap x (f⁻¹ x) * f⁻¹) (f⁻¹ b) ≠ f⁻¹ b, by rw [mul_apply, swap_apply_def]; split_ifs; simp [inv_eq_iff_eq, eq_inv_iff_eq] at *; cc, let ⟨i, hi⟩ := is_cycle_swap_mul_aux₁ n hb (show (f⁻¹ ^ n) (f⁻¹ x) = f⁻¹ b, by rw [← gpow_coe_nat, ← h, ← mul_apply, ← mul_apply, ← mul_apply, gpow_neg_succ_of_nat, ← inv_pow, pow_succ', mul_assoc, mul_assoc, inv_mul_self, mul_one, gpow_coe_nat, ← pow_succ', ← pow_succ]) in have h : (swap x (f⁻¹ x) * f⁻¹) (f x) = f⁻¹ x, by rw [mul_apply, inv_apply_self, swap_apply_left], ⟨-i, by rw [← add_sub_cancel i 1, neg_sub, sub_eq_add_neg, gpow_add, gpow_one, gpow_neg, ← inv_gpow, mul_inv_rev, swap_inv, mul_swap_eq_swap_mul, inv_apply_self, swap_comm _ x, gpow_add, gpow_one, mul_apply, mul_apply (_ ^ i), h, hi, mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (ne.symm hfbx')]⟩ lemma eq_swap_of_is_cycle_of_apply_apply_eq_self {f : perm α} (hf : is_cycle f) {x : α} (hfx : f x ≠ x) (hffx : f (f x) = x) : f = swap x (f x) := equiv.ext $ λ y, let ⟨z, hz⟩ := hf in let ⟨i, hi⟩ := hz.2 x hfx in if hyx : y = x then by simp [hyx] else if hfyx : y = f x then by simp [hfyx, hffx] else begin rw [swap_apply_of_ne_of_ne hyx hfyx], refine by_contradiction (λ hy, _), cases hz.2 y hy with j hj, rw [← sub_add_cancel j i, gpow_add, mul_apply, hi] at hj, cases gpow_apply_eq_of_apply_apply_eq_self hffx (j - i) with hji hji, { rw [← hj, hji] at hyx, cc }, { rw [← hj, hji] at hfyx, cc } end lemma is_cycle_swap_mul {f : perm α} (hf : is_cycle f) {x : α} (hx : f x ≠ x) (hffx : f (f x) ≠ x) : is_cycle (swap x (f x) * f) := ⟨f x, by simp only [swap_apply_def, mul_apply]; split_ifs; simp [injective.eq_iff f.injective] at *; cc, λ y hy, let ⟨i, hi⟩ := exists_gpow_eq_of_is_cycle hf hx (ne_and_ne_of_swap_mul_apply_ne_self hy).1 in have hi : (f ^ (i - 1)) (f x) = y, from calc (f ^ (i - 1)) (f x) = (f ^ (i - 1) * f ^ (1 : ℤ)) x : by rw [gpow_one, mul_apply] ... = y : by rwa [← gpow_add, sub_add_cancel], is_cycle_swap_mul_aux₂ (i - 1) hy hi⟩ @[simp] lemma support_swap [fintype α] {x y : α} (hxy : x ≠ y) : (swap x y).support = {x, y} := finset.ext $ λ a, by simp [swap_apply_def]; split_ifs; cc lemma card_support_swap [fintype α] {x y : α} (hxy : x ≠ y) : (swap x y).support.card = 2 := show (swap x y).support.card = finset.card ⟨x::y::0, by simp [hxy]⟩, from congr_arg card $ by rw [support_swap hxy]; simp [*, finset.ext_iff]; cc lemma sign_cycle [fintype α] : ∀ {f : perm α} (hf : is_cycle f), sign f = -(-1) ^ f.support.card | f := λ hf, let ⟨x, hx⟩ := hf in calc sign f = sign (swap x (f x) * (swap x (f x) * f)) : by rw [← mul_assoc, mul_def, mul_def, swap_swap, trans_refl] ... = -(-1) ^ f.support.card : if h1 : f (f x) = x then have h : swap x (f x) * f = 1, begin rw eq_swap_of_is_cycle_of_apply_apply_eq_self hf hx.1 h1, simp [mul_def, one_def] end, by rw [sign_mul, sign_swap hx.1.symm, h, sign_one, eq_swap_of_is_cycle_of_apply_apply_eq_self hf hx.1 h1, card_support_swap hx.1.symm]; refl else have h : card (support (swap x (f x) * f)) + 1 = card (support f), by rw [← insert_erase (mem_support.2 hx.1), support_swap_mul_eq h1, card_insert_of_not_mem (not_mem_erase _ _)], have wf : card (support (swap x (f x) * f)) < card (support f), from card_support_swap_mul hx.1, by rw [sign_mul, sign_swap hx.1.symm, sign_cycle (is_cycle_swap_mul hf hx.1 h1), ← h]; simp [pow_add] using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ f, f.support.card)⟩]} end sign end equiv.perm
830ec6d8fa8eb24875646c19785baea882effa1e
3618c6e11aa822fd542440674dfb9a7b9921dba0
/src/tactic/group1r.lean
98a1362f3a41928bcd31f1b450b2385957390a6d
[]
no_license
ChrisHughes24/single_relation
99ceedcc02d236ce46d6c65d72caa669857533c5
057e157a59de6d0e43b50fcb537d66792ec20450
refs/heads/master
1,683,652,062,698
1,683,360,089,000
1,683,360,089,000
279,346,432
0
0
null
null
null
null
UTF-8
Lean
false
false
8,814
lean
import solve tactic.group open expr tactic free_group local notation `C∞` := multiplicative ℤ meta structure cache := (G : expr) (univ : level) (red : transparency) (ic : ref instance_cache) -- instance_cache for G (atoms : ref (buffer expr)) @[derive [monad, alternative]] meta def group1r_m (α : Type) : Type := reader_t cache tactic α namespace group1r meta def get_cache : group1r_m cache := reader_t.read /-- Run a `group1r_m` tactic in the tactic monad. -/ meta def group1r_m.run (red : transparency) (G : expr) {α} (m : group1r_m α) : tactic α := do u ← mk_meta_univ, infer_type G >>= unify (expr.sort (level.succ u)), u ← get_univ_assignment u, ic ← mk_instance_cache G, zc ← mk_instance_cache `(ℤ), using_new_ref ic $ λ ric, using_new_ref mk_buffer $ λ atoms, reader_t.run m ⟨G, u, red, ric, atoms⟩ namespace group1r_m meta def lift {α : Type} : tactic α → group1r_m α := reader_t.lift /-- Lift an instance cache tactic (probably from `norm_num`) to the `ring_m` monad. This version is abstract over the instance cache in question (either the ring `α`, or `ℕ` for exponents). -/ @[inline] meta def ic_lift' (icf : cache → ref instance_cache) {α} (f : instance_cache → tactic (instance_cache × α)) : group1r_m α := ⟨λ c, do let r := icf c, ic ← read_ref r, (ic', a) ← f ic, a <$ write_ref r ic'⟩ /-- Lift an instance cache tactic (probably from `norm_num`) to the `group1r_m` monad. This uses the instance cache corresponding to the ring `α`. -/ @[inline] meta def ic_lift {α} : (instance_cache → tactic (instance_cache × α)) → group1r_m α := ic_lift' cache.ic meta def add_atom (e : expr) : group1r_m ℕ := ⟨λ l, do es ← read_ref l.atoms, es.iterate failed (λ n e' t, t <|> (is_def_eq e e' l.red $> n.1)) <|> (es.size <$ write_ref l.atoms (es.push_back e))⟩ /-- Get an already encountered atom by its index. -/ meta def get_atom (n : ℕ) : group1r_m expr := ⟨λ c, do es ← read_ref c.atoms, pure (es.read' n)⟩ meta def to_free_group : expr → group1r_m (free_group ℕ) | `(%%a * %%b) := do a' ← to_free_group a, b' ← to_free_group b, return (a' * b') | `((%%a)⁻¹) := do a' ← to_free_group a, return (a'⁻¹) | `(@has_one.one _ _) := return 1 | e@`((%%a) ^ (-%%n)) := cond (is_numeral n) (do ne ← lift (eval_expr' ℤ n), a' ← to_free_group a, return (a' ^ -ne)) (do i ← add_atom e, return (of i)) | e@`((%%a) ^ (%%n)) := cond (is_numeral n) ((do ne ← lift (eval_expr' ℕ n), a' ← to_free_group a, return (a' ^ ne)) <|> (do ne ← lift (eval_expr' ℤ n), a' ← to_free_group a, return (a' ^ ne))) (do i ← add_atom e, return (of i)) | e := do i ← add_atom e, return (of i) -- meta def to_group_equality : expr → group1r_m (expr × free_group ℕ × free_group ℕ) -- | `(@eq %%G %%a %%b) := -- do a' ← to_free_group a, -- b' ← to_free_group b, -- return (G, a', b') -- | _ := failure -- meta def X : has_reflect int := reflect n -- #print int.has_reflect -- set_option pp.numerals false -- run_cmd tactic.trace (X (-12)) protected meta def expr.of_nat (n : ℕ) : expr := if n = 0 then `(0 : ℤ) else let one := `(1 : ℤ) in n.binary_rec one $ λ b n e, if n = 0 then one else cond b `((bit1 %%e : ℤ)) `((bit0 %%e : ℤ)) protected meta def expr.of_int : ℤ → expr | (n : ℕ) := expr.of_nat n | -[1+ n] := `(has_neg.neg %%(expr.of_nat (n + 1)) : ℤ) meta def free_group_to_expr_aux : list (Σ i : ℕ, C∞) → group1r_m expr | [] := ic_lift $ λ ic, ic.mk_app ``has_one.one [] | (⟨a, n⟩ :: l) := do w ← free_group_to_expr_aux l, ae ← get_atom a, lift $ do p ← tactic.mk_app `has_pow.pow [ae, expr.of_int n.to_add], tactic.mk_app `has_mul.mul [p, w] meta def free_group_to_expr : free_group ℕ → group1r_m expr := free_group_to_expr_aux ∘ subtype.val meta def free_group_free_group_to_expr_aux : list (Σ i : free_group ℕ, C∞) → group1r_m expr | [] := do c ← get_cache, return (app (const `list.nil [level.max c.univ level.zero]) (app (app (const `prod [c.univ, level.zero]) c.G) `(ℤ))) | (⟨w, n⟩ :: l) := do w' ← free_group_to_expr w, l' ← free_group_free_group_to_expr_aux l, c ← get_cache, lift $ do w'n ← tactic.mk_app `prod.mk [w', expr.of_int n.to_add], tactic.mk_app `list.cons [w'n, l'] def eval_conj {G : Type*} [group G] (r : G) : list (G × ℤ) → G | [] := 1 | (a::l) := a.1 * (r ^ a.2 * (a.1⁻¹ * eval_conj l)) lemma eval_conj_eq_one {G : Type*} [group G] (r : G) (hr : r = 1) : ∀ (l : list (G × ℤ)), eval_conj r l = 1 | [] := rfl | (⟨g, n⟩::l) := by rw [eval_conj, eval_conj_eq_one, hr]; simp [*, eval_conj] lemma mul_inv_eq_one_of_eq {G : Type*} [group G] (a b : G) (h : a = b) : a * b⁻¹ = 1 := by simp [h] meta def free_group_free_group_to_expr (p : free_group (free_group ℕ)) (r : expr) (r_eq_one : expr) : group1r_m expr := free_group_free_group_to_expr_aux p.to_list /- What do I have left? -/ end group1r_m open group1r.group1r_m group1r meta def mk_list (hyp : expr) (hyp_type : expr) (tgt : expr) (red : transparency) : -- first expr is an expr of type `list (G × ℤ)` -- second expr is a proof of r = 1 tactic (expr × expr) := do (hyp_left, hyp_right) ← is_eq hyp_type, (tgt_left, tgt_right) ← is_eq tgt, G ← infer_type hyp_left, group1r_m.run red G $ do hyp_lhs ← to_free_group hyp_left, hyp_rhs ← to_free_group hyp_right, tgt_lhs ← to_free_group tgt_left, tgt_rhs ← to_free_group tgt_right, r ← ic_lift (λ ic, do (ic, right_inv) ← ic.mk_app `has_inv.inv [hyp_right], ic.mk_app `has_mul.mul [hyp_left, right_inv]), r_eq_one ← ic_lift (λ ic, ic.mk_app `group1r.group1r_m.mul_inv_eq_one_of_eq [hyp_left, hyp_right, hyp]), p ← group1r_m.lift (_root_.golf_solve (hyp_lhs * hyp_rhs⁻¹) ∅ (tgt_lhs * tgt_rhs⁻¹)), group1r_m.lift $ tactic.trace (repr (list.map (λ x : Σ i : free_group ℕ, C∞, x.snd.nat_abs) p.left.1).sum), l ← free_group_free_group_to_expr p.left r r_eq_one, return (l, r_eq_one) lemma helper {G : Type*} [group G] {r : G} (hr : r = 1) {a b : G} (l : list (G × ℤ)) : a = eval_conj r l * b → a = b := by { rw [eval_conj_eq_one r hr, one_mul], exact id } end group1r namespace tactic.interactive open lean.parser lean interactive.types interactive group1r tactic.simp_arg_type local postfix `?`:9001 := optional meta def group1r (red : parse (lean.parser.tk "!")?) (hyp : parse (tk "using" *> texpr)) : tactic unit := do hyp ← (hyp : option pexpr) >>= i_to_expr, let transp := if red.is_some then semireducible else reducible, hyp_type ← infer_type hyp, tgt ← target, (l, r_eq_one) ← mk_list hyp hyp_type tgt transp, `[refine group1r.helper %%r_eq_one %%l _, simp only [group1r.group1r_m.eval_conj, gpow_bit0, gpow_bit1, one_mul, mul_one, mul_inv_rev, mul_assoc, gpow_neg, mul_inv_self, inv_mul_self, one_inv, mul_inv_cancel_left, inv_mul_cancel_left, gpow_one, gpow_zero, pow_bit0, pow_bit1, pow_one, inv_inv]] end tactic.interactive set_option pp.implicit true set_option profiler true -- example {G : Type*} [group G] {a b c : G} -- (h : (a * b) * (b^2 * a * c) * (a * b)⁻¹ = (b^2 * a * c)^2) : -- (a * b)^5 * (b^2 * a * c) * (a * b)^(-5 : int) * (b^2 * a * c) = -- (b^2 * a * c) * (a * b)^5 * (b^2 * a * c) * (a * b)^(-5 : int) := -- begin -- group1r using h, -- end set_option profiler true -- example {G : Type*} [group G] (a b : G) -- (h : a * b * a^(-11 : int) * b^ 4 = 1) : -- a^10 * b^(-4 : int) * a^11 * b⁻¹ * a * b * a^(-11 : int) * b^5 * a^(-11 : int) -- * b * a^(11 : int) * b⁻¹ * a⁻¹ * b⁻¹ * a^(-10 : int) = 1 := -- begin -- group1r using h, -- end example {G : Type} [group G] (a b c d : G) (h : a * b * c * a * b^2 = 1) (h2 : a * b * d * a * b * c^(-2 : int) = 1) : a * b * d * a * b = (b⁻¹ * a⁻¹ * b^(-2 : int) * a⁻¹)^(2 : int) := have d = b⁻¹ * a⁻¹ * (a * b * c^(-2 : int))⁻¹, by group1r using h2, begin subst this, group1r using h, end example {G : Type*} [group G] {a b c : G} (m : nat) (h : a * b * a⁻¹ = b^2) (n : nat) : a ^ n * b = b ^ (2^n) * a^n := begin induction n with n ih, { norm_num }, { simp only [pow_succ, mul_comm 2], simp only [pow_mul], } end def W {G : Type*} [group G] (a b : G): ℕ → G | 0 := a | (n+1) := (b⁻¹ * W n * b)⁻¹ * a * (b⁻¹ * W n * b) example {G : Type*} [group G] (a b : G) (h : (b⁻¹ * a * b)⁻¹ * a * (b⁻¹ * a * b) = a ^ 2) : W a b 2 = a ^ 4 := begin dunfold W, simp [mul_assoc, gpow_bit0, gpow_bit1], group1r using h, end
59adc6fef4d3714f5a193a2d16ab4c15a570a841
75bd9c50a345718d735a7533c007cf45f9da9a83
/src/ring_theory/algebra_tower.lean
9ba0e28ffc9adcc088e58a6d33403aec3ee49c6b
[ "Apache-2.0" ]
permissive
jtbarker/mathlib
a1a3b1ddc16179826260578410746756ef18032c
392d3e376b44265ef2dedbd92231d3177acc1fd0
refs/heads/master
1,671,246,411,096
1,600,801,712,000
1,600,801,712,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
14,601
lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import ring_theory.adjoin /-! # Towers of algebras We set up the basic theory of algebra towers. An algebra tower A/S/R is expressed by having instances of `algebra A S`, `algebra R S`, `algebra R A` and `is_scalar_tower R S A`, the later asserting the compatibility condition `(r • s) • a = r • (s • a)`. In `field_theory/tower.lean` we use this to prove the tower law for finite extensions, that if `R` and `S` are both fields, then `[A:R] = [A:S] [S:A]`. In this file we prepare the main lemma: if `{bi | i ∈ I}` is an `R`-basis of `S` and `{cj | j ∈ J}` is a `S`-basis of `A`, then `{bi cj | i ∈ I, j ∈ J}` is an `R`-basis of `A`. This statement does not require the base rings to be a field, so we also generalize the lemma to rings in this file. -/ universes u v w u₁ variables (R : Type u) (S : Type v) (A : Type w) (B : Type u₁) namespace is_scalar_tower section semimodule variables [comm_semiring R] [semiring S] [add_comm_monoid A] [add_comm_monoid B] variables [algebra R S] [semimodule S A] [semimodule R A] [semimodule S B] [semimodule R B] variables [is_scalar_tower R S A] [is_scalar_tower R S B] variables {R} (S) {A} theorem algebra_map_smul (r : R) (x : A) : algebra_map R S r • x = r • x := by rw [algebra.algebra_map_eq_smul_one, smul_assoc, one_smul] variables {R S A} theorem smul_left_comm (r : R) (s : S) (x : A) : r • s • x = s • r • x := by rw [← smul_assoc, algebra.smul_def r s, algebra.commutes, mul_smul, algebra_map_smul] end semimodule section semiring variables [comm_semiring R] [comm_semiring S] [semiring A] [semiring B] variables [algebra R S] [algebra S A] [algebra R A] [algebra S B] [algebra R B] variables {R S A} theorem of_algebra_map_eq (h : ∀ x, algebra_map R A x = algebra_map S A (algebra_map R S x)) : is_scalar_tower R S A := ⟨λ x y z, by simp_rw [algebra.smul_def, ring_hom.map_mul, mul_assoc, h]⟩ variables [is_scalar_tower R S A] [is_scalar_tower R S B] variables (R S A) theorem algebra_map_eq : algebra_map R A = (algebra_map S A).comp (algebra_map R S) := ring_hom.ext $ λ x, by simp_rw [ring_hom.comp_apply, algebra.algebra_map_eq_smul_one, smul_assoc, one_smul] theorem algebra_map_apply (x : R) : algebra_map R A x = algebra_map S A (algebra_map R S x) := by rw [algebra_map_eq R S A, ring_hom.comp_apply] @[ext] lemma algebra.ext {S : Type u} {A : Type v} [comm_semiring S] [semiring A] (h1 h2 : algebra S A) (h : ∀ {r : S} {x : A}, (by haveI := h1; exact r • x) = r • x) : h1 = h2 := begin unfreezingI { cases h1 with f1 g1 h11 h12, cases h2 with f2 g2 h21 h22, cases f1, cases f2, congr', { ext r x, exact h }, ext r, erw [← mul_one (g1 r), ← h12, ← mul_one (g2 r), ← h22, h], refl } end variables (R S A) theorem algebra_comap_eq : algebra.comap.algebra R S A = ‹_› := algebra.ext _ _ $ λ x (z : A), calc algebra_map R S x • z = (x • 1 : S) • z : by rw algebra.algebra_map_eq_smul_one ... = x • (1 : S) • z : by rw smul_assoc ... = (by exact x • z : A) : by rw one_smul /-- In a tower, the canonical map from the middle element to the top element is an algebra homomorphism over the bottom element. -/ def to_alg_hom : S →ₐ[R] A := { commutes' := λ _, (algebra_map_apply _ _ _ _).symm, .. algebra_map S A } @[simp] lemma to_alg_hom_apply (y : S) : to_alg_hom R S A y = algebra_map S A y := rfl variables (R) {S A B} /-- R ⟶ S induces S-Alg ⥤ R-Alg -/ def restrict_base (f : A →ₐ[S] B) : A →ₐ[R] B := { commutes' := λ r, by { rw [algebra_map_apply R S A, algebra_map_apply R S B], exact f.commutes (algebra_map R S r) }, .. (f : A →+* B) } @[simp] lemma restrict_base_apply (f : A →ₐ[S] B) (x : A) : restrict_base R f x = f x := rfl instance right : is_scalar_tower R S S := of_algebra_map_eq $ λ x, rfl instance nat : is_scalar_tower ℕ S A := of_algebra_map_eq $ λ x, ((algebra_map S A).map_nat_cast x).symm instance comap {R S A : Type*} [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] : is_scalar_tower R S (algebra.comap R S A) := of_algebra_map_eq $ λ x, rfl instance subsemiring (U : subsemiring S) : is_scalar_tower U S A := of_algebra_map_eq $ λ x, rfl instance subring {S A : Type*} [comm_ring S] [ring A] [algebra S A] (U : set S) [is_subring U] : is_scalar_tower U S A := of_algebra_map_eq $ λ x, rfl @[nolint instance_priority] instance of_ring_hom {R A B : Type*} [comm_semiring R] [comm_semiring A] [comm_semiring B] [algebra R A] [algebra R B] (f : A →ₐ[R] B) : @is_scalar_tower R A B _ (f.to_ring_hom.to_algebra.to_has_scalar) _ := by { letI := (f : A →+* B).to_algebra, exact of_algebra_map_eq (λ x, (f.commutes x).symm) } end semiring section comm_semiring variables [comm_semiring R] [comm_semiring A] [algebra R A] variables [comm_semiring B] [algebra A B] [algebra R B] [is_scalar_tower R A B] instance subalgebra (S : subalgebra R A) : is_scalar_tower R S A := of_algebra_map_eq $ λ x, rfl instance polynomial : is_scalar_tower R A (polynomial B) := of_algebra_map_eq $ λ x, congr_arg polynomial.C $ algebra_map_apply R A B x theorem aeval_apply (x : B) (p : polynomial R) : polynomial.aeval x p = polynomial.aeval x (polynomial.map (algebra_map R A) p) := by rw [polynomial.aeval_def, polynomial.aeval_def, polynomial.eval₂_map, algebra_map_eq R A B] instance linear_map (R : Type u) (A : Type v) (V : Type w) [comm_semiring R] [comm_semiring A] [add_comm_monoid V] [semimodule R V] [algebra R A] : is_scalar_tower R A (V →ₗ[R] A) := ⟨λ x y f, linear_map.ext $ λ v, algebra.smul_mul_assoc x y (f v)⟩ end comm_semiring section comm_ring variables [comm_ring R] [comm_ring S] [comm_ring A] [algebra R S] [algebra S A] [algebra R A] variables [is_scalar_tower R S A] instance int : is_scalar_tower ℤ S A := of_algebra_map_eq $ λ x, ((algebra_map S A).map_int_cast x).symm end comm_ring section division_ring variables [field R] [division_ring S] [algebra R S] [char_zero R] [char_zero S] instance rat : is_scalar_tower ℚ R S := of_algebra_map_eq $ λ x, ((algebra_map R S).map_rat_cast x).symm end division_ring end is_scalar_tower namespace algebra theorem adjoin_algebra_map' {R : Type u} {S : Type v} {A : Type w} [comm_ring R] [comm_ring S] [comm_ring A] [algebra R S] [algebra S A] (s : set S) : adjoin R (algebra_map S (comap R S A) '' s) = subalgebra.map (adjoin R s) (to_comap R S A) := le_antisymm (adjoin_le $ set.image_subset_iff.2 $ λ y hy, ⟨y, subset_adjoin hy, rfl⟩) (subalgebra.map_le.2 $ adjoin_le $ λ y hy, subset_adjoin ⟨y, hy, rfl⟩) theorem adjoin_algebra_map (R : Type u) (S : Type v) (A : Type w) [comm_ring R] [comm_ring S] [comm_ring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] (s : set S) : adjoin R (algebra_map S A '' s) = subalgebra.map (adjoin R s) (is_scalar_tower.to_alg_hom R S A) := le_antisymm (adjoin_le $ set.image_subset_iff.2 $ λ y hy, ⟨y, subset_adjoin hy, rfl⟩) (subalgebra.map_le.2 $ adjoin_le $ λ y hy, subset_adjoin ⟨y, hy, rfl⟩) end algebra namespace subalgebra open is_scalar_tower variables (R) {S A} [comm_semiring R] [comm_semiring S] [semiring A] variables [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] /-- If A/S/R is a tower of algebras then the `res`triction of a S-subalgebra of A is an R-subalgebra of A. -/ def res (U : subalgebra S A) : subalgebra R A := { algebra_map_mem' := λ x, by { rw algebra_map_apply R S A, exact U.algebra_map_mem _ }, .. U} @[simp] lemma res_top : res R (⊤ : subalgebra S A) = ⊤ := algebra.eq_top_iff.2 $ λ _, show _ ∈ (⊤ : subalgebra S A), from algebra.mem_top @[simp] lemma mem_res {U : subalgebra S A} {x : A} : x ∈ res R U ↔ x ∈ U := iff.rfl lemma res_inj {U V : subalgebra S A} (H : res R U = res R V) : U = V := ext $ λ x, by rw [← mem_res R, H, mem_res] /-- Produces a map from `subalgebra.under`. -/ def of_under {R A B : Type*} [comm_semiring R] [comm_semiring A] [semiring B] [algebra R A] [algebra R B] (S : subalgebra R A) (U : subalgebra S A) [algebra S B] [is_scalar_tower R S B] (f : U →ₐ[S] B) : S.under U →ₐ[R] B := { commutes' := λ r, (f.commutes (algebra_map R S r)).trans (algebra_map_apply R S B r).symm, .. f } end subalgebra namespace is_scalar_tower open subalgebra variables [comm_semiring R] [comm_semiring S] [comm_semiring A] variables [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] theorem range_under_adjoin (t : set A) : (to_alg_hom R S A).range.under (algebra.adjoin _ t) = res R (algebra.adjoin S t) := subalgebra.ext $ λ z, show z ∈ subsemiring.closure (set.range (algebra_map (to_alg_hom R S A).range A) ∪ t : set A) ↔ z ∈ subsemiring.closure (set.range (algebra_map S A) ∪ t : set A), from suffices set.range (algebra_map (to_alg_hom R S A).range A) = set.range (algebra_map S A), by rw this, by { ext z, exact ⟨λ ⟨⟨x, y, _, h1⟩, h2⟩, ⟨y, h2 ▸ h1⟩, λ ⟨y, hy⟩, ⟨⟨z, y, set.mem_univ _, hy⟩, rfl⟩⟩ } end is_scalar_tower namespace submodule open is_scalar_tower variables [comm_semiring R] [semiring S] [add_comm_monoid A] variables [algebra R S] [semimodule S A] [semimodule R A] [is_scalar_tower R S A] variables (R) {S A} /-- Restricting the scalars of submodules in an algebra tower. -/ def restrict_scalars' (U : submodule S A) : submodule R A := { smul_mem' := λ r x hx, algebra_map_smul S r x ▸ U.smul_mem _ hx, .. U } variables (R S A) theorem restrict_scalars'_top : restrict_scalars' R (⊤ : submodule S A) = ⊤ := rfl variables {R S A} theorem restrict_scalars'_injective (U₁ U₂ : submodule S A) (h : restrict_scalars' R U₁ = restrict_scalars' R U₂) : U₁ = U₂ := ext $ by convert set.ext_iff.1 (ext'_iff.1 h); refl theorem restrict_scalars'_inj {U₁ U₂ : submodule S A} : restrict_scalars' R U₁ = restrict_scalars' R U₂ ↔ U₁ = U₂ := ⟨restrict_scalars'_injective U₁ U₂, congr_arg _⟩ end submodule section semiring variables {R S A} variables [comm_semiring R] [semiring S] [add_comm_monoid A] variables [algebra R S] [semimodule S A] [semimodule R A] [is_scalar_tower R S A] namespace submodule open is_scalar_tower theorem smul_mem_span_smul_of_mem {s : set S} {t : set A} {k : S} (hks : k ∈ span R s) {x : A} (hx : x ∈ t) : k • x ∈ span R (s • t) := span_induction hks (λ c hc, subset_span $ set.mem_smul.2 ⟨c, x, hc, hx, rfl⟩) (by { rw zero_smul, exact zero_mem _ }) (λ c₁ c₂ ih₁ ih₂, by { rw add_smul, exact add_mem _ ih₁ ih₂ }) (λ b c hc, by { rw is_scalar_tower.smul_assoc, exact smul_mem _ _ hc }) theorem smul_mem_span_smul {s : set S} (hs : span R s = ⊤) {t : set A} {k : S} {x : A} (hx : x ∈ span R t) : k • x ∈ span R (s • t) := span_induction hx (λ x hx, smul_mem_span_smul_of_mem (hs.symm ▸ mem_top) hx) (by { rw smul_zero, exact zero_mem _ }) (λ x y ihx ihy, by { rw smul_add, exact add_mem _ ihx ihy }) (λ c x hx, smul_left_comm c k x ▸ smul_mem _ _ hx) theorem smul_mem_span_smul' {s : set S} (hs : span R s = ⊤) {t : set A} {k : S} {x : A} (hx : x ∈ span R (s • t)) : k • x ∈ span R (s • t) := span_induction hx (λ x hx, let ⟨p, q, hp, hq, hpq⟩ := set.mem_smul.1 hx in by { rw [← hpq, smul_smul], exact smul_mem_span_smul_of_mem (hs.symm ▸ mem_top) hq }) (by { rw smul_zero, exact zero_mem _ }) (λ x y ihx ihy, by { rw smul_add, exact add_mem _ ihx ihy }) (λ c x hx, smul_left_comm c k x ▸ smul_mem _ _ hx) theorem span_smul {s : set S} (hs : span R s = ⊤) (t : set A) : span R (s • t) = (span S t).restrict_scalars' R := le_antisymm (span_le.2 $ λ x hx, let ⟨p, q, hps, hqt, hpqx⟩ := set.mem_smul.1 hx in hpqx ▸ (span S t).smul_mem p (subset_span hqt)) $ λ p hp, span_induction hp (λ x hx, one_smul S x ▸ smul_mem_span_smul hs (subset_span hx)) (zero_mem _) (λ _ _, add_mem _) (λ k x hx, smul_mem_span_smul' hs hx) end submodule end semiring section ring open finsupp open_locale big_operators classical universes v₁ w₁ variables {R S A} variables [comm_ring R] [ring S] [add_comm_group A] variables [algebra R S] [module S A] [module R A] [is_scalar_tower R S A] theorem linear_independent_smul {ι : Type v₁} {b : ι → S} {ι' : Type w₁} {c : ι' → A} (hb : linear_independent R b) (hc : linear_independent S c) : linear_independent R (λ p : ι × ι', b p.1 • c p.2) := begin rw linear_independent_iff' at hb hc, rw linear_independent_iff'', rintros s g hg hsg ⟨i, k⟩, by_cases hik : (i, k) ∈ s, { have h1 : ∑ i in (s.image prod.fst).product (s.image prod.snd), g i • b i.1 • c i.2 = 0, { rw ← hsg, exact (finset.sum_subset finset.subset_product $ λ p _ hp, show g p • b p.1 • c p.2 = 0, by rw [hg p hp, zero_smul]).symm }, rw [finset.sum_product, finset.sum_comm] at h1, simp_rw [← smul_assoc, ← finset.sum_smul] at h1, exact hb _ _ (hc _ _ h1 k (finset.mem_image_of_mem _ hik)) i (finset.mem_image_of_mem _ hik) }, exact hg _ hik end theorem is_basis.smul {ι : Type v₁} {b : ι → S} {ι' : Type w₁} {c : ι' → A} (hb : is_basis R b) (hc : is_basis S c) : is_basis R (λ p : ι × ι', b p.1 • c p.2) := ⟨linear_independent_smul hb.1 hc.1, by rw [← set.range_smul_range, submodule.span_smul hb.2, ← submodule.restrict_scalars'_top R S A, submodule.restrict_scalars'_inj, hc.2]⟩ theorem is_basis.smul_repr {ι ι' : Type*} {b : ι → S} {c : ι' → A} (hb : is_basis R b) (hc : is_basis S c) (x : A) (ij : ι × ι') : (hb.smul hc).repr x ij = hb.repr (hc.repr x ij.2) ij.1 := begin apply (hb.smul hc).repr_apply_eq, { intros x y, ext, simp only [linear_map.map_add, add_apply, pi.add_apply] }, { intros c x, ext, simp only [← is_scalar_tower.algebra_map_smul S c x, linear_map.map_smul, smul_eq_mul, ← algebra.smul_def, smul_apply, pi.smul_apply] }, rintros ij, ext ij', rw single_apply, split_ifs with hij, { simp [hij] }, rw [linear_map.map_smul, smul_apply, hc.repr_self_apply], split_ifs with hj, { simp [hj, show ¬ (ij.1 = ij'.1), from λ hi, hij (prod.ext hi hj)] }, simp end theorem is_basis.smul_repr_mk {ι ι' : Type*} {b : ι → S} {c : ι' → A} (hb : is_basis R b) (hc : is_basis S c) (x : A) (i : ι) (j : ι') : (hb.smul hc).repr x (i, j) = hb.repr (hc.repr x j) i := by simp [is_basis.smul_repr] end ring
0c989dc7e6b5a11c36ed863f0032db13ba13b917
6dc0c8ce7a76229dd81e73ed4474f15f88a9e294
/src/Lean/PrettyPrinter/Delaborator/Builtins.lean
ca2b3ced565c0e8f32e61333a49a7347735c8224
[ "Apache-2.0" ]
permissive
williamdemeo/lean4
72161c58fe65c3ad955d6a3050bb7d37c04c0d54
6d00fcf1d6d873e195f9220c668ef9c58e9c4a35
refs/heads/master
1,678,305,356,877
1,614,708,995,000
1,614,708,995,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
23,815
lean
/- Copyright (c) 2020 Sebastian Ullrich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sebastian Ullrich -/ import Lean.PrettyPrinter.Delaborator.Basic import Lean.Parser namespace Lean.PrettyPrinter.Delaborator open Lean.Meta open Lean.Parser.Term @[builtinDelab fvar] def delabFVar : Delab := do let Expr.fvar id _ ← getExpr | unreachable! try let l ← getLocalDecl id pure $ mkIdent l.userName catch _ => -- loose free variable, use internal name pure $ mkIdent id -- loose bound variable, use pseudo syntax @[builtinDelab bvar] def delabBVar : Delab := do let Expr.bvar idx _ ← getExpr | unreachable! pure $ mkIdent $ Name.mkSimple $ "#" ++ toString idx @[builtinDelab mvar] def delabMVar : Delab := do let Expr.mvar n _ ← getExpr | unreachable! let n := n.replacePrefix `_uniq `m `(?$(mkIdent n)) @[builtinDelab sort] def delabSort : Delab := do let Expr.sort l _ ← getExpr | unreachable! match l with | Level.zero _ => `(Prop) | Level.succ (Level.zero _) _ => `(Type) | _ => match l.dec with | some l' => `(Type $(Level.quote l' maxPrec!)) | none => `(Sort $(Level.quote l maxPrec!)) -- find shorter names for constants, in reverse to Lean.Elab.ResolveName private def unresolveQualifiedName (ns : Name) (c : Name) : DelabM Name := do let c' := c.replacePrefix ns Name.anonymous; let env ← getEnv guard $ c' != c && !c'.isAnonymous && (!c'.isAtomic || !isProtected env c) pure c' private def unresolveUsingNamespace (c : Name) : Name → DelabM Name | ns@(Name.str p _ _) => unresolveQualifiedName ns c <|> unresolveUsingNamespace c p | _ => failure private def unresolveOpenDecls (c : Name) : List OpenDecl → DelabM Name | [] => failure | OpenDecl.simple ns exs :: openDecls => let c' := c.replacePrefix ns Name.anonymous if c' != c && exs.elem c' then unresolveOpenDecls c openDecls else unresolveQualifiedName ns c <|> unresolveOpenDecls c openDecls | OpenDecl.explicit openedId resolvedId :: openDecls => guard (c == resolvedId) *> pure openedId <|> unresolveOpenDecls c openDecls -- NOTE: not a registered delaborator, as `const` is never called (see [delab] description) def delabConst : Delab := do let Expr.const c ls _ ← getExpr | unreachable! let c ← if (← getPPOption getPPFullNames) then pure c else let ctx ← read let env ← getEnv let as := getRevAliases env c -- might want to use a more clever heuristic such as selecting the shortest alias... let c := as.headD c unresolveUsingNamespace c ctx.currNamespace <|> unresolveOpenDecls c ctx.openDecls <|> pure c let c ← if (← getPPOption getPPPrivateNames) then pure c else pure $ (privateToUserName? c).getD c let ppUnivs ← getPPOption getPPUniverses if ls.isEmpty || !ppUnivs then pure $ mkIdent c else `($(mkIdent c).{$[$(ls.toArray.map quote)],*}) inductive ParamKind where | explicit -- combines implicit params, optParams, and autoParams | implicit (defVal : Option Expr) /-- Return array with n-th element set to kind of n-th parameter of `e`. -/ def getParamKinds (e : Expr) : MetaM (Array ParamKind) := do let t ← inferType e forallTelescopeReducing t fun params _ => params.mapM fun param => do let l ← getLocalDecl param.fvarId! match l.type.getOptParamDefault? with | some val => pure $ ParamKind.implicit val | _ => if l.type.isAutoParam || !l.binderInfo.isExplicit then pure $ ParamKind.implicit none else pure ParamKind.explicit @[builtinDelab app] def delabAppExplicit : Delab := do let (fnStx, argStxs) ← withAppFnArgs (do let fn ← getExpr let stx ← if fn.isConst then delabConst else delab let paramKinds ← liftM <| getParamKinds fn <|> pure #[] let stx ← if paramKinds.any (fun | ParamKind.explicit => false | _ => true) then `(@$stx) else pure stx pure (stx, #[])) (fun ⟨fnStx, argStxs⟩ => do let argStx ← delab pure (fnStx, argStxs.push argStx)) Syntax.mkApp fnStx argStxs @[builtinDelab app] def delabAppImplicit : Delab := whenNotPPOption getPPExplicit do let (fnStx, _, argStxs) ← withAppFnArgs (do let fn ← getExpr let stx ← if fn.isConst then delabConst else delab let paramKinds ← liftM (getParamKinds fn <|> pure #[]) pure (stx, paramKinds.toList, #[])) (fun (fnStx, paramKinds, argStxs) => do let arg ← getExpr; let implicit : Bool := match paramKinds with -- TODO: check why we need `: Bool` here | [ParamKind.implicit (some v)] => !v.hasLooseBVars && v == arg | ParamKind.implicit none :: _ => true | _ => false if implicit then pure (fnStx, paramKinds.tailD [], argStxs) else do let argStx ← delab pure (fnStx, paramKinds.tailD [], argStxs.push argStx)) Syntax.mkApp fnStx argStxs @[builtinDelab app] def delabAppWithUnexpander : Delab := whenPPOption getPPNotation do let Expr.const c _ _ ← pure (← getExpr).getAppFn | failure let stx ← delabAppImplicit match stx with | `($cPP:ident $args*) => do let some (f::_) ← pure <| (appUnexpanderAttribute.ext.getState (← getEnv)).table.find? c | pure stx let EStateM.Result.ok stx _ ← f stx |>.run () | pure stx pure stx | _ => pure stx /-- State for `delabAppMatch` and helpers. -/ structure AppMatchState where info : MatcherInfo matcherTy : Expr params : Array Expr := #[] hasMotive : Bool := false discrs : Array Syntax := #[] varNames : Array (Array Name) := #[] rhss : Array Syntax := #[] -- additional arguments applied to the result of the `match` expression moreArgs : Array Syntax := #[] /-- Extract arguments of motive applications from the matcher type. For the example below: `#[#[`([])], #[`(a::as)]]` -/ private partial def delabPatterns (st : AppMatchState) : DelabM (Array (Array Syntax)) := do let ty ← instantiateForall st.matcherTy st.params forallTelescope ty fun params _ => do -- skip motive and discriminators let alts := Array.ofSubarray $ params[1 + st.discrs.size:] alts.mapIdxM fun idx alt => do let ty ← inferType alt withReader ({ · with expr := ty }) $ usingNames st.varNames[idx] do withAppFnArgs (pure #[]) (fun pats => do pure $ pats.push (← delab)) where usingNames {α} (varNames : Array Name) (x : DelabM α) : DelabM α := usingNamesAux 0 varNames x usingNamesAux {α} (i : Nat) (varNames : Array Name) (x : DelabM α) : DelabM α := if i < varNames.size then withBindingBody varNames[i] <| usingNamesAux (i+1) varNames x else x /-- Skip `numParams` binders, and execute `x varNames` where `varNames` contains the new binder names. -/ private def skippingBinders {α} (numParams : Nat) (x : Array Name → DelabM α) : DelabM α := loop numParams #[] where loop : Nat → Array Name → DelabM α | 0, varNames => x varNames | n+1, varNames => do let varName ← (← getExpr).bindingName!.eraseMacroScopes -- Pattern variables cannot shadow each other if varNames.contains varName then let varName := (← getLCtx).getUnusedName varName withBindingBody varName do loop n (varNames.push varName) else withBindingBodyUnusedName fun id => do loop n (varNames.push id.getId) /-- Delaborate applications of "matchers" such as ``` List.map.match_1 : {α : Type _} → (motive : List α → Sort _) → (x : List α) → (Unit → motive List.nil) → ((a : α) → (as : List α) → motive (a :: as)) → motive x ``` -/ @[builtinDelab app] def delabAppMatch : Delab := whenPPOption getPPNotation do -- incrementally fill `AppMatchState` from arguments let st ← withAppFnArgs (do let (Expr.const c us _) ← getExpr | failure let (some info) ← getMatcherInfo? c | failure { matcherTy := (← getConstInfo c).instantiateTypeLevelParams us, info := info : AppMatchState }) (fun st => do if st.params.size < st.info.numParams then pure { st with params := st.params.push (← getExpr) } else if !st.hasMotive then -- discard motive argument pure { st with hasMotive := true } else if st.discrs.size < st.info.numDiscrs then pure { st with discrs := st.discrs.push (← delab) } else if st.rhss.size < st.info.altNumParams.size then /- We save the variables names here to be able to implement safe_shadowing. The pattern delaboration must use the names saved here. -/ let (varNames, rhs) ← skippingBinders st.info.altNumParams[st.rhss.size] fun varNames => do let rhs ← delab return (varNames, rhs) pure { st with rhss := st.rhss.push rhs, varNames := st.varNames.push varNames } else pure { st with moreArgs := st.moreArgs.push (← delab) }) if st.discrs.size < st.info.numDiscrs || st.rhss.size < st.info.altNumParams.size then -- underapplied failure match st.discrs, st.rhss with | #[discr], #[] => let stx ← `(nomatch $discr) Syntax.mkApp stx st.moreArgs | _, #[] => failure | _, _ => let pats ← delabPatterns st let stx ← `(match $[$st.discrs:term],* with $[| $pats,* => $st.rhss]*) Syntax.mkApp stx st.moreArgs @[builtinDelab mdata] def delabMData : Delab := do -- only interpret `pp.` values by default let Expr.mdata m _ _ ← getExpr | unreachable! let mut posOpts := (← read).optionsPerPos let mut inaccessible := false let pos := (← read).pos for (k, v) in m do if (`pp).isPrefixOf k then let opts := posOpts.find? pos |>.getD {} posOpts := posOpts.insert pos (opts.insert k v) if k == `inaccessible then inaccessible := true withReader ({ · with optionsPerPos := posOpts }) do let s ← withMDataExpr delab if inaccessible then `(.($s)) else pure s /-- Check for a `Syntax.ident` of the given name anywhere in the tree. This is usually a bad idea since it does not check for shadowing bindings, but in the delaborator we assume that bindings are never shadowed. -/ partial def hasIdent (id : Name) : Syntax → Bool | Syntax.ident _ _ id' _ => id == id' | Syntax.node _ args => args.any (hasIdent id) | _ => false /-- Return `true` iff current binder should be merged with the nested binder, if any, into a single binder group: * both binders must have same binder info and domain * they cannot be inst-implicit (`[a b : A]` is not valid syntax) * `pp.binder_types` must be the same value for both terms * prefer `fun a b` over `fun (a b)` -/ private def shouldGroupWithNext : DelabM Bool := do let e ← getExpr let ppEType ← getPPOption getPPBinderTypes; let go (e' : Expr) := do let ppE'Type ← withBindingBody `_ $ getPPOption getPPBinderTypes pure $ e.binderInfo == e'.binderInfo && e.bindingDomain! == e'.bindingDomain! && e'.binderInfo != BinderInfo.instImplicit && ppEType == ppE'Type && (e'.binderInfo != BinderInfo.default || ppE'Type) match e with | Expr.lam _ _ e'@(Expr.lam _ _ _ _) _ => go e' | Expr.forallE _ _ e'@(Expr.forallE _ _ _ _) _ => go e' | _ => pure false private partial def delabBinders (delabGroup : Array Syntax → Syntax → Delab) : optParam (Array Syntax) #[] → Delab -- Accumulate names (`Syntax.ident`s with position information) of the current, unfinished -- binder group `(d e ...)` as determined by `shouldGroupWithNext`. We cannot do grouping -- inside-out, on the Syntax level, because it depends on comparing the Expr binder types. | curNames => do if (← shouldGroupWithNext) then -- group with nested binder => recurse immediately withBindingBodyUnusedName fun stxN => delabBinders delabGroup (curNames.push stxN) else -- don't group => delab body and prepend current binder group let (stx, stxN) ← withBindingBodyUnusedName fun stxN => do (← delab, stxN) delabGroup (curNames.push stxN) stx @[builtinDelab lam] def delabLam : Delab := delabBinders fun curNames stxBody => do let e ← getExpr let stxT ← withBindingDomain delab let ppTypes ← getPPOption getPPBinderTypes let expl ← getPPOption getPPExplicit -- leave lambda implicit if possible let blockImplicitLambda := expl || e.binderInfo == BinderInfo.default || Elab.Term.blockImplicitLambda stxBody || curNames.any (fun n => hasIdent n.getId stxBody); if !blockImplicitLambda then pure stxBody else let group ← match e.binderInfo, ppTypes with | BinderInfo.default, true => -- "default" binder group is the only one that expects binder names -- as a term, i.e. a single `Syntax.ident` or an application thereof let stxCurNames ← if curNames.size > 1 then `($(curNames.get! 0) $(curNames.eraseIdx 0)*) else pure $ curNames.get! 0; `(funBinder| ($stxCurNames : $stxT)) | BinderInfo.default, false => pure curNames.back -- here `curNames.size == 1` | BinderInfo.implicit, true => `(funBinder| {$curNames* : $stxT}) | BinderInfo.implicit, false => `(funBinder| {$curNames*}) | BinderInfo.instImplicit, _ => `(funBinder| [$curNames.back : $stxT]) -- here `curNames.size == 1` | _ , _ => unreachable!; match stxBody with | `(fun $binderGroups* => $stxBody) => `(fun $group $binderGroups* => $stxBody) | _ => `(fun $group => $stxBody) @[builtinDelab forallE] def delabForall : Delab := delabBinders fun curNames stxBody => do let e ← getExpr let prop ← try isProp e catch _ => false let stxT ← withBindingDomain delab let group ← match e.binderInfo with | BinderInfo.implicit => `(bracketedBinderF|{$curNames* : $stxT}) -- here `curNames.size == 1` | BinderInfo.instImplicit => `(bracketedBinderF|[$curNames.back : $stxT]) | _ => -- heuristic: use non-dependent arrows only if possible for whole group to avoid -- noisy mix like `(α : Type) → Type → (γ : Type) → ...`. let dependent := curNames.any $ fun n => hasIdent n.getId stxBody -- NOTE: non-dependent arrows are available only for the default binder info if dependent then if prop && !(← getPPOption getPPBinderTypes) then return ← `(∀ $curNames:ident*, $stxBody) else `(bracketedBinderF|($curNames* : $stxT)) else return ← curNames.foldrM (fun _ stxBody => `($stxT → $stxBody)) stxBody if prop then match stxBody with | `(∀ $groups*, $stxBody) => `(∀ $group $groups*, $stxBody) | _ => `(∀ $group, $stxBody) else `($group:bracketedBinder → $stxBody) @[builtinDelab letE] def delabLetE : Delab := do let Expr.letE n t v b _ ← getExpr | unreachable! let n ← getUnusedName n b let stxT ← descend t 0 delab let stxV ← descend v 1 delab let stxB ← withLetDecl n t v fun fvar => let b := b.instantiate1 fvar descend b 2 delab `(let $(mkIdent n) : $stxT := $stxV; $stxB) @[builtinDelab lit] def delabLit : Delab := do let Expr.lit l _ ← getExpr | unreachable! match l with | Literal.natVal n => pure $ quote n | Literal.strVal s => pure $ quote s -- `@OfNat.ofNat _ n _` ~> `n` @[builtinDelab app.OfNat.ofNat] def delabOfNat : Delab := whenPPOption getPPCoercions do let (Expr.app (Expr.app _ (Expr.lit (Literal.natVal n) _) _) _ _) ← getExpr | failure return quote n -- `@OfDecimal.ofDecimal _ _ m s e` ~> `m*10^(sign * e)` where `sign == 1` if `s = false` and `sign = -1` if `s = true` @[builtinDelab app.OfScientific.ofScientific] def delabOfScientific : Delab := whenPPOption getPPCoercions do let expr ← getExpr guard <| expr.getAppNumArgs == 5 let Expr.lit (Literal.natVal m) _ ← pure (expr.getArg! 2) | failure let Expr.lit (Literal.natVal e) _ ← pure (expr.getArg! 4) | failure let s ← match expr.getArg! 3 with | Expr.const `Bool.true _ _ => pure true | Expr.const `Bool.false _ _ => pure false | _ => failure let str := toString m if s && e == str.length then return Syntax.mkScientificLit ("0." ++ str) else if s && e < str.length then let mStr := str.extract 0 (str.length - e) let eStr := str.extract (str.length - e) str.length return Syntax.mkScientificLit (mStr ++ "." ++ eStr) else return Syntax.mkScientificLit (str ++ "e" ++ (if s then "-" else "") ++ toString e) /-- Delaborate a projection primitive. These do not usually occur in user code, but are pretty-printed when e.g. `#print`ing a projection function. -/ @[builtinDelab proj] def delabProj : Delab := do let Expr.proj _ idx _ _ ← getExpr | unreachable! let e ← withProj delab -- not perfectly authentic: elaborates to the `idx`-th named projection -- function (e.g. `e.1` is `Prod.fst e`), which unfolds to the actual -- `proj`. let idx := Syntax.mkLit fieldIdxKind (toString (idx + 1)); `($(e).$idx:fieldIdx) /-- Delaborate a call to a projection function such as `Prod.fst`. -/ @[builtinDelab app] def delabProjectionApp : Delab := whenPPOption getPPStructureProjections $ do let e@(Expr.app fn _ _) ← getExpr | failure let Expr.const c@(Name.str _ f _) _ _ ← pure fn.getAppFn | failure let env ← getEnv let some info ← pure $ env.getProjectionFnInfo? c | failure -- can't use with classes since the instance parameter is implicit guard $ !info.fromClass -- projection function should be fully applied (#struct params + 1 instance parameter) -- TODO: support over-application guard $ e.getAppNumArgs == info.nparams + 1 -- If pp.explicit is true, and the structure has parameters, we should not -- use field notation because we will not be able to see the parameters. let expl ← getPPOption getPPExplicit guard $ !expl || info.nparams == 0 let appStx ← withAppArg delab `($(appStx).$(mkIdent f):ident) @[builtinDelab app] def delabStructureInstance : Delab := whenPPOption getPPStructureInstances do let env ← getEnv let e ← getExpr let some s ← pure $ e.isConstructorApp? env | failure guard $ isStructure env s.induct; /- If implicit arguments should be shown, and the structure has parameters, we should not pretty print using { ... }, because we will not be able to see the parameters. -/ let explicit ← getPPOption getPPExplicit guard !(explicit && s.numParams > 0) let fieldNames := getStructureFields env s.induct let (_, fields) ← withAppFnArgs (pure (0, #[])) fun ⟨idx, fields⟩ => do if idx < s.numParams then pure (idx + 1, fields) else let val ← delab let field ← `(structInstField|$(mkIdent <| fieldNames.get! (idx - s.numParams)):ident := $val) pure (idx + 1, fields.push field) let lastField := fields[fields.size - 1] let fields := fields.pop let ty ← if (← getPPOption getPPStructureInstanceType) then let ty ← inferType e -- `ty` is not actually part of `e`, but since `e` must be an application or constant, we know that -- index 2 is unused. pure <| some (← descend ty 2 delab) else pure <| none `({ $[$fields, ]* $lastField $[: $ty]? }) @[builtinDelab app.Prod.mk] def delabTuple : Delab := whenPPOption getPPNotation do let e ← getExpr guard $ e.getAppNumArgs == 4 let a ← withAppFn $ withAppArg delab let b ← withAppArg delab match b with | `(($b, $bs,*)) => `(($a, $b, $bs,*)) | _ => `(($a, $b)) -- abbrev coe {α : Sort u} {β : Sort v} (a : α) [CoeT α a β] : β @[builtinDelab app.coe] def delabCoe : Delab := whenPPOption getPPCoercions do let e ← getExpr guard $ e.getAppNumArgs >= 4 -- delab as application, then discard function let stx ← delabAppImplicit match stx with | `($fn $arg) => arg | `($fn $args*) => `($(args.get! 0) $(args.eraseIdx 0)*) | _ => failure -- abbrev coeFun {α : Sort u} {γ : α → Sort v} (a : α) [CoeFun α γ] : γ a @[builtinDelab app.coeFun] def delabCoeFun : Delab := delabCoe @[builtinDelab app.List.nil] def delabNil : Delab := whenPPOption getPPNotation do guard $ (← getExpr).getAppNumArgs == 1 `([]) @[builtinDelab app.List.cons] def delabConsList : Delab := whenPPOption getPPNotation do guard $ (← getExpr).getAppNumArgs == 3 let x ← withAppFn (withAppArg delab) match (← withAppArg delab) with | `([]) => `([$x]) | `([$xs,*]) => `([$x, $xs,*]) | _ => failure @[builtinDelab app.List.toArray] def delabListToArray : Delab := whenPPOption getPPNotation do guard $ (← getExpr).getAppNumArgs == 2 match (← withAppArg delab) with | `([$xs,*]) => `(#[$xs,*]) | _ => failure @[builtinDelab app.ite] def delabIte : Delab := whenPPOption getPPNotation do guard $ (← getExpr).getAppNumArgs == 5 let c ← withAppFn $ withAppFn $ withAppFn $ withAppArg delab let t ← withAppFn $ withAppArg delab let e ← withAppArg delab `(if $c then $t else $e) @[builtinDelab app.dite] def delabDIte : Delab := whenPPOption getPPNotation do guard $ (← getExpr).getAppNumArgs == 5 let c ← withAppFn $ withAppFn $ withAppFn $ withAppArg delab let (t, h) ← withAppFn $ withAppArg $ delabBranch none let (e, _) ← withAppArg $ delabBranch h `(if $(mkIdent h):ident : $c then $t else $e) where delabBranch (h? : Option Name) : DelabM (Syntax × Name) := do let e ← getExpr guard e.isLambda let h ← match h? with | some h => return (← withBindingBody h delab, h) | none => withBindingBodyUnusedName fun h => do return (← delab, h.getId) @[builtinDelab app.namedPattern] def delabNamedPattern : Delab := do guard $ (← getExpr).getAppNumArgs == 3 let x ← withAppFn $ withAppArg delab let p ← withAppArg delab guard x.isIdent `($x:ident@$p:term) partial def delabDoElems : DelabM (List Syntax) := do let e ← getExpr if e.isAppOfArity `Bind.bind 6 then -- Bind.bind.{u, v} : {m : Type u → Type v} → [self : Bind m] → {α β : Type u} → m α → (α → m β) → m β let ma ← withAppFn $ withAppArg delab withAppArg do match (← getExpr) with | Expr.lam _ _ body _ => withBindingBodyUnusedName fun n => do if body.hasLooseBVars then prependAndRec `(doElem|let $n:term ← $ma) else prependAndRec `(doElem|$ma:term) | _ => failure else if e.isLet then let Expr.letE n t v b _ ← getExpr | unreachable! let n ← getUnusedName n b let stxT ← descend t 0 delab let stxV ← descend v 1 delab withLetDecl n t v fun fvar => let b := b.instantiate1 fvar descend b 2 $ prependAndRec `(doElem|let $(mkIdent n) : $stxT := $stxV) else let stx ← delab [←`(doElem|$stx:term)] where prependAndRec x : DelabM _ := List.cons <$> x <*> delabDoElems @[builtinDelab app.Bind.bind] def delabDo : Delab := whenPPOption getPPNotation do unless (← getExpr).isAppOfArity `Bind.bind 6 do failure let elems ← delabDoElems let items ← elems.toArray.mapM (`(doSeqItem|$(·):doElem)) `(do $items:doSeqItem*) @[builtinDelab app.sorryAx] def delabSorryAx : Delab := whenPPOption getPPNotation do unless (← getExpr).isAppOfArity ``sorryAx 2 do failure `(sorry) end Lean.PrettyPrinter.Delaborator
a866e2df8d332b2534abb7e68a91b5454abdc393
618003631150032a5676f229d13a079ac875ff77
/src/analysis/normed_space/basic.lean
840262fe5124da1332844174d081cdd6b7635934
[ "Apache-2.0" ]
permissive
awainverse/mathlib
939b68c8486df66cfda64d327ad3d9165248c777
ea76bd8f3ca0a8bf0a166a06a475b10663dec44a
refs/heads/master
1,659,592,962,036
1,590,987,592,000
1,590,987,592,000
268,436,019
1
0
Apache-2.0
1,590,990,500,000
1,590,990,500,000
null
UTF-8
Lean
false
false
46,118
lean
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl -/ import topology.instances.nnreal import topology.instances.complex import topology.algebra.module import topology.metric_space.antilipschitz /-! # Normed spaces -/ variables {α : Type*} {β : Type*} {γ : Type*} {ι : Type*} noncomputable theory open filter metric open_locale topological_space big_operators localized "notation f `→_{`:50 a `}`:0 b := filter.tendsto f (_root_.nhds a) (_root_.nhds b)" in filter /-- Auxiliary class, endowing a type `α` with a function `norm : α → ℝ`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ class has_norm (α : Type*) := (norm : α → ℝ) export has_norm (norm) notation `∥`:1024 e:1 `∥`:1 := norm e section prio set_option default_priority 100 -- see Note [default priority] /-- A normed group is an additive group endowed with a norm for which `dist x y = ∥x - y∥` defines a metric space structure. -/ class normed_group (α : Type*) extends has_norm α, add_comm_group α, metric_space α := (dist_eq : ∀ x y, dist x y = norm (x - y)) end prio /-- Construct a normed group from a translation invariant distance -/ def normed_group.of_add_dist [has_norm α] [add_comm_group α] [metric_space α] (H1 : ∀ x:α, ∥x∥ = dist x 0) (H2 : ∀ x y z : α, dist x y ≤ dist (x + z) (y + z)) : normed_group α := { dist_eq := λ x y, begin rw H1, apply le_antisymm, { rw [sub_eq_add_neg, ← add_right_neg y], apply H2 }, { have := H2 (x-y) 0 y, rwa [sub_add_cancel, zero_add] at this } end } /-- Construct a normed group from a translation invariant distance -/ def normed_group.of_add_dist' [has_norm α] [add_comm_group α] [metric_space α] (H1 : ∀ x:α, ∥x∥ = dist x 0) (H2 : ∀ x y z : α, dist (x + z) (y + z) ≤ dist x y) : normed_group α := { dist_eq := λ x y, begin rw H1, apply le_antisymm, { have := H2 (x-y) 0 y, rwa [sub_add_cancel, zero_add] at this }, { rw [sub_eq_add_neg, ← add_right_neg y], apply H2 } end } /-- A normed group can be built from a norm that satisfies algebraic properties. This is formalised in this structure. -/ structure normed_group.core (α : Type*) [add_comm_group α] [has_norm α] : Prop := (norm_eq_zero_iff : ∀ x : α, ∥x∥ = 0 ↔ x = 0) (triangle : ∀ x y : α, ∥x + y∥ ≤ ∥x∥ + ∥y∥) (norm_neg : ∀ x : α, ∥-x∥ = ∥x∥) /-- Constructing a normed group from core properties of a norm, i.e., registering the distance and the metric space structure from the norm properties. -/ noncomputable def normed_group.of_core (α : Type*) [add_comm_group α] [has_norm α] (C : normed_group.core α) : normed_group α := { dist := λ x y, ∥x - y∥, dist_eq := assume x y, by refl, dist_self := assume x, (C.norm_eq_zero_iff (x - x)).mpr (show x - x = 0, by simp), eq_of_dist_eq_zero := assume x y h, show (x = y), from sub_eq_zero.mp $ (C.norm_eq_zero_iff (x - y)).mp h, dist_triangle := assume x y z, calc ∥x - z∥ = ∥x - y + (y - z)∥ : by rw sub_add_sub_cancel ... ≤ ∥x - y∥ + ∥y - z∥ : C.triangle _ _, dist_comm := assume x y, calc ∥x - y∥ = ∥ -(y - x)∥ : by simp ... = ∥y - x∥ : by { rw [C.norm_neg] } } section normed_group variables [normed_group α] [normed_group β] lemma dist_eq_norm (g h : α) : dist g h = ∥g - h∥ := normed_group.dist_eq _ _ @[simp] lemma dist_zero_right (g : α) : dist g 0 = ∥g∥ := by rw [dist_eq_norm, sub_zero] lemma norm_sub_rev (g h : α) : ∥g - h∥ = ∥h - g∥ := by simpa only [dist_eq_norm] using dist_comm g h @[simp] lemma norm_neg (g : α) : ∥-g∥ = ∥g∥ := by simpa using norm_sub_rev 0 g @[simp] lemma dist_add_left (g h₁ h₂ : α) : dist (g + h₁) (g + h₂) = dist h₁ h₂ := by simp [dist_eq_norm] @[simp] lemma dist_add_right (g₁ g₂ h : α) : dist (g₁ + h) (g₂ + h) = dist g₁ g₂ := by simp [dist_eq_norm] @[simp] lemma dist_neg_neg (g h : α) : dist (-g) (-h) = dist g h := by simp only [dist_eq_norm, neg_sub_neg, norm_sub_rev] @[simp] lemma dist_sub_left (g h₁ h₂ : α) : dist (g - h₁) (g - h₂) = dist h₁ h₂ := by simp only [sub_eq_add_neg, dist_add_left, dist_neg_neg] @[simp] lemma dist_sub_right (g₁ g₂ h : α) : dist (g₁ - h) (g₂ - h) = dist g₁ g₂ := dist_add_right _ _ _ /-- Triangle inequality for the norm. -/ lemma norm_add_le (g h : α) : ∥g + h∥ ≤ ∥g∥ + ∥h∥ := by simpa [dist_eq_norm] using dist_triangle g 0 (-h) lemma norm_add_le_of_le {g₁ g₂ : α} {n₁ n₂ : ℝ} (H₁ : ∥g₁∥ ≤ n₁) (H₂ : ∥g₂∥ ≤ n₂) : ∥g₁ + g₂∥ ≤ n₁ + n₂ := le_trans (norm_add_le g₁ g₂) (add_le_add H₁ H₂) lemma dist_add_add_le (g₁ g₂ h₁ h₂ : α) : dist (g₁ + g₂) (h₁ + h₂) ≤ dist g₁ h₁ + dist g₂ h₂ := by simpa only [dist_add_left, dist_add_right] using dist_triangle (g₁ + g₂) (h₁ + g₂) (h₁ + h₂) lemma dist_add_add_le_of_le {g₁ g₂ h₁ h₂ : α} {d₁ d₂ : ℝ} (H₁ : dist g₁ h₁ ≤ d₁) (H₂ : dist g₂ h₂ ≤ d₂) : dist (g₁ + g₂) (h₁ + h₂) ≤ d₁ + d₂ := le_trans (dist_add_add_le g₁ g₂ h₁ h₂) (add_le_add H₁ H₂) lemma dist_sub_sub_le (g₁ g₂ h₁ h₂ : α) : dist (g₁ - g₂) (h₁ - h₂) ≤ dist g₁ h₁ + dist g₂ h₂ := dist_neg_neg g₂ h₂ ▸ dist_add_add_le _ _ _ _ lemma dist_sub_sub_le_of_le {g₁ g₂ h₁ h₂ : α} {d₁ d₂ : ℝ} (H₁ : dist g₁ h₁ ≤ d₁) (H₂ : dist g₂ h₂ ≤ d₂) : dist (g₁ - g₂) (h₁ - h₂) ≤ d₁ + d₂ := le_trans (dist_sub_sub_le g₁ g₂ h₁ h₂) (add_le_add H₁ H₂) lemma abs_dist_sub_le_dist_add_add (g₁ g₂ h₁ h₂ : α) : abs (dist g₁ h₁ - dist g₂ h₂) ≤ dist (g₁ + g₂) (h₁ + h₂) := by simpa only [dist_add_left, dist_add_right, dist_comm h₂] using abs_dist_sub_le (g₁ + g₂) (h₁ + h₂) (h₁ + g₂) @[simp] lemma norm_nonneg (g : α) : 0 ≤ ∥g∥ := by { rw[←dist_zero_right], exact dist_nonneg } @[simp] lemma norm_eq_zero {g : α} : ∥g∥ = 0 ↔ g = 0 := dist_zero_right g ▸ dist_eq_zero @[simp] lemma norm_zero : ∥(0:α)∥ = 0 := norm_eq_zero.2 rfl lemma norm_sum_le {β} : ∀(s : finset β) (f : β → α), ∥s.sum f∥ ≤ s.sum (λa, ∥ f a ∥) := finset.le_sum_of_subadditive norm norm_zero norm_add_le lemma norm_sum_le_of_le {β} (s : finset β) {f : β → α} {n : β → ℝ} (h : ∀ b ∈ s, ∥f b∥ ≤ n b) : ∥s.sum f∥ ≤ s.sum n := by { haveI := classical.dec_eq β, exact le_trans (norm_sum_le s f) (finset.sum_le_sum h) } lemma norm_pos_iff {g : α} : 0 < ∥ g ∥ ↔ g ≠ 0 := dist_zero_right g ▸ dist_pos lemma norm_le_zero_iff {g : α} : ∥g∥ ≤ 0 ↔ g = 0 := by { rw[←dist_zero_right], exact dist_le_zero } lemma norm_sub_le (g h : α) : ∥g - h∥ ≤ ∥g∥ + ∥h∥ := by simpa [dist_eq_norm] using dist_triangle g 0 h lemma norm_sub_le_of_le {g₁ g₂ : α} {n₁ n₂ : ℝ} (H₁ : ∥g₁∥ ≤ n₁) (H₂ : ∥g₂∥ ≤ n₂) : ∥g₁ - g₂∥ ≤ n₁ + n₂ := le_trans (norm_sub_le g₁ g₂) (add_le_add H₁ H₂) lemma dist_le_norm_add_norm (g h : α) : dist g h ≤ ∥g∥ + ∥h∥ := by { rw dist_eq_norm, apply norm_sub_le } lemma abs_norm_sub_norm_le (g h : α) : abs(∥g∥ - ∥h∥) ≤ ∥g - h∥ := by simpa [dist_eq_norm] using abs_dist_sub_le g h 0 lemma norm_sub_norm_le (g h : α) : ∥g∥ - ∥h∥ ≤ ∥g - h∥ := le_trans (le_abs_self _) (abs_norm_sub_norm_le g h) lemma dist_norm_norm_le (g h : α) : dist ∥g∥ ∥h∥ ≤ ∥g - h∥ := abs_norm_sub_norm_le g h lemma ball_0_eq (ε : ℝ) : ball (0:α) ε = {x | ∥x∥ < ε} := set.ext $ assume a, by simp lemma norm_le_of_mem_closed_ball {g h : α} {r : ℝ} (H : h ∈ closed_ball g r) : ∥h∥ ≤ ∥g∥ + r := calc ∥h∥ = ∥g + (h - g)∥ : by rw [add_sub_cancel'_right] ... ≤ ∥g∥ + ∥h - g∥ : norm_add_le _ _ ... ≤ ∥g∥ + r : by { apply add_le_add_left, rw ← dist_eq_norm, exact H } lemma norm_lt_of_mem_ball {g h : α} {r : ℝ} (H : h ∈ ball g r) : ∥h∥ < ∥g∥ + r := calc ∥h∥ = ∥g + (h - g)∥ : by rw [add_sub_cancel'_right] ... ≤ ∥g∥ + ∥h - g∥ : norm_add_le _ _ ... < ∥g∥ + r : by { apply add_lt_add_left, rw ← dist_eq_norm, exact H } theorem normed_group.tendsto_nhds_zero {f : γ → α} {l : filter γ} : tendsto f l (𝓝 0) ↔ ∀ ε > 0, ∀ᶠ x in l, ∥ f x ∥ < ε := metric.tendsto_nhds.trans $ by simp only [dist_zero_right] section nnnorm /-- Version of the norm taking values in nonnegative reals. -/ def nnnorm (a : α) : nnreal := ⟨norm a, norm_nonneg a⟩ @[simp] lemma coe_nnnorm (a : α) : (nnnorm a : ℝ) = norm a := rfl lemma nndist_eq_nnnorm (a b : α) : nndist a b = nnnorm (a - b) := nnreal.eq $ dist_eq_norm _ _ lemma nnnorm_eq_zero {a : α} : nnnorm a = 0 ↔ a = 0 := by simp only [nnreal.eq_iff.symm, nnreal.coe_zero, coe_nnnorm, norm_eq_zero] @[simp] lemma nnnorm_zero : nnnorm (0 : α) = 0 := nnreal.eq norm_zero lemma nnnorm_add_le (g h : α) : nnnorm (g + h) ≤ nnnorm g + nnnorm h := nnreal.coe_le_coe.2 $ norm_add_le g h @[simp] lemma nnnorm_neg (g : α) : nnnorm (-g) = nnnorm g := nnreal.eq $ norm_neg g lemma nndist_nnnorm_nnnorm_le (g h : α) : nndist (nnnorm g) (nnnorm h) ≤ nnnorm (g - h) := nnreal.coe_le_coe.2 $ dist_norm_norm_le g h lemma of_real_norm_eq_coe_nnnorm (x : β) : ennreal.of_real ∥x∥ = (nnnorm x : ennreal) := ennreal.of_real_eq_coe_nnreal _ lemma edist_eq_coe_nnnorm_sub (x y : β) : edist x y = (nnnorm (x - y) : ennreal) := by rw [edist_dist, dist_eq_norm, of_real_norm_eq_coe_nnnorm] lemma edist_eq_coe_nnnorm (x : β) : edist x 0 = (nnnorm x : ennreal) := by rw [edist_eq_coe_nnnorm_sub, _root_.sub_zero] lemma nndist_add_add_le (g₁ g₂ h₁ h₂ : α) : nndist (g₁ + g₂) (h₁ + h₂) ≤ nndist g₁ h₁ + nndist g₂ h₂ := nnreal.coe_le_coe.2 $ dist_add_add_le g₁ g₂ h₁ h₂ lemma edist_add_add_le (g₁ g₂ h₁ h₂ : α) : edist (g₁ + g₂) (h₁ + h₂) ≤ edist g₁ h₁ + edist g₂ h₂ := by { simp only [edist_nndist], norm_cast, apply nndist_add_add_le } lemma nnnorm_sum_le {β} : ∀(s : finset β) (f : β → α), nnnorm (s.sum f) ≤ s.sum (λa, nnnorm (f a)) := finset.le_sum_of_subadditive nnnorm nnnorm_zero nnnorm_add_le end nnnorm lemma lipschitz_with.neg {α : Type*} [emetric_space α] {K : nnreal} {f : α → β} (hf : lipschitz_with K f) : lipschitz_with K (λ x, -f x) := λ x y, by simpa only [edist_dist, dist_neg_neg] using hf x y lemma lipschitz_with.add {α : Type*} [emetric_space α] {Kf : nnreal} {f : α → β} (hf : lipschitz_with Kf f) {Kg : nnreal} {g : α → β} (hg : lipschitz_with Kg g) : lipschitz_with (Kf + Kg) (λ x, f x + g x) := λ x y, calc edist (f x + g x) (f y + g y) ≤ edist (f x) (f y) + edist (g x) (g y) : edist_add_add_le _ _ _ _ ... ≤ Kf * edist x y + Kg * edist x y : add_le_add' (hf x y) (hg x y) ... = (Kf + Kg) * edist x y : (add_mul _ _ _).symm lemma lipschitz_with.sub {α : Type*} [emetric_space α] {Kf : nnreal} {f : α → β} (hf : lipschitz_with Kf f) {Kg : nnreal} {g : α → β} (hg : lipschitz_with Kg g) : lipschitz_with (Kf + Kg) (λ x, f x - g x) := hf.add hg.neg lemma antilipschitz_with.add_lipschitz_with {α : Type*} [metric_space α] {Kf : nnreal} {f : α → β} (hf : antilipschitz_with Kf f) {Kg : nnreal} {g : α → β} (hg : lipschitz_with Kg g) (hK : Kg < Kf⁻¹) : antilipschitz_with (Kf⁻¹ - Kg)⁻¹ (λ x, f x + g x) := begin refine antilipschitz_with.of_le_mul_dist (λ x y, _), rw [nnreal.coe_inv, ← div_eq_inv_mul], apply le_div_of_mul_le (nnreal.coe_pos.2 $ nnreal.sub_pos.2 hK), rw [mul_comm, nnreal.coe_sub (le_of_lt hK), sub_mul], calc ↑Kf⁻¹ * dist x y - Kg * dist x y ≤ dist (f x) (f y) - dist (g x) (g y) : sub_le_sub (hf.mul_le_dist x y) (hg.dist_le_mul x y) ... ≤ _ : le_trans (le_abs_self _) (abs_dist_sub_le_dist_add_add _ _ _ _) end /-- A submodule of a normed group is also a normed group, with the restriction of the norm. As all instances can be inferred from the submodule `s`, they are put as implicit instead of typeclasses. -/ instance submodule.normed_group {𝕜 : Type*} {_ : ring 𝕜} {E : Type*} [normed_group E] {_ : module 𝕜 E} (s : submodule 𝕜 E) : normed_group s := { norm := λx, norm (x : E), dist_eq := λx y, dist_eq_norm (x : E) (y : E) } /-- normed group instance on the product of two normed groups, using the sup norm. -/ instance prod.normed_group : normed_group (α × β) := { norm := λx, max ∥x.1∥ ∥x.2∥, dist_eq := assume (x y : α × β), show max (dist x.1 y.1) (dist x.2 y.2) = (max ∥(x - y).1∥ ∥(x - y).2∥), by simp [dist_eq_norm] } lemma prod.norm_def (x : α × β) : ∥x∥ = (max ∥x.1∥ ∥x.2∥) := rfl lemma norm_fst_le (x : α × β) : ∥x.1∥ ≤ ∥x∥ := le_max_left _ _ lemma norm_snd_le (x : α × β) : ∥x.2∥ ≤ ∥x∥ := le_max_right _ _ lemma norm_prod_le_iff {x : α × β} {r : ℝ} : ∥x∥ ≤ r ↔ ∥x.1∥ ≤ r ∧ ∥x.2∥ ≤ r := max_le_iff /-- normed group instance on the product of finitely many normed groups, using the sup norm. -/ instance pi.normed_group {π : ι → Type*} [fintype ι] [∀i, normed_group (π i)] : normed_group (Πi, π i) := { norm := λf, ((finset.sup finset.univ (λ b, nnnorm (f b)) : nnreal) : ℝ), dist_eq := assume x y, congr_arg (coe : nnreal → ℝ) $ congr_arg (finset.sup finset.univ) $ funext $ assume a, show nndist (x a) (y a) = nnnorm (x a - y a), from nndist_eq_nnnorm _ _ } /-- The norm of an element in a product space is `≤ r` if and only if the norm of each component is. -/ lemma pi_norm_le_iff {π : ι → Type*} [fintype ι] [∀i, normed_group (π i)] {r : ℝ} (hr : 0 ≤ r) {x : Πi, π i} : ∥x∥ ≤ r ↔ ∀i, ∥x i∥ ≤ r := by { simp only [(dist_zero_right _).symm, dist_pi_le_iff hr], refl } lemma norm_le_pi_norm {π : ι → Type*} [fintype ι] [∀i, normed_group (π i)] (x : Πi, π i) (i : ι) : ∥x i∥ ≤ ∥x∥ := (pi_norm_le_iff (norm_nonneg x)).1 (le_refl _) i lemma tendsto_iff_norm_tendsto_zero {f : ι → β} {a : filter ι} {b : β} : tendsto f a (𝓝 b) ↔ tendsto (λ e, ∥ f e - b ∥) a (𝓝 0) := by rw tendsto_iff_dist_tendsto_zero ; simp only [(dist_eq_norm _ _).symm] lemma tendsto_zero_iff_norm_tendsto_zero {f : γ → β} {a : filter γ} : tendsto f a (𝓝 0) ↔ tendsto (λ e, ∥ f e ∥) a (𝓝 0) := have tendsto f a (𝓝 0) ↔ tendsto (λ e, ∥ f e - 0 ∥) a (𝓝 0) := tendsto_iff_norm_tendsto_zero, by simpa lemma lim_norm (x : α) : (λg:α, ∥g - x∥) →_{x} 0 := tendsto_iff_norm_tendsto_zero.1 (continuous_iff_continuous_at.1 continuous_id x) lemma lim_norm_zero : (λg:α, ∥g∥) →_{0} 0 := by simpa using lim_norm (0:α) lemma continuous_norm : continuous (λg:α, ∥g∥) := begin rw continuous_iff_continuous_at, intro x, rw [continuous_at, tendsto_iff_dist_tendsto_zero], exact squeeze_zero (λ t, abs_nonneg _) (λ t, abs_norm_sub_norm_le _ _) (lim_norm x) end lemma filter.tendsto.norm {β : Type*} {l : filter β} {f : β → α} {a : α} (h : tendsto f l (𝓝 a)) : tendsto (λ x, ∥f x∥) l (𝓝 ∥a∥) := tendsto.comp continuous_norm.continuous_at h lemma continuous_nnnorm : continuous (nnnorm : α → nnreal) := continuous_subtype_mk _ continuous_norm lemma filter.tendsto.nnnorm {β : Type*} {l : filter β} {f : β → α} {a : α} (h : tendsto f l (𝓝 a)) : tendsto (λ x, nnnorm (f x)) l (𝓝 (nnnorm a)) := tendsto.comp continuous_nnnorm.continuous_at h /-- If `∥y∥→∞`, then we can assume `y≠x` for any fixed `x`. -/ lemma eventually_ne_of_tendsto_norm_at_top {l : filter γ} {f : γ → α} (h : tendsto (λ y, ∥f y∥) l at_top) (x : α) : ∀ᶠ y in l, f y ≠ x := begin have : ∀ᶠ y in l, 1 + ∥x∥ ≤ ∥f y∥ := h (mem_at_top (1 + ∥x∥)), refine this.mono (λ y hy hxy, _), subst x, exact not_le_of_lt zero_lt_one (add_le_iff_nonpos_left.1 hy) end /-- A normed group is a uniform additive group, i.e., addition and subtraction are uniformly continuous. -/ @[priority 100] -- see Note [lower instance priority] instance normed_uniform_group : uniform_add_group α := begin refine ⟨metric.uniform_continuous_iff.2 $ assume ε hε, ⟨ε / 2, half_pos hε, assume a b h, _⟩⟩, rw [prod.dist_eq, max_lt_iff, dist_eq_norm, dist_eq_norm] at h, calc dist (a.1 - a.2) (b.1 - b.2) = ∥(a.1 - b.1) - (a.2 - b.2)∥ : by simp [dist_eq_norm, sub_eq_add_neg]; abel ... ≤ ∥a.1 - b.1∥ + ∥a.2 - b.2∥ : norm_sub_le _ _ ... < ε / 2 + ε / 2 : add_lt_add h.1 h.2 ... = ε : add_halves _ end @[priority 100] -- see Note [lower instance priority] instance normed_top_monoid : topological_add_monoid α := by apply_instance -- short-circuit type class inference @[priority 100] -- see Note [lower instance priority] instance normed_top_group : topological_add_group α := by apply_instance -- short-circuit type class inference end normed_group section normed_ring section prio set_option default_priority 100 -- see Note [default priority] /-- A normed ring is a ring endowed with a norm which satisfies the inequality `∥x y∥ ≤ ∥x∥ ∥y∥`. -/ class normed_ring (α : Type*) extends has_norm α, ring α, metric_space α := (dist_eq : ∀ x y, dist x y = norm (x - y)) (norm_mul : ∀ a b, norm (a * b) ≤ norm a * norm b) end prio @[priority 100] -- see Note [lower instance priority] instance normed_ring.to_normed_group [β : normed_ring α] : normed_group α := { ..β } lemma norm_mul_le {α : Type*} [normed_ring α] (a b : α) : (∥a*b∥) ≤ (∥a∥) * (∥b∥) := normed_ring.norm_mul _ _ lemma norm_pow_le {α : Type*} [normed_ring α] (a : α) : ∀ {n : ℕ}, 0 < n → ∥a^n∥ ≤ ∥a∥^n | 1 h := by simp | (n+2) h := le_trans (norm_mul_le a (a^(n+1))) (mul_le_mul (le_refl _) (norm_pow_le (nat.succ_pos _)) (norm_nonneg _) (norm_nonneg _)) /-- Normed ring structure on the product of two normed rings, using the sup norm. -/ instance prod.normed_ring [normed_ring α] [normed_ring β] : normed_ring (α × β) := { norm_mul := assume x y, calc ∥x * y∥ = ∥(x.1*y.1, x.2*y.2)∥ : rfl ... = (max ∥x.1*y.1∥ ∥x.2*y.2∥) : rfl ... ≤ (max (∥x.1∥*∥y.1∥) (∥x.2∥*∥y.2∥)) : max_le_max (norm_mul_le (x.1) (y.1)) (norm_mul_le (x.2) (y.2)) ... = (max (∥x.1∥*∥y.1∥) (∥y.2∥*∥x.2∥)) : by simp[mul_comm] ... ≤ (max (∥x.1∥) (∥x.2∥)) * (max (∥y.2∥) (∥y.1∥)) : by { apply max_mul_mul_le_max_mul_max; simp [norm_nonneg] } ... = (max (∥x.1∥) (∥x.2∥)) * (max (∥y.1∥) (∥y.2∥)) : by simp[max_comm] ... = (∥x∥*∥y∥) : rfl, ..prod.normed_group } end normed_ring @[priority 100] -- see Note [lower instance priority] instance normed_ring_top_monoid [normed_ring α] : topological_monoid α := ⟨ continuous_iff_continuous_at.2 $ λ x, tendsto_iff_norm_tendsto_zero.2 $ have ∀ e : α × α, e.fst * e.snd - x.fst * x.snd = e.fst * e.snd - e.fst * x.snd + (e.fst * x.snd - x.fst * x.snd), by intro; rw sub_add_sub_cancel, begin apply squeeze_zero, { intro, apply norm_nonneg }, { simp only [this], intro, apply norm_add_le }, { rw ←zero_add (0 : ℝ), apply tendsto.add, { apply squeeze_zero, { intro, apply norm_nonneg }, { intro t, show ∥t.fst * t.snd - t.fst * x.snd∥ ≤ ∥t.fst∥ * ∥t.snd - x.snd∥, rw ←mul_sub, apply norm_mul_le }, { rw ←mul_zero (∥x.fst∥), apply tendsto.mul, { apply continuous_iff_continuous_at.1, apply continuous_norm.comp continuous_fst }, { apply tendsto_iff_norm_tendsto_zero.1, apply continuous_iff_continuous_at.1, apply continuous_snd }}}, { apply squeeze_zero, { intro, apply norm_nonneg }, { intro t, show ∥t.fst * x.snd - x.fst * x.snd∥ ≤ ∥t.fst - x.fst∥ * ∥x.snd∥, rw ←sub_mul, apply norm_mul_le }, { rw ←zero_mul (∥x.snd∥), apply tendsto.mul, { apply tendsto_iff_norm_tendsto_zero.1, apply continuous_iff_continuous_at.1, apply continuous_fst }, { apply tendsto_const_nhds }}}} end ⟩ /-- A normed ring is a topological ring. -/ @[priority 100] -- see Note [lower instance priority] instance normed_top_ring [normed_ring α] : topological_ring α := ⟨ continuous_iff_continuous_at.2 $ λ x, tendsto_iff_norm_tendsto_zero.2 $ have ∀ e : α, -e - -x = -(e - x), by intro; simp, by simp only [this, norm_neg]; apply lim_norm ⟩ section prio set_option default_priority 100 -- see Note [default priority] /-- A normed field is a field with a norm satisfying ∥x y∥ = ∥x∥ ∥y∥. -/ class normed_field (α : Type*) extends has_norm α, field α, metric_space α := (dist_eq : ∀ x y, dist x y = norm (x - y)) (norm_mul' : ∀ a b, norm (a * b) = norm a * norm b) /-- A nondiscrete normed field is a normed field in which there is an element of norm different from `0` and `1`. This makes it possible to bring any element arbitrarily close to `0` by multiplication by the powers of any element, and thus to relate algebra and topology. -/ class nondiscrete_normed_field (α : Type*) extends normed_field α := (non_trivial : ∃x:α, 1<∥x∥) end prio @[priority 100] -- see Note [lower instance priority] instance normed_field.to_normed_ring [i : normed_field α] : normed_ring α := { norm_mul := by finish [i.norm_mul'], ..i } namespace normed_field @[simp] lemma norm_one {α : Type*} [normed_field α] : ∥(1 : α)∥ = 1 := have ∥(1 : α)∥ * ∥(1 : α)∥ = ∥(1 : α)∥ * 1, by calc ∥(1 : α)∥ * ∥(1 : α)∥ = ∥(1 : α) * (1 : α)∥ : by rw normed_field.norm_mul' ... = ∥(1 : α)∥ * 1 : by simp, eq_of_mul_eq_mul_left (ne_of_gt (norm_pos_iff.2 (by simp))) this @[simp] lemma norm_mul [normed_field α] (a b : α) : ∥a * b∥ = ∥a∥ * ∥b∥ := normed_field.norm_mul' a b instance normed_field.is_monoid_hom_norm [normed_field α] : is_monoid_hom (norm : α → ℝ) := { map_one := norm_one, map_mul := norm_mul } @[simp] lemma norm_pow [normed_field α] (a : α) : ∀ (n : ℕ), ∥a^n∥ = ∥a∥^n := is_monoid_hom.map_pow norm a @[simp] lemma norm_prod {β : Type*} [normed_field α] (s : finset β) (f : β → α) : ∥s.prod f∥ = s.prod (λb, ∥f b∥) := eq.symm (s.prod_hom norm) @[simp] lemma norm_div {α : Type*} [normed_field α] (a b : α) : ∥a/b∥ = ∥a∥/∥b∥ := begin classical, by_cases hb : b = 0, {simp [hb]}, apply eq_div_of_mul_eq, { apply ne_of_gt, apply norm_pos_iff.mpr hb }, { rw [←normed_field.norm_mul, div_mul_cancel _ hb] } end @[simp] lemma norm_inv {α : Type*} [normed_field α] (a : α) : ∥a⁻¹∥ = ∥a∥⁻¹ := by simp only [inv_eq_one_div, norm_div, norm_one] @[simp] lemma norm_fpow {α : Type*} [normed_field α] (a : α) : ∀n : ℤ, ∥a^n∥ = ∥a∥^n | (n : ℕ) := norm_pow a n | -[1+ n] := by simp [fpow_neg_succ_of_nat] lemma exists_one_lt_norm (α : Type*) [i : nondiscrete_normed_field α] : ∃x : α, 1 < ∥x∥ := i.non_trivial lemma exists_norm_lt_one (α : Type*) [nondiscrete_normed_field α] : ∃x : α, 0 < ∥x∥ ∧ ∥x∥ < 1 := begin rcases exists_one_lt_norm α with ⟨y, hy⟩, refine ⟨y⁻¹, _, _⟩, { simp only [inv_eq_zero, ne.def, norm_pos_iff], assume h, rw ← norm_eq_zero at h, rw h at hy, exact lt_irrefl _ (lt_trans zero_lt_one hy) }, { simp [inv_lt_one hy] } end lemma exists_lt_norm (α : Type*) [nondiscrete_normed_field α] (r : ℝ) : ∃ x : α, r < ∥x∥ := let ⟨w, hw⟩ := exists_one_lt_norm α in let ⟨n, hn⟩ := pow_unbounded_of_one_lt r hw in ⟨w^n, by rwa norm_pow⟩ lemma exists_norm_lt (α : Type*) [nondiscrete_normed_field α] {r : ℝ} (hr : 0 < r) : ∃ x : α, 0 < ∥x∥ ∧ ∥x∥ < r := let ⟨w, hw⟩ := exists_one_lt_norm α in let ⟨n, hle, hlt⟩ := exists_int_pow_near' hr hw in ⟨w^n, by { rw norm_fpow; exact fpow_pos_of_pos (lt_trans zero_lt_one hw) _}, by rwa norm_fpow⟩ lemma punctured_nhds_ne_bot {α : Type*} [nondiscrete_normed_field α] (x : α) : nhds_within x (-{x}) ≠ ⊥ := begin rw [← mem_closure_iff_nhds_within_ne_bot, metric.mem_closure_iff], rintros ε ε0, rcases normed_field.exists_norm_lt α ε0 with ⟨b, hb0, hbε⟩, refine ⟨x + b, mt (set.mem_singleton_iff.trans add_right_eq_self).1 $ norm_pos_iff.1 hb0, _⟩, rwa [dist_comm, dist_eq_norm, add_sub_cancel'], end lemma tendsto_inv [normed_field α] {r : α} (r0 : r ≠ 0) : tendsto (λq, q⁻¹) (𝓝 r) (𝓝 r⁻¹) := begin refine (nhds_basis_closed_ball.tendsto_iff nhds_basis_closed_ball).2 (λε εpos, _), let δ := min (ε/2 * ∥r∥^2) (∥r∥/2), have norm_r_pos : 0 < ∥r∥ := norm_pos_iff.mpr r0, have A : 0 < ε / 2 * ∥r∥ ^ 2 := mul_pos (half_pos εpos) (pow_pos norm_r_pos 2), have δpos : 0 < δ, by simp [half_pos norm_r_pos, A], refine ⟨δ, δpos, λ x hx, _⟩, have rx : ∥r∥/2 ≤ ∥x∥ := calc ∥r∥/2 = ∥r∥ - ∥r∥/2 : by ring ... ≤ ∥r∥ - ∥r - x∥ : begin apply sub_le_sub (le_refl _), rw [← dist_eq_norm, dist_comm], exact le_trans hx (min_le_right _ _) end ... ≤ ∥r - (r - x)∥ : norm_sub_norm_le r (r - x) ... = ∥x∥ : by simp [sub_sub_cancel], have norm_x_pos : 0 < ∥x∥ := lt_of_lt_of_le (half_pos norm_r_pos) rx, have : x⁻¹ - r⁻¹ = (r - x) * x⁻¹ * r⁻¹, by rw [sub_mul, sub_mul, mul_inv_cancel (norm_pos_iff.mp norm_x_pos), one_mul, mul_comm, ← mul_assoc, inv_mul_cancel r0, one_mul], calc dist x⁻¹ r⁻¹ = ∥x⁻¹ - r⁻¹∥ : dist_eq_norm _ _ ... ≤ ∥r-x∥ * ∥x∥⁻¹ * ∥r∥⁻¹ : by rw [this, norm_mul, norm_mul, norm_inv, norm_inv] ... ≤ (ε/2 * ∥r∥^2) * (2 * ∥r∥⁻¹) * (∥r∥⁻¹) : begin apply_rules [mul_le_mul, inv_nonneg.2, le_of_lt A, norm_nonneg, inv_nonneg.2, mul_nonneg, (inv_le_inv norm_x_pos norm_r_pos).2, le_refl], show ∥r - x∥ ≤ ε / 2 * ∥r∥ ^ 2, by { rw [← dist_eq_norm, dist_comm], exact le_trans hx (min_le_left _ _) }, show ∥x∥⁻¹ ≤ 2 * ∥r∥⁻¹, { convert (inv_le_inv norm_x_pos (half_pos norm_r_pos)).2 rx, rw [inv_div, div_eq_inv_mul, mul_comm] }, show (0 : ℝ) ≤ 2, by norm_num end ... = ε * (∥r∥ * ∥r∥⁻¹)^2 : by { generalize : ∥r∥⁻¹ = u, ring } ... = ε : by { rw [mul_inv_cancel (ne.symm (ne_of_lt norm_r_pos))], simp } end lemma continuous_on_inv [normed_field α] : continuous_on (λ(x:α), x⁻¹) {x | x ≠ 0} := begin assume x hx, apply continuous_at.continuous_within_at, exact (tendsto_inv hx) end instance : normed_field ℝ := { norm := λ x, abs x, dist_eq := assume x y, rfl, norm_mul' := abs_mul } instance : nondiscrete_normed_field ℝ := { non_trivial := ⟨2, by { unfold norm, rw abs_of_nonneg; norm_num }⟩ } end normed_field /-- If a function converges to a nonzero value, its inverse converges to the inverse of this value. We use the name `tendsto.inv'` as `tendsto.inv` is already used in multiplicative topological groups. -/ lemma filter.tendsto.inv' [normed_field α] {l : filter β} {f : β → α} {y : α} (hy : y ≠ 0) (h : tendsto f l (𝓝 y)) : tendsto (λx, (f x)⁻¹) l (𝓝 y⁻¹) := (normed_field.tendsto_inv hy).comp h lemma filter.tendsto.div [normed_field α] {l : filter β} {f g : β → α} {x y : α} (hf : tendsto f l (𝓝 x)) (hg : tendsto g l (𝓝 y)) (hy : y ≠ 0) : tendsto (λa, f a / g a) l (𝓝 (x / y)) := hf.mul (hg.inv' hy) lemma filter.tendsto.div_const [normed_field α] {l : filter β} {f : β → α} {x y : α} (hf : tendsto f l (𝓝 x)) : tendsto (λa, f a / y) l (𝓝 (x / y)) := by { simp only [div_eq_inv_mul], exact tendsto_const_nhds.mul hf } /-- Continuity at a point of the result of dividing two functions continuous at that point, where the denominator is nonzero. -/ lemma continuous_at.div [topological_space α] [normed_field β] {f : α → β} {g : α → β} {x : α} (hf : continuous_at f x) (hg : continuous_at g x) (hnz : g x ≠ 0) : continuous_at (λ x, f x / g x) x := hf.div hg hnz lemma real.norm_eq_abs (r : ℝ) : norm r = abs r := rfl @[simp] lemma real.norm_two : ∥(2:ℝ)∥ = 2 := abs_of_pos (@two_pos ℝ _) @[simp] lemma norm_norm [normed_group α] (x : α) : ∥∥x∥∥ = ∥x∥ := by rw [real.norm_eq_abs, abs_of_nonneg (norm_nonneg _)] @[simp] lemma nnnorm_norm [normed_group α] (a : α) : nnnorm ∥a∥ = nnnorm a := by simp only [nnnorm, norm_norm] instance : normed_ring ℤ := { norm := λ n, ∥(n : ℝ)∥, norm_mul := λ m n, le_of_eq $ by simp only [norm, int.cast_mul, abs_mul], dist_eq := λ m n, by simp only [int.dist_eq, norm, int.cast_sub] } @[norm_cast] lemma int.norm_cast_real (m : ℤ) : ∥(m : ℝ)∥ = ∥m∥ := rfl instance : normed_field ℚ := { norm := λ r, ∥(r : ℝ)∥, norm_mul' := λ r₁ r₂, by simp only [norm, rat.cast_mul, abs_mul], dist_eq := λ r₁ r₂, by simp only [rat.dist_eq, norm, rat.cast_sub] } instance : nondiscrete_normed_field ℚ := { non_trivial := ⟨2, by { unfold norm, rw abs_of_nonneg; norm_num }⟩ } @[norm_cast, simp] lemma rat.norm_cast_real (r : ℚ) : ∥(r : ℝ)∥ = ∥r∥ := rfl @[norm_cast, simp] lemma int.norm_cast_rat (m : ℤ) : ∥(m : ℚ)∥ = ∥m∥ := by rw [← rat.norm_cast_real, ← int.norm_cast_real]; congr' 1; norm_cast section normed_space section prio set_option default_priority 920 -- see Note [default priority]. Here, we set a rather high priority, -- to take precedence over `semiring.to_semimodule` as this leads to instance paths with better -- unification properties. -- see Note[vector space definition] for why we extend `semimodule`. /-- A normed space over a normed field is a vector space endowed with a norm which satisfies the equality `∥c • x∥ = ∥c∥ ∥x∥`. We require only `∥c • x∥ ≤ ∥c∥ ∥x∥` in the definition, then prove `∥c • x∥ = ∥c∥ ∥x∥` in `norm_smul`. -/ class normed_space (α : Type*) (β : Type*) [normed_field α] [normed_group β] extends semimodule α β := (norm_smul_le : ∀ (a:α) (b:β), ∥a • b∥ ≤ ∥a∥ * ∥b∥) end prio variables [normed_field α] [normed_group β] instance normed_field.to_normed_space : normed_space α α := { norm_smul_le := λ a b, le_of_eq (normed_field.norm_mul a b) } lemma norm_smul [normed_space α β] (s : α) (x : β) : ∥s • x∥ = ∥s∥ * ∥x∥ := begin classical, by_cases h : s = 0, { simp [h] }, { refine le_antisymm (normed_space.norm_smul_le s x) _, calc ∥s∥ * ∥x∥ = ∥s∥ * ∥s⁻¹ • s • x∥ : by rw [inv_smul_smul' h] ... ≤ ∥s∥ * (∥s⁻¹∥ * ∥s • x∥) : _ ... = ∥s • x∥ : _, exact mul_le_mul_of_nonneg_left (normed_space.norm_smul_le _ _) (norm_nonneg _), rw [normed_field.norm_inv, ← mul_assoc, mul_inv_cancel, one_mul], rwa [ne.def, norm_eq_zero] } end lemma dist_smul [normed_space α β] (s : α) (x y : β) : dist (s • x) (s • y) = ∥s∥ * dist x y := by simp only [dist_eq_norm, (norm_smul _ _).symm, smul_sub] lemma nnnorm_smul [normed_space α β] (s : α) (x : β) : nnnorm (s • x) = nnnorm s * nnnorm x := nnreal.eq $ norm_smul s x lemma nndist_smul [normed_space α β] (s : α) (x y : β) : nndist (s • x) (s • y) = nnnorm s * nndist x y := nnreal.eq $ dist_smul s x y variables {E : Type*} {F : Type*} [normed_group E] [normed_space α E] [normed_group F] [normed_space α F] @[priority 100] -- see Note [lower instance priority] instance normed_space.topological_vector_space : topological_vector_space α E := begin refine { continuous_smul := continuous_iff_continuous_at.2 $ λ p, tendsto_iff_norm_tendsto_zero.2 _ }, refine squeeze_zero (λ _, norm_nonneg _) _ _, { exact λ q, ∥q.1 - p.1∥ * ∥q.2∥ + ∥p.1∥ * ∥q.2 - p.2∥ }, { intro q, rw [← sub_add_sub_cancel, ← norm_smul, ← norm_smul, smul_sub, sub_smul], exact norm_add_le _ _ }, { conv { congr, skip, skip, congr, rw [← zero_add (0:ℝ)], congr, rw [← zero_mul ∥p.2∥], skip, rw [← mul_zero ∥p.1∥] }, exact ((tendsto_iff_norm_tendsto_zero.1 (continuous_fst.tendsto p)).mul (continuous_snd.tendsto p).norm).add (tendsto_const_nhds.mul (tendsto_iff_norm_tendsto_zero.1 (continuous_snd.tendsto p))) } end /-- In a normed space over a nondiscrete normed field, only `⊤` submodule has a nonempty interior. See also `submodule.eq_top_of_nonempty_interior'` for a `topological_module` version. -/ lemma submodule.eq_top_of_nonempty_interior {α E : Type*} [nondiscrete_normed_field α] [normed_group E] [normed_space α E] (s : submodule α E) (hs : (interior (s:set E)).nonempty) : s = ⊤ := begin refine s.eq_top_of_nonempty_interior' _ hs, simp only [is_unit_iff_ne_zero, @ne.def α, set.mem_singleton_iff.symm], exact normed_field.punctured_nhds_ne_bot _ end theorem closure_ball [normed_space ℝ E] (x : E) {r : ℝ} (hr : 0 < r) : closure (ball x r) = closed_ball x r := begin refine set.subset.antisymm closure_ball_subset_closed_ball (λ y hy, _), have : continuous_within_at (λ c : ℝ, c • (y - x) + x) (set.Ico 0 1) 1 := ((continuous_id.smul continuous_const).add continuous_const).continuous_within_at, convert this.mem_closure _ _, { rw [one_smul, sub_add_cancel] }, { simp [closure_Ico (@zero_lt_one ℝ _), zero_le_one] }, { rintros c ⟨hc0, hc1⟩, rw [set.mem_preimage, mem_ball, dist_eq_norm, add_sub_cancel, norm_smul, real.norm_eq_abs, abs_of_nonneg hc0, mul_comm, ← mul_one r], rw [mem_closed_ball, dist_eq_norm] at hy, apply mul_lt_mul'; assumption } end theorem frontier_ball [normed_space ℝ E] (x : E) {r : ℝ} (hr : 0 < r) : frontier (ball x r) = sphere x r := begin rw [frontier, closure_ball x hr, interior_eq_of_open is_open_ball], ext x, exact (@eq_iff_le_not_lt ℝ _ _ _).symm end theorem interior_closed_ball [normed_space ℝ E] (x : E) {r : ℝ} (hr : 0 < r) : interior (closed_ball x r) = ball x r := begin refine set.subset.antisymm _ ball_subset_interior_closed_ball, intros y hy, rcases le_iff_lt_or_eq.1 (mem_closed_ball.1 $ interior_subset hy) with hr|rfl, { exact hr }, set f : ℝ → E := λ c : ℝ, c • (y - x) + x, suffices : f ⁻¹' closed_ball x (dist y x) ⊆ set.Icc (-1) 1, { have hfc : continuous f := (continuous_id.smul continuous_const).add continuous_const, have hf1 : (1:ℝ) ∈ f ⁻¹' (interior (closed_ball x $ dist y x)), by simpa [f], have h1 : (1:ℝ) ∈ interior (set.Icc (-1:ℝ) 1) := interior_mono this (preimage_interior_subset_interior_preimage hfc hf1), contrapose h1, simp }, intros c hc, rw [set.mem_Icc, ← abs_le, ← real.norm_eq_abs, ← mul_le_mul_right hr], simpa [f, dist_eq_norm, norm_smul] using hc end theorem interior_closed_ball' [normed_space ℝ E] (x : E) (r : ℝ) (hE : ∃ z : E, z ≠ 0) : interior (closed_ball x r) = ball x r := begin rcases lt_trichotomy r 0 with hr|rfl|hr, { simp [closed_ball_eq_empty_iff_neg.2 hr, ball_eq_empty_iff_nonpos.2 (le_of_lt hr)] }, { suffices : x ∉ interior {x}, { rw [ball_zero, closed_ball_zero, ← set.subset_empty_iff], intros y hy, obtain rfl : y = x := set.mem_singleton_iff.1 (interior_subset hy), exact this hy }, rw [← set.mem_compl_iff, ← closure_compl], rcases hE with ⟨z, hz⟩, suffices : (λ c : ℝ, x + c • z) 0 ∈ closure (-{x} : set E), by simpa only [zero_smul, add_zero] using this, have : (0:ℝ) ∈ closure (set.Ioi (0:ℝ)), by simp [closure_Ioi], refine (continuous_const.add (continuous_id.smul continuous_const)).continuous_within_at.mem_closure this _, intros c hc, simp [smul_eq_zero, hz, ne_of_gt hc] }, { exact interior_closed_ball x hr } end theorem frontier_closed_ball [normed_space ℝ E] (x : E) {r : ℝ} (hr : 0 < r) : frontier (closed_ball x r) = sphere x r := by rw [frontier, closure_eq_of_is_closed is_closed_ball, interior_closed_ball x hr, closed_ball_diff_ball] theorem frontier_closed_ball' [normed_space ℝ E] (x : E) (r : ℝ) (hE : ∃ z : E, z ≠ 0) : frontier (closed_ball x r) = sphere x r := by rw [frontier, closure_eq_of_is_closed is_closed_ball, interior_closed_ball' x r hE, closed_ball_diff_ball] open normed_field /-- If there is a scalar `c` with `∥c∥>1`, then any element can be moved by scalar multiplication to any shell of width `∥c∥`. Also recap information on the norm of the rescaling element that shows up in applications. -/ lemma rescale_to_shell {c : α} (hc : 1 < ∥c∥) {ε : ℝ} (εpos : 0 < ε) {x : E} (hx : x ≠ 0) : ∃d:α, d ≠ 0 ∧ ∥d • x∥ ≤ ε ∧ (ε/∥c∥ ≤ ∥d • x∥) ∧ (∥d∥⁻¹ ≤ ε⁻¹ * ∥c∥ * ∥x∥) := begin have xεpos : 0 < ∥x∥/ε := div_pos_of_pos_of_pos (norm_pos_iff.2 hx) εpos, rcases exists_int_pow_near xεpos hc with ⟨n, hn⟩, have cpos : 0 < ∥c∥ := lt_trans (zero_lt_one : (0 :ℝ) < 1) hc, have cnpos : 0 < ∥c^(n+1)∥ := by { rw norm_fpow, exact lt_trans xεpos hn.2 }, refine ⟨(c^(n+1))⁻¹, _, _, _, _⟩, show (c ^ (n + 1))⁻¹ ≠ 0, by rwa [ne.def, inv_eq_zero, ← ne.def, ← norm_pos_iff], show ∥(c ^ (n + 1))⁻¹ • x∥ ≤ ε, { rw [norm_smul, norm_inv, ← div_eq_inv_mul, div_le_iff cnpos, mul_comm, norm_fpow], exact (div_le_iff εpos).1 (le_of_lt (hn.2)) }, show ε / ∥c∥ ≤ ∥(c ^ (n + 1))⁻¹ • x∥, { rw [div_le_iff cpos, norm_smul, norm_inv, norm_fpow, fpow_add (ne_of_gt cpos), fpow_one, mul_inv', mul_comm, ← mul_assoc, ← mul_assoc, mul_inv_cancel (ne_of_gt cpos), one_mul, ← div_eq_inv_mul, le_div_iff (fpow_pos_of_pos cpos _), mul_comm], exact (le_div_iff εpos).1 hn.1 }, show ∥(c ^ (n + 1))⁻¹∥⁻¹ ≤ ε⁻¹ * ∥c∥ * ∥x∥, { have : ε⁻¹ * ∥c∥ * ∥x∥ = ε⁻¹ * ∥x∥ * ∥c∥, by ring, rw [norm_inv, inv_inv', norm_fpow, fpow_add (ne_of_gt cpos), fpow_one, this, ← div_eq_inv_mul], exact mul_le_mul_of_nonneg_right hn.1 (norm_nonneg _) } end /-- The product of two normed spaces is a normed space, with the sup norm. -/ instance : normed_space α (E × F) := { norm_smul_le := λ s x, le_of_eq $ by simp [prod.norm_def, norm_smul, mul_max_of_nonneg], -- TODO: without the next two lines Lean unfolds `≤` to `real.le` add_smul := λ r x y, prod.ext (add_smul _ _ _) (add_smul _ _ _), smul_add := λ r x y, prod.ext (smul_add _ _ _) (smul_add _ _ _), ..prod.normed_group, ..prod.semimodule } /-- The product of finitely many normed spaces is a normed space, with the sup norm. -/ instance pi.normed_space {E : ι → Type*} [fintype ι] [∀i, normed_group (E i)] [∀i, normed_space α (E i)] : normed_space α (Πi, E i) := { norm_smul_le := λ a f, le_of_eq $ show (↑(finset.sup finset.univ (λ (b : ι), nnnorm (a • f b))) : ℝ) = nnnorm a * ↑(finset.sup finset.univ (λ (b : ι), nnnorm (f b))), by simp only [(nnreal.coe_mul _ _).symm, nnreal.mul_finset_sup, nnnorm_smul] } /-- A subspace of a normed space is also a normed space, with the restriction of the norm. -/ instance submodule.normed_space {𝕜 : Type*} [normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] (s : submodule 𝕜 E) : normed_space 𝕜 s := { norm_smul_le := λc x, le_of_eq $ norm_smul c (x : E) } end normed_space section normed_algebra section prio set_option default_priority 100 -- see Note [default priority] /-- A normed algebra `𝕜'` over `𝕜` is an algebra endowed with a norm for which the embedding of `𝕜` in `𝕜'` is an isometry. -/ class normed_algebra (𝕜 : Type*) (𝕜' : Type*) [normed_field 𝕜] [normed_ring 𝕜'] extends algebra 𝕜 𝕜' := (norm_algebra_map_eq : ∀x:𝕜, ∥algebra_map 𝕜 𝕜' x∥ = ∥x∥) end prio @[simp] lemma norm_algebra_map_eq {𝕜 : Type*} (𝕜' : Type*) [normed_field 𝕜] [normed_ring 𝕜'] [h : normed_algebra 𝕜 𝕜'] (x : 𝕜) : ∥algebra_map 𝕜 𝕜' x∥ = ∥x∥ := normed_algebra.norm_algebra_map_eq _ @[priority 100] instance to_normed_space (𝕜 : Type*) (𝕜' : Type*) [normed_field 𝕜] [normed_ring 𝕜'] [h : normed_algebra 𝕜 𝕜'] : normed_space 𝕜 𝕜' := { norm_smul_le := λ s x, calc ∥s • x∥ = ∥((algebra_map 𝕜 𝕜') s) * x∥ : by { rw h.smul_def', refl } ... ≤ ∥algebra_map 𝕜 𝕜' s∥ * ∥x∥ : normed_ring.norm_mul _ _ ... = ∥s∥ * ∥x∥ : by rw norm_algebra_map_eq, ..h } end normed_algebra section restrict_scalars variables (𝕜 : Type*) (𝕜' : Type*) [normed_field 𝕜] [normed_field 𝕜'] [normed_algebra 𝕜 𝕜'] {E : Type*} [normed_group E] [normed_space 𝕜' E] /-- `𝕜`-normed space structure induced by a `𝕜'`-normed space structure when `𝕜'` is a normed algebra over `𝕜`. Not registered as an instance as `𝕜'` can not be inferred. -/ -- We could add a type synonym equipped with this as an instance, -- as we've done for `module.restrict_scalars`. def normed_space.restrict_scalars : normed_space 𝕜 E := { norm_smul_le := λc x, le_of_eq $ begin change ∥(algebra_map 𝕜 𝕜' c) • x∥ = ∥c∥ * ∥x∥, simp [norm_smul] end, ..module.restrict_scalars' 𝕜 𝕜' E } end restrict_scalars section summable open_locale classical open finset filter variables [normed_group α] @[nolint ge_or_gt] -- see Note [nolint_ge] lemma cauchy_seq_finset_iff_vanishing_norm {f : ι → α} : cauchy_seq (λ s : finset ι, s.sum f) ↔ ∀ε > 0, ∃s:finset ι, ∀t, disjoint t s → ∥ t.sum f ∥ < ε := begin simp only [cauchy_seq_finset_iff_vanishing, metric.mem_nhds_iff, exists_imp_distrib], split, { assume h ε hε, refine h {x | ∥x∥ < ε} ε hε _, rw [ball_0_eq ε] }, { assume h s ε hε hs, rcases h ε hε with ⟨t, ht⟩, refine ⟨t, assume u hu, hs _⟩, rw [ball_0_eq], exact ht u hu } end @[nolint ge_or_gt] -- see Note [nolint_ge] lemma summable_iff_vanishing_norm [complete_space α] {f : ι → α} : summable f ↔ ∀ε > 0, ∃s:finset ι, ∀t, disjoint t s → ∥ t.sum f ∥ < ε := by rw [summable_iff_cauchy_seq_finset, cauchy_seq_finset_iff_vanishing_norm] lemma cauchy_seq_finset_of_norm_bounded {f : ι → α} (g : ι → ℝ) (hg : summable g) (h : ∀i, ∥f i∥ ≤ g i) : cauchy_seq (λ s : finset ι, s.sum f) := cauchy_seq_finset_iff_vanishing_norm.2 $ assume ε hε, let ⟨s, hs⟩ := summable_iff_vanishing_norm.1 hg ε hε in ⟨s, assume t ht, have ∥t.sum g∥ < ε := hs t ht, have nn : 0 ≤ t.sum g := finset.sum_nonneg (assume a _, le_trans (norm_nonneg _) (h a)), lt_of_le_of_lt (norm_sum_le_of_le t (λ i _, h i)) $ by rwa [real.norm_eq_abs, abs_of_nonneg nn] at this⟩ lemma cauchy_seq_finset_of_summable_norm {f : ι → α} (hf : summable (λa, ∥f a∥)) : cauchy_seq (λ s : finset ι, s.sum f) := cauchy_seq_finset_of_norm_bounded _ hf (assume i, le_refl _) /-- If a function `f` is summable in norm, and along some sequence of finsets exhausting the space its sum is converging to a limit `a`, then this holds along all finsets, i.e., `f` is summable with sum `a`. -/ lemma has_sum_of_subseq_of_summable {f : ι → α} (hf : summable (λa, ∥f a∥)) {s : β → finset ι} {p : filter β} (hp : p ≠ ⊥) (hs : tendsto s p at_top) {a : α} (ha : tendsto (λ b, ∑ i in s b, f i) p (𝓝 a)) : has_sum f a := tendsto_nhds_of_cauchy_seq_of_subseq (cauchy_seq_finset_of_summable_norm hf) hp hs ha /-- If `∑' i, ∥f i∥` is summable, then `∥(∑' i, f i)∥ ≤ (∑' i, ∥f i∥)`. Note that we do not assume that `∑' i, f i` is summable, and it might not be the case if `α` is not a complete space. -/ lemma norm_tsum_le_tsum_norm {f : ι → α} (hf : summable (λi, ∥f i∥)) : ∥(∑'i, f i)∥ ≤ (∑' i, ∥f i∥) := begin by_cases h : summable f, { have h₁ : tendsto (λs:finset ι, ∥s.sum f∥) at_top (𝓝 ∥(∑' i, f i)∥) := (continuous_norm.tendsto _).comp h.has_sum, have h₂ : tendsto (λs:finset ι, s.sum (λi, ∥f i∥)) at_top (𝓝 (∑' i, ∥f i∥)) := hf.has_sum, exact le_of_tendsto_of_tendsto' at_top_ne_bot h₁ h₂ (assume s, norm_sum_le _ _) }, { rw tsum_eq_zero_of_not_summable h, simp [tsum_nonneg] } end lemma has_sum_iff_tendsto_nat_of_summable_norm {f : ℕ → α} {a : α} (hf : summable (λi, ∥f i∥)) : has_sum f a ↔ tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) := ⟨λ h, h.tendsto_sum_nat, λ h, has_sum_of_subseq_of_summable hf at_top_ne_bot tendsto_finset_range h⟩ variable [complete_space α] lemma summable_of_norm_bounded {f : ι → α} (g : ι → ℝ) (hg : summable g) (h : ∀i, ∥f i∥ ≤ g i) : summable f := by { rw summable_iff_cauchy_seq_finset, exact cauchy_seq_finset_of_norm_bounded g hg h } lemma summable_of_nnnorm_bounded {f : ι → α} (g : ι → nnreal) (hg : summable g) (h : ∀i, nnnorm (f i) ≤ g i) : summable f := summable_of_norm_bounded (λ i, (g i : ℝ)) (nnreal.summable_coe.2 hg) (λ i, by exact_mod_cast h i) lemma summable_of_summable_norm {f : ι → α} (hf : summable (λa, ∥f a∥)) : summable f := summable_of_norm_bounded _ hf (assume i, le_refl _) lemma summable_of_summable_nnnorm {f : ι → α} (hf : summable (λa, nnnorm (f a))) : summable f := summable_of_nnnorm_bounded _ hf (assume i, le_refl _) end summable
01df073e5c099df2322666deab1acb4d6f6eead9
4fa161becb8ce7378a709f5992a594764699e268
/src/category_theory/limits/shapes/regular_mono.lean
f200db75a0465f041a3ae1950a1f6b358b5f5a75
[ "Apache-2.0" ]
permissive
laughinggas/mathlib
e4aa4565ae34e46e834434284cb26bd9d67bc373
86dcd5cda7a5017c8b3c8876c89a510a19d49aad
refs/heads/master
1,669,496,232,688
1,592,831,995,000
1,592,831,995,000
274,155,979
0
0
Apache-2.0
1,592,835,190,000
1,592,835,189,000
null
UTF-8
Lean
false
false
6,557
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.limits.shapes.kernels import category_theory.limits.shapes.strong_epi /-! # Definitions and basic properties of regular and normal monomorphisms and epimorphisms. A regular monomorphism is a morphism that is the equalizer of some parallel pair. A normal monomorphism is a morphism that is the kernel of some other morphism. We give the constructions * `split_mono → regular_mono` * `normal_mono → regular_mono`, and * `regular_mono → mono` as well as the dual constructions for regular and normal epimorphisms. Additionally, we give the construction * `regular_epi ⟶ strong_epi`. -/ namespace category_theory open category_theory.limits universes v₁ u₁ variables {C : Type u₁} [category.{v₁} C] variables {X Y : C} /-- A regular monomorphism is a morphism which is the equalizer of some parallel pair. -/ class regular_mono (f : X ⟶ Y) := (Z : C) (left right : Y ⟶ Z) (w : f ≫ left = f ≫ right) (is_limit : is_limit (fork.of_ι f w)) attribute [reassoc] regular_mono.w /-- Every regular monomorphism is a monomorphism. -/ @[priority 100] instance regular_mono.mono (f : X ⟶ Y) [regular_mono f] : mono f := mono_of_is_limit_parallel_pair regular_mono.is_limit instance equalizer_regular (g h : X ⟶ Y) [has_limit (parallel_pair g h)] : regular_mono (equalizer.ι g h) := { Z := Y, left := g, right := h, w := equalizer.condition g h, is_limit := fork.is_limit.mk _ (λ s, limit.lift _ s) (by simp) (λ s m w, by { ext1, simp [←w] }) } /-- Every split monomorphism is a regular monomorphism. -/ @[priority 100] instance regular_mono.of_split_mono (f : X ⟶ Y) [split_mono f] : regular_mono f := { Z := Y, left := 𝟙 Y, right := retraction f ≫ f, w := by tidy, is_limit := split_mono_equalizes f } /-- If `f` is a regular mono, then any map `k : W ⟶ Y` equalizing `regular_mono.left` and `regular_mono.right` induces a morphism `l : W ⟶ X` such that `l ≫ f = k`. -/ def regular_mono.lift' {W : C} (f : X ⟶ Y) [regular_mono f] (k : W ⟶ Y) (h : k ≫ (regular_mono.left : Y ⟶ @regular_mono.Z _ _ _ _ f _) = k ≫ regular_mono.right) : {l : W ⟶ X // l ≫ f = k} := fork.is_limit.lift' regular_mono.is_limit _ h /-- A regular monomorphism is an isomorphism if it is an epimorphism. -/ def is_iso_of_regular_mono_of_epi (f : X ⟶ Y) [regular_mono f] [e : epi f] : is_iso f := @is_iso_limit_cone_parallel_pair_of_epi _ _ _ _ _ _ _ regular_mono.is_limit e section variables [has_zero_morphisms.{v₁} C] /-- A normal monomorphism is a morphism which is the kernel of some morphism. -/ class normal_mono (f : X ⟶ Y) := (Z : C) (g : Y ⟶ Z) (w : f ≫ g = 0) (is_limit : is_limit (kernel_fork.of_ι f w)) /-- Every normal monomorphism is a regular monomorphism. -/ @[priority 100] instance normal_mono.regular_mono (f : X ⟶ Y) [I : normal_mono f] : regular_mono f := { left := I.g, right := 0, w := (by simpa using I.w), ..I } /-- If `f` is a normal mono, then any map `k : W ⟶ Y` such that `k ≫ normal_mono.g = 0` induces a morphism `l : W ⟶ X` such that `l ≫ f = k`. -/ def normal_mono.lift' {W : C} (f : X ⟶ Y) [normal_mono f] (k : W ⟶ Y) (h : k ≫ normal_mono.g = 0) : {l : W ⟶ X // l ≫ f = k} := kernel_fork.is_limit.lift' normal_mono.is_limit _ h end /-- A regular epimorphism is a morphism which is the coequalizer of some parallel pair. -/ class regular_epi (f : X ⟶ Y) := (W : C) (left right : W ⟶ X) (w : left ≫ f = right ≫ f) (is_colimit : is_colimit (cofork.of_π f w)) attribute [reassoc] regular_epi.w /-- Every regular epimorphism is an epimorphism. -/ @[priority 100] instance regular_epi.epi (f : X ⟶ Y) [regular_epi f] : epi f := epi_of_is_colimit_parallel_pair regular_epi.is_colimit instance coequalizer_regular (g h : X ⟶ Y) [has_colimit (parallel_pair g h)] : regular_epi (coequalizer.π g h) := { W := X, left := g, right := h, w := coequalizer.condition g h, is_colimit := cofork.is_colimit.mk _ (λ s, colimit.desc _ s) (by simp) (λ s m w, by { ext1, simp [←w] }) } /-- Every split epimorphism is a regular epimorphism. -/ @[priority 100] instance regular_epi.of_split_epi (f : X ⟶ Y) [split_epi f] : regular_epi f := { W := X, left := 𝟙 X, right := f ≫ section_ f, w := by tidy, is_colimit := split_epi_coequalizes f } /-- If `f` is a regular epi, then every morphism `k : X ⟶ W` coequalizing `regular_epi.left` and `regular_epi.right` induces `l : Y ⟶ W` such that `f ≫ l = k`. -/ def regular_epi.desc' {W : C} (f : X ⟶ Y) [regular_epi f] (k : X ⟶ W) (h : (regular_epi.left : regular_epi.W f ⟶ X) ≫ k = regular_epi.right ≫ k) : {l : Y ⟶ W // f ≫ l = k} := cofork.is_colimit.desc' (regular_epi.is_colimit) _ h /-- A regular epimorphism is an isomorphism if it is a monomorphism. -/ def is_iso_of_regular_epi_of_mono (f : X ⟶ Y) [regular_epi f] [m : mono f] : is_iso f := @is_iso_limit_cocone_parallel_pair_of_epi _ _ _ _ _ _ _ regular_epi.is_colimit m @[priority 100] instance strong_epi_of_regular_epi (f : X ⟶ Y) [regular_epi f] : strong_epi f := { epi := by apply_instance, has_lift := begin introsI, have : (regular_epi.left : regular_epi.W f ⟶ X) ≫ u = regular_epi.right ≫ u, { apply (cancel_mono z).1, simp only [category.assoc, h, regular_epi.w_assoc] }, obtain ⟨t, ht⟩ := regular_epi.desc' f u this, exact ⟨t, ht, (cancel_epi f).1 (by simp only [←category.assoc, ht, ←h, arrow.mk_hom, arrow.hom_mk'_right])⟩, end } section variables [has_zero_morphisms.{v₁} C] /-- A normal epimorphism is a morphism which is the cokernel of some morphism. -/ class normal_epi (f : X ⟶ Y) := (W : C) (g : W ⟶ X) (w : g ≫ f = 0) (is_colimit : is_colimit (cokernel_cofork.of_π f w)) /-- Every normal epimorphism is a regular epimorphism. -/ @[priority 100] instance normal_epi.regular_epi (f : X ⟶ Y) [I : normal_epi f] : regular_epi f := { left := I.g, right := 0, w := (by simpa using I.w), ..I } /-- If `f` is a normal epi, then every morphism `k : X ⟶ W` satisfying `normal_epi.g ≫ k = 0` induces `l : Y ⟶ W` such that `f ≫ l = k`. -/ def normal_epi.desc' {W : C} (f : X ⟶ Y) [normal_epi f] (k : X ⟶ W) (h : normal_epi.g ≫ k = 0) : {l : Y ⟶ W // f ≫ l = k} := cokernel_cofork.is_colimit.desc' (normal_epi.is_colimit) _ h end end category_theory
1ba53c5f64bd208eaaa92ce2c886e0f4fec21d6c
7cef822f3b952965621309e88eadf618da0c8ae9
/src/tactic/rewrite_all/basic.lean
f054942d78f672c5af320de392c625088255c9d1
[ "Apache-2.0" ]
permissive
rmitta/mathlib
8d90aee30b4db2b013e01f62c33f297d7e64a43d
883d974b608845bad30ae19e27e33c285200bf84
refs/heads/master
1,585,776,832,544
1,576,874,096,000
1,576,874,096,000
153,663,165
0
2
Apache-2.0
1,544,806,490,000
1,539,884,365,000
Lean
UTF-8
Lean
false
false
1,931
lean
/- Copyright (c) 2018 Keeley Hoek. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Keeley Hoek, Scott Morrison -/ import data.option.defs data.mllist open tactic @[derive decidable_eq] inductive side | L | R def side.other : side → side | side.L := side.R | side.R := side.L def side.to_string : side → string | side.L := "L" | side.R := "R" instance : has_to_string side := ⟨side.to_string⟩ namespace tactic.rewrite_all meta structure cfg extends rewrite_cfg := (try_simp : bool := ff) (discharger : tactic unit := skip) -- Warning: rewrite_search can't produce tactic scripts when the simplifier is used. (simplifier : expr → tactic (expr × expr) := λ e, failed) meta structure tracked_rewrite := (exp : expr) (proof : tactic expr) -- If `addr` is not provided by the underlying implementation of `rewrite_all` (i.e. kabstract) -- `rewrite_search` will not be able to produce tactic scripts. (addr : option (list side)) namespace tracked_rewrite meta def eval (rw : tracked_rewrite) : tactic (expr × expr) := do prf ← rw.proof, return (rw.exp, prf) meta def replace_target (rw : tracked_rewrite) : tactic unit := do (exp, prf) ← rw.eval, tactic.replace_target exp prf private meta def replace_target_side (new_target lam : pexpr) (prf : expr) : tactic unit := do new_target ← to_expr new_target tt ff, prf' ← to_expr ``(congr_arg %%lam %%prf) tt ff, tactic.replace_target new_target prf' meta def replace_target_lhs (rw : tracked_rewrite) : tactic unit := do (new_lhs, prf) ← rw.eval, `(%%_ = %%rhs) ← target, replace_target_side ``(%%new_lhs = %%rhs) ``(λ L, L = %%rhs) prf meta def replace_target_rhs (rw : tracked_rewrite) : tactic unit := do (new_rhs, prf) ← rw.eval, `(%%lhs = %%_) ← target, replace_target_side ``(%%lhs = %%new_rhs) ``(λ R, %%lhs = R) prf end tracked_rewrite end tactic.rewrite_all
0abf989770f204aee769871622961e49964fe232
491068d2ad28831e7dade8d6dff871c3e49d9431
/tests/lean/run/notation_priority.lean
9ffaa104dc953deb192500eccb73d481e35c6181
[ "Apache-2.0" ]
permissive
davidmueller13/lean
65a3ed141b4088cd0a268e4de80eb6778b21a0e9
c626e2e3c6f3771e07c32e82ee5b9e030de5b050
refs/heads/master
1,611,278,313,401
1,444,021,177,000
1,444,021,177,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
597
lean
constant f : nat → nat → nat constant g : nat → nat → nat infix [priority 10] + := f infix [priority 20] + := g variables a b : nat example : a + b = g a b := rfl infix [priority 5] + := g example : a + b = f a b := rfl infix [priority 15] + := g example : a + b = g a b := rfl infix [priority std.priority.default+1] + := f infix + := g example : a + b = f a b := rfl infix [priority std.priority.default+2] + := g example : a + b = g a b := rfl infix + := f infix + := g example : a + b = f a b := rfl infix [priority std.priority.default+1] + := g example : a + b = g a b := rfl
7336114f408d4b536ae83f9d6ce3f054208953e3
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/data/polynomial/identities.lean
642cf06533b7d4b7817297b50177cd73aa57af42
[ "Apache-2.0" ]
permissive
alreadydone/mathlib
dc0be621c6c8208c581f5170a8216c5ba6721927
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
refs/heads/master
1,685,523,275,196
1,670,184,141,000
1,670,184,141,000
287,574,545
0
0
Apache-2.0
1,670,290,714,000
1,597,421,623,000
Lean
UTF-8
Lean
false
false
3,647
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import data.polynomial.derivative import tactic.linear_combination import tactic.ring_exp /-! # Theory of univariate polynomials The main def is `binom_expansion`. -/ noncomputable theory namespace polynomial open_locale polynomial universes u v w x y z variables {R : Type u} {S : Type v} {T : Type w} {ι : Type x} {k : Type y} {A : Type z} {a b : R} {m n : ℕ} section identities /- @TODO: pow_add_expansion and pow_sub_pow_factor are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use data.nat.choose to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def pow_add_expansion {R : Type*} [comm_semiring R] (x y : R) : ∀ (n : ℕ), {k // (x + y)^n = x^n + n*x^(n-1)*y + k * y^2} | 0 := ⟨0, by simp⟩ | 1 := ⟨0, by simp⟩ | (n+2) := begin cases pow_add_expansion (n+1) with z hz, existsi x*z + (n+1)*x^n+z*y, calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) : by ring_exp ... = (x + y) * (x ^ (n + 1) + ↑(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) : by rw hz ... = x ^ (n + 2) + ↑(n + 2) * x ^ (n + 1) * y + (x*z + (n+1)*x^n+z*y) * y ^ 2 : by { push_cast, ring_exp! } end variables [comm_ring R] private def poly_binom_aux1 (x y : R) (e : ℕ) (a : R) : {k : R // a * (x + y)^e = a * (x^e + e*x^(e-1)*y + k*y^2)} := begin existsi (pow_add_expansion x y e).val, congr, apply (pow_add_expansion _ _ _).property end private lemma poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum (λ e a, a * (x^e + e*x^(e-1)*y + (poly_binom_aux1 x y e a).val*y^2)) := begin unfold eval eval₂, congr' with n z, apply (poly_binom_aux1 x y _ _).property end private lemma poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum (λ e a, a * x^e) + f.sum (λ e a, (a * e * x^(e-1)) * y) + f.sum (λ e a, (a *(poly_binom_aux1 x y e a).val)*y^2) := by { rw poly_binom_aux2, simp [left_distrib, sum_add, mul_assoc] } /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binom_expansion (f : R[X]) (x y : R) : {k : R // f.eval (x + y) = f.eval x + (f.derivative.eval x) * y + k * y^2} := begin existsi f.sum (λ e a, a *((poly_binom_aux1 x y e a).val)), rw poly_binom_aux3, congr, { rw [←eval_eq_sum], }, { rw derivative_eval, exact finset.sum_mul.symm }, { exact finset.sum_mul.symm } end /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def pow_sub_pow_factor (x y : R) : Π (i : ℕ), {z : R // x^i - y^i = z * (x - y)} | 0 := ⟨0, by simp⟩ | 1 := ⟨1, by simp⟩ | (k+2) := begin cases @pow_sub_pow_factor (k+1) with z hz, existsi z*x + y^(k+1), linear_combination x * hz with { normalization_tactic := `[ring_exp] } end /-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def eval_sub_factor (f : R[X]) (x y : R) : {z : R // f.eval x - f.eval y = z * (x - y)} := begin refine ⟨f.sum (λ i r, r * (pow_sub_pow_factor x y i).val), _⟩, delta eval eval₂, simp only [sum, ← finset.sum_sub_distrib, finset.sum_mul], dsimp, congr' with i r, rw [mul_assoc, ←(pow_sub_pow_factor x y _).prop, mul_sub], end end identities end polynomial
b7018a37f6d32b6bc5b34aaab50c12ae4a4debef
618003631150032a5676f229d13a079ac875ff77
/src/linear_algebra/dual.lean
5c54bd969f89f84ce40a2af70db15a0d403d0382
[ "Apache-2.0" ]
permissive
awainverse/mathlib
939b68c8486df66cfda64d327ad3d9165248c777
ea76bd8f3ca0a8bf0a166a06a475b10663dec44a
refs/heads/master
1,659,592,962,036
1,590,987,592,000
1,590,987,592,000
268,436,019
1
0
Apache-2.0
1,590,990,500,000
1,590,990,500,000
null
UTF-8
Lean
false
false
10,102
lean
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Fabian Glöckle -/ import linear_algebra.finite_dimensional import tactic.apply_fun noncomputable theory /-! # Dual vector spaces The dual space of an R-module M is the R-module of linear maps `M → R`. ## Main definitions * `dual R M` defines the dual space of M over R. * Given a basis for a K-vector space `V`, `is_basis.to_dual` produces a map from `V` to `dual K V`. * Given families of vectors `e` and `ε`, `dual_pair e ε` states that these families have the characteristic properties of a basis and a dual. ## Main results * `to_dual_equiv` : the dual space is linearly equivalent to the primal space. * `dual_pair.is_basis` and `dual_pair.eq_dual`: if `e` and `ε` form a dual pair, `e` is a basis and `ε` is its dual basis. ## Notation We sometimes use `V'` as local notation for `dual K V`. -/ namespace module variables (R : Type*) (M : Type*) variables [comm_ring R] [add_comm_group M] [module R M] /-- The dual space of an R-module M is the R-module of linear maps `M → R`. -/ @[derive [add_comm_group, module R]] def dual := M →ₗ[R] R namespace dual instance : inhabited (dual R M) := by dunfold dual; apply_instance instance : has_coe_to_fun (dual R M) := ⟨_, linear_map.to_fun⟩ /-- Maps a module M to the dual of the dual of M. See `vector_space.eval_range` and `vector_space.eval_equiv`. -/ def eval : M →ₗ[R] (dual R (dual R M)) := linear_map.flip linear_map.id lemma eval_apply (v : M) (a : dual R M) : (eval R M v) a = a v := begin dunfold eval, rw [linear_map.flip_apply, linear_map.id_apply] end end dual end module namespace is_basis universes u v w variables {K : Type u} {V : Type v} {ι : Type w} variables [field K] [add_comm_group V] [vector_space K V] open vector_space module module.dual submodule linear_map cardinal function variables [de : decidable_eq ι] variables {B : ι → V} (h : is_basis K B) include de h /-- The linear map from a vector space equipped with basis to its dual vector space, taking basis elements to corresponding dual basis elements. -/ def to_dual : V →ₗ[K] module.dual K V := h.constr $ λ v, h.constr $ λ w, if w = v then 1 else 0 lemma to_dual_apply (i j : ι) : (h.to_dual (B i)) (B j) = if i = j then 1 else 0 := by erw [constr_basis h, constr_basis h]; ac_refl def to_dual_flip (v : V) : (V →ₗ[K] K) := (linear_map.flip h.to_dual).to_fun v omit de h /-- Evaluation of finitely supported functions at a fixed point `i`, as a `K`-linear map. -/ def eval_finsupp_at (i : ι) : (ι →₀ K) →ₗ[K] K := { to_fun := λ f, f i, add := by intros; rw finsupp.add_apply, smul := by intros; rw finsupp.smul_apply } include h def coord_fun (i : ι) : (V →ₗ[K] K) := linear_map.comp (eval_finsupp_at i) h.repr lemma coord_fun_eq_repr (v : V) (i : ι) : h.coord_fun i v = h.repr v i := rfl include de lemma to_dual_swap_eq_to_dual (v w : V) : h.to_dual_flip v w = h.to_dual w v := rfl lemma to_dual_eq_repr (v : V) (i : ι) : (h.to_dual v) (B i) = h.repr v i := begin rw [←coord_fun_eq_repr, ←to_dual_swap_eq_to_dual], apply congr_fun, dsimp, congr', apply h.ext, { intros, rw [to_dual_swap_eq_to_dual, to_dual_apply], { split_ifs with hx, { rwa [hx, coord_fun_eq_repr, repr_eq_single, finsupp.single_apply, if_pos rfl] }, { rw [coord_fun_eq_repr, repr_eq_single, finsupp.single_apply], symmetry, convert if_neg hx } } } end lemma to_dual_inj (v : V) (a : h.to_dual v = 0) : v = 0 := begin rw [← mem_bot K, ← h.repr_ker, mem_ker], apply finsupp.ext, intro b, rw [←to_dual_eq_repr _ _ _, a], refl end theorem to_dual_ker : h.to_dual.ker = ⊥ := ker_eq_bot'.mpr h.to_dual_inj theorem to_dual_range [fin : fintype ι] : h.to_dual.range = ⊤ := begin rw eq_top_iff', intro f, rw linear_map.mem_range, let lin_comb : ι →₀ K := finsupp.on_finset fin.elems (λ i, f.to_fun (B i)) _, { use finsupp.total ι V K B lin_comb, apply h.ext, { intros i, rw [h.to_dual_eq_repr _ i, repr_total h], { refl }, { rw [finsupp.mem_supported], exact λ _ _, set.mem_univ _ } } }, { intros a _, apply fin.complete } end /-- Maps a basis for `V` to a basis for the dual space. -/ def dual_basis : ι → dual K V := λ i, h.to_dual (B i) theorem dual_lin_independent : linear_independent K h.dual_basis := begin apply linear_independent.image h.1, rw to_dual_ker, exact disjoint_bot_right end /-- A vector space is linearly equivalent to its dual space. -/ def to_dual_equiv [fintype ι] : V ≃ₗ[K] (dual K V) := linear_equiv.of_bijective h.to_dual h.to_dual_ker h.to_dual_range theorem dual_basis_is_basis [fintype ι] : is_basis K h.dual_basis := h.to_dual_equiv.is_basis h @[simp] lemma to_dual_to_dual [fintype ι] : (h.dual_basis_is_basis.to_dual).comp h.to_dual = eval K V := begin refine h.ext (λ i, h.dual_basis_is_basis.ext (λ j, _)), dunfold eval, rw [linear_map.flip_apply, linear_map.id_apply, linear_map.comp_apply], apply eq.trans (to_dual_apply h.dual_basis_is_basis i j), { dunfold dual_basis, rw to_dual_apply, by_cases h : i = j, { rw [if_pos h, if_pos h.symm] }, { rw [if_neg h, if_neg (ne.symm h)] } } end omit de theorem dual_dim_eq [fintype ι] : cardinal.lift.{v u} (dim K V) = dim K (dual K V) := begin classical, have := linear_equiv.dim_eq_lift h.to_dual_equiv, simp only [cardinal.lift_umax] at this, rw [this, ← cardinal.lift_umax], apply cardinal.lift_id, end end is_basis namespace vector_space universes u v variables {K : Type u} {V : Type v} variables [field K] [add_comm_group V] [vector_space K V] open module module.dual submodule linear_map cardinal is_basis theorem eval_ker : (eval K V).ker = ⊥ := begin classical, rw ker_eq_bot', intros v h, rw linear_map.ext_iff at h, by_contradiction H, rcases exists_subset_is_basis (linear_independent_singleton H) with ⟨b, hv, hb⟩, swap 4, assumption, have hv' : v = (coe : b → V) ⟨v, hv (set.mem_singleton v)⟩ := rfl, let hx := h (hb.to_dual v), rw [eval_apply, hv', to_dual_apply, if_pos rfl, zero_apply] at hx, exact one_ne_zero hx end theorem dual_dim_eq (h : dim K V < omega) : cardinal.lift.{v u} (dim K V) = dim K (dual K V) := begin classical, rcases exists_is_basis_fintype h with ⟨b, hb, ⟨hf⟩⟩, resetI, exact hb.dual_dim_eq end lemma eval_range (h : dim K V < omega) : (eval K V).range = ⊤ := begin classical, rcases exists_is_basis_fintype h with ⟨b, hb, ⟨hf⟩⟩, rw [← hb.to_dual_to_dual, range_comp, hb.to_dual_range, map_top, to_dual_range _], apply_instance end /-- A vector space is linearly equivalent to the dual of its dual space. -/ def eval_equiv (h : dim K V < omega) : V ≃ₗ[K] dual K (dual K V) := linear_equiv.of_bijective (eval K V) eval_ker (eval_range h) end vector_space section dual_pair open vector_space module module.dual linear_map function universes u v w variables {K : Type u} {V : Type v} {ι : Type w} [decidable_eq ι] variables [field K] [add_comm_group V] [vector_space K V] local notation `V'` := dual K V /-- `e` and `ε` have characteristic properties of a basis and its dual -/ structure dual_pair (e : ι → V) (ε : ι → V') := (eval : ∀ i j : ι, ε i (e j) = if i = j then 1 else 0) (total : ∀ {v : V}, (∀ i, ε i v = 0) → v = 0) [finite : ∀ v : V, fintype {i | ε i v ≠ 0}] end dual_pair namespace dual_pair open vector_space module module.dual linear_map function universes u v w variables {K : Type u} {V : Type v} {ι : Type w} [dι : decidable_eq ι] variables [field K] [add_comm_group V] [vector_space K V] variables {e : ι → V} {ε : ι → dual K V} (h : dual_pair e ε) include h /-- The coefficients of `v` on the basis `e` -/ def coeffs (v : V) : ι →₀ K := { to_fun := λ i, ε i v, support := by { haveI := h.finite v, exact {i : ι | ε i v ≠ 0}.to_finset }, mem_support_to_fun := by {intro i, rw set.mem_to_finset, exact iff.rfl } } @[simp] lemma coeffs_apply (v : V) (i : ι) : h.coeffs v i = ε i v := rfl omit h /-- linear combinations of elements of `e`. This is a convenient abbreviation for `finsupp.total _ V K e l` -/ def lc (e : ι → V) (l : ι →₀ K) : V := l.sum (λ (i : ι) (a : K), a • (e i)) include h lemma dual_lc (l : ι →₀ K) (i : ι) : ε i (dual_pair.lc e l) = l i := begin erw linear_map.map_sum, simp only [h.eval, map_smul, smul_eq_mul], rw finset.sum_eq_single i, { simp }, { intros q q_in q_ne, simp [q_ne.symm] }, { intro p_not_in, simp [finsupp.not_mem_support_iff.1 p_not_in] }, end @[simp] lemma coeffs_lc (l : ι →₀ K) : h.coeffs (dual_pair.lc e l) = l := by { ext i, rw [h.coeffs_apply, h.dual_lc] } /-- For any v : V n, \sum_{p ∈ Q n} (ε p v) • e p = v -/ lemma decomposition (v : V) : dual_pair.lc e (h.coeffs v) = v := begin refine eq_of_sub_eq_zero (h.total _), intros i, simp [-sub_eq_add_neg, linear_map.map_sub, h.dual_lc, sub_eq_zero_iff_eq] end lemma mem_of_mem_span {H : set ι} {x : V} (hmem : x ∈ submodule.span K (e '' H)) : ∀ i : ι, ε i x ≠ 0 → i ∈ H := begin intros i hi, rcases (finsupp.mem_span_iff_total _).mp hmem with ⟨l, supp_l, sum_l⟩, change dual_pair.lc e l = x at sum_l, rw finsupp.mem_supported' at supp_l, apply classical.by_contradiction, intro i_not, apply hi, rw ← sum_l, simpa [h.dual_lc] using supp_l i i_not end lemma is_basis : is_basis K e := begin split, { rw linear_independent_iff, intros l H, change dual_pair.lc e l = 0 at H, ext i, apply_fun ε i at H, simpa [h.dual_lc] using H }, { rw submodule.eq_top_iff', intro v, rw [← set.image_univ, finsupp.mem_span_iff_total], exact ⟨h.coeffs v, by simp, h.decomposition v⟩ }, end lemma eq_dual : ε = is_basis.dual_basis h.is_basis := begin funext i, refine h.is_basis.ext (λ _, _), erw [is_basis.to_dual_apply, h.eval] end end dual_pair
a4416d8a472f6d7f2e33fd615cb262c18f8d03ac
1963cb8789bf8cf695607cc2d4106d7fdd8fb9f2
/homework1/homework1.lean
481a34c5acc82311ef2af6283788a101087f5095
[]
no_license
mtegene/homework-mtegene-master
ed43dd0b8cbcea936b6eec82c614842eca02a406
5f9b3623a46d2d3b98c54d8cbc82962d3fef49f5
refs/heads/master
1,610,605,612,607
1,488,481,866,000
1,488,481,866,000
81,875,687
0
0
null
null
null
null
UTF-8
Lean
false
false
5,407
lean
/- Dependent types In class, I presented "vector α n" and "matrix α m n" as examples of dependent types. Make up some operations on these types -- like "vector_add" or "vector_reverse" -- and declare constants of the right type to describe them. Use implicit arguments for parameters that can be inferred. Then use "check" to make sure they work. You can make up other dependent types if you would like. Don't worry about the definitions; just declare constants with the right types. -/ universe variable u constant vector : Type u → ℕ → Type u constant matrix : Type u → ℕ → ℕ → Type u section variable α : Type u variables m n : ℕ check vector α n check matrix α m n variables v₁ v₂ : vector α n variables v₃ v₄ : vector α m end /- Propositional logic Do at least five of these, and satisfy the following constraints: - make sure you use introduction and elimination rules for all the connectives - do at least one that requires classical logic - prove ¬(p ↔ ¬p) without using classical logic -/ section open classical variables p q r s : Prop -- commutativity of ∧ and ∨ example : p ∧ q ↔ q ∧ p := sorry example : p ∨ q ↔ q ∨ p := sorry -- associativity of ∧ and ∨ example : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) := sorry example : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := sorry -- distributivity -- this next one is in *Theorem Proving in Lean* -- example : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := sorry example : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := sorry -- other properties example : (p → (q → r)) ↔ (p ∧ q → r) := sorry example : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := sorry example : ¬(p ∨ q) ↔ ¬p ∧ ¬q := sorry example : ¬p ∨ ¬q → ¬(p ∧ q) := sorry example : ¬(p ∧ ¬ p) := sorry example : p ∧ ¬q → ¬(p → q) := sorry example : ¬p → (p → q) := sorry example : (¬p ∨ q) → (p → q) := sorry example : p ∨ false ↔ p := sorry example : p ∧ false ↔ false := sorry example : ¬(p ↔ ¬p) := sorry example : (p → q) → (¬q → ¬p) := sorry -- these require classical reasoning example : (p → r ∨ s) → ((p → r) ∨ (p → s)) := sorry example : ¬(p ∧ q) → ¬p ∨ ¬q := sorry example : ¬(p → q) → p ∧ ¬q := sorry example : (p → q) → (¬p ∨ q) := sorry example : (¬q → ¬p) → (p → q) := sorry example : p ∨ ¬p := sorry example : (((p → q) → p) → p) := sorry end /- Writing mathematical assertions I put the definitions of "divides" and "pow" in a funny namespace here, to avoid conflicts with similarly-named definitions elsewhere in the library (though at the moment though would not pose any such conflicts). Don't worry about the recursive definition of pow or the "instance" declaration -- we will discuss those later. Fill in the definitions and statements indicated; you can use Wikipedia to look them up. -/ namespace experiment def divides (m n : ℕ) : Prop := ∃ k, m * k = n instance : has_dvd nat := ⟨divides⟩ def pow (m : ℕ) : ℕ → ℕ | 0 := 1 | (n+1) := m * pow n infix `^` := pow section variables m n : ℕ check m ∣ n -- use \| to type the divides symbol check dvd m n -- this is equivalent check m^n check pow m n vm_eval 2^10 vm_eval 2^100 vm_eval 10^2 end def even (n : ℕ) : Prop := 2 ∣ n def prime (n : ℕ) : Prop := sorry -- Without any parameters, an expression of type Prop is an -- assertion. The next one should be the statement that there are -- infinitely many primes. You can say this by asserting that for -- every natural number n, there is a prime number bigger than n. def infinitely_many_primes : Prop := sorry def Fermat_prime (n : ℕ) : Prop := sorry def infinitely_many_Fermat_primes : Prop := sorry def goldbach_conjecture : Prop := sorry -- This is the statement that every odd number greater than 5 is the -- sum of three primes. def Goldbach's_weak_conjecture : Prop := sorry def Fermat's_last_theorem : Prop := sorry end experiment /- Reasoning with quantifiers: Do at least three of these, including - at least one involving the universal quantifier - at least one involving the existential quantifier - at least one that requires classical logic -/ section variable α : Type variables (p q : α → Prop) (r : Prop) variable a : α example : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) := sorry example : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) := sorry example : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x := sorry example : (∃ x : α, r) → r := sorry example : r → (∃ x : α, r) := sorry example : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r := sorry -- in *Theorem Proving in Lean* -- example : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) := sorry example : (∀ x, p x) ↔ ¬ (∃ x, ¬ p x) := sorry example : (∃ x, p x) ↔ ¬ (∀ x, ¬ p x) := sorry example : (¬ ∃ x, p x) ↔ (∀ x, ¬ p x) := sorry example : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) := sorry example : (∀ x, p x → r) ↔ (∃ x, p x) → r := sorry -- in *Theorem Proving in Lean* -- example : (∃ x, p x → r) ↔ (∀ x, p x) → r := sorry example : (∃ x, r → p x) ↔ (r → ∃ x, p x) := sorry end
3ac43255a5ca95ef5b99f024ecd4e236f8ad3490
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/tests/lean/run/do_match_else.lean
e8181c79be4867501f3aa5f13aa8e84301060ae0
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
564
lean
open tactic set_option pp.all true definition app2 (f a b : expr) := expr.app (expr.app f a) b example (a b c x y : nat) (H : nat.add (nat.add x y) y = 0) : true := by do a ← get_local `a, b ← get_local `b, c ← get_local `c, H ← get_local `H >>= infer_type, (lhs, rhs) ← match_eq H, nat_add : expr ← mk_const `nat.add, p : pattern ← mk_pattern [] [a, b] (app2 nat_add a b) [app2 nat_add b a, a, b], trace (pattern.output p), [v₁, v₂, v₃] ← match_pattern p lhs | failed, trace v₁, trace v₂, trace v₃, constructor
7e9eaf892d9d619fffd7d023a427224a7be48d04
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/dottedCtorNamedArgPattern.lean
7f75b9aec9eb99e896331f58c779daa305d4578f
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
leanprover/lean4
4bdf9790294964627eb9be79f5e8f6157780b4cc
f1f9dc0f2f531af3312398999d8b8303fa5f096b
refs/heads/master
1,693,360,665,786
1,693,350,868,000
1,693,350,868,000
129,571,436
2,827
311
Apache-2.0
1,694,716,156,000
1,523,760,560,000
Lean
UTF-8
Lean
false
false
316
lean
import Lean def f (x : Nat × Nat) := match x with | .mk (snd := snd) .. => snd example : f (10, 20) = 20 := rfl open Lean def g (e : Expr) : Expr := match e with | .forallE (binderType := type) .. => type | e => e def h (x : Nat × Nat) := match x with | .mk (α := .(Nat)) (snd := snd) .. => snd
070d077c6305938b1b9a34506fecf9215e3850ab
46ee5dc7248ccc9ee615639c0c003c05f58975cd
/src/interpolation.lean
ac88d4c8beb4a40f23dd948723d8056b5e3d18a7
[ "Apache-2.0" ]
permissive
m4lvin/tablean
e61d593b4dde6512245192c577edeb36c48f63c0
836202612fc2bfacb5545696412e7d27f7704141
refs/heads/main
1,685,613,112,076
1,676,755,678,000
1,676,755,678,000
454,064,275
8
1
null
null
null
null
UTF-8
Lean
false
false
1,061
lean
-- INTERPOLATION import syntax import completeness import partitions open hasVocabulary def interpolant (φ : formula) (ψ : formula) (θ : formula) := tautology (φ ↣ θ) ∧ tautology (θ ↣ ψ) ∧ voc θ ⊆ (voc φ ∩ voc ψ) lemma interpolation {ϕ ψ} : tautology (ϕ ↣ ψ) → ∃ θ, interpolant ϕ ψ θ := begin intros hyp, let X1 : finset formula := {ϕ}, let X2 : finset formula := {~ψ}, have ctX : closedTableau (X1 ∪ X2), { rw tautImp_iff_comboNotUnsat at hyp, rw ← completeness at hyp, -- using completeness! unfold consistent at hyp, simp at hyp, unfold inconsistent at hyp, change closedTableau {ϕ, ~ψ}, exact classical.choice hyp, }, have partInt := tabToInt ctX, -- using tableau interpolation! rcases partInt with ⟨θ,pI_prop⟩, unfold partInterpolant at pI_prop, use θ, split, { rw tautImp_iff_comboNotUnsat, tauto, }, split, { rw tautImp_iff_comboNotUnsat, simp at *, tauto, }, { cases pI_prop, unfold voc vocabOfSetFormula at *, simp at *, tauto, }, end
453cfe184ad2a32f39905a8043e99ab9ac99af29
957a80ea22c5abb4f4670b250d55534d9db99108
/tests/lean/run/tactic_io.lean
63b9f9e95dbf2fa5f52903370a74ae89a391f998
[ "Apache-2.0" ]
permissive
GaloisInc/lean
aa1e64d604051e602fcf4610061314b9a37ab8cd
f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0
refs/heads/master
1,592,202,909,807
1,504,624,387,000
1,504,624,387,000
75,319,626
2
1
Apache-2.0
1,539,290,164,000
1,480,616,104,000
C++
UTF-8
Lean
false
false
246
lean
import system.io section variable [io.interface] def tst_io : io string := do b ← io.fs.read_file "tactic_io.lean", return b^.to_string end open tactic meta def tac : tactic unit := do s ← tactic.run_io @tst_io, trace s run_cmd tac
9e346671ba03d9af21c2839bb9c000a64d4f9953
e37bb385769d6f4ac9931236fd07b708397e086b
/src/library/src_ordered_field_lemmas.lean
e1a397a4efe7a5071bbc611eb0e700c87fead954
[]
no_license
gihanmarasingha/ems_reals
5f5d5b9d9dfb5a10da465046336d74995132dff6
9df527742db69d0a389add44b506538fdb4d0800
refs/heads/master
1,675,327,747,064
1,608,036,820,000
1,608,036,820,000
315,825,726
0
0
null
null
null
null
UTF-8
Lean
false
false
14,992
lean
import .src_ordered_field tactic namespace mth1001 namespace myreal section ordered variables {R : Type} [myordered_field R] open_locale classical open myordered_field lemma pos_one : pos (1 : R) := begin rcases trichotomy (1 : R) with ⟨hpo, _, _ ⟩ | ⟨_, hoe, _ ⟩ | ⟨hnpo, hnoe, hpno⟩ , { exact hpo, }, { exact absurd hoe zero_ne_one.symm, }, { exfalso, apply hnpo, convert pos_mul_of_pos_of_pos _ _ hpno hpno, rw [neg_mul_neg_self, one_mul], }, end lemma pos_nat (n : ℕ) : n ≠ 0 → pos (n : R) := begin induction n with k hk, { intro _, contradiction, }, { intro _, rw coe_nat_succ, by_cases h₁ : k = 0, { rw h₁, change pos((0 : R) + (1 : R)), rw zero_add, exact pos_one, }, { exact pos_add_of_pos_of_pos _ _ (hk h₁) pos_one }, }, end lemma lt_iff_pos_sub (x y : R) : x < y ↔ pos (y -x) := by refl lemma lt_iff_pos_neg (x y : R) : x < y ↔ pos (y + -x) := by refl lemma zero_lt_one' : (0 : R) < (1 : R) := begin rw [lt_iff_pos_sub, sub_zero], exact pos_one, end lemma gt_zero_mul_of_gt_zero_of_gt_zero {a b : R} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := begin rw [lt_iff_pos_sub, sub_zero] at *, exact pos_mul_of_pos_of_pos a b h₁ h₂, end lemma mul_pos (a b : R) : 0 < a → 0 < b → 0 < a * b := begin intros h₁ h₂, rw [lt_iff_pos_sub, sub_zero] at *, exact pos_mul_of_pos_of_pos a b h₁ h₂, end lemma neg_pos {x : R} : 0 < -x ↔ x < 0:= begin repeat {rw lt_iff_pos_neg}, rw zero_add, have : -(0 : R) = (0 : R), { rw [←add_zero (-(0 : R) : R), neg_add], }, rw [this, add_zero], end lemma trichotomy' (x y: R) : x < y ∧ ¬x = y ∧ ¬y < x ∨ ¬x < y ∧ x = y ∧ ¬y < x ∨ ¬x < y ∧ ¬x = y ∧ y < x := begin repeat {rw lt_iff_pos_sub}, have : x - y = -(y - x), { rw [sub_eq_add_neg', sub_eq_add_neg', neg_add_eq_neg_add_neg', neg_neg], }, rw this, rw [@eq_comm _ x y, (sub_eq_zero_iff_eq y x).symm], exact trichotomy (y + -x), end lemma lt_trans {x y z : R} : x < y → y < z → x < z := begin repeat {rw lt_iff_pos_sub}, intros pyx pzy, have : z - x = (z - y) + (y - x), { repeat {rw sub_eq_add_neg'}, rw [←add_assoc, add_assoc z _ _, neg_add, add_zero], }, rw this, exact pos_add_of_pos_of_pos _ _ pzy pyx, end lemma add_lt_add_iff_right_mpr {x y : R} (z : R) : x < y → x + z < y + z := begin repeat {rw lt_iff_pos_sub}, apply eq.substr, rw [sub_eq_add_neg', neg_add_eq_neg_add_neg', ←add_assoc], rw [add_assoc y, add_neg', add_zero, sub_eq_add_neg'], end lemma add_lt_add_iff_right_mp {x y : R} (z : R) : x + z < y + z → x < y := begin intro h, convert add_lt_add_iff_right_mpr (-z) h; rw [add_assoc, add_neg', add_zero], end lemma add_lt_add_iff_right {x y : R} (z : R) : x + z < y + z ↔ x < y := iff.intro (add_lt_add_iff_right_mp z) (add_lt_add_iff_right_mpr z) theorem neg_lt_neg_iff {a b : R} : -a < -b ↔ b < a := begin have h₁ : -a < -b ↔ -a + a < -b + a, from (add_lt_add_iff_right a).symm, have h₂ : b < a ↔ b + -a < a + -a, from (add_lt_add_iff_right (-a)).symm, have h₃ : -b + a = - (b + -a), { rw [neg_add_eq_neg_add_neg', neg_neg, add_comm], }, rw [h₁, h₂, neg_add, add_neg', h₃, neg_pos], end lemma mul_lt_mul_left_mpr {x y z : R} : 0 < z → x < y → z * x < z * y := begin repeat {rw lt_iff_pos_sub}, rw [←mul_sub, sub_zero], exact pos_mul_of_pos_of_pos _ _, end theorem add_lt_add {a b c d : R} : a < b → c < d → a + c < b + d := begin repeat {rw lt_iff_pos_sub}, intros h₁ h₂, convert pos_add_of_pos_of_pos _ _ h₁ h₂, repeat {rw sub_eq_add_neg'}, rw neg_add_eq_neg_add_neg', rw [add_assoc, add_comm (-c) (-a), ←add_assoc d, add_comm d (-a), add_assoc (-a), ←add_assoc], end lemma lt_irrefl {x : R} : ¬x < x := begin rcases (trichotomy' x x) with ⟨_, _, nxx⟩ | ⟨nxx, _⟩ | ⟨nxx, _⟩; exact nxx, end theorem ne_of_gt {a b : R} (h : b < a) : a ≠ b := λ k, lt_irrefl (@eq.subst _ (λ x, b < x) a b k h) lemma le_iff_lt_or_eq {x y : R} : x ≤ y ↔ ((x < y) ∨ x = y) := by refl lemma zero_le_one : (0 : R) ≤ 1 := begin rw le_iff_lt_or_eq, exact or.inl zero_lt_one', end lemma le_refl (x : R) : x ≤ x := or.inr rfl lemma not_le_iff_lt (x y : R) : ¬(x ≤ y) ↔ (y < x) := begin rw le_iff_lt_or_eq, push_neg, rcases trichotomy' x y with ⟨hxlty, _, _⟩ | ⟨_, hxy, hnyltx ⟩ | ⟨hnxlty, hnxy, hxlty ⟩ , { split, { rintro ⟨hnxy, _⟩, contradiction, }, { intros hyltx, exfalso, exact lt_irrefl (lt_trans hxlty hyltx), }, }, { split, { rintro ⟨_, hnxy⟩, contradiction, }, { intro hyltx, contradiction, }, }, { split, { intro _, exact hxlty, }, { intro _, exact ⟨hnxlty, hnxy⟩, }, }, end lemma not_lt_iff_le (x y : R) : ¬(x < y) ↔ (y ≤ x) := by rw [←not_le_iff_lt, not_not] lemma lt_iff_le_not_le (a b : R) : a < b ↔ a ≤ b ∧ ¬b ≤ a := begin rw [not_le_iff_lt, le_iff_lt_or_eq, or_and_distrib_right, and_self], exact ⟨λ h, or.inl h, λ h, or.elim h id (λ k, k.2)⟩, end lemma neg_nonneg {x : R} : 0 ≤ -x ↔ x ≤ 0 := begin repeat {rw le_iff_lt_or_eq}, have k : 0 < -x ↔ x < 0, from neg_pos, split, { rintro (h₁ | h₂), { left, rwa ←k, }, { right, rw [←neg_neg x, ←h₂, neg_zero], } }, { rintro (h | rfl), { left, rwa k, }, { right, rw neg_zero, }, }, end lemma le_trans (x y z : R) : x ≤ y → y ≤ z → x ≤ z := begin rintro (h₁ | rfl) (h₂ | rfl), { left, exact lt_trans h₁ h₂}, { left, exact h₁ }, { left, exact h₂, }, { right, refl, }, end lemma lt_of_le_of_lt {a b c : R} (h₁ : a ≤ b) (h₂ : b < c) : a < c := begin cases h₁ with altb aeqb, { exact lt_trans altb h₂, }, { rw aeqb, exact h₂, }, end lemma le_total (x y : R) : x ≤ y ∨ y ≤ x := begin rcases trichotomy' x y with ⟨xltx, _⟩ | ⟨_, xeqy, _⟩ | ⟨_, _, yltx⟩, { left, left, exact xltx, }, { left, right, exact xeqy, }, { right, left, exact yltx, }, end lemma anti_symm (x y : R) : x ≤ y → y ≤ x → x = y := begin intros h₁ h₂, have h : (x ≠ y → false), -- Could do this using `by_contra`, but that's slow. { intro h, have h₃ : y < x := or.elim h₂ id (λ k, absurd k.symm h), have h₄ : x < y := or.elim h₁ id (λ k, absurd k h), exact lt_irrefl (lt_trans h₃ h₄), }, rw [←(@not_not (x=y))], exact h, end theorem neg_le_neg_iff {a b : R} : -a ≤ -b ↔ b ≤ a := begin repeat {rw le_iff_lt_or_eq}, split, { rintro (hlt | heq), { left, rwa ←neg_lt_neg_iff, }, { right, rw [←neg_neg a, heq, neg_neg], }, }, { rintro (hlt | heq), { left, rwa neg_lt_neg_iff, }, { right, rw heq, }, }, end theorem add_le_add {a b c d : R} : a ≤ b → c ≤ d → a + c ≤ b + d := begin rintro (h₁| rfl) (h₂ | rfl), { left, exact add_lt_add h₁ h₂ }, { left, exact add_lt_add_iff_right_mpr c h₁, }, { left, repeat {rw add_comm a _}, exact add_lt_add_iff_right_mpr a h₂, }, { exact le_refl _, }, end theorem add_le_add_left (a b: R) : a ≤ b → ∀ (c : R), c + a ≤ c + b := λ aleb c, add_le_add (le_refl c) aleb theorem mul_self_non_neg (a : R) : 0 ≤ a * a:= begin rcases trichotomy' 0 a with ⟨posa, _⟩ | ⟨_, eq0, _⟩ | ⟨_, _, nega⟩, { left, convert mul_lt_mul_left_mpr posa posa, rw mul_zero, }, { right, rw [←eq0, mul_zero], }, { left, rw ←neg_pos at nega, rw ←neg_mul_neg_self, convert mul_lt_mul_left_mpr nega nega, rw mul_zero, }, end lemma non_neg_mul_of_non_neg_of_non_neg {a b : R} (h₁ : 0 ≤ a) (h₂ : 0 ≤ b) : 0 ≤ a * b := begin cases h₁ with apos aeq0, { cases h₂ with bpos beq0, { left, exact gt_zero_mul_of_gt_zero_of_gt_zero apos bpos, }, { right, rw [←beq0, mul_zero], }, }, { right, rw [←aeq0, zero_mul], }, end lemma non_neg_of_non_neg_mul_of_pos {x y : R} (h₁ : 0 ≤ x * y) (h₂ : 0 < x) : 0 ≤ y := begin cases h₁ with xlty xyeq0, { by_contra h₃, rw [not_le_iff_lt, ←neg_pos] at h₃, have h₄ : 0 < x * -y, from gt_zero_mul_of_gt_zero_of_gt_zero h₂ h₃, rw [←neg_mul_eq_mul_neg, neg_pos] at h₄, exact lt_irrefl (lt_trans h₄ xlty), }, { right, rw mul_comm at xyeq0, symmetry, apply eq_zero_of_not_eq_zero_of_mul_not_eq_zero _ _ (ne_of_gt h₂) (xyeq0.symm), }, end lemma non_neg_mul_iff_non_neg_and_non_neg_or_non_pos_and_non_pos (a b : R) : 0 ≤ a * b ↔ (0 ≤ a ∧ 0 ≤ b) ∨ (a ≤ 0 ∧ b ≤ 0) := begin split, { intro h₁, by_cases h₂ : 0 ≤ a, { by_cases h₃ : a = 0, { rw h₃, exact or.elim (le_total b 0) (λ h₄, or.inr ⟨le_refl 0, h₄⟩) (λ h₄, or.inl ⟨le_refl 0, h₄⟩), }, { have h₄ : 0 < a, from or.elim h₂ id (λ aeq0, absurd aeq0.symm h₃), have h₅ : 0 ≤ b, from non_neg_of_non_neg_mul_of_pos h₁ h₄, exact or.inl ⟨or.inl h₄, h₅⟩, }, }, { rw not_le_iff_lt at h₂, right, have k : b ≤ 0, { by_contra h₃, rw not_le_iff_lt at h₃, rw ←neg_pos at h₂, have h₄ : 0 < b * -a, from gt_zero_mul_of_gt_zero_of_gt_zero h₃ h₂, rw [←neg_mul_eq_mul_neg, mul_comm, neg_pos] at h₄, exact lt_irrefl (lt_of_le_of_lt h₁ h₄), }, exact ⟨or.inl h₂, k⟩, }, }, { rintro (⟨h₁, h₂⟩ | ⟨h₁, h₂⟩), { exact non_neg_mul_of_non_neg_of_non_neg h₁ h₂, }, { rw ←neg_mul_neg a b, rw ←neg_nonneg at h₁ h₂, exact non_neg_mul_of_non_neg_of_non_neg h₁ h₂, }, }, end theorem inv_pos {a : R} (h : a ≠ 0) : 0 < a⁻¹ ↔ 0 < a := begin split, { intro k, have h₂ : 0 ≤ a * a, from mul_self_non_neg a, cases h₂ with posaa eq0, { convert mul_lt_mul_left_mpr k posaa, { rw mul_zero, }, { rw [←mul_assoc, inv_mul a h, one_mul], }, }, { have h₃ : a = 0, { cases eq_zero_or_eq_zero_of_mul_eq_zero a a eq0.symm; assumption, }, exact absurd h₃ h, }, }, { intro k, have h₂ : 0 ≤ (a⁻¹ * a⁻¹), from mul_self_non_neg a⁻¹, cases h₂ with posainvsq eq0, { convert mul_lt_mul_left_mpr k posainvsq, { rw mul_zero, }, { rw [←mul_assoc, mul_inv a h, one_mul], }, }, { have h₃ : a⁻¹ = 0, { cases eq_zero_or_eq_zero_of_mul_eq_zero _ _ eq0.symm; assumption, }, exact absurd h₃ (inv_ne_zero h), }, }, end theorem inv_lt_inv {a b : R} (h₁ : 0 < a) (h₂ : 0 < b) : a⁻¹ < b⁻¹ ↔ b < a := begin split, { intro h₃, have h₄ : a * a⁻¹ < a * b⁻¹, from mul_lt_mul_left_mpr h₁ h₃, have h₅ : a ≠ 0, from ne_of_gt h₁, rw (mul_inv a h₅) at h₄, have h₆ : b * 1 < b * (a * b⁻¹), from mul_lt_mul_left_mpr h₂ h₄, have h₇ : b ≠ 0, from ne_of_gt h₂, rw [mul_one, mul_comm, mul_assoc, inv_mul b h₇, mul_one] at h₆, exact h₆, }, { intro h₃, have h₅ : a ≠ 0, from ne_of_gt h₁, have k₁ : a⁻¹ > 0, from (inv_pos h₅).mpr h₁, have h₄ : a⁻¹ * b < a⁻¹ * a, from mul_lt_mul_left_mpr k₁ h₃, rw inv_mul a h₅ at h₄, have h₇ : b ≠ 0, from ne_of_gt h₂, have k₂ : b⁻¹ > 0, from (inv_pos h₇).mpr h₂, have h₆ : b⁻¹ * (a⁻¹ * b) < b⁻¹ * 1, from mul_lt_mul_left_mpr k₂ h₄, rw [mul_comm, mul_assoc, mul_inv b h₇, mul_one, mul_one] at h₆, exact h₆, }, end end ordered section max_abs variables {R : Type} [myordered_field R] open_locale classical open myordered_field lemma le_max_right (a b : R) : b ≤ max a b := begin unfold max, by_cases h : b ≤ a, { rwa (if_pos h), }, { rw (if_neg h), exact le_refl b, }, end lemma le_max_left (a b : R) : a ≤ max a b := begin unfold max, by_cases h : b ≤ a, { rw (if_pos h), exact le_refl a, }, { rw (if_neg h), rw not_le_iff_lt at h, left, exact h, }, end lemma max_choice (a b : R) : max a b = a ∨ max a b = b := begin unfold max, by_cases h : b ≤ a, { rw (if_pos h), left, refl, }, { rw (if_neg h), right, refl, }, end lemma neg_le_abs (a : R) : -a ≤ abs a := begin unfold abs max, by_cases h : -a ≤ a, { rw (if_pos h), exact h, }, { rw (if_neg h), exact le_refl (-a), }, end lemma le_abs_self (a : R) : a ≤ abs a := begin unfold abs max, by_cases h : -a ≤ a, { rw (if_pos h), right, refl, }, { rw (if_neg h), left, rw le_iff_lt_or_eq at h, push_neg at h, rw [not_lt_iff_le, le_iff_lt_or_eq, or_and_distrib_right] at h, rcases h with ⟨haltma, _⟩ | ⟨hama, hnama⟩, { exact haltma, }, { exact absurd hama hnama.symm, }, }, end theorem triangle_inequality (x y : R) : abs (x + y) ≤ abs x + abs y := begin by_cases h : -(x+y) ≤ x+y, { have : abs (x+y) = x + y, { unfold abs max, rw (if_pos h), }, rw this, have h₁ : x ≤ abs x, from le_abs_self x, have h₂ : y ≤ abs y, from le_abs_self y, exact add_le_add h₁ h₂, }, { have : abs (x+y) = -(x+y), { unfold abs max, rw (if_neg h), }, rw this, rw [neg_add_eq_neg_add_neg', add_comm], have h₁ : -x ≤ abs x, from neg_le_abs x, have h₂ : -y ≤ abs y, from neg_le_abs y, exact add_le_add h₁ h₂, }, end end max_abs section upper_bounds variables {R : Type} [myordered_field R] theorem sup_uniqueness (S : set R) (a b : R) (h₁ : is_sup a S) (h₂ : is_sup b S) : a = b := anti_symm _ _ (h₁.right b h₂.left) (h₂.right a h₁.left) theorem empty_set_upper_bound (u : R) : upper_bound u ∅ := λ s, (set.mem_empty_eq s) ▸ false.elim end upper_bounds section instance_linear_ordered_comm_ring open_locale classical noncomputable theory variables {R : Type} [myordered_field R] instance : linear_ordered_comm_ring R := { add := comm_group.add, add_assoc := comm_group.add_assoc, zero := comm_group.zero, zero_add := zero_add, add_zero := add_zero, neg := comm_group.neg, add_left_neg := neg_add, add_comm := comm_group.add_comm, mul := myfield.mul, mul_assoc := myfield.mul_assoc, one := myfield.one, one_mul := one_mul, mul_one := myfield.mul_one, left_distrib := myfield.mul_add, right_distrib := add_mul, le := le, lt := lt, lt_iff_le_not_le := lt_iff_le_not_le, le_refl := le_refl, le_trans := le_trans, le_antisymm := anti_symm, add_le_add_left := add_le_add_left, mul_pos := mul_pos, le_total := le_total, mul_comm := myfield.mul_comm, zero_lt_one := zero_lt_one', zero_ne_one := zero_ne_one, } end instance_linear_ordered_comm_ring end myreal end mth1001
d2bf3f99d7885822a64887a33b18588f1b150580
0845ae2ca02071debcfd4ac24be871236c01784f
/library/init/control/functor.lean
a8d49fee4968718acdaaebac04e6f4986f3738c4
[ "Apache-2.0" ]
permissive
GaloisInc/lean4
74c267eb0e900bfaa23df8de86039483ecbd60b7
228ddd5fdcd98dd4e9c009f425284e86917938aa
refs/heads/master
1,643,131,356,301
1,562,715,572,000
1,562,715,572,000
192,390,898
0
0
null
1,560,792,750,000
1,560,792,749,000
null
UTF-8
Lean
false
false
873
lean
/- Copyright (c) Luke Nelson and Jared Roesch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Luke Nelson, Jared Roesch, Sebastian Ullrich, Leonardo de Moura -/ prelude import init.core open Function universes u v class Functor (f : Type u → Type v) : Type (max (u+1) v) := (map : ∀ {α β : Type u}, (α → β) → f α → f β) (mapConst : ∀ {α β : Type u}, α → f β → f α := fun α β => map ∘ const β) infixr <$> := Functor.map infixr <$ := Functor.mapConst @[reducible] def Functor.mapConstRev {f : Type u → Type v} [Functor f] {α β : Type u} : f β → α → f α := fun a b => b <$ a infixr $> := Functor.mapConstRev @[reducible] def Functor.mapRev {f : Type u → Type v} [Functor f] {α β : Type u} : f α → (α → β) → f β := fun a f => f <$> a infixl <&> := Functor.mapRev
10058fd5e8122f4db8cd9fbe909025520ab0ec6d
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/tests/lean/autoIssue.lean
fd4b9dec2456d71c1d66284fa6dbd8bbf86b5ae3
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
1,105
lean
import Lean structure A := x : Nat a' : x = 1 := by trivial #check @A.a' example (z : A) : z.x = 1 := by have := z.a' trace_state exact this example (z : A) : z.x = 1 := by have := z.2 trace_state exact this #check @A.rec example (z : A) : z.x = 1 := by have ⟨x, a'⟩ := z trace_state subst a' rfl example (z : A) : z.x = 1 := by induction z with | mk x a' => trace_state subst a' rfl structure B := x : Nat y : Nat := 2 example (b : B) : b = { x := b.x, y := b.y } := by cases b with | mk x y => trace_state; rfl open Lean open Lean.Meta def tst : MetaM Unit := withLocalDeclD `a (mkConst ``A) fun a => do let e := mkProj ``A 1 a IO.println (← Meta.ppExpr (← inferType e)) #eval tst example (z : A) : z.x = 1 := by match z with | { a' := h } => trace_state; exact h example (z : A) : z.x = 1 := by match z with | A.mk x a' => trace_state; exact a' example : A := { x := 1, a' := _ } example : A := A.mk 1 _ def f (x : Nat) (h : x = 1) : A := A.mk x h example : A := f 2 _ example : A := by apply f done
e4349d93261a9a05c7d561a0f676e63b0ab632ad
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/exfalso1.lean
e7637709c2075fc95a8181a35b91645bdb25fa51
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
236
lean
open tactic nat example (a b : nat) : a = 0 → b = 1 → a = b → a + b * b ≤ 10000 := by do intro_lst [`a0, `a1, `ab], exfalso, trace_state, get_local `a >>= subst, get_local `b >>= subst, trace_state, contradiction
ea27381c92bcf484f33264740f7f3f6bd816fe9a
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/algebra/module/ordered.lean
1e7d79d129c016315be71d365fc43245fd167a16
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
7,866
lean
/- Copyright (c) 2020 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import algebra.module.pi import algebra.ordered_pi import algebra.module.prod import algebra.ordered_field /-! # Ordered modules In this file we define * `ordered_module R M` : an ordered additive commutative monoid `M` is an `ordered_module` over an `ordered_semiring` `R` if the scalar product respects the order relation on the monoid and on the ring. There is a correspondence between this structure and convex cones, which is proven in `analysis/convex/cone.lean`. ## Implementation notes * We choose to define `ordered_module` as a `Prop`-valued mixin, so that it can be used for both modules and algebras (the axioms for an "ordered algebra" are exactly that the algebra is ordered as a module). * To get ordered modules and ordered vector spaces, it suffices to replace the `order_add_comm_monoid` and the `ordered_semiring` as desired. ## References * https://en.wikipedia.org/wiki/Ordered_module ## Tags ordered module, ordered module, ordered vector space -/ /-- An ordered module is an ordered additive commutative monoid with a partial order in which the scalar multiplication is compatible with the order. -/ @[protect_proj] class ordered_module (R M : Type*) [ordered_semiring R] [ordered_add_comm_monoid M] [module R M] : Prop := (smul_lt_smul_of_pos : ∀ {a b : M}, ∀ {c : R}, a < b → 0 < c → c • a < c • b) (lt_of_smul_lt_smul_of_pos : ∀ {a b : M}, ∀ {c : R}, c • a < c • b → 0 < c → a < b) section ordered_module variables {R M : Type*} [ordered_semiring R] [ordered_add_comm_monoid M] [module R M] [ordered_module R M] {a b : M} {c : R} lemma smul_lt_smul_of_pos : a < b → 0 < c → c • a < c • b := ordered_module.smul_lt_smul_of_pos lemma smul_le_smul_of_nonneg (h₁ : a ≤ b) (h₂ : 0 ≤ c) : c • a ≤ c • b := begin by_cases H₁ : c = 0, { simp [H₁, zero_smul] }, { by_cases H₂ : a = b, { rw H₂ }, { exact le_of_lt (smul_lt_smul_of_pos (lt_of_le_of_ne h₁ H₂) (lt_of_le_of_ne h₂ (ne.symm H₁))), } } end lemma eq_of_smul_eq_smul_of_pos_of_le (h₁ : c • a = c • b) (hc : 0 < c) (hle : a ≤ b) : a = b := hle.lt_or_eq.resolve_left $ λ hlt, (smul_lt_smul_of_pos hlt hc).ne h₁ lemma lt_of_smul_lt_smul_of_nonneg (h : c • a < c • b) (hc : 0 ≤ c) : a < b := hc.eq_or_lt.elim (λ hc, false.elim $ lt_irrefl (0:M) $ by rwa [← hc, zero_smul, zero_smul] at h) (ordered_module.lt_of_smul_lt_smul_of_pos h) lemma smul_lt_smul_iff_of_pos (hc : 0 < c) : c • a < c • b ↔ a < b := ⟨λ h, lt_of_smul_lt_smul_of_nonneg h hc.le, λ h, smul_lt_smul_of_pos h hc⟩ lemma smul_pos_iff_of_pos (hc : 0 < c) : 0 < c • a ↔ 0 < a := calc 0 < c • a ↔ c • 0 < c • a : by rw smul_zero ... ↔ 0 < a : smul_lt_smul_iff_of_pos hc end ordered_module /-- If `R` is a linear ordered semifield, then it suffices to verify only the first axiom of `ordered_module`. Moreover, it suffices to verify that `a < b` and `0 < c` imply `c • a ≤ c • b`. We have no semifields in `mathlib`, so we use the assumption `∀ c ≠ 0, is_unit c` instead. -/ lemma ordered_module.mk'' {R M : Type*} [linear_ordered_semiring R] [ordered_add_comm_monoid M] [module R M] (hR : ∀ {c : R}, c ≠ 0 → is_unit c) (hlt : ∀ ⦃a b : M⦄ ⦃c : R⦄, a < b → 0 < c → c • a ≤ c • b) : ordered_module R M := begin have hlt' : ∀ ⦃a b : M⦄ ⦃c : R⦄, a < b → 0 < c → c • a < c • b, { refine λ a b c hab hc, (hlt hab hc).lt_of_ne _, rw [ne.def, (hR hc.ne').smul_left_cancel], exact hab.ne }, refine { smul_lt_smul_of_pos := hlt', .. }, intros a b c h hc, rcases (hR hc.ne') with ⟨c, rfl⟩, rw [← inv_smul_smul c a, ← inv_smul_smul c b], refine hlt' h (pos_of_mul_pos_left _ hc.le), simp only [c.mul_inv, zero_lt_one] end /-- If `R` is a linear ordered field, then it suffices to verify only the first axiom of `ordered_module`. -/ lemma ordered_module.mk' {k M : Type*} [linear_ordered_field k] [ordered_add_comm_monoid M] [module k M] (hlt : ∀ ⦃a b : M⦄ ⦃c : k⦄, a < b → 0 < c → c • a ≤ c • b) : ordered_module k M := ordered_module.mk'' (λ c hc, is_unit.mk0 _ hc) hlt instance linear_ordered_semiring.to_ordered_module {R : Type*} [linear_ordered_semiring R] : ordered_module R R := { smul_lt_smul_of_pos := ordered_semiring.mul_lt_mul_of_pos_left, lt_of_smul_lt_smul_of_pos := λ _ _ _ h hc, lt_of_mul_lt_mul_left h hc.le } section field variables {k M N : Type*} [linear_ordered_field k] [ordered_add_comm_group M] [module k M] [ordered_module k M] [ordered_add_comm_group N] [module k N] [ordered_module k N] {a b : M} {c : k} lemma smul_le_smul_iff_of_pos (hc : 0 < c) : c • a ≤ c • b ↔ a ≤ b := ⟨λ h, inv_smul_smul' hc.ne' a ▸ inv_smul_smul' hc.ne' b ▸ smul_le_smul_of_nonneg h (inv_nonneg.2 hc.le), λ h, smul_le_smul_of_nonneg h hc.le⟩ lemma smul_le_smul_iff_of_neg (hc : c < 0) : c • a ≤ c • b ↔ b ≤ a := begin rw [← neg_neg c, neg_smul, neg_smul (-c), neg_le_neg_iff, smul_le_smul_iff_of_pos (neg_pos.2 hc)], apply_instance, end lemma smul_lt_iff_of_pos (hc : 0 < c) : c • a < b ↔ a < c⁻¹ • b := calc c • a < b ↔ c • a < c • c⁻¹ • b : by rw [smul_inv_smul' hc.ne'] ... ↔ a < c⁻¹ • b : smul_lt_smul_iff_of_pos hc lemma smul_le_iff_of_pos (hc : 0 < c) : c • a ≤ b ↔ a ≤ c⁻¹ • b := calc c • a ≤ b ↔ c • a ≤ c • c⁻¹ • b : by rw [smul_inv_smul' hc.ne'] ... ↔ a ≤ c⁻¹ • b : smul_le_smul_iff_of_pos hc lemma le_smul_iff_of_pos (hc : 0 < c) : a ≤ c • b ↔ c⁻¹ • a ≤ b := calc a ≤ c • b ↔ c • c⁻¹ • a ≤ c • b : by rw [smul_inv_smul' hc.ne'] ... ↔ c⁻¹ • a ≤ b : smul_le_smul_iff_of_pos hc instance prod.ordered_module : ordered_module k (M × N) := ordered_module.mk' $ λ v u c h hc, ⟨smul_le_smul_of_nonneg h.1.1 hc.le, smul_le_smul_of_nonneg h.1.2 hc.le⟩ instance pi.ordered_module {ι : Type*} {M : ι → Type*} [Π i, ordered_add_comm_group (M i)] [Π i, module k (M i)] [∀ i, ordered_module k (M i)] : ordered_module k (Π i : ι, M i) := begin refine (ordered_module.mk' $ λ v u c h hc i, _), change c • v i ≤ c • u i, exact smul_le_smul_of_nonneg (h.le i) hc.le, end -- Sometimes Lean fails to apply the dependent version to non-dependent functions, -- so we define another instance instance pi.ordered_module' {ι : Type*} {M : Type*} [ordered_add_comm_group M] [module k M] [ordered_module k M] : ordered_module k (ι → M) := pi.ordered_module end field section order_dual variables {R M : Type*} instance [semiring R] [ordered_add_comm_monoid M] [module R M] : has_scalar R (order_dual M) := { smul := @has_scalar.smul R M _ } instance [semiring R] [ordered_add_comm_monoid M] [module R M] : mul_action R (order_dual M) := { one_smul := @mul_action.one_smul R M _ _, mul_smul := @mul_action.mul_smul R M _ _ } instance [semiring R] [ordered_add_comm_monoid M] [module R M] : distrib_mul_action R (order_dual M) := { smul_add := @distrib_mul_action.smul_add R M _ _ _, smul_zero := @distrib_mul_action.smul_zero R M _ _ _ } instance [semiring R] [ordered_add_comm_monoid M] [module R M] : module R (order_dual M) := { add_smul := @module.add_smul R M _ _ _, zero_smul := @module.zero_smul R M _ _ _ } instance [ordered_semiring R] [ordered_add_comm_monoid M] [module R M] [ordered_module R M] : ordered_module R (order_dual M) := { smul_lt_smul_of_pos := λ a b, @ordered_module.smul_lt_smul_of_pos R M _ _ _ _ b a, lt_of_smul_lt_smul_of_pos := λ a b, @ordered_module.lt_of_smul_lt_smul_of_pos R M _ _ _ _ b a } end order_dual
cb8b74a767c10dbdfbe4c3758731aca956d68ed0
ebbdcbd7ddc89a9ef7c3b397b301d5f5272a918f
/qp/p0_stdlib.lean
570b1400006e56bbd96820ddbb52b26cf7e02808
[]
no_license
intoverflow/qvr
34b9ef23604738381ca20b7d622fd0399d88f2dd
0cfcd33fe4bf8d93851a00cec5bfd21e77105d74
refs/heads/master
1,616,591,570,371
1,492,575,772,000
1,492,575,772,000
80,061,627
0
0
null
null
null
null
UTF-8
Lean
false
false
167
lean
import .p0_stdlib.c0_misc import .p0_stdlib.c1_fin import .p0_stdlib.c2_finite_type import .p0_stdlib.c3_order import .p0_stdlib.c4_algebra import .p0_stdlib.c5_dlist
9fb7c238b1248c7f2db6667824aab5e812f911c5
5de7964e7bf47062fd89c1c93ee8e66af8e43c56
/config_backup/.config.lean
01e9555bf19fb9ff9cfa5557eff9dd6bc42cb3eb
[ "MIT" ]
permissive
doppelkalt/MT1300
6cec000163a56100c8e36069e41e553429cf8aae
bc252f1601748549ec0c936871ac05f243d1055d
refs/heads/main
1,678,470,446,990
1,613,995,552,000
1,613,995,552,000
341,185,676
10
0
MIT
1,613,995,253,000
1,613,995,253,000
null
UTF-8
Lean
false
false
248,661
lean
# # Automatically generated file; DO NOT EDIT. # OpenWrt Configuration # CONFIG_MODULES=y CONFIG_HAVE_DOT_CONFIG=y # CONFIG_TARGET_sunxi is not set # CONFIG_TARGET_apm821xx is not set # CONFIG_TARGET_ath25 is not set # CONFIG_TARGET_ar71xx is not set # CONFIG_TARGET_ath79 is not set # CONFIG_TARGET_bcm27xx is not set # CONFIG_TARGET_bcm53xx is not set # CONFIG_TARGET_bcm47xx is not set # CONFIG_TARGET_bcm63xx is not set # CONFIG_TARGET_cns3xxx is not set # CONFIG_TARGET_octeon is not set # CONFIG_TARGET_gemini is not set # CONFIG_TARGET_mpc85xx is not set # CONFIG_TARGET_imx6 is not set # CONFIG_TARGET_mxs is not set # CONFIG_TARGET_lantiq is not set # CONFIG_TARGET_malta is not set # CONFIG_TARGET_pistachio is not set # CONFIG_TARGET_mvebu is not set # CONFIG_TARGET_kirkwood is not set # CONFIG_TARGET_mediatek is not set CONFIG_TARGET_ramips=y # CONFIG_TARGET_at91 is not set # CONFIG_TARGET_rb532 is not set # CONFIG_TARGET_tegra is not set # CONFIG_TARGET_layerscape is not set # CONFIG_TARGET_octeontx is not set # CONFIG_TARGET_oxnas is not set # CONFIG_TARGET_armvirt is not set # CONFIG_TARGET_ipq40xx is not set # CONFIG_TARGET_ipq806x is not set # CONFIG_TARGET_ipq807x is not set # CONFIG_TARGET_rockchip is not set # CONFIG_TARGET_samsung is not set # CONFIG_TARGET_arc770 is not set # CONFIG_TARGET_archs38 is not set # CONFIG_TARGET_omap is not set # CONFIG_TARGET_uml is not set # CONFIG_TARGET_zynq is not set # CONFIG_TARGET_x86 is not set # CONFIG_TARGET_ramips_mt7620 is not set CONFIG_TARGET_ramips_mt7621=y # CONFIG_TARGET_ramips_mt76x8 is not set # CONFIG_TARGET_ramips_rt288x is not set # CONFIG_TARGET_ramips_rt305x is not set # CONFIG_TARGET_ramips_rt3883 is not set # CONFIG_TARGET_MULTI_PROFILE is not set # CONFIG_TARGET_ramips_mt7621_Default is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_adslr_g7 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_afoundry_ew1200 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_alfa-network_quad-e4g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac57u is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac65p is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac85p is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asiarf_ap7621-001 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asiarf_ap7621-nv1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-1166dhp is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-2533dhpl is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-600dhp is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xzwifi_creativebox-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-860l-b1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-867-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-878-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-882-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1167ghbk2-s is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1900gst is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-2533gst is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-2533gst2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_edimax_rg21s is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_edimax_ra21s is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_firefly_firewrt is not set CONFIG_TARGET_ramips_mt7621_DEVICE_glinet_gl-mt1300=y # CONFIG_TARGET_ramips_mt7621_DEVICE_gehua_ghl-r-001 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_gnubee_gb-pc1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_gnubee_gb-pc2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_hiwifi_hc5962 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax1167gr is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax1167gr2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax2033gr is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-dx1167r is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-gx300gr is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wnpr2600g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_jcg_jhr-ac876m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_jcg_y2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_jdcloud_re-sp-01b is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_ea7500-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_re6500 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mqmaker_witi is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mtc_wr1201 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mediatek_mt7621-eval-board is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mediatek_ap-mt7621a-v60 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-750gr3 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-m11g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-m33g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_motorola_mr2600 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_ex6150 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6700-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6220 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6260 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6350 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6800 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6850 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wac104 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wac124 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wndr3700-v5 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netis_wf2881 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_lenovo_newifi-d1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_d-team_newifi-d2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_d-team_pbr-m1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_phicomm_k2p is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_planex_vr500 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_storylink_sap-g3200u3 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_samknows_whitebox-v8 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_totolink_a7000r is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_re350-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_re650-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_telco-electronics_x1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_thunder_timecloud is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_edgerouter-x is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_edgerouter-x-sfp is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_unifi-nanohd is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_unielec_u7621-06-16m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_unielec_u7621-06-64m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_wevo_11acnas is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_wevo_w2914ns-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaoyu_xy-c5 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir3p is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir3g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir3g-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir4 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mi-router-ac2100 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_redmi-router-ac2100 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_youhua_wr1200js is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_youku_yk-l2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zio_freezio is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-we1326 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-we3526 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg2626 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg3526-16m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg3526-32m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iptime_a6ns-m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iptime_a8004t is not set CONFIG_HAS_SUBTARGETS=y CONFIG_HAS_DEVICES=y CONFIG_TARGET_BOARD="ramips" CONFIG_TARGET_SUBTARGET="mt7621" CONFIG_TARGET_PROFILE="DEVICE_glinet_gl-mt1300" CONFIG_TARGET_ARCH_PACKAGES="mipsel_24kc" CONFIG_DEFAULT_TARGET_OPTIMIZATION="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc" CONFIG_CPU_TYPE="24kc" CONFIG_LINUX_5_4=y CONFIG_DEFAULT_base-files=y CONFIG_DEFAULT_block-mount=y CONFIG_DEFAULT_busybox=y CONFIG_DEFAULT_ca-certificates=y CONFIG_DEFAULT_coremark=y CONFIG_DEFAULT_ddns-scripts_aliyun=y CONFIG_DEFAULT_ddns-scripts_dnspod=y CONFIG_DEFAULT_default-settings=y CONFIG_DEFAULT_dnsmasq-full=y CONFIG_DEFAULT_dropbear=y CONFIG_DEFAULT_firewall=y CONFIG_DEFAULT_fstools=y CONFIG_DEFAULT_iptables=y CONFIG_DEFAULT_kmod-gpio-button-hotplug=y CONFIG_DEFAULT_kmod-ipt-raw=y CONFIG_DEFAULT_kmod-leds-gpio=y CONFIG_DEFAULT_kmod-mt7615-firmware=y CONFIG_DEFAULT_kmod-mt7615e=y CONFIG_DEFAULT_kmod-nf-nathelper=y CONFIG_DEFAULT_kmod-nf-nathelper-extra=y CONFIG_DEFAULT_kmod-usb3=y CONFIG_DEFAULT_libc=y CONFIG_DEFAULT_libgcc=y CONFIG_DEFAULT_libustream-openssl=y CONFIG_DEFAULT_logd=y CONFIG_DEFAULT_luci=y CONFIG_DEFAULT_luci-app-accesscontrol=y CONFIG_DEFAULT_luci-app-arpbind=y CONFIG_DEFAULT_luci-app-autoreboot=y CONFIG_DEFAULT_luci-app-cpufreq=y CONFIG_DEFAULT_luci-app-ddns=y CONFIG_DEFAULT_luci-app-filetransfer=y CONFIG_DEFAULT_luci-app-flowoffload=y CONFIG_DEFAULT_luci-app-nlbwmon=y CONFIG_DEFAULT_luci-app-ramfree=y CONFIG_DEFAULT_luci-app-ssr-plus=y CONFIG_DEFAULT_luci-app-unblockmusic=y CONFIG_DEFAULT_luci-app-upnp=y CONFIG_DEFAULT_luci-app-vlmcsd=y CONFIG_DEFAULT_luci-app-vsftpd=y CONFIG_DEFAULT_luci-app-webadmin=y CONFIG_DEFAULT_luci-app-wol=y CONFIG_DEFAULT_mtd=y CONFIG_DEFAULT_netifd=y CONFIG_DEFAULT_opkg=y CONFIG_DEFAULT_ppp=y CONFIG_DEFAULT_ppp-mod-pppoe=y CONFIG_DEFAULT_swconfig=y CONFIG_DEFAULT_uci=y CONFIG_DEFAULT_uclient-fetch=y CONFIG_DEFAULT_urandom-seed=y CONFIG_DEFAULT_urngd=y CONFIG_DEFAULT_wget=y CONFIG_AUDIO_SUPPORT=y CONFIG_GPIO_SUPPORT=y CONFIG_PCI_SUPPORT=y CONFIG_USB_SUPPORT=y CONFIG_RTC_SUPPORT=y CONFIG_USES_DEVICETREE=y CONFIG_USES_INITRAMFS=y CONFIG_USES_SQUASHFS=y CONFIG_USES_MINOR=y CONFIG_HAS_MIPS16=y CONFIG_NAND_SUPPORT=y CONFIG_mipsel=y CONFIG_ARCH="mipsel" # # Target Images # CONFIG_TARGET_ROOTFS_INITRAMFS=y # CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2 is not set CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA=y # CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4 is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ is not set CONFIG_EXTERNAL_CPIO="" # CONFIG_TARGET_INITRAMFS_FORCE is not set # # Root filesystem archives # # CONFIG_TARGET_ROOTFS_CPIOGZ is not set # CONFIG_TARGET_ROOTFS_TARGZ is not set # # Root filesystem images # # CONFIG_TARGET_ROOTFS_EXT4FS is not set CONFIG_TARGET_ROOTFS_SQUASHFS=y CONFIG_TARGET_SQUASHFS_BLOCK_SIZE=256 CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP=y CONFIG_TARGET_UBIFS_JOURNAL_SIZE="" # # Image Options # # end of Target Images # # Global build settings # # CONFIG_JSON_OVERVIEW_IMAGE_INFO is not set # CONFIG_ALL_NONSHARED is not set # CONFIG_ALL_KMODS is not set # CONFIG_ALL is not set # CONFIG_BUILDBOT is not set CONFIG_SIGNED_PACKAGES=y CONFIG_SIGNATURE_CHECK=y # # General build options # # CONFIG_DISPLAY_SUPPORT is not set # CONFIG_BUILD_PATENTED is not set # CONFIG_BUILD_NLS is not set CONFIG_SHADOW_PASSWORDS=y # CONFIG_CLEAN_IPKG is not set # CONFIG_IPK_FILES_CHECKSUMS is not set # CONFIG_INCLUDE_CONFIG is not set # CONFIG_COLLECT_KERNEL_DEBUG is not set # # Kernel build options # CONFIG_KERNEL_BUILD_USER="" CONFIG_KERNEL_BUILD_DOMAIN="" CONFIG_KERNEL_PRINTK=y CONFIG_KERNEL_CRASHLOG=y CONFIG_KERNEL_SWAP=y CONFIG_KERNEL_DEBUG_FS=y CONFIG_KERNEL_MIPS_FPU_EMULATOR=y CONFIG_KERNEL_MIPS_FP_SUPPORT=y # CONFIG_KERNEL_PERF_EVENTS is not set # CONFIG_KERNEL_PROFILING is not set # CONFIG_KERNEL_UBSAN is not set # CONFIG_KERNEL_KCOV is not set # CONFIG_KERNEL_TASKSTATS is not set CONFIG_KERNEL_KALLSYMS=y # CONFIG_KERNEL_FTRACE is not set CONFIG_KERNEL_DEBUG_KERNEL=y CONFIG_KERNEL_DEBUG_INFO=y # CONFIG_KERNEL_DYNAMIC_DEBUG is not set # CONFIG_KERNEL_KPROBES is not set CONFIG_KERNEL_AIO=y CONFIG_KERNEL_FHANDLE=y CONFIG_KERNEL_FANOTIFY=y # CONFIG_KERNEL_BLK_DEV_BSG is not set CONFIG_KERNEL_MAGIC_SYSRQ=y # CONFIG_KERNEL_DEBUG_PINCTRL is not set # CONFIG_KERNEL_DEBUG_GPIO is not set CONFIG_KERNEL_COREDUMP=y CONFIG_KERNEL_ELF_CORE=y # CONFIG_KERNEL_PROVE_LOCKING is not set # CONFIG_KERNEL_LOCKUP_DETECTOR is not set # CONFIG_KERNEL_DETECT_HUNG_TASK is not set # CONFIG_KERNEL_WQ_WATCHDOG is not set # CONFIG_KERNEL_DEBUG_ATOMIC_SLEEP is not set # CONFIG_KERNEL_DEBUG_VM is not set CONFIG_KERNEL_PRINTK_TIME=y # CONFIG_KERNEL_SLABINFO is not set # CONFIG_KERNEL_PROC_PAGE_MONITOR is not set # CONFIG_KERNEL_KEXEC is not set # CONFIG_USE_RFKILL is not set # CONFIG_USE_SPARSE is not set # CONFIG_KERNEL_DEVTMPFS is not set # CONFIG_KERNEL_KEYS is not set CONFIG_KERNEL_CGROUPS=y # CONFIG_KERNEL_CGROUP_DEBUG is not set CONFIG_KERNEL_FREEZER=y CONFIG_KERNEL_CGROUP_FREEZER=y CONFIG_KERNEL_CGROUP_DEVICE=y CONFIG_KERNEL_CGROUP_PIDS=y CONFIG_KERNEL_CPUSETS=y # CONFIG_KERNEL_PROC_PID_CPUSET is not set CONFIG_KERNEL_CGROUP_CPUACCT=y CONFIG_KERNEL_RESOURCE_COUNTERS=y CONFIG_KERNEL_MM_OWNER=y CONFIG_KERNEL_MEMCG=y # CONFIG_KERNEL_MEMCG_SWAP is not set CONFIG_KERNEL_MEMCG_KMEM=y # CONFIG_KERNEL_CGROUP_PERF is not set CONFIG_KERNEL_CGROUP_SCHED=y CONFIG_KERNEL_FAIR_GROUP_SCHED=y # CONFIG_KERNEL_CFS_BANDWIDTH is not set CONFIG_KERNEL_RT_GROUP_SCHED=y CONFIG_KERNEL_BLK_CGROUP=y # CONFIG_KERNEL_CFQ_GROUP_IOSCHED is not set # CONFIG_KERNEL_BLK_DEV_THROTTLING is not set # CONFIG_KERNEL_DEBUG_BLK_CGROUP is not set CONFIG_KERNEL_NET_CLS_CGROUP=y CONFIG_KERNEL_CGROUP_NET_PRIO=y CONFIG_KERNEL_NAMESPACES=y CONFIG_KERNEL_UTS_NS=y CONFIG_KERNEL_IPC_NS=y CONFIG_KERNEL_USER_NS=y CONFIG_KERNEL_PID_NS=y CONFIG_KERNEL_NET_NS=y CONFIG_KERNEL_DEVPTS_MULTIPLE_INSTANCES=y CONFIG_KERNEL_POSIX_MQUEUE=y CONFIG_KERNEL_SECCOMP_FILTER=y CONFIG_KERNEL_SECCOMP=y CONFIG_KERNEL_IP_MROUTE=y CONFIG_KERNEL_IPV6=y CONFIG_KERNEL_IPV6_MULTIPLE_TABLES=y CONFIG_KERNEL_IPV6_SUBTREES=y CONFIG_KERNEL_IPV6_MROUTE=y # CONFIG_KERNEL_IPV6_PIMSM_V2 is not set # CONFIG_KERNEL_IP_PNP is not set # # Filesystem ACL and attr support options # # CONFIG_USE_FS_ACL_ATTR is not set # CONFIG_KERNEL_FS_POSIX_ACL is not set # CONFIG_KERNEL_BTRFS_FS_POSIX_ACL is not set # CONFIG_KERNEL_EXT4_FS_POSIX_ACL is not set # CONFIG_KERNEL_F2FS_FS_POSIX_ACL is not set # CONFIG_KERNEL_JFFS2_FS_POSIX_ACL is not set # CONFIG_KERNEL_TMPFS_POSIX_ACL is not set # CONFIG_KERNEL_CIFS_ACL is not set # CONFIG_KERNEL_HFS_FS_POSIX_ACL is not set # CONFIG_KERNEL_HFSPLUS_FS_POSIX_ACL is not set # CONFIG_KERNEL_NFS_ACL_SUPPORT is not set # CONFIG_KERNEL_NFS_V3_ACL_SUPPORT is not set # CONFIG_KERNEL_NFSD_V2_ACL_SUPPORT is not set # CONFIG_KERNEL_NFSD_V3_ACL_SUPPORT is not set # CONFIG_KERNEL_REISER_FS_POSIX_ACL is not set # CONFIG_KERNEL_XFS_POSIX_ACL is not set # CONFIG_KERNEL_JFS_POSIX_ACL is not set # end of Filesystem ACL and attr support options # CONFIG_KERNEL_DEVMEM is not set # CONFIG_KERNEL_DEVKMEM is not set CONFIG_KERNEL_SQUASHFS_FRAGMENT_CACHE_SIZE=3 CONFIG_KERNEL_CC_OPTIMIZE_FOR_PERFORMANCE=y # CONFIG_KERNEL_CC_OPTIMIZE_FOR_SIZE is not set # end of Kernel build options # # Package build options # # CONFIG_DEBUG is not set CONFIG_IPV6=y # # Stripping options # # CONFIG_NO_STRIP is not set # CONFIG_USE_STRIP is not set CONFIG_USE_SSTRIP=y # CONFIG_STRIP_KERNEL_EXPORTS is not set # CONFIG_USE_MKLIBS is not set CONFIG_USE_UCLIBCXX=y # CONFIG_USE_LIBCXX is not set # CONFIG_USE_LIBSTDCXX is not set # # Hardening build options # CONFIG_PKG_CHECK_FORMAT_SECURITY=y # CONFIG_PKG_ASLR_PIE_NONE is not set CONFIG_PKG_ASLR_PIE_REGULAR=y # CONFIG_PKG_ASLR_PIE_ALL is not set # CONFIG_PKG_CC_STACKPROTECTOR_NONE is not set CONFIG_PKG_CC_STACKPROTECTOR_REGULAR=y # CONFIG_KERNEL_CC_STACKPROTECTOR_NONE is not set CONFIG_KERNEL_CC_STACKPROTECTOR_REGULAR=y # CONFIG_KERNEL_CC_STACKPROTECTOR_STRONG is not set CONFIG_KERNEL_STACKPROTECTOR=y # CONFIG_KERNEL_STACKPROTECTOR_STRONG is not set # CONFIG_PKG_FORTIFY_SOURCE_NONE is not set CONFIG_PKG_FORTIFY_SOURCE_1=y # CONFIG_PKG_FORTIFY_SOURCE_2 is not set # CONFIG_PKG_RELRO_NONE is not set # CONFIG_PKG_RELRO_PARTIAL is not set CONFIG_PKG_RELRO_FULL=y # end of Global build settings # CONFIG_DEVEL is not set # CONFIG_BROKEN is not set CONFIG_BINARY_FOLDER="" CONFIG_DOWNLOAD_FOLDER="" CONFIG_LOCALMIRROR="" CONFIG_AUTOREBUILD=y # CONFIG_AUTOREMOVE is not set CONFIG_BUILD_SUFFIX="" CONFIG_TARGET_ROOTFS_DIR="" # CONFIG_CCACHE is not set CONFIG_EXTERNAL_KERNEL_TREE="" CONFIG_KERNEL_GIT_CLONE_URI="" CONFIG_BUILD_LOG_DIR="" CONFIG_EXTRA_OPTIMIZATION="-fno-caller-saves -fno-plt" CONFIG_TARGET_OPTIMIZATION="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc" CONFIG_SOFT_FLOAT=y CONFIG_USE_MIPS16=y # CONFIG_EXTRA_TARGET_ARCH is not set CONFIG_EXTRA_BINUTILS_CONFIG_OPTIONS="" CONFIG_EXTRA_GCC_CONFIG_OPTIONS="" # CONFIG_GCC_DEFAULT_PIE is not set # CONFIG_GCC_DEFAULT_SSP is not set # CONFIG_SJLJ_EXCEPTIONS is not set # CONFIG_INSTALL_GFORTRAN is not set CONFIG_GDB=y CONFIG_USE_MUSL=y CONFIG_SSP_SUPPORT=y CONFIG_BINUTILS_VERSION_2_31_1=y CONFIG_BINUTILS_VERSION="2.31.1" CONFIG_GCC_VERSION="8.4.0" # CONFIG_GCC_USE_IREMAP is not set CONFIG_LIBC="musl" CONFIG_TARGET_SUFFIX="musl" # CONFIG_IB is not set # CONFIG_SDK is not set # CONFIG_MAKE_TOOLCHAIN is not set # CONFIG_IMAGEOPT is not set # CONFIG_PREINITOPT is not set CONFIG_TARGET_PREINIT_SUPPRESS_STDERR=y # CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE is not set CONFIG_TARGET_PREINIT_TIMEOUT=2 # CONFIG_TARGET_PREINIT_SHOW_NETMSG is not set # CONFIG_TARGET_PREINIT_SUPPRESS_FAILSAFE_NETMSG is not set CONFIG_TARGET_PREINIT_IFNAME="" CONFIG_TARGET_PREINIT_IP="192.168.1.1" CONFIG_TARGET_PREINIT_NETMASK="255.255.255.0" CONFIG_TARGET_PREINIT_BROADCAST="192.168.1.255" # CONFIG_INITOPT is not set CONFIG_TARGET_INIT_PATH="/usr/sbin:/usr/bin:/sbin:/bin" CONFIG_TARGET_INIT_ENV="" CONFIG_TARGET_INIT_CMD="/sbin/init" CONFIG_TARGET_INIT_SUPPRESS_STDERR=y # CONFIG_VERSIONOPT is not set CONFIG_PER_FEED_REPO=y CONFIG_FEED_packages=y CONFIG_FEED_luci=y CONFIG_FEED_routing=y CONFIG_FEED_telephony=y CONFIG_FEED_freifunk=y # # Base system # # CONFIG_PACKAGE_attendedsysupgrade-common is not set # CONFIG_PACKAGE_auc is not set CONFIG_PACKAGE_base-files=y CONFIG_PACKAGE_block-mount=y # CONFIG_PACKAGE_blockd is not set # CONFIG_PACKAGE_bridge is not set CONFIG_PACKAGE_busybox=y # CONFIG_BUSYBOX_CUSTOM is not set CONFIG_BUSYBOX_DEFAULT_HAVE_DOT_CONFIG=y # CONFIG_BUSYBOX_DEFAULT_DESKTOP is not set # CONFIG_BUSYBOX_DEFAULT_EXTRA_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_FEDORA_COMPAT is not set CONFIG_BUSYBOX_DEFAULT_INCLUDE_SUSv2=y CONFIG_BUSYBOX_DEFAULT_LONG_OPTS=y CONFIG_BUSYBOX_DEFAULT_SHOW_USAGE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE_USAGE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_COMPRESS_USAGE is not set CONFIG_BUSYBOX_DEFAULT_LFS=y # CONFIG_BUSYBOX_DEFAULT_PAM is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_DEVPTS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UTMP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WTMP is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDFILE=y CONFIG_BUSYBOX_DEFAULT_PID_FILE_PATH="/var/run" # CONFIG_BUSYBOX_DEFAULT_BUSYBOX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SHOW_SCRIPT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSTALLER is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_NO_USR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID_CONFIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID_CONFIG_QUIET is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_PREFER_APPLETS=y CONFIG_BUSYBOX_DEFAULT_BUSYBOX_EXEC_PATH="/proc/self/exe" # CONFIG_BUSYBOX_DEFAULT_SELINUX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CLEAN_UP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOG_INFO is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOG=y CONFIG_BUSYBOX_DEFAULT_PLATFORM_LINUX=y # CONFIG_BUSYBOX_DEFAULT_STATIC is not set # CONFIG_BUSYBOX_DEFAULT_PIE is not set # CONFIG_BUSYBOX_DEFAULT_NOMMU is not set # CONFIG_BUSYBOX_DEFAULT_BUILD_LIBBUSYBOX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LIBBUSYBOX_STATIC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INDIVIDUAL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SHARED_BUSYBOX is not set CONFIG_BUSYBOX_DEFAULT_CROSS_COMPILER_PREFIX="" CONFIG_BUSYBOX_DEFAULT_SYSROOT="" CONFIG_BUSYBOX_DEFAULT_EXTRA_CFLAGS="" CONFIG_BUSYBOX_DEFAULT_EXTRA_LDFLAGS="" CONFIG_BUSYBOX_DEFAULT_EXTRA_LDLIBS="" # CONFIG_BUSYBOX_DEFAULT_USE_PORTABLE_CODE is not set # CONFIG_BUSYBOX_DEFAULT_STACK_OPTIMIZATION_386 is not set CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_SYMLINKS=y # CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_HARDLINKS is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_SCRIPT_WRAPPERS is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_DONT is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_SYMLINK is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_HARDLINK is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set CONFIG_BUSYBOX_DEFAULT_PREFIX="./_install" # CONFIG_BUSYBOX_DEFAULT_DEBUG is not set # CONFIG_BUSYBOX_DEFAULT_DEBUG_PESSIMIZE is not set # CONFIG_BUSYBOX_DEFAULT_DEBUG_SANITIZE is not set # CONFIG_BUSYBOX_DEFAULT_UNIT_TEST is not set # CONFIG_BUSYBOX_DEFAULT_WERROR is not set CONFIG_BUSYBOX_DEFAULT_NO_DEBUG_LIB=y # CONFIG_BUSYBOX_DEFAULT_DMALLOC is not set # CONFIG_BUSYBOX_DEFAULT_EFENCE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_BSS_TAIL is not set # CONFIG_BUSYBOX_DEFAULT_FLOAT_DURATION is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RTMINMAX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_USE_MALLOC is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_GO_ON_STACK=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_GO_IN_BSS is not set CONFIG_BUSYBOX_DEFAULT_PASSWORD_MINLEN=6 CONFIG_BUSYBOX_DEFAULT_MD5_SMALL=1 CONFIG_BUSYBOX_DEFAULT_SHA3_SMALL=1 CONFIG_BUSYBOX_DEFAULT_FEATURE_FAST_TOP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_ETC_NETWORKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ETC_SERVICES is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING=y CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_MAX_LEN=512 # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_VI is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_HISTORY=256 # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_SAVEHISTORY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_SAVE_ON_EXIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_REVERSE_SEARCH is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAB_COMPLETION=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_USERNAME_COMPLETION is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_FANCY_PROMPT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_WINCH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_ASK_TERMINAL is not set # CONFIG_BUSYBOX_DEFAULT_LOCALE_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_USING_LOCALE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_UNICODE_IN_ENV is not set CONFIG_BUSYBOX_DEFAULT_SUBST_WCHAR=0 CONFIG_BUSYBOX_DEFAULT_LAST_SUPPORTED_WCHAR=0 # CONFIG_BUSYBOX_DEFAULT_UNICODE_COMBINING_WCHARS is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_WIDE_WCHARS is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_BIDI_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_NEUTRAL_TABLE is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_PRESERVE_BROKEN is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_NON_POSIX_CP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE_CP_MESSAGE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_SENDFILE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_COPYBUF_KB=4 # CONFIG_BUSYBOX_DEFAULT_FEATURE_SKIP_ROOTFS is not set CONFIG_BUSYBOX_DEFAULT_MONOTONIC_SYSCALL=y CONFIG_BUSYBOX_DEFAULT_IOCTL_HEX2STR_ERROR=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_HWIB is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_XZ is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_LZMA is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_BZ2 is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_GZ=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_Z is not set # CONFIG_BUSYBOX_DEFAULT_AR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_AR_LONG_FILENAMES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_AR_CREATE is not set # CONFIG_BUSYBOX_DEFAULT_UNCOMPRESS is not set CONFIG_BUSYBOX_DEFAULT_GUNZIP=y CONFIG_BUSYBOX_DEFAULT_ZCAT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_GUNZIP_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_BUNZIP2=y CONFIG_BUSYBOX_DEFAULT_BZCAT=y # CONFIG_BUSYBOX_DEFAULT_UNLZMA is not set # CONFIG_BUSYBOX_DEFAULT_LZCAT is not set # CONFIG_BUSYBOX_DEFAULT_LZMA is not set # CONFIG_BUSYBOX_DEFAULT_UNXZ is not set # CONFIG_BUSYBOX_DEFAULT_XZCAT is not set # CONFIG_BUSYBOX_DEFAULT_XZ is not set # CONFIG_BUSYBOX_DEFAULT_BZIP2 is not set CONFIG_BUSYBOX_DEFAULT_BZIP2_SMALL=0 CONFIG_BUSYBOX_DEFAULT_FEATURE_BZIP2_DECOMPRESS=y # CONFIG_BUSYBOX_DEFAULT_CPIO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CPIO_O is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CPIO_P is not set # CONFIG_BUSYBOX_DEFAULT_DPKG is not set # CONFIG_BUSYBOX_DEFAULT_DPKG_DEB is not set CONFIG_BUSYBOX_DEFAULT_GZIP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_GZIP_FAST=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_LEVELS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_DECOMPRESS=y # CONFIG_BUSYBOX_DEFAULT_LZOP is not set # CONFIG_BUSYBOX_DEFAULT_UNLZOP is not set # CONFIG_BUSYBOX_DEFAULT_LZOPCAT is not set # CONFIG_BUSYBOX_DEFAULT_LZOP_COMPR_HIGH is not set # CONFIG_BUSYBOX_DEFAULT_RPM is not set # CONFIG_BUSYBOX_DEFAULT_RPM2CPIO is not set CONFIG_BUSYBOX_DEFAULT_TAR=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_CREATE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_AUTODETECT is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_FROM=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_OLDGNU_COMPATIBILITY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_OLDSUN_COMPATIBILITY is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_GNU_EXTENSIONS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_TO_COMMAND is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_UNAME_GNAME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_NOPRESERVE_TIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_SELINUX is not set # CONFIG_BUSYBOX_DEFAULT_UNZIP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_CDF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_BZIP2 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_LZMA is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_XZ is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LZMA_FAST is not set CONFIG_BUSYBOX_DEFAULT_BASENAME=y CONFIG_BUSYBOX_DEFAULT_CAT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CATN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CATV is not set CONFIG_BUSYBOX_DEFAULT_CHGRP=y CONFIG_BUSYBOX_DEFAULT_CHMOD=y CONFIG_BUSYBOX_DEFAULT_CHOWN=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHOWN_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_CHROOT=y # CONFIG_BUSYBOX_DEFAULT_CKSUM is not set # CONFIG_BUSYBOX_DEFAULT_COMM is not set CONFIG_BUSYBOX_DEFAULT_CP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CP_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CP_REFLINK is not set CONFIG_BUSYBOX_DEFAULT_CUT=y CONFIG_BUSYBOX_DEFAULT_DATE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_ISOFMT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_NANO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_COMPAT is not set CONFIG_BUSYBOX_DEFAULT_DD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_SIGNAL_HANDLING=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_THIRD_STATUS_LINE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_IBS_OBS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_STATUS is not set CONFIG_BUSYBOX_DEFAULT_DF=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DF_FANCY is not set CONFIG_BUSYBOX_DEFAULT_DIRNAME=y # CONFIG_BUSYBOX_DEFAULT_DOS2UNIX is not set # CONFIG_BUSYBOX_DEFAULT_UNIX2DOS is not set CONFIG_BUSYBOX_DEFAULT_DU=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K=y CONFIG_BUSYBOX_DEFAULT_ECHO=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_ECHO=y CONFIG_BUSYBOX_DEFAULT_ENV=y # CONFIG_BUSYBOX_DEFAULT_EXPAND is not set # CONFIG_BUSYBOX_DEFAULT_UNEXPAND is not set CONFIG_BUSYBOX_DEFAULT_EXPR=y CONFIG_BUSYBOX_DEFAULT_EXPR_MATH_SUPPORT_64=y # CONFIG_BUSYBOX_DEFAULT_FACTOR is not set CONFIG_BUSYBOX_DEFAULT_FALSE=y # CONFIG_BUSYBOX_DEFAULT_FOLD is not set CONFIG_BUSYBOX_DEFAULT_HEAD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_HEAD=y # CONFIG_BUSYBOX_DEFAULT_HOSTID is not set CONFIG_BUSYBOX_DEFAULT_ID=y # CONFIG_BUSYBOX_DEFAULT_GROUPS is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSTALL_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_LINK is not set CONFIG_BUSYBOX_DEFAULT_LN=y # CONFIG_BUSYBOX_DEFAULT_LOGNAME is not set CONFIG_BUSYBOX_DEFAULT_LS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_FILETYPES=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_FOLLOWLINKS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_RECURSIVE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_WIDTH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_SORTFILES=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_TIMESTAMPS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_USERNAME=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_COLOR=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_COLOR_IS_DEFAULT=y CONFIG_BUSYBOX_DEFAULT_MD5SUM=y # CONFIG_BUSYBOX_DEFAULT_SHA1SUM is not set CONFIG_BUSYBOX_DEFAULT_SHA256SUM=y # CONFIG_BUSYBOX_DEFAULT_SHA512SUM is not set # CONFIG_BUSYBOX_DEFAULT_SHA3SUM is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MD5_SHA1_SUM_CHECK=y CONFIG_BUSYBOX_DEFAULT_MKDIR=y CONFIG_BUSYBOX_DEFAULT_MKFIFO=y CONFIG_BUSYBOX_DEFAULT_MKNOD=y CONFIG_BUSYBOX_DEFAULT_MKTEMP=y CONFIG_BUSYBOX_DEFAULT_MV=y CONFIG_BUSYBOX_DEFAULT_NICE=y # CONFIG_BUSYBOX_DEFAULT_NL is not set # CONFIG_BUSYBOX_DEFAULT_NOHUP is not set # CONFIG_BUSYBOX_DEFAULT_NPROC is not set # CONFIG_BUSYBOX_DEFAULT_OD is not set # CONFIG_BUSYBOX_DEFAULT_PASTE is not set # CONFIG_BUSYBOX_DEFAULT_PRINTENV is not set CONFIG_BUSYBOX_DEFAULT_PRINTF=y CONFIG_BUSYBOX_DEFAULT_PWD=y CONFIG_BUSYBOX_DEFAULT_READLINK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_READLINK_FOLLOW=y # CONFIG_BUSYBOX_DEFAULT_REALPATH is not set CONFIG_BUSYBOX_DEFAULT_RM=y CONFIG_BUSYBOX_DEFAULT_RMDIR=y CONFIG_BUSYBOX_DEFAULT_SEQ=y # CONFIG_BUSYBOX_DEFAULT_SHRED is not set # CONFIG_BUSYBOX_DEFAULT_SHUF is not set CONFIG_BUSYBOX_DEFAULT_SLEEP=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_SLEEP=y CONFIG_BUSYBOX_DEFAULT_SORT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SORT_BIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SORT_OPTIMIZE_MEMORY is not set # CONFIG_BUSYBOX_DEFAULT_SPLIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SPLIT_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_STAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_STAT_FORMAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_STAT_FILESYSTEM is not set # CONFIG_BUSYBOX_DEFAULT_STTY is not set # CONFIG_BUSYBOX_DEFAULT_SUM is not set CONFIG_BUSYBOX_DEFAULT_SYNC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYNC_FANCY is not set CONFIG_BUSYBOX_DEFAULT_FSYNC=y # CONFIG_BUSYBOX_DEFAULT_TAC is not set CONFIG_BUSYBOX_DEFAULT_TAIL=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_TAIL=y CONFIG_BUSYBOX_DEFAULT_TEE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TEE_USE_BLOCK_IO=y CONFIG_BUSYBOX_DEFAULT_TEST=y CONFIG_BUSYBOX_DEFAULT_TEST1=y CONFIG_BUSYBOX_DEFAULT_TEST2=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TEST_64=y # CONFIG_BUSYBOX_DEFAULT_TIMEOUT is not set CONFIG_BUSYBOX_DEFAULT_TOUCH=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOUCH_NODEREF is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TOUCH_SUSV3=y CONFIG_BUSYBOX_DEFAULT_TR=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TR_CLASSES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TR_EQUIV is not set CONFIG_BUSYBOX_DEFAULT_TRUE=y # CONFIG_BUSYBOX_DEFAULT_TRUNCATE is not set # CONFIG_BUSYBOX_DEFAULT_TTY is not set CONFIG_BUSYBOX_DEFAULT_UNAME=y CONFIG_BUSYBOX_DEFAULT_UNAME_OSNAME="GNU/Linux" # CONFIG_BUSYBOX_DEFAULT_BB_ARCH is not set CONFIG_BUSYBOX_DEFAULT_UNIQ=y # CONFIG_BUSYBOX_DEFAULT_UNLINK is not set # CONFIG_BUSYBOX_DEFAULT_USLEEP is not set # CONFIG_BUSYBOX_DEFAULT_UUDECODE is not set # CONFIG_BUSYBOX_DEFAULT_BASE64 is not set # CONFIG_BUSYBOX_DEFAULT_UUENCODE is not set CONFIG_BUSYBOX_DEFAULT_WC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_WC_LARGE is not set # CONFIG_BUSYBOX_DEFAULT_WHO is not set # CONFIG_BUSYBOX_DEFAULT_W is not set # CONFIG_BUSYBOX_DEFAULT_USERS is not set # CONFIG_BUSYBOX_DEFAULT_WHOAMI is not set CONFIG_BUSYBOX_DEFAULT_YES=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_PRESERVE_HARDLINKS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_HUMAN_READABLE=y # CONFIG_BUSYBOX_DEFAULT_CHVT is not set CONFIG_BUSYBOX_DEFAULT_CLEAR=y # CONFIG_BUSYBOX_DEFAULT_DEALLOCVT is not set # CONFIG_BUSYBOX_DEFAULT_DUMPKMAP is not set # CONFIG_BUSYBOX_DEFAULT_FGCONSOLE is not set # CONFIG_BUSYBOX_DEFAULT_KBD_MODE is not set # CONFIG_BUSYBOX_DEFAULT_LOADFONT is not set # CONFIG_BUSYBOX_DEFAULT_SETFONT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETFONT_TEXTUAL_MAP is not set CONFIG_BUSYBOX_DEFAULT_DEFAULT_SETFONT_DIR="" # CONFIG_BUSYBOX_DEFAULT_FEATURE_LOADFONT_PSF2 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LOADFONT_RAW is not set # CONFIG_BUSYBOX_DEFAULT_LOADKMAP is not set # CONFIG_BUSYBOX_DEFAULT_OPENVT is not set CONFIG_BUSYBOX_DEFAULT_RESET=y # CONFIG_BUSYBOX_DEFAULT_RESIZE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RESIZE_PRINT is not set # CONFIG_BUSYBOX_DEFAULT_SETCONSOLE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETCONSOLE_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_SETKEYCODES is not set # CONFIG_BUSYBOX_DEFAULT_SETLOGCONS is not set # CONFIG_BUSYBOX_DEFAULT_SHOWKEY is not set # CONFIG_BUSYBOX_DEFAULT_PIPE_PROGRESS is not set # CONFIG_BUSYBOX_DEFAULT_RUN_PARTS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RUN_PARTS_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RUN_PARTS_FANCY is not set CONFIG_BUSYBOX_DEFAULT_START_STOP_DAEMON=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_START_STOP_DAEMON_FANCY is not set CONFIG_BUSYBOX_DEFAULT_WHICH=y # CONFIG_BUSYBOX_DEFAULT_MINIPS is not set # CONFIG_BUSYBOX_DEFAULT_NUKE is not set # CONFIG_BUSYBOX_DEFAULT_RESUME is not set # CONFIG_BUSYBOX_DEFAULT_RUN_INIT is not set CONFIG_BUSYBOX_DEFAULT_AWK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_AWK_LIBM=y CONFIG_BUSYBOX_DEFAULT_FEATURE_AWK_GNU_EXTENSIONS=y CONFIG_BUSYBOX_DEFAULT_CMP=y # CONFIG_BUSYBOX_DEFAULT_DIFF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DIFF_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DIFF_DIR is not set # CONFIG_BUSYBOX_DEFAULT_ED is not set # CONFIG_BUSYBOX_DEFAULT_PATCH is not set CONFIG_BUSYBOX_DEFAULT_SED=y CONFIG_BUSYBOX_DEFAULT_VI=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_MAX_LEN=1024 # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_8BIT is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_COLON=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_YANKMARK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SEARCH=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_REGEX_SEARCH is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_USE_SIGNALS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_DOT_CMD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_READONLY=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SETOPTS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SET=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_WIN_RESIZE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_ASK_TERMINAL=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO_QUEUE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO_QUEUE_MAX=0 CONFIG_BUSYBOX_DEFAULT_FEATURE_ALLOW_EXEC=y CONFIG_BUSYBOX_DEFAULT_FIND=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PRINT0=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MTIME=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MMIN is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PERM=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_TYPE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXECUTABLE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_XDEV=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MAXDEPTH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_NEWER=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_INUM is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXEC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXEC_PLUS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_USER=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_GROUP=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_NOT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_DEPTH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PAREN=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_SIZE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PRUNE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_QUIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_DELETE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PATH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_REGEX=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_CONTEXT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_LINKS is not set CONFIG_BUSYBOX_DEFAULT_GREP=y CONFIG_BUSYBOX_DEFAULT_EGREP=y CONFIG_BUSYBOX_DEFAULT_FGREP=y CONFIG_BUSYBOX_DEFAULT_FEATURE_GREP_CONTEXT=y CONFIG_BUSYBOX_DEFAULT_XARGS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_CONFIRMATION=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_QUOTES=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_TERMOPT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_ZERO_TERM=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_REPL_STR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_PARALLEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_ARGS_FILE is not set # CONFIG_BUSYBOX_DEFAULT_BOOTCHARTD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BOOTCHARTD_BLOATED_HEADER is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BOOTCHARTD_CONFIG_FILE is not set CONFIG_BUSYBOX_DEFAULT_HALT=y CONFIG_BUSYBOX_DEFAULT_POWEROFF=y CONFIG_BUSYBOX_DEFAULT_REBOOT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_WAIT_FOR_INIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CALL_TELINIT is not set CONFIG_BUSYBOX_DEFAULT_TELINIT_PATH="" # CONFIG_BUSYBOX_DEFAULT_INIT is not set # CONFIG_BUSYBOX_DEFAULT_LINUXRC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_INITTAB is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_KILL_REMOVED is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_KILL_DELAY=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_SCTTY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_SYSLOG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_QUIET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_COREDUMPS is not set CONFIG_BUSYBOX_DEFAULT_INIT_TERMINAL_TYPE="" # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_MODIFY_CMDLINE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SHADOWPASSWDS=y # CONFIG_BUSYBOX_DEFAULT_USE_BB_PWD_GRP is not set # CONFIG_BUSYBOX_DEFAULT_USE_BB_SHADOW is not set # CONFIG_BUSYBOX_DEFAULT_USE_BB_CRYPT is not set # CONFIG_BUSYBOX_DEFAULT_USE_BB_CRYPT_SHA is not set # CONFIG_BUSYBOX_DEFAULT_ADD_SHELL is not set # CONFIG_BUSYBOX_DEFAULT_REMOVE_SHELL is not set # CONFIG_BUSYBOX_DEFAULT_ADDGROUP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ADDUSER_TO_GROUP is not set # CONFIG_BUSYBOX_DEFAULT_ADDUSER is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_NAMES is not set CONFIG_BUSYBOX_DEFAULT_LAST_ID=0 CONFIG_BUSYBOX_DEFAULT_FIRST_SYSTEM_ID=0 CONFIG_BUSYBOX_DEFAULT_LAST_SYSTEM_ID=0 # CONFIG_BUSYBOX_DEFAULT_CHPASSWD is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_DEFAULT_PASSWD_ALGO="md5" # CONFIG_BUSYBOX_DEFAULT_CRYPTPW is not set # CONFIG_BUSYBOX_DEFAULT_MKPASSWD is not set # CONFIG_BUSYBOX_DEFAULT_DELUSER is not set # CONFIG_BUSYBOX_DEFAULT_DELGROUP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DEL_USER_FROM_GROUP is not set # CONFIG_BUSYBOX_DEFAULT_GETTY is not set CONFIG_BUSYBOX_DEFAULT_LOGIN=y CONFIG_BUSYBOX_DEFAULT_LOGIN_SESSION_AS_CHILD=y # CONFIG_BUSYBOX_DEFAULT_LOGIN_SCRIPTS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NOLOGIN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SECURETTY is not set CONFIG_BUSYBOX_DEFAULT_PASSWD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_PASSWD_WEAK_CHECK=y # CONFIG_BUSYBOX_DEFAULT_SU is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_SYSLOG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_CHECKS_SHELLS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_BLANK_PW_NEEDS_SECURE_TTY is not set # CONFIG_BUSYBOX_DEFAULT_SULOGIN is not set # CONFIG_BUSYBOX_DEFAULT_VLOCK is not set # CONFIG_BUSYBOX_DEFAULT_CHATTR is not set # CONFIG_BUSYBOX_DEFAULT_FSCK is not set # CONFIG_BUSYBOX_DEFAULT_LSATTR is not set # CONFIG_BUSYBOX_DEFAULT_TUNE2FS is not set # CONFIG_BUSYBOX_DEFAULT_MODPROBE_SMALL is not set # CONFIG_BUSYBOX_DEFAULT_DEPMOD is not set # CONFIG_BUSYBOX_DEFAULT_INSMOD is not set # CONFIG_BUSYBOX_DEFAULT_LSMOD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set # CONFIG_BUSYBOX_DEFAULT_MODINFO is not set # CONFIG_BUSYBOX_DEFAULT_MODPROBE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODPROBE_BLACKLIST is not set # CONFIG_BUSYBOX_DEFAULT_RMMOD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CMDLINE_MODULE_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_2_4_MODULES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_VERSION_CHECKING is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOADINKMEM is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOAD_MAP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOAD_MAP_FULL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_TAINTED_MODULE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_TRY_MMAP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODUTILS_ALIAS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODUTILS_SYMBOLS is not set CONFIG_BUSYBOX_DEFAULT_DEFAULT_MODULES_DIR="" CONFIG_BUSYBOX_DEFAULT_DEFAULT_DEPMOD_FILE="" # CONFIG_BUSYBOX_DEFAULT_ACPID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ACPID_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_BLKDISCARD is not set # CONFIG_BUSYBOX_DEFAULT_BLKID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BLKID_TYPE is not set # CONFIG_BUSYBOX_DEFAULT_BLOCKDEV is not set # CONFIG_BUSYBOX_DEFAULT_CAL is not set # CONFIG_BUSYBOX_DEFAULT_CHRT is not set CONFIG_BUSYBOX_DEFAULT_DMESG=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DMESG_PRETTY=y # CONFIG_BUSYBOX_DEFAULT_EJECT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_EJECT_SCSI is not set # CONFIG_BUSYBOX_DEFAULT_FALLOCATE is not set # CONFIG_BUSYBOX_DEFAULT_FATATTR is not set # CONFIG_BUSYBOX_DEFAULT_FBSET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FBSET_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FBSET_READMODE is not set # CONFIG_BUSYBOX_DEFAULT_FDFORMAT is not set # CONFIG_BUSYBOX_DEFAULT_FDISK is not set # CONFIG_BUSYBOX_DEFAULT_FDISK_SUPPORT_LARGE_DISKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FDISK_WRITABLE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_AIX_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SGI_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUN_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_OSF_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_GPT_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FDISK_ADVANCED is not set # CONFIG_BUSYBOX_DEFAULT_FINDFS is not set CONFIG_BUSYBOX_DEFAULT_FLOCK=y # CONFIG_BUSYBOX_DEFAULT_FDFLUSH is not set # CONFIG_BUSYBOX_DEFAULT_FREERAMDISK is not set # CONFIG_BUSYBOX_DEFAULT_FSCK_MINIX is not set # CONFIG_BUSYBOX_DEFAULT_FSFREEZE is not set # CONFIG_BUSYBOX_DEFAULT_FSTRIM is not set # CONFIG_BUSYBOX_DEFAULT_GETOPT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_GETOPT_LONG is not set CONFIG_BUSYBOX_DEFAULT_HEXDUMP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_HEXDUMP_REVERSE is not set # CONFIG_BUSYBOX_DEFAULT_HD is not set # CONFIG_BUSYBOX_DEFAULT_XXD is not set CONFIG_BUSYBOX_DEFAULT_HWCLOCK=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_HWCLOCK_ADJTIME_FHS is not set # CONFIG_BUSYBOX_DEFAULT_IONICE is not set # CONFIG_BUSYBOX_DEFAULT_IPCRM is not set # CONFIG_BUSYBOX_DEFAULT_IPCS is not set # CONFIG_BUSYBOX_DEFAULT_LAST is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LAST_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_LOSETUP is not set # CONFIG_BUSYBOX_DEFAULT_LSPCI is not set # CONFIG_BUSYBOX_DEFAULT_LSUSB is not set # CONFIG_BUSYBOX_DEFAULT_MDEV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_CONF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_RENAME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_RENAME_REGEXP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_EXEC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_LOAD_FIRMWARE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_DAEMON is not set # CONFIG_BUSYBOX_DEFAULT_MESG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MESG_ENABLE_ONLY_GROUP is not set # CONFIG_BUSYBOX_DEFAULT_MKE2FS is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_EXT2 is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_MINIX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MINIX2 is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_REISER is not set # CONFIG_BUSYBOX_DEFAULT_MKDOSFS is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_VFAT is not set CONFIG_BUSYBOX_DEFAULT_MKSWAP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MKSWAP_UUID is not set # CONFIG_BUSYBOX_DEFAULT_MORE is not set CONFIG_BUSYBOX_DEFAULT_MOUNT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FAKE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_VERBOSE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_HELPERS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_NFS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_CIFS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FLAGS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FSTAB=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_OTHERTAB is not set # CONFIG_BUSYBOX_DEFAULT_MOUNTPOINT is not set # CONFIG_BUSYBOX_DEFAULT_NOLOGIN is not set # CONFIG_BUSYBOX_DEFAULT_NOLOGIN_DEPENDENCIES is not set # CONFIG_BUSYBOX_DEFAULT_NSENTER is not set CONFIG_BUSYBOX_DEFAULT_PIVOT_ROOT=y # CONFIG_BUSYBOX_DEFAULT_RDATE is not set # CONFIG_BUSYBOX_DEFAULT_RDEV is not set # CONFIG_BUSYBOX_DEFAULT_READPROFILE is not set # CONFIG_BUSYBOX_DEFAULT_RENICE is not set # CONFIG_BUSYBOX_DEFAULT_REV is not set # CONFIG_BUSYBOX_DEFAULT_RTCWAKE is not set # CONFIG_BUSYBOX_DEFAULT_SCRIPT is not set # CONFIG_BUSYBOX_DEFAULT_SCRIPTREPLAY is not set # CONFIG_BUSYBOX_DEFAULT_SETARCH is not set # CONFIG_BUSYBOX_DEFAULT_LINUX32 is not set # CONFIG_BUSYBOX_DEFAULT_LINUX64 is not set # CONFIG_BUSYBOX_DEFAULT_SETPRIV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_DUMP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_CAPABILITIES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_CAPABILITY_NAMES is not set # CONFIG_BUSYBOX_DEFAULT_SETSID is not set CONFIG_BUSYBOX_DEFAULT_SWAPON=y CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPON_DISCARD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPON_PRI=y CONFIG_BUSYBOX_DEFAULT_SWAPOFF=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPONOFF_LABEL is not set CONFIG_BUSYBOX_DEFAULT_SWITCH_ROOT=y # CONFIG_BUSYBOX_DEFAULT_TASKSET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TASKSET_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_UEVENT is not set CONFIG_BUSYBOX_DEFAULT_UMOUNT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_UMOUNT_ALL=y # CONFIG_BUSYBOX_DEFAULT_UNSHARE is not set # CONFIG_BUSYBOX_DEFAULT_WALL is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LOOP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LOOP_CREATE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MTAB_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_VOLUMEID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_BCACHE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_BTRFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_CRAMFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_EXFAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_EXT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_F2FS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_FAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_HFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_ISO9660 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_JFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LINUXRAID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LINUXSWAP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LUKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_MINIX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_NILFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_NTFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_OCFS2 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_REISERFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_ROMFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_SQUASHFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_SYSV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_UBIFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_UDF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_XFS is not set # CONFIG_BUSYBOX_DEFAULT_ADJTIMEX is not set # CONFIG_BUSYBOX_DEFAULT_BBCONFIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_COMPRESS_BBCONFIG is not set # CONFIG_BUSYBOX_DEFAULT_BC is not set # CONFIG_BUSYBOX_DEFAULT_DC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DC_BIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DC_LIBM is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BC_INTERACTIVE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BC_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_BEEP is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_BEEP_FREQ=0 CONFIG_BUSYBOX_DEFAULT_FEATURE_BEEP_LENGTH_MS=0 # CONFIG_BUSYBOX_DEFAULT_CHAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_NOFAIL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_TTY_HIFI is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_IMPLICIT_CR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_SWALLOW_OPTS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_SEND_ESCAPES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_VAR_ABORT_LEN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_CLR_ABORT is not set # CONFIG_BUSYBOX_DEFAULT_CONSPY is not set CONFIG_BUSYBOX_DEFAULT_CROND=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_D is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_CALL_SENDMAIL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_SPECIAL_TIMES is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_DIR="/etc" CONFIG_BUSYBOX_DEFAULT_CRONTAB=y # CONFIG_BUSYBOX_DEFAULT_DEVFSD is not set # CONFIG_BUSYBOX_DEFAULT_DEVFSD_MODLOAD is not set # CONFIG_BUSYBOX_DEFAULT_DEVFSD_FG_NP is not set # CONFIG_BUSYBOX_DEFAULT_DEVFSD_VERBOSE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DEVFS is not set # CONFIG_BUSYBOX_DEFAULT_DEVMEM is not set # CONFIG_BUSYBOX_DEFAULT_FBSPLASH is not set # CONFIG_BUSYBOX_DEFAULT_FLASH_ERASEALL is not set # CONFIG_BUSYBOX_DEFAULT_FLASH_LOCK is not set # CONFIG_BUSYBOX_DEFAULT_FLASH_UNLOCK is not set # CONFIG_BUSYBOX_DEFAULT_FLASHCP is not set # CONFIG_BUSYBOX_DEFAULT_HDPARM is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_GET_IDENTITY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_SCAN_HWIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_DRIVE_RESET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_TRISTATE_HWIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_GETSET_DMA is not set # CONFIG_BUSYBOX_DEFAULT_HEXEDIT is not set # CONFIG_BUSYBOX_DEFAULT_I2CGET is not set # CONFIG_BUSYBOX_DEFAULT_I2CSET is not set # CONFIG_BUSYBOX_DEFAULT_I2CDUMP is not set # CONFIG_BUSYBOX_DEFAULT_I2CDETECT is not set # CONFIG_BUSYBOX_DEFAULT_I2CTRANSFER is not set # CONFIG_BUSYBOX_DEFAULT_INOTIFYD is not set CONFIG_BUSYBOX_DEFAULT_LESS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_MAXLINES=9999999 # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_BRACKETS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_FLAGS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_TRUNCATE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_MARKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_REGEXP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_WINCH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_ASK_TERMINAL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_DASHCMD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_LINENUMS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_RAW is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_ENV is not set CONFIG_BUSYBOX_DEFAULT_LOCK=y # CONFIG_BUSYBOX_DEFAULT_LSSCSI is not set # CONFIG_BUSYBOX_DEFAULT_MAKEDEVS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MAKEDEVS_LEAF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MAKEDEVS_TABLE is not set # CONFIG_BUSYBOX_DEFAULT_MAN is not set # CONFIG_BUSYBOX_DEFAULT_MICROCOM is not set # CONFIG_BUSYBOX_DEFAULT_MT is not set # CONFIG_BUSYBOX_DEFAULT_NANDWRITE is not set # CONFIG_BUSYBOX_DEFAULT_NANDDUMP is not set # CONFIG_BUSYBOX_DEFAULT_PARTPROBE is not set # CONFIG_BUSYBOX_DEFAULT_RAIDAUTORUN is not set # CONFIG_BUSYBOX_DEFAULT_READAHEAD is not set # CONFIG_BUSYBOX_DEFAULT_RFKILL is not set # CONFIG_BUSYBOX_DEFAULT_RUNLEVEL is not set # CONFIG_BUSYBOX_DEFAULT_RX is not set # CONFIG_BUSYBOX_DEFAULT_SETFATTR is not set # CONFIG_BUSYBOX_DEFAULT_SETSERIAL is not set CONFIG_BUSYBOX_DEFAULT_STRINGS=y CONFIG_BUSYBOX_DEFAULT_TIME=y # CONFIG_BUSYBOX_DEFAULT_TS is not set # CONFIG_BUSYBOX_DEFAULT_TTYSIZE is not set # CONFIG_BUSYBOX_DEFAULT_UBIATTACH is not set # CONFIG_BUSYBOX_DEFAULT_UBIDETACH is not set # CONFIG_BUSYBOX_DEFAULT_UBIMKVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIRMVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIRSVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIUPDATEVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIRENAME is not set # CONFIG_BUSYBOX_DEFAULT_VOLNAME is not set # CONFIG_BUSYBOX_DEFAULT_WATCHDOG is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IPV6=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNIX_LOCAL is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_PREFER_IPV4_ADDRESS=y CONFIG_BUSYBOX_DEFAULT_VERBOSE_RESOLUTION_ERRORS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TLS_SHA1 is not set # CONFIG_BUSYBOX_DEFAULT_ARP is not set # CONFIG_BUSYBOX_DEFAULT_ARPING is not set CONFIG_BUSYBOX_DEFAULT_BRCTL=y CONFIG_BUSYBOX_DEFAULT_FEATURE_BRCTL_FANCY=y CONFIG_BUSYBOX_DEFAULT_FEATURE_BRCTL_SHOW=y # CONFIG_BUSYBOX_DEFAULT_DNSD is not set # CONFIG_BUSYBOX_DEFAULT_ETHER_WAKE is not set # CONFIG_BUSYBOX_DEFAULT_FTPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_WRITE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_ACCEPT_BROKEN_LIST is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_AUTHENTICATION is not set # CONFIG_BUSYBOX_DEFAULT_FTPGET is not set # CONFIG_BUSYBOX_DEFAULT_FTPPUT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPGETPUT_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_HOSTNAME is not set # CONFIG_BUSYBOX_DEFAULT_DNSDOMAINNAME is not set # CONFIG_BUSYBOX_DEFAULT_HTTPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_RANGES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_SETUID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_BASIC_AUTH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_AUTH_MD5 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_CGI is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_ENCODE_URL_STR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_ERROR_PAGES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_PROXY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_GZIP is not set CONFIG_BUSYBOX_DEFAULT_IFCONFIG=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_STATUS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_SLIP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_HW=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_BROADCAST_PLUS=y # CONFIG_BUSYBOX_DEFAULT_IFENSLAVE is not set # CONFIG_BUSYBOX_DEFAULT_IFPLUGD is not set # CONFIG_BUSYBOX_DEFAULT_IFUP is not set # CONFIG_BUSYBOX_DEFAULT_IFDOWN is not set CONFIG_BUSYBOX_DEFAULT_IFUPDOWN_IFSTATE_PATH="" # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IPV4 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IPV6 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_MAPPING is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set # CONFIG_BUSYBOX_DEFAULT_INETD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_RPC is not set CONFIG_BUSYBOX_DEFAULT_IP=y # CONFIG_BUSYBOX_DEFAULT_IPADDR is not set # CONFIG_BUSYBOX_DEFAULT_IPLINK is not set # CONFIG_BUSYBOX_DEFAULT_IPROUTE is not set # CONFIG_BUSYBOX_DEFAULT_IPTUNNEL is not set # CONFIG_BUSYBOX_DEFAULT_IPRULE is not set # CONFIG_BUSYBOX_DEFAULT_IPNEIGH is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ADDRESS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_LINK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ROUTE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ROUTE_DIR="/etc/iproute2" # CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_TUNNEL is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_RULE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_NEIGH=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_RARE_PROTOCOLS is not set # CONFIG_BUSYBOX_DEFAULT_IPCALC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IPCALC_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IPCALC_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_FAKEIDENTD is not set # CONFIG_BUSYBOX_DEFAULT_NAMEIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NAMEIF_EXTENDED is not set # CONFIG_BUSYBOX_DEFAULT_NBDCLIENT is not set CONFIG_BUSYBOX_DEFAULT_NC=y # CONFIG_BUSYBOX_DEFAULT_NETCAT is not set # CONFIG_BUSYBOX_DEFAULT_NC_SERVER is not set # CONFIG_BUSYBOX_DEFAULT_NC_EXTRA is not set # CONFIG_BUSYBOX_DEFAULT_NC_110_COMPAT is not set CONFIG_BUSYBOX_DEFAULT_NETMSG=y CONFIG_BUSYBOX_DEFAULT_NETSTAT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_NETSTAT_WIDE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_NETSTAT_PRG=y # CONFIG_BUSYBOX_DEFAULT_NSLOOKUP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NSLOOKUP_BIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NSLOOKUP_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_NSLOOKUP_OPENWRT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_NSLOOKUP_OPENWRT_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_NTPD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_NTPD_SERVER=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_NTPD_CONF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NTP_AUTH is not set CONFIG_BUSYBOX_DEFAULT_PING=y CONFIG_BUSYBOX_DEFAULT_PING6=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_PING=y # CONFIG_BUSYBOX_DEFAULT_PSCAN is not set CONFIG_BUSYBOX_DEFAULT_ROUTE=y # CONFIG_BUSYBOX_DEFAULT_SLATTACH is not set # CONFIG_BUSYBOX_DEFAULT_SSL_CLIENT is not set # CONFIG_BUSYBOX_DEFAULT_TC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TC_INGRESS is not set # CONFIG_BUSYBOX_DEFAULT_TCPSVD is not set # CONFIG_BUSYBOX_DEFAULT_UDPSVD is not set # CONFIG_BUSYBOX_DEFAULT_TELNET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_TTYPE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_AUTOLOGIN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_WIDTH is not set # CONFIG_BUSYBOX_DEFAULT_TELNETD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNETD_STANDALONE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNETD_INETD_WAIT is not set # CONFIG_BUSYBOX_DEFAULT_TFTP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_PROGRESS_BAR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_HPA_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_TFTPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_GET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_PUT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_BLOCKSIZE is not set # CONFIG_BUSYBOX_DEFAULT_TFTP_DEBUG is not set # CONFIG_BUSYBOX_DEFAULT_TLS is not set CONFIG_BUSYBOX_DEFAULT_TRACEROUTE=y CONFIG_BUSYBOX_DEFAULT_TRACEROUTE6=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TRACEROUTE_VERBOSE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TRACEROUTE_USE_ICMP is not set # CONFIG_BUSYBOX_DEFAULT_TUNCTL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TUNCTL_UG is not set # CONFIG_BUSYBOX_DEFAULT_VCONFIG is not set # CONFIG_BUSYBOX_DEFAULT_WGET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_STATUSBAR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_AUTHENTICATION is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_TIMEOUT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_HTTPS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_OPENSSL is not set # CONFIG_BUSYBOX_DEFAULT_WHOIS is not set # CONFIG_BUSYBOX_DEFAULT_ZCIP is not set # CONFIG_BUSYBOX_DEFAULT_UDHCPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPD_BASE_IP_ON_MAC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPD_WRITE_LEASES_EARLY is not set CONFIG_BUSYBOX_DEFAULT_DHCPD_LEASES_FILE="" # CONFIG_BUSYBOX_DEFAULT_DUMPLEASES is not set # CONFIG_BUSYBOX_DEFAULT_DHCPRELAY is not set CONFIG_BUSYBOX_DEFAULT_UDHCPC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC_ARPING is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC_SANITIZEOPT is not set CONFIG_BUSYBOX_DEFAULT_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script" # CONFIG_BUSYBOX_DEFAULT_UDHCPC6 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC3646 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC4704 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC4833 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC5970 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_PORT is not set CONFIG_BUSYBOX_DEFAULT_UDHCP_DEBUG=0 CONFIG_BUSYBOX_DEFAULT_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80 CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_RFC3397=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_8021Q is not set CONFIG_BUSYBOX_DEFAULT_IFUPDOWN_UDHCPC_CMD_OPTIONS="" # CONFIG_BUSYBOX_DEFAULT_LPD is not set # CONFIG_BUSYBOX_DEFAULT_LPR is not set # CONFIG_BUSYBOX_DEFAULT_LPQ is not set # CONFIG_BUSYBOX_DEFAULT_MAKEMIME is not set # CONFIG_BUSYBOX_DEFAULT_POPMAILDIR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_POPMAILDIR_DELIVERY is not set # CONFIG_BUSYBOX_DEFAULT_REFORMIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_REFORMIME_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_SENDMAIL is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MIME_CHARSET="" CONFIG_BUSYBOX_DEFAULT_FREE=y # CONFIG_BUSYBOX_DEFAULT_FUSER is not set # CONFIG_BUSYBOX_DEFAULT_IOSTAT is not set CONFIG_BUSYBOX_DEFAULT_KILL=y CONFIG_BUSYBOX_DEFAULT_KILLALL=y # CONFIG_BUSYBOX_DEFAULT_KILLALL5 is not set # CONFIG_BUSYBOX_DEFAULT_LSOF is not set # CONFIG_BUSYBOX_DEFAULT_MPSTAT is not set # CONFIG_BUSYBOX_DEFAULT_NMETER is not set CONFIG_BUSYBOX_DEFAULT_PGREP=y # CONFIG_BUSYBOX_DEFAULT_PKILL is not set CONFIG_BUSYBOX_DEFAULT_PIDOF=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDOF_SINGLE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDOF_OMIT is not set # CONFIG_BUSYBOX_DEFAULT_PMAP is not set # CONFIG_BUSYBOX_DEFAULT_POWERTOP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_POWERTOP_INTERACTIVE is not set CONFIG_BUSYBOX_DEFAULT_PS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_WIDE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_LONG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_TIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_UNUSUAL_SYSTEMS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_ADDITIONAL_COLUMNS is not set # CONFIG_BUSYBOX_DEFAULT_PSTREE is not set # CONFIG_BUSYBOX_DEFAULT_PWDX is not set # CONFIG_BUSYBOX_DEFAULT_SMEMCAP is not set CONFIG_BUSYBOX_DEFAULT_BB_SYSCTL=y CONFIG_BUSYBOX_DEFAULT_TOP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_INTERACTIVE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_SMP_CPU is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_DECIMALS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_SMP_PROCESS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOPMEM is not set CONFIG_BUSYBOX_DEFAULT_UPTIME=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UPTIME_UTMP_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_WATCH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SHOW_THREADS is not set # CONFIG_BUSYBOX_DEFAULT_CHPST is not set # CONFIG_BUSYBOX_DEFAULT_SETUIDGID is not set # CONFIG_BUSYBOX_DEFAULT_ENVUIDGID is not set # CONFIG_BUSYBOX_DEFAULT_ENVDIR is not set # CONFIG_BUSYBOX_DEFAULT_SOFTLIMIT is not set # CONFIG_BUSYBOX_DEFAULT_RUNSV is not set # CONFIG_BUSYBOX_DEFAULT_RUNSVDIR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RUNSVDIR_LOG is not set # CONFIG_BUSYBOX_DEFAULT_SV is not set CONFIG_BUSYBOX_DEFAULT_SV_DEFAULT_SERVICE_DIR="" # CONFIG_BUSYBOX_DEFAULT_SVC is not set # CONFIG_BUSYBOX_DEFAULT_SVOK is not set # CONFIG_BUSYBOX_DEFAULT_SVLOGD is not set # CONFIG_BUSYBOX_DEFAULT_CHCON is not set # CONFIG_BUSYBOX_DEFAULT_GETENFORCE is not set # CONFIG_BUSYBOX_DEFAULT_GETSEBOOL is not set # CONFIG_BUSYBOX_DEFAULT_LOAD_POLICY is not set # CONFIG_BUSYBOX_DEFAULT_MATCHPATHCON is not set # CONFIG_BUSYBOX_DEFAULT_RUNCON is not set # CONFIG_BUSYBOX_DEFAULT_SELINUXENABLED is not set # CONFIG_BUSYBOX_DEFAULT_SESTATUS is not set # CONFIG_BUSYBOX_DEFAULT_SETENFORCE is not set # CONFIG_BUSYBOX_DEFAULT_SETFILES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETFILES_CHECK_OPTION is not set # CONFIG_BUSYBOX_DEFAULT_RESTORECON is not set # CONFIG_BUSYBOX_DEFAULT_SETSEBOOL is not set CONFIG_BUSYBOX_DEFAULT_SH_IS_ASH=y # CONFIG_BUSYBOX_DEFAULT_SH_IS_HUSH is not set # CONFIG_BUSYBOX_DEFAULT_SH_IS_NONE is not set # CONFIG_BUSYBOX_DEFAULT_BASH_IS_ASH is not set # CONFIG_BUSYBOX_DEFAULT_BASH_IS_HUSH is not set CONFIG_BUSYBOX_DEFAULT_BASH_IS_NONE=y CONFIG_BUSYBOX_DEFAULT_ASH=y # CONFIG_BUSYBOX_DEFAULT_ASH_OPTIMIZE_FOR_SIZE is not set CONFIG_BUSYBOX_DEFAULT_ASH_INTERNAL_GLOB=y CONFIG_BUSYBOX_DEFAULT_ASH_BASH_COMPAT=y # CONFIG_BUSYBOX_DEFAULT_ASH_BASH_SOURCE_CURDIR is not set # CONFIG_BUSYBOX_DEFAULT_ASH_BASH_NOT_FOUND_HOOK is not set CONFIG_BUSYBOX_DEFAULT_ASH_JOB_CONTROL=y CONFIG_BUSYBOX_DEFAULT_ASH_ALIAS=y # CONFIG_BUSYBOX_DEFAULT_ASH_RANDOM_SUPPORT is not set CONFIG_BUSYBOX_DEFAULT_ASH_EXPAND_PRMT=y # CONFIG_BUSYBOX_DEFAULT_ASH_IDLE_TIMEOUT is not set # CONFIG_BUSYBOX_DEFAULT_ASH_MAIL is not set CONFIG_BUSYBOX_DEFAULT_ASH_ECHO=y CONFIG_BUSYBOX_DEFAULT_ASH_PRINTF=y CONFIG_BUSYBOX_DEFAULT_ASH_TEST=y # CONFIG_BUSYBOX_DEFAULT_ASH_HELP is not set CONFIG_BUSYBOX_DEFAULT_ASH_GETOPTS=y CONFIG_BUSYBOX_DEFAULT_ASH_CMDCMD=y # CONFIG_BUSYBOX_DEFAULT_CTTYHACK is not set # CONFIG_BUSYBOX_DEFAULT_HUSH is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_BASH_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_BRACE_EXPANSION is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_LINENO_VAR is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_BASH_SOURCE_CURDIR is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_INTERACTIVE is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_SAVEHISTORY is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_JOB is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TICK is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_IF is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_LOOPS is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_CASE is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_FUNCTIONS is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_LOCAL is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_RANDOM_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_MODE_X is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_ECHO is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_PRINTF is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TEST is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_HELP is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_EXPORT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_EXPORT_N is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_READONLY is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_KILL is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_WAIT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_COMMAND is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TRAP is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TYPE is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TIMES is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_READ is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_SET is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_UNSET is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_ULIMIT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_UMASK is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_GETOPTS is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_MEMLEAK is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH_64=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH_BASE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_EXTRA_QUIET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_STANDALONE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_NOFORK=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_READ_FRAC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_HISTFILESIZE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_EMBEDDED_SCRIPTS is not set # CONFIG_BUSYBOX_DEFAULT_KLOGD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_KLOGD_KLOGCTL is not set CONFIG_BUSYBOX_DEFAULT_LOGGER=y # CONFIG_BUSYBOX_DEFAULT_LOGREAD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LOGREAD_REDUCED_LOCKING is not set # CONFIG_BUSYBOX_DEFAULT_SYSLOGD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ROTATE_LOGFILE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_REMOTE_LOG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_DUP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_CFG is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_READ_BUFFER_SIZE=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_IPC_SYSLOG is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IPC_SYSLOG_BUFFER_SIZE=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_KMSG_SYSLOG is not set CONFIG_PACKAGE_ca-bundle=y CONFIG_PACKAGE_ca-certificates=y # CONFIG_PACKAGE_dnsmasq is not set # CONFIG_PACKAGE_dnsmasq-dhcpv6 is not set CONFIG_PACKAGE_dnsmasq-full=y CONFIG_PACKAGE_dnsmasq_full_dhcp=y # CONFIG_PACKAGE_dnsmasq_full_dhcpv6 is not set # CONFIG_PACKAGE_dnsmasq_full_dnssec is not set # CONFIG_PACKAGE_dnsmasq_full_auth is not set CONFIG_PACKAGE_dnsmasq_full_ipset=y # CONFIG_PACKAGE_dnsmasq_full_conntrack is not set # CONFIG_PACKAGE_dnsmasq_full_noid is not set # CONFIG_PACKAGE_dnsmasq_full_broken_rtc is not set CONFIG_PACKAGE_dnsmasq_full_tftp=y CONFIG_PACKAGE_dropbear=y # # Configuration # CONFIG_DROPBEAR_CURVE25519=y # CONFIG_DROPBEAR_ECC is not set # CONFIG_DROPBEAR_ED25519 is not set CONFIG_DROPBEAR_CHACHA20POLY1305=y # CONFIG_DROPBEAR_ZLIB is not set CONFIG_DROPBEAR_DBCLIENT=y # end of Configuration # CONFIG_PACKAGE_ead is not set CONFIG_PACKAGE_firewall=y CONFIG_PACKAGE_fstools=y CONFIG_FSTOOLS_UBIFS_EXTROOT=y # CONFIG_FSTOOLS_OVL_MOUNT_FULL_ACCESS_TIME is not set # CONFIG_FSTOOLS_OVL_MOUNT_COMPRESS_ZLIB is not set CONFIG_PACKAGE_fwtool=y CONFIG_PACKAGE_getrandom=y CONFIG_PACKAGE_jsonfilter=y CONFIG_PACKAGE_libatomic=y CONFIG_PACKAGE_libc=y CONFIG_PACKAGE_libgcc=y # CONFIG_PACKAGE_libgomp is not set CONFIG_PACKAGE_libpthread=y CONFIG_PACKAGE_librt=y CONFIG_PACKAGE_libstdcpp=y CONFIG_PACKAGE_logd=y CONFIG_PACKAGE_mtd=y CONFIG_PACKAGE_netifd=y # CONFIG_PACKAGE_nft-qos is not set # CONFIG_PACKAGE_om-watchdog is not set CONFIG_PACKAGE_openwrt-keyring=y CONFIG_PACKAGE_opkg=y CONFIG_PACKAGE_procd=y # # Configuration # # CONFIG_PROCD_SHOW_BOOT is not set # CONFIG_PROCD_ZRAM_TMPFS is not set # end of Configuration # CONFIG_PACKAGE_procd-seccomp is not set # CONFIG_PACKAGE_procd-ujail is not set # CONFIG_PACKAGE_procd-ujail-console is not set # CONFIG_PACKAGE_qos-scripts is not set CONFIG_PACKAGE_resolveip=y CONFIG_PACKAGE_rpcd=y # CONFIG_PACKAGE_rpcd-mod-file is not set # CONFIG_PACKAGE_rpcd-mod-iwinfo is not set # CONFIG_PACKAGE_rpcd-mod-rpcsys is not set # CONFIG_PACKAGE_snapshot-tool is not set # CONFIG_PACKAGE_sqm-scripts is not set # CONFIG_PACKAGE_sqm-scripts-extra is not set CONFIG_PACKAGE_swconfig=y CONFIG_PACKAGE_ubox=y CONFIG_PACKAGE_ubus=y CONFIG_PACKAGE_ubusd=y # CONFIG_PACKAGE_ucert is not set # CONFIG_PACKAGE_ucert-full is not set CONFIG_PACKAGE_uci=y CONFIG_PACKAGE_urandom-seed=y CONFIG_PACKAGE_urngd=y CONFIG_PACKAGE_usign=y # CONFIG_PACKAGE_wireless-tools is not set # CONFIG_PACKAGE_zram-swap is not set # end of Base system # # Administration # # # OpenWISP # # CONFIG_PACKAGE_openwisp-config-cyassl is not set # CONFIG_PACKAGE_openwisp-config-mbedtls is not set # CONFIG_PACKAGE_openwisp-config-nossl is not set # CONFIG_PACKAGE_openwisp-config-openssl is not set # end of OpenWISP # # Zabbix # # CONFIG_PACKAGE_zabbix-agentd is not set # # SSL support # # CONFIG_ZABBIX_OPENSSL is not set # CONFIG_ZABBIX_GNUTLS is not set CONFIG_ZABBIX_NOSSL=y # CONFIG_PACKAGE_zabbix-extra-mac80211 is not set # CONFIG_PACKAGE_zabbix-extra-network is not set # CONFIG_PACKAGE_zabbix-extra-wifi is not set # CONFIG_PACKAGE_zabbix-get is not set # CONFIG_PACKAGE_zabbix-proxy is not set # CONFIG_PACKAGE_zabbix-sender is not set # CONFIG_PACKAGE_zabbix-server is not set # # Database Software # # CONFIG_ZABBIX_MYSQL is not set CONFIG_ZABBIX_POSTGRESQL=y # CONFIG_PACKAGE_zabbix-server-frontend is not set # end of Zabbix # CONFIG_PACKAGE_atop is not set # CONFIG_PACKAGE_backuppc is not set # CONFIG_PACKAGE_debootstrap is not set # CONFIG_PACKAGE_gkrellmd is not set CONFIG_PACKAGE_gotop=y CONFIG_PACKAGE_htop=y # CONFIG_PACKAGE_ipmitool is not set # CONFIG_PACKAGE_monit is not set # CONFIG_PACKAGE_monit-nossl is not set # CONFIG_PACKAGE_muninlite is not set # CONFIG_PACKAGE_netatop is not set # CONFIG_PACKAGE_netdata is not set # CONFIG_PACKAGE_nyx is not set # CONFIG_PACKAGE_schroot is not set # # Configuration # # CONFIG_SCHROOT_BTRFS is not set # CONFIG_SCHROOT_LOOPBACK is not set # CONFIG_SCHROOT_LVM is not set # CONFIG_SCHROOT_UUID is not set # end of Configuration # CONFIG_PACKAGE_sudo is not set # CONFIG_PACKAGE_syslog-ng is not set # end of Administration # # Boot Loaders # # end of Boot Loaders # # Development # # # Libraries # # CONFIG_PACKAGE_libncurses-dev is not set # CONFIG_PACKAGE_libxml2-dev is not set # CONFIG_PACKAGE_zlib-dev is not set # end of Libraries # CONFIG_PACKAGE_ar is not set # CONFIG_PACKAGE_autoconf is not set # CONFIG_PACKAGE_automake is not set # CONFIG_PACKAGE_binutils is not set # CONFIG_PACKAGE_diffutils is not set # CONFIG_PACKAGE_gcc is not set # CONFIG_PACKAGE_gdb is not set # CONFIG_PACKAGE_gdbserver is not set # CONFIG_PACKAGE_libtool-bin is not set # CONFIG_PACKAGE_lpc21isp is not set # CONFIG_PACKAGE_lttng-tools is not set # CONFIG_PACKAGE_m4 is not set # CONFIG_PACKAGE_make is not set # CONFIG_PACKAGE_meson is not set # CONFIG_PACKAGE_mt76-test is not set # CONFIG_PACKAGE_ninja is not set # CONFIG_PACKAGE_objdump is not set # CONFIG_PACKAGE_patch is not set # CONFIG_PACKAGE_pkg-config is not set # CONFIG_PACKAGE_pkgconf is not set # CONFIG_PACKAGE_trace-cmd is not set # CONFIG_PACKAGE_trace-cmd-extra is not set # CONFIG_PACKAGE_valgrind is not set # end of Development # # Extra packages # # CONFIG_PACKAGE_automount is not set # CONFIG_PACKAGE_autosamba is not set # CONFIG_PACKAGE_ipv6helper is not set # CONFIG_PACKAGE_jose is not set # CONFIG_PACKAGE_k3wifi is not set # CONFIG_PACKAGE_libjose is not set # CONFIG_PACKAGE_tang is not set # CONFIG_PACKAGE_wireguard-tools is not set # end of Extra packages # # Firmware # # # ath10k Board-Specific Overrides # # end of ath10k Board-Specific Overrides # CONFIG_PACKAGE_aircard-pcmcia-firmware is not set # CONFIG_PACKAGE_amdgpu-firmware is not set # CONFIG_PACKAGE_ar3k-firmware is not set # CONFIG_PACKAGE_ath10k-board-qca4019 is not set # CONFIG_PACKAGE_ath10k-board-qca9887 is not set # CONFIG_PACKAGE_ath10k-board-qca9888 is not set # CONFIG_PACKAGE_ath10k-board-qca988x is not set # CONFIG_PACKAGE_ath10k-board-qca9984 is not set # CONFIG_PACKAGE_ath10k-board-qca99x0 is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019 is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019-ct-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca6174 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9887 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9887-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca9887-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888-ct-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca988x is not set # CONFIG_PACKAGE_ath10k-firmware-qca988x-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca988x-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984-ct-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0 is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct-htt is not set # CONFIG_PACKAGE_ath6k-firmware is not set # CONFIG_PACKAGE_ath9k-htc-firmware is not set # CONFIG_PACKAGE_b43legacy-firmware is not set # CONFIG_PACKAGE_bnx2-firmware is not set # CONFIG_PACKAGE_bnx2x-firmware is not set # CONFIG_PACKAGE_brcmfmac-firmware-4329-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43362-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43430-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43430-sdio-rpi-3b is not set # CONFIG_PACKAGE_brcmfmac-firmware-43430-sdio-rpi-zero-w is not set # CONFIG_PACKAGE_brcmfmac-firmware-43430a0-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43455-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43455-sdio-rpi-3b-plus is not set # CONFIG_PACKAGE_brcmfmac-firmware-43455-sdio-rpi-4b is not set # CONFIG_PACKAGE_brcmfmac-firmware-43602a1-pcie is not set # CONFIG_PACKAGE_brcmfmac-firmware-4366b1-pcie is not set # CONFIG_PACKAGE_brcmfmac-firmware-4366c0-pcie is not set # CONFIG_PACKAGE_brcmfmac-firmware-usb is not set # CONFIG_PACKAGE_brcmsmac-firmware is not set # CONFIG_PACKAGE_carl9170-firmware is not set # CONFIG_PACKAGE_cypress-firmware-43012-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43340-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43362-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4339-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43430-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43455-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4354-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4356-pcie is not set # CONFIG_PACKAGE_cypress-firmware-4356-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43570-pcie is not set # CONFIG_PACKAGE_cypress-firmware-4359-pcie is not set # CONFIG_PACKAGE_cypress-firmware-4359-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4373-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4373-usb is not set # CONFIG_PACKAGE_cypress-firmware-54591-pcie is not set # CONFIG_PACKAGE_cypress-firmware-89459-pcie is not set # CONFIG_PACKAGE_e100-firmware is not set # CONFIG_PACKAGE_edgeport-firmware is not set # CONFIG_PACKAGE_eip197-mini-firmware is not set # CONFIG_PACKAGE_ibt-firmware is not set # CONFIG_PACKAGE_iwl3945-firmware is not set # CONFIG_PACKAGE_iwl4965-firmware is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl100 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl1000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl105 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl135 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl2000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl2030 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl3160 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl3168 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl5000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl5150 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2a is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2b is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6050 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl7260 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl7265 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl7265d is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl8260c is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl8265 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl9000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl9260 is not set # CONFIG_PACKAGE_jboot-tools is not set # CONFIG_PACKAGE_libertas-sdio-firmware is not set # CONFIG_PACKAGE_libertas-spi-firmware is not set # CONFIG_PACKAGE_libertas-usb-firmware is not set # CONFIG_PACKAGE_mt7601u-firmware is not set # CONFIG_PACKAGE_mt7622bt-firmware is not set # CONFIG_PACKAGE_mwifiex-pcie-firmware is not set # CONFIG_PACKAGE_mwifiex-sdio-firmware is not set # CONFIG_PACKAGE_mwl8k-firmware is not set # CONFIG_PACKAGE_p54-pci-firmware is not set # CONFIG_PACKAGE_p54-spi-firmware is not set # CONFIG_PACKAGE_p54-usb-firmware is not set # CONFIG_PACKAGE_prism54-firmware is not set # CONFIG_PACKAGE_r8169-firmware is not set # CONFIG_PACKAGE_radeon-firmware is not set # CONFIG_PACKAGE_rs9113-firmware is not set # CONFIG_PACKAGE_rt2800-pci-firmware is not set # CONFIG_PACKAGE_rt2800-usb-firmware is not set # CONFIG_PACKAGE_rt61-pci-firmware is not set # CONFIG_PACKAGE_rt73-usb-firmware is not set # CONFIG_PACKAGE_rtl8188eu-firmware is not set # CONFIG_PACKAGE_rtl8192ce-firmware is not set # CONFIG_PACKAGE_rtl8192cu-firmware is not set # CONFIG_PACKAGE_rtl8192de-firmware is not set # CONFIG_PACKAGE_rtl8192eu-firmware is not set # CONFIG_PACKAGE_rtl8192se-firmware is not set # CONFIG_PACKAGE_rtl8192su-firmware is not set # CONFIG_PACKAGE_rtl8723au-firmware is not set # CONFIG_PACKAGE_rtl8723bs-firmware is not set # CONFIG_PACKAGE_rtl8723bu-firmware is not set # CONFIG_PACKAGE_rtl8821ae-firmware is not set # CONFIG_PACKAGE_rtl8822be-firmware is not set # CONFIG_PACKAGE_rtl8822ce-firmware is not set # CONFIG_PACKAGE_ti-3410-firmware is not set # CONFIG_PACKAGE_ti-5052-firmware is not set # CONFIG_PACKAGE_wil6210-firmware is not set CONFIG_PACKAGE_wireless-regdb=y # CONFIG_PACKAGE_wl12xx-firmware is not set # CONFIG_PACKAGE_wl18xx-firmware is not set # end of Firmware # # Fonts # # # DejaVu # # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuMathTeXGyre is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-BoldOblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-ExtraLight is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-Oblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-BoldOblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-Oblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-BoldOblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-Oblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-BoldItalic is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-Italic is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-BoldItalic is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-Italic is not set # end of DejaVu # end of Fonts # # Kernel modules # # # Block Devices # # CONFIG_PACKAGE_kmod-aoe is not set # CONFIG_PACKAGE_kmod-ata-ahci is not set # CONFIG_PACKAGE_kmod-ata-artop is not set # CONFIG_PACKAGE_kmod-ata-core is not set # CONFIG_PACKAGE_kmod-ata-marvell-sata is not set # CONFIG_PACKAGE_kmod-ata-nvidia-sata is not set # CONFIG_PACKAGE_kmod-ata-pdc202xx-old is not set # CONFIG_PACKAGE_kmod-ata-piix is not set # CONFIG_PACKAGE_kmod-ata-sil is not set # CONFIG_PACKAGE_kmod-ata-sil24 is not set # CONFIG_PACKAGE_kmod-ata-via-sata is not set # CONFIG_PACKAGE_kmod-block2mtd is not set # CONFIG_PACKAGE_kmod-dax is not set # CONFIG_PACKAGE_kmod-dm is not set # CONFIG_PACKAGE_kmod-dm-raid is not set # CONFIG_PACKAGE_kmod-iosched-bfq is not set # CONFIG_PACKAGE_kmod-iscsi-initiator is not set # CONFIG_PACKAGE_kmod-loop is not set # CONFIG_PACKAGE_kmod-md-mod is not set # CONFIG_PACKAGE_kmod-nbd is not set # CONFIG_PACKAGE_kmod-scsi-cdrom is not set CONFIG_PACKAGE_kmod-scsi-core=y # CONFIG_PACKAGE_kmod-scsi-generic is not set # CONFIG_PACKAGE_kmod-scsi-tape is not set # end of Block Devices # # CAN Support # # CONFIG_PACKAGE_kmod-can is not set # end of CAN Support # # Cryptographic API modules # CONFIG_PACKAGE_kmod-crypto-aead=y CONFIG_PACKAGE_kmod-crypto-arc4=y CONFIG_PACKAGE_kmod-crypto-authenc=y # CONFIG_PACKAGE_kmod-crypto-cbc is not set # CONFIG_PACKAGE_kmod-crypto-ccm is not set # CONFIG_PACKAGE_kmod-crypto-cmac is not set CONFIG_PACKAGE_kmod-crypto-crc32c=y # CONFIG_PACKAGE_kmod-crypto-ctr is not set # CONFIG_PACKAGE_kmod-crypto-cts is not set # CONFIG_PACKAGE_kmod-crypto-deflate is not set # CONFIG_PACKAGE_kmod-crypto-des is not set CONFIG_PACKAGE_kmod-crypto-ecb=y # CONFIG_PACKAGE_kmod-crypto-ecdh is not set # CONFIG_PACKAGE_kmod-crypto-echainiv is not set # CONFIG_PACKAGE_kmod-crypto-fcrypt is not set # CONFIG_PACKAGE_kmod-crypto-gcm is not set # CONFIG_PACKAGE_kmod-crypto-gf128 is not set # CONFIG_PACKAGE_kmod-crypto-ghash is not set CONFIG_PACKAGE_kmod-crypto-hash=y # CONFIG_PACKAGE_kmod-crypto-hmac is not set # CONFIG_PACKAGE_kmod-crypto-hw-ccp is not set # CONFIG_PACKAGE_kmod-crypto-hw-geode is not set # CONFIG_PACKAGE_kmod-crypto-hw-hifn-795x is not set # CONFIG_PACKAGE_kmod-crypto-hw-padlock is not set # CONFIG_PACKAGE_kmod-crypto-hw-talitos is not set CONFIG_PACKAGE_kmod-crypto-manager=y # CONFIG_PACKAGE_kmod-crypto-md4 is not set # CONFIG_PACKAGE_kmod-crypto-md5 is not set # CONFIG_PACKAGE_kmod-crypto-michael-mic is not set # CONFIG_PACKAGE_kmod-crypto-misc is not set CONFIG_PACKAGE_kmod-crypto-null=y # CONFIG_PACKAGE_kmod-crypto-pcbc is not set CONFIG_PACKAGE_kmod-crypto-pcompress=y # CONFIG_PACKAGE_kmod-crypto-rmd160 is not set # CONFIG_PACKAGE_kmod-crypto-rng is not set # CONFIG_PACKAGE_kmod-crypto-seqiv is not set CONFIG_PACKAGE_kmod-crypto-sha1=y # CONFIG_PACKAGE_kmod-crypto-sha256 is not set # CONFIG_PACKAGE_kmod-crypto-sha512 is not set # CONFIG_PACKAGE_kmod-crypto-test is not set CONFIG_PACKAGE_kmod-crypto-user=y # CONFIG_PACKAGE_kmod-crypto-wq is not set # CONFIG_PACKAGE_kmod-crypto-xcbc is not set # CONFIG_PACKAGE_kmod-crypto-xts is not set CONFIG_PACKAGE_kmod-cryptodev=y # end of Cryptographic API modules # # Filesystems # # CONFIG_PACKAGE_kmod-fs-afs is not set # CONFIG_PACKAGE_kmod-fs-antfs is not set # CONFIG_PACKAGE_kmod-fs-autofs4 is not set # CONFIG_PACKAGE_kmod-fs-btrfs is not set # CONFIG_PACKAGE_kmod-fs-cifs is not set # CONFIG_PACKAGE_kmod-fs-configfs is not set # CONFIG_PACKAGE_kmod-fs-cramfs is not set CONFIG_PACKAGE_kmod-fs-exfat=y # CONFIG_PACKAGE_kmod-fs-exportfs is not set CONFIG_PACKAGE_kmod-fs-ext4=y # CONFIG_PACKAGE_kmod-fs-f2fs is not set # CONFIG_PACKAGE_kmod-fs-fscache is not set # CONFIG_PACKAGE_kmod-fs-hfs is not set # CONFIG_PACKAGE_kmod-fs-hfsplus is not set # CONFIG_PACKAGE_kmod-fs-isofs is not set # CONFIG_PACKAGE_kmod-fs-jfs is not set # CONFIG_PACKAGE_kmod-fs-ksmbd is not set # CONFIG_PACKAGE_kmod-fs-minix is not set # CONFIG_PACKAGE_kmod-fs-msdos is not set # CONFIG_PACKAGE_kmod-fs-nfs is not set # CONFIG_PACKAGE_kmod-fs-nfs-common is not set # CONFIG_PACKAGE_kmod-fs-nfs-common-rpcsec is not set # CONFIG_PACKAGE_kmod-fs-nfs-v3 is not set # CONFIG_PACKAGE_kmod-fs-nfs-v4 is not set # CONFIG_PACKAGE_kmod-fs-nfsd is not set CONFIG_PACKAGE_kmod-fs-ntfs=y # CONFIG_PACKAGE_kmod-fs-reiserfs is not set # CONFIG_PACKAGE_kmod-fs-squashfs is not set # CONFIG_PACKAGE_kmod-fs-udf is not set CONFIG_PACKAGE_kmod-fs-vfat=y # CONFIG_PACKAGE_kmod-fs-xfs is not set # CONFIG_PACKAGE_kmod-fuse is not set # end of Filesystems # # FireWire support # # CONFIG_PACKAGE_kmod-firewire is not set # end of FireWire support # # Hardware Monitoring Support # # CONFIG_PACKAGE_kmod-hwmon-ad7418 is not set # CONFIG_PACKAGE_kmod-hwmon-adcxx is not set # CONFIG_PACKAGE_kmod-hwmon-ads1015 is not set # CONFIG_PACKAGE_kmod-hwmon-adt7410 is not set # CONFIG_PACKAGE_kmod-hwmon-adt7475 is not set # CONFIG_PACKAGE_kmod-hwmon-core is not set # CONFIG_PACKAGE_kmod-hwmon-dme1737 is not set # CONFIG_PACKAGE_kmod-hwmon-drivetemp is not set # CONFIG_PACKAGE_kmod-hwmon-gpiofan is not set # CONFIG_PACKAGE_kmod-hwmon-ina209 is not set # CONFIG_PACKAGE_kmod-hwmon-ina2xx is not set # CONFIG_PACKAGE_kmod-hwmon-it87 is not set # CONFIG_PACKAGE_kmod-hwmon-lm63 is not set # CONFIG_PACKAGE_kmod-hwmon-lm75 is not set # CONFIG_PACKAGE_kmod-hwmon-lm77 is not set # CONFIG_PACKAGE_kmod-hwmon-lm85 is not set # CONFIG_PACKAGE_kmod-hwmon-lm90 is not set # CONFIG_PACKAGE_kmod-hwmon-lm92 is not set # CONFIG_PACKAGE_kmod-hwmon-lm95241 is not set # CONFIG_PACKAGE_kmod-hwmon-ltc4151 is not set # CONFIG_PACKAGE_kmod-hwmon-mcp3021 is not set # CONFIG_PACKAGE_kmod-hwmon-pwmfan is not set # CONFIG_PACKAGE_kmod-hwmon-sch5627 is not set # CONFIG_PACKAGE_kmod-hwmon-sht21 is not set # CONFIG_PACKAGE_kmod-hwmon-tmp102 is not set # CONFIG_PACKAGE_kmod-hwmon-tmp103 is not set # CONFIG_PACKAGE_kmod-hwmon-tmp421 is not set # CONFIG_PACKAGE_kmod-hwmon-vid is not set # CONFIG_PACKAGE_kmod-hwmon-w83793 is not set # CONFIG_PACKAGE_kmod-pmbus-core is not set # CONFIG_PACKAGE_kmod-pmbus-zl6100 is not set # end of Hardware Monitoring Support # # I2C support # # CONFIG_PACKAGE_kmod-i2c-algo-bit is not set # CONFIG_PACKAGE_kmod-i2c-algo-pca is not set # CONFIG_PACKAGE_kmod-i2c-algo-pcf is not set # CONFIG_PACKAGE_kmod-i2c-core is not set # CONFIG_PACKAGE_kmod-i2c-gpio is not set # CONFIG_PACKAGE_kmod-i2c-mux is not set # CONFIG_PACKAGE_kmod-i2c-mux-gpio is not set # CONFIG_PACKAGE_kmod-i2c-mux-pca9541 is not set # CONFIG_PACKAGE_kmod-i2c-mux-pca954x is not set # CONFIG_PACKAGE_kmod-i2c-pxa is not set # CONFIG_PACKAGE_kmod-i2c-smbus is not set # CONFIG_PACKAGE_kmod-i2c-tiny-usb is not set # end of I2C support # # Industrial I/O Modules # # CONFIG_PACKAGE_kmod-iio-ad799x is not set # CONFIG_PACKAGE_kmod-iio-am2315 is not set # CONFIG_PACKAGE_kmod-iio-bh1750 is not set # CONFIG_PACKAGE_kmod-iio-bme680 is not set # CONFIG_PACKAGE_kmod-iio-bme680-i2c is not set # CONFIG_PACKAGE_kmod-iio-bme680-spi is not set # CONFIG_PACKAGE_kmod-iio-bmp280 is not set # CONFIG_PACKAGE_kmod-iio-bmp280-i2c is not set # CONFIG_PACKAGE_kmod-iio-bmp280-spi is not set # CONFIG_PACKAGE_kmod-iio-ccs811 is not set # CONFIG_PACKAGE_kmod-iio-core is not set # CONFIG_PACKAGE_kmod-iio-dht11 is not set # CONFIG_PACKAGE_kmod-iio-fxas21002c is not set # CONFIG_PACKAGE_kmod-iio-fxas21002c-i2c is not set # CONFIG_PACKAGE_kmod-iio-fxas21002c-spi is not set # CONFIG_PACKAGE_kmod-iio-fxos8700 is not set # CONFIG_PACKAGE_kmod-iio-fxos8700-i2c is not set # CONFIG_PACKAGE_kmod-iio-fxos8700-spi is not set # CONFIG_PACKAGE_kmod-iio-hmc5843 is not set # CONFIG_PACKAGE_kmod-iio-htu21 is not set # CONFIG_PACKAGE_kmod-iio-kfifo-buf is not set # CONFIG_PACKAGE_kmod-iio-lsm6dsx is not set # CONFIG_PACKAGE_kmod-iio-lsm6dsx-i2c is not set # CONFIG_PACKAGE_kmod-iio-lsm6dsx-spi is not set # CONFIG_PACKAGE_kmod-iio-si7020 is not set # CONFIG_PACKAGE_kmod-iio-sps30 is not set # CONFIG_PACKAGE_kmod-iio-st_accel is not set # CONFIG_PACKAGE_kmod-iio-st_accel-i2c is not set # CONFIG_PACKAGE_kmod-iio-st_accel-spi is not set # CONFIG_PACKAGE_kmod-iio-tsl4531 is not set # CONFIG_PACKAGE_kmod-industrialio-triggered-buffer is not set # end of Industrial I/O Modules # # Input modules # # CONFIG_PACKAGE_kmod-hid is not set # CONFIG_PACKAGE_kmod-hid-generic is not set # CONFIG_PACKAGE_kmod-input-core is not set # CONFIG_PACKAGE_kmod-input-evdev is not set # CONFIG_PACKAGE_kmod-input-gpio-encoder is not set # CONFIG_PACKAGE_kmod-input-gpio-keys is not set # CONFIG_PACKAGE_kmod-input-gpio-keys-polled is not set # CONFIG_PACKAGE_kmod-input-joydev is not set # CONFIG_PACKAGE_kmod-input-matrixkmap is not set # CONFIG_PACKAGE_kmod-input-polldev is not set # CONFIG_PACKAGE_kmod-input-touchscreen-ads7846 is not set # CONFIG_PACKAGE_kmod-input-uinput is not set # end of Input modules # # LED modules # CONFIG_PACKAGE_kmod-leds-gpio=y # CONFIG_PACKAGE_kmod-leds-pca963x is not set # CONFIG_PACKAGE_kmod-ledtrig-activity is not set # CONFIG_PACKAGE_kmod-ledtrig-default-on is not set # CONFIG_PACKAGE_kmod-ledtrig-gpio is not set # CONFIG_PACKAGE_kmod-ledtrig-heartbeat is not set # CONFIG_PACKAGE_kmod-ledtrig-netdev is not set # CONFIG_PACKAGE_kmod-ledtrig-oneshot is not set # CONFIG_PACKAGE_kmod-ledtrig-timer is not set # CONFIG_PACKAGE_kmod-ledtrig-transient is not set # end of LED modules # # Libraries # CONFIG_PACKAGE_kmod-asn1-decoder=y # CONFIG_PACKAGE_kmod-lib-cordic is not set CONFIG_PACKAGE_kmod-lib-crc-ccitt=y # CONFIG_PACKAGE_kmod-lib-crc-itu-t is not set CONFIG_PACKAGE_kmod-lib-crc16=y # CONFIG_PACKAGE_kmod-lib-crc32c is not set # CONFIG_PACKAGE_kmod-lib-crc7 is not set # CONFIG_PACKAGE_kmod-lib-crc8 is not set # CONFIG_PACKAGE_kmod-lib-lz4 is not set CONFIG_PACKAGE_kmod-lib-textsearch=y # end of Libraries # # Native Language Support # CONFIG_PACKAGE_kmod-nls-base=y # CONFIG_PACKAGE_kmod-nls-cp1250 is not set # CONFIG_PACKAGE_kmod-nls-cp1251 is not set CONFIG_PACKAGE_kmod-nls-cp437=y # CONFIG_PACKAGE_kmod-nls-cp775 is not set # CONFIG_PACKAGE_kmod-nls-cp850 is not set # CONFIG_PACKAGE_kmod-nls-cp852 is not set # CONFIG_PACKAGE_kmod-nls-cp862 is not set # CONFIG_PACKAGE_kmod-nls-cp864 is not set # CONFIG_PACKAGE_kmod-nls-cp866 is not set # CONFIG_PACKAGE_kmod-nls-cp932 is not set # CONFIG_PACKAGE_kmod-nls-cp936 is not set # CONFIG_PACKAGE_kmod-nls-cp950 is not set CONFIG_PACKAGE_kmod-nls-iso8859-1=y # CONFIG_PACKAGE_kmod-nls-iso8859-13 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-15 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-2 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-6 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-8 is not set # CONFIG_PACKAGE_kmod-nls-koi8r is not set CONFIG_PACKAGE_kmod-nls-utf8=y # end of Native Language Support # # Netfilter Extensions # # CONFIG_PACKAGE_kmod-arptables is not set # CONFIG_PACKAGE_kmod-br-netfilter is not set # CONFIG_PACKAGE_kmod-ebtables is not set # CONFIG_PACKAGE_kmod-ebtables-ipv4 is not set # CONFIG_PACKAGE_kmod-ebtables-ipv6 is not set # CONFIG_PACKAGE_kmod-ebtables-watchers is not set CONFIG_PACKAGE_kmod-ip6tables=y # CONFIG_PACKAGE_kmod-ip6tables-extra is not set # CONFIG_PACKAGE_kmod-ipt-account is not set # CONFIG_PACKAGE_kmod-ipt-chaos is not set # CONFIG_PACKAGE_kmod-ipt-checksum is not set # CONFIG_PACKAGE_kmod-ipt-cluster is not set # CONFIG_PACKAGE_kmod-ipt-clusterip is not set # CONFIG_PACKAGE_kmod-ipt-compat-xtables is not set # CONFIG_PACKAGE_kmod-ipt-condition is not set CONFIG_PACKAGE_kmod-ipt-conntrack=y # CONFIG_PACKAGE_kmod-ipt-conntrack-extra is not set # CONFIG_PACKAGE_kmod-ipt-conntrack-label is not set CONFIG_PACKAGE_kmod-ipt-core=y # CONFIG_PACKAGE_kmod-ipt-debug is not set # CONFIG_PACKAGE_kmod-ipt-delude is not set # CONFIG_PACKAGE_kmod-ipt-dhcpmac is not set # CONFIG_PACKAGE_kmod-ipt-dnetmap is not set CONFIG_PACKAGE_kmod-ipt-extra=y # CONFIG_PACKAGE_kmod-ipt-filter is not set CONFIG_PACKAGE_kmod-ipt-fullconenat=y # CONFIG_PACKAGE_kmod-ipt-fuzzy is not set # CONFIG_PACKAGE_kmod-ipt-geoip is not set # CONFIG_PACKAGE_kmod-ipt-hashlimit is not set # CONFIG_PACKAGE_kmod-ipt-iface is not set # CONFIG_PACKAGE_kmod-ipt-ipmark is not set # CONFIG_PACKAGE_kmod-ipt-ipopt is not set # CONFIG_PACKAGE_kmod-ipt-ipp2p is not set # CONFIG_PACKAGE_kmod-ipt-iprange is not set # CONFIG_PACKAGE_kmod-ipt-ipsec is not set CONFIG_PACKAGE_kmod-ipt-ipset=y # CONFIG_PACKAGE_kmod-ipt-ipv4options is not set # CONFIG_PACKAGE_kmod-ipt-led is not set # CONFIG_PACKAGE_kmod-ipt-length2 is not set # CONFIG_PACKAGE_kmod-ipt-logmark is not set # CONFIG_PACKAGE_kmod-ipt-lscan is not set # CONFIG_PACKAGE_kmod-ipt-lua is not set CONFIG_PACKAGE_kmod-ipt-nat=y # CONFIG_PACKAGE_kmod-ipt-nat-extra is not set # CONFIG_PACKAGE_kmod-ipt-nat6 is not set # CONFIG_PACKAGE_kmod-ipt-nathelper-rtsp is not set # CONFIG_PACKAGE_kmod-ipt-nflog is not set # CONFIG_PACKAGE_kmod-ipt-nfqueue is not set CONFIG_PACKAGE_kmod-ipt-offload=y # CONFIG_PACKAGE_kmod-ipt-physdev is not set # CONFIG_PACKAGE_kmod-ipt-proto is not set # CONFIG_PACKAGE_kmod-ipt-psd is not set # CONFIG_PACKAGE_kmod-ipt-quota2 is not set CONFIG_PACKAGE_kmod-ipt-raw=y # CONFIG_PACKAGE_kmod-ipt-raw6 is not set # CONFIG_PACKAGE_kmod-ipt-rpfilter is not set # CONFIG_PACKAGE_kmod-ipt-rtpengine is not set # CONFIG_PACKAGE_kmod-ipt-sysrq is not set # CONFIG_PACKAGE_kmod-ipt-tarpit is not set # CONFIG_PACKAGE_kmod-ipt-tee is not set CONFIG_PACKAGE_kmod-ipt-tproxy=y # CONFIG_PACKAGE_kmod-ipt-u32 is not set # CONFIG_PACKAGE_kmod-ipt-ulog is not set # CONFIG_PACKAGE_kmod-netatop is not set CONFIG_PACKAGE_kmod-nf-conntrack=y # CONFIG_PACKAGE_kmod-nf-conntrack-netlink is not set CONFIG_PACKAGE_kmod-nf-conntrack6=y CONFIG_PACKAGE_kmod-nf-flow=y CONFIG_PACKAGE_kmod-nf-ipt=y CONFIG_PACKAGE_kmod-nf-ipt6=y # CONFIG_PACKAGE_kmod-nf-ipvs is not set CONFIG_PACKAGE_kmod-nf-nat=y # CONFIG_PACKAGE_kmod-nf-nat6 is not set CONFIG_PACKAGE_kmod-nf-nathelper=y CONFIG_PACKAGE_kmod-nf-nathelper-extra=y CONFIG_PACKAGE_kmod-nf-reject=y CONFIG_PACKAGE_kmod-nf-reject6=y CONFIG_PACKAGE_kmod-nfnetlink=y # CONFIG_PACKAGE_kmod-nfnetlink-log is not set # CONFIG_PACKAGE_kmod-nfnetlink-queue is not set # CONFIG_PACKAGE_kmod-nft-arp is not set # CONFIG_PACKAGE_kmod-nft-bridge is not set # CONFIG_PACKAGE_kmod-nft-core is not set # CONFIG_PACKAGE_kmod-nft-fib is not set # CONFIG_PACKAGE_kmod-nft-nat is not set # CONFIG_PACKAGE_kmod-nft-nat6 is not set # CONFIG_PACKAGE_kmod-nft-netdev is not set # CONFIG_PACKAGE_kmod-nft-offload is not set # CONFIG_PACKAGE_kmod-nft-queue is not set # end of Netfilter Extensions # # Network Devices # # CONFIG_PACKAGE_kmod-3c59x is not set # CONFIG_PACKAGE_kmod-8139cp is not set # CONFIG_PACKAGE_kmod-8139too is not set # CONFIG_PACKAGE_kmod-alx is not set # CONFIG_PACKAGE_kmod-atl1 is not set # CONFIG_PACKAGE_kmod-atl1c is not set # CONFIG_PACKAGE_kmod-atl1e is not set # CONFIG_PACKAGE_kmod-atl2 is not set # CONFIG_PACKAGE_kmod-b44 is not set # CONFIG_PACKAGE_kmod-be2net is not set # CONFIG_PACKAGE_kmod-bnx2 is not set # CONFIG_PACKAGE_kmod-bnx2x is not set # CONFIG_PACKAGE_kmod-dm9000 is not set # CONFIG_PACKAGE_kmod-dummy is not set # CONFIG_PACKAGE_kmod-e100 is not set # CONFIG_PACKAGE_kmod-e1000 is not set # CONFIG_PACKAGE_kmod-et131x is not set # CONFIG_PACKAGE_kmod-ethoc is not set # CONFIG_PACKAGE_kmod-forcedeth is not set # CONFIG_PACKAGE_kmod-hfcmulti is not set # CONFIG_PACKAGE_kmod-hfcpci is not set # CONFIG_PACKAGE_kmod-i40e is not set # CONFIG_PACKAGE_kmod-iavf is not set # CONFIG_PACKAGE_kmod-ifb is not set # CONFIG_PACKAGE_kmod-igb is not set # CONFIG_PACKAGE_kmod-igc is not set # CONFIG_PACKAGE_kmod-ixgbe is not set # CONFIG_PACKAGE_kmod-ixgbevf is not set # CONFIG_PACKAGE_kmod-libphy is not set CONFIG_PACKAGE_kmod-macvlan=y # CONFIG_PACKAGE_kmod-mdio-gpio is not set # CONFIG_PACKAGE_kmod-mii is not set # CONFIG_PACKAGE_kmod-mlx4-core is not set # CONFIG_PACKAGE_kmod-mlx5-core is not set # CONFIG_PACKAGE_kmod-natsemi is not set # CONFIG_PACKAGE_kmod-ne2k-pci is not set # CONFIG_PACKAGE_kmod-niu is not set # CONFIG_PACKAGE_kmod-of-mdio is not set # CONFIG_PACKAGE_kmod-pcnet32 is not set # CONFIG_PACKAGE_kmod-phy-bcm84881 is not set # CONFIG_PACKAGE_kmod-phy-broadcom is not set # CONFIG_PACKAGE_kmod-phy-realtek is not set # CONFIG_PACKAGE_kmod-phylink is not set # CONFIG_PACKAGE_kmod-r6040 is not set # CONFIG_PACKAGE_kmod-r8125 is not set # CONFIG_PACKAGE_kmod-r8168 is not set # CONFIG_PACKAGE_kmod-r8169 is not set # CONFIG_PACKAGE_kmod-sfc is not set # CONFIG_PACKAGE_kmod-sfc-falcon is not set # CONFIG_PACKAGE_kmod-sfp is not set # CONFIG_PACKAGE_kmod-siit is not set # CONFIG_PACKAGE_kmod-sis190 is not set # CONFIG_PACKAGE_kmod-sis900 is not set # CONFIG_PACKAGE_kmod-skge is not set # CONFIG_PACKAGE_kmod-sky2 is not set # CONFIG_PACKAGE_kmod-solos-pci is not set # CONFIG_PACKAGE_kmod-spi-ks8995 is not set # CONFIG_PACKAGE_kmod-swconfig is not set # CONFIG_PACKAGE_kmod-switch-bcm53xx is not set # CONFIG_PACKAGE_kmod-switch-bcm53xx-mdio is not set # CONFIG_PACKAGE_kmod-switch-ip17xx is not set # CONFIG_PACKAGE_kmod-switch-mvsw61xx is not set # CONFIG_PACKAGE_kmod-switch-rtl8306 is not set # CONFIG_PACKAGE_kmod-switch-rtl8366-smi is not set # CONFIG_PACKAGE_kmod-switch-rtl8366rb is not set # CONFIG_PACKAGE_kmod-switch-rtl8366s is not set # CONFIG_PACKAGE_kmod-switch-rtl8367b is not set # CONFIG_PACKAGE_kmod-tg3 is not set # CONFIG_PACKAGE_kmod-tulip is not set # CONFIG_PACKAGE_kmod-via-rhine is not set # CONFIG_PACKAGE_kmod-via-velocity is not set # CONFIG_PACKAGE_kmod-vmxnet3 is not set # end of Network Devices # # Network Support # # CONFIG_PACKAGE_kmod-atm is not set # CONFIG_PACKAGE_kmod-ax25 is not set # CONFIG_PACKAGE_kmod-batman-adv is not set # CONFIG_PACKAGE_kmod-bonding is not set # CONFIG_PACKAGE_kmod-bpf-test is not set # CONFIG_PACKAGE_kmod-capi is not set # CONFIG_PACKAGE_kmod-dnsresolver is not set CONFIG_PACKAGE_kmod-fast-classifier=y # CONFIG_PACKAGE_kmod-fast-classifier-noload is not set # CONFIG_PACKAGE_kmod-fou is not set # CONFIG_PACKAGE_kmod-fou6 is not set # CONFIG_PACKAGE_kmod-geneve is not set # CONFIG_PACKAGE_kmod-gre is not set # CONFIG_PACKAGE_kmod-gre6 is not set # CONFIG_PACKAGE_kmod-ip6-tunnel is not set # CONFIG_PACKAGE_kmod-ipip is not set # CONFIG_PACKAGE_kmod-ipsec is not set # CONFIG_PACKAGE_kmod-iptunnel6 is not set # CONFIG_PACKAGE_kmod-isdn4linux is not set # CONFIG_PACKAGE_kmod-jool is not set # CONFIG_PACKAGE_kmod-l2tp is not set # CONFIG_PACKAGE_kmod-l2tp-eth is not set # CONFIG_PACKAGE_kmod-l2tp-ip is not set # CONFIG_PACKAGE_kmod-macremapper is not set # CONFIG_PACKAGE_kmod-macsec is not set # CONFIG_PACKAGE_kmod-misdn is not set # CONFIG_PACKAGE_kmod-mpls is not set # CONFIG_PACKAGE_kmod-nat46 is not set # CONFIG_PACKAGE_kmod-netem is not set # CONFIG_PACKAGE_kmod-netlink-diag is not set # CONFIG_PACKAGE_kmod-nlmon is not set # CONFIG_PACKAGE_kmod-nsh is not set # CONFIG_PACKAGE_kmod-openvswitch is not set # CONFIG_PACKAGE_kmod-openvswitch-geneve is not set # CONFIG_PACKAGE_kmod-openvswitch-gre is not set # CONFIG_PACKAGE_kmod-openvswitch-vxlan is not set # CONFIG_PACKAGE_kmod-pf-ring is not set # CONFIG_PACKAGE_kmod-pktgen is not set CONFIG_PACKAGE_kmod-ppp=y CONFIG_PACKAGE_kmod-mppe=y # CONFIG_PACKAGE_kmod-ppp-synctty is not set # CONFIG_PACKAGE_kmod-pppoa is not set CONFIG_PACKAGE_kmod-pppoe=y # CONFIG_PACKAGE_kmod-pppol2tp is not set CONFIG_PACKAGE_kmod-pppox=y # CONFIG_PACKAGE_kmod-pptp is not set # CONFIG_PACKAGE_kmod-sched is not set # CONFIG_PACKAGE_kmod-sched-act-vlan is not set # CONFIG_PACKAGE_kmod-sched-bpf is not set # CONFIG_PACKAGE_kmod-sched-cake is not set # CONFIG_PACKAGE_kmod-sched-cake-virtual is not set # CONFIG_PACKAGE_kmod-sched-connmark is not set # CONFIG_PACKAGE_kmod-sched-core is not set # CONFIG_PACKAGE_kmod-sched-ctinfo is not set # CONFIG_PACKAGE_kmod-sched-flower is not set # CONFIG_PACKAGE_kmod-sched-ipset is not set # CONFIG_PACKAGE_kmod-sched-mqprio is not set # CONFIG_PACKAGE_kmod-sctp is not set CONFIG_PACKAGE_kmod-shortcut-fe=y # CONFIG_PACKAGE_kmod-shortcut-fe-cm is not set # CONFIG_PACKAGE_kmod-sit is not set CONFIG_PACKAGE_kmod-slhc=y # CONFIG_PACKAGE_kmod-slip is not set CONFIG_PACKAGE_kmod-tcp-bbr=y # CONFIG_PACKAGE_kmod-trelay is not set CONFIG_PACKAGE_kmod-tun=y # CONFIG_PACKAGE_kmod-veth is not set # CONFIG_PACKAGE_kmod-vxlan is not set # CONFIG_PACKAGE_kmod-wireguard is not set # end of Network Support # # Other modules # # CONFIG_PACKAGE_kmod-6lowpan is not set # CONFIG_PACKAGE_kmod-ath3k is not set # CONFIG_PACKAGE_kmod-bcma is not set # CONFIG_PACKAGE_kmod-bluetooth is not set # CONFIG_PACKAGE_kmod-bluetooth-6lowpan is not set # CONFIG_PACKAGE_kmod-bmp085 is not set # CONFIG_PACKAGE_kmod-bmp085-i2c is not set # CONFIG_PACKAGE_kmod-bmp085-spi is not set # CONFIG_PACKAGE_kmod-btmrvl is not set # CONFIG_PACKAGE_kmod-button-hotplug is not set # CONFIG_PACKAGE_kmod-dma-ralink is not set # CONFIG_PACKAGE_kmod-echo is not set # CONFIG_PACKAGE_kmod-eeprom-93cx6 is not set # CONFIG_PACKAGE_kmod-eeprom-at24 is not set # CONFIG_PACKAGE_kmod-eeprom-at25 is not set # CONFIG_PACKAGE_kmod-gpio-beeper is not set CONFIG_PACKAGE_kmod-gpio-button-hotplug=y # CONFIG_PACKAGE_kmod-gpio-dev is not set # CONFIG_PACKAGE_kmod-gpio-mcp23s08 is not set # CONFIG_PACKAGE_kmod-gpio-nxp-74hc164 is not set # CONFIG_PACKAGE_kmod-gpio-pca953x is not set # CONFIG_PACKAGE_kmod-gpio-pcf857x is not set # CONFIG_PACKAGE_kmod-hsdma-mtk is not set # CONFIG_PACKAGE_kmod-ikconfig is not set # CONFIG_PACKAGE_kmod-it87-wdt is not set # CONFIG_PACKAGE_kmod-itco-wdt is not set # CONFIG_PACKAGE_kmod-lp is not set # CONFIG_PACKAGE_kmod-mmc is not set # CONFIG_PACKAGE_kmod-mtd-rw is not set # CONFIG_PACKAGE_kmod-mtdoops is not set # CONFIG_PACKAGE_kmod-mtdram is not set # CONFIG_PACKAGE_kmod-mtdtests is not set # CONFIG_PACKAGE_kmod-parport-pc is not set # CONFIG_PACKAGE_kmod-ppdev is not set # CONFIG_PACKAGE_kmod-pps is not set # CONFIG_PACKAGE_kmod-pps-gpio is not set # CONFIG_PACKAGE_kmod-pps-ldisc is not set # CONFIG_PACKAGE_kmod-ptp is not set # CONFIG_PACKAGE_kmod-random-core is not set # CONFIG_PACKAGE_kmod-rtc-ds1307 is not set # CONFIG_PACKAGE_kmod-rtc-ds1374 is not set # CONFIG_PACKAGE_kmod-rtc-ds1672 is not set # CONFIG_PACKAGE_kmod-rtc-em3027 is not set # CONFIG_PACKAGE_kmod-rtc-isl1208 is not set # CONFIG_PACKAGE_kmod-rtc-pcf2123 is not set # CONFIG_PACKAGE_kmod-rtc-pcf2127 is not set # CONFIG_PACKAGE_kmod-rtc-pcf8563 is not set # CONFIG_PACKAGE_kmod-rtc-pt7c4338 is not set # CONFIG_PACKAGE_kmod-rtc-rs5c372a is not set # CONFIG_PACKAGE_kmod-rtc-rx8025 is not set # CONFIG_PACKAGE_kmod-rtc-s35390a is not set # CONFIG_PACKAGE_kmod-sdhci is not set # CONFIG_PACKAGE_kmod-sdhci-mt7620 is not set # CONFIG_PACKAGE_kmod-serial-8250 is not set # CONFIG_PACKAGE_kmod-serial-8250-exar is not set # CONFIG_PACKAGE_kmod-softdog is not set # CONFIG_PACKAGE_kmod-ssb is not set # CONFIG_PACKAGE_kmod-tpm is not set # CONFIG_PACKAGE_kmod-tpm-i2c-atmel is not set # CONFIG_PACKAGE_kmod-tpm-i2c-infineon is not set # CONFIG_PACKAGE_kmod-w83627hf-wdt is not set # CONFIG_PACKAGE_kmod-zram is not set # end of Other modules # # PCMCIA support # # end of PCMCIA support # # SPI Support # # CONFIG_PACKAGE_kmod-mmc-spi is not set # CONFIG_PACKAGE_kmod-spi-bitbang is not set # CONFIG_PACKAGE_kmod-spi-dev is not set # CONFIG_PACKAGE_kmod-spi-gpio is not set # end of SPI Support # # Sound Support # # CONFIG_PACKAGE_kmod-sound-core is not set # end of Sound Support # # USB Support # # CONFIG_PACKAGE_kmod-chaoskey is not set # CONFIG_PACKAGE_kmod-usb-acm is not set # CONFIG_PACKAGE_kmod-usb-atm is not set # CONFIG_PACKAGE_kmod-usb-cm109 is not set CONFIG_PACKAGE_kmod-usb-core=y # CONFIG_PACKAGE_kmod-usb-dwc2 is not set # CONFIG_PACKAGE_kmod-usb-dwc3 is not set CONFIG_PACKAGE_kmod-usb-ehci=y # CONFIG_PACKAGE_kmod-usb-hid is not set # CONFIG_PACKAGE_kmod-usb-ledtrig-usbport is not set # CONFIG_PACKAGE_kmod-usb-net is not set # CONFIG_PACKAGE_kmod-usb-net-aqc111 is not set # CONFIG_PACKAGE_kmod-usb-net-asix is not set # CONFIG_PACKAGE_kmod-usb-net-asix-ax88179 is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-eem is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-ether is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-mbim is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-ncm is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-subset is not set # CONFIG_PACKAGE_kmod-usb-net-dm9601-ether is not set # CONFIG_PACKAGE_kmod-usb-net-hso is not set # CONFIG_PACKAGE_kmod-usb-net-huawei-cdc-ncm is not set # CONFIG_PACKAGE_kmod-usb-net-ipheth is not set # CONFIG_PACKAGE_kmod-usb-net-kalmia is not set # CONFIG_PACKAGE_kmod-usb-net-kaweth is not set # CONFIG_PACKAGE_kmod-usb-net-mcs7830 is not set # CONFIG_PACKAGE_kmod-usb-net-pegasus is not set # CONFIG_PACKAGE_kmod-usb-net-pl is not set # CONFIG_PACKAGE_kmod-usb-net-qmi-wwan is not set # CONFIG_PACKAGE_kmod-usb-net-rndis is not set # CONFIG_PACKAGE_kmod-usb-net-rtl8150 is not set # CONFIG_PACKAGE_kmod-usb-net-rtl8152 is not set # CONFIG_PACKAGE_kmod-usb-net-sierrawireless is not set # CONFIG_PACKAGE_kmod-usb-net-smsc95xx is not set # CONFIG_PACKAGE_kmod-usb-net-sr9700 is not set # CONFIG_PACKAGE_kmod-usb-ohci is not set # CONFIG_PACKAGE_kmod-usb-ohci-pci is not set # CONFIG_PACKAGE_kmod-usb-printer is not set # CONFIG_PACKAGE_kmod-usb-serial is not set CONFIG_PACKAGE_kmod-usb-storage=y # CONFIG_PACKAGE_kmod-usb-storage-extras is not set # CONFIG_PACKAGE_kmod-usb-storage-uas is not set # CONFIG_PACKAGE_kmod-usb-uhci is not set # CONFIG_PACKAGE_kmod-usb-wdm is not set # CONFIG_PACKAGE_kmod-usb-yealink is not set CONFIG_PACKAGE_kmod-usb2=y # CONFIG_PACKAGE_kmod-usb2-pci is not set CONFIG_PACKAGE_kmod-usb3=y # CONFIG_PACKAGE_kmod-usbip is not set # CONFIG_PACKAGE_kmod-usbip-client is not set # CONFIG_PACKAGE_kmod-usbip-server is not set # CONFIG_PACKAGE_kmod-usbmon is not set # end of USB Support # # Video Support # # CONFIG_PACKAGE_kmod-video-core is not set # end of Video Support # # Virtualization # # end of Virtualization # # Voice over IP # # CONFIG_PACKAGE_kmod-dahdi is not set # end of Voice over IP # # W1 support # # CONFIG_PACKAGE_kmod-w1 is not set # end of W1 support # # WPAN 802.15.4 Support # # CONFIG_PACKAGE_kmod-at86rf230 is not set # CONFIG_PACKAGE_kmod-atusb is not set # CONFIG_PACKAGE_kmod-ca8210 is not set # CONFIG_PACKAGE_kmod-cc2520 is not set # CONFIG_PACKAGE_kmod-fakelb is not set # CONFIG_PACKAGE_kmod-ieee802154 is not set # CONFIG_PACKAGE_kmod-ieee802154-6lowpan is not set # CONFIG_PACKAGE_kmod-mac802154 is not set # CONFIG_PACKAGE_kmod-mrf24j40 is not set # end of WPAN 802.15.4 Support # # Wireless Drivers # # CONFIG_PACKAGE_kmod-acx-mac80211 is not set # CONFIG_PACKAGE_kmod-adm8211 is not set # CONFIG_PACKAGE_kmod-ar5523 is not set # CONFIG_PACKAGE_kmod-ath is not set # CONFIG_PACKAGE_kmod-ath10k is not set # CONFIG_PACKAGE_kmod-ath10k-ct is not set # CONFIG_PACKAGE_kmod-ath10k-ct-smallbuffers is not set # CONFIG_PACKAGE_kmod-ath5k is not set # CONFIG_PACKAGE_kmod-ath6kl-sdio is not set # CONFIG_PACKAGE_kmod-ath6kl-usb is not set # CONFIG_PACKAGE_kmod-ath9k is not set # CONFIG_PACKAGE_kmod-ath9k-htc is not set # CONFIG_PACKAGE_kmod-b43 is not set # CONFIG_PACKAGE_kmod-b43legacy is not set # CONFIG_PACKAGE_kmod-brcmfmac is not set # CONFIG_PACKAGE_kmod-brcmsmac is not set # CONFIG_PACKAGE_kmod-brcmutil is not set # CONFIG_PACKAGE_kmod-carl9170 is not set CONFIG_PACKAGE_kmod-cfg80211=y # CONFIG_PACKAGE_CFG80211_TESTMODE is not set # CONFIG_PACKAGE_kmod-hermes is not set # CONFIG_PACKAGE_kmod-hermes-pci is not set # CONFIG_PACKAGE_kmod-hermes-plx is not set # CONFIG_PACKAGE_kmod-ipw2100 is not set # CONFIG_PACKAGE_kmod-ipw2200 is not set # CONFIG_PACKAGE_kmod-iwl-legacy is not set # CONFIG_PACKAGE_kmod-iwl3945 is not set # CONFIG_PACKAGE_kmod-iwl4965 is not set # CONFIG_PACKAGE_kmod-iwlwifi is not set # CONFIG_PACKAGE_kmod-lib80211 is not set # CONFIG_PACKAGE_kmod-libertas-sdio is not set # CONFIG_PACKAGE_kmod-libertas-spi is not set # CONFIG_PACKAGE_kmod-libertas-usb is not set # CONFIG_PACKAGE_kmod-libipw is not set CONFIG_PACKAGE_kmod-mac80211=y CONFIG_PACKAGE_MAC80211_DEBUGFS=y # CONFIG_PACKAGE_MAC80211_TRACING is not set CONFIG_PACKAGE_MAC80211_MESH=y # CONFIG_PACKAGE_kmod-mac80211-hwsim is not set # CONFIG_PACKAGE_kmod-mt76 is not set CONFIG_PACKAGE_kmod-mt76-core=y # CONFIG_PACKAGE_kmod-mt7601u is not set # CONFIG_PACKAGE_kmod-mt7603 is not set # CONFIG_PACKAGE_kmod-mt7603e is not set CONFIG_PACKAGE_kmod-mt7615-common=y CONFIG_PACKAGE_kmod-mt7615-firmware=y # CONFIG_PACKAGE_kmod-mt7615d is not set # CONFIG_PACKAGE_kmod-mt7615d_dbdc is not set CONFIG_PACKAGE_kmod-mt7615e=y # CONFIG_PACKAGE_kmod-mt7663-firmware-ap is not set # CONFIG_PACKAGE_kmod-mt7663-firmware-sta is not set # CONFIG_PACKAGE_kmod-mt7663s is not set # CONFIG_PACKAGE_kmod-mt7663u is not set # CONFIG_PACKAGE_kmod-mt76x0e is not set # CONFIG_PACKAGE_kmod-mt76x0u is not set # CONFIG_PACKAGE_kmod-mt76x2 is not set # CONFIG_PACKAGE_kmod-mt76x2e is not set # CONFIG_PACKAGE_kmod-mt76x2u is not set # CONFIG_PACKAGE_kmod-mt7915e is not set # CONFIG_PACKAGE_kmod-mwifiex-pcie is not set # CONFIG_PACKAGE_kmod-mwifiex-sdio is not set # CONFIG_PACKAGE_kmod-mwl8k is not set # CONFIG_PACKAGE_kmod-net-prism54 is not set # CONFIG_PACKAGE_kmod-net-rtl8192su is not set # CONFIG_PACKAGE_kmod-owl-loader is not set # CONFIG_PACKAGE_kmod-p54-common is not set # CONFIG_PACKAGE_kmod-p54-pci is not set # CONFIG_PACKAGE_kmod-p54-usb is not set # CONFIG_PACKAGE_kmod-rsi91x is not set # CONFIG_PACKAGE_kmod-rsi91x-sdio is not set # CONFIG_PACKAGE_kmod-rsi91x-usb is not set # CONFIG_PACKAGE_kmod-rt2400-pci is not set # CONFIG_PACKAGE_kmod-rt2500-pci is not set # CONFIG_PACKAGE_kmod-rt2500-usb is not set # CONFIG_PACKAGE_kmod-rt2800-pci is not set # CONFIG_PACKAGE_kmod-rt2800-usb is not set # CONFIG_PACKAGE_kmod-rt2x00-lib is not set # CONFIG_PACKAGE_kmod-rt61-pci is not set # CONFIG_PACKAGE_kmod-rt73-usb is not set # CONFIG_PACKAGE_kmod-rtl8180 is not set # CONFIG_PACKAGE_kmod-rtl8187 is not set # CONFIG_PACKAGE_kmod-rtl8192ce is not set # CONFIG_PACKAGE_kmod-rtl8192cu is not set # CONFIG_PACKAGE_kmod-rtl8192de is not set # CONFIG_PACKAGE_kmod-rtl8192se is not set # CONFIG_PACKAGE_kmod-rtl8723bs is not set # CONFIG_PACKAGE_kmod-rtl8812au-ct is not set # CONFIG_PACKAGE_kmod-rtl8821ae is not set # CONFIG_PACKAGE_kmod-rtl8xxxu is not set # CONFIG_PACKAGE_kmod-rtw88 is not set # CONFIG_PACKAGE_kmod-wil6210 is not set # CONFIG_PACKAGE_kmod-wl12xx is not set # CONFIG_PACKAGE_kmod-wl18xx is not set # CONFIG_PACKAGE_kmod-wlcore is not set # CONFIG_PACKAGE_kmod-zd1211rw is not set # end of Wireless Drivers # end of Kernel modules # # Languages # # # Erlang # # CONFIG_PACKAGE_erlang is not set # CONFIG_PACKAGE_erlang-asn1 is not set # CONFIG_PACKAGE_erlang-compiler is not set # CONFIG_PACKAGE_erlang-crypto is not set # CONFIG_PACKAGE_erlang-erl-interface is not set # CONFIG_PACKAGE_erlang-hipe is not set # CONFIG_PACKAGE_erlang-inets is not set # CONFIG_PACKAGE_erlang-mnesia is not set # CONFIG_PACKAGE_erlang-os_mon is not set # CONFIG_PACKAGE_erlang-public-key is not set # CONFIG_PACKAGE_erlang-reltool is not set # CONFIG_PACKAGE_erlang-runtime-tools is not set # CONFIG_PACKAGE_erlang-snmp is not set # CONFIG_PACKAGE_erlang-ssh is not set # CONFIG_PACKAGE_erlang-ssl is not set # CONFIG_PACKAGE_erlang-syntax-tools is not set # CONFIG_PACKAGE_erlang-tools is not set # CONFIG_PACKAGE_erlang-xmerl is not set # end of Erlang # # Go # # CONFIG_PACKAGE_golang is not set # # Configuration # CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT="" CONFIG_GOLANG_BUILD_CACHE_DIR="" # CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE is not set # end of Configuration # CONFIG_PACKAGE_golang-doc is not set # CONFIG_PACKAGE_golang-github-jedisct1-dnscrypt-proxy2-dev is not set # CONFIG_PACKAGE_golang-github-nextdns-nextdns-dev is not set # CONFIG_PACKAGE_golang-gitlab-yawning-obfs4-dev is not set # CONFIG_PACKAGE_golang-src is not set # CONFIG_PACKAGE_golang-torproject-tor-fw-helper-dev is not set # end of Go # # Lua # # CONFIG_PACKAGE_dkjson is not set # CONFIG_PACKAGE_json4lua is not set # CONFIG_PACKAGE_ldbus is not set CONFIG_PACKAGE_libiwinfo-lua=y # CONFIG_PACKAGE_lpeg is not set # CONFIG_PACKAGE_lsqlite3 is not set CONFIG_PACKAGE_lua=y # CONFIG_PACKAGE_lua-bencode is not set # CONFIG_PACKAGE_lua-bit32 is not set # CONFIG_PACKAGE_lua-cjson is not set # CONFIG_PACKAGE_lua-copas is not set # CONFIG_PACKAGE_lua-coxpcall is not set # CONFIG_PACKAGE_lua-ev is not set # CONFIG_PACKAGE_lua-examples is not set # CONFIG_PACKAGE_lua-libmodbus is not set # CONFIG_PACKAGE_lua-lzlib is not set # CONFIG_PACKAGE_lua-md5 is not set # CONFIG_PACKAGE_lua-mobdebug is not set # CONFIG_PACKAGE_lua-mosquitto is not set # CONFIG_PACKAGE_lua-openssl is not set # CONFIG_PACKAGE_lua-penlight is not set # CONFIG_PACKAGE_lua-rings is not set # CONFIG_PACKAGE_lua-rs232 is not set # CONFIG_PACKAGE_lua-sha2 is not set # CONFIG_PACKAGE_lua-wsapi-base is not set # CONFIG_PACKAGE_lua-wsapi-xavante is not set # CONFIG_PACKAGE_lua-xavante is not set # CONFIG_PACKAGE_lua5.3 is not set # CONFIG_PACKAGE_luabitop is not set # CONFIG_PACKAGE_luac is not set # CONFIG_PACKAGE_luac5.3 is not set # CONFIG_PACKAGE_luaexpat is not set # CONFIG_PACKAGE_luafilesystem is not set # CONFIG_PACKAGE_luajit is not set # CONFIG_PACKAGE_lualanes is not set # CONFIG_PACKAGE_luaposix is not set # CONFIG_PACKAGE_luarocks is not set # CONFIG_PACKAGE_luasec is not set # CONFIG_PACKAGE_luasoap is not set # CONFIG_PACKAGE_luasocket is not set # CONFIG_PACKAGE_luasocket5.3 is not set # CONFIG_PACKAGE_luasql-mysql is not set # CONFIG_PACKAGE_luasql-pgsql is not set # CONFIG_PACKAGE_luasql-sqlite3 is not set # CONFIG_PACKAGE_luasrcdiet is not set CONFIG_PACKAGE_luci-lib-fs=y # CONFIG_PACKAGE_luv is not set # CONFIG_PACKAGE_lzmq is not set # CONFIG_PACKAGE_uuid is not set # end of Lua # # Node.js # # CONFIG_PACKAGE_node is not set # CONFIG_PACKAGE_node-arduino-firmata is not set # CONFIG_PACKAGE_node-cylon is not set # CONFIG_PACKAGE_node-cylon-firmata is not set # CONFIG_PACKAGE_node-cylon-gpio is not set # CONFIG_PACKAGE_node-cylon-i2c is not set # CONFIG_PACKAGE_node-hid is not set # CONFIG_PACKAGE_node-homebridge is not set # CONFIG_PACKAGE_node-javascript-obfuscator is not set # CONFIG_PACKAGE_node-npm is not set # CONFIG_PACKAGE_node-serialport is not set # CONFIG_PACKAGE_node-serialport-bindings is not set # end of Node.js # # PHP # # CONFIG_PACKAGE_php7 is not set # end of PHP # # Perl # # CONFIG_PACKAGE_perl is not set # end of Perl # # Python # # CONFIG_PACKAGE_gunicorn3 is not set # CONFIG_PACKAGE_micropython is not set # CONFIG_PACKAGE_micropython-lib is not set # CONFIG_PACKAGE_python-pip-conf is not set # CONFIG_PACKAGE_python3 is not set # CONFIG_PACKAGE_python3-aiohttp is not set # CONFIG_PACKAGE_python3-aiohttp-cors is not set # CONFIG_PACKAGE_python3-appdirs is not set # CONFIG_PACKAGE_python3-asgiref is not set # CONFIG_PACKAGE_python3-asn1crypto is not set # CONFIG_PACKAGE_python3-astral is not set # CONFIG_PACKAGE_python3-async-timeout is not set # CONFIG_PACKAGE_python3-asyncio is not set # CONFIG_PACKAGE_python3-atomicwrites is not set # CONFIG_PACKAGE_python3-attrs is not set # CONFIG_PACKAGE_python3-automat is not set # CONFIG_PACKAGE_python3-awscli is not set # CONFIG_PACKAGE_python3-base is not set # CONFIG_PACKAGE_python3-bcrypt is not set # CONFIG_PACKAGE_python3-boto3 is not set # CONFIG_PACKAGE_python3-botocore is not set # CONFIG_PACKAGE_python3-bottle is not set # CONFIG_PACKAGE_python3-cached-property is not set # CONFIG_PACKAGE_python3-cachelib is not set # CONFIG_PACKAGE_python3-cachetools is not set # CONFIG_PACKAGE_python3-certifi is not set # CONFIG_PACKAGE_python3-cffi is not set # CONFIG_PACKAGE_python3-cgi is not set # CONFIG_PACKAGE_python3-cgitb is not set # CONFIG_PACKAGE_python3-chardet is not set # CONFIG_PACKAGE_python3-click is not set # CONFIG_PACKAGE_python3-click-log is not set # CONFIG_PACKAGE_python3-codecs is not set # CONFIG_PACKAGE_python3-colorama is not set # CONFIG_PACKAGE_python3-constantly is not set # CONFIG_PACKAGE_python3-contextlib2 is not set # CONFIG_PACKAGE_python3-cryptodome is not set # CONFIG_PACKAGE_python3-cryptodomex is not set # CONFIG_PACKAGE_python3-cryptography is not set # CONFIG_PACKAGE_python3-ctypes is not set # CONFIG_PACKAGE_python3-curl is not set # CONFIG_PACKAGE_python3-dateutil is not set # CONFIG_PACKAGE_python3-dbm is not set # CONFIG_PACKAGE_python3-decimal is not set # CONFIG_PACKAGE_python3-decorator is not set # CONFIG_PACKAGE_python3-defusedxml is not set # CONFIG_PACKAGE_python3-dev is not set # CONFIG_PACKAGE_python3-distro is not set # CONFIG_PACKAGE_python3-distutils is not set # CONFIG_PACKAGE_python3-django is not set # CONFIG_PACKAGE_python3-django-appconf is not set # CONFIG_PACKAGE_python3-django-compressor is not set # CONFIG_PACKAGE_python3-django-cors-headers is not set # CONFIG_PACKAGE_python3-django-etesync-journal is not set # CONFIG_PACKAGE_python3-django-formtools is not set # CONFIG_PACKAGE_python3-django-jsonfield is not set # CONFIG_PACKAGE_python3-django-jsonfield2 is not set # CONFIG_PACKAGE_python3-django-picklefield is not set # CONFIG_PACKAGE_python3-django-postoffice is not set # CONFIG_PACKAGE_python3-django-ranged-response is not set # CONFIG_PACKAGE_python3-django-restframework is not set # CONFIG_PACKAGE_python3-django-restframework39 is not set # CONFIG_PACKAGE_python3-django-simple-captcha is not set # CONFIG_PACKAGE_python3-django-statici18n is not set # CONFIG_PACKAGE_python3-django-webpack-loader is not set # CONFIG_PACKAGE_python3-django1 is not set # CONFIG_PACKAGE_python3-dns is not set # CONFIG_PACKAGE_python3-docker is not set # CONFIG_PACKAGE_python3-dockerpty is not set # CONFIG_PACKAGE_python3-docopt is not set # CONFIG_PACKAGE_python3-docutils is not set # CONFIG_PACKAGE_python3-dotenv is not set # CONFIG_PACKAGE_python3-drf-nested-routers is not set # CONFIG_PACKAGE_python3-email is not set # CONFIG_PACKAGE_python3-et_xmlfile is not set # CONFIG_PACKAGE_python3-evdev is not set # CONFIG_PACKAGE_python3-flask is not set # CONFIG_PACKAGE_python3-flask-login is not set # CONFIG_PACKAGE_python3-gdbm is not set # CONFIG_PACKAGE_python3-gmpy2 is not set # CONFIG_PACKAGE_python3-gnupg is not set # CONFIG_PACKAGE_python3-gpiod is not set # CONFIG_PACKAGE_python3-gunicorn is not set # CONFIG_PACKAGE_python3-hyperlink is not set # CONFIG_PACKAGE_python3-idna is not set # CONFIG_PACKAGE_python3-ifaddr is not set # CONFIG_PACKAGE_python3-incremental is not set # CONFIG_PACKAGE_python3-influxdb is not set # CONFIG_PACKAGE_python3-intelhex is not set # CONFIG_PACKAGE_python3-itsdangerous is not set # CONFIG_PACKAGE_python3-jdcal is not set # CONFIG_PACKAGE_python3-jinja2 is not set # CONFIG_PACKAGE_python3-jmespath is not set # CONFIG_PACKAGE_python3-jsonpath-ng is not set # CONFIG_PACKAGE_python3-jsonschema is not set # CONFIG_PACKAGE_python3-lib2to3 is not set # CONFIG_PACKAGE_python3-libmodbus is not set # CONFIG_PACKAGE_python3-light is not set # # Configuration # # CONFIG_PYTHON3_BLUETOOTH_SUPPORT is not set # end of Configuration # CONFIG_PACKAGE_python3-logging is not set # CONFIG_PACKAGE_python3-lxml is not set # CONFIG_PACKAGE_python3-lzma is not set # CONFIG_PACKAGE_python3-markdown is not set # CONFIG_PACKAGE_python3-markupsafe is not set # CONFIG_PACKAGE_python3-maxminddb is not set # CONFIG_PACKAGE_python3-more-itertools is not set # CONFIG_PACKAGE_python3-multidict is not set # CONFIG_PACKAGE_python3-multiprocessing is not set # CONFIG_PACKAGE_python3-mysqlclient is not set # CONFIG_PACKAGE_python3-ncurses is not set # CONFIG_PACKAGE_python3-netdisco is not set # CONFIG_PACKAGE_python3-netifaces is not set # CONFIG_PACKAGE_python3-newt is not set # CONFIG_PACKAGE_python3-oauthlib is not set # CONFIG_PACKAGE_python3-openpyxl is not set # CONFIG_PACKAGE_python3-openssl is not set # CONFIG_PACKAGE_python3-packaging is not set # CONFIG_PACKAGE_python3-paho-mqtt is not set # CONFIG_PACKAGE_python3-paramiko is not set # CONFIG_PACKAGE_python3-parsley is not set # CONFIG_PACKAGE_python3-passlib is not set # CONFIG_PACKAGE_python3-pillow is not set # CONFIG_PACKAGE_python3-pip is not set # CONFIG_PACKAGE_python3-pkg-resources is not set # CONFIG_PACKAGE_python3-pluggy is not set # CONFIG_PACKAGE_python3-ply is not set # CONFIG_PACKAGE_python3-py is not set # CONFIG_PACKAGE_python3-pyasn1 is not set # CONFIG_PACKAGE_python3-pyasn1-modules is not set # CONFIG_PACKAGE_python3-pycparser is not set # CONFIG_PACKAGE_python3-pydoc is not set # CONFIG_PACKAGE_python3-pyjwt is not set # CONFIG_PACKAGE_python3-pymysql is not set # CONFIG_PACKAGE_python3-pynacl is not set # CONFIG_PACKAGE_python3-pyodbc is not set # CONFIG_PACKAGE_python3-pyopenssl is not set # CONFIG_PACKAGE_python3-pyotp is not set # CONFIG_PACKAGE_python3-pyparsing is not set # CONFIG_PACKAGE_python3-pyroute2 is not set # CONFIG_PACKAGE_python3-pyrsistent is not set # CONFIG_PACKAGE_python3-pyserial is not set # CONFIG_PACKAGE_python3-pytest is not set # CONFIG_PACKAGE_python3-pytz is not set # CONFIG_PACKAGE_python3-qrcode is not set # CONFIG_PACKAGE_python3-rcssmin is not set # CONFIG_PACKAGE_python3-requests is not set # CONFIG_PACKAGE_python3-requests-oauthlib is not set # CONFIG_PACKAGE_python3-rsa is not set # CONFIG_PACKAGE_python3-ruamel-yaml is not set # CONFIG_PACKAGE_python3-s3transfer is not set # CONFIG_PACKAGE_python3-schedule is not set # CONFIG_PACKAGE_python3-schema is not set # CONFIG_PACKAGE_python3-seafile-ccnet is not set # CONFIG_PACKAGE_python3-seafile-server is not set # CONFIG_PACKAGE_python3-searpc is not set # CONFIG_PACKAGE_python3-sentry-sdk is not set # CONFIG_PACKAGE_python3-service-identity is not set # CONFIG_PACKAGE_python3-setuptools is not set # CONFIG_PACKAGE_python3-simplejson is not set # CONFIG_PACKAGE_python3-six is not set # CONFIG_PACKAGE_python3-slugify is not set # CONFIG_PACKAGE_python3-smbus is not set # CONFIG_PACKAGE_python3-speedtest-cli is not set # CONFIG_PACKAGE_python3-sqlalchemy is not set # CONFIG_PACKAGE_python3-sqlite3 is not set # CONFIG_PACKAGE_python3-sqlparse is not set # CONFIG_PACKAGE_python3-stem is not set # CONFIG_PACKAGE_python3-sysrepo is not set # CONFIG_PACKAGE_python3-text-unidecode is not set # CONFIG_PACKAGE_python3-texttable is not set # CONFIG_PACKAGE_python3-twisted is not set # CONFIG_PACKAGE_python3-unidecode is not set # CONFIG_PACKAGE_python3-unittest is not set # CONFIG_PACKAGE_python3-urllib is not set # CONFIG_PACKAGE_python3-urllib3 is not set # CONFIG_PACKAGE_python3-vobject is not set # CONFIG_PACKAGE_python3-voluptuous is not set # CONFIG_PACKAGE_python3-voluptuous-serialize is not set # CONFIG_PACKAGE_python3-wcwidth is not set # CONFIG_PACKAGE_python3-websocket-client is not set # CONFIG_PACKAGE_python3-werkzeug is not set # CONFIG_PACKAGE_python3-xml is not set # CONFIG_PACKAGE_python3-xmltodict is not set # CONFIG_PACKAGE_python3-yaml is not set # CONFIG_PACKAGE_python3-yarl is not set # CONFIG_PACKAGE_python3-zeroconf is not set # CONFIG_PACKAGE_python3-zipp is not set # CONFIG_PACKAGE_python3-zope-interface is not set # end of Python # # Ruby # CONFIG_PACKAGE_ruby=y # # Standard Library # # CONFIG_PACKAGE_ruby-stdlib is not set # CONFIG_PACKAGE_ruby-benchmark is not set CONFIG_PACKAGE_ruby-bigdecimal=y # CONFIG_PACKAGE_ruby-bundler is not set # CONFIG_PACKAGE_ruby-cgi is not set # CONFIG_PACKAGE_ruby-csv is not set CONFIG_PACKAGE_ruby-date=y CONFIG_PACKAGE_ruby-dbm=y # CONFIG_PACKAGE_ruby-debuglib is not set # CONFIG_PACKAGE_ruby-delegate is not set # CONFIG_PACKAGE_ruby-dev is not set # CONFIG_PACKAGE_ruby-did-you-mean is not set CONFIG_PACKAGE_ruby-digest=y # CONFIG_RUBY_DIGEST_USE_OPENSSL is not set # CONFIG_PACKAGE_ruby-drb is not set CONFIG_PACKAGE_ruby-enc=y # CONFIG_PACKAGE_ruby-enc-extra is not set # CONFIG_PACKAGE_ruby-erb is not set # CONFIG_PACKAGE_ruby-etc is not set # CONFIG_PACKAGE_ruby-fcntl is not set # CONFIG_PACKAGE_ruby-fiddle is not set # CONFIG_PACKAGE_ruby-filelib is not set # CONFIG_PACKAGE_ruby-fileutils is not set # CONFIG_PACKAGE_ruby-forwardable is not set # CONFIG_PACKAGE_ruby-gdbm is not set # CONFIG_PACKAGE_ruby-gems is not set # CONFIG_PACKAGE_ruby-getoptlong is not set # CONFIG_PACKAGE_ruby-io-console is not set # CONFIG_PACKAGE_ruby-ipaddr is not set # CONFIG_PACKAGE_ruby-irb is not set # CONFIG_PACKAGE_ruby-json is not set # CONFIG_PACKAGE_ruby-logger is not set # CONFIG_PACKAGE_ruby-matrix is not set # CONFIG_PACKAGE_ruby-minitest is not set # CONFIG_PACKAGE_ruby-misc is not set # CONFIG_PACKAGE_ruby-mkmf is not set # CONFIG_PACKAGE_ruby-multithread is not set # CONFIG_PACKAGE_ruby-mutex_m is not set # CONFIG_PACKAGE_ruby-net is not set # CONFIG_PACKAGE_ruby-net-pop is not set # CONFIG_PACKAGE_ruby-net-smtp is not set # CONFIG_PACKAGE_ruby-net-telnet is not set # CONFIG_PACKAGE_ruby-nkf is not set # CONFIG_PACKAGE_ruby-observer is not set # CONFIG_PACKAGE_ruby-open3 is not set # CONFIG_PACKAGE_ruby-openssl is not set # CONFIG_PACKAGE_ruby-optparse is not set # CONFIG_PACKAGE_ruby-ostruct is not set # CONFIG_PACKAGE_ruby-powerassert is not set # CONFIG_PACKAGE_ruby-prettyprint is not set # CONFIG_PACKAGE_ruby-prime is not set CONFIG_PACKAGE_ruby-pstore=y CONFIG_PACKAGE_ruby-psych=y # CONFIG_PACKAGE_ruby-racc is not set # CONFIG_PACKAGE_ruby-rake is not set # CONFIG_PACKAGE_ruby-rbconfig is not set # CONFIG_PACKAGE_ruby-rdoc is not set # CONFIG_PACKAGE_ruby-readline is not set # CONFIG_PACKAGE_ruby-readline-ext is not set # CONFIG_PACKAGE_ruby-reline is not set # CONFIG_PACKAGE_ruby-rexml is not set # CONFIG_PACKAGE_ruby-rinda is not set # CONFIG_PACKAGE_ruby-ripper is not set # CONFIG_PACKAGE_ruby-rss is not set # CONFIG_PACKAGE_ruby-sdbm is not set # CONFIG_PACKAGE_ruby-singleton is not set # CONFIG_PACKAGE_ruby-socket is not set CONFIG_PACKAGE_ruby-stringio=y CONFIG_PACKAGE_ruby-strscan=y # CONFIG_PACKAGE_ruby-testunit is not set # CONFIG_PACKAGE_ruby-time is not set # CONFIG_PACKAGE_ruby-timeout is not set # CONFIG_PACKAGE_ruby-tracer is not set # CONFIG_PACKAGE_ruby-unicodenormalize is not set # CONFIG_PACKAGE_ruby-uri is not set # CONFIG_PACKAGE_ruby-webrick is not set # CONFIG_PACKAGE_ruby-xmlrpc is not set CONFIG_PACKAGE_ruby-yaml=y # CONFIG_PACKAGE_ruby-zlib is not set # end of Ruby # # Tcl # # CONFIG_PACKAGE_tcl is not set # end of Tcl # CONFIG_PACKAGE_chicken-scheme-full is not set # CONFIG_PACKAGE_chicken-scheme-interpreter is not set # CONFIG_PACKAGE_slsh is not set # end of Languages # # Libraries # # # Compression # # CONFIG_PACKAGE_libbz2 is not set # CONFIG_PACKAGE_liblz4 is not set # CONFIG_PACKAGE_liblzma is not set # CONFIG_PACKAGE_libunrar is not set # CONFIG_PACKAGE_libzip-gnutls is not set # CONFIG_PACKAGE_libzip-mbedtls is not set # CONFIG_PACKAGE_libzip-nossl is not set # CONFIG_PACKAGE_libzip-openssl is not set # CONFIG_PACKAGE_libzstd is not set # end of Compression # # Database # # CONFIG_PACKAGE_libmariadb is not set # CONFIG_PACKAGE_libpq is not set # CONFIG_PACKAGE_libsqlite3 is not set # CONFIG_PACKAGE_pgsqlodbc is not set # CONFIG_PACKAGE_psqlodbca is not set # CONFIG_PACKAGE_psqlodbcw is not set # CONFIG_PACKAGE_redis-cli is not set # CONFIG_PACKAGE_redis-full is not set # CONFIG_PACKAGE_redis-server is not set # CONFIG_PACKAGE_redis-utils is not set # CONFIG_PACKAGE_tdb is not set # CONFIG_PACKAGE_unixodbc is not set # end of Database # # Filesystem # # CONFIG_PACKAGE_libacl is not set # CONFIG_PACKAGE_libattr is not set # CONFIG_PACKAGE_libfuse is not set # CONFIG_PACKAGE_libfuse3 is not set # CONFIG_PACKAGE_libow is not set # CONFIG_PACKAGE_libow-capi is not set # CONFIG_PACKAGE_libsysfs is not set # end of Filesystem # # Firewall # # CONFIG_PACKAGE_libfko is not set CONFIG_PACKAGE_libip4tc=y CONFIG_PACKAGE_libip6tc=y CONFIG_PACKAGE_libxtables=y # CONFIG_PACKAGE_libxtables-nft is not set # end of Firewall # # Instant Messaging # # CONFIG_PACKAGE_quasselc is not set # end of Instant Messaging # # IoT # # CONFIG_PACKAGE_libmraa is not set # CONFIG_PACKAGE_libmraa-node is not set # CONFIG_PACKAGE_libupm-a110x is not set # CONFIG_PACKAGE_libupm-a110x-node is not set # CONFIG_PACKAGE_libupm-abp is not set # CONFIG_PACKAGE_libupm-abp-node is not set # CONFIG_PACKAGE_libupm-ad8232 is not set # CONFIG_PACKAGE_libupm-ad8232-node is not set # CONFIG_PACKAGE_libupm-adafruitms1438 is not set # CONFIG_PACKAGE_libupm-adafruitms1438-node is not set # CONFIG_PACKAGE_libupm-adafruitss is not set # CONFIG_PACKAGE_libupm-adafruitss-node is not set # CONFIG_PACKAGE_libupm-adc121c021 is not set # CONFIG_PACKAGE_libupm-adc121c021-node is not set # CONFIG_PACKAGE_libupm-adis16448 is not set # CONFIG_PACKAGE_libupm-adis16448-node is not set # CONFIG_PACKAGE_libupm-ads1x15 is not set # CONFIG_PACKAGE_libupm-ads1x15-node is not set # CONFIG_PACKAGE_libupm-adxl335 is not set # CONFIG_PACKAGE_libupm-adxl335-node is not set # CONFIG_PACKAGE_libupm-adxl345 is not set # CONFIG_PACKAGE_libupm-adxl345-node is not set # CONFIG_PACKAGE_libupm-adxrs610 is not set # CONFIG_PACKAGE_libupm-adxrs610-node is not set # CONFIG_PACKAGE_libupm-am2315 is not set # CONFIG_PACKAGE_libupm-am2315-node is not set # CONFIG_PACKAGE_libupm-apa102 is not set # CONFIG_PACKAGE_libupm-apa102-node is not set # CONFIG_PACKAGE_libupm-apds9002 is not set # CONFIG_PACKAGE_libupm-apds9002-node is not set # CONFIG_PACKAGE_libupm-apds9930 is not set # CONFIG_PACKAGE_libupm-apds9930-node is not set # CONFIG_PACKAGE_libupm-at42qt1070 is not set # CONFIG_PACKAGE_libupm-at42qt1070-node is not set # CONFIG_PACKAGE_libupm-bh1749 is not set # CONFIG_PACKAGE_libupm-bh1749-node is not set # CONFIG_PACKAGE_libupm-bh1750 is not set # CONFIG_PACKAGE_libupm-bh1750-node is not set # CONFIG_PACKAGE_libupm-bh1792 is not set # CONFIG_PACKAGE_libupm-bh1792-node is not set # CONFIG_PACKAGE_libupm-biss0001 is not set # CONFIG_PACKAGE_libupm-biss0001-node is not set # CONFIG_PACKAGE_libupm-bma220 is not set # CONFIG_PACKAGE_libupm-bma220-node is not set # CONFIG_PACKAGE_libupm-bma250e is not set # CONFIG_PACKAGE_libupm-bma250e-node is not set # CONFIG_PACKAGE_libupm-bmg160 is not set # CONFIG_PACKAGE_libupm-bmg160-node is not set # CONFIG_PACKAGE_libupm-bmi160 is not set # CONFIG_PACKAGE_libupm-bmi160-node is not set # CONFIG_PACKAGE_libupm-bmm150 is not set # CONFIG_PACKAGE_libupm-bmm150-node is not set # CONFIG_PACKAGE_libupm-bmp280 is not set # CONFIG_PACKAGE_libupm-bmp280-node is not set # CONFIG_PACKAGE_libupm-bmpx8x is not set # CONFIG_PACKAGE_libupm-bmpx8x-node is not set # CONFIG_PACKAGE_libupm-bmx055 is not set # CONFIG_PACKAGE_libupm-bmx055-node is not set # CONFIG_PACKAGE_libupm-bno055 is not set # CONFIG_PACKAGE_libupm-bno055-node is not set # CONFIG_PACKAGE_libupm-button is not set # CONFIG_PACKAGE_libupm-button-node is not set # CONFIG_PACKAGE_libupm-buzzer is not set # CONFIG_PACKAGE_libupm-buzzer-node is not set # CONFIG_PACKAGE_libupm-cjq4435 is not set # CONFIG_PACKAGE_libupm-cjq4435-node is not set # CONFIG_PACKAGE_libupm-collision is not set # CONFIG_PACKAGE_libupm-collision-node is not set # CONFIG_PACKAGE_libupm-curieimu is not set # CONFIG_PACKAGE_libupm-curieimu-node is not set # CONFIG_PACKAGE_libupm-cwlsxxa is not set # CONFIG_PACKAGE_libupm-cwlsxxa-node is not set # CONFIG_PACKAGE_libupm-dfrec is not set # CONFIG_PACKAGE_libupm-dfrec-node is not set # CONFIG_PACKAGE_libupm-dfrorp is not set # CONFIG_PACKAGE_libupm-dfrorp-node is not set # CONFIG_PACKAGE_libupm-dfrph is not set # CONFIG_PACKAGE_libupm-dfrph-node is not set # CONFIG_PACKAGE_libupm-ds1307 is not set # CONFIG_PACKAGE_libupm-ds1307-node is not set # CONFIG_PACKAGE_libupm-ds1808lc is not set # CONFIG_PACKAGE_libupm-ds1808lc-node is not set # CONFIG_PACKAGE_libupm-ds18b20 is not set # CONFIG_PACKAGE_libupm-ds18b20-node is not set # CONFIG_PACKAGE_libupm-ds2413 is not set # CONFIG_PACKAGE_libupm-ds2413-node is not set # CONFIG_PACKAGE_libupm-ecezo is not set # CONFIG_PACKAGE_libupm-ecezo-node is not set # CONFIG_PACKAGE_libupm-ecs1030 is not set # CONFIG_PACKAGE_libupm-ecs1030-node is not set # CONFIG_PACKAGE_libupm-ehr is not set # CONFIG_PACKAGE_libupm-ehr-node is not set # CONFIG_PACKAGE_libupm-eldriver is not set # CONFIG_PACKAGE_libupm-eldriver-node is not set # CONFIG_PACKAGE_libupm-electromagnet is not set # CONFIG_PACKAGE_libupm-electromagnet-node is not set # CONFIG_PACKAGE_libupm-emg is not set # CONFIG_PACKAGE_libupm-emg-node is not set # CONFIG_PACKAGE_libupm-enc03r is not set # CONFIG_PACKAGE_libupm-enc03r-node is not set # CONFIG_PACKAGE_libupm-flex is not set # CONFIG_PACKAGE_libupm-flex-node is not set # CONFIG_PACKAGE_libupm-gas is not set # CONFIG_PACKAGE_libupm-gas-node is not set # CONFIG_PACKAGE_libupm-gp2y0a is not set # CONFIG_PACKAGE_libupm-gp2y0a-node is not set # CONFIG_PACKAGE_libupm-gprs is not set # CONFIG_PACKAGE_libupm-gprs-node is not set # CONFIG_PACKAGE_libupm-gsr is not set # CONFIG_PACKAGE_libupm-gsr-node is not set # CONFIG_PACKAGE_libupm-guvas12d is not set # CONFIG_PACKAGE_libupm-guvas12d-node is not set # CONFIG_PACKAGE_libupm-h3lis331dl is not set # CONFIG_PACKAGE_libupm-h3lis331dl-node is not set # CONFIG_PACKAGE_libupm-h803x is not set # CONFIG_PACKAGE_libupm-h803x-node is not set # CONFIG_PACKAGE_libupm-hcsr04 is not set # CONFIG_PACKAGE_libupm-hcsr04-node is not set # CONFIG_PACKAGE_libupm-hdc1000 is not set # CONFIG_PACKAGE_libupm-hdc1000-node is not set # CONFIG_PACKAGE_libupm-hdxxvxta is not set # CONFIG_PACKAGE_libupm-hdxxvxta-node is not set # CONFIG_PACKAGE_libupm-hka5 is not set # CONFIG_PACKAGE_libupm-hka5-node is not set # CONFIG_PACKAGE_libupm-hlg150h is not set # CONFIG_PACKAGE_libupm-hlg150h-node is not set # CONFIG_PACKAGE_libupm-hm11 is not set # CONFIG_PACKAGE_libupm-hm11-node is not set # CONFIG_PACKAGE_libupm-hmc5883l is not set # CONFIG_PACKAGE_libupm-hmc5883l-node is not set # CONFIG_PACKAGE_libupm-hmtrp is not set # CONFIG_PACKAGE_libupm-hmtrp-node is not set # CONFIG_PACKAGE_libupm-hp20x is not set # CONFIG_PACKAGE_libupm-hp20x-node is not set # CONFIG_PACKAGE_libupm-ht9170 is not set # CONFIG_PACKAGE_libupm-ht9170-node is not set # CONFIG_PACKAGE_libupm-htu21d is not set # CONFIG_PACKAGE_libupm-htu21d-node is not set # CONFIG_PACKAGE_libupm-hwxpxx is not set # CONFIG_PACKAGE_libupm-hwxpxx-node is not set # CONFIG_PACKAGE_libupm-hx711 is not set # CONFIG_PACKAGE_libupm-hx711-node is not set # CONFIG_PACKAGE_libupm-ili9341 is not set # CONFIG_PACKAGE_libupm-ili9341-node is not set # CONFIG_PACKAGE_libupm-ims is not set # CONFIG_PACKAGE_libupm-ims-node is not set # CONFIG_PACKAGE_libupm-ina132 is not set # CONFIG_PACKAGE_libupm-ina132-node is not set # CONFIG_PACKAGE_libupm-interfaces is not set # CONFIG_PACKAGE_libupm-interfaces-node is not set # CONFIG_PACKAGE_libupm-isd1820 is not set # CONFIG_PACKAGE_libupm-isd1820-node is not set # CONFIG_PACKAGE_libupm-itg3200 is not set # CONFIG_PACKAGE_libupm-itg3200-node is not set # CONFIG_PACKAGE_libupm-jhd1313m1 is not set # CONFIG_PACKAGE_libupm-jhd1313m1-node is not set # CONFIG_PACKAGE_libupm-joystick12 is not set # CONFIG_PACKAGE_libupm-joystick12-node is not set # CONFIG_PACKAGE_libupm-kx122 is not set # CONFIG_PACKAGE_libupm-kx122-node is not set # CONFIG_PACKAGE_libupm-kxcjk1013 is not set # CONFIG_PACKAGE_libupm-kxcjk1013-node is not set # CONFIG_PACKAGE_libupm-kxtj3 is not set # CONFIG_PACKAGE_libupm-kxtj3-node is not set # CONFIG_PACKAGE_libupm-l298 is not set # CONFIG_PACKAGE_libupm-l298-node is not set # CONFIG_PACKAGE_libupm-l3gd20 is not set # CONFIG_PACKAGE_libupm-l3gd20-node is not set # CONFIG_PACKAGE_libupm-lcd is not set # CONFIG_PACKAGE_libupm-lcd-node is not set # CONFIG_PACKAGE_libupm-lcdks is not set # CONFIG_PACKAGE_libupm-lcdks-node is not set # CONFIG_PACKAGE_libupm-lcm1602 is not set # CONFIG_PACKAGE_libupm-lcm1602-node is not set # CONFIG_PACKAGE_libupm-ldt0028 is not set # CONFIG_PACKAGE_libupm-ldt0028-node is not set # CONFIG_PACKAGE_libupm-led is not set # CONFIG_PACKAGE_libupm-led-node is not set # CONFIG_PACKAGE_libupm-lidarlitev3 is not set # CONFIG_PACKAGE_libupm-lidarlitev3-node is not set # CONFIG_PACKAGE_libupm-light is not set # CONFIG_PACKAGE_libupm-light-node is not set # CONFIG_PACKAGE_libupm-linefinder is not set # CONFIG_PACKAGE_libupm-linefinder-node is not set # CONFIG_PACKAGE_libupm-lis2ds12 is not set # CONFIG_PACKAGE_libupm-lis2ds12-node is not set # CONFIG_PACKAGE_libupm-lis3dh is not set # CONFIG_PACKAGE_libupm-lis3dh-node is not set # CONFIG_PACKAGE_libupm-lm35 is not set # CONFIG_PACKAGE_libupm-lm35-node is not set # CONFIG_PACKAGE_libupm-lol is not set # CONFIG_PACKAGE_libupm-lol-node is not set # CONFIG_PACKAGE_libupm-loudness is not set # CONFIG_PACKAGE_libupm-loudness-node is not set # CONFIG_PACKAGE_libupm-lp8860 is not set # CONFIG_PACKAGE_libupm-lp8860-node is not set # CONFIG_PACKAGE_libupm-lpd8806 is not set # CONFIG_PACKAGE_libupm-lpd8806-node is not set # CONFIG_PACKAGE_libupm-lsm303agr is not set # CONFIG_PACKAGE_libupm-lsm303agr-node is not set # CONFIG_PACKAGE_libupm-lsm303d is not set # CONFIG_PACKAGE_libupm-lsm303d-node is not set # CONFIG_PACKAGE_libupm-lsm303dlh is not set # CONFIG_PACKAGE_libupm-lsm303dlh-node is not set # CONFIG_PACKAGE_libupm-lsm6ds3h is not set # CONFIG_PACKAGE_libupm-lsm6ds3h-node is not set # CONFIG_PACKAGE_libupm-lsm6dsl is not set # CONFIG_PACKAGE_libupm-lsm6dsl-node is not set # CONFIG_PACKAGE_libupm-lsm9ds0 is not set # CONFIG_PACKAGE_libupm-lsm9ds0-node is not set # CONFIG_PACKAGE_libupm-m24lr64e is not set # CONFIG_PACKAGE_libupm-m24lr64e-node is not set # CONFIG_PACKAGE_libupm-mag3110 is not set # CONFIG_PACKAGE_libupm-mag3110-node is not set # CONFIG_PACKAGE_libupm-max30100 is not set # CONFIG_PACKAGE_libupm-max30100-node is not set # CONFIG_PACKAGE_libupm-max31723 is not set # CONFIG_PACKAGE_libupm-max31723-node is not set # CONFIG_PACKAGE_libupm-max31855 is not set # CONFIG_PACKAGE_libupm-max31855-node is not set # CONFIG_PACKAGE_libupm-max44000 is not set # CONFIG_PACKAGE_libupm-max44000-node is not set # CONFIG_PACKAGE_libupm-max44009 is not set # CONFIG_PACKAGE_libupm-max44009-node is not set # CONFIG_PACKAGE_libupm-max5487 is not set # CONFIG_PACKAGE_libupm-max5487-node is not set # CONFIG_PACKAGE_libupm-maxds3231m is not set # CONFIG_PACKAGE_libupm-maxds3231m-node is not set # CONFIG_PACKAGE_libupm-maxsonarez is not set # CONFIG_PACKAGE_libupm-maxsonarez-node is not set # CONFIG_PACKAGE_libupm-mb704x is not set # CONFIG_PACKAGE_libupm-mb704x-node is not set # CONFIG_PACKAGE_libupm-mcp2515 is not set # CONFIG_PACKAGE_libupm-mcp2515-node is not set # CONFIG_PACKAGE_libupm-mcp9808 is not set # CONFIG_PACKAGE_libupm-mcp9808-node is not set # CONFIG_PACKAGE_libupm-md is not set # CONFIG_PACKAGE_libupm-md-node is not set # CONFIG_PACKAGE_libupm-mg811 is not set # CONFIG_PACKAGE_libupm-mg811-node is not set # CONFIG_PACKAGE_libupm-mhz16 is not set # CONFIG_PACKAGE_libupm-mhz16-node is not set # CONFIG_PACKAGE_libupm-mic is not set # CONFIG_PACKAGE_libupm-mic-node is not set # CONFIG_PACKAGE_libupm-micsv89 is not set # CONFIG_PACKAGE_libupm-micsv89-node is not set # CONFIG_PACKAGE_libupm-mlx90614 is not set # CONFIG_PACKAGE_libupm-mlx90614-node is not set # CONFIG_PACKAGE_libupm-mma7361 is not set # CONFIG_PACKAGE_libupm-mma7361-node is not set # CONFIG_PACKAGE_libupm-mma7455 is not set # CONFIG_PACKAGE_libupm-mma7455-node is not set # CONFIG_PACKAGE_libupm-mma7660 is not set # CONFIG_PACKAGE_libupm-mma7660-node is not set # CONFIG_PACKAGE_libupm-mma8x5x is not set # CONFIG_PACKAGE_libupm-mma8x5x-node is not set # CONFIG_PACKAGE_libupm-mmc35240 is not set # CONFIG_PACKAGE_libupm-mmc35240-node is not set # CONFIG_PACKAGE_libupm-moisture is not set # CONFIG_PACKAGE_libupm-moisture-node is not set # CONFIG_PACKAGE_libupm-mpl3115a2 is not set # CONFIG_PACKAGE_libupm-mpl3115a2-node is not set # CONFIG_PACKAGE_libupm-mpr121 is not set # CONFIG_PACKAGE_libupm-mpr121-node is not set # CONFIG_PACKAGE_libupm-mpu9150 is not set # CONFIG_PACKAGE_libupm-mpu9150-node is not set # CONFIG_PACKAGE_libupm-mq303a is not set # CONFIG_PACKAGE_libupm-mq303a-node is not set # CONFIG_PACKAGE_libupm-ms5611 is not set # CONFIG_PACKAGE_libupm-ms5611-node is not set # CONFIG_PACKAGE_libupm-ms5803 is not set # CONFIG_PACKAGE_libupm-ms5803-node is not set # CONFIG_PACKAGE_libupm-my9221 is not set # CONFIG_PACKAGE_libupm-my9221-node is not set # CONFIG_PACKAGE_libupm-nlgpio16 is not set # CONFIG_PACKAGE_libupm-nlgpio16-node is not set # CONFIG_PACKAGE_libupm-nmea_gps is not set # CONFIG_PACKAGE_libupm-nmea_gps-node is not set # CONFIG_PACKAGE_libupm-nrf24l01 is not set # CONFIG_PACKAGE_libupm-nrf24l01-node is not set # CONFIG_PACKAGE_libupm-nrf8001 is not set # CONFIG_PACKAGE_libupm-nrf8001-node is not set # CONFIG_PACKAGE_libupm-nunchuck is not set # CONFIG_PACKAGE_libupm-nunchuck-node is not set # CONFIG_PACKAGE_libupm-o2 is not set # CONFIG_PACKAGE_libupm-o2-node is not set # CONFIG_PACKAGE_libupm-otp538u is not set # CONFIG_PACKAGE_libupm-otp538u-node is not set # CONFIG_PACKAGE_libupm-ozw is not set # CONFIG_PACKAGE_libupm-ozw-node is not set # CONFIG_PACKAGE_libupm-p9813 is not set # CONFIG_PACKAGE_libupm-p9813-node is not set # CONFIG_PACKAGE_libupm-pca9685 is not set # CONFIG_PACKAGE_libupm-pca9685-node is not set # CONFIG_PACKAGE_libupm-pn532 is not set # CONFIG_PACKAGE_libupm-pn532-node is not set # CONFIG_PACKAGE_libupm-ppd42ns is not set # CONFIG_PACKAGE_libupm-ppd42ns-node is not set # CONFIG_PACKAGE_libupm-pulsensor is not set # CONFIG_PACKAGE_libupm-pulsensor-node is not set # CONFIG_PACKAGE_libupm-relay is not set # CONFIG_PACKAGE_libupm-relay-node is not set # CONFIG_PACKAGE_libupm-rf22 is not set # CONFIG_PACKAGE_libupm-rf22-node is not set # CONFIG_PACKAGE_libupm-rfr359f is not set # CONFIG_PACKAGE_libupm-rfr359f-node is not set # CONFIG_PACKAGE_libupm-rgbringcoder is not set # CONFIG_PACKAGE_libupm-rgbringcoder-node is not set # CONFIG_PACKAGE_libupm-rhusb is not set # CONFIG_PACKAGE_libupm-rhusb-node is not set # CONFIG_PACKAGE_libupm-rn2903 is not set # CONFIG_PACKAGE_libupm-rn2903-node is not set # CONFIG_PACKAGE_libupm-rotary is not set # CONFIG_PACKAGE_libupm-rotary-node is not set # CONFIG_PACKAGE_libupm-rotaryencoder is not set # CONFIG_PACKAGE_libupm-rotaryencoder-node is not set # CONFIG_PACKAGE_libupm-rpr220 is not set # CONFIG_PACKAGE_libupm-rpr220-node is not set # CONFIG_PACKAGE_libupm-rsc is not set # CONFIG_PACKAGE_libupm-rsc-node is not set # CONFIG_PACKAGE_libupm-scam is not set # CONFIG_PACKAGE_libupm-scam-node is not set # CONFIG_PACKAGE_libupm-sensortemplate is not set # CONFIG_PACKAGE_libupm-sensortemplate-node is not set # CONFIG_PACKAGE_libupm-servo is not set # CONFIG_PACKAGE_libupm-servo-node is not set # CONFIG_PACKAGE_libupm-sht1x is not set # CONFIG_PACKAGE_libupm-sht1x-node is not set # CONFIG_PACKAGE_libupm-si1132 is not set # CONFIG_PACKAGE_libupm-si1132-node is not set # CONFIG_PACKAGE_libupm-si114x is not set # CONFIG_PACKAGE_libupm-si114x-node is not set # CONFIG_PACKAGE_libupm-si7005 is not set # CONFIG_PACKAGE_libupm-si7005-node is not set # CONFIG_PACKAGE_libupm-slide is not set # CONFIG_PACKAGE_libupm-slide-node is not set # CONFIG_PACKAGE_libupm-sm130 is not set # CONFIG_PACKAGE_libupm-sm130-node is not set # CONFIG_PACKAGE_libupm-smartdrive is not set # CONFIG_PACKAGE_libupm-smartdrive-node is not set # CONFIG_PACKAGE_libupm-speaker is not set # CONFIG_PACKAGE_libupm-speaker-node is not set # CONFIG_PACKAGE_libupm-ssd1351 is not set # CONFIG_PACKAGE_libupm-ssd1351-node is not set # CONFIG_PACKAGE_libupm-st7735 is not set # CONFIG_PACKAGE_libupm-st7735-node is not set # CONFIG_PACKAGE_libupm-stepmotor is not set # CONFIG_PACKAGE_libupm-stepmotor-node is not set # CONFIG_PACKAGE_libupm-sx1276 is not set # CONFIG_PACKAGE_libupm-sx1276-node is not set # CONFIG_PACKAGE_libupm-sx6119 is not set # CONFIG_PACKAGE_libupm-sx6119-node is not set # CONFIG_PACKAGE_libupm-t3311 is not set # CONFIG_PACKAGE_libupm-t3311-node is not set # CONFIG_PACKAGE_libupm-t6713 is not set # CONFIG_PACKAGE_libupm-t6713-node is not set # CONFIG_PACKAGE_libupm-ta12200 is not set # CONFIG_PACKAGE_libupm-ta12200-node is not set # CONFIG_PACKAGE_libupm-tca9548a is not set # CONFIG_PACKAGE_libupm-tca9548a-node is not set # CONFIG_PACKAGE_libupm-tcs3414cs is not set # CONFIG_PACKAGE_libupm-tcs3414cs-node is not set # CONFIG_PACKAGE_libupm-tcs37727 is not set # CONFIG_PACKAGE_libupm-tcs37727-node is not set # CONFIG_PACKAGE_libupm-teams is not set # CONFIG_PACKAGE_libupm-teams-node is not set # CONFIG_PACKAGE_libupm-temperature is not set # CONFIG_PACKAGE_libupm-temperature-node is not set # CONFIG_PACKAGE_libupm-tex00 is not set # CONFIG_PACKAGE_libupm-tex00-node is not set # CONFIG_PACKAGE_libupm-th02 is not set # CONFIG_PACKAGE_libupm-th02-node is not set # CONFIG_PACKAGE_libupm-tm1637 is not set # CONFIG_PACKAGE_libupm-tm1637-node is not set # CONFIG_PACKAGE_libupm-tmp006 is not set # CONFIG_PACKAGE_libupm-tmp006-node is not set # CONFIG_PACKAGE_libupm-tsl2561 is not set # CONFIG_PACKAGE_libupm-tsl2561-node is not set # CONFIG_PACKAGE_libupm-ttp223 is not set # CONFIG_PACKAGE_libupm-ttp223-node is not set # CONFIG_PACKAGE_libupm-uartat is not set # CONFIG_PACKAGE_libupm-uartat-node is not set # CONFIG_PACKAGE_libupm-uln200xa is not set # CONFIG_PACKAGE_libupm-uln200xa-node is not set # CONFIG_PACKAGE_libupm-ultrasonic is not set # CONFIG_PACKAGE_libupm-ultrasonic-node is not set # CONFIG_PACKAGE_libupm-urm37 is not set # CONFIG_PACKAGE_libupm-urm37-node is not set # CONFIG_PACKAGE_libupm-utilities is not set # CONFIG_PACKAGE_libupm-utilities-node is not set # CONFIG_PACKAGE_libupm-vcap is not set # CONFIG_PACKAGE_libupm-vcap-node is not set # CONFIG_PACKAGE_libupm-vdiv is not set # CONFIG_PACKAGE_libupm-vdiv-node is not set # CONFIG_PACKAGE_libupm-veml6070 is not set # CONFIG_PACKAGE_libupm-veml6070-node is not set # CONFIG_PACKAGE_libupm-water is not set # CONFIG_PACKAGE_libupm-water-node is not set # CONFIG_PACKAGE_libupm-waterlevel is not set # CONFIG_PACKAGE_libupm-waterlevel-node is not set # CONFIG_PACKAGE_libupm-wfs is not set # CONFIG_PACKAGE_libupm-wfs-node is not set # CONFIG_PACKAGE_libupm-wheelencoder is not set # CONFIG_PACKAGE_libupm-wheelencoder-node is not set # CONFIG_PACKAGE_libupm-wt5001 is not set # CONFIG_PACKAGE_libupm-wt5001-node is not set # CONFIG_PACKAGE_libupm-xbee is not set # CONFIG_PACKAGE_libupm-xbee-node is not set # CONFIG_PACKAGE_libupm-yg1006 is not set # CONFIG_PACKAGE_libupm-yg1006-node is not set # CONFIG_PACKAGE_libupm-zfm20 is not set # CONFIG_PACKAGE_libupm-zfm20-node is not set # end of IoT # # Languages # CONFIG_PACKAGE_libyaml=y # end of Languages # # LibElektra # # CONFIG_PACKAGE_libelektra-boost is not set # CONFIG_PACKAGE_libelektra-core is not set # CONFIG_PACKAGE_libelektra-cpp is not set # CONFIG_PACKAGE_libelektra-crypto is not set # CONFIG_PACKAGE_libelektra-curlget is not set # CONFIG_PACKAGE_libelektra-dbus is not set # CONFIG_PACKAGE_libelektra-extra is not set # CONFIG_PACKAGE_libelektra-lua is not set # CONFIG_PACKAGE_libelektra-plugins is not set # CONFIG_PACKAGE_libelektra-python3 is not set # CONFIG_PACKAGE_libelektra-resolvers is not set # CONFIG_PACKAGE_libelektra-xerces is not set # CONFIG_PACKAGE_libelektra-xml is not set # CONFIG_PACKAGE_libelektra-yajl is not set # CONFIG_PACKAGE_libelektra-yamlcpp is not set # CONFIG_PACKAGE_libelektra-zmq is not set # end of LibElektra # # Networking # # CONFIG_PACKAGE_libdcwproto is not set # CONFIG_PACKAGE_libdcwsocket is not set # CONFIG_PACKAGE_libsctp is not set # CONFIG_PACKAGE_libuhttpd-mbedtls is not set # CONFIG_PACKAGE_libuhttpd-nossl is not set # CONFIG_PACKAGE_libuhttpd-openssl is not set # CONFIG_PACKAGE_libuhttpd-wolfssl is not set # CONFIG_PACKAGE_libulfius-gnutls is not set # CONFIG_PACKAGE_libulfius-nossl is not set # CONFIG_PACKAGE_libunbound is not set # CONFIG_PACKAGE_libuwsc-mbedtls is not set # CONFIG_PACKAGE_libuwsc-nossl is not set # CONFIG_PACKAGE_libuwsc-openssl is not set # CONFIG_PACKAGE_libuwsc-wolfssl is not set # end of Networking # # Qt5 # # CONFIG_PACKAGE_qt5-core is not set # CONFIG_PACKAGE_qt5-network is not set # CONFIG_PACKAGE_qt5-sql is not set # CONFIG_PACKAGE_qt5-xml is not set # end of Qt5 # # SSL # # CONFIG_PACKAGE_libgnutls is not set CONFIG_PACKAGE_libmbedtls=y # CONFIG_LIBMBEDTLS_DEBUG_C is not set # CONFIG_PACKAGE_libnss is not set CONFIG_PACKAGE_libopenssl=y # # Build Options # CONFIG_OPENSSL_OPTIMIZE_SPEED=y CONFIG_OPENSSL_WITH_ASM=y CONFIG_OPENSSL_WITH_DEPRECATED=y # CONFIG_OPENSSL_NO_DEPRECATED is not set CONFIG_OPENSSL_WITH_ERROR_MESSAGES=y # # Protocol Support # CONFIG_OPENSSL_WITH_TLS13=y # CONFIG_OPENSSL_WITH_DTLS is not set # CONFIG_OPENSSL_WITH_NPN is not set CONFIG_OPENSSL_WITH_SRP=y CONFIG_OPENSSL_WITH_CMS=y # # Algorithm Selection # # CONFIG_OPENSSL_WITH_EC2M is not set CONFIG_OPENSSL_WITH_CHACHA_POLY1305=y CONFIG_OPENSSL_PREFER_CHACHA_OVER_GCM=y CONFIG_OPENSSL_WITH_PSK=y # # Less commonly used build options # # CONFIG_OPENSSL_WITH_ARIA is not set # CONFIG_OPENSSL_WITH_CAMELLIA is not set # CONFIG_OPENSSL_WITH_IDEA is not set # CONFIG_OPENSSL_WITH_SEED is not set # CONFIG_OPENSSL_WITH_SM234 is not set # CONFIG_OPENSSL_WITH_BLAKE2 is not set # CONFIG_OPENSSL_WITH_MDC2 is not set # CONFIG_OPENSSL_WITH_WHIRLPOOL is not set # CONFIG_OPENSSL_WITH_COMPRESSION is not set # CONFIG_OPENSSL_WITH_RFC3779 is not set # # Engine/Hardware Support # CONFIG_OPENSSL_ENGINE=y CONFIG_OPENSSL_ENGINE_BUILTIN=y CONFIG_OPENSSL_ENGINE_BUILTIN_AFALG=y CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO=y # CONFIG_OPENSSL_WITH_GOST is not set CONFIG_PACKAGE_libopenssl-conf=y # CONFIG_PACKAGE_libopenssl-devcrypto is not set # CONFIG_PACKAGE_libopenssl1.1 is not set # CONFIG_PACKAGE_libpolarssl is not set # CONFIG_PACKAGE_libwolfssl is not set # end of SSL # # Sound # # CONFIG_PACKAGE_liblo is not set # end of Sound # # Telephony # # CONFIG_PACKAGE_bcg729 is not set # CONFIG_PACKAGE_dahdi-tools-libtonezone is not set # CONFIG_PACKAGE_gsmlib is not set # CONFIG_PACKAGE_libctb is not set # CONFIG_PACKAGE_libfreetdm is not set # CONFIG_PACKAGE_libiksemel is not set # CONFIG_PACKAGE_libks is not set # CONFIG_PACKAGE_libosip2 is not set # CONFIG_PACKAGE_libpj is not set # CONFIG_PACKAGE_libpjlib-util is not set # CONFIG_PACKAGE_libpjmedia is not set # CONFIG_PACKAGE_libpjnath is not set # CONFIG_PACKAGE_libpjsip is not set # CONFIG_PACKAGE_libpjsip-simple is not set # CONFIG_PACKAGE_libpjsip-ua is not set # CONFIG_PACKAGE_libpjsua is not set # CONFIG_PACKAGE_libpjsua2 is not set # CONFIG_PACKAGE_libre is not set # CONFIG_PACKAGE_librem is not set # CONFIG_PACKAGE_libspandsp is not set # CONFIG_PACKAGE_libspandsp3 is not set # CONFIG_PACKAGE_libsrtp2 is not set # CONFIG_PACKAGE_signalwire-client-c is not set # CONFIG_PACKAGE_sofia-sip is not set # end of Telephony # # libimobiledevice # # CONFIG_PACKAGE_libimobiledevice is not set # CONFIG_PACKAGE_libirecovery is not set # CONFIG_PACKAGE_libplist is not set # CONFIG_PACKAGE_libplistcxx is not set # CONFIG_PACKAGE_libusbmuxd is not set # end of libimobiledevice # CONFIG_PACKAGE_alsa-lib is not set # CONFIG_PACKAGE_argp-standalone is not set # CONFIG_PACKAGE_bind-libs is not set # CONFIG_PACKAGE_bluez-libs is not set # CONFIG_PACKAGE_boost is not set # CONFIG_boost-context-exclude is not set # CONFIG_boost-coroutine-exclude is not set # CONFIG_boost-fiber-exclude is not set # CONFIG_PACKAGE_ccid is not set # CONFIG_PACKAGE_check is not set # CONFIG_PACKAGE_confuse is not set # CONFIG_PACKAGE_czmq is not set # CONFIG_PACKAGE_dtndht is not set # CONFIG_PACKAGE_getdns is not set # CONFIG_PACKAGE_giflib is not set # CONFIG_PACKAGE_glib2 is not set # CONFIG_PACKAGE_google-authenticator-libpam is not set # CONFIG_PACKAGE_hidapi is not set # CONFIG_PACKAGE_ibrcommon is not set # CONFIG_PACKAGE_ibrdtn is not set # CONFIG_PACKAGE_icu is not set # CONFIG_PACKAGE_icu-data-tools is not set # CONFIG_PACKAGE_icu-full-data is not set # CONFIG_PACKAGE_jansson is not set # CONFIG_PACKAGE_json-glib is not set # CONFIG_PACKAGE_jsoncpp is not set # CONFIG_PACKAGE_knot-libs is not set # CONFIG_PACKAGE_knot-libzscanner is not set # CONFIG_PACKAGE_libaio is not set # CONFIG_PACKAGE_libantlr3c is not set # CONFIG_PACKAGE_libao is not set # CONFIG_PACKAGE_libapr is not set # CONFIG_PACKAGE_libaprutil is not set # CONFIG_PACKAGE_libarchive is not set # CONFIG_PACKAGE_libarchive-noopenssl is not set # CONFIG_PACKAGE_libasm is not set # CONFIG_PACKAGE_libavahi-client is not set # CONFIG_PACKAGE_libavahi-compat-libdnssd is not set # CONFIG_PACKAGE_libavahi-dbus-support is not set # CONFIG_PACKAGE_libavahi-nodbus-support is not set # CONFIG_PACKAGE_libbfd is not set # CONFIG_PACKAGE_libblkid is not set CONFIG_PACKAGE_libblobmsg-json=y # CONFIG_PACKAGE_libbsd is not set CONFIG_PACKAGE_libcap=y CONFIG_PACKAGE_libcap-bin=y CONFIG_PACKAGE_libcap-bin-capsh-shell="/bin/sh" # CONFIG_PACKAGE_libcap-ng is not set # CONFIG_PACKAGE_libcares is not set # CONFIG_PACKAGE_libcgroup is not set # CONFIG_PACKAGE_libcharset is not set # CONFIG_PACKAGE_libcoap is not set # CONFIG_PACKAGE_libcomerr is not set # CONFIG_PACKAGE_libconfig is not set # CONFIG_PACKAGE_libcryptopp is not set # CONFIG_PACKAGE_libcups is not set CONFIG_PACKAGE_libcurl=y # # SSL support # CONFIG_LIBCURL_MBEDTLS=y # CONFIG_LIBCURL_WOLFSSL is not set # CONFIG_LIBCURL_OPENSSL is not set # CONFIG_LIBCURL_GNUTLS is not set # CONFIG_LIBCURL_NOSSL is not set # # Supported protocols # # CONFIG_LIBCURL_DICT is not set CONFIG_LIBCURL_FILE=y CONFIG_LIBCURL_FTP=y # CONFIG_LIBCURL_GOPHER is not set CONFIG_LIBCURL_HTTP=y CONFIG_LIBCURL_COOKIES=y # CONFIG_LIBCURL_IMAP is not set # CONFIG_LIBCURL_LDAP is not set # CONFIG_LIBCURL_POP3 is not set # CONFIG_LIBCURL_RTSP is not set # CONFIG_LIBCURL_SSH2 is not set CONFIG_LIBCURL_NO_SMB="!" # CONFIG_LIBCURL_SMTP is not set # CONFIG_LIBCURL_TELNET is not set # CONFIG_LIBCURL_TFTP is not set # CONFIG_LIBCURL_NGHTTP2 is not set # # Miscellaneous # CONFIG_LIBCURL_PROXY=y # CONFIG_LIBCURL_CRYPTO_AUTH is not set # CONFIG_LIBCURL_TLS_SRP is not set # CONFIG_LIBCURL_LIBIDN2 is not set # CONFIG_LIBCURL_THREADED_RESOLVER is not set # CONFIG_LIBCURL_ZLIB is not set # CONFIG_LIBCURL_UNIX_SOCKETS is not set # CONFIG_LIBCURL_LIBCURL_OPTION is not set # CONFIG_LIBCURL_VERBOSE is not set # CONFIG_PACKAGE_libcxx is not set # CONFIG_PACKAGE_libdaemon is not set # CONFIG_PACKAGE_libdaq is not set CONFIG_PACKAGE_libdb47=y # CONFIG_PACKAGE_libdb47xx is not set # CONFIG_PACKAGE_libdbi is not set # CONFIG_PACKAGE_libdbus is not set # CONFIG_PACKAGE_libdevmapper is not set # CONFIG_PACKAGE_libdmapsharing is not set # CONFIG_PACKAGE_libdnet is not set # CONFIG_PACKAGE_libdouble-conversion is not set # CONFIG_PACKAGE_libdrm is not set # CONFIG_PACKAGE_libdw is not set # CONFIG_PACKAGE_libecdsautil is not set # CONFIG_PACKAGE_libedit is not set CONFIG_PACKAGE_libelf=y # CONFIG_PACKAGE_libesmtp is not set # CONFIG_PACKAGE_libestr is not set CONFIG_PACKAGE_libev=y # CONFIG_PACKAGE_libevdev is not set # CONFIG_PACKAGE_libevent2 is not set # CONFIG_PACKAGE_libevent2-core is not set # CONFIG_PACKAGE_libevent2-extra is not set # CONFIG_PACKAGE_libevent2-openssl is not set # CONFIG_PACKAGE_libevent2-pthreads is not set # CONFIG_PACKAGE_libevhtp is not set # CONFIG_LIBEVHTP_BUILD_DEPENDS is not set # CONFIG_PACKAGE_libexif is not set # CONFIG_PACKAGE_libexpat is not set # CONFIG_PACKAGE_libexslt is not set # CONFIG_PACKAGE_libext2fs is not set # CONFIG_PACKAGE_libextractor is not set # CONFIG_PACKAGE_libf2fs is not set # CONFIG_PACKAGE_libfaad2 is not set # CONFIG_PACKAGE_libfastjson is not set # CONFIG_PACKAGE_libfdisk is not set # CONFIG_PACKAGE_libfdt is not set # CONFIG_PACKAGE_libffi is not set # CONFIG_PACKAGE_libffmpeg-audio-dec is not set # CONFIG_PACKAGE_libffmpeg-custom is not set # CONFIG_PACKAGE_libffmpeg-full is not set # CONFIG_PACKAGE_libffmpeg-mini is not set # CONFIG_PACKAGE_libflac is not set # CONFIG_PACKAGE_libfmt is not set # CONFIG_PACKAGE_libfreetype is not set # CONFIG_PACKAGE_libfstrm is not set # CONFIG_PACKAGE_libftdi is not set # CONFIG_PACKAGE_libftdi1 is not set # CONFIG_PACKAGE_libgabe is not set # CONFIG_PACKAGE_libgcrypt is not set # CONFIG_PACKAGE_libgd is not set # CONFIG_PACKAGE_libgd-full is not set # CONFIG_PACKAGE_libgdbm is not set # CONFIG_PACKAGE_libgee is not set CONFIG_PACKAGE_libgmp=y # CONFIG_PACKAGE_libgnurl is not set # CONFIG_PACKAGE_libgpg-error is not set # CONFIG_PACKAGE_libgphoto2 is not set # CONFIG_PACKAGE_libgpiod is not set # CONFIG_PACKAGE_libgps is not set # CONFIG_PACKAGE_libh2o is not set # CONFIG_PACKAGE_libh2o-evloop is not set # CONFIG_PACKAGE_libhamlib is not set # CONFIG_PACKAGE_libhavege is not set # CONFIG_PACKAGE_libhiredis is not set # CONFIG_PACKAGE_libhttp-parser is not set # CONFIG_PACKAGE_libhwloc is not set # CONFIG_PACKAGE_libi2c is not set # CONFIG_PACKAGE_libical is not set # CONFIG_PACKAGE_libiconv is not set # CONFIG_PACKAGE_libiconv-full is not set # CONFIG_PACKAGE_libid3tag is not set # CONFIG_PACKAGE_libidn is not set # CONFIG_PACKAGE_libidn2 is not set # CONFIG_PACKAGE_libiio is not set # CONFIG_PACKAGE_libinotifytools is not set # CONFIG_PACKAGE_libinput is not set # CONFIG_PACKAGE_libintl is not set # CONFIG_PACKAGE_libintl-full is not set # CONFIG_PACKAGE_libipfs-http-client is not set # CONFIG_PACKAGE_libiw is not set CONFIG_PACKAGE_libiwinfo=y # CONFIG_PACKAGE_libjpeg-turbo is not set CONFIG_PACKAGE_libjson-c=y # CONFIG_PACKAGE_libkeyutils is not set # CONFIG_PACKAGE_libkmod is not set # CONFIG_PACKAGE_libldns is not set # CONFIG_PACKAGE_libleptonica is not set # CONFIG_PACKAGE_libloragw is not set CONFIG_PACKAGE_libltdl=y CONFIG_PACKAGE_liblua=y CONFIG_PACKAGE_liblua5.3=y # CONFIG_PACKAGE_liblzo is not set # CONFIG_PACKAGE_libmad is not set # CONFIG_PACKAGE_libmagic is not set # CONFIG_PACKAGE_libmaxminddb is not set # CONFIG_PACKAGE_libmbim is not set # CONFIG_PACKAGE_libmcrypt is not set # CONFIG_PACKAGE_libmicrohttpd-no-ssl is not set # CONFIG_PACKAGE_libmicrohttpd-ssl is not set # CONFIG_PACKAGE_libmilter-sendmail is not set CONFIG_PACKAGE_libminiupnpc=y # CONFIG_PACKAGE_libmms is not set CONFIG_PACKAGE_libmnl=y # CONFIG_PACKAGE_libmodbus is not set # CONFIG_PACKAGE_libmosquitto-nossl is not set # CONFIG_PACKAGE_libmosquitto-ssl is not set # CONFIG_PACKAGE_libmount is not set # CONFIG_PACKAGE_libmpdclient is not set # CONFIG_PACKAGE_libmpeg2 is not set # CONFIG_PACKAGE_libmpg123 is not set CONFIG_PACKAGE_libnatpmp=y CONFIG_PACKAGE_libncurses=y # CONFIG_PACKAGE_libndpi is not set # CONFIG_PACKAGE_libneon is not set # CONFIG_PACKAGE_libnet-1.2.x is not set # CONFIG_PACKAGE_libnetconf2 is not set # CONFIG_PACKAGE_libnetfilter-acct is not set # CONFIG_PACKAGE_libnetfilter-conntrack is not set # CONFIG_PACKAGE_libnetfilter-cthelper is not set # CONFIG_PACKAGE_libnetfilter-cttimeout is not set # CONFIG_PACKAGE_libnetfilter-log is not set # CONFIG_PACKAGE_libnetfilter-queue is not set # CONFIG_PACKAGE_libnetsnmp is not set # CONFIG_PACKAGE_libnettle is not set # CONFIG_PACKAGE_libnewt is not set # CONFIG_PACKAGE_libnfnetlink is not set # CONFIG_PACKAGE_libnftnl is not set # CONFIG_PACKAGE_libnghttp2 is not set # CONFIG_PACKAGE_libnl is not set # CONFIG_PACKAGE_libnl-core is not set # CONFIG_PACKAGE_libnl-genl is not set # CONFIG_PACKAGE_libnl-nf is not set # CONFIG_PACKAGE_libnl-route is not set CONFIG_PACKAGE_libnl-tiny=y # CONFIG_PACKAGE_libnopoll is not set # CONFIG_PACKAGE_libnpupnp is not set # CONFIG_PACKAGE_libogg is not set # CONFIG_PACKAGE_liboil is not set # CONFIG_PACKAGE_libopcodes is not set # CONFIG_PACKAGE_libopendkim is not set # CONFIG_PACKAGE_libopenobex is not set # CONFIG_PACKAGE_libopensc is not set # CONFIG_PACKAGE_libopenzwave is not set # CONFIG_PACKAGE_liboping is not set # CONFIG_PACKAGE_libopus is not set # CONFIG_PACKAGE_libopusenc is not set # CONFIG_PACKAGE_libopusfile is not set # CONFIG_PACKAGE_liborcania is not set # CONFIG_PACKAGE_libout123 is not set # CONFIG_PACKAGE_libowfat is not set # CONFIG_PACKAGE_libp11 is not set # CONFIG_PACKAGE_libpagekite is not set # CONFIG_PACKAGE_libpam is not set # CONFIG_PACKAGE_libpbc is not set # CONFIG_PACKAGE_libpcap is not set # CONFIG_PACKAGE_libpci is not set # CONFIG_PACKAGE_libpciaccess is not set CONFIG_PACKAGE_libpcre=y # CONFIG_PCRE_JIT_ENABLED is not set # CONFIG_PACKAGE_libpcre16 is not set # CONFIG_PACKAGE_libpcre2 is not set # CONFIG_PACKAGE_libpcre2-16 is not set # CONFIG_PACKAGE_libpcre2-32 is not set # CONFIG_PACKAGE_libpcre32 is not set # CONFIG_PACKAGE_libpcrecpp is not set # CONFIG_PACKAGE_libpcsclite is not set # CONFIG_PACKAGE_libpfring is not set # CONFIG_PACKAGE_libpkcs11-spy is not set # CONFIG_PACKAGE_libpkgconf is not set # CONFIG_PACKAGE_libpng is not set # CONFIG_PACKAGE_libpopt is not set # CONFIG_PACKAGE_libpri is not set # CONFIG_PACKAGE_libprotobuf-c is not set # CONFIG_PACKAGE_libpsl is not set # CONFIG_PACKAGE_libqmi is not set # CONFIG_PACKAGE_libqrencode is not set # CONFIG_PACKAGE_libradcli is not set # CONFIG_PACKAGE_libradiotap is not set CONFIG_PACKAGE_libreadline=y # CONFIG_PACKAGE_libredblack is not set # CONFIG_PACKAGE_librouteros is not set # CONFIG_PACKAGE_libroxml is not set # CONFIG_PACKAGE_librrd1 is not set # CONFIG_PACKAGE_librtlsdr is not set CONFIG_PACKAGE_libruby=y # CONFIG_PACKAGE_libsamplerate is not set # CONFIG_PACKAGE_libsane is not set # CONFIG_PACKAGE_libsasl2 is not set # CONFIG_PACKAGE_libsearpc is not set # CONFIG_PACKAGE_libseccomp is not set # CONFIG_PACKAGE_libselinux is not set # CONFIG_PACKAGE_libsensors is not set # CONFIG_PACKAGE_libsepol is not set # CONFIG_PACKAGE_libshout is not set # CONFIG_PACKAGE_libshout-full is not set # CONFIG_PACKAGE_libshout-nossl is not set # CONFIG_PACKAGE_libsispmctl is not set # CONFIG_PACKAGE_libslang2 is not set # CONFIG_PACKAGE_libslang2-mod-base64 is not set # CONFIG_PACKAGE_libslang2-mod-chksum is not set # CONFIG_PACKAGE_libslang2-mod-csv is not set # CONFIG_PACKAGE_libslang2-mod-fcntl is not set # CONFIG_PACKAGE_libslang2-mod-fork is not set # CONFIG_PACKAGE_libslang2-mod-histogram is not set # CONFIG_PACKAGE_libslang2-mod-iconv is not set # CONFIG_PACKAGE_libslang2-mod-json is not set # CONFIG_PACKAGE_libslang2-mod-onig is not set # CONFIG_PACKAGE_libslang2-mod-pcre is not set # CONFIG_PACKAGE_libslang2-mod-png is not set # CONFIG_PACKAGE_libslang2-mod-rand is not set # CONFIG_PACKAGE_libslang2-mod-select is not set # CONFIG_PACKAGE_libslang2-mod-slsmg is not set # CONFIG_PACKAGE_libslang2-mod-socket is not set # CONFIG_PACKAGE_libslang2-mod-stats is not set # CONFIG_PACKAGE_libslang2-mod-sysconf is not set # CONFIG_PACKAGE_libslang2-mod-termios is not set # CONFIG_PACKAGE_libslang2-mod-varray is not set # CONFIG_PACKAGE_libslang2-mod-zlib is not set # CONFIG_PACKAGE_libslang2-modules is not set # CONFIG_PACKAGE_libsmartcols is not set # CONFIG_PACKAGE_libsndfile is not set # CONFIG_PACKAGE_libsoc is not set # CONFIG_PACKAGE_libsocks is not set CONFIG_PACKAGE_libsodium=y # # Configuration # CONFIG_LIBSODIUM_MINIMAL=y # end of Configuration # CONFIG_PACKAGE_libsoup is not set # CONFIG_PACKAGE_libsoxr is not set # CONFIG_PACKAGE_libspeex is not set # CONFIG_PACKAGE_libspeexdsp is not set # CONFIG_PACKAGE_libspice-server is not set # CONFIG_PACKAGE_libss is not set # CONFIG_PACKAGE_libssh is not set # CONFIG_PACKAGE_libssh2 is not set # CONFIG_PACKAGE_libstoken is not set # CONFIG_PACKAGE_libstrophe is not set # CONFIG_PACKAGE_libsysrepo is not set # CONFIG_PACKAGE_libtalloc is not set # CONFIG_PACKAGE_libtasn1 is not set # CONFIG_PACKAGE_libtheora is not set # CONFIG_PACKAGE_libtiff is not set # CONFIG_PACKAGE_libtiffxx is not set # CONFIG_PACKAGE_libtins is not set # CONFIG_PACKAGE_libtirpc is not set # CONFIG_PACKAGE_libtorrent is not set CONFIG_PACKAGE_libubox=y # CONFIG_PACKAGE_libubox-lua is not set CONFIG_PACKAGE_libubus=y CONFIG_PACKAGE_libubus-lua=y CONFIG_PACKAGE_libuci=y CONFIG_PACKAGE_libuci-lua=y CONFIG_PACKAGE_libuclient=y # CONFIG_PACKAGE_libudev-fbsd is not set # CONFIG_PACKAGE_libudns is not set # CONFIG_PACKAGE_libuecc is not set # CONFIG_PACKAGE_libugpio is not set # CONFIG_PACKAGE_libunistring is not set # CONFIG_PACKAGE_libunwind is not set # CONFIG_PACKAGE_libupnp is not set # CONFIG_PACKAGE_libupnpp is not set # CONFIG_PACKAGE_liburcu is not set # CONFIG_PACKAGE_liburing is not set # CONFIG_PACKAGE_libusb-1.0 is not set # CONFIG_PACKAGE_libusb-compat is not set # CONFIG_PACKAGE_libustream-mbedtls is not set CONFIG_PACKAGE_libustream-openssl=y # CONFIG_PACKAGE_libustream-wolfssl is not set CONFIG_PACKAGE_libuuid=y CONFIG_PACKAGE_libuv=y # CONFIG_PACKAGE_libuwifi is not set # CONFIG_PACKAGE_libv4l is not set # CONFIG_PACKAGE_libvorbis is not set # CONFIG_PACKAGE_libvorbisidec is not set # CONFIG_PACKAGE_libvpx is not set # CONFIG_PACKAGE_libwebcam is not set # CONFIG_PACKAGE_libwebp is not set CONFIG_PACKAGE_libwebsockets-full=y # CONFIG_PACKAGE_libwebsockets-mbedtls is not set # CONFIG_PACKAGE_libwebsockets-openssl is not set # CONFIG_PACKAGE_libwrap is not set # CONFIG_PACKAGE_libwslay is not set # CONFIG_PACKAGE_libwxbase is not set # CONFIG_PACKAGE_libxerces-c is not set # CONFIG_PACKAGE_libxerces-c-samples is not set CONFIG_PACKAGE_libxml2=y # CONFIG_PACKAGE_libxslt is not set # CONFIG_PACKAGE_libyaml-cpp is not set # CONFIG_PACKAGE_libyang is not set # CONFIG_PACKAGE_libyang-cpp is not set # CONFIG_PACKAGE_libyubikey is not set # CONFIG_PACKAGE_libzmq-curve is not set # CONFIG_PACKAGE_libzmq-nc is not set # CONFIG_PACKAGE_linux-atm is not set # CONFIG_PACKAGE_lmdb is not set # CONFIG_PACKAGE_log4cplus is not set # CONFIG_PACKAGE_loudmouth is not set # CONFIG_PACKAGE_lttng-ust is not set # CONFIG_PACKAGE_measurement-kit is not set # CONFIG_MEASUREMENT_KIT_BUILD_DEPENDS is not set # CONFIG_PACKAGE_minizip is not set # CONFIG_PACKAGE_mtdev is not set # CONFIG_PACKAGE_musl-fts is not set # CONFIG_PACKAGE_mxml is not set # CONFIG_PACKAGE_nacl is not set # CONFIG_PACKAGE_nlohmannjson is not set # CONFIG_PACKAGE_nspr is not set # CONFIG_PACKAGE_oniguruma is not set # CONFIG_PACKAGE_open-isns is not set # CONFIG_PACKAGE_p11-kit is not set # CONFIG_PACKAGE_pixman is not set # CONFIG_PACKAGE_poco is not set # CONFIG_PACKAGE_poco-all is not set # CONFIG_PACKAGE_protobuf is not set # CONFIG_PACKAGE_protobuf-lite is not set # CONFIG_PACKAGE_pthsem is not set # CONFIG_PACKAGE_rblibtorrent is not set # CONFIG_PACKAGE_re2 is not set CONFIG_PACKAGE_rpcd-mod-rrdns=y # CONFIG_PACKAGE_sbc is not set # CONFIG_PACKAGE_serdisplib is not set # CONFIG_PACKAGE_spice-protocol is not set CONFIG_PACKAGE_terminfo=y # CONFIG_PACKAGE_tinycdb is not set # CONFIG_PACKAGE_uclibcxx is not set # CONFIG_PACKAGE_uw-imap is not set # CONFIG_PACKAGE_xmlrpc-c is not set # CONFIG_PACKAGE_xmlrpc-c-client is not set # CONFIG_PACKAGE_xmlrpc-c-server is not set # CONFIG_PACKAGE_yajl is not set # CONFIG_PACKAGE_yubico-pam is not set CONFIG_PACKAGE_zlib=y # # Configuration # # CONFIG_ZLIB_OPTIMIZE_SPEED is not set # end of Configuration # end of Libraries # # LuCI # # # 1. Collections # CONFIG_PACKAGE_luci=y # CONFIG_PACKAGE_luci-nginx is not set # CONFIG_PACKAGE_luci-ssl-nginx is not set # CONFIG_PACKAGE_luci-ssl-openssl is not set # end of 1. Collections # # 2. Modules # CONFIG_PACKAGE_luci-base=y # CONFIG_LUCI_SRCDIET is not set # # Translations # # CONFIG_LUCI_LANG_hu is not set # CONFIG_LUCI_LANG_pt is not set # CONFIG_LUCI_LANG_no is not set # CONFIG_LUCI_LANG_sk is not set # CONFIG_LUCI_LANG_el is not set # CONFIG_LUCI_LANG_uk is not set # CONFIG_LUCI_LANG_ru is not set # CONFIG_LUCI_LANG_vi is not set # CONFIG_LUCI_LANG_de is not set # CONFIG_LUCI_LANG_ro is not set # CONFIG_LUCI_LANG_ms is not set # CONFIG_LUCI_LANG_pl is not set CONFIG_LUCI_LANG_zh-cn=y # CONFIG_LUCI_LANG_ko is not set # CONFIG_LUCI_LANG_he is not set # CONFIG_LUCI_LANG_zh-tw is not set # CONFIG_LUCI_LANG_tr is not set # CONFIG_LUCI_LANG_sv is not set # CONFIG_LUCI_LANG_ja is not set # CONFIG_LUCI_LANG_pt-br is not set # CONFIG_LUCI_LANG_ca is not set # CONFIG_LUCI_LANG_en is not set # CONFIG_LUCI_LANG_es is not set # CONFIG_LUCI_LANG_cs is not set # CONFIG_LUCI_LANG_fr is not set # CONFIG_LUCI_LANG_it is not set # end of Translations CONFIG_PACKAGE_luci-compat=y CONFIG_PACKAGE_luci-mod-admin-full=y # CONFIG_PACKAGE_luci-mod-failsafe is not set # CONFIG_PACKAGE_luci-mod-freifunk is not set # CONFIG_PACKAGE_luci-mod-freifunk-community is not set # CONFIG_PACKAGE_luci-mod-rpc is not set # end of 2. Modules # # 3. Applications # # CONFIG_PACKAGE_luci-app-accesscontrol is not set # CONFIG_PACKAGE_luci-app-adblock is not set CONFIG_PACKAGE_luci-app-adbyby-plus=y # CONFIG_PACKAGE_luci-app-adguardhome is not set # CONFIG_PACKAGE_luci-app-advanced-reboot is not set # CONFIG_PACKAGE_luci-app-ahcp is not set # CONFIG_PACKAGE_luci-app-airplay2 is not set # CONFIG_PACKAGE_luci-app-amule is not set # CONFIG_PACKAGE_luci-app-aria2 is not set # CONFIG_PACKAGE_luci-app-arpbind is not set # CONFIG_PACKAGE_luci-app-asterisk is not set # CONFIG_PACKAGE_luci-app-attendedsysupgrade is not set CONFIG_PACKAGE_luci-app-autoreboot=y # CONFIG_PACKAGE_luci-app-baidupcs-web is not set # CONFIG_PACKAGE_luci-app-bcp38 is not set # CONFIG_PACKAGE_luci-app-bird1-ipv4 is not set # CONFIG_PACKAGE_luci-app-bird1-ipv6 is not set # CONFIG_PACKAGE_luci-app-bmx6 is not set # CONFIG_PACKAGE_luci-app-cifs-mount is not set # CONFIG_PACKAGE_luci-app-cifsd is not set # CONFIG_PACKAGE_luci-app-cjdns is not set # CONFIG_PACKAGE_luci-app-clamav is not set # CONFIG_PACKAGE_luci-app-commands is not set # CONFIG_PACKAGE_luci-app-control-timewol is not set # CONFIG_PACKAGE_luci-app-control-webrestriction is not set # CONFIG_PACKAGE_luci-app-control-weburl is not set # CONFIG_PACKAGE_luci-app-cshark is not set CONFIG_PACKAGE_luci-app-ddns=y # CONFIG_PACKAGE_luci-app-diag-core is not set # CONFIG_PACKAGE_luci-app-diskman is not set # CONFIG_PACKAGE_luci-app-diskman_INCLUDE_btrfs_progs is not set # CONFIG_PACKAGE_luci-app-diskman_INCLUDE_lsblk is not set # CONFIG_PACKAGE_luci-app-diskman_INCLUDE_mdadm is not set # CONFIG_PACKAGE_luci-app-dnscrypt-proxy is not set # CONFIG_PACKAGE_luci-app-dnsforwarder is not set # CONFIG_PACKAGE_luci-app-dump1090 is not set # CONFIG_PACKAGE_luci-app-dynapoint is not set # CONFIG_PACKAGE_luci-app-e2guardian is not set # CONFIG_PACKAGE_luci-app-familycloud is not set CONFIG_PACKAGE_luci-app-fileassistant=y CONFIG_PACKAGE_luci-app-filebrowser=y CONFIG_PACKAGE_luci-app-filetransfer=y CONFIG_PACKAGE_luci-app-firewall=y CONFIG_PACKAGE_luci-app-flowoffload=y # CONFIG_PACKAGE_luci-app-freifunk-diagnostics is not set # CONFIG_PACKAGE_luci-app-freifunk-policyrouting is not set # CONFIG_PACKAGE_luci-app-freifunk-widgets is not set # CONFIG_PACKAGE_luci-app-frpc is not set # CONFIG_PACKAGE_luci-app-frps is not set # CONFIG_PACKAGE_luci-app-fwknopd is not set CONFIG_PACKAGE_luci-app-guest-wifi=y # CONFIG_PACKAGE_luci-app-haproxy-tcp is not set # CONFIG_PACKAGE_luci-app-hd-idle is not set # CONFIG_PACKAGE_luci-app-hnet is not set # CONFIG_PACKAGE_luci-app-https-dns-proxy is not set # CONFIG_PACKAGE_luci-app-ipsec-server is not set # CONFIG_PACKAGE_luci-app-ipsec-vpnd is not set # CONFIG_PACKAGE_luci-app-jd-dailybonus is not set # CONFIG_PACKAGE_luci-app-kodexplorer is not set # CONFIG_PACKAGE_luci-app-lxc is not set # CONFIG_PACKAGE_luci-app-meshwizard is not set # CONFIG_PACKAGE_luci-app-minidlna is not set # CONFIG_PACKAGE_luci-app-mjpg-streamer is not set # CONFIG_PACKAGE_luci-app-mtwifi is not set # CONFIG_PACKAGE_luci-app-music-remote-center is not set # CONFIG_PACKAGE_luci-app-mwan3 is not set # CONFIG_PACKAGE_luci-app-mwan3helper is not set # CONFIG_PACKAGE_luci-app-n2n_v2 is not set # CONFIG_PACKAGE_luci-app-netdata is not set # CONFIG_PACKAGE_luci-app-nfs is not set # CONFIG_PACKAGE_luci-app-nft-qos is not set # CONFIG_PACKAGE_luci-app-nginx-pingos is not set # CONFIG_PACKAGE_luci-app-nlbwmon is not set # CONFIG_PACKAGE_luci-app-noddos is not set # CONFIG_PACKAGE_luci-app-nps is not set # CONFIG_PACKAGE_luci-app-ntpc is not set # CONFIG_PACKAGE_luci-app-ocserv is not set # CONFIG_PACKAGE_luci-app-olsr is not set # CONFIG_PACKAGE_luci-app-olsr-services is not set # CONFIG_PACKAGE_luci-app-olsr-viz is not set CONFIG_PACKAGE_luci-app-openclash=y # CONFIG_PACKAGE_luci-app-openvpn is not set # CONFIG_PACKAGE_luci-app-openvpn-server is not set # CONFIG_PACKAGE_luci-app-p910nd is not set # CONFIG_PACKAGE_luci-app-pagekitec is not set CONFIG_PACKAGE_luci-app-passwall=y # # Configuration # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks_Server is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ShadowsocksR=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ShadowsocksR_Server is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Xray=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_V2ray is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Trojan_Plus is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Trojan_GO is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Brook is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_NaiveProxy is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_kcptun is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_haproxy=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ChinaDNS_NG is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_dns2socks=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_v2ray-plugin is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_simple-obfs is not set # end of Configuration # CONFIG_PACKAGE_luci-app-polipo is not set # CONFIG_PACKAGE_luci-app-pppoe-relay is not set # CONFIG_PACKAGE_luci-app-pppoe-server is not set # CONFIG_PACKAGE_luci-app-pptp-server is not set # CONFIG_PACKAGE_luci-app-privoxy is not set # CONFIG_PACKAGE_luci-app-ps3netsrv is not set # CONFIG_PACKAGE_luci-app-qbittorrent is not set # CONFIG_PACKAGE_luci-app-qos is not set # CONFIG_PACKAGE_luci-app-radicale is not set CONFIG_PACKAGE_luci-app-ramfree=y # CONFIG_PACKAGE_luci-app-rclone is not set # CONFIG_PACKAGE_luci-app-rclone_INCLUDE_rclone-webui is not set # CONFIG_PACKAGE_luci-app-rclone_INCLUDE_rclone-ng is not set # CONFIG_PACKAGE_luci-app-rclone_INCLUDE_fuse-utils is not set # CONFIG_PACKAGE_luci-app-rp-pppoe-server is not set CONFIG_PACKAGE_luci-app-samba=y # CONFIG_PACKAGE_luci-app-samba4 is not set # CONFIG_PACKAGE_luci-app-sfe is not set # CONFIG_PACKAGE_luci-app-shadowsocks-libev is not set # CONFIG_PACKAGE_luci-app-shairplay is not set # CONFIG_PACKAGE_luci-app-siitwizard is not set # CONFIG_PACKAGE_luci-app-simple-adblock is not set CONFIG_PACKAGE_luci-app-smartdns=y # CONFIG_PACKAGE_luci-app-socat is not set # CONFIG_PACKAGE_luci-app-softethervpn is not set # CONFIG_PACKAGE_luci-app-splash is not set # CONFIG_PACKAGE_luci-app-sqm is not set # CONFIG_PACKAGE_luci-app-squid is not set # CONFIG_PACKAGE_luci-app-ssr-mudb-server is not set CONFIG_PACKAGE_luci-app-ssr-plus=y CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Xray=y # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Trojan is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Redsocks2 is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_NaiveProxy is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Trojan-go is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Kcptun is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray_plugin is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_ShadowsocksR_Server is not set # CONFIG_PACKAGE_luci-app-ssrserver-python is not set # CONFIG_PACKAGE_luci-app-statistics is not set # CONFIG_PACKAGE_luci-app-syncdial is not set # CONFIG_PACKAGE_luci-app-syncthing is not set # CONFIG_PACKAGE_luci-app-timecontrol is not set # CONFIG_PACKAGE_luci-app-tinyproxy is not set # CONFIG_PACKAGE_luci-app-transmission is not set CONFIG_PACKAGE_luci-app-travelmate=y CONFIG_PACKAGE_luci-app-ttyd=y # CONFIG_PACKAGE_luci-app-udpxy is not set # CONFIG_PACKAGE_luci-app-uhttpd is not set # CONFIG_PACKAGE_luci-app-unblockmusic is not set # CONFIG_UnblockNeteaseMusic_Go is not set # CONFIG_UnblockNeteaseMusic_NodeJS is not set # CONFIG_PACKAGE_luci-app-unbound is not set CONFIG_PACKAGE_luci-app-upnp=y # CONFIG_PACKAGE_luci-app-usb-printer is not set # CONFIG_PACKAGE_luci-app-uugamebooster is not set # CONFIG_PACKAGE_luci-app-v2ray-server is not set # CONFIG_PACKAGE_luci-app-verysync is not set CONFIG_PACKAGE_luci-app-vlmcsd=y # CONFIG_PACKAGE_luci-app-vnstat is not set # CONFIG_PACKAGE_luci-app-vpnbypass is not set CONFIG_PACKAGE_luci-app-vsftpd=y # CONFIG_PACKAGE_luci-app-watchcat is not set CONFIG_PACKAGE_luci-app-webadmin=y CONFIG_PACKAGE_luci-app-wifischedule=y # CONFIG_PACKAGE_luci-app-wireguard is not set # CONFIG_PACKAGE_luci-app-wol is not set # CONFIG_PACKAGE_luci-app-wrtbwmon is not set # CONFIG_PACKAGE_luci-app-xlnetacc is not set CONFIG_PACKAGE_luci-app-zerotier=y # end of 3. Applications # # 4. Themes # # CONFIG_PACKAGE_luci-theme-argon is not set CONFIG_PACKAGE_luci-theme-bootstrap=y # CONFIG_PACKAGE_luci-theme-freifunk-generic is not set # CONFIG_PACKAGE_luci-theme-material is not set # CONFIG_PACKAGE_luci-theme-netgear is not set # end of 4. Themes # # 5. Protocols # # CONFIG_PACKAGE_luci-proto-3g is not set # CONFIG_PACKAGE_luci-proto-bonding is not set # CONFIG_PACKAGE_luci-proto-ipip is not set # CONFIG_PACKAGE_luci-proto-ipv6 is not set # CONFIG_PACKAGE_luci-proto-openconnect is not set CONFIG_PACKAGE_luci-proto-ppp=y # CONFIG_PACKAGE_luci-proto-qmi is not set # CONFIG_PACKAGE_luci-proto-relay is not set # CONFIG_PACKAGE_luci-proto-vpnc is not set # CONFIG_PACKAGE_luci-proto-wireguard is not set # end of 5. Protocols # # 6. Libraries # # CONFIG_PACKAGE_luci-lib-docker is not set # CONFIG_PACKAGE_luci-lib-dracula is not set # CONFIG_PACKAGE_luci-lib-httpclient is not set # CONFIG_PACKAGE_luci-lib-httpprotoutils is not set CONFIG_PACKAGE_luci-lib-ip=y # CONFIG_PACKAGE_luci-lib-iptparser is not set # CONFIG_PACKAGE_luci-lib-jquery-1-4 is not set # CONFIG_PACKAGE_luci-lib-json is not set CONFIG_PACKAGE_luci-lib-jsonc=y # CONFIG_PACKAGE_luci-lib-luaneightbl is not set CONFIG_PACKAGE_luci-lib-nixio=y # CONFIG_PACKAGE_luci-lib-px5g is not set # end of 6. Libraries # # 9. Freifunk # # CONFIG_PACKAGE_freifunk-common is not set # CONFIG_PACKAGE_freifunk-firewall is not set # CONFIG_PACKAGE_freifunk-policyrouting is not set # CONFIG_PACKAGE_freifunk-watchdog is not set # CONFIG_PACKAGE_meshwizard is not set # end of 9. Freifunk CONFIG_PACKAGE_default-settings=y CONFIG_PACKAGE_luci-i18n-adbyby-plus-zh-cn=y CONFIG_PACKAGE_luci-i18n-autoreboot-zh-cn=y # CONFIG_PACKAGE_luci-i18n-base-ca is not set # CONFIG_PACKAGE_luci-i18n-base-cs is not set # CONFIG_PACKAGE_luci-i18n-base-de is not set # CONFIG_PACKAGE_luci-i18n-base-el is not set # CONFIG_PACKAGE_luci-i18n-base-en is not set # CONFIG_PACKAGE_luci-i18n-base-es is not set # CONFIG_PACKAGE_luci-i18n-base-fr is not set # CONFIG_PACKAGE_luci-i18n-base-he is not set # CONFIG_PACKAGE_luci-i18n-base-hu is not set # CONFIG_PACKAGE_luci-i18n-base-it is not set # CONFIG_PACKAGE_luci-i18n-base-ja is not set # CONFIG_PACKAGE_luci-i18n-base-ko is not set # CONFIG_PACKAGE_luci-i18n-base-ms is not set # CONFIG_PACKAGE_luci-i18n-base-no is not set # CONFIG_PACKAGE_luci-i18n-base-pl is not set # CONFIG_PACKAGE_luci-i18n-base-pt is not set # CONFIG_PACKAGE_luci-i18n-base-pt-br is not set # CONFIG_PACKAGE_luci-i18n-base-ro is not set # CONFIG_PACKAGE_luci-i18n-base-ru is not set # CONFIG_PACKAGE_luci-i18n-base-sk is not set # CONFIG_PACKAGE_luci-i18n-base-sv is not set # CONFIG_PACKAGE_luci-i18n-base-tr is not set # CONFIG_PACKAGE_luci-i18n-base-uk is not set # CONFIG_PACKAGE_luci-i18n-base-vi is not set CONFIG_PACKAGE_luci-i18n-base-zh-cn=y # CONFIG_PACKAGE_luci-i18n-base-zh-tw is not set # CONFIG_PACKAGE_luci-i18n-ddns-bg is not set # CONFIG_PACKAGE_luci-i18n-ddns-ca is not set # CONFIG_PACKAGE_luci-i18n-ddns-cs is not set # CONFIG_PACKAGE_luci-i18n-ddns-de is not set # CONFIG_PACKAGE_luci-i18n-ddns-el is not set # CONFIG_PACKAGE_luci-i18n-ddns-en is not set # CONFIG_PACKAGE_luci-i18n-ddns-es is not set # CONFIG_PACKAGE_luci-i18n-ddns-fr is not set # CONFIG_PACKAGE_luci-i18n-ddns-he is not set # CONFIG_PACKAGE_luci-i18n-ddns-hi is not set # CONFIG_PACKAGE_luci-i18n-ddns-hu is not set # CONFIG_PACKAGE_luci-i18n-ddns-it is not set # CONFIG_PACKAGE_luci-i18n-ddns-ja is not set # CONFIG_PACKAGE_luci-i18n-ddns-ko is not set # CONFIG_PACKAGE_luci-i18n-ddns-mr is not set # CONFIG_PACKAGE_luci-i18n-ddns-ms is not set # CONFIG_PACKAGE_luci-i18n-ddns-no is not set # CONFIG_PACKAGE_luci-i18n-ddns-pl is not set # CONFIG_PACKAGE_luci-i18n-ddns-pt is not set # CONFIG_PACKAGE_luci-i18n-ddns-pt-br is not set # CONFIG_PACKAGE_luci-i18n-ddns-ro is not set # CONFIG_PACKAGE_luci-i18n-ddns-ru is not set # CONFIG_PACKAGE_luci-i18n-ddns-sk is not set # CONFIG_PACKAGE_luci-i18n-ddns-sv is not set # CONFIG_PACKAGE_luci-i18n-ddns-tr is not set # CONFIG_PACKAGE_luci-i18n-ddns-uk is not set # CONFIG_PACKAGE_luci-i18n-ddns-vi is not set CONFIG_PACKAGE_luci-i18n-ddns-zh-cn=y # CONFIG_PACKAGE_luci-i18n-ddns-zh-tw is not set CONFIG_PACKAGE_luci-i18n-filebrowser-zh-cn=y CONFIG_PACKAGE_luci-i18n-filetransfer-zh-cn=y # CONFIG_PACKAGE_luci-i18n-firewall-ca is not set # CONFIG_PACKAGE_luci-i18n-firewall-cs is not set # CONFIG_PACKAGE_luci-i18n-firewall-de is not set # CONFIG_PACKAGE_luci-i18n-firewall-el is not set # CONFIG_PACKAGE_luci-i18n-firewall-en is not set # CONFIG_PACKAGE_luci-i18n-firewall-es is not set # CONFIG_PACKAGE_luci-i18n-firewall-fr is not set # CONFIG_PACKAGE_luci-i18n-firewall-he is not set # CONFIG_PACKAGE_luci-i18n-firewall-hu is not set # CONFIG_PACKAGE_luci-i18n-firewall-it is not set # CONFIG_PACKAGE_luci-i18n-firewall-ja is not set # CONFIG_PACKAGE_luci-i18n-firewall-ko is not set # CONFIG_PACKAGE_luci-i18n-firewall-ms is not set # CONFIG_PACKAGE_luci-i18n-firewall-no is not set # CONFIG_PACKAGE_luci-i18n-firewall-pl is not set # CONFIG_PACKAGE_luci-i18n-firewall-pt is not set # CONFIG_PACKAGE_luci-i18n-firewall-pt-br is not set # CONFIG_PACKAGE_luci-i18n-firewall-ro is not set # CONFIG_PACKAGE_luci-i18n-firewall-ru is not set # CONFIG_PACKAGE_luci-i18n-firewall-sk is not set # CONFIG_PACKAGE_luci-i18n-firewall-sv is not set # CONFIG_PACKAGE_luci-i18n-firewall-tr is not set # CONFIG_PACKAGE_luci-i18n-firewall-uk is not set # CONFIG_PACKAGE_luci-i18n-firewall-vi is not set CONFIG_PACKAGE_luci-i18n-firewall-zh-cn=y # CONFIG_PACKAGE_luci-i18n-firewall-zh-tw is not set CONFIG_PACKAGE_luci-i18n-flowoffload-zh-cn=y CONFIG_PACKAGE_luci-i18n-guest-wifi-zh-cn=y CONFIG_PACKAGE_luci-i18n-ramfree-zh-cn=y # CONFIG_PACKAGE_luci-i18n-samba-ca is not set # CONFIG_PACKAGE_luci-i18n-samba-cs is not set # CONFIG_PACKAGE_luci-i18n-samba-de is not set # CONFIG_PACKAGE_luci-i18n-samba-el is not set # CONFIG_PACKAGE_luci-i18n-samba-en is not set # CONFIG_PACKAGE_luci-i18n-samba-es is not set # CONFIG_PACKAGE_luci-i18n-samba-fr is not set # CONFIG_PACKAGE_luci-i18n-samba-he is not set # CONFIG_PACKAGE_luci-i18n-samba-hu is not set # CONFIG_PACKAGE_luci-i18n-samba-it is not set # CONFIG_PACKAGE_luci-i18n-samba-ja is not set # CONFIG_PACKAGE_luci-i18n-samba-ms is not set # CONFIG_PACKAGE_luci-i18n-samba-no is not set # CONFIG_PACKAGE_luci-i18n-samba-pl is not set # CONFIG_PACKAGE_luci-i18n-samba-pt is not set # CONFIG_PACKAGE_luci-i18n-samba-pt-br is not set # CONFIG_PACKAGE_luci-i18n-samba-ro is not set # CONFIG_PACKAGE_luci-i18n-samba-ru is not set # CONFIG_PACKAGE_luci-i18n-samba-sk is not set # CONFIG_PACKAGE_luci-i18n-samba-sv is not set # CONFIG_PACKAGE_luci-i18n-samba-tr is not set # CONFIG_PACKAGE_luci-i18n-samba-uk is not set # CONFIG_PACKAGE_luci-i18n-samba-vi is not set CONFIG_PACKAGE_luci-i18n-samba-zh-cn=y # CONFIG_PACKAGE_luci-i18n-samba-zh-tw is not set CONFIG_PACKAGE_luci-i18n-smartdns-zh-cn=y CONFIG_PACKAGE_luci-i18n-ssr-plus-zh-cn=y # CONFIG_PACKAGE_luci-i18n-ssr-plus-zh_Hans is not set # CONFIG_PACKAGE_luci-i18n-travelmate-ja is not set # CONFIG_PACKAGE_luci-i18n-travelmate-pt-br is not set # CONFIG_PACKAGE_luci-i18n-travelmate-ru is not set CONFIG_PACKAGE_luci-i18n-ttyd-zh-cn=y # CONFIG_PACKAGE_luci-i18n-upnp-ca is not set # CONFIG_PACKAGE_luci-i18n-upnp-cs is not set # CONFIG_PACKAGE_luci-i18n-upnp-de is not set # CONFIG_PACKAGE_luci-i18n-upnp-el is not set # CONFIG_PACKAGE_luci-i18n-upnp-en is not set # CONFIG_PACKAGE_luci-i18n-upnp-es is not set # CONFIG_PACKAGE_luci-i18n-upnp-fr is not set # CONFIG_PACKAGE_luci-i18n-upnp-he is not set # CONFIG_PACKAGE_luci-i18n-upnp-hu is not set # CONFIG_PACKAGE_luci-i18n-upnp-it is not set # CONFIG_PACKAGE_luci-i18n-upnp-ja is not set # CONFIG_PACKAGE_luci-i18n-upnp-ms is not set # CONFIG_PACKAGE_luci-i18n-upnp-no is not set # CONFIG_PACKAGE_luci-i18n-upnp-pl is not set # CONFIG_PACKAGE_luci-i18n-upnp-pt is not set # CONFIG_PACKAGE_luci-i18n-upnp-pt-br is not set # CONFIG_PACKAGE_luci-i18n-upnp-ro is not set # CONFIG_PACKAGE_luci-i18n-upnp-ru is not set # CONFIG_PACKAGE_luci-i18n-upnp-sk is not set # CONFIG_PACKAGE_luci-i18n-upnp-sv is not set # CONFIG_PACKAGE_luci-i18n-upnp-tr is not set # CONFIG_PACKAGE_luci-i18n-upnp-uk is not set # CONFIG_PACKAGE_luci-i18n-upnp-vi is not set CONFIG_PACKAGE_luci-i18n-upnp-zh-cn=y # CONFIG_PACKAGE_luci-i18n-upnp-zh-tw is not set CONFIG_PACKAGE_luci-i18n-vlmcsd-zh-cn=y CONFIG_PACKAGE_luci-i18n-vsftpd-zh-cn=y CONFIG_PACKAGE_luci-i18n-webadmin-zh-cn=y # CONFIG_PACKAGE_luci-i18n-wifischedule-it is not set # CONFIG_PACKAGE_luci-i18n-wifischedule-ja is not set # CONFIG_PACKAGE_luci-i18n-wifischedule-pt-br is not set # CONFIG_PACKAGE_luci-i18n-wifischedule-ru is not set # CONFIG_PACKAGE_luci-i18n-wifischedule-sv is not set CONFIG_PACKAGE_luci-i18n-wifischedule-zh-cn=y CONFIG_PACKAGE_luci-i18n-zerotier-zh-cn=y # end of LuCI # # Mail # # CONFIG_PACKAGE_alpine is not set # CONFIG_PACKAGE_alpine-nossl is not set # CONFIG_PACKAGE_bogofilter is not set # CONFIG_PACKAGE_clamsmtp is not set # CONFIG_PACKAGE_dovecot is not set # CONFIG_PACKAGE_dovecot-pigeonhole is not set # CONFIG_PACKAGE_dovecot-utils is not set # CONFIG_PACKAGE_emailrelay is not set # CONFIG_PACKAGE_fdm is not set # CONFIG_PACKAGE_greyfix is not set # CONFIG_PACKAGE_mailsend is not set # CONFIG_PACKAGE_mailsend-nossl is not set # CONFIG_PACKAGE_msmtp is not set # CONFIG_PACKAGE_msmtp-mta is not set # CONFIG_PACKAGE_msmtp-nossl is not set # CONFIG_PACKAGE_msmtp-queue is not set # CONFIG_PACKAGE_mutt is not set # CONFIG_PACKAGE_nail is not set # CONFIG_PACKAGE_opendkim is not set # CONFIG_PACKAGE_opendkim-tools is not set # CONFIG_PACKAGE_postfix is not set # # Select postfix build options # CONFIG_POSTFIX_TLS=y CONFIG_POSTFIX_SASL=y CONFIG_POSTFIX_LDAP=y # CONFIG_POSTFIX_DB is not set CONFIG_POSTFIX_CDB=y CONFIG_POSTFIX_SQLITE=y # CONFIG_POSTFIX_MYSQL is not set # CONFIG_POSTFIX_PGSQL is not set CONFIG_POSTFIX_PCRE=y # CONFIG_POSTFIX_EAI is not set # end of Select postfix build options # CONFIG_PACKAGE_ssmtp is not set # end of Mail # # Multimedia # # # Streaming # # CONFIG_PACKAGE_oggfwd is not set # end of Streaming # CONFIG_PACKAGE_ffmpeg is not set # CONFIG_PACKAGE_ffprobe is not set # CONFIG_PACKAGE_fswebcam is not set # CONFIG_PACKAGE_gerbera is not set # CONFIG_PACKAGE_gmediarender is not set # CONFIG_PACKAGE_gphoto2 is not set # CONFIG_PACKAGE_graphicsmagick is not set # CONFIG_PACKAGE_grilo is not set # CONFIG_PACKAGE_grilo-plugins is not set # CONFIG_PACKAGE_gst1-libav is not set # CONFIG_PACKAGE_gstreamer1-libs is not set # CONFIG_PACKAGE_gstreamer1-plugins-bad is not set # CONFIG_PACKAGE_gstreamer1-plugins-base is not set # CONFIG_PACKAGE_gstreamer1-plugins-good is not set # CONFIG_PACKAGE_gstreamer1-plugins-ugly is not set # CONFIG_PACKAGE_gstreamer1-utils is not set # CONFIG_PACKAGE_icecast is not set # CONFIG_PACKAGE_imagemagick is not set # CONFIG_PACKAGE_lcdgrilo is not set # CONFIG_PACKAGE_minidlna is not set # CONFIG_PACKAGE_minisatip is not set # CONFIG_PACKAGE_mjpg-streamer is not set # CONFIG_PACKAGE_motion is not set # CONFIG_PACKAGE_tvheadend is not set # CONFIG_PACKAGE_v4l2rtspserver is not set # CONFIG_PACKAGE_vips is not set # CONFIG_PACKAGE_xupnpd is not set # CONFIG_PACKAGE_youtube-dl is not set # end of Multimedia # # Network # # # BitTorrent # # CONFIG_PACKAGE_mktorrent is not set # CONFIG_PACKAGE_opentracker is not set # CONFIG_PACKAGE_opentracker6 is not set # CONFIG_PACKAGE_qBittorrent is not set # CONFIG_PACKAGE_rtorrent is not set # CONFIG_PACKAGE_rtorrent-rpc is not set # CONFIG_PACKAGE_transmission-cli-openssl is not set # CONFIG_PACKAGE_transmission-daemon-openssl is not set # CONFIG_PACKAGE_transmission-remote-openssl is not set # CONFIG_PACKAGE_transmission-web is not set # CONFIG_PACKAGE_transmission-web-control is not set # end of BitTorrent # # Captive Portals # # CONFIG_PACKAGE_apfree-wifidog is not set # CONFIG_PACKAGE_coova-chilli is not set # CONFIG_PACKAGE_nodogsplash is not set # CONFIG_PACKAGE_opennds is not set # CONFIG_PACKAGE_wifidog is not set # CONFIG_PACKAGE_wifidog-tls is not set # end of Captive Portals # # Cloud Manager # # CONFIG_PACKAGE_rclone-ng is not set # CONFIG_PACKAGE_rclone-webui-react is not set # end of Cloud Manager # # Dial-in/up # # CONFIG_PACKAGE_rp-pppoe-common is not set # CONFIG_PACKAGE_rp-pppoe-relay is not set # CONFIG_PACKAGE_rp-pppoe-server is not set # end of Dial-in/up # # Download Manager # # CONFIG_PACKAGE_ariang is not set # CONFIG_PACKAGE_ariang-nginx is not set # CONFIG_PACKAGE_leech is not set # CONFIG_PACKAGE_webui-aria2 is not set # end of Download Manager # # File Transfer # # CONFIG_PACKAGE_aria2 is not set # CONFIG_PACKAGE_atftp is not set # CONFIG_PACKAGE_atftpd is not set CONFIG_PACKAGE_curl=y # CONFIG_PACKAGE_gnurl is not set # CONFIG_PACKAGE_lftp is not set # CONFIG_PACKAGE_ps3netsrv is not set # CONFIG_PACKAGE_rosy-file-server is not set # CONFIG_PACKAGE_rsync is not set # CONFIG_PACKAGE_rsyncd is not set # CONFIG_PACKAGE_vsftpd is not set CONFIG_PACKAGE_vsftpd-alt=y CONFIG_VSFTPD_USE_UCI_SCRIPTS=y # CONFIG_PACKAGE_vsftpd-tls is not set CONFIG_PACKAGE_wget=y # CONFIG_PACKAGE_wget-nossl is not set # end of File Transfer # # Filesystem # # CONFIG_PACKAGE_davfs2 is not set # CONFIG_PACKAGE_ksmbd-avahi-service is not set # CONFIG_PACKAGE_ksmbd-server is not set # CONFIG_PACKAGE_ksmbd-utils is not set # CONFIG_PACKAGE_netatalk is not set # CONFIG_PACKAGE_nfs-kernel-server is not set # CONFIG_PACKAGE_owftpd is not set # CONFIG_PACKAGE_owhttpd is not set # CONFIG_PACKAGE_owserver is not set # CONFIG_PACKAGE_sshfs is not set # end of Filesystem # # Firewall # # CONFIG_PACKAGE_arptables is not set # CONFIG_PACKAGE_conntrack is not set # CONFIG_PACKAGE_conntrackd is not set # CONFIG_PACKAGE_ebtables is not set # CONFIG_PACKAGE_fwknop is not set # CONFIG_PACKAGE_fwknopd is not set # CONFIG_PACKAGE_ip6tables is not set CONFIG_PACKAGE_iptables=y # CONFIG_IPTABLES_CONNLABEL is not set # CONFIG_IPTABLES_NFTABLES is not set # CONFIG_PACKAGE_iptables-mod-account is not set # CONFIG_PACKAGE_iptables-mod-chaos is not set # CONFIG_PACKAGE_iptables-mod-checksum is not set # CONFIG_PACKAGE_iptables-mod-cluster is not set # CONFIG_PACKAGE_iptables-mod-clusterip is not set # CONFIG_PACKAGE_iptables-mod-condition is not set # CONFIG_PACKAGE_iptables-mod-conntrack-extra is not set # CONFIG_PACKAGE_iptables-mod-delude is not set # CONFIG_PACKAGE_iptables-mod-dhcpmac is not set # CONFIG_PACKAGE_iptables-mod-dnetmap is not set CONFIG_PACKAGE_iptables-mod-extra=y # CONFIG_PACKAGE_iptables-mod-filter is not set CONFIG_PACKAGE_iptables-mod-fullconenat=y # CONFIG_PACKAGE_iptables-mod-fuzzy is not set # CONFIG_PACKAGE_iptables-mod-geoip is not set # CONFIG_PACKAGE_iptables-mod-hashlimit is not set # CONFIG_PACKAGE_iptables-mod-iface is not set # CONFIG_PACKAGE_iptables-mod-ipmark is not set # CONFIG_PACKAGE_iptables-mod-ipopt is not set # CONFIG_PACKAGE_iptables-mod-ipp2p is not set # CONFIG_PACKAGE_iptables-mod-iprange is not set # CONFIG_PACKAGE_iptables-mod-ipsec is not set # CONFIG_PACKAGE_iptables-mod-ipv4options is not set # CONFIG_PACKAGE_iptables-mod-led is not set # CONFIG_PACKAGE_iptables-mod-length2 is not set # CONFIG_PACKAGE_iptables-mod-logmark is not set # CONFIG_PACKAGE_iptables-mod-lscan is not set # CONFIG_PACKAGE_iptables-mod-lua is not set # CONFIG_PACKAGE_iptables-mod-nat-extra is not set # CONFIG_PACKAGE_iptables-mod-nflog is not set # CONFIG_PACKAGE_iptables-mod-nfqueue is not set # CONFIG_PACKAGE_iptables-mod-physdev is not set # CONFIG_PACKAGE_iptables-mod-proto is not set # CONFIG_PACKAGE_iptables-mod-psd is not set # CONFIG_PACKAGE_iptables-mod-quota2 is not set # CONFIG_PACKAGE_iptables-mod-rpfilter is not set # CONFIG_PACKAGE_iptables-mod-rtpengine is not set # CONFIG_PACKAGE_iptables-mod-sysrq is not set # CONFIG_PACKAGE_iptables-mod-tarpit is not set # CONFIG_PACKAGE_iptables-mod-tee is not set CONFIG_PACKAGE_iptables-mod-tproxy=y # CONFIG_PACKAGE_iptables-mod-trace is not set # CONFIG_PACKAGE_iptables-mod-u32 is not set # CONFIG_PACKAGE_iptables-mod-ulog is not set # CONFIG_PACKAGE_iptaccount is not set # CONFIG_PACKAGE_iptgeoip is not set # CONFIG_PACKAGE_miniupnpc is not set CONFIG_PACKAGE_miniupnpd=y # CONFIG_MINIUPNPD_IGDv2 is not set # CONFIG_PACKAGE_natpmpc is not set # CONFIG_PACKAGE_nftables-json is not set # CONFIG_PACKAGE_nftables-nojson is not set # CONFIG_PACKAGE_shorewall is not set # CONFIG_PACKAGE_shorewall-core is not set # CONFIG_PACKAGE_shorewall-lite is not set # CONFIG_PACKAGE_shorewall6 is not set # CONFIG_PACKAGE_shorewall6-lite is not set # CONFIG_PACKAGE_snort is not set # CONFIG_PACKAGE_snort3 is not set # end of Firewall # # Firewall Tunnel # # CONFIG_PACKAGE_iodine is not set # CONFIG_PACKAGE_iodined is not set # end of Firewall Tunnel # # FreeRADIUS (version 3) # # CONFIG_PACKAGE_freeradius3 is not set # CONFIG_PACKAGE_freeradius3-common is not set # CONFIG_PACKAGE_freeradius3-utils is not set # end of FreeRADIUS (version 3) # # IP Addresses and Names # # CONFIG_PACKAGE_aggregate is not set # CONFIG_PACKAGE_announce is not set # CONFIG_PACKAGE_avahi-autoipd is not set # CONFIG_PACKAGE_avahi-daemon-service-http is not set # CONFIG_PACKAGE_avahi-daemon-service-ssh is not set # CONFIG_PACKAGE_avahi-dbus-daemon is not set # CONFIG_PACKAGE_avahi-dnsconfd is not set # CONFIG_PACKAGE_avahi-nodbus-daemon is not set # CONFIG_PACKAGE_avahi-utils is not set # CONFIG_PACKAGE_bind-check is not set # CONFIG_PACKAGE_bind-client is not set # CONFIG_PACKAGE_bind-dig is not set # CONFIG_PACKAGE_bind-dnssec is not set # CONFIG_PACKAGE_bind-host is not set # CONFIG_PACKAGE_bind-nslookup is not set # CONFIG_PACKAGE_bind-rndc is not set # CONFIG_PACKAGE_bind-server is not set # CONFIG_PACKAGE_bind-tools is not set CONFIG_PACKAGE_ddns-scripts=y CONFIG_PACKAGE_ddns-scripts_aliyun=y # CONFIG_PACKAGE_ddns-scripts_cloudflare.com-v4 is not set CONFIG_PACKAGE_ddns-scripts_dnspod=y # CONFIG_PACKAGE_ddns-scripts_freedns_42_pl is not set # CONFIG_PACKAGE_ddns-scripts_godaddy.com-v1 is not set # CONFIG_PACKAGE_ddns-scripts_no-ip_com is not set # CONFIG_PACKAGE_ddns-scripts_nsupdate is not set # CONFIG_PACKAGE_ddns-scripts_route53-v1 is not set # CONFIG_PACKAGE_dhcp-forwarder is not set CONFIG_PACKAGE_dns2socks=y # CONFIG_PACKAGE_dnscrypt-proxy is not set # CONFIG_PACKAGE_dnscrypt-proxy-resolvers is not set # CONFIG_PACKAGE_dnsdist is not set # CONFIG_PACKAGE_drill is not set # CONFIG_PACKAGE_hostip is not set # CONFIG_PACKAGE_idn is not set # CONFIG_PACKAGE_idn2 is not set # CONFIG_PACKAGE_inadyn is not set # CONFIG_PACKAGE_isc-dhcp-client-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-client-ipv6 is not set # CONFIG_PACKAGE_isc-dhcp-omshell-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-omshell-ipv6 is not set # CONFIG_PACKAGE_isc-dhcp-relay-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-relay-ipv6 is not set # CONFIG_PACKAGE_isc-dhcp-server-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-server-ipv6 is not set # CONFIG_PACKAGE_kadnode is not set # CONFIG_PACKAGE_kea-admin is not set # CONFIG_PACKAGE_kea-ctrl is not set # CONFIG_PACKAGE_kea-dhcp-ddns is not set # CONFIG_PACKAGE_kea-dhcp4 is not set # CONFIG_PACKAGE_kea-dhcp6 is not set # CONFIG_PACKAGE_kea-lfc is not set # CONFIG_PACKAGE_kea-libs is not set # CONFIG_PACKAGE_kea-perfdhcp is not set # CONFIG_PACKAGE_knot is not set # CONFIG_PACKAGE_knot-dig is not set # CONFIG_PACKAGE_knot-host is not set # CONFIG_PACKAGE_knot-keymgr is not set # CONFIG_PACKAGE_knot-nsupdate is not set # CONFIG_PACKAGE_knot-tests is not set # CONFIG_PACKAGE_knot-zonecheck is not set # CONFIG_PACKAGE_ldns-examples is not set # CONFIG_PACKAGE_mdns-utils is not set # CONFIG_PACKAGE_mdnsd is not set # CONFIG_PACKAGE_mdnsresponder is not set # CONFIG_PACKAGE_nsd is not set # CONFIG_PACKAGE_nsd-control is not set # CONFIG_PACKAGE_nsd-control-setup is not set # CONFIG_PACKAGE_nsd-nossl is not set # CONFIG_PACKAGE_ohybridproxy is not set # CONFIG_PACKAGE_overture is not set # CONFIG_PACKAGE_pdns is not set # CONFIG_PACKAGE_pdns-ixfrdist is not set # CONFIG_PACKAGE_pdns-recursor is not set # CONFIG_PACKAGE_pdns-tools is not set # CONFIG_PACKAGE_stubby is not set # CONFIG_PACKAGE_tor-hs is not set # CONFIG_PACKAGE_torsocks is not set # CONFIG_PACKAGE_unbound-anchor is not set # CONFIG_PACKAGE_unbound-checkconf is not set # CONFIG_PACKAGE_unbound-control is not set # CONFIG_PACKAGE_unbound-control-setup is not set # CONFIG_PACKAGE_unbound-daemon is not set # CONFIG_PACKAGE_unbound-host is not set # CONFIG_PACKAGE_wsdd2 is not set # CONFIG_PACKAGE_zonestitcher is not set # end of IP Addresses and Names # # Instant Messaging # # CONFIG_PACKAGE_bitlbee is not set # CONFIG_PACKAGE_irssi is not set # CONFIG_PACKAGE_ngircd is not set # CONFIG_PACKAGE_ngircd-nossl is not set # CONFIG_PACKAGE_prosody is not set # CONFIG_PACKAGE_quassel-irssi is not set # CONFIG_PACKAGE_umurmur-mbedtls is not set # CONFIG_PACKAGE_umurmur-openssl is not set # CONFIG_PACKAGE_znc is not set # end of Instant Messaging # # Linux ATM tools # # CONFIG_PACKAGE_atm-aread is not set # CONFIG_PACKAGE_atm-atmaddr is not set # CONFIG_PACKAGE_atm-atmdiag is not set # CONFIG_PACKAGE_atm-atmdump is not set # CONFIG_PACKAGE_atm-atmloop is not set # CONFIG_PACKAGE_atm-atmsigd is not set # CONFIG_PACKAGE_atm-atmswitch is not set # CONFIG_PACKAGE_atm-atmtcp is not set # CONFIG_PACKAGE_atm-awrite is not set # CONFIG_PACKAGE_atm-bus is not set # CONFIG_PACKAGE_atm-debug-tools is not set # CONFIG_PACKAGE_atm-diagnostics is not set # CONFIG_PACKAGE_atm-esi is not set # CONFIG_PACKAGE_atm-ilmid is not set # CONFIG_PACKAGE_atm-ilmidiag is not set # CONFIG_PACKAGE_atm-lecs is not set # CONFIG_PACKAGE_atm-les is not set # CONFIG_PACKAGE_atm-mpcd is not set # CONFIG_PACKAGE_atm-saaldump is not set # CONFIG_PACKAGE_atm-sonetdiag is not set # CONFIG_PACKAGE_atm-svc_recv is not set # CONFIG_PACKAGE_atm-svc_send is not set # CONFIG_PACKAGE_atm-tools is not set # CONFIG_PACKAGE_atm-ttcp_atm is not set # CONFIG_PACKAGE_atm-zeppelin is not set # CONFIG_PACKAGE_br2684ctl is not set # end of Linux ATM tools # # LoRaWAN # # CONFIG_PACKAGE_libloragw-tests is not set # CONFIG_PACKAGE_libloragw-utils is not set # end of LoRaWAN # # NMAP Suite # # CONFIG_PACKAGE_ncat is not set # CONFIG_PACKAGE_ncat-full is not set # CONFIG_PACKAGE_ncat-ssl is not set # CONFIG_PACKAGE_ndiff is not set # CONFIG_PACKAGE_nmap is not set # CONFIG_PACKAGE_nmap-full is not set # CONFIG_PACKAGE_nmap-ssl is not set # CONFIG_PACKAGE_nping is not set # CONFIG_PACKAGE_nping-ssl is not set # end of NMAP Suite # # NTRIP # # CONFIG_PACKAGE_ntripcaster is not set # CONFIG_PACKAGE_ntripclient is not set # CONFIG_PACKAGE_ntripserver is not set # end of NTRIP # # NeteaseMusic # # CONFIG_PACKAGE_UnblockNeteaseMusic is not set # CONFIG_PACKAGE_UnblockNeteaseMusicGo is not set CONFIG_UnblockNeteaseMusicGo_INCLUDE_GOPROXY=y # end of NeteaseMusic # # OLSR.org network framework # # CONFIG_PACKAGE_oonf-dlep-proxy is not set # CONFIG_PACKAGE_oonf-dlep-radio is not set # CONFIG_PACKAGE_oonf-init-scripts is not set # CONFIG_PACKAGE_oonf-olsrd2 is not set # end of OLSR.org network framework # # Open vSwitch # # CONFIG_PACKAGE_openvswitch is not set # CONFIG_PACKAGE_openvswitch-ovn-host is not set # CONFIG_PACKAGE_openvswitch-ovn-north is not set # CONFIG_PACKAGE_openvswitch-python3 is not set # end of Open vSwitch # # OpenLDAP # # CONFIG_PACKAGE_libopenldap is not set CONFIG_OPENLDAP_DEBUG=y # CONFIG_OPENLDAP_CRYPT is not set # CONFIG_OPENLDAP_MONITOR is not set # CONFIG_OPENLDAP_DB47 is not set # CONFIG_OPENLDAP_ICU is not set # CONFIG_PACKAGE_openldap-server is not set # CONFIG_PACKAGE_openldap-utils is not set # end of OpenLDAP # # P2P # # CONFIG_PACKAGE_amule is not set # CONFIG_AMULE_CRYPTOPP_STATIC_LINKING is not set # CONFIG_PACKAGE_antileech is not set # end of P2P # # Printing # # CONFIG_PACKAGE_p910nd is not set # end of Printing # # Project V # # CONFIG_PACKAGE_v2ray is not set # CONFIG_PACKAGE_v2ray-plugin is not set CONFIG_v2ray-plugin_INCLUDE_GOPROXY=y # end of Project V # # Project X # CONFIG_PACKAGE_xray=y # # Xray Configuration # # CONFIG_XRAY_COMPRESS_GOPROXY is not set CONFIG_XRAY_EXCLUDE_ASSETS=y CONFIG_XRAY_COMPRESS_UPX=y # CONFIG_XRAY_COMPATIBILITY_MODE is not set # end of Xray Configuration # end of Project X # # Routing and Redirection # # CONFIG_PACKAGE_babel-pinger is not set # CONFIG_PACKAGE_babeld is not set # CONFIG_PACKAGE_batmand is not set # CONFIG_PACKAGE_bcp38 is not set # CONFIG_PACKAGE_bfdd is not set # CONFIG_PACKAGE_bird1-ipv4 is not set # CONFIG_PACKAGE_bird1-ipv4-uci is not set # CONFIG_PACKAGE_bird1-ipv6 is not set # CONFIG_PACKAGE_bird1-ipv6-uci is not set # CONFIG_PACKAGE_bird1c-ipv4 is not set # CONFIG_PACKAGE_bird1c-ipv6 is not set # CONFIG_PACKAGE_bird1cl-ipv4 is not set # CONFIG_PACKAGE_bird1cl-ipv6 is not set # CONFIG_PACKAGE_bird2 is not set # CONFIG_PACKAGE_bird2c is not set # CONFIG_PACKAGE_bird2cl is not set # CONFIG_PACKAGE_bmx6 is not set # CONFIG_PACKAGE_bmx7 is not set # CONFIG_PACKAGE_cjdns is not set # CONFIG_PACKAGE_cjdns-tests is not set # CONFIG_PACKAGE_dcstad is not set # CONFIG_PACKAGE_dcwapd is not set # CONFIG_PACKAGE_devlink is not set # CONFIG_PACKAGE_frr is not set # CONFIG_PACKAGE_genl is not set # CONFIG_PACKAGE_igmpproxy is not set # CONFIG_PACKAGE_ip-bridge is not set CONFIG_PACKAGE_ip-full=y # CONFIG_PACKAGE_ip-tiny is not set # CONFIG_PACKAGE_lldpd is not set # CONFIG_PACKAGE_mcproxy is not set # CONFIG_PACKAGE_mrmctl is not set # CONFIG_PACKAGE_mwan3 is not set # CONFIG_PACKAGE_nstat is not set # CONFIG_PACKAGE_olsrd is not set # CONFIG_PACKAGE_prince is not set # CONFIG_PACKAGE_quagga is not set # CONFIG_PACKAGE_rdma is not set # CONFIG_PACKAGE_relayd is not set # CONFIG_PACKAGE_smcroute is not set # CONFIG_PACKAGE_ss is not set # CONFIG_PACKAGE_sslh is not set # CONFIG_PACKAGE_tc is not set # CONFIG_PACKAGE_tcpproxy is not set # CONFIG_PACKAGE_vis is not set # CONFIG_PACKAGE_yggdrasil is not set # end of Routing and Redirection # # SSH # # CONFIG_PACKAGE_autossh is not set # CONFIG_PACKAGE_openssh-client is not set # CONFIG_PACKAGE_openssh-client-utils is not set # CONFIG_PACKAGE_openssh-keygen is not set # CONFIG_PACKAGE_openssh-moduli is not set # CONFIG_PACKAGE_openssh-server is not set # CONFIG_PACKAGE_openssh-server-pam is not set # CONFIG_PACKAGE_openssh-sftp-avahi-service is not set # CONFIG_PACKAGE_openssh-sftp-client is not set # CONFIG_PACKAGE_openssh-sftp-server is not set # CONFIG_PACKAGE_sshtunnel is not set # end of SSH # # THC-IPv6 attack and analyzing toolkit # # CONFIG_PACKAGE_thc-ipv6-address6 is not set # CONFIG_PACKAGE_thc-ipv6-alive6 is not set # CONFIG_PACKAGE_thc-ipv6-covert-send6 is not set # CONFIG_PACKAGE_thc-ipv6-covert-send6d is not set # CONFIG_PACKAGE_thc-ipv6-denial6 is not set # CONFIG_PACKAGE_thc-ipv6-detect-new-ip6 is not set # CONFIG_PACKAGE_thc-ipv6-detect-sniffer6 is not set # CONFIG_PACKAGE_thc-ipv6-dnsdict6 is not set # CONFIG_PACKAGE_thc-ipv6-dnsrevenum6 is not set # CONFIG_PACKAGE_thc-ipv6-dos-new-ip6 is not set # CONFIG_PACKAGE_thc-ipv6-dump-router6 is not set # CONFIG_PACKAGE_thc-ipv6-exploit6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-advertise6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-dhcps6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-dns6d is not set # CONFIG_PACKAGE_thc-ipv6-fake-dnsupdate6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mipv6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mld26 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mld6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mldrouter6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-router26 is not set # CONFIG_PACKAGE_thc-ipv6-fake-router6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-solicitate6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-advertise6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-dhcpc6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-mld26 is not set # CONFIG_PACKAGE_thc-ipv6-flood-mld6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-mldrouter6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-router26 is not set # CONFIG_PACKAGE_thc-ipv6-flood-router6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-solicitate6 is not set # CONFIG_PACKAGE_thc-ipv6-fragmentation6 is not set # CONFIG_PACKAGE_thc-ipv6-fuzz-dhcpc6 is not set # CONFIG_PACKAGE_thc-ipv6-fuzz-dhcps6 is not set # CONFIG_PACKAGE_thc-ipv6-fuzz-ip6 is not set # CONFIG_PACKAGE_thc-ipv6-implementation6 is not set # CONFIG_PACKAGE_thc-ipv6-implementation6d is not set # CONFIG_PACKAGE_thc-ipv6-inverse-lookup6 is not set # CONFIG_PACKAGE_thc-ipv6-kill-router6 is not set # CONFIG_PACKAGE_thc-ipv6-ndpexhaust6 is not set # CONFIG_PACKAGE_thc-ipv6-node-query6 is not set # CONFIG_PACKAGE_thc-ipv6-parasite6 is not set # CONFIG_PACKAGE_thc-ipv6-passive-discovery6 is not set # CONFIG_PACKAGE_thc-ipv6-randicmp6 is not set # CONFIG_PACKAGE_thc-ipv6-redir6 is not set # CONFIG_PACKAGE_thc-ipv6-rsmurf6 is not set # CONFIG_PACKAGE_thc-ipv6-sendpees6 is not set # CONFIG_PACKAGE_thc-ipv6-sendpeesmp6 is not set # CONFIG_PACKAGE_thc-ipv6-smurf6 is not set # CONFIG_PACKAGE_thc-ipv6-thcping6 is not set # CONFIG_PACKAGE_thc-ipv6-toobig6 is not set # CONFIG_PACKAGE_thc-ipv6-trace6 is not set # end of THC-IPv6 attack and analyzing toolkit # # Tcpreplay # # CONFIG_PACKAGE_tcpbridge is not set # CONFIG_PACKAGE_tcpcapinfo is not set # CONFIG_PACKAGE_tcpliveplay is not set # CONFIG_PACKAGE_tcpprep is not set # CONFIG_PACKAGE_tcpreplay is not set # CONFIG_PACKAGE_tcpreplay-all is not set # CONFIG_PACKAGE_tcpreplay-edit is not set # CONFIG_PACKAGE_tcprewrite is not set # end of Tcpreplay # # Telephony # # CONFIG_PACKAGE_asterisk is not set # CONFIG_PACKAGE_baresip is not set # CONFIG_PACKAGE_freeswitch is not set # CONFIG_PACKAGE_kamailio is not set # CONFIG_PACKAGE_miax is not set # CONFIG_PACKAGE_pcapsipdump is not set # CONFIG_PACKAGE_restund is not set # CONFIG_PACKAGE_rtpengine is not set # CONFIG_PACKAGE_rtpengine-no-transcode is not set # CONFIG_PACKAGE_rtpengine-recording is not set # CONFIG_PACKAGE_rtpproxy is not set # CONFIG_PACKAGE_sipp is not set # CONFIG_PACKAGE_siproxd is not set # CONFIG_PACKAGE_yate is not set # end of Telephony # # Telephony Lantiq # # end of Telephony Lantiq # # Time Synchronization # # CONFIG_PACKAGE_chrony is not set # CONFIG_PACKAGE_htpdate is not set # CONFIG_PACKAGE_linuxptp is not set # CONFIG_PACKAGE_ntp-keygen is not set # CONFIG_PACKAGE_ntp-utils is not set # CONFIG_PACKAGE_ntpclient is not set # CONFIG_PACKAGE_ntpd is not set # CONFIG_PACKAGE_ntpdate is not set # end of Time Synchronization # # VPN # # CONFIG_PACKAGE_chaosvpn is not set # CONFIG_PACKAGE_fastd is not set # CONFIG_PACKAGE_libreswan is not set # CONFIG_PACKAGE_n2n-edge is not set # CONFIG_PACKAGE_n2n-supernode is not set # CONFIG_PACKAGE_ocserv is not set # CONFIG_PACKAGE_openconnect is not set # CONFIG_PACKAGE_openfortivpn is not set # CONFIG_PACKAGE_openvpn-easy-rsa is not set # CONFIG_PACKAGE_openvpn-mbedtls is not set # CONFIG_PACKAGE_openvpn-nossl is not set # CONFIG_PACKAGE_openvpn-openssl is not set # CONFIG_PACKAGE_pptpd is not set # CONFIG_PACKAGE_softethervpn-base is not set # CONFIG_PACKAGE_softethervpn-bridge is not set # CONFIG_PACKAGE_softethervpn-client is not set # CONFIG_PACKAGE_softethervpn-server is not set # CONFIG_PACKAGE_softethervpn5-bridge is not set # CONFIG_PACKAGE_softethervpn5-client is not set # CONFIG_PACKAGE_softethervpn5-server is not set # CONFIG_PACKAGE_sstp-client is not set # CONFIG_PACKAGE_strongswan is not set # CONFIG_PACKAGE_tinc is not set # CONFIG_PACKAGE_uanytun is not set # CONFIG_PACKAGE_uanytun-nettle is not set # CONFIG_PACKAGE_uanytun-nocrypt is not set # CONFIG_PACKAGE_uanytun-sslcrypt is not set # CONFIG_PACKAGE_vpnc is not set # CONFIG_PACKAGE_vpnc-scripts is not set # CONFIG_PACKAGE_wireguard is not set # CONFIG_PACKAGE_xl2tpd is not set CONFIG_PACKAGE_zerotier=y # # Configuration # # CONFIG_ZEROTIER_ENABLE_DEBUG is not set # CONFIG_ZEROTIER_ENABLE_SELFTEST is not set # end of Configuration # end of VPN # # Version Control Systems # # CONFIG_PACKAGE_git is not set # CONFIG_PACKAGE_git-http is not set # CONFIG_PACKAGE_subversion-client is not set # CONFIG_PACKAGE_subversion-libs is not set # CONFIG_PACKAGE_subversion-server is not set # end of Version Control Systems # # WWAN # # CONFIG_PACKAGE_adb-enablemodem is not set # CONFIG_PACKAGE_comgt is not set # CONFIG_PACKAGE_comgt-directip is not set # CONFIG_PACKAGE_umbim is not set # CONFIG_PACKAGE_uqmi is not set # end of WWAN # # Web Servers/Proxies # # CONFIG_PACKAGE_apache is not set # CONFIG_PACKAGE_cgi-io is not set # CONFIG_PACKAGE_clamav is not set # CONFIG_PACKAGE_e2guardian is not set # CONFIG_PACKAGE_etesync-server is not set # CONFIG_PACKAGE_freshclam is not set # CONFIG_PACKAGE_frpc is not set # CONFIG_PACKAGE_frps is not set CONFIG_PACKAGE_haproxy=y # CONFIG_PACKAGE_halog is not set # CONFIG_PACKAGE_haproxy-nossl is not set # CONFIG_PACKAGE_kcptun-client is not set # CONFIG_PACKAGE_kcptun-server is not set # CONFIG_PACKAGE_lighttpd is not set # CONFIG_PACKAGE_naiveproxy is not set # CONFIG_PACKAGE_nginx is not set CONFIG_NGINX_NOPCRE=y # CONFIG_PACKAGE_nginx-all-module is not set # CONFIG_PACKAGE_nginx-mod-luci is not set # CONFIG_PACKAGE_nginx-mod-luci-ssl is not set # CONFIG_PACKAGE_nginx-ssl is not set # CONFIG_PACKAGE_nginx-ssl-util is not set # CONFIG_PACKAGE_nginx-ssl-util-nopcre is not set # CONFIG_PACKAGE_nginx-util is not set CONFIG_PACKAGE_pdnsd-alt=y # CONFIG_PACKAGE_polipo is not set # CONFIG_PACKAGE_privoxy is not set # CONFIG_PACKAGE_radicale is not set # CONFIG_PACKAGE_radicale2 is not set # CONFIG_PACKAGE_radicale2-examples is not set # CONFIG_PACKAGE_redsocks2 is not set # CONFIG_PACKAGE_shadowsocks-libev-config is not set CONFIG_PACKAGE_shadowsocks-libev-ss-local=y CONFIG_PACKAGE_shadowsocks-libev-ss-redir=y # CONFIG_PACKAGE_shadowsocks-libev-ss-rules is not set # CONFIG_PACKAGE_shadowsocks-libev-ss-server is not set # CONFIG_PACKAGE_shadowsocks-libev-ss-tunnel is not set # CONFIG_PACKAGE_sockd is not set # CONFIG_PACKAGE_socksify is not set # CONFIG_PACKAGE_spawn-fcgi is not set # CONFIG_PACKAGE_squid is not set # CONFIG_PACKAGE_srelay is not set # CONFIG_PACKAGE_tinyproxy is not set # CONFIG_PACKAGE_trojan-go is not set CONFIG_PACKAGE_uhttpd=y # CONFIG_PACKAGE_uhttpd-mod-lua is not set CONFIG_PACKAGE_uhttpd-mod-ubus=y # CONFIG_PACKAGE_uwsgi is not set # end of Web Servers/Proxies # # Wireless # # CONFIG_PACKAGE_aircrack-ng is not set # CONFIG_PACKAGE_airmon-ng is not set # CONFIG_PACKAGE_dynapoint is not set # CONFIG_PACKAGE_hcxdumptool is not set # CONFIG_PACKAGE_hcxtools is not set # CONFIG_PACKAGE_horst is not set # CONFIG_PACKAGE_kismet-client is not set # CONFIG_PACKAGE_kismet-drone is not set # CONFIG_PACKAGE_kismet-server is not set # CONFIG_PACKAGE_mt_wifi is not set # CONFIG_PACKAGE_pixiewps is not set # CONFIG_PACKAGE_reaver is not set # CONFIG_PACKAGE_wavemon is not set CONFIG_PACKAGE_wifischedule=y # end of Wireless # # WirelessAPD # # CONFIG_PACKAGE_eapol-test is not set # CONFIG_PACKAGE_eapol-test-openssl is not set # CONFIG_PACKAGE_eapol-test-wolfssl is not set CONFIG_PACKAGE_hostapd=y # CONFIG_PACKAGE_hostapd-basic is not set # CONFIG_PACKAGE_hostapd-basic-openssl is not set # CONFIG_PACKAGE_hostapd-basic-wolfssl is not set CONFIG_PACKAGE_hostapd-common=y # CONFIG_PACKAGE_hostapd-mini is not set # CONFIG_PACKAGE_hostapd-openssl is not set # CONFIG_PACKAGE_hostapd-utils is not set # CONFIG_PACKAGE_hostapd-wolfssl is not set # CONFIG_PACKAGE_wpa-cli is not set CONFIG_PACKAGE_wpa-supplicant=y # CONFIG_WPA_RFKILL_SUPPORT is not set CONFIG_WPA_MSG_MIN_PRIORITY=3 # CONFIG_WPA_WOLFSSL is not set # CONFIG_DRIVER_WEXT_SUPPORT is not set CONFIG_DRIVER_11N_SUPPORT=y CONFIG_DRIVER_11AC_SUPPORT=y # CONFIG_DRIVER_11AX_SUPPORT is not set # CONFIG_DRIVER_11W_SUPPORT is not set # CONFIG_WPA_ENABLE_WEP is not set # CONFIG_PACKAGE_wpa-supplicant-basic is not set # CONFIG_PACKAGE_wpa-supplicant-mesh-openssl is not set # CONFIG_PACKAGE_wpa-supplicant-mesh-wolfssl is not set # CONFIG_PACKAGE_wpa-supplicant-mini is not set # CONFIG_PACKAGE_wpa-supplicant-openssl is not set # CONFIG_PACKAGE_wpa-supplicant-p2p is not set # CONFIG_PACKAGE_wpa-supplicant-wolfssl is not set # CONFIG_PACKAGE_wpad is not set # CONFIG_PACKAGE_wpad-basic is not set # CONFIG_PACKAGE_wpad-basic-openssl is not set # CONFIG_PACKAGE_wpad-basic-wolfssl is not set # CONFIG_PACKAGE_wpad-mesh-openssl is not set # CONFIG_PACKAGE_wpad-mesh-wolfssl is not set # CONFIG_PACKAGE_wpad-mini is not set # CONFIG_PACKAGE_wpad-openssl is not set # CONFIG_PACKAGE_wpad-wolfssl is not set # end of WirelessAPD # # arp-scan # # CONFIG_PACKAGE_arp-scan is not set # CONFIG_PACKAGE_arp-scan-database is not set # end of arp-scan # CONFIG_PACKAGE_464xlat is not set # CONFIG_PACKAGE_6in4 is not set # CONFIG_PACKAGE_6rd is not set # CONFIG_PACKAGE_6to4 is not set # CONFIG_PACKAGE_acme is not set # CONFIG_PACKAGE_acme-dnsapi is not set # CONFIG_PACKAGE_adblock is not set CONFIG_PACKAGE_adbyby=y # CONFIG_PACKAGE_addrwatch is not set # CONFIG_PACKAGE_ahcpd is not set # CONFIG_PACKAGE_alfred is not set # CONFIG_PACKAGE_apcupsd is not set # CONFIG_PACKAGE_apcupsd-cgi is not set # CONFIG_PACKAGE_apinger is not set # CONFIG_PACKAGE_baidupcs-web is not set # CONFIG_PACKAGE_banip is not set # CONFIG_PACKAGE_batctl-default is not set # CONFIG_PACKAGE_batctl-full is not set # CONFIG_PACKAGE_batctl-tiny is not set # CONFIG_PACKAGE_beanstalkd is not set # CONFIG_PACKAGE_bmon is not set # CONFIG_PACKAGE_boinc is not set # CONFIG_PACKAGE_brook is not set # CONFIG_PACKAGE_bwm-ng is not set # CONFIG_PACKAGE_bwping is not set # CONFIG_PACKAGE_chat is not set # CONFIG_PACKAGE_chinadns-ng is not set # CONFIG_PACKAGE_cifsmount is not set # CONFIG_PACKAGE_coap-server is not set # CONFIG_PACKAGE_conserver is not set # CONFIG_PACKAGE_cshark is not set # CONFIG_PACKAGE_daemonlogger is not set # CONFIG_PACKAGE_darkstat is not set # CONFIG_PACKAGE_dawn is not set # CONFIG_PACKAGE_dhcpcd is not set # CONFIG_PACKAGE_dmapd is not set # CONFIG_PACKAGE_dnscrypt-proxy2 is not set # CONFIG_PACKAGE_dnsforwarder is not set # CONFIG_PACKAGE_dnstop is not set # CONFIG_PACKAGE_ds-lite is not set # CONFIG_PACKAGE_dsmboot is not set # CONFIG_PACKAGE_esniper is not set # CONFIG_PACKAGE_etherwake is not set # CONFIG_PACKAGE_etherwake-nfqueue is not set # CONFIG_PACKAGE_ethtool is not set # CONFIG_PACKAGE_fakeidentd is not set # CONFIG_PACKAGE_family-dns is not set # CONFIG_PACKAGE_foolsm is not set # CONFIG_PACKAGE_fping is not set # CONFIG_PACKAGE_geth is not set # CONFIG_PACKAGE_gnunet is not set # CONFIG_PACKAGE_gre is not set # CONFIG_PACKAGE_hnet-full is not set # CONFIG_PACKAGE_hnet-full-l2tp is not set # CONFIG_PACKAGE_hnet-full-secure is not set # CONFIG_PACKAGE_hnetd-nossl is not set # CONFIG_PACKAGE_hnetd-openssl is not set # CONFIG_PACKAGE_httping is not set # CONFIG_PACKAGE_httping-nossl is not set # CONFIG_PACKAGE_https-dns-proxy is not set # CONFIG_PACKAGE_i2pd is not set # CONFIG_PACKAGE_ibrdtn-tools is not set # CONFIG_PACKAGE_ibrdtnd is not set # CONFIG_PACKAGE_ifstat is not set # CONFIG_PACKAGE_iftop is not set # CONFIG_PACKAGE_iiod is not set # CONFIG_PACKAGE_iperf is not set # CONFIG_PACKAGE_iperf3 is not set # CONFIG_PACKAGE_iperf3-ssl is not set # CONFIG_PACKAGE_ipip is not set CONFIG_PACKAGE_ipset=y # CONFIG_PACKAGE_ipset-dns is not set CONFIG_PACKAGE_ipt2socks=y # CONFIG_PACKAGE_iptraf-ng is not set # CONFIG_PACKAGE_iputils-arping is not set # CONFIG_PACKAGE_iputils-clockdiff is not set # CONFIG_PACKAGE_iputils-ping is not set # CONFIG_PACKAGE_iputils-ping6 is not set # CONFIG_PACKAGE_iputils-tftpd is not set # CONFIG_PACKAGE_iputils-tracepath is not set # CONFIG_PACKAGE_iputils-tracepath6 is not set # CONFIG_PACKAGE_iputils-traceroute6 is not set # CONFIG_PACKAGE_ipvsadm is not set CONFIG_PACKAGE_iw=y # CONFIG_PACKAGE_iw-full is not set # CONFIG_PACKAGE_jool is not set # CONFIG_PACKAGE_jool-tools is not set # CONFIG_PACKAGE_keepalived is not set # CONFIG_PACKAGE_knxd is not set # CONFIG_PACKAGE_kplex is not set # CONFIG_PACKAGE_krb5-client is not set # CONFIG_PACKAGE_krb5-libs is not set # CONFIG_PACKAGE_krb5-server is not set # CONFIG_PACKAGE_krb5-server-extras is not set CONFIG_PACKAGE_libipset=y # CONFIG_PACKAGE_libndp is not set # CONFIG_PACKAGE_linknx is not set # CONFIG_PACKAGE_lynx is not set # CONFIG_PACKAGE_mac-telnet-client is not set # CONFIG_PACKAGE_mac-telnet-discover is not set # CONFIG_PACKAGE_mac-telnet-ping is not set # CONFIG_PACKAGE_mac-telnet-server is not set # CONFIG_PACKAGE_map is not set # CONFIG_PACKAGE_memcached is not set CONFIG_PACKAGE_microsocks=y # CONFIG_PACKAGE_mii-tool is not set # CONFIG_PACKAGE_mikrotik-btest is not set # CONFIG_PACKAGE_mini_snmpd is not set # CONFIG_PACKAGE_minimalist-pcproxy is not set # CONFIG_PACKAGE_miredo is not set # CONFIG_PACKAGE_modemmanager is not set # CONFIG_PACKAGE_mosquitto-client-nossl is not set # CONFIG_PACKAGE_mosquitto-client-ssl is not set # CONFIG_PACKAGE_mosquitto-nossl is not set # CONFIG_PACKAGE_mosquitto-ssl is not set # CONFIG_PACKAGE_mrd6 is not set # CONFIG_PACKAGE_mstpd is not set # CONFIG_PACKAGE_mtr is not set # CONFIG_PACKAGE_nbd is not set # CONFIG_PACKAGE_nbd-server is not set # CONFIG_PACKAGE_ncp is not set # CONFIG_PACKAGE_ndppd is not set # CONFIG_PACKAGE_ndptool is not set # CONFIG_PACKAGE_net-tools-route is not set # CONFIG_PACKAGE_netcat is not set # CONFIG_PACKAGE_netdiscover is not set # CONFIG_PACKAGE_netifyd is not set # CONFIG_PACKAGE_netperf is not set # CONFIG_PACKAGE_netsniff-ng is not set # CONFIG_PACKAGE_nextdns is not set # CONFIG_PACKAGE_nfdump is not set # CONFIG_PACKAGE_nlbwmon is not set # CONFIG_PACKAGE_noddos is not set # CONFIG_PACKAGE_noping is not set # CONFIG_PACKAGE_npc is not set # CONFIG_PACKAGE_nut is not set # CONFIG_PACKAGE_obfs4proxy is not set # CONFIG_PACKAGE_odhcp6c is not set # CONFIG_PACKAGE_odhcpd is not set # CONFIG_PACKAGE_odhcpd-ipv6only is not set # CONFIG_PACKAGE_ola is not set # CONFIG_PACKAGE_omcproxy is not set # CONFIG_PACKAGE_oor is not set # CONFIG_PACKAGE_oping is not set # CONFIG_PACKAGE_ostiary is not set # CONFIG_PACKAGE_pagekitec is not set # CONFIG_PACKAGE_pen is not set # CONFIG_PACKAGE_phantap is not set # CONFIG_PACKAGE_pimbd is not set # CONFIG_PACKAGE_pingcheck is not set # CONFIG_PACKAGE_port-mirroring is not set CONFIG_PACKAGE_ppp=y # CONFIG_PACKAGE_ppp-mod-passwordfd is not set # CONFIG_PACKAGE_ppp-mod-pppoa is not set CONFIG_PACKAGE_ppp-mod-pppoe=y # CONFIG_PACKAGE_ppp-mod-pppol2tp is not set # CONFIG_PACKAGE_ppp-mod-pptp is not set # CONFIG_PACKAGE_ppp-mod-radius is not set # CONFIG_PACKAGE_ppp-multilink is not set # CONFIG_PACKAGE_pppdump is not set # CONFIG_PACKAGE_pppoe-discovery is not set # CONFIG_PACKAGE_pppossh is not set # CONFIG_PACKAGE_pppstats is not set # CONFIG_PACKAGE_proto-bonding is not set # CONFIG_PACKAGE_proxychains-ng is not set # CONFIG_PACKAGE_ptunnel-ng is not set # CONFIG_PACKAGE_radsecproxy is not set # CONFIG_PACKAGE_ratechecker is not set # CONFIG_PACKAGE_redsocks is not set # CONFIG_PACKAGE_remserial is not set # CONFIG_PACKAGE_restic-rest-server is not set # CONFIG_PACKAGE_rpcbind is not set # CONFIG_PACKAGE_rssileds is not set # CONFIG_PACKAGE_rsyslog is not set # CONFIG_PACKAGE_safe-search is not set # CONFIG_PACKAGE_samba36-client is not set # CONFIG_PACKAGE_samba36-net is not set CONFIG_PACKAGE_samba36-server=y CONFIG_PACKAGE_SAMBA_MAX_DEBUG_LEVEL=-1 # CONFIG_PACKAGE_samba4-admin is not set # CONFIG_PACKAGE_samba4-client is not set # CONFIG_PACKAGE_samba4-libs is not set # CONFIG_PACKAGE_samba4-server is not set # CONFIG_PACKAGE_samba4-utils is not set # CONFIG_PACKAGE_scapy is not set # CONFIG_PACKAGE_sctp is not set # CONFIG_PACKAGE_sctp-tools is not set # CONFIG_PACKAGE_seafile-ccnet is not set # CONFIG_PACKAGE_seafile-seahub is not set # CONFIG_PACKAGE_seafile-server is not set # CONFIG_PACKAGE_seafile-server-fuse is not set # CONFIG_PACKAGE_ser2net is not set # CONFIG_PACKAGE_shadowsocksr-libev is not set CONFIG_PACKAGE_shadowsocksr-libev-alt=y # CONFIG_PACKAGE_shadowsocksr-libev-server is not set CONFIG_PACKAGE_shadowsocksr-libev-ssr-local=y # CONFIG_PACKAGE_simple-adblock is not set CONFIG_PACKAGE_simple-obfs=y # CONFIG_PACKAGE_simple-obfs-server is not set # # Simple-obfs Compile Configuration # # CONFIG_SIMPLE_OBFS_STATIC_LINK is not set # end of Simple-obfs Compile Configuration CONFIG_PACKAGE_smartdns=y # CONFIG_PACKAGE_smartsnmpd is not set # CONFIG_PACKAGE_smbinfo is not set # CONFIG_PACKAGE_snmp-mibs is not set # CONFIG_PACKAGE_snmp-utils is not set # CONFIG_PACKAGE_snmpd is not set # CONFIG_PACKAGE_snmpd-static is not set # CONFIG_PACKAGE_snmptrapd is not set # CONFIG_PACKAGE_socat is not set # CONFIG_PACKAGE_softflowd is not set # CONFIG_PACKAGE_soloscli is not set # CONFIG_PACKAGE_speedtest-netperf is not set # CONFIG_PACKAGE_spoofer is not set CONFIG_PACKAGE_ssocks=y # CONFIG_PACKAGE_ssocksd is not set # CONFIG_PACKAGE_stunnel is not set # CONFIG_PACKAGE_switchdev-poller is not set # CONFIG_PACKAGE_tac_plus is not set # CONFIG_PACKAGE_tac_plus-pam is not set # CONFIG_PACKAGE_tayga is not set # CONFIG_PACKAGE_tcpdump is not set # CONFIG_PACKAGE_tcpdump-mini is not set CONFIG_PACKAGE_tcping=y # CONFIG_PACKAGE_tcpping is not set # CONFIG_PACKAGE_tgt is not set # CONFIG_PACKAGE_tor is not set # CONFIG_PACKAGE_tor-fw-helper is not set # CONFIG_PACKAGE_tor-gencert is not set # CONFIG_PACKAGE_tor-geoip is not set # CONFIG_PACKAGE_tor-resolve is not set # CONFIG_PACKAGE_trafficshaper is not set CONFIG_PACKAGE_travelmate=y # CONFIG_PACKAGE_trojan is not set # CONFIG_PACKAGE_trojan-plus is not set # CONFIG_PACKAGE_u2pnpd is not set # CONFIG_PACKAGE_uacme is not set CONFIG_PACKAGE_uclient-fetch=y # CONFIG_PACKAGE_udptunnel is not set # CONFIG_PACKAGE_udpxy is not set # CONFIG_PACKAGE_ulogd is not set # CONFIG_PACKAGE_umdns is not set # CONFIG_PACKAGE_usbip is not set # CONFIG_PACKAGE_uugamebooster is not set # CONFIG_PACKAGE_vallumd is not set # CONFIG_PACKAGE_verysync is not set CONFIG_PACKAGE_vlmcsd=y # CONFIG_PACKAGE_vncrepeater is not set # CONFIG_PACKAGE_vnstat is not set # CONFIG_PACKAGE_vnstat2 is not set # CONFIG_PACKAGE_vpn-policy-routing is not set # CONFIG_PACKAGE_vpnbypass is not set # CONFIG_PACKAGE_vti is not set # CONFIG_PACKAGE_vxlan is not set # CONFIG_PACKAGE_wakeonlan is not set # CONFIG_PACKAGE_wol is not set # CONFIG_PACKAGE_wpan-tools is not set # CONFIG_PACKAGE_wwan is not set # CONFIG_PACKAGE_xinetd is not set # end of Network # # Sound # # CONFIG_PACKAGE_alsa-utils is not set # CONFIG_PACKAGE_alsa-utils-seq is not set # CONFIG_PACKAGE_alsa-utils-tests is not set # CONFIG_PACKAGE_aserver is not set # CONFIG_PACKAGE_espeak is not set # CONFIG_PACKAGE_faad2 is not set # CONFIG_PACKAGE_fdk-aac is not set # CONFIG_PACKAGE_forked-daapd is not set # CONFIG_PACKAGE_ices is not set # CONFIG_PACKAGE_lame is not set # CONFIG_PACKAGE_lame-lib is not set # CONFIG_PACKAGE_liblo-utils is not set # CONFIG_PACKAGE_madplay is not set # CONFIG_PACKAGE_madplay-alsa is not set # CONFIG_PACKAGE_moc is not set # CONFIG_PACKAGE_mpc is not set # CONFIG_PACKAGE_mpd-avahi-service is not set # CONFIG_PACKAGE_mpd-full is not set # CONFIG_PACKAGE_mpd-mini is not set # CONFIG_PACKAGE_mpg123 is not set # CONFIG_PACKAGE_opus-tools is not set # CONFIG_PACKAGE_pianod is not set # CONFIG_PACKAGE_pianod-client is not set # CONFIG_PACKAGE_portaudio is not set # CONFIG_PACKAGE_pulseaudio-daemon is not set # CONFIG_PACKAGE_pulseaudio-daemon-avahi is not set # CONFIG_PACKAGE_shairplay is not set # CONFIG_PACKAGE_shairport-sync-mbedtls is not set # CONFIG_PACKAGE_shairport-sync-mini is not set # CONFIG_PACKAGE_shairport-sync-openssl is not set # CONFIG_PACKAGE_shine is not set # CONFIG_PACKAGE_sox is not set # CONFIG_PACKAGE_squeezelite-full is not set # CONFIG_PACKAGE_squeezelite-mini is not set # CONFIG_PACKAGE_svox is not set # CONFIG_PACKAGE_upmpdcli is not set # end of Sound # # Utilities # # # BigClown # # CONFIG_PACKAGE_bigclown-control-tool is not set # CONFIG_PACKAGE_bigclown-firmware-tool is not set # CONFIG_PACKAGE_bigclown-mqtt2influxdb is not set # end of BigClown # # Boot Loaders # # CONFIG_PACKAGE_fconfig is not set # CONFIG_PACKAGE_uboot-envtools is not set # end of Boot Loaders # # Compression # # CONFIG_PACKAGE_bsdtar is not set # CONFIG_PACKAGE_bsdtar-noopenssl is not set # CONFIG_PACKAGE_bzip2 is not set # CONFIG_PACKAGE_gzip is not set # CONFIG_PACKAGE_lz4 is not set # CONFIG_PACKAGE_pigz is not set # CONFIG_PACKAGE_unrar is not set CONFIG_PACKAGE_unzip=y # CONFIG_PACKAGE_xz-utils is not set # CONFIG_PACKAGE_zipcmp is not set # CONFIG_PACKAGE_zipmerge is not set # CONFIG_PACKAGE_ziptool is not set # CONFIG_PACKAGE_zstd is not set # end of Compression # # Database # # CONFIG_PACKAGE_mariadb-common is not set # CONFIG_PACKAGE_pgsql-cli is not set # CONFIG_PACKAGE_pgsql-cli-extra is not set # CONFIG_PACKAGE_pgsql-server is not set # CONFIG_PACKAGE_rrdcgi1 is not set # CONFIG_PACKAGE_rrdtool1 is not set # CONFIG_PACKAGE_sqlite3-cli is not set # CONFIG_PACKAGE_unixodbc-tools is not set # end of Database # # Disc # # CONFIG_PACKAGE_blkdiscard is not set # CONFIG_PACKAGE_blkid is not set # CONFIG_PACKAGE_blockdev is not set # CONFIG_PACKAGE_cfdisk is not set # CONFIG_PACKAGE_cgdisk is not set # CONFIG_PACKAGE_eject is not set # CONFIG_PACKAGE_fdisk is not set # CONFIG_PACKAGE_findfs is not set # CONFIG_PACKAGE_fio is not set # CONFIG_PACKAGE_fixparts is not set # CONFIG_PACKAGE_gdisk is not set # CONFIG_PACKAGE_hd-idle is not set # CONFIG_PACKAGE_hdparm is not set # CONFIG_PACKAGE_lsblk is not set # CONFIG_PACKAGE_lvm2 is not set # CONFIG_PACKAGE_mdadm is not set # CONFIG_PACKAGE_parted is not set # CONFIG_PACKAGE_partx-utils is not set # CONFIG_PACKAGE_sfdisk is not set # CONFIG_PACKAGE_sgdisk is not set # CONFIG_PACKAGE_wipefs is not set # end of Disc # # Editors # # CONFIG_PACKAGE_joe is not set # CONFIG_PACKAGE_jupp is not set # CONFIG_PACKAGE_mg is not set # CONFIG_PACKAGE_nano is not set # CONFIG_PACKAGE_vim is not set # CONFIG_PACKAGE_vim-full is not set # CONFIG_PACKAGE_vim-fuller is not set # CONFIG_PACKAGE_vim-help is not set # CONFIG_PACKAGE_vim-runtime is not set # CONFIG_PACKAGE_zile is not set # end of Editors # # Encryption # # CONFIG_PACKAGE_ccrypt is not set # CONFIG_PACKAGE_certtool is not set # CONFIG_PACKAGE_cryptsetup is not set # CONFIG_PACKAGE_gnupg is not set # CONFIG_PACKAGE_gnutls-utils is not set # CONFIG_PACKAGE_gpgv is not set # CONFIG_PACKAGE_keyctl is not set # CONFIG_PACKAGE_px5g-mbedtls is not set # CONFIG_PACKAGE_px5g-standalone is not set # CONFIG_PACKAGE_stoken is not set # end of Encryption # # Filesystem # # CONFIG_PACKAGE_acl is not set # CONFIG_PACKAGE_antfs-mount is not set # CONFIG_PACKAGE_attr is not set # CONFIG_PACKAGE_badblocks is not set # CONFIG_PACKAGE_btrfs-progs is not set # CONFIG_PACKAGE_chattr is not set # CONFIG_PACKAGE_debugfs is not set # CONFIG_PACKAGE_dosfstools is not set # CONFIG_PACKAGE_dumpe2fs is not set # CONFIG_PACKAGE_e2freefrag is not set # CONFIG_PACKAGE_e2fsprogs is not set # CONFIG_PACKAGE_e4crypt is not set # CONFIG_PACKAGE_exfat-fsck is not set # CONFIG_PACKAGE_exfat-mkfs is not set # CONFIG_PACKAGE_f2fs-tools is not set # CONFIG_PACKAGE_f2fsck is not set # CONFIG_PACKAGE_filefrag is not set # CONFIG_PACKAGE_fstrim is not set # CONFIG_PACKAGE_fuse-utils is not set # CONFIG_PACKAGE_hfsfsck is not set # CONFIG_PACKAGE_lsattr is not set # CONFIG_PACKAGE_mkf2fs is not set # CONFIG_PACKAGE_mkhfs is not set # CONFIG_PACKAGE_ncdu is not set # CONFIG_PACKAGE_nfs-utils is not set # CONFIG_PACKAGE_nfs-utils-libs is not set # CONFIG_PACKAGE_ntfs-3g is not set # CONFIG_PACKAGE_ntfs-3g-low is not set # CONFIG_PACKAGE_ntfs-3g-utils is not set # CONFIG_PACKAGE_owfs is not set # CONFIG_PACKAGE_owshell is not set # CONFIG_PACKAGE_resize2fs is not set # CONFIG_PACKAGE_squashfs-tools-mksquashfs is not set # CONFIG_PACKAGE_squashfs-tools-unsquashfs is not set # CONFIG_PACKAGE_swap-utils is not set # CONFIG_PACKAGE_sysfsutils is not set # CONFIG_PACKAGE_tune2fs is not set # CONFIG_PACKAGE_xfs-admin is not set # CONFIG_PACKAGE_xfs-fsck is not set # CONFIG_PACKAGE_xfs-growfs is not set # CONFIG_PACKAGE_xfs-mkfs is not set # end of Filesystem # # Image Manipulation # # CONFIG_PACKAGE_libjpeg-turbo-utils is not set # CONFIG_PACKAGE_tiff-utils is not set # end of Image Manipulation # # Microcontroller programming # # CONFIG_PACKAGE_avrdude is not set # CONFIG_PACKAGE_dfu-programmer is not set # CONFIG_PACKAGE_stm32flash is not set # end of Microcontroller programming # # RTKLIB Suite # # CONFIG_PACKAGE_convbin is not set # CONFIG_PACKAGE_pos2kml is not set # CONFIG_PACKAGE_rnx2rtkp is not set # CONFIG_PACKAGE_rtkrcv is not set # CONFIG_PACKAGE_str2str is not set # end of RTKLIB Suite # # Shells # CONFIG_PACKAGE_bash=y # CONFIG_PACKAGE_fish is not set # CONFIG_PACKAGE_klish is not set # CONFIG_PACKAGE_mksh is not set # CONFIG_PACKAGE_tcsh is not set # CONFIG_PACKAGE_zsh is not set # end of Shells # # Telephony # # CONFIG_PACKAGE_dahdi-cfg is not set # CONFIG_PACKAGE_dahdi-monitor is not set # CONFIG_PACKAGE_gsm-utils is not set # CONFIG_PACKAGE_sipgrep is not set # CONFIG_PACKAGE_sngrep is not set # end of Telephony # # Terminal # # CONFIG_PACKAGE_agetty is not set # CONFIG_PACKAGE_dvtm is not set # CONFIG_PACKAGE_minicom is not set # CONFIG_PACKAGE_picocom is not set # CONFIG_PACKAGE_rtty-mbedtls is not set # CONFIG_PACKAGE_rtty-nossl is not set # CONFIG_PACKAGE_rtty-openssl is not set # CONFIG_PACKAGE_rtty-wolfssl is not set # CONFIG_PACKAGE_screen is not set # CONFIG_PACKAGE_script-utils is not set # CONFIG_PACKAGE_serialconsole is not set # CONFIG_PACKAGE_setterm is not set # CONFIG_PACKAGE_tio is not set # CONFIG_PACKAGE_tmux is not set CONFIG_PACKAGE_ttyd=y # CONFIG_PACKAGE_wall is not set # end of Terminal # # Virtualization # # end of Virtualization # # Zoneinfo # # CONFIG_PACKAGE_zoneinfo-africa is not set # CONFIG_PACKAGE_zoneinfo-all is not set # CONFIG_PACKAGE_zoneinfo-asia is not set # CONFIG_PACKAGE_zoneinfo-atlantic is not set # CONFIG_PACKAGE_zoneinfo-australia-nz is not set # CONFIG_PACKAGE_zoneinfo-core is not set # CONFIG_PACKAGE_zoneinfo-europe is not set # CONFIG_PACKAGE_zoneinfo-india is not set # CONFIG_PACKAGE_zoneinfo-northamerica is not set # CONFIG_PACKAGE_zoneinfo-pacific is not set # CONFIG_PACKAGE_zoneinfo-poles is not set # CONFIG_PACKAGE_zoneinfo-simple is not set # CONFIG_PACKAGE_zoneinfo-southamerica is not set # end of Zoneinfo # # libimobiledevice # # CONFIG_PACKAGE_idevicerestore is not set # CONFIG_PACKAGE_irecovery is not set # CONFIG_PACKAGE_libimobiledevice-utils is not set # CONFIG_PACKAGE_libusbmuxd-utils is not set # CONFIG_PACKAGE_plistutil is not set # CONFIG_PACKAGE_usbmuxd is not set # end of libimobiledevice # CONFIG_PACKAGE_acpid is not set # CONFIG_PACKAGE_adb is not set # CONFIG_PACKAGE_ap51-flash is not set # CONFIG_PACKAGE_at is not set # CONFIG_PACKAGE_bandwidthd is not set # CONFIG_PACKAGE_bandwidthd-pgsql is not set # CONFIG_PACKAGE_bandwidthd-php is not set # CONFIG_PACKAGE_bandwidthd-sqlite is not set # CONFIG_PACKAGE_banhostlist is not set # CONFIG_PACKAGE_bc is not set # CONFIG_PACKAGE_bluelog is not set # CONFIG_PACKAGE_bluez-daemon is not set # CONFIG_PACKAGE_bluez-utils is not set # CONFIG_PACKAGE_bluez-utils-extra is not set # CONFIG_PACKAGE_bonniexx is not set # CONFIG_PACKAGE_bsdiff is not set # CONFIG_PACKAGE_bspatch is not set # CONFIG_PACKAGE_byobu is not set # CONFIG_PACKAGE_byobu-utils is not set # CONFIG_PACKAGE_cache-domains-mbedtls is not set # CONFIG_PACKAGE_cache-domains-openssl is not set # CONFIG_PACKAGE_cal is not set # CONFIG_PACKAGE_canutils is not set # CONFIG_PACKAGE_cgroup-tools is not set # CONFIG_PACKAGE_cgroupfs-mount is not set # CONFIG_PACKAGE_cmdpad is not set # CONFIG_PACKAGE_coap-client is not set # CONFIG_PACKAGE_collectd is not set CONFIG_PACKAGE_coremark=y CONFIG_PACKAGE_coreutils=y # CONFIG_PACKAGE_coreutils-b2sum is not set # CONFIG_PACKAGE_coreutils-base32 is not set CONFIG_PACKAGE_coreutils-base64=y # CONFIG_PACKAGE_coreutils-basename is not set # CONFIG_PACKAGE_coreutils-basenc is not set # CONFIG_PACKAGE_coreutils-cat is not set # CONFIG_PACKAGE_coreutils-chcon is not set # CONFIG_PACKAGE_coreutils-chgrp is not set # CONFIG_PACKAGE_coreutils-chmod is not set # CONFIG_PACKAGE_coreutils-chown is not set # CONFIG_PACKAGE_coreutils-chroot is not set # CONFIG_PACKAGE_coreutils-cksum is not set # CONFIG_PACKAGE_coreutils-comm is not set # CONFIG_PACKAGE_coreutils-cp is not set # CONFIG_PACKAGE_coreutils-csplit is not set # CONFIG_PACKAGE_coreutils-cut is not set # CONFIG_PACKAGE_coreutils-date is not set # CONFIG_PACKAGE_coreutils-dd is not set # CONFIG_PACKAGE_coreutils-df is not set # CONFIG_PACKAGE_coreutils-dir is not set # CONFIG_PACKAGE_coreutils-dircolors is not set # CONFIG_PACKAGE_coreutils-dirname is not set # CONFIG_PACKAGE_coreutils-du is not set # CONFIG_PACKAGE_coreutils-echo is not set # CONFIG_PACKAGE_coreutils-env is not set # CONFIG_PACKAGE_coreutils-expand is not set # CONFIG_PACKAGE_coreutils-expr is not set # CONFIG_PACKAGE_coreutils-factor is not set # CONFIG_PACKAGE_coreutils-false is not set # CONFIG_PACKAGE_coreutils-fmt is not set # CONFIG_PACKAGE_coreutils-fold is not set # CONFIG_PACKAGE_coreutils-groups is not set # CONFIG_PACKAGE_coreutils-head is not set # CONFIG_PACKAGE_coreutils-hostid is not set # CONFIG_PACKAGE_coreutils-id is not set # CONFIG_PACKAGE_coreutils-install is not set # CONFIG_PACKAGE_coreutils-join is not set # CONFIG_PACKAGE_coreutils-kill is not set # CONFIG_PACKAGE_coreutils-link is not set # CONFIG_PACKAGE_coreutils-ln is not set # CONFIG_PACKAGE_coreutils-logname is not set # CONFIG_PACKAGE_coreutils-ls is not set # CONFIG_PACKAGE_coreutils-md5sum is not set # CONFIG_PACKAGE_coreutils-mkdir is not set # CONFIG_PACKAGE_coreutils-mkfifo is not set # CONFIG_PACKAGE_coreutils-mknod is not set # CONFIG_PACKAGE_coreutils-mktemp is not set # CONFIG_PACKAGE_coreutils-mv is not set # CONFIG_PACKAGE_coreutils-nice is not set # CONFIG_PACKAGE_coreutils-nl is not set CONFIG_PACKAGE_coreutils-nohup=y # CONFIG_PACKAGE_coreutils-nproc is not set # CONFIG_PACKAGE_coreutils-numfmt is not set # CONFIG_PACKAGE_coreutils-od is not set # CONFIG_PACKAGE_coreutils-paste is not set # CONFIG_PACKAGE_coreutils-pathchk is not set # CONFIG_PACKAGE_coreutils-pinky is not set # CONFIG_PACKAGE_coreutils-pr is not set # CONFIG_PACKAGE_coreutils-printenv is not set # CONFIG_PACKAGE_coreutils-printf is not set # CONFIG_PACKAGE_coreutils-ptx is not set # CONFIG_PACKAGE_coreutils-pwd is not set # CONFIG_PACKAGE_coreutils-readlink is not set # CONFIG_PACKAGE_coreutils-realpath is not set # CONFIG_PACKAGE_coreutils-rm is not set # CONFIG_PACKAGE_coreutils-rmdir is not set # CONFIG_PACKAGE_coreutils-runcon is not set # CONFIG_PACKAGE_coreutils-seq is not set # CONFIG_PACKAGE_coreutils-sha1sum is not set # CONFIG_PACKAGE_coreutils-sha224sum is not set # CONFIG_PACKAGE_coreutils-sha256sum is not set # CONFIG_PACKAGE_coreutils-sha384sum is not set # CONFIG_PACKAGE_coreutils-sha512sum is not set # CONFIG_PACKAGE_coreutils-shred is not set # CONFIG_PACKAGE_coreutils-shuf is not set # CONFIG_PACKAGE_coreutils-sleep is not set # CONFIG_PACKAGE_coreutils-sort is not set # CONFIG_PACKAGE_coreutils-split is not set # CONFIG_PACKAGE_coreutils-stat is not set # CONFIG_PACKAGE_coreutils-stdbuf is not set # CONFIG_PACKAGE_coreutils-stty is not set # CONFIG_PACKAGE_coreutils-sum is not set # CONFIG_PACKAGE_coreutils-sync is not set # CONFIG_PACKAGE_coreutils-tac is not set # CONFIG_PACKAGE_coreutils-tail is not set # CONFIG_PACKAGE_coreutils-tee is not set # CONFIG_PACKAGE_coreutils-test is not set # CONFIG_PACKAGE_coreutils-timeout is not set # CONFIG_PACKAGE_coreutils-touch is not set # CONFIG_PACKAGE_coreutils-tr is not set # CONFIG_PACKAGE_coreutils-true is not set # CONFIG_PACKAGE_coreutils-truncate is not set # CONFIG_PACKAGE_coreutils-tsort is not set # CONFIG_PACKAGE_coreutils-tty is not set # CONFIG_PACKAGE_coreutils-uname is not set # CONFIG_PACKAGE_coreutils-unexpand is not set # CONFIG_PACKAGE_coreutils-uniq is not set # CONFIG_PACKAGE_coreutils-unlink is not set # CONFIG_PACKAGE_coreutils-uptime is not set # CONFIG_PACKAGE_coreutils-users is not set # CONFIG_PACKAGE_coreutils-vdir is not set # CONFIG_PACKAGE_coreutils-wc is not set # CONFIG_PACKAGE_coreutils-who is not set # CONFIG_PACKAGE_coreutils-whoami is not set # CONFIG_PACKAGE_coreutils-yes is not set # CONFIG_PACKAGE_crconf is not set # CONFIG_PACKAGE_crelay is not set # CONFIG_PACKAGE_csstidy is not set # CONFIG_PACKAGE_ct-bugcheck is not set # CONFIG_PACKAGE_dbus is not set # CONFIG_PACKAGE_dbus-utils is not set # CONFIG_PACKAGE_device-observatory is not set # CONFIG_PACKAGE_dfu-util is not set # CONFIG_PACKAGE_digitemp is not set # CONFIG_PACKAGE_digitemp-usb is not set # CONFIG_PACKAGE_dmesg is not set # CONFIG_PACKAGE_domoticz is not set # CONFIG_PACKAGE_dropbearconvert is not set # CONFIG_PACKAGE_dtc is not set # CONFIG_PACKAGE_dump1090 is not set # CONFIG_PACKAGE_ecdsautils is not set # CONFIG_PACKAGE_elektra-kdb is not set # CONFIG_PACKAGE_evtest is not set # CONFIG_PACKAGE_extract is not set # CONFIG_PACKAGE_fdt-utils is not set # CONFIG_PACKAGE_file is not set # CONFIG_PACKAGE_findutils is not set # CONFIG_PACKAGE_findutils-find is not set # CONFIG_PACKAGE_findutils-locate is not set # CONFIG_PACKAGE_findutils-xargs is not set # CONFIG_PACKAGE_flashrom is not set # CONFIG_PACKAGE_flashrom-pci is not set # CONFIG_PACKAGE_flashrom-spi is not set # CONFIG_PACKAGE_flashrom-usb is not set # CONFIG_PACKAGE_flent-tools is not set # CONFIG_PACKAGE_flock is not set # CONFIG_PACKAGE_fritz-caldata is not set # CONFIG_PACKAGE_fritz-tffs is not set # CONFIG_PACKAGE_fritz-tffs-nand is not set # CONFIG_PACKAGE_ftdi_eeprom is not set # CONFIG_PACKAGE_gammu is not set # CONFIG_PACKAGE_gawk is not set # CONFIG_PACKAGE_gddrescue is not set # CONFIG_PACKAGE_getopt is not set # CONFIG_PACKAGE_giflib-utils is not set # CONFIG_PACKAGE_gkermit is not set # CONFIG_PACKAGE_gnuplot is not set # CONFIG_PACKAGE_gpioctl-sysfs is not set # CONFIG_PACKAGE_gpiod-tools is not set # CONFIG_PACKAGE_gpsd is not set # CONFIG_PACKAGE_gpsd-clients is not set # CONFIG_PACKAGE_grep is not set # CONFIG_PACKAGE_hamlib is not set # CONFIG_PACKAGE_haserl is not set # CONFIG_PACKAGE_hashdeep is not set # CONFIG_PACKAGE_haveged is not set # CONFIG_PACKAGE_hplip-common is not set # CONFIG_PACKAGE_hplip-sane is not set # CONFIG_PACKAGE_hub-ctrl is not set # CONFIG_PACKAGE_hwclock is not set # CONFIG_PACKAGE_hwinfo is not set # CONFIG_PACKAGE_hwloc-utils is not set # CONFIG_PACKAGE_i2c-tools is not set # CONFIG_PACKAGE_iconv is not set # CONFIG_PACKAGE_iio-utils is not set # CONFIG_PACKAGE_inotifywait is not set # CONFIG_PACKAGE_inotifywatch is not set # CONFIG_PACKAGE_io is not set # CONFIG_PACKAGE_ipfs-http-client-tests is not set # CONFIG_PACKAGE_irqbalance is not set # CONFIG_PACKAGE_iwcap is not set CONFIG_PACKAGE_iwinfo=y # CONFIG_PACKAGE_jq is not set CONFIG_PACKAGE_jshn=y # CONFIG_PACKAGE_kmod is not set # CONFIG_PACKAGE_lcd4linux-custom is not set # CONFIG_PACKAGE_lcdproc-clients is not set # CONFIG_PACKAGE_lcdproc-drivers is not set # CONFIG_PACKAGE_lcdproc-server is not set # CONFIG_PACKAGE_less is not set # CONFIG_PACKAGE_less-wide is not set CONFIG_PACKAGE_libjson-script=y # CONFIG_PACKAGE_libxml2-utils is not set # CONFIG_PACKAGE_lm-sensors is not set # CONFIG_PACKAGE_lm-sensors-detect is not set # CONFIG_PACKAGE_logger is not set # CONFIG_PACKAGE_logrotate is not set # CONFIG_PACKAGE_look is not set # CONFIG_PACKAGE_losetup is not set # CONFIG_PACKAGE_lrzsz is not set # CONFIG_PACKAGE_lscpu is not set # CONFIG_PACKAGE_lsof is not set # CONFIG_PACKAGE_lxc is not set # CONFIG_PACKAGE_maccalc is not set # CONFIG_PACKAGE_macchanger is not set # CONFIG_PACKAGE_mbedtls-util is not set # CONFIG_PACKAGE_mbim-utils is not set # CONFIG_PACKAGE_mbtools is not set # CONFIG_PACKAGE_mc is not set # CONFIG_PACKAGE_mcookie is not set # CONFIG_PACKAGE_micrond is not set # CONFIG_PACKAGE_mmc-utils is not set # CONFIG_PACKAGE_more is not set # CONFIG_PACKAGE_moreutils is not set # CONFIG_PACKAGE_mosh-client is not set # CONFIG_PACKAGE_mosh-server is not set # CONFIG_PACKAGE_mount-utils is not set # CONFIG_PACKAGE_mpack is not set # CONFIG_PACKAGE_mt-st is not set # CONFIG_PACKAGE_namei is not set # CONFIG_PACKAGE_nand-utils is not set # CONFIG_PACKAGE_netopeer2-cli is not set # CONFIG_PACKAGE_netopeer2-keystored is not set # CONFIG_PACKAGE_netopeer2-server is not set # CONFIG_PACKAGE_netwhere is not set # CONFIG_PACKAGE_nnn is not set # CONFIG_PACKAGE_nsenter is not set # CONFIG_PACKAGE_nss-utils is not set # CONFIG_PACKAGE_oath-toolkit is not set # CONFIG_PACKAGE_open-plc-utils is not set # CONFIG_PACKAGE_open2300 is not set # CONFIG_PACKAGE_openobex is not set # CONFIG_PACKAGE_openobex-apps is not set # CONFIG_PACKAGE_openocd is not set # CONFIG_PACKAGE_opensc-utils is not set CONFIG_PACKAGE_openssl-util=y # CONFIG_PACKAGE_openzwave is not set # CONFIG_PACKAGE_openzwave-config is not set # CONFIG_PACKAGE_owipcalc is not set # CONFIG_PACKAGE_pciutils is not set # CONFIG_PACKAGE_pcsc-tools is not set # CONFIG_PACKAGE_pcscd is not set # CONFIG_PACKAGE_powertop is not set # CONFIG_PACKAGE_pps-tools is not set # CONFIG_PACKAGE_prlimit is not set # CONFIG_PACKAGE_procps-ng is not set # CONFIG_PACKAGE_progress is not set # CONFIG_PACKAGE_prometheus is not set # CONFIG_PACKAGE_prometheus-node-exporter-lua is not set # CONFIG_PACKAGE_prometheus-statsd-exporter is not set # CONFIG_PACKAGE_pservice is not set # CONFIG_PACKAGE_pv is not set # CONFIG_PACKAGE_qmi-utils is not set # CONFIG_PACKAGE_qrencode is not set # CONFIG_PACKAGE_quota is not set # CONFIG_PACKAGE_ravpower-mcu is not set # CONFIG_PACKAGE_rclone is not set # CONFIG_PACKAGE_readsb is not set # CONFIG_PACKAGE_relayctl is not set # CONFIG_PACKAGE_rename is not set # CONFIG_PACKAGE_restic is not set # CONFIG_PACKAGE_rng-tools is not set # CONFIG_PACKAGE_rtl-ais is not set # CONFIG_PACKAGE_rtl-sdr is not set # CONFIG_PACKAGE_rtl_433 is not set # CONFIG_PACKAGE_sane-backends is not set # CONFIG_PACKAGE_sane-daemon is not set # CONFIG_PACKAGE_sane-frontends is not set # CONFIG_PACKAGE_sed is not set # CONFIG_PACKAGE_serdisplib-tools is not set # CONFIG_PACKAGE_setserial is not set # CONFIG_PACKAGE_shadow-utils is not set CONFIG_PACKAGE_shellsync=y # CONFIG_PACKAGE_sispmctl is not set # CONFIG_PACKAGE_slide-switch is not set # CONFIG_PACKAGE_smartd is not set # CONFIG_PACKAGE_smartd-mail is not set # CONFIG_PACKAGE_smartmontools is not set # CONFIG_PACKAGE_smartmontools-drivedb is not set # CONFIG_PACKAGE_smstools3 is not set # CONFIG_PACKAGE_sockread is not set # CONFIG_PACKAGE_spi-tools is not set # CONFIG_PACKAGE_spidev-test is not set # CONFIG_PACKAGE_ssdeep is not set # CONFIG_PACKAGE_sshpass is not set # CONFIG_PACKAGE_strace is not set CONFIG_STRACE_NONE=y # CONFIG_STRACE_LIBDW is not set # CONFIG_STRACE_LIBUNWIND is not set # CONFIG_PACKAGE_stress is not set # CONFIG_PACKAGE_sumo is not set # CONFIG_PACKAGE_syncthing is not set # CONFIG_PACKAGE_sysrepo is not set # CONFIG_PACKAGE_sysrepocfg is not set # CONFIG_PACKAGE_sysrepoctl is not set # CONFIG_PACKAGE_sysstat is not set # CONFIG_PACKAGE_tar is not set # CONFIG_PACKAGE_taskwarrior is not set # CONFIG_PACKAGE_telldus-core is not set # CONFIG_PACKAGE_temperusb is not set # CONFIG_PACKAGE_tesseract is not set # CONFIG_PACKAGE_tini is not set # CONFIG_PACKAGE_tracertools is not set # CONFIG_PACKAGE_tree is not set # CONFIG_PACKAGE_triggerhappy is not set CONFIG_PACKAGE_ubi-utils=y # CONFIG_PACKAGE_udns-dnsget is not set # CONFIG_PACKAGE_udns-ex-rdns is not set # CONFIG_PACKAGE_udns-rblcheck is not set # CONFIG_PACKAGE_ugps is not set # CONFIG_PACKAGE_uledd is not set # CONFIG_PACKAGE_unshare is not set # CONFIG_PACKAGE_usb-modeswitch is not set # CONFIG_PACKAGE_usbreset is not set # CONFIG_PACKAGE_usbutils is not set # CONFIG_PACKAGE_uuidd is not set # CONFIG_PACKAGE_uuidgen is not set # CONFIG_PACKAGE_uvcdynctrl is not set # CONFIG_PACKAGE_v4l-utils is not set # CONFIG_PACKAGE_view1090 is not set # CONFIG_PACKAGE_viewadsb is not set # CONFIG_PACKAGE_watchcat is not set # CONFIG_PACKAGE_whereis is not set # CONFIG_PACKAGE_which is not set # CONFIG_PACKAGE_whiptail is not set # CONFIG_PACKAGE_wifitoggle is not set # CONFIG_PACKAGE_wipe is not set # CONFIG_PACKAGE_xsltproc is not set # CONFIG_PACKAGE_xxd is not set # CONFIG_PACKAGE_yanglint is not set # CONFIG_PACKAGE_yara is not set # CONFIG_PACKAGE_ykclient is not set # CONFIG_PACKAGE_ykpers is not set # end of Utilities # # Xorg # # # Font-Utils # # CONFIG_PACKAGE_fontconfig is not set # end of Font-Utils # end of Xorg CONFIG_OVERRIDE_PKGS="smartdns"
392cb1d16740c9afe17f9fcc4ffca184e4ec0608
94e33a31faa76775069b071adea97e86e218a8ee
/src/data/rat/cast.lean
92abef91da186c080ba112dae7a1e34c15021aad
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
14,957
lean
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import data.rat.order import data.int.char_zero import algebra.field.opposite /-! # Casts for Rational Numbers ## Summary We define the canonical injection from ℚ into an arbitrary division ring and prove various casting lemmas showing the well-behavedness of this injection. ## Notations - `/.` is infix notation for `rat.mk`. ## Tags rat, rationals, field, ℚ, numerator, denominator, num, denom, cast, coercion, casting -/ open_locale big_operators variables {F ι α β : Type*} namespace rat open_locale rat section with_div_ring variable [division_ring α] /-- Construct the canonical injection from `ℚ` into an arbitrary division ring. If the field has positive characteristic `p`, we define `1 / p = 1 / 0 = 0` for consistency with our division by zero convention. -/ -- see Note [coercion into rings] @[priority 900] instance cast_coe : has_coe_t ℚ α := ⟨λ r, r.1 / r.2⟩ theorem cast_def (r : ℚ) : (r : α) = r.num / r.denom := rfl @[simp] theorem cast_of_int (n : ℤ) : (of_int n : α) = n := show (n / (1:ℕ) : α) = n, by rw [nat.cast_one, div_one] @[simp, norm_cast] theorem cast_coe_int (n : ℤ) : ((n : ℚ) : α) = n := by rw [coe_int_eq_of_int, cast_of_int] @[simp, norm_cast] theorem cast_coe_nat (n : ℕ) : ((n : ℚ) : α) = n := by rw [← int.cast_coe_nat, cast_coe_int, int.cast_coe_nat] @[simp, norm_cast] theorem cast_zero : ((0 : ℚ) : α) = 0 := (cast_of_int _).trans int.cast_zero @[simp, norm_cast] theorem cast_one : ((1 : ℚ) : α) = 1 := (cast_of_int _).trans int.cast_one theorem cast_commute (r : ℚ) (a : α) : commute ↑r a := (r.1.cast_commute a).div_left (r.2.cast_commute a) theorem cast_comm (r : ℚ) (a : α) : (r : α) * a = a * r := (cast_commute r a).eq theorem commute_cast (a : α) (r : ℚ) : commute a r := (r.cast_commute a).symm @[norm_cast] theorem cast_mk_of_ne_zero (a b : ℤ) (b0 : (b:α) ≠ 0) : (a /. b : α) = a / b := begin have b0' : b ≠ 0, { refine mt _ b0, simp {contextual := tt} }, cases e : a /. b with n d h c, have d0 : (d:α) ≠ 0, { intro d0, have dd := denom_dvd a b, cases (show (d:ℤ) ∣ b, by rwa e at dd) with k ke, have : (b:α) = (d:α) * (k:α), {rw [ke, int.cast_mul, int.cast_coe_nat]}, rw [d0, zero_mul] at this, contradiction }, rw [num_denom'] at e, have := congr_arg (coe : ℤ → α) ((mk_eq b0' $ ne_of_gt $ int.coe_nat_pos.2 h).1 e), rw [int.cast_mul, int.cast_mul, int.cast_coe_nat] at this, symmetry, change (a / b : α) = n / d, rw [div_eq_mul_inv, eq_div_iff_mul_eq d0, mul_assoc, (d.commute_cast _).eq, ← mul_assoc, this, mul_assoc, mul_inv_cancel b0, mul_one] end @[norm_cast] theorem cast_add_of_ne_zero : ∀ {m n : ℚ}, (m.denom : α) ≠ 0 → (n.denom : α) ≠ 0 → ((m + n : ℚ) : α) = m + n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := λ (d₁0 : (d₁:α) ≠ 0) (d₂0 : (d₂:α) ≠ 0), begin have d₁0' : (d₁:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₁0; exact d₁0 nat.cast_zero), have d₂0' : (d₂:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₂0; exact d₂0 nat.cast_zero), rw [num_denom', num_denom', add_def d₁0' d₂0'], suffices : (n₁ * (d₂ * (d₂⁻¹ * d₁⁻¹)) + n₂ * (d₁ * d₂⁻¹) * d₁⁻¹ : α) = n₁ * d₁⁻¹ + n₂ * d₂⁻¹, { rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, cast_mk_of_ne_zero], { simpa [division_def, left_distrib, right_distrib, mul_inv_rev, d₁0, d₂0, mul_assoc] }, all_goals {simp [d₁0, d₂0]} }, rw [← mul_assoc (d₂:α), mul_inv_cancel d₂0, one_mul, (nat.cast_commute _ _).eq], simp [d₁0, mul_assoc] end @[simp, norm_cast] theorem cast_neg : ∀ n, ((-n : ℚ) : α) = -n | ⟨n, d, h, c⟩ := show (↑-n / d : α) = -(n / d), by rw [div_eq_mul_inv, div_eq_mul_inv, int.cast_neg, neg_mul_eq_neg_mul] @[norm_cast] theorem cast_sub_of_ne_zero {m n : ℚ} (m0 : (m.denom : α) ≠ 0) (n0 : (n.denom : α) ≠ 0) : ((m - n : ℚ) : α) = m - n := have ((-n).denom : α) ≠ 0, by cases n; exact n0, by simp [sub_eq_add_neg, (cast_add_of_ne_zero m0 this)] @[norm_cast] theorem cast_mul_of_ne_zero : ∀ {m n : ℚ}, (m.denom : α) ≠ 0 → (n.denom : α) ≠ 0 → ((m * n : ℚ) : α) = m * n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := λ (d₁0 : (d₁:α) ≠ 0) (d₂0 : (d₂:α) ≠ 0), begin have d₁0' : (d₁:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₁0; exact d₁0 nat.cast_zero), have d₂0' : (d₂:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₂0; exact d₂0 nat.cast_zero), rw [num_denom', num_denom', mul_def d₁0' d₂0'], suffices : (n₁ * ((n₂ * d₂⁻¹) * d₁⁻¹) : α) = n₁ * (d₁⁻¹ * (n₂ * d₂⁻¹)), { rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, cast_mk_of_ne_zero], { simpa [division_def, mul_inv_rev, d₁0, d₂0, mul_assoc] }, all_goals {simp [d₁0, d₂0]} }, rw [(d₁.commute_cast (_:α)).inv_right₀.eq] end @[simp] theorem cast_inv_nat (n : ℕ) : ((n⁻¹ : ℚ) : α) = n⁻¹ := begin cases n, { simp }, simp_rw [coe_nat_eq_mk, inv_def, mk, mk_nat, dif_neg n.succ_ne_zero, mk_pnat], simp [cast_def] end @[simp] theorem cast_inv_int (n : ℤ) : ((n⁻¹ : ℚ) : α) = n⁻¹ := begin cases n, { simp [cast_inv_nat] }, { simp only [int.cast_neg_succ_of_nat, ← nat.cast_succ, cast_neg, inv_neg, cast_inv_nat] } end @[norm_cast] theorem cast_inv_of_ne_zero : ∀ {n : ℚ}, (n.num : α) ≠ 0 → (n.denom : α) ≠ 0 → ((n⁻¹ : ℚ) : α) = n⁻¹ | ⟨n, d, h, c⟩ := λ (n0 : (n:α) ≠ 0) (d0 : (d:α) ≠ 0), begin have n0' : (n:ℤ) ≠ 0 := λ e, by rw e at n0; exact n0 int.cast_zero, have d0' : (d:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d0; exact d0 nat.cast_zero), rw [num_denom', inv_def], rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, inv_div]; simp [n0, d0] end @[norm_cast] theorem cast_div_of_ne_zero {m n : ℚ} (md : (m.denom : α) ≠ 0) (nn : (n.num : α) ≠ 0) (nd : (n.denom : α) ≠ 0) : ((m / n : ℚ) : α) = m / n := have (n⁻¹.denom : ℤ) ∣ n.num, by conv in n⁻¹.denom { rw [←(@num_denom n), inv_def] }; apply denom_dvd, have (n⁻¹.denom : α) = 0 → (n.num : α) = 0, from λ h, let ⟨k, e⟩ := this in by have := congr_arg (coe : ℤ → α) e; rwa [int.cast_mul, int.cast_coe_nat, h, zero_mul] at this, by rw [division_def, cast_mul_of_ne_zero md (mt this nn), cast_inv_of_ne_zero nn nd, division_def] @[simp, norm_cast] theorem cast_inj [char_zero α] : ∀ {m n : ℚ}, (m : α) = n ↔ m = n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := begin refine ⟨λ h, _, congr_arg _⟩, have d₁0 : d₁ ≠ 0 := ne_of_gt h₁, have d₂0 : d₂ ≠ 0 := ne_of_gt h₂, have d₁a : (d₁:α) ≠ 0 := nat.cast_ne_zero.2 d₁0, have d₂a : (d₂:α) ≠ 0 := nat.cast_ne_zero.2 d₂0, rw [num_denom', num_denom'] at h ⊢, rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero] at h; simp [d₁0, d₂0] at h ⊢, rwa [eq_div_iff_mul_eq d₂a, division_def, mul_assoc, (d₁.cast_commute (d₂:α)).inv_left₀.eq, ← mul_assoc, ← division_def, eq_comm, eq_div_iff_mul_eq d₁a, eq_comm, ← int.cast_coe_nat d₁, ← int.cast_mul, ← int.cast_coe_nat d₂, ← int.cast_mul, int.cast_inj, ← mk_eq (int.coe_nat_ne_zero.2 d₁0) (int.coe_nat_ne_zero.2 d₂0)] at h end theorem cast_injective [char_zero α] : function.injective (coe : ℚ → α) | m n := cast_inj.1 @[simp] theorem cast_eq_zero [char_zero α] {n : ℚ} : (n : α) = 0 ↔ n = 0 := by rw [← cast_zero, cast_inj] theorem cast_ne_zero [char_zero α] {n : ℚ} : (n : α) ≠ 0 ↔ n ≠ 0 := not_congr cast_eq_zero @[simp, norm_cast] theorem cast_add [char_zero α] (m n) : ((m + n : ℚ) : α) = m + n := cast_add_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, norm_cast] theorem cast_sub [char_zero α] (m n) : ((m - n : ℚ) : α) = m - n := cast_sub_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, norm_cast] theorem cast_mul [char_zero α] (m n) : ((m * n : ℚ) : α) = m * n := cast_mul_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, norm_cast] theorem cast_bit0 [char_zero α] (n : ℚ) : ((bit0 n : ℚ) : α) = bit0 n := cast_add _ _ @[simp, norm_cast] theorem cast_bit1 [char_zero α] (n : ℚ) : ((bit1 n : ℚ) : α) = bit1 n := by rw [bit1, cast_add, cast_one, cast_bit0]; refl variables (α) [char_zero α] /-- Coercion `ℚ → α` as a `ring_hom`. -/ def cast_hom : ℚ →+* α := ⟨coe, cast_one, cast_mul, cast_zero, cast_add⟩ variable {α} @[simp] lemma coe_cast_hom : ⇑(cast_hom α) = coe := rfl @[simp, norm_cast] theorem cast_inv (n) : ((n⁻¹ : ℚ) : α) = n⁻¹ := (cast_hom α).map_inv _ @[simp, norm_cast] theorem cast_div (m n) : ((m / n : ℚ) : α) = m / n := (cast_hom α).map_div _ _ @[norm_cast] theorem cast_mk (a b : ℤ) : ((a /. b) : α) = a / b := by simp only [mk_eq_div, cast_div, cast_coe_int] @[simp, norm_cast] theorem cast_pow (q) (k : ℕ) : ((q ^ k : ℚ) : α) = q ^ k := (cast_hom α).map_pow q k @[simp, norm_cast] lemma cast_list_sum (s : list ℚ) : (↑(s.sum) : α) = (s.map coe).sum := map_list_sum (rat.cast_hom α) _ @[simp, norm_cast] lemma cast_multiset_sum (s : multiset ℚ) : (↑(s.sum) : α) = (s.map coe).sum := map_multiset_sum (rat.cast_hom α) _ @[simp, norm_cast] lemma cast_sum (s : finset ι) (f : ι → ℚ) : (↑(∑ i in s, f i) : α) = ∑ i in s, f i := map_sum (rat.cast_hom α) _ _ @[simp, norm_cast] lemma cast_list_prod (s : list ℚ) : (↑(s.prod) : α) = (s.map coe).prod := map_list_prod (rat.cast_hom α) _ end with_div_ring section field variables [field α] [char_zero α] @[simp, norm_cast] lemma cast_multiset_prod (s : multiset ℚ) : (↑(s.prod) : α) = (s.map coe).prod := map_multiset_prod (rat.cast_hom α) _ @[simp, norm_cast] lemma cast_prod (s : finset ι) (f : ι → ℚ) : (↑(∏ i in s, f i) : α) = ∏ i in s, f i := map_prod (rat.cast_hom α) _ _ end field @[simp, norm_cast] theorem cast_nonneg [linear_ordered_field α] : ∀ {n : ℚ}, 0 ≤ (n : α) ↔ 0 ≤ n | ⟨n, d, h, c⟩ := by { rw [num_denom', cast_mk, mk_eq_div, div_nonneg_iff, div_nonneg_iff], norm_cast } @[simp, norm_cast] theorem cast_le [linear_ordered_field α] {m n : ℚ} : (m : α) ≤ n ↔ m ≤ n := by rw [← sub_nonneg, ← cast_sub, cast_nonneg, sub_nonneg] @[simp, norm_cast] theorem cast_lt [linear_ordered_field α] {m n : ℚ} : (m : α) < n ↔ m < n := by simpa [-cast_le] using not_congr (@cast_le α _ n m) @[simp] theorem cast_nonpos [linear_ordered_field α] {n : ℚ} : (n : α) ≤ 0 ↔ n ≤ 0 := by rw [← cast_zero, cast_le] @[simp] theorem cast_pos [linear_ordered_field α] {n : ℚ} : (0 : α) < n ↔ 0 < n := by rw [← cast_zero, cast_lt] @[simp] theorem cast_lt_zero [linear_ordered_field α] {n : ℚ} : (n : α) < 0 ↔ n < 0 := by rw [← cast_zero, cast_lt] @[simp, norm_cast] theorem cast_id : ∀ n : ℚ, ↑n = n | ⟨n, d, h, c⟩ := by rw [num_denom', cast_mk, mk_eq_div] @[simp] lemma cast_hom_rat : cast_hom ℚ = ring_hom.id ℚ := ring_hom.ext cast_id @[simp, norm_cast] theorem cast_min [linear_ordered_field α] {a b : ℚ} : (↑(min a b) : α) = min a b := by by_cases a ≤ b; simp [h, min_def] @[simp, norm_cast] theorem cast_max [linear_ordered_field α] {a b : ℚ} : (↑(max a b) : α) = max a b := by by_cases b ≤ a; simp [h, max_def] @[simp, norm_cast] theorem cast_abs [linear_ordered_field α] {q : ℚ} : ((|q| : ℚ) : α) = |q| := by simp [abs_eq_max_neg] end rat open rat ring_hom lemma ring_hom.eq_rat_cast {k} [division_ring k] (f : ℚ →+* k) (r : ℚ) : f r = r := calc f r = f (r.1 / r.2) : by rw [← int.cast_coe_nat, ← mk_eq_div, num_denom] ... = f r.1 / f r.2 : f.map_div _ _ ... = r.1 / r.2 : by rw [map_nat_cast, map_int_cast] -- This seems to be true for a `[char_p k]` too because `k'` must have the same characteristic -- but the proof would be much longer @[simp] lemma map_rat_cast [division_ring α] [division_ring β] [char_zero α] [ring_hom_class F α β] (f : F) (q : ℚ) : f q = q := ((f : α →+* β).comp $ cast_hom α).eq_rat_cast q lemma ring_hom.ext_rat {R : Type*} [semiring R] (f g : ℚ →+* R) : f = g := begin ext r, refine rat.num_denom_cases_on' r _, intros a b b0, let φ : ℤ →+* R := f.comp (int.cast_ring_hom ℚ), let ψ : ℤ →+* R := g.comp (int.cast_ring_hom ℚ), rw [rat.mk_eq_div, int.cast_coe_nat], have b0' : (b:ℚ) ≠ 0 := nat.cast_ne_zero.2 b0, have : ∀ n : ℤ, f n = g n := λ n, show φ n = ψ n, by rw [φ.ext_int ψ], calc f (a * b⁻¹) = f a * f b⁻¹ * (g (b:ℤ) * g b⁻¹) : by rw [int.cast_coe_nat, ← g.map_mul, mul_inv_cancel b0', g.map_one, mul_one, f.map_mul] ... = g a * f b⁻¹ * (f (b:ℤ) * g b⁻¹) : by rw [this a, ← this b] ... = g (a * b⁻¹) : by rw [int.cast_coe_nat, mul_assoc, ← mul_assoc (f b⁻¹), ← f.map_mul, inv_mul_cancel b0', f.map_one, one_mul, g.map_mul] end instance rat.subsingleton_ring_hom {R : Type*} [semiring R] : subsingleton (ℚ →+* R) := ⟨ring_hom.ext_rat⟩ namespace monoid_with_zero_hom variables {M : Type*} [group_with_zero M] /-- If `f` and `g` agree on the integers then they are equal `φ`. See note [partially-applied ext lemmas] for why `comp` is used here. -/ @[ext] theorem ext_rat {f g : ℚ →*₀ M} (same_on_int : f.comp (int.cast_ring_hom ℚ).to_monoid_with_zero_hom = g.comp (int.cast_ring_hom ℚ).to_monoid_with_zero_hom) : f = g := begin have same_on_int' : ∀ k : ℤ, f k = g k := congr_fun same_on_int, ext x, rw [← @rat.num_denom x, rat.mk_eq_div, f.map_div, g.map_div, same_on_int' x.num, same_on_int' x.denom], end /-- Positive integer values of a morphism `φ` and its value on `-1` completely determine `φ`. -/ theorem ext_rat_on_pnat {f g : ℚ →*₀ M} (same_on_neg_one : f (-1) = g (-1)) (same_on_pnat : ∀ n : ℕ, 0 < n → f n = g n) : f = g := ext_rat $ ext_int' (by simpa) ‹_› end monoid_with_zero_hom namespace mul_opposite variables [division_ring α] @[simp, norm_cast] lemma op_rat_cast (r : ℚ) : op (r : α) = (↑r : αᵐᵒᵖ) := by rw [cast_def, div_eq_mul_inv, op_mul, op_inv, op_nat_cast, op_int_cast, (commute.cast_int_right _ r.num).eq, cast_def, div_eq_mul_inv] @[simp, norm_cast] lemma unop_rat_cast (r : ℚ) : unop (r : αᵐᵒᵖ) = r := by rw [cast_def, div_eq_mul_inv, unop_mul, unop_inv, unop_nat_cast, unop_int_cast, (commute.cast_int_right _ r.num).eq, cast_def, div_eq_mul_inv] end mul_opposite
16f436a48f9e8a36ee29d3839b68f367ab2bb103
c777c32c8e484e195053731103c5e52af26a25d1
/src/algebra/module/dedekind_domain.lean
eee85d418a999a543e1311cbf7b53e687bf44ae0
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib
2ff9e85dfe2a46f4b291927f983afec17e946eb8
58537299e922f9c77df76cb613910914a479c1f7
refs/heads/master
1,685,313,702,744
1,683,974,212,000
1,683,974,212,000
128,185,277
1
0
null
1,522,920,600,000
1,522,920,600,000
null
UTF-8
Lean
false
false
3,774
lean
/- Copyright (c) 2022 Pierre-Alexandre Bazin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Pierre-Alexandre Bazin -/ import algebra.module.torsion import ring_theory.dedekind_domain.ideal /-! # Modules over a Dedekind domain Over a Dedekind domain, a `I`-torsion module is the internal direct sum of its `p i ^ e i`-torsion submodules, where `I = ∏ i, p i ^ e i` is its unique decomposition in prime ideals. Therefore, as any finitely generated torsion module is `I`-torsion for some `I`, it is an internal direct sum of its `p i ^ e i`-torsion submodules for some prime ideals `p i` and numbers `e i`. -/ universes u v open_locale big_operators variables {R : Type u} [comm_ring R] [is_domain R] {M : Type v} [add_comm_group M] [module R M] open_locale direct_sum namespace submodule variables [is_dedekind_domain R] open unique_factorization_monoid open_locale classical /--Over a Dedekind domain, a `I`-torsion module is the internal direct sum of its `p i ^ e i`- torsion submodules, where `I = ∏ i, p i ^ e i` is its unique decomposition in prime ideals.-/ lemma is_internal_prime_power_torsion_of_is_torsion_by_ideal {I : ideal R} (hI : I ≠ ⊥) (hM : module.is_torsion_by_set R M I) : direct_sum.is_internal (λ p : (factors I).to_finset, torsion_by_set R M (p ^ (factors I).count p : ideal R)) := begin let P := factors I, have prime_of_mem := λ p (hp : p ∈ P.to_finset), prime_of_factor p (multiset.mem_to_finset.mp hp), apply @torsion_by_set_is_internal _ _ _ _ _ _ _ _ (λ p, p ^ P.count p) _, { convert hM, rw [← finset.inf_eq_infi, is_dedekind_domain.inf_prime_pow_eq_prod, ← finset.prod_multiset_count, ← associated_iff_eq], { exact factors_prod hI }, { exact prime_of_mem }, { exact λ _ _ _ _ ij, ij } }, { intros p hp q hq pq, dsimp, rw irreducible_pow_sup, { suffices : (normalized_factors _).count p = 0, { rw [this, zero_min, pow_zero, ideal.one_eq_top] }, { rw [multiset.count_eq_zero, normalized_factors_of_irreducible_pow (prime_of_mem q hq).irreducible, multiset.mem_replicate], exact λ H, pq $ H.2.trans $ normalize_eq q } }, { rw ← ideal.zero_eq_bot, apply pow_ne_zero, exact (prime_of_mem q hq).ne_zero }, { exact (prime_of_mem p hp).irreducible } } end /--A finitely generated torsion module over a Dedekind domain is an internal direct sum of its `p i ^ e i`-torsion submodules where `p i` are factors of `(⊤ : submodule R M).annihilator` and `e i` are their multiplicities. -/ theorem is_internal_prime_power_torsion [module.finite R M] (hM : module.is_torsion R M) : direct_sum.is_internal (λ p : (factors (⊤ : submodule R M).annihilator).to_finset, torsion_by_set R M (p ^ (factors (⊤ : submodule R M).annihilator).count p : ideal R)) := begin have hM' := module.is_torsion_by_set_annihilator_top R M, have hI := submodule.annihilator_top_inter_non_zero_divisors hM, refine is_internal_prime_power_torsion_of_is_torsion_by_ideal _ hM', rw ←set.nonempty_iff_ne_empty at hI, rw submodule.ne_bot_iff, obtain ⟨x, H, hx⟩ := hI, exact ⟨x, H, non_zero_divisors.ne_zero hx⟩ end /--A finitely generated torsion module over a Dedekind domain is an internal direct sum of its `p i ^ e i`-torsion submodules for some prime ideals `p i` and numbers `e i`.-/ theorem exists_is_internal_prime_power_torsion [module.finite R M] (hM : module.is_torsion R M) : ∃ (P : finset $ ideal R) [decidable_eq P] [∀ p ∈ P, prime p] (e : P → ℕ), by exactI direct_sum.is_internal (λ p : P, torsion_by_set R M (p ^ e p : ideal R)) := ⟨_, _, λ p hp, prime_of_factor p (multiset.mem_to_finset.mp hp), _, is_internal_prime_power_torsion hM⟩ end submodule
f380e6f38cf0eba9b022ccd30c4128bc653c40cb
4efff1f47634ff19e2f786deadd394270a59ecd2
/src/order/lattice.lean
a71bc2d152c4a41e1e6239b3cb40237f664ae7ab
[ "Apache-2.0" ]
permissive
agjftucker/mathlib
d634cd0d5256b6325e3c55bb7fb2403548371707
87fe50de17b00af533f72a102d0adefe4a2285e8
refs/heads/master
1,625,378,131,941
1,599,166,526,000
1,599,166,526,000
160,748,509
0
0
Apache-2.0
1,544,141,789,000
1,544,141,789,000
null
UTF-8
Lean
false
false
18,063
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl Defines the inf/sup (semi)-lattice with optionally top/bot type class hierarchy. -/ import order.basic set_option old_structure_cmd true universes u v w variables {α : Type u} {β : Type v} -- TODO: move this eventually, if we decide to use them attribute [ematch] le_trans lt_of_le_of_lt lt_of_lt_of_le lt_trans section -- TODO: this seems crazy, but it also seems to work reasonably well @[ematch] theorem le_antisymm' [partial_order α] : ∀ {a b : α}, (: a ≤ b :) → b ≤ a → a = b := @le_antisymm _ _ end /- TODO: automatic construction of dual definitions / theorems -/ reserve infixl ` ⊓ `:70 reserve infixl ` ⊔ `:65 /-- Typeclass for the `⊔` (`\lub`) notation -/ class has_sup (α : Type u) := (sup : α → α → α) /-- Typeclass for the `⊓` (`\glb`) notation -/ class has_inf (α : Type u) := (inf : α → α → α) infix ⊔ := has_sup.sup infix ⊓ := has_inf.inf section prio set_option default_priority 100 -- see Note [default priority] /-- A `semilattice_sup` is a join-semilattice, that is, a partial order with a join (a.k.a. lub / least upper bound, sup / supremum) operation `⊔` which is the least element larger than both factors. -/ class semilattice_sup (α : Type u) extends has_sup α, partial_order α := (le_sup_left : ∀ a b : α, a ≤ a ⊔ b) (le_sup_right : ∀ a b : α, b ≤ a ⊔ b) (sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c) end prio section semilattice_sup variables [semilattice_sup α] {a b c d : α} @[simp] theorem le_sup_left : a ≤ a ⊔ b := semilattice_sup.le_sup_left a b @[ematch] theorem le_sup_left' : a ≤ (: a ⊔ b :) := le_sup_left @[simp] theorem le_sup_right : b ≤ a ⊔ b := semilattice_sup.le_sup_right a b @[ematch] theorem le_sup_right' : b ≤ (: a ⊔ b :) := le_sup_right theorem le_sup_left_of_le (h : c ≤ a) : c ≤ a ⊔ b := le_trans h le_sup_left theorem le_sup_right_of_le (h : c ≤ b) : c ≤ a ⊔ b := le_trans h le_sup_right theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c := semilattice_sup.sup_le a b c @[simp] theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c := ⟨assume h : a ⊔ b ≤ c, ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩, assume ⟨h₁, h₂⟩, sup_le h₁ h₂⟩ @[simp] theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a := le_antisymm_iff.trans $ by simp [le_refl] theorem sup_of_le_left (h : b ≤ a) : a ⊔ b = a := sup_eq_left.2 h @[simp] theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a := eq_comm.trans sup_eq_left @[simp] theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b := le_antisymm_iff.trans $ by simp [le_refl] theorem sup_of_le_right (h : a ≤ b) : a ⊔ b = b := sup_eq_right.2 h @[simp] theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b := eq_comm.trans sup_eq_right theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d := sup_le (le_sup_left_of_le h₁) (le_sup_right_of_le h₂) theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b := sup_le_sup (le_refl _) h₁ theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c := sup_le_sup h₁ (le_refl _) theorem le_of_sup_eq (h : a ⊔ b = b) : a ≤ b := by { rw ← h, simp } lemma sup_ind [is_total α (≤)] (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊔ b) := (is_total.total a b).elim (λ h : a ≤ b, by rwa sup_eq_right.2 h) (λ h, by rwa sup_eq_left.2 h) @[simp] lemma sup_lt_iff [is_total α (≤)] {a b c : α} : b ⊔ c < a ↔ b < a ∧ c < a := ⟨λ h, ⟨lt_of_le_of_lt le_sup_left h, lt_of_le_of_lt le_sup_right h⟩, λ h, sup_ind b c h.1 h.2⟩ @[simp] theorem sup_idem : a ⊔ a = a := by apply le_antisymm; simp instance sup_is_idempotent : is_idempotent α (⊔) := ⟨@sup_idem _ _⟩ theorem sup_comm : a ⊔ b = b ⊔ a := by apply le_antisymm; simp instance sup_is_commutative : is_commutative α (⊔) := ⟨@sup_comm _ _⟩ theorem sup_assoc : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := le_antisymm (sup_le (sup_le le_sup_left (le_sup_right_of_le le_sup_left)) (le_sup_right_of_le le_sup_right)) (sup_le (le_sup_left_of_le le_sup_left) (sup_le (le_sup_left_of_le le_sup_right) le_sup_right)) instance sup_is_associative : is_associative α (⊔) := ⟨@sup_assoc _ _⟩ @[simp] lemma sup_left_idem : a ⊔ (a ⊔ b) = a ⊔ b := by rw [← sup_assoc, sup_idem] @[simp] lemma sup_right_idem : (a ⊔ b) ⊔ b = a ⊔ b := by rw [sup_assoc, sup_idem] lemma sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a] lemma forall_le_or_exists_lt_sup (a : α) : (∀b, b ≤ a) ∨ (∃b, a < b) := suffices (∃b, ¬b ≤ a) → (∃b, a < b), by rwa [or_iff_not_imp_left, not_forall], assume ⟨b, hb⟩, ⟨a ⊔ b, lt_of_le_of_ne le_sup_left $ mt left_eq_sup.1 hb⟩ theorem semilattice_sup.ext_sup {α} {A B : semilattice_sup α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) (x y : α) : (by haveI := A; exact (x ⊔ y)) = x ⊔ y := eq_of_forall_ge_iff $ λ c, by simp only [sup_le_iff]; rw [← H, @sup_le_iff α A, H, H] theorem semilattice_sup.ext {α} {A B : semilattice_sup α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin have := partial_order.ext H, have ss := funext (λ x, funext $ semilattice_sup.ext_sup H x), casesI A, casesI B, injection this; congr' end end semilattice_sup section prio set_option default_priority 100 -- see Note [default priority] /-- A `semilattice_inf` is a meet-semilattice, that is, a partial order with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation `⊓` which is the greatest element smaller than both factors. -/ class semilattice_inf (α : Type u) extends has_inf α, partial_order α := (inf_le_left : ∀ a b : α, a ⊓ b ≤ a) (inf_le_right : ∀ a b : α, a ⊓ b ≤ b) (le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ b ⊓ c) end prio section semilattice_inf variables [semilattice_inf α] {a b c d : α} @[simp] theorem inf_le_left : a ⊓ b ≤ a := semilattice_inf.inf_le_left a b @[ematch] theorem inf_le_left' : (: a ⊓ b :) ≤ a := semilattice_inf.inf_le_left a b @[simp] theorem inf_le_right : a ⊓ b ≤ b := semilattice_inf.inf_le_right a b @[ematch] theorem inf_le_right' : (: a ⊓ b :) ≤ b := semilattice_inf.inf_le_right a b theorem le_inf : a ≤ b → a ≤ c → a ≤ b ⊓ c := semilattice_inf.le_inf a b c theorem inf_le_left_of_le (h : a ≤ c) : a ⊓ b ≤ c := le_trans inf_le_left h theorem inf_le_right_of_le (h : b ≤ c) : a ⊓ b ≤ c := le_trans inf_le_right h @[simp] theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c := ⟨assume h : a ≤ b ⊓ c, ⟨le_trans h inf_le_left, le_trans h inf_le_right⟩, assume ⟨h₁, h₂⟩, le_inf h₁ h₂⟩ @[simp] theorem inf_eq_left : a ⊓ b = a ↔ a ≤ b := le_antisymm_iff.trans $ by simp [le_refl] theorem inf_of_le_left (h : a ≤ b) : a ⊓ b = a := inf_eq_left.2 h @[simp] theorem left_eq_inf : a = a ⊓ b ↔ a ≤ b := eq_comm.trans inf_eq_left @[simp] theorem inf_eq_right : a ⊓ b = b ↔ b ≤ a := le_antisymm_iff.trans $ by simp [le_refl] theorem inf_of_le_right (h : b ≤ a) : a ⊓ b = b := inf_eq_right.2 h @[simp] theorem right_eq_inf : b = a ⊓ b ↔ b ≤ a := eq_comm.trans inf_eq_right theorem inf_le_inf (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊓ c ≤ b ⊓ d := le_inf (inf_le_left_of_le h₁) (inf_le_right_of_le h₂) lemma inf_le_inf_right (a : α) {b c : α} (h : b ≤ c) : b ⊓ a ≤ c ⊓ a := inf_le_inf h (le_refl _) lemma inf_le_inf_left (a : α) {b c : α} (h : b ≤ c) : a ⊓ b ≤ a ⊓ c := inf_le_inf (le_refl _) h theorem le_of_inf_eq (h : a ⊓ b = a) : a ≤ b := by { rw ← h, simp } lemma inf_ind [is_total α (≤)] (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊓ b) := (is_total.total a b).elim (λ h : a ≤ b, by rwa inf_eq_left.2 h) (λ h, by rwa inf_eq_right.2 h) @[simp] lemma lt_inf_iff [is_total α (≤)] {a b c : α} : a < b ⊓ c ↔ a < b ∧ a < c := ⟨λ h, ⟨lt_of_lt_of_le h inf_le_left, lt_of_lt_of_le h inf_le_right⟩, λ h, inf_ind b c h.1 h.2⟩ @[simp] theorem inf_idem : a ⊓ a = a := by apply le_antisymm; simp instance inf_is_idempotent : is_idempotent α (⊓) := ⟨@inf_idem _ _⟩ theorem inf_comm : a ⊓ b = b ⊓ a := by apply le_antisymm; simp instance inf_is_commutative : is_commutative α (⊓) := ⟨@inf_comm _ _⟩ theorem inf_assoc : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := le_antisymm (le_inf (inf_le_left_of_le inf_le_left) (le_inf (inf_le_left_of_le inf_le_right) inf_le_right)) (le_inf (le_inf inf_le_left (inf_le_right_of_le inf_le_left)) (inf_le_right_of_le inf_le_right)) instance inf_is_associative : is_associative α (⊓) := ⟨@inf_assoc _ _⟩ @[simp] lemma inf_left_idem : a ⊓ (a ⊓ b) = a ⊓ b := by rw [← inf_assoc, inf_idem] @[simp] lemma inf_right_idem : (a ⊓ b) ⊓ b = a ⊓ b := by rw [inf_assoc, inf_idem] lemma inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) := by rw [← inf_assoc, ← inf_assoc, @inf_comm α _ a] lemma forall_le_or_exists_lt_inf (a : α) : (∀b, a ≤ b) ∨ (∃b, b < a) := suffices (∃b, ¬a ≤ b) → (∃b, b < a), by rwa [or_iff_not_imp_left, not_forall], assume ⟨b, hb⟩, have a ⊓ b ≠ a, from assume eq, hb $ eq ▸ inf_le_right, ⟨a ⊓ b, lt_of_le_of_ne inf_le_left ‹a ⊓ b ≠ a›⟩ theorem semilattice_inf.ext_inf {α} {A B : semilattice_inf α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) (x y : α) : (by haveI := A; exact (x ⊓ y)) = x ⊓ y := eq_of_forall_le_iff $ λ c, by simp only [le_inf_iff]; rw [← H, @le_inf_iff α A, H, H] theorem semilattice_inf.ext {α} {A B : semilattice_inf α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin have := partial_order.ext H, have ss := funext (λ x, funext $ semilattice_inf.ext_inf H x), casesI A, casesI B, injection this; congr' end end semilattice_inf /- Lattices -/ section prio set_option default_priority 100 -- see Note [default priority] /-- A lattice is a join-semilattice which is also a meet-semilattice. -/ class lattice (α : Type u) extends semilattice_sup α, semilattice_inf α end prio section lattice variables [lattice α] {a b c d : α} /- Distributivity laws -/ /- TODO: better names? -/ theorem sup_inf_le : a ⊔ (b ⊓ c) ≤ (a ⊔ b) ⊓ (a ⊔ c) := le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _) theorem le_inf_sup : (a ⊓ b) ⊔ (a ⊓ c) ≤ a ⊓ (b ⊔ c) := sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right) theorem inf_sup_self : a ⊓ (a ⊔ b) = a := by simp theorem sup_inf_self : a ⊔ (a ⊓ b) = a := by simp theorem lattice.ext {α} {A B : lattice α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin have SS : @lattice.to_semilattice_sup α A = @lattice.to_semilattice_sup α B := semilattice_sup.ext H, have II := semilattice_inf.ext H, casesI A, casesI B, injection SS; injection II; congr' end end lattice section prio set_option default_priority 100 -- see Note [default priority] /-- A distributive lattice is a lattice that satisfies any of four equivalent distribution properties (of sup over inf or inf over sup, on the left or right). A classic example of a distributive lattice is the lattice of subsets of a set, and in fact this example is generic in the sense that every distributive lattice is realizable as a sublattice of a powerset lattice. -/ class distrib_lattice α extends lattice α := (le_sup_inf : ∀x y z : α, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z)) end prio section distrib_lattice variables [distrib_lattice α] {x y z : α} theorem le_sup_inf : ∀{x y z : α}, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z) := distrib_lattice.le_sup_inf theorem sup_inf_left : x ⊔ (y ⊓ z) = (x ⊔ y) ⊓ (x ⊔ z) := le_antisymm sup_inf_le le_sup_inf theorem sup_inf_right : (y ⊓ z) ⊔ x = (y ⊔ x) ⊓ (z ⊔ x) := by simp only [sup_inf_left, λy:α, @sup_comm α _ y x, eq_self_iff_true] theorem inf_sup_left : x ⊓ (y ⊔ z) = (x ⊓ y) ⊔ (x ⊓ z) := calc x ⊓ (y ⊔ z) = (x ⊓ (x ⊔ z)) ⊓ (y ⊔ z) : by rw [inf_sup_self] ... = x ⊓ ((x ⊓ y) ⊔ z) : by simp only [inf_assoc, sup_inf_right, eq_self_iff_true] ... = (x ⊔ (x ⊓ y)) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_inf_self] ... = ((x ⊓ y) ⊔ x) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_comm] ... = (x ⊓ y) ⊔ (x ⊓ z) : by rw [sup_inf_left] theorem inf_sup_right : (y ⊔ z) ⊓ x = (y ⊓ x) ⊔ (z ⊓ x) := by simp only [inf_sup_left, λy:α, @inf_comm α _ y x, eq_self_iff_true] lemma le_of_inf_le_sup_le (h₁ : x ⊓ z ≤ y ⊓ z) (h₂ : x ⊔ z ≤ y ⊔ z) : x ≤ y := calc x ≤ (y ⊓ z) ⊔ x : le_sup_right ... = (y ⊔ x) ⊓ (x ⊔ z) : by rw [sup_inf_right, @sup_comm _ _ x] ... ≤ (y ⊔ x) ⊓ (y ⊔ z) : inf_le_inf_left _ h₂ ... = y ⊔ (x ⊓ z) : sup_inf_left.symm ... ≤ y ⊔ (y ⊓ z) : sup_le_sup_left h₁ _ ... ≤ _ : sup_le (le_refl y) inf_le_left lemma eq_of_inf_eq_sup_eq {α : Type u} [distrib_lattice α] {a b c : α} (h₁ : b ⊓ a = c ⊓ a) (h₂ : b ⊔ a = c ⊔ a) : b = c := le_antisymm (le_of_inf_le_sup_le (le_of_eq h₁) (le_of_eq h₂)) (le_of_inf_le_sup_le (le_of_eq h₁.symm) (le_of_eq h₂.symm)) end distrib_lattice /- Lattices derived from linear orders -/ @[priority 100] -- see Note [lower instance priority] instance lattice_of_decidable_linear_order {α : Type u} [o : decidable_linear_order α] : lattice α := { sup := max, le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := assume a b c, max_le, inf := min, inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := assume a b c, le_min, ..o } theorem sup_eq_max [decidable_linear_order α] {x y : α} : x ⊔ y = max x y := rfl theorem inf_eq_min [decidable_linear_order α] {x y : α} : x ⊓ y = min x y := rfl @[priority 100] -- see Note [lower instance priority] instance distrib_lattice_of_decidable_linear_order {α : Type u} [o : decidable_linear_order α] : distrib_lattice α := { le_sup_inf := assume a b c, match le_total b c with | or.inl h := inf_le_left_of_le $ sup_le_sup_left (le_inf (le_refl b) h) _ | or.inr h := inf_le_right_of_le $ sup_le_sup_left (le_inf h (le_refl c)) _ end, ..lattice_of_decidable_linear_order } instance nat.distrib_lattice : distrib_lattice ℕ := by apply_instance namespace monotone lemma le_map_sup [semilattice_sup α] [semilattice_sup β] {f : α → β} (h : monotone f) (x y : α) : f x ⊔ f y ≤ f (x ⊔ y) := sup_le (h le_sup_left) (h le_sup_right) lemma map_sup [semilattice_sup α] [is_total α (≤)] [semilattice_sup β] {f : α → β} (hf : monotone f) (x y : α) : f (x ⊔ y) = f x ⊔ f y := (is_total.total x y).elim (λ h : x ≤ y, by simp only [h, hf h, sup_of_le_right]) (λ h, by simp only [h, hf h, sup_of_le_left]) lemma map_inf_le [semilattice_inf α] [semilattice_inf β] {f : α → β} (h : monotone f) (x y : α) : f (x ⊓ y) ≤ f x ⊓ f y := le_inf (h inf_le_left) (h inf_le_right) lemma map_inf [semilattice_inf α] [is_total α (≤)] [semilattice_inf β] {f : α → β} (hf : monotone f) (x y : α) : f (x ⊓ y) = f x ⊓ f y := (is_total.total x y).elim (λ h : x ≤ y, by simp only [h, hf h, inf_of_le_left]) (λ h, by simp only [h, hf h, inf_of_le_right]) end monotone namespace order_dual variable (α) instance [has_inf α] : has_sup (order_dual α) := ⟨((⊓) : α → α → α)⟩ instance [has_sup α] : has_inf (order_dual α) := ⟨((⊔) : α → α → α)⟩ instance [semilattice_inf α] : semilattice_sup (order_dual α) := { le_sup_left := @inf_le_left α _, le_sup_right := @inf_le_right α _, sup_le := assume a b c hca hcb, @le_inf α _ _ _ _ hca hcb, .. order_dual.partial_order α, .. order_dual.has_sup α } instance [semilattice_sup α] : semilattice_inf (order_dual α) := { inf_le_left := @le_sup_left α _, inf_le_right := @le_sup_right α _, le_inf := assume a b c hca hcb, @sup_le α _ _ _ _ hca hcb, .. order_dual.partial_order α, .. order_dual.has_inf α } instance [lattice α] : lattice (order_dual α) := { .. order_dual.semilattice_sup α, .. order_dual.semilattice_inf α } instance [distrib_lattice α] : distrib_lattice (order_dual α) := { le_sup_inf := assume x y z, le_of_eq inf_sup_left.symm, .. order_dual.lattice α } end order_dual namespace prod variables (α β) instance [has_sup α] [has_sup β] : has_sup (α × β) := ⟨λp q, ⟨p.1 ⊔ q.1, p.2 ⊔ q.2⟩⟩ instance [has_inf α] [has_inf β] : has_inf (α × β) := ⟨λp q, ⟨p.1 ⊓ q.1, p.2 ⊓ q.2⟩⟩ instance [semilattice_sup α] [semilattice_sup β] : semilattice_sup (α × β) := { sup_le := assume a b c h₁ h₂, ⟨sup_le h₁.1 h₂.1, sup_le h₁.2 h₂.2⟩, le_sup_left := assume a b, ⟨le_sup_left, le_sup_left⟩, le_sup_right := assume a b, ⟨le_sup_right, le_sup_right⟩, .. prod.partial_order α β, .. prod.has_sup α β } instance [semilattice_inf α] [semilattice_inf β] : semilattice_inf (α × β) := { le_inf := assume a b c h₁ h₂, ⟨le_inf h₁.1 h₂.1, le_inf h₁.2 h₂.2⟩, inf_le_left := assume a b, ⟨inf_le_left, inf_le_left⟩, inf_le_right := assume a b, ⟨inf_le_right, inf_le_right⟩, .. prod.partial_order α β, .. prod.has_inf α β } instance [lattice α] [lattice β] : lattice (α × β) := { .. prod.semilattice_inf α β, .. prod.semilattice_sup α β } instance [distrib_lattice α] [distrib_lattice β] : distrib_lattice (α × β) := { le_sup_inf := assume a b c, ⟨le_sup_inf, le_sup_inf⟩, .. prod.lattice α β } end prod
93196a26ea846e24061600722cc2a32aa73fb9cb
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/class_bug1.lean
912bbdb509b31e5430e4c81aea37c6f73b601f7b
[ "Apache-2.0" ]
permissive
soonhokong/lean
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
38607e3eb57f57f77c0ac114ad169e9e4262e24f
refs/heads/master
1,611,187,284,081
1,450,766,737,000
1,476,122,547,000
11,513,992
2
0
null
1,401,763,102,000
1,374,182,235,000
C++
UTF-8
Lean
false
false
986
lean
import logic inductive category (ob : Type) (mor : ob → ob → Type) : Type := mk : Π (comp : Π⦃A B C : ob⦄, mor B C → mor A B → mor A C) (id : Π {A : ob}, mor A A), (Π {A B C D : ob} {f : mor A B} {g : mor B C} {h : mor C D}, comp h (comp g f) = comp (comp h g) f) → (Π {A B : ob} {f : mor A B}, comp f id = f) → (Π {A B : ob} {f : mor A B}, comp id f = f) → category ob mor attribute category [class] namespace category section sec_cat parameter A : Type inductive foo := mk : A → foo attribute foo [class] parameters {ob : Type} {mor : ob → ob → Type} {Cat : category ob mor} definition compose := category.rec (λ comp id assoc idr idl, comp) Cat definition id := category.rec (λ comp id assoc idr idl, id) Cat local infixr ∘ := compose inductive is_section {A B : ob} (f : mor A B) : Type := mk : ∀g, g ∘ f = id → is_section f end sec_cat end category
2c8b60eee0b735386cdbb8cc0ba5e6bdb688daeb
957a80ea22c5abb4f4670b250d55534d9db99108
/tests/lean/user_attribute.lean
7d3539bab7ccc26048c490305e1fb4ee5d55e679
[ "Apache-2.0" ]
permissive
GaloisInc/lean
aa1e64d604051e602fcf4610061314b9a37ab8cd
f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0
refs/heads/master
1,592,202,909,807
1,504,624,387,000
1,504,624,387,000
75,319,626
2
1
Apache-2.0
1,539,290,164,000
1,480,616,104,000
C++
UTF-8
Lean
false
false
782
lean
@[user_attribute] meta def foo_attr : user_attribute := { name := `foo, descr := "bar" } attribute [foo] eq.refl #print [foo] #print eq.refl run_cmd attribute.get_instances `foo >>= tactic.pp >>= tactic.trace #print "---" -- compound names @[user_attribute] meta def foo_baz_attr : user_attribute := { name := `foo.baz, descr := "bar" } attribute [foo.baz] eq.refl #print [foo.baz] #print eq.refl run_cmd attribute.get_instances `foo.baz >>= tactic.pp >>= tactic.trace -- can't redeclare attributes @[user_attribute] meta def duplicate : user_attribute := { name := `reducible, descr := "bar" } -- wrong type @[user_attribute] meta def bar := "bar" section variable x : string @[user_attribute] meta def baz_attr : user_attribute := { name := `baz, descr := x } end
31e9e957159771dff8f4df09134c06fc33abe947
5aaf2c36656c8e760e9c8e4d3b19422402d70634
/src/tut3.lean
534a48466b78161cbb1d65e61a46f2c2ec148f24
[]
no_license
BassemSafieldeen/Lean-tutorials
535746ccf8d4419419f4fcb544c1687dc564b537
031a14fa9700898e9895c9d41be8495275618c46
refs/heads/main
1,673,748,866,999
1,605,459,118,000
1,605,459,118,000
307,048,364
0
0
null
null
null
null
UTF-8
Lean
false
false
768
lean
import linear_algebra.tensor_product import tut2 open_locale tensor_product variables {ℋ : Type} [complex_hilbert_space ℋ] {ρ σ τ : ℋ →ₗ[ℂ] ℋ} [quantum_state ρ] [quantum_state σ] [quantum_state τ] #check tensor_product #check ρ ⊗ₜ[ℂ] σ notation A ` ⊗ ` B := A ⊗ₜ[ℂ] B example {a : ℂ} : a • (ρ ⊗ σ) = (a • ρ) ⊗ σ := begin exact rfl, end example {a : ℂ} : a • (ρ ⊗ σ) = ρ ⊗ (a • σ) := begin norm_num, end example {a : ℂ} : a • (ρ + σ) = a • ρ + a • σ := begin rw smul_add, end example : ρ ⊗ (σ + τ) = ρ ⊗ σ + ρ ⊗ τ := begin rw tensor_product.tmul_add, end example : (σ + τ) ⊗ ρ = σ ⊗ ρ + τ ⊗ ρ := begin rw tensor_product.add_tmul, end
37b29d4a476c961aff062d9e3face6c384cd6ad0
26ac254ecb57ffcb886ff709cf018390161a9225
/src/order/order_iso.lean
5f74573214da472b99d648c7580bc0acd69b0eab
[ "Apache-2.0" ]
permissive
eric-wieser/mathlib
42842584f584359bbe1fc8b88b3ff937c8acd72d
d0df6b81cd0920ad569158c06a3fd5abb9e63301
refs/heads/master
1,669,546,404,255
1,595,254,668,000
1,595,254,668,000
281,173,504
0
0
Apache-2.0
1,595,263,582,000
1,595,263,581,000
null
UTF-8
Lean
false
false
16,516
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import logic.embedding import logic.function.iterate import order.rel_classes open function universes u v w variables {α : Type*} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} /-- An increasing function is injective -/ lemma injective_of_increasing (r : α → α → Prop) (s : β → β → Prop) [is_trichotomous α r] [is_irrefl β s] (f : α → β) (hf : ∀{x y}, r x y → s (f x) (f y)) : injective f := begin intros x y hxy, rcases trichotomous_of r x y with h | h | h, have := hf h, rw hxy at this, exfalso, exact irrefl_of s (f y) this, exact h, have := hf h, rw hxy at this, exfalso, exact irrefl_of s (f y) this end /-- An order embedding with respect to a given pair of orders `r` and `s` is an embedding `f : α ↪ β` such that `r a b ↔ s (f a) (f b)`. -/ structure order_embedding {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) extends α ↪ β := (ord' : ∀ {a b}, r a b ↔ s (to_embedding a) (to_embedding b)) infix ` ≼o `:25 := order_embedding /-- the induced order on a subtype is an embedding under the natural inclusion. -/ definition subtype.order_embedding {X : Type*} (r : X → X → Prop) (p : X → Prop) : ((subtype.val : subtype p → X) ⁻¹'o r) ≼o r := ⟨⟨subtype.val,subtype.val_injective⟩,by intros;refl⟩ theorem preimage_equivalence {α β} (f : α → β) {s : β → β → Prop} (hs : equivalence s) : equivalence (f ⁻¹'o s) := ⟨λ a, hs.1 _, λ a b h, hs.2.1 h, λ a b c h₁ h₂, hs.2.2 h₁ h₂⟩ namespace order_embedding instance : has_coe_to_fun (r ≼o s) := ⟨λ _, α → β, λ o, o.to_embedding⟩ theorem injective (f : r ≼o s) : injective f := f.inj' theorem ord (f : r ≼o s) : ∀ {a b}, r a b ↔ s (f a) (f b) := f.ord' @[simp] theorem coe_fn_mk (f : α ↪ β) (o) : (@order_embedding.mk _ _ r s f o : α → β) = f := rfl @[simp] theorem coe_fn_to_embedding (f : r ≼o s) : (f.to_embedding : α → β) = f := rfl /-- The map `coe_fn : (r ≼o s) → (r → s)` is injective. We can't use `function.injective` here but mimic its signature by using `⦃e₁ e₂⦄`. -/ theorem coe_fn_inj : ∀ ⦃e₁ e₂ : r ≼o s⦄, (e₁ : α → β) = e₂ → e₁ = e₂ | ⟨⟨f₁, h₁⟩, o₁⟩ ⟨⟨f₂, h₂⟩, o₂⟩ h := by { congr, exact h } @[refl] protected def refl (r : α → α → Prop) : r ≼o r := ⟨embedding.refl _, λ a b, iff.rfl⟩ @[trans] protected def trans (f : r ≼o s) (g : s ≼o t) : r ≼o t := ⟨f.1.trans g.1, λ a b, by rw [f.2, g.2]; simp⟩ @[simp] theorem refl_apply (x : α) : order_embedding.refl r x = x := rfl @[simp] theorem trans_apply (f : r ≼o s) (g : s ≼o t) (a : α) : (f.trans g) a = g (f a) := rfl /-- An order embedding is also an order embedding between dual orders. -/ def rsymm (f : r ≼o s) : swap r ≼o swap s := ⟨f.to_embedding, λ a b, f.ord⟩ /-- If `f` is injective, then it is an order embedding from the preimage order of `s` to `s`. -/ def preimage (f : α ↪ β) (s : β → β → Prop) : f ⁻¹'o s ≼o s := ⟨f, λ a b, iff.rfl⟩ theorem eq_preimage (f : r ≼o s) : r = f ⁻¹'o s := by { ext a b, exact f.ord } protected theorem is_irrefl : ∀ (f : r ≼o s) [is_irrefl β s], is_irrefl α r | ⟨f, o⟩ ⟨H⟩ := ⟨λ a h, H _ (o.1 h)⟩ protected theorem is_refl : ∀ (f : r ≼o s) [is_refl β s], is_refl α r | ⟨f, o⟩ ⟨H⟩ := ⟨λ a, o.2 (H _)⟩ protected theorem is_symm : ∀ (f : r ≼o s) [is_symm β s], is_symm α r | ⟨f, o⟩ ⟨H⟩ := ⟨λ a b h, o.2 (H _ _ (o.1 h))⟩ protected theorem is_asymm : ∀ (f : r ≼o s) [is_asymm β s], is_asymm α r | ⟨f, o⟩ ⟨H⟩ := ⟨λ a b h₁ h₂, H _ _ (o.1 h₁) (o.1 h₂)⟩ protected theorem is_antisymm : ∀ (f : r ≼o s) [is_antisymm β s], is_antisymm α r | ⟨f, o⟩ ⟨H⟩ := ⟨λ a b h₁ h₂, f.inj' (H _ _ (o.1 h₁) (o.1 h₂))⟩ protected theorem is_trans : ∀ (f : r ≼o s) [is_trans β s], is_trans α r | ⟨f, o⟩ ⟨H⟩ := ⟨λ a b c h₁ h₂, o.2 (H _ _ _ (o.1 h₁) (o.1 h₂))⟩ protected theorem is_total : ∀ (f : r ≼o s) [is_total β s], is_total α r | ⟨f, o⟩ ⟨H⟩ := ⟨λ a b, (or_congr o o).2 (H _ _)⟩ protected theorem is_preorder : ∀ (f : r ≼o s) [is_preorder β s], is_preorder α r | f H := by exactI {..f.is_refl, ..f.is_trans} protected theorem is_partial_order : ∀ (f : r ≼o s) [is_partial_order β s], is_partial_order α r | f H := by exactI {..f.is_preorder, ..f.is_antisymm} protected theorem is_linear_order : ∀ (f : r ≼o s) [is_linear_order β s], is_linear_order α r | f H := by exactI {..f.is_partial_order, ..f.is_total} protected theorem is_strict_order : ∀ (f : r ≼o s) [is_strict_order β s], is_strict_order α r | f H := by exactI {..f.is_irrefl, ..f.is_trans} protected theorem is_trichotomous : ∀ (f : r ≼o s) [is_trichotomous β s], is_trichotomous α r | ⟨f, o⟩ ⟨H⟩ := ⟨λ a b, (or_congr o (or_congr f.inj'.eq_iff.symm o)).2 (H _ _)⟩ protected theorem is_strict_total_order' : ∀ (f : r ≼o s) [is_strict_total_order' β s], is_strict_total_order' α r | f H := by exactI {..f.is_trichotomous, ..f.is_strict_order} protected theorem acc (f : r ≼o s) (a : α) : acc s (f a) → acc r a := begin generalize h : f a = b, intro ac, induction ac with _ H IH generalizing a, subst h, exact ⟨_, λ a' h, IH (f a') (f.ord.1 h) _ rfl⟩ end protected theorem well_founded : ∀ (f : r ≼o s) (h : well_founded s), well_founded r | f ⟨H⟩ := ⟨λ a, f.acc _ (H _)⟩ protected theorem is_well_order : ∀ (f : r ≼o s) [is_well_order β s], is_well_order α r | f H := by exactI {wf := f.well_founded H.wf, ..f.is_strict_total_order'} /-- It suffices to prove `f` is monotone between strict orders to show it is an order embedding. -/ def of_monotone [is_trichotomous α r] [is_asymm β s] (f : α → β) (H : ∀ a b, r a b → s (f a) (f b)) : r ≼o s := begin haveI := @is_asymm.is_irrefl β s _, refine ⟨⟨f, λ a b e, _⟩, λ a b, ⟨H _ _, λ h, _⟩⟩, { refine ((@trichotomous _ r _ a b).resolve_left _).resolve_right _; exact λ h, @irrefl _ s _ _ (by simpa [e] using H _ _ h) }, { refine (@trichotomous _ r _ a b).resolve_right (or.rec (λ e, _) (λ h', _)), { subst e, exact irrefl _ h }, { exact asymm (H _ _ h') h } } end @[simp] theorem of_monotone_coe [is_trichotomous α r] [is_asymm β s] (f : α → β) (H) : (@of_monotone _ _ r s _ _ f H : α → β) = f := rfl -- If le is preserved by an order embedding of preorders, then lt is too def lt_embedding_of_le_embedding [preorder α] [preorder β] (f : ((≤) : α → α → Prop) ≼o ((≤) : β → β → Prop)) : (has_lt.lt : α → α → Prop) ≼o (has_lt.lt : β → β → Prop) := { ord' := by intros; simp [lt_iff_le_not_le,f.ord], .. f } end order_embedding /-- The inclusion map `fin n → ℕ` is an order embedding. -/ def fin.val.order_embedding (n) : @order_embedding (fin n) ℕ (<) (<) := ⟨⟨fin.val, @fin.eq_of_veq _⟩, λ a b, iff.rfl⟩ /-- The inclusion map `fin m → fin n` is an order embedding. -/ def fin_fin.order_embedding {m n} (h : m ≤ n) : @order_embedding (fin m) (fin n) (<) (<) := ⟨⟨λ ⟨x, h'⟩, ⟨x, lt_of_lt_of_le h' h⟩, λ ⟨a, _⟩ ⟨b, _⟩ h, by congr; injection h⟩, by intros; cases a; cases b; refl⟩ instance fin.lt.is_well_order (n) : is_well_order (fin n) (<) := (fin.val.order_embedding _).is_well_order /-- An order isomorphism is an equivalence that is also an order embedding. -/ structure order_iso {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) extends α ≃ β := (ord' : ∀ {a b}, r a b ↔ s (to_equiv a) (to_equiv b)) infix ` ≃o `:25 := order_iso namespace order_iso /-- Convert an `order_iso` to an `order_embedding`. This function is also available as a coercion but often it is easier to write `f.to_order_embedding` than to write explicitly `r` and `s` in the target type. -/ def to_order_embedding (f : r ≃o s) : r ≼o s := ⟨f.to_equiv.to_embedding, f.ord'⟩ instance : has_coe (r ≃o s) (r ≼o s) := ⟨to_order_embedding⟩ -- see Note [function coercion] instance : has_coe_to_fun (r ≃o s) := ⟨λ _, α → β, λ f, f⟩ @[simp] lemma to_order_embedding_eq_coe (f : r ≃o s) : f.to_order_embedding = f := rfl @[simp] lemma coe_coe_fn (f : r ≃o s) : ((f : r ≼o s) : α → β) = f := rfl theorem ord (f : r ≃o s) : ∀ {a b}, r a b ↔ s (f a) (f b) := f.ord' lemma ord'' {r : α → α → Prop} {s : β → β → Prop} (f : r ≃o s) {x y : α} : r x y ↔ s ((↑f : r ≼o s) x) ((↑f : r ≼o s) y) := f.ord @[simp] theorem coe_fn_mk (f : α ≃ β) (o) : (@order_iso.mk _ _ r s f o : α → β) = f := rfl @[simp] theorem coe_fn_to_equiv (f : r ≃o s) : (f.to_equiv : α → β) = f := rfl theorem to_equiv_injective : injective (to_equiv : (r ≃o s) → α ≃ β) | ⟨e₁, o₁⟩ ⟨e₂, o₂⟩ h := by { congr, exact h } /-- The map `coe_fn : (r ≃o s) → (r → s)` is injective. We can't use `function.injective` here but mimic its signature by using `⦃e₁ e₂⦄`. -/ theorem coe_fn_injective ⦃e₁ e₂ : r ≃o s⦄ (h : (e₁ : α → β) = e₂) : e₁ = e₂ := to_equiv_injective $ equiv.coe_fn_injective h @[ext] theorem ext {e₁ e₂ : r ≃o s} (h : ∀ x, e₁ x = e₂ x) : e₁ = e₂ := coe_fn_injective $ funext h /-- Identity map is an order isomorphism. -/ @[refl] protected def refl (r : α → α → Prop) : r ≃o r := ⟨equiv.refl _, λ a b, iff.rfl⟩ /-- Inverse map of an order isomorphism is an order isomorphism. -/ @[symm] protected def symm (f : r ≃o s) : s ≃o r := ⟨f.to_equiv.symm, λ a b, by cases f with f o; rw o; simp⟩ /-- Composition of two order isomorphisms is an order isomorphism. -/ @[trans] protected def trans (f₁ : r ≃o s) (f₂ : s ≃o t) : r ≃o t := ⟨f₁.to_equiv.trans f₂.to_equiv, λ a b, f₁.ord.trans f₂.ord⟩ /-- An order isomorphism is also an order isomorphism between dual orders. -/ def rsymm (f : r ≃o s) : (swap r) ≃o (swap s) := ⟨f.to_equiv, λ _ _, f.ord⟩ @[simp] theorem coe_fn_symm_mk (f o) : ((@order_iso.mk _ _ r s f o).symm : β → α) = f.symm := rfl @[simp] theorem refl_apply (x : α) : order_iso.refl r x = x := rfl @[simp] theorem trans_apply (f : r ≃o s) (g : s ≃o t) (a : α) : (f.trans g) a = g (f a) := rfl @[simp] theorem apply_symm_apply (e : r ≃o s) (x : β) : e (e.symm x) = x := e.to_equiv.apply_symm_apply x @[simp] theorem symm_apply_apply (e : r ≃o s) (x : α) : e.symm (e x) = x := e.to_equiv.symm_apply_apply x theorem rel_symm_apply (e : r ≃o s) {x y} : r x (e.symm y) ↔ s (e x) y := by rw [e.ord, e.apply_symm_apply] theorem symm_apply_rel (e : r ≃o s) {x y} : r (e.symm x) y ↔ s x (e y) := by rw [e.ord, e.apply_symm_apply] protected lemma bijective (e : r ≃o s) : bijective e := e.to_equiv.bijective protected lemma injective (e : r ≃o s) : injective e := e.to_equiv.injective protected lemma surjective (e : r ≃o s) : surjective e := e.to_equiv.surjective /-- Any equivalence lifts to an order isomorphism between `s` and its preimage. -/ protected def preimage (f : α ≃ β) (s : β → β → Prop) : f ⁻¹'o s ≃o s := ⟨f, λ a b, iff.rfl⟩ /-- A surjective order embedding is an order isomorphism. -/ noncomputable def of_surjective (f : r ≼o s) (H : surjective f) : r ≃o s := ⟨equiv.of_bijective f ⟨f.injective, H⟩, by simp [f.ord']⟩ @[simp] theorem of_surjective_coe (f : r ≼o s) (H) : (of_surjective f H : α → β) = f := rfl def sum_lex_congr {α₁ α₂ β₁ β₂ r₁ r₂ s₁ s₂} (e₁ : @order_iso α₁ α₂ r₁ r₂) (e₂ : @order_iso β₁ β₂ s₁ s₂) : sum.lex r₁ s₁ ≃o sum.lex r₂ s₂ := ⟨equiv.sum_congr e₁.to_equiv e₂.to_equiv, λ a b, by cases e₁ with f hf; cases e₂ with g hg; cases a; cases b; simp [hf, hg]⟩ def prod_lex_congr {α₁ α₂ β₁ β₂ r₁ r₂ s₁ s₂} (e₁ : @order_iso α₁ α₂ r₁ r₂) (e₂ : @order_iso β₁ β₂ s₁ s₂) : prod.lex r₁ s₁ ≃o prod.lex r₂ s₂ := ⟨equiv.prod_congr e₁.to_equiv e₂.to_equiv, λ a b, begin cases e₁ with f hf; cases e₂ with g hg, cases a with a₁ a₂; cases b with b₁ b₂, suffices : prod.lex r₁ s₁ (a₁, a₂) (b₁, b₂) ↔ prod.lex r₂ s₂ (f a₁, g a₂) (f b₁, g b₂), {simpa [hf, hg]}, split, { intro h, cases h with _ _ _ _ h _ _ _ h, { left, exact hf.1 h }, { right, exact hg.1 h } }, { generalize e : f b₁ = fb₁, intro h, cases h with _ _ _ _ h _ _ _ h, { subst e, left, exact hf.2 h }, { have := f.injective e, subst b₁, right, exact hg.2 h } } end⟩ instance : group (r ≃o r) := { one := order_iso.refl r, mul := λ f₁ f₂, f₂.trans f₁, inv := order_iso.symm, mul_assoc := λ f₁ f₂ f₃, rfl, one_mul := λ f, ext $ λ _, rfl, mul_one := λ f, ext $ λ _, rfl, mul_left_inv := λ f, ext f.symm_apply_apply } @[simp] lemma coe_one : ⇑(1 : r ≃o r) = id := rfl @[simp] lemma coe_mul (e₁ e₂ : r ≃o r) : ⇑(e₁ * e₂) = e₁ ∘ e₂ := rfl lemma mul_apply (e₁ e₂ : r ≃o r) (x : α) : (e₁ * e₂) x = e₁ (e₂ x) := rfl @[simp] lemma inv_apply_self (e : r ≃o r) (x) : e⁻¹ (e x) = x := e.symm_apply_apply x @[simp] lemma apply_inv_self (e : r ≃o r) (x) : e (e⁻¹ x) = x := e.apply_symm_apply x end order_iso /-- A subset `p : set α` embeds into `α` -/ def set_coe_embedding {α : Type*} (p : set α) : p ↪ α := ⟨subtype.val, @subtype.eq _ _⟩ /-- `subrel r p` is the inherited relation on a subset. -/ def subrel (r : α → α → Prop) (p : set α) : p → p → Prop := @subtype.val _ p ⁻¹'o r @[simp] theorem subrel_val (r : α → α → Prop) (p : set α) {a b} : subrel r p a b ↔ r a.1 b.1 := iff.rfl namespace subrel protected def order_embedding (r : α → α → Prop) (p : set α) : subrel r p ≼o r := ⟨set_coe_embedding _, λ a b, iff.rfl⟩ @[simp] theorem order_embedding_apply (r : α → α → Prop) (p a) : subrel.order_embedding r p a = a.1 := rfl instance (r : α → α → Prop) [is_well_order α r] (p : set α) : is_well_order p (subrel r p) := order_embedding.is_well_order (subrel.order_embedding r p) end subrel /-- Restrict the codomain of an order embedding -/ def order_embedding.cod_restrict (p : set β) (f : r ≼o s) (H : ∀ a, f a ∈ p) : r ≼o subrel s p := ⟨f.to_embedding.cod_restrict p H, f.ord'⟩ @[simp] theorem order_embedding.cod_restrict_apply (p) (f : r ≼o s) (H a) : order_embedding.cod_restrict p f H a = ⟨f a, H a⟩ := rfl section lattice_isos lemma order_iso.map_bot [order_bot α] [order_bot β] (f : ((≤) : α → α → Prop) ≃o ((≤) : β → β → Prop)) : f ⊥ = ⊥ := by { rw [eq_bot_iff, ← f.apply_symm_apply ⊥, ← f.ord], apply bot_le, } lemma order_iso.map_top [order_top α] [order_top β] (f : ((≤) : α → α → Prop) ≃o ((≤) : β → β → Prop)) : f ⊤ = ⊤ := by { rw [eq_top_iff, ← f.apply_symm_apply ⊤, ← f.ord], apply le_top, } variables {a₁ a₂ : α} lemma order_embedding.map_inf_le [semilattice_inf α] [semilattice_inf β] (f : ((≤) : α → α → Prop) ≼o ((≤) : β → β → Prop)) : f (a₁ ⊓ a₂) ≤ f a₁ ⊓ f a₂ := by simp [← f.ord] lemma order_iso.map_inf [semilattice_inf α] [semilattice_inf β] (f : ((≤) : α → α → Prop) ≃o ((≤) : β → β → Prop)) : f (a₁ ⊓ a₂) = f a₁ ⊓ f a₂ := begin apply le_antisymm, { apply f.to_order_embedding.map_inf_le }, rw [f.symm.ord, order_iso.symm_apply_apply], convert f.symm.to_order_embedding.map_inf_le; simp, end lemma order_embedding.le_map_sup [semilattice_sup α] [semilattice_sup β] (f : ((≤) : α → α → Prop) ≼o ((≤) : β → β → Prop)) : f a₁ ⊔ f a₂ ≤ f (a₁ ⊔ a₂) := by simp [← f.ord] lemma order_iso.map_sup [semilattice_sup α] [semilattice_sup β] (f : ((≤) : α → α → Prop) ≃o ((≤) : β → β → Prop)) : f (a₁ ⊔ a₂) = f a₁ ⊔ f a₂ := begin apply le_antisymm, swap, { apply f.to_order_embedding.le_map_sup }, rw [f.symm.ord, order_iso.symm_apply_apply], convert f.symm.to_order_embedding.le_map_sup; simp, end end lattice_isos
b7d9dd65657a2c2a9b48067fdd77b9ad00be15e6
1a61aba1b67cddccce19532a9596efe44be4285f
/library/algebra/order.lean
cabf2121948289308dbc5cb75caa4afdaec39583
[ "Apache-2.0" ]
permissive
eigengrau/lean
07986a0f2548688c13ba36231f6cdbee82abf4c6
f8a773be1112015e2d232661ce616d23f12874d0
refs/heads/master
1,610,939,198,566
1,441,352,386,000
1,441,352,494,000
41,903,576
0
0
null
1,441,352,210,000
1,441,352,210,000
null
UTF-8
Lean
false
false
16,652
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad Weak orders "≤", strict orders "<", and structures that include both. -/ import logic.eq logic.connectives algebra.binary algebra.priority open eq eq.ops namespace algebra variable {A : Type} /- overloaded symbols -/ structure has_le [class] (A : Type) := (le : A → A → Prop) structure has_lt [class] (A : Type) := (lt : A → A → Prop) infixl [priority algebra.prio] `<=` := has_le.le infixl [priority algebra.prio] `≤` := has_le.le infixl [priority algebra.prio] `<` := has_lt.lt definition has_le.ge [reducible] {A : Type} [s : has_le A] (a b : A) := b ≤ a notation [priority algebra.prio] a ≥ b := has_le.ge a b notation [priority algebra.prio] a >= b := has_le.ge a b definition has_lt.gt [reducible] {A : Type} [s : has_lt A] (a b : A) := b < a notation [priority algebra.prio] a > b := has_lt.gt a b /- weak orders -/ structure weak_order [class] (A : Type) extends has_le A := (le_refl : ∀a, le a a) (le_trans : ∀a b c, le a b → le b c → le a c) (le_antisymm : ∀a b, le a b → le b a → a = b) section variable [s : weak_order A] include s theorem le.refl (a : A) : a ≤ a := !weak_order.le_refl theorem le.trans [trans] {a b c : A} : a ≤ b → b ≤ c → a ≤ c := !weak_order.le_trans theorem ge.trans [trans] {a b c : A} (H1 : a ≥ b) (H2: b ≥ c) : a ≥ c := le.trans H2 H1 theorem le.antisymm {a b : A} : a ≤ b → b ≤ a → a = b := !weak_order.le_antisymm -- Alternate syntax. (Abbreviations do not migrate well.) theorem eq_of_le_of_ge {a b : A} : a ≤ b → b ≤ a → a = b := !le.antisymm end structure linear_weak_order [class] (A : Type) extends weak_order A := (le_total : ∀a b, le a b ∨ le b a) theorem le.total [s : linear_weak_order A] (a b : A) : a ≤ b ∨ b ≤ a := !linear_weak_order.le_total /- strict orders -/ structure strict_order [class] (A : Type) extends has_lt A := (lt_irrefl : ∀a, ¬ lt a a) (lt_trans : ∀a b c, lt a b → lt b c → lt a c) section variable [s : strict_order A] include s theorem lt.irrefl (a : A) : ¬ a < a := !strict_order.lt_irrefl theorem not_lt_self (a : A) : ¬ a < a := !lt.irrefl -- alternate syntax theorem lt.trans [trans] {a b c : A} : a < b → b < c → a < c := !strict_order.lt_trans theorem gt.trans [trans] {a b c : A} (H1 : a > b) (H2: b > c) : a > c := lt.trans H2 H1 theorem ne_of_lt {a b : A} (lt_ab : a < b) : a ≠ b := assume eq_ab : a = b, show false, from lt.irrefl b (eq_ab ▸ lt_ab) theorem ne_of_gt {a b : A} (gt_ab : a > b) : a ≠ b := ne.symm (ne_of_lt gt_ab) theorem lt.asymm {a b : A} (H : a < b) : ¬ b < a := assume H1 : b < a, lt.irrefl _ (lt.trans H H1) theorem not_lt_of_gt {a b : A} (H : a > b) : ¬ a < b := !lt.asymm H -- alternate syntax end /- well-founded orders -/ structure wf_strict_order [class] (A : Type) extends strict_order A := (wf_rec : ∀P : A → Type, (∀x, (∀y, lt y x → P y) → P x) → ∀x, P x) definition wf.rec_on {A : Type} [s : wf_strict_order A] {P : A → Type} (x : A) (H : ∀x, (∀y, wf_strict_order.lt y x → P y) → P x) : P x := wf_strict_order.wf_rec P H x theorem wf.ind_on.{u v} {A : Type.{u}} [s : wf_strict_order.{u 0} A] {P : A → Prop} (x : A) (H : ∀x, (∀y, wf_strict_order.lt y x → P y) → P x) : P x := wf.rec_on x H /- structures with a weak and a strict order -/ structure order_pair [class] (A : Type) extends weak_order A, has_lt A := (le_of_lt : ∀ a b, lt a b → le a b) (lt_of_lt_of_le : ∀ a b c, lt a b → le b c → lt a c) (lt_of_le_of_lt : ∀ a b c, le a b → lt b c → lt a c) (lt_irrefl : ∀ a, ¬ lt a a) section variable [s : order_pair A] variables {a b c : A} include s theorem le_of_lt : a < b → a ≤ b := !order_pair.le_of_lt theorem lt_of_lt_of_le [trans] : a < b → b ≤ c → a < c := !order_pair.lt_of_lt_of_le theorem lt_of_le_of_lt [trans] : a ≤ b → b < c → a < c := !order_pair.lt_of_le_of_lt private theorem lt_irrefl (s' : order_pair A) (a : A) : ¬ a < a := !order_pair.lt_irrefl private theorem lt_trans (s' : order_pair A) (a b c: A) (lt_ab : a < b) (lt_bc : b < c) : a < c := lt_of_lt_of_le lt_ab (le_of_lt lt_bc) definition order_pair.to_strict_order [trans-instance] [coercion] [reducible] : strict_order A := ⦃ strict_order, s, lt_irrefl := lt_irrefl s, lt_trans := lt_trans s ⦄ theorem gt_of_gt_of_ge [trans] (H1 : a > b) (H2 : b ≥ c) : a > c := lt_of_le_of_lt H2 H1 theorem gt_of_ge_of_gt [trans] (H1 : a ≥ b) (H2 : b > c) : a > c := lt_of_lt_of_le H2 H1 theorem not_le_of_gt (H : a > b) : ¬ a ≤ b := assume H1 : a ≤ b, lt.irrefl _ (lt_of_lt_of_le H H1) theorem not_lt_of_ge (H : a ≥ b) : ¬ a < b := assume H1 : a < b, lt.irrefl _ (lt_of_le_of_lt H H1) end structure strong_order_pair [class] (A : Type) extends weak_order A, has_lt A := (le_iff_lt_or_eq : ∀a b, le a b ↔ lt a b ∨ a = b) (lt_irrefl : ∀ a, ¬ lt a a) theorem le_iff_lt_or_eq [s : strong_order_pair A] {a b : A} : a ≤ b ↔ a < b ∨ a = b := !strong_order_pair.le_iff_lt_or_eq theorem lt_or_eq_of_le [s : strong_order_pair A] {a b : A} (le_ab : a ≤ b) : a < b ∨ a = b := iff.mp le_iff_lt_or_eq le_ab theorem le_of_lt_or_eq [s : strong_order_pair A] {a b : A} (lt_or_eq : a < b ∨ a = b) : a ≤ b := iff.mpr le_iff_lt_or_eq lt_or_eq private theorem lt_irrefl' [s : strong_order_pair A] (a : A) : ¬ a < a := !strong_order_pair.lt_irrefl private theorem le_of_lt' [s : strong_order_pair A] (a b : A) : a < b → a ≤ b := take Hlt, le_of_lt_or_eq (or.inl Hlt) private theorem lt_iff_le_and_ne [s : strong_order_pair A] {a b : A} : a < b ↔ (a ≤ b ∧ a ≠ b) := iff.intro (take Hlt, and.intro (le_of_lt_or_eq (or.inl Hlt)) (take Hab, absurd (Hab ▸ Hlt) !lt_irrefl')) (take Hand, have Hor : a < b ∨ a = b, from lt_or_eq_of_le (and.left Hand), or_resolve_left Hor (and.right Hand)) theorem lt_of_le_of_ne [s : strong_order_pair A] {a b : A} : a ≤ b → a ≠ b → a < b := take H1 H2, iff.mpr lt_iff_le_and_ne (and.intro H1 H2) private theorem ne_of_lt' [s : strong_order_pair A] {a b : A} (H : a < b) : a ≠ b := and.right ((iff.mp lt_iff_le_and_ne) H) private theorem lt_of_lt_of_le' [s : strong_order_pair A] (a b c : A) : a < b → b ≤ c → a < c := assume lt_ab : a < b, assume le_bc : b ≤ c, have le_ac : a ≤ c, from le.trans (le_of_lt' _ _ lt_ab) le_bc, have ne_ac : a ≠ c, from assume eq_ac : a = c, have le_ba : b ≤ a, from eq_ac⁻¹ ▸ le_bc, have eq_ab : a = b, from le.antisymm (le_of_lt' _ _ lt_ab) le_ba, show false, from ne_of_lt' lt_ab eq_ab, show a < c, from iff.mpr (lt_iff_le_and_ne) (and.intro le_ac ne_ac) theorem lt_of_le_of_lt' [s : strong_order_pair A] (a b c : A) : a ≤ b → b < c → a < c := assume le_ab : a ≤ b, assume lt_bc : b < c, have le_ac : a ≤ c, from le.trans le_ab (le_of_lt' _ _ lt_bc), have ne_ac : a ≠ c, from assume eq_ac : a = c, have le_cb : c ≤ b, from eq_ac ▸ le_ab, have eq_bc : b = c, from le.antisymm (le_of_lt' _ _ lt_bc) le_cb, show false, from ne_of_lt' lt_bc eq_bc, show a < c, from iff.mpr (lt_iff_le_and_ne) (and.intro le_ac ne_ac) definition strong_order_pair.to_order_pair [trans-instance] [coercion] [reducible] [s : strong_order_pair A] : order_pair A := ⦃ order_pair, s, lt_irrefl := lt_irrefl', le_of_lt := le_of_lt', lt_of_le_of_lt := lt_of_le_of_lt', lt_of_lt_of_le := lt_of_lt_of_le' ⦄ /- linear orders -/ structure linear_order_pair [class] (A : Type) extends order_pair A, linear_weak_order A structure linear_strong_order_pair [class] (A : Type) extends strong_order_pair A, linear_weak_order A definition linear_strong_order_pair.to_linear_order_pair [trans-instance] [coercion] [reducible] [s : linear_strong_order_pair A] : linear_order_pair A := ⦃ linear_order_pair, s, strong_order_pair.to_order_pair ⦄ section variable [s : linear_strong_order_pair A] variables (a b c : A) include s theorem lt.trichotomy : a < b ∨ a = b ∨ b < a := or.elim (le.total a b) (assume H : a ≤ b, or.elim (iff.mp !le_iff_lt_or_eq H) (assume H1, or.inl H1) (assume H1, or.inr (or.inl H1))) (assume H : b ≤ a, or.elim (iff.mp !le_iff_lt_or_eq H) (assume H1, or.inr (or.inr H1)) (assume H1, or.inr (or.inl (H1⁻¹)))) theorem lt.by_cases {a b : A} {P : Prop} (H1 : a < b → P) (H2 : a = b → P) (H3 : b < a → P) : P := or.elim !lt.trichotomy (assume H, H1 H) (assume H, or.elim H (assume H', H2 H') (assume H', H3 H')) theorem le_of_not_gt {a b : A} (H : ¬ a > b) : a ≤ b := lt.by_cases (assume H', absurd H' H) (assume H', H' ▸ !le.refl) (assume H', le_of_lt H') theorem lt_of_not_ge {a b : A} (H : ¬ a ≥ b) : a < b := lt.by_cases (assume H', absurd (le_of_lt H') H) (assume H', absurd (H' ▸ !le.refl) H) (assume H', H') theorem lt_or_ge : a < b ∨ a ≥ b := lt.by_cases (assume H1 : a < b, or.inl H1) (assume H1 : a = b, or.inr (H1 ▸ le.refl a)) (assume H1 : a > b, or.inr (le_of_lt H1)) theorem le_or_gt : a ≤ b ∨ a > b := !or.swap (lt_or_ge b a) theorem lt_or_gt_of_ne {a b : A} (H : a ≠ b) : a < b ∨ a > b := lt.by_cases (assume H1, or.inl H1) (assume H1, absurd H1 H) (assume H1, or.inr H1) end open decidable structure decidable_linear_order [class] (A : Type) extends linear_strong_order_pair A := (decidable_lt : decidable_rel lt) section variable [s : decidable_linear_order A] variables {a b c d : A} include s open decidable definition decidable_lt [instance] : decidable (a < b) := @decidable_linear_order.decidable_lt _ _ _ _ definition decidable_le [instance] : decidable (a ≤ b) := by_cases (assume H : a < b, inl (le_of_lt H)) (assume H : ¬ a < b, have H1 : b ≤ a, from le_of_not_gt H, by_cases (assume H2 : b < a, inr (not_le_of_gt H2)) (assume H2 : ¬ b < a, inl (le_of_not_gt H2))) definition has_decidable_eq [instance] : decidable (a = b) := by_cases (assume H : a ≤ b, by_cases (assume H1 : b ≤ a, inl (le.antisymm H H1)) (assume H1 : ¬ b ≤ a, inr (assume H2 : a = b, H1 (H2 ▸ le.refl a)))) (assume H : ¬ a ≤ b, (inr (assume H1 : a = b, H (H1 ▸ !le.refl)))) -- testing equality first may result in more definitional equalities definition lt.cases {B : Type} (a b : A) (t_lt t_eq t_gt : B) : B := if a = b then t_eq else (if a < b then t_lt else t_gt) theorem lt.cases_of_eq {B : Type} {a b : A} {t_lt t_eq t_gt : B} (H : a = b) : lt.cases a b t_lt t_eq t_gt = t_eq := if_pos H theorem lt.cases_of_lt {B : Type} {a b : A} {t_lt t_eq t_gt : B} (H : a < b) : lt.cases a b t_lt t_eq t_gt = t_lt := if_neg (ne_of_lt H) ⬝ if_pos H theorem lt.cases_of_gt {B : Type} {a b : A} {t_lt t_eq t_gt : B} (H : a > b) : lt.cases a b t_lt t_eq t_gt = t_gt := if_neg (ne.symm (ne_of_lt H)) ⬝ if_neg (lt.asymm H) definition min (a b : A) : A := if a ≤ b then a else b definition max (a b : A) : A := if a ≤ b then b else a /- these show min and max form a lattice -/ theorem min_le_left (a b : A) : min a b ≤ a := by_cases (assume H : a ≤ b, by rewrite [↑min, if_pos H]; apply le.refl) (assume H : ¬ a ≤ b, by rewrite [↑min, if_neg H]; apply le_of_lt (lt_of_not_ge H)) theorem min_le_right (a b : A) : min a b ≤ b := by_cases (assume H : a ≤ b, by rewrite [↑min, if_pos H]; apply H) (assume H : ¬ a ≤ b, by rewrite [↑min, if_neg H]; apply le.refl) theorem le_min {a b c : A} (H₁ : c ≤ a) (H₂ : c ≤ b) : c ≤ min a b := by_cases (assume H : a ≤ b, by rewrite [↑min, if_pos H]; apply H₁) (assume H : ¬ a ≤ b, by rewrite [↑min, if_neg H]; apply H₂) theorem le_max_left (a b : A) : a ≤ max a b := by_cases (assume H : a ≤ b, by rewrite [↑max, if_pos H]; apply H) (assume H : ¬ a ≤ b, by rewrite [↑max, if_neg H]; apply le.refl) theorem le_max_right (a b : A) : b ≤ max a b := by_cases (assume H : a ≤ b, by rewrite [↑max, if_pos H]; apply le.refl) (assume H : ¬ a ≤ b, by rewrite [↑max, if_neg H]; apply le_of_lt (lt_of_not_ge H)) theorem max_le {a b c : A} (H₁ : a ≤ c) (H₂ : b ≤ c) : max a b ≤ c := by_cases (assume H : a ≤ b, by rewrite [↑max, if_pos H]; apply H₂) (assume H : ¬ a ≤ b, by rewrite [↑max, if_neg H]; apply H₁) /- these are also proved for lattices, but with inf and sup in place of min and max -/ theorem eq_min {a b c : A} (H₁ : c ≤ a) (H₂ : c ≤ b) (H₃ : ∀{d}, d ≤ a → d ≤ b → d ≤ c) : c = min a b := le.antisymm (le_min H₁ H₂) (H₃ !min_le_left !min_le_right) theorem min.comm (a b : A) : min a b = min b a := eq_min !min_le_right !min_le_left (λ c H₁ H₂, le_min H₂ H₁) theorem min.assoc (a b c : A) : min (min a b) c = min a (min b c) := begin apply eq_min, { apply le.trans, apply min_le_left, apply min_le_left }, { apply le_min, apply le.trans, apply min_le_left, apply min_le_right, apply min_le_right }, { intros [d, H₁, H₂], apply le_min, apply le_min H₁, apply le.trans H₂, apply min_le_left, apply le.trans H₂, apply min_le_right } end theorem min.left_comm (a b c : A) : min a (min b c) = min b (min a c) := binary.left_comm (@min.comm A s) (@min.assoc A s) a b c theorem min.right_comm (a b c : A) : min (min a b) c = min (min a c) b := binary.right_comm (@min.comm A s) (@min.assoc A s) a b c theorem min_self (a : A) : min a a = a := by apply eq.symm; apply eq_min (le.refl a) !le.refl; intros; assumption theorem min_eq_left {a b : A} (H : a ≤ b) : min a b = a := by apply eq.symm; apply eq_min !le.refl H; intros; assumption theorem min_eq_right {a b : A} (H : b ≤ a) : min a b = b := eq.subst !min.comm (min_eq_left H) theorem eq_max {a b c : A} (H₁ : a ≤ c) (H₂ : b ≤ c) (H₃ : ∀{d}, a ≤ d → b ≤ d → c ≤ d) : c = max a b := le.antisymm (H₃ !le_max_left !le_max_right) (max_le H₁ H₂) theorem max.comm (a b : A) : max a b = max b a := eq_max !le_max_right !le_max_left (λ c H₁ H₂, max_le H₂ H₁) theorem max.assoc (a b c : A) : max (max a b) c = max a (max b c) := begin apply eq_max, { apply le.trans, apply le_max_left a b, apply le_max_left }, { apply max_le, apply le.trans, apply le_max_right a b, apply le_max_left, apply le_max_right }, { intros [d, H₁, H₂], apply max_le, apply max_le H₁, apply le.trans !le_max_left H₂, apply le.trans !le_max_right H₂} end theorem max.left_comm (a b c : A) : max a (max b c) = max b (max a c) := binary.left_comm (@max.comm A s) (@max.assoc A s) a b c theorem max.right_comm (a b c : A) : max (max a b) c = max (max a c) b := binary.right_comm (@max.comm A s) (@max.assoc A s) a b c theorem max_self (a : A) : max a a = a := by apply eq.symm; apply eq_max (le.refl a) !le.refl; intros; assumption theorem max_eq_left {a b : A} (H : b ≤ a) : max a b = a := by apply eq.symm; apply eq_max !le.refl H; intros; assumption theorem max_eq_right {a b : A} (H : a ≤ b) : max a b = b := eq.subst !max.comm (max_eq_left H) /- these rely on lt_of_lt -/ theorem min_eq_left_of_lt {a b : A} (H : a < b) : min a b = a := min_eq_left (le_of_lt H) theorem min_eq_right_of_lt {a b : A} (H : b < a) : min a b = b := min_eq_right (le_of_lt H) theorem max_eq_left_of_lt {a b : A} (H : b < a) : max a b = a := max_eq_left (le_of_lt H) theorem max_eq_right_of_lt {a b : A} (H : a < b) : max a b = b := max_eq_right (le_of_lt H) /- these use the fact that it is a linear ordering -/ theorem lt_min {a b c : A} (H₁ : a < b) (H₂ : a < c) : a < min b c := or.elim !le_or_gt (assume H : b ≤ c, by rewrite (min_eq_left H); apply H₁) (assume H : b > c, by rewrite (min_eq_right_of_lt H); apply H₂) theorem max_lt {a b c : A} (H₁ : a < c) (H₂ : b < c) : max a b < c := or.elim !le_or_gt (assume H : a ≤ b, by rewrite (max_eq_right H); apply H₂) (assume H : a > b, by rewrite (max_eq_left_of_lt H); apply H₁) end end algebra /- For reference, these are all the transitivity rules defined in this file: calc_trans le.trans calc_trans lt.trans calc_trans lt_of_lt_of_le calc_trans lt_of_le_of_lt calc_trans ge.trans calc_trans gt.trans calc_trans gt_of_gt_of_ge calc_trans gt_of_ge_of_gt -/
96ed1dc9ffcc9ac36e93bed9fc26b4eed7aed2ba
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
/10_Structures_and_Records.org.9.lean
d3576e50b760d5496706428a5b43807175509f6a
[]
no_license
cjmazey/lean-tutorial
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
refs/heads/master
1,610,286,098,832
1,447,124,923,000
1,447,124,923,000
43,082,433
0
0
null
null
null
null
UTF-8
Lean
false
false
136
lean
import standard open nat structure point (A : Type) := mk :: (x : A) (y : A) -- BEGIN check ⦃ point nat, x := 10, y := 20 ⦄ -- END