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
03710a712397afa64b15fa65ed450a5c27af9c8c
fa13c1c721affe5edc1a2bb53016ee9791ed3b8d
/src/lists-exercises.lean
c852920e3d502652f1ad940a0cf7159d50132e4c
[]
no_license
bbencina/Logic_lean_lists
4068cd202f9e4522dc21f9b53a9e2efc7fd53a62
1ed3acae62ce760f59d25c533778b9065ce1ce17
refs/heads/master
1,665,321,993,633
1,591,791,469,000
1,591,791,469,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
12,997
lean
/- This is a short tutorial on lean for the Logic in Computer Science course at the university of Ljubljana. -/ namespace logika_v_racunalnistvu /- Definitions of inductive types are made using the inductive keyword. Different constructors are separated by |. -/ inductive list (A : Type) : Type | nil : list | cons : A → list → list /- We open the namespace list, so that we can use nil and cons directly. -/ namespace list /- We will now define some basic operations on lists. -/ /- Direct definitions are made using the definition keyword, followed by := -/ definition unit {A : Type} (a : A) : list A := cons a nil /- A shorthand for definition is def, which may also be used. -/ /- Since the type of lists is an inductive type, we can make inductive definitions on list using pattern matching. The syntax is analogous to the syntax of the inductive type itself. Note that in pattern matching definitions, we don't use := at the end of the specification. -/ def fold {A : Type} {B : Type} (b : B) (μ : A → B → B) : list A → B | nil := b | (cons a l) := μ a (fold l) def map {A : Type} {B : Type} (f : A → B) : list A → list B := fold nil (cons ∘ f) def length {A : Type} : list A → ℕ := fold 0 (λ _ n, n + 1) /- Exercise 1: -/ def sum_list_ℕ : list ℕ → ℕ := fold 0 (+) /- Tests for sum_list_ℕ: -/ #reduce sum_list_ℕ nil #reduce sum_list_ℕ (cons 1 (cons 2 (cons 3 nil))) def concat {A : Type} : list A → list A → list A := fold id (λ a f l, cons a (f l)) #reduce concat (cons 1 nil) (nil) /- The idea of the flattening operation is to transform a list of lists into an ordinary list by iterated concatenation. For example, we should have flatten (cons (cons 1 (cons 2 nil)) (cons (cons 3 nil) (cons 4 (cons 5 nil)))) should evaluate to cons 1 (cons 2 (cons 3 (cons 4 (cons 5 nil)))) -/ /- Exercise 2: (Can it be done just by fold? Better safe than sorry.) -/ def flatten {A : Type} : list (list A) → list A | nil := nil | (cons hd tl) := concat hd (flatten tl) /- We have now finished defining our basic operations on lists. Let us check by some examples that the operations indeed do what they are supposed to do. With your mouse, hover over the #reduce keyword to see what each term reduces to. -/ #reduce concat (cons 1 (cons 2 (cons 3 nil))) (cons 4 (cons 5 nil)) #reduce flatten (cons (cons 1 (cons 2 nil)) (cons (cons 3 nil) (cons (cons 4 (cons 5 nil)) nil))) /- Of course, if you really want to know that your operations behave as expected, you should prove the relevant properties about them. This is what we will do next. -/ /- When proving theorems, we can also proceed by pattern matching. In a pattern matching argument we can recursively call the object we are defining on earlier instances. The arguments that we want to pattern-match on, must appear after the colon (:) in the specification of the theorem. -/ theorem map_id {A : Type} : ∀ (x : list A), map id x = x | nil := rfl | (cons a x) := calc map id (cons a x) = cons a (map id x) : rfl ... = cons a x : by rw map_id theorem map_composition {A : Type} {B : Type} {C : Type} (f : A → B) (g : B → C) : ∀ (x : list A), map (g ∘ f) x = map g (map f x) | nil := rfl | (cons a x) := calc map (g ∘ f) (cons a x) = cons (g (f a)) (map (g ∘ f) x) : rfl ... = cons (g (f a)) (map g (map f x)) : by rw map_composition ... = map g (map f (cons a x)) : rfl /- Next, we prove some properties concatenation. Concatenation of lists is an associative operation, and it satisfies the left and right unit laws.universe In order to prove associativity, we note that since concatenation is defined by induction on the left argument, we will again use induction on the left argument to prove this propoerty. The proof is presented by pattern matching. In the proof we will use the built-in equation compiler. We just calculate as if we were working on a sheet of paper, and each time we mention the reason why the equality holds. -/ theorem assoc_concat {A : Type} : ∀ (x y z : list A), concat (concat x y) z = concat x (concat y z) | nil _ _ := rfl | (cons a l) y z := calc concat (concat (cons a l) y) z = cons a (concat (concat l y) z) : by reflexivity ... = cons a (concat l (concat y z)) : by rw assoc_concat ... = concat (cons a l) (concat y z) : by reflexivity theorem left_unit_concat {A : Type} : ∀ (x : list A), concat nil x = x := eq.refl theorem right_unit_concat {A : Type} : ∀ (x : list A), concat x nil = x | nil := rfl | (cons a x) := show cons a (concat x nil) = cons a x, by rw right_unit_concat /- Next, we prove the elementary properties of the length function. -/ theorem length_nil {A : Type} : length (@nil A) = 0 := rfl theorem length_unit {A : Type} (a : A) : length (unit a) = 1 := rfl theorem length_concat {A : Type} : ∀ (x y : list A), length (concat x y) = length x + length y | nil y := calc length (concat nil y) = length y : rfl ... = 0 + length y : by rw nat.zero_add ... = length nil + length y : by rw length_nil | (cons a x) y := calc length (concat (cons a x) y) = length (concat x y) + 1 : rfl ... = (length x + length y) + 1 : by rw length_concat ... = (length x + 1) + length y : by rw nat.succ_add ... = (length (cons a x)) + length y : rfl /- Next, we prove the elemenatary properties of the flatten function. -/ /- Exercise 3: -/ theorem flatten_unit {A : Type} : ∀ (x : list A), flatten (unit x) = x | nil := rfl | (cons hd tl) := calc flatten (unit (cons hd tl)) = (cons hd (flatten (unit tl))) : rfl ... = (cons hd tl) : by rw flatten_unit ... = (cons hd tl) : rfl /- Exercise 4: -/ theorem flatten_map_unit {A : Type} : ∀ (x : list A), flatten (map unit x) = x | nil := rfl | (cons hd tl) := calc flatten (map unit (cons hd tl)) = flatten (cons (unit hd) (map unit tl)) : rfl ... = cons hd (flatten (map unit tl)) : rfl ... = cons hd tl : by rw flatten_map_unit ... = (cons hd tl) : rfl /- Exercise 5: -/ theorem length_flatten {A : Type} : ∀ (x : list (list A)), length (flatten x) = sum_list_ℕ (map length x) | nil := rfl | (cons hd tl) := calc length (flatten (cons hd tl)) = length (concat hd (flatten tl)) : rfl ... = (length hd) + (length (flatten tl)) : by rw length_concat ... = (length hd) + (sum_list_ℕ (map length tl)) : by rw length_flatten ... = sum_list_ℕ (map length (cons hd tl)) : rfl /- Exercise 6: -/ theorem flatten_concat {A : Type} : ∀ (x y : list (list A)), flatten (concat x y) = concat (flatten x) (flatten y) | nil _ := rfl | (cons hd tl) y := calc flatten (concat (cons hd tl) y) = flatten (cons hd (concat tl y)) : rfl ... = concat hd (flatten (concat tl y)) : rfl ... = concat hd (concat (flatten tl) (flatten y)) : by rw flatten_concat ... = concat (concat hd (flatten tl)) (flatten y) : by rw assoc_concat ... = concat (flatten (cons hd tl)) (flatten y) : rfl /- Exercise 7: -/ theorem flatten_flatten {A : Type} : ∀ (x : list (list (list A))), flatten (flatten x) = flatten (map flatten x) | nil := rfl | (cons hd tl) := calc flatten (flatten (cons hd tl)) = flatten (concat hd (flatten tl)) : rfl ... = concat (flatten hd) (flatten (flatten tl)) : by rw flatten_concat ... = concat (flatten hd) (flatten (map flatten tl)) : by rw flatten_flatten ... = flatten (map flatten (cons hd tl)) : rfl /- This concludes our coverage of lists in Lean. -/ end list /- Next, we study lists of a fixed length. They are a natural example of a dependent type.-/ inductive vector (A : Type) : ℕ → Type | nil : vector 0 | cons : ∀ {n : ℕ}, A → vector n → vector (n+1) namespace vector def map {A : Type} {B : Type} (f : A → B) : ∀ {n : ℕ}, vector A n → vector B n | 0 nil := nil | (n+1) (cons a x) := cons (f a) (map x) def concat {A : Type} : ∀ {m n : ℕ}, vector A m → vector A n → vector A (m+n) | 0 n nil y := begin rw nat.zero_add, exact y, end | (m+1) n (cons a x) y := begin rw nat.succ_add, exact cons a (concat x y), end def head {A : Type} : ∀ {n : ℕ}, vector A (n+1) → A | n (cons a x) := a def tail {A : Type} : ∀ {n : ℕ}, vector A (n+1) → vector A n | n (cons a x) := x /- Using lists of fixed length, we can define matrices. The type Matrix m n A is the type of matrices with m rows and n columns and with coefficients in A. -/ def Matrix (m n : ℕ) (A : Type) : Type := vector (vector A n) m def top_row {A : Type} {m n : ℕ} : Matrix (m+1) n A → vector A n := head def tail_vertical {A : Type} {m n : ℕ} : Matrix (m+1) n A → Matrix m n A := tail def left_column {A : Type} {m n : ℕ} : Matrix m (n+1) A → vector A m := map head def tail_horizontal {A : Type} {m n : ℕ} : Matrix m (n+1) A → Matrix m n A := map tail /- Since matrices are rectangular, we have a horizontal as well as vertical empty matrices. -/ def nil_vertical {A : Type} {n : ℕ} : Matrix 0 n A := nil theorem eq_nil_vertical {A : Type} : ∀ {n : ℕ} (x : Matrix 0 n A), x = nil_vertical | 0 nil := rfl | (n+1) nil := rfl def nil_horizontal {A : Type} : ∀ {m : ℕ}, Matrix m 0 A | 0 := nil | (m+1) := cons nil nil_horizontal theorem eq_nil_horizontal {A : Type} : ∀ {m : ℕ} (x : Matrix m 0 A), x = nil_horizontal | 0 nil := rfl | (m+1) (cons nil M) := calc cons nil M = cons nil nil_horizontal : by rw eq_nil_horizontal M ... = nil_horizontal : rfl /- Similarly, there is a horizontal cons and a vertical cons. -/ /- cons_vertical adds a new row from the top. -/ def cons_vertical {A : Type} {m n : ℕ} : vector A n → Matrix m n A → Matrix (m+1) n A := cons /- cons_horizontal adds a new column from the left. -/ def cons_horizontal {A : Type} : ∀ {m n : ℕ}, vector A m → Matrix m n A → Matrix m (n+1) A | 0 n nil M := nil | (m+1) n (cons a x) M := cons (cons a (top_row M)) (cons_horizontal x (tail_vertical M)) /- We define the transposition of a matrix. -/ def transpose {A : Type} : ∀ {m n : ℕ}, Matrix m n A → Matrix n m A | 0 n M := nil_horizontal | (m+1) n (cons x M) := cons_horizontal x (transpose M) /- The following two theorems show how transpose interacts with the basic operations on matrices. These will help to show that transposition is an involution. -/ /- Exercise 9: (moved here because trivial and I want to use it in Ex. 8)-/ theorem transpose_cons_vertical {A : Type} : ∀ {m n : ℕ} (x : vector A n) (M : Matrix m n A), transpose (cons_vertical x M) = cons_horizontal x (transpose M) | m 0 _ _ := rfl | _ n _ _ := rfl /- Exercise 8: -/ theorem transpose_cons_horizontal {A : Type} : ∀ {m n : ℕ} (x : vector A m) (M : Matrix m n A), transpose (cons_horizontal x M) = cons_vertical x (transpose M) | 0 0 nil nil := rfl | 0 n nil M := rfl | (m+1) n (cons a x) (cons v M) := calc transpose (cons_horizontal (cons a x) (cons v M)) = transpose (cons_vertical (cons a v) (cons_horizontal x M)) : rfl ... = cons_horizontal (cons a v) (transpose (cons_horizontal x M)) : by rw transpose_cons_vertical ... = cons_horizontal (cons a v) (cons_vertical x (transpose M)) : by rw transpose_cons_horizontal ... = cons_horizontal (cons a v) (cons x (transpose M)) : rfl ... = cons (cons a (top_row (cons x (transpose M)))) (cons_horizontal v (tail_vertical (cons x (transpose M)))) : rfl ... = cons (cons a (top_row (cons_vertical x (transpose M)))) (cons_horizontal v (tail_vertical (cons_vertical x (transpose M)))) : rfl ... = cons (cons a x) (cons_horizontal v (transpose M)) : rfl ... = cons (cons a x) (transpose (cons_vertical v M)) : by rw transpose_cons_vertical ... = cons (cons a x) (transpose (cons v M)) : rfl ... = cons_vertical (cons a x) (transpose (cons v M)) : rfl /- Note: A bunch of these rfl's can be commented out for the proof to still work. Of course I leave them in for legibility's sake, otherwise I'd be lost the next time I try to read this. -/ /- We finally show that transposition is an involution. -/ theorem transpose_transpose {A : Type} : ∀ {m n : ℕ} (M : Matrix m n A), transpose (transpose M) = M | 0 0 nil := rfl | 0 (n+1) nil := rfl | m n (cons v M) := calc transpose (transpose (cons v M)) = transpose (transpose (cons_vertical v M)) : rfl ... = transpose (cons_horizontal v (transpose M)) : by rw transpose_cons_vertical ... = cons_vertical v (transpose (transpose M)) : by rw transpose_cons_horizontal ... = cons_vertical v M : by rw transpose_transpose ... = cons v M : rfl end vector end logika_v_racunalnistvu
ad150017ddc9d7be4c3cfd1610098b6736a09879
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/combinatorics/pigeonhole.lean
c3b26ed38bac7d2d64055bc0abb7cb04fa85cd12
[ "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
19,346
lean
/- Copyright (c) 2020 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller, Yury Kudryashov -/ import data.set.finite import data.nat.modeq import algebra.big_operators.order /-! # Pigeonhole principles Given pigeons (possibly infinitely many) in pigeonholes, the pigeonhole principle states that, if there are more pigeons than pigeonholes, then there is a pigeonhole with two or more pigeons. There are a few variations on this statement, and the conclusion can be made stronger depending on how many pigeons you know you might have. The basic statements of the pigeonhole principle appear in the following locations: * `data.finset.basic` has `finset.exists_ne_map_eq_of_card_lt_of_maps_to` * `data.fintype.basic` has `fintype.exists_ne_map_eq_of_card_lt` * `data.fintype.basic` has `fintype.exists_ne_map_eq_of_infinite` * `data.fintype.basic` has `fintype.exists_infinite_fiber` * `data.set.finite` has `set.infinite.exists_ne_map_eq_of_maps_to` This module gives access to these pigeonhole principles along with 20 more. The versions vary by: * using a function between `fintype`s or a function between possibly infinite types restricted to `finset`s; * counting pigeons by a general weight function (`∑ x in s, w x`) or by heads (`finset.card s`); * using strict or non-strict inequalities; * establishing upper or lower estimate on the number (or the total weight) of the pigeons in one pigeonhole; * in case when we count pigeons by some weight function `w` and consider a function `f` between `finset`s `s` and `t`, we can either assume that each pigeon is in one of the pigeonholes (`∀ x ∈ s, f x ∈ t`), or assume that for `y ∉ t`, the total weight of the pigeons in this pigeonhole `∑ x in s.filter (λ x, f x = y), w x` is nonpositive or nonnegative depending on the inequality we are proving. Lemma names follow `mathlib` convention (e.g., `finset.exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum`); "pigeonhole principle" is mentioned in the docstrings instead of the names. ## See also * `ordinal.infinite_pigeonhole`: pigeonhole principle for cardinals, formulated using cofinality; * `measure_theory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure`, `measure_theory.exists_nonempty_inter_of_measure_univ_lt_sum_measure`: pigeonhole principle in a measure space. ## Tags pigeonhole principle -/ universes u v w variables {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] open_locale big_operators namespace finset variables {s : finset α} {t : finset β} {f : α → β} {w : α → M} {b : M} {n : ℕ} /-! ### The pigeonhole principles on `finset`s, pigeons counted by weight In this section we prove the following version of the pigeonhole principle: if the total weight of a finite set of pigeons is greater than `n • b`, and they are sorted into `n` pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is greateer than `b`, and a few variations of this theorem. The principle is formalized in the following way, see `finset.exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum`: if `f : α → β` is a function which maps all elements of `s : finset α` to `t : finset β` and `card t • b < ∑ x in s, w x`, where `w : α → M` is a weight function taking values in a `linear_ordered_cancel_add_comm_monoid`, then for some `y ∈ t`, the sum of the weights of all `x ∈ s` such that `f x = y` is greater than `b`. There are a few bits we can change in this theorem: * reverse all inequalities, with obvious adjustments to the name; * replace the assumption `∀ a ∈ s, f a ∈ t` with `∀ y ∉ t, (∑ x in s.filter (λ x, f x = y), w x) ≤ 0`, and replace `of_maps_to` with `of_sum_fiber_nonpos` in the name; * use non-strict inequalities assuming `t` is nonempty. We can do all these variations independently, so we have eight versions of the theorem. -/ /-! #### Strict inequality versions -/ /-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version: if the total weight of a finite set of pigeons is greater than `n • b`, and they are sorted into `n` pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is greater than `b`. -/ lemma exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum (hf : ∀ a ∈ s, f a ∈ t) (hb : t.card • b < ∑ x in s, w x) : ∃ y ∈ t, b < ∑ x in s.filter (λ x, f x = y), w x := exists_lt_of_sum_lt $ by simpa only [sum_fiberwise_of_maps_to hf, sum_const] /-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version: if the total weight of a finite set of pigeons is less than `n • b`, and they are sorted into `n` pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is less than `b`. -/ lemma exists_sum_fiber_lt_of_maps_to_of_sum_lt_nsmul (hf : ∀ a ∈ s, f a ∈ t) (hb : (∑ x in s, w x) < t.card • b) : ∃ y ∈ t, (∑ x in s.filter (λ x, f x = y), w x) < b := @exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum α β (order_dual M) _ _ _ _ _ _ _ hf hb /-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version: if the total weight of a finite set of pigeons is greater than `n • b`, they are sorted into some pigeonholes, and for all but `n` pigeonholes the total weight of the pigeons there is nonpositive, then for at least one of these `n` pigeonholes, the total weight of the pigeons in this pigeonhole is greater than `b`. -/ lemma exists_lt_sum_fiber_of_sum_fiber_nonpos_of_nsmul_lt_sum (ht : ∀ y ∉ t, (∑ x in s.filter (λ x, f x = y), w x) ≤ 0) (hb : t.card • b < ∑ x in s, w x) : ∃ y ∈ t, b < ∑ x in s.filter (λ x, f x = y), w x := exists_lt_of_sum_lt $ calc (∑ y in t, b) < ∑ x in s, w x : by simpa ... ≤ ∑ y in t, ∑ x in s.filter (λ x, f x = y), w x : sum_le_sum_fiberwise_of_sum_fiber_nonpos ht /-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version: if the total weight of a finite set of pigeons is less than `n • b`, they are sorted into some pigeonholes, and for all but `n` pigeonholes the total weight of the pigeons there is nonnegative, then for at least one of these `n` pigeonholes, the total weight of the pigeons in this pigeonhole is less than `b`. -/ lemma exists_sum_fiber_lt_of_sum_fiber_nonneg_of_sum_lt_nsmul (ht : ∀ y ∉ t, (0:M) ≤ ∑ x in s.filter (λ x, f x = y), w x) (hb : (∑ x in s, w x) < t.card • b) : ∃ y ∈ t, (∑ x in s.filter (λ x, f x = y), w x) < b := @exists_lt_sum_fiber_of_sum_fiber_nonpos_of_nsmul_lt_sum α β (order_dual M) _ _ _ _ _ _ _ ht hb /-! #### Non-strict inequality versions -/ /-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality version: if the total weight of a finite set of pigeons is greater than or equal to `n • b`, and they are sorted into `n > 0` pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is greater than or equal to `b`. -/ lemma exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum (hf : ∀ a ∈ s, f a ∈ t) (ht : t.nonempty) (hb : t.card • b ≤ ∑ x in s, w x) : ∃ y ∈ t, b ≤ ∑ x in s.filter (λ x, f x = y), w x := exists_le_of_sum_le ht $ by simpa only [sum_fiberwise_of_maps_to hf, sum_const] /-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality version: if the total weight of a finite set of pigeons is less than or equal to `n • b`, and they are sorted into `n > 0` pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is less than or equal to `b`. -/ lemma exists_sum_fiber_le_of_maps_to_of_sum_le_nsmul (hf : ∀ a ∈ s, f a ∈ t) (ht : t.nonempty) (hb : (∑ x in s, w x) ≤ t.card • b) : ∃ y ∈ t, (∑ x in s.filter (λ x, f x = y), w x) ≤ b := @exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum α β (order_dual M) _ _ _ _ _ _ _ hf ht hb /-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality version: if the total weight of a finite set of pigeons is greater than or equal to `n • b`, they are sorted into some pigeonholes, and for all but `n > 0` pigeonholes the total weight of the pigeons there is nonpositive, then for at least one of these `n` pigeonholes, the total weight of the pigeons in this pigeonhole is greater than or equal to `b`. -/ lemma exists_le_sum_fiber_of_sum_fiber_nonpos_of_nsmul_le_sum (hf : ∀ y ∉ t, (∑ x in s.filter (λ x, f x = y), w x) ≤ 0) (ht : t.nonempty) (hb : t.card • b ≤ ∑ x in s, w x) : ∃ y ∈ t, b ≤ ∑ x in s.filter (λ x, f x = y), w x := exists_le_of_sum_le ht $ calc (∑ y in t, b) ≤ ∑ x in s, w x : by simpa ... ≤ ∑ y in t, ∑ x in s.filter (λ x, f x = y), w x : sum_le_sum_fiberwise_of_sum_fiber_nonpos hf /-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality version: if the total weight of a finite set of pigeons is less than or equal to `n • b`, they are sorted into some pigeonholes, and for all but `n > 0` pigeonholes the total weight of the pigeons there is nonnegative, then for at least one of these `n` pigeonholes, the total weight of the pigeons in this pigeonhole is less than or equal to `b`. -/ lemma exists_sum_fiber_le_of_sum_fiber_nonneg_of_sum_le_nsmul (hf : ∀ y ∉ t, (0:M) ≤ ∑ x in s.filter (λ x, f x = y), w x) (ht : t.nonempty) (hb : (∑ x in s, w x) ≤ t.card • b) : ∃ y ∈ t, (∑ x in s.filter (λ x, f x = y), w x) ≤ b := @exists_le_sum_fiber_of_sum_fiber_nonpos_of_nsmul_le_sum α β (order_dual M) _ _ _ _ _ _ _ hf ht hb /-! ### The pigeonhole principles on `finset`s, pigeons counted by heads In this section we formalize a few versions of the following pigeonhole principle: there is a pigeonhole with at least as many pigeons as the ceiling of the average number of pigeons across all pigeonholes. First, we can use strict or non-strict inequalities. While the versions with non-strict inequalities are weaker than those with strict inequalities, sometimes it might be more convenient to apply the weaker version. Second, we can either state that there exists a pigeonhole with at least `n` pigeons, or state that there exists a pigeonhole with at most `n` pigeons. In the latter case we do not need the assumption `∀ a ∈ s, f a ∈ t`. So, we prove four theorems: `finset.exists_lt_card_fiber_of_maps_to_of_mul_lt_card`, `finset.exists_le_card_fiber_of_maps_to_of_mul_le_card`, `finset.exists_card_fiber_lt_of_card_lt_mul`, and `finset.exists_card_fiber_le_of_card_le_mul`. -/ /-- The pigeonhole principle for finitely many pigeons counted by heads: there is a pigeonhole with at least as many pigeons as the ceiling of the average number of pigeons across all pigeonholes. ("The maximum is at least the mean" specialized to integers.) More formally, given a function between finite sets `s` and `t` and a natural number `n` such that `card t * n < card s`, there exists `y ∈ t` such that its preimage in `s` has more than `n` elements. -/ lemma exists_lt_card_fiber_of_mul_lt_card_of_maps_to (hf : ∀ a ∈ s, f a ∈ t) (hn : t.card * n < s.card) : ∃ y ∈ t, n < (s.filter (λ x, f x = y)).card := begin simp only [card_eq_sum_ones], apply exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum hf, simpa end /-- The pigeonhole principle for finitely many pigeons counted by heads: there is a pigeonhole with at most as many pigeons as the floor of the average number of pigeons across all pigeonholes. ("The minimum is at most the mean" specialized to integers.) More formally, given a function `f`, a finite sets `s` in its domain, a finite set `t` in its codomain, and a natural number `n` such that `card s < card t * n`, there exists `y ∈ t` such that its preimage in `s` has less than `n` elements. -/ lemma exists_card_fiber_lt_of_card_lt_mul (hn : s.card < t.card * n) : ∃ y ∈ t, (s.filter (λ x, f x = y)).card < n:= begin simp only [card_eq_sum_ones], apply exists_sum_fiber_lt_of_sum_fiber_nonneg_of_sum_lt_nsmul (λ _ _, nat.zero_le _), simpa end /-- The pigeonhole principle for finitely many pigeons counted by heads: given a function between finite sets `s` and `t` and a natural number `n` such that `card t * n ≤ card s`, there exists `y ∈ t` such that its preimage in `s` has at least `n` elements. See also `finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to` for a stronger statement. -/ lemma exists_le_card_fiber_of_mul_le_card_of_maps_to (hf : ∀ a ∈ s, f a ∈ t) (ht : t.nonempty) (hn : t.card * n ≤ s.card) : ∃ y ∈ t, n ≤ (s.filter (λ x, f x = y)).card := begin simp only [card_eq_sum_ones], apply exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum hf ht, simpa end /-- The pigeonhole principle for finitely many pigeons counted by heads: given a function `f`, a finite sets `s` in its domain, a finite set `t` in its codomain, and a natural number `n` such that `card s ≤ card t * n`, there exists `y ∈ t` such that its preimage in `s` has no more than `n` elements. See also `finset.exists_card_fiber_lt_of_card_lt_mul` for a stronger statement. -/ lemma exists_card_fiber_le_of_card_le_mul (ht : t.nonempty) (hn : s.card ≤ t.card * n) : ∃ y ∈ t, (s.filter (λ x, f x = y)).card ≤ n:= begin simp only [card_eq_sum_ones], apply exists_sum_fiber_le_of_sum_fiber_nonneg_of_sum_le_nsmul (λ _ _, nat.zero_le _) ht, simpa end end finset namespace fintype open finset variables [fintype α] [fintype β] (f : α → β) {w : α → M} {b : M} {n : ℕ} /-! ### The pigeonhole principles on `fintypes`s, pigeons counted by weight In this section we specialize theorems from the previous section to the special case of functions between `fintype`s and `s = univ`, `t = univ`. In this case the assumption `∀ x ∈ s, f x ∈ t` always holds, so we have four theorems instead of eight. -/ /-- The pigeonhole principle for finitely many pigeons of different weights, strict inequality version: there is a pigeonhole with the total weight of pigeons in it greater than `b` provided that the total number of pigeonholes times `b` is less than the total weight of all pigeons. -/ lemma exists_lt_sum_fiber_of_nsmul_lt_sum (hb : card β • b < ∑ x, w x) : ∃ y, b < ∑ x in univ.filter (λ x, f x = y), w x := let ⟨y, _, hy⟩ := exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum (λ _ _, mem_univ _) hb in ⟨y, hy⟩ /-- The pigeonhole principle for finitely many pigeons of different weights, non-strict inequality version: there is a pigeonhole with the total weight of pigeons in it greater than or equal to `b` provided that the total number of pigeonholes times `b` is less than or equal to the total weight of all pigeons. -/ lemma exists_le_sum_fiber_of_nsmul_le_sum [nonempty β] (hb : card β • b ≤ ∑ x, w x) : ∃ y, b ≤ ∑ x in univ.filter (λ x, f x = y), w x := let ⟨y, _, hy⟩ := exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum (λ _ _, mem_univ _) univ_nonempty hb in ⟨y, hy⟩ /-- The pigeonhole principle for finitely many pigeons of different weights, strict inequality version: there is a pigeonhole with the total weight of pigeons in it less than `b` provided that the total number of pigeonholes times `b` is greater than the total weight of all pigeons. -/ lemma exists_sum_fiber_lt_of_sum_lt_nsmul (hb : (∑ x, w x) < card β • b) : ∃ y, (∑ x in univ.filter (λ x, f x = y), w x) < b := @exists_lt_sum_fiber_of_nsmul_lt_sum α β (order_dual M) _ _ _ _ _ w b hb /-- The pigeonhole principle for finitely many pigeons of different weights, non-strict inequality version: there is a pigeonhole with the total weight of pigeons in it less than or equal to `b` provided that the total number of pigeonholes times `b` is greater than or equal to the total weight of all pigeons. -/ lemma exists_sum_fiber_le_of_sum_le_nsmul [nonempty β] (hb : (∑ x, w x) ≤ card β • b) : ∃ y, (∑ x in univ.filter (λ x, f x = y), w x) ≤ b := @exists_le_sum_fiber_of_nsmul_le_sum α β (order_dual M) _ _ _ _ _ w b _ hb /-- The strong pigeonhole principle for finitely many pigeons and pigeonholes. There is a pigeonhole with at least as many pigeons as the ceiling of the average number of pigeons across all pigeonholes. ("The maximum is at least the mean" specialized to integers.) More formally, given a function `f` between finite types `α` and `β` and a number `n` such that `card β * n < card α`, there exists an element `y : β` such that its preimage has more than `n` elements. -/ lemma exists_lt_card_fiber_of_mul_lt_card (hn : card β * n < card α) : ∃ y : β, n < (univ.filter (λ x, f x = y)).card := let ⟨y, _, h⟩ := exists_lt_card_fiber_of_mul_lt_card_of_maps_to (λ _ _, mem_univ _) hn in ⟨y, h⟩ /-- The strong pigeonhole principle for finitely many pigeons and pigeonholes. There is a pigeonhole with at most as many pigeons as the floor of the average number of pigeons across all pigeonholes. ("The minimum is at most the mean" specialized to integers.) More formally, given a function `f` between finite types `α` and `β` and a number `n` such that `card α < card β * n`, there exists an element `y : β` such that its preimage has less than `n` elements. -/ lemma exists_card_fiber_lt_of_card_lt_mul (hn : card α < card β * n) : ∃ y : β, (univ.filter (λ x, f x = y)).card < n := let ⟨y, _, h⟩ := exists_card_fiber_lt_of_card_lt_mul hn in ⟨y, h⟩ /-- The strong pigeonhole principle for finitely many pigeons and pigeonholes. Given a function `f` between finite types `α` and `β` and a number `n` such that `card β * n ≤ card α`, there exists an element `y : β` such that its preimage has at least `n` elements. See also `fintype.exists_lt_card_fiber_of_mul_lt_card` for a stronger statement. -/ lemma exists_le_card_fiber_of_mul_le_card [nonempty β] (hn : card β * n ≤ card α) : ∃ y : β, n ≤ (univ.filter (λ x, f x = y)).card := let ⟨y, _, h⟩ := exists_le_card_fiber_of_mul_le_card_of_maps_to (λ _ _, mem_univ _) univ_nonempty hn in ⟨y, h⟩ /-- The strong pigeonhole principle for finitely many pigeons and pigeonholes. Given a function `f` between finite types `α` and `β` and a number `n` such that `card α ≤ card β * n`, there exists an element `y : β` such that its preimage has at most `n` elements. See also `fintype.exists_card_fiber_lt_of_card_lt_mul` for a stronger statement. -/ lemma exists_card_fiber_le_of_card_le_mul [nonempty β] (hn : card α ≤ card β * n) : ∃ y : β, (univ.filter (λ x, f x = y)).card ≤ n := let ⟨y, _, h⟩ := exists_card_fiber_le_of_card_le_mul univ_nonempty hn in ⟨y, h⟩ end fintype namespace nat open set /-- If `s` is an infinite set of natural numbers and `k > 0`, then `s` contains two elements `m < n` that are equal mod `k`. -/ theorem exists_lt_modeq_of_infinite {s : set ℕ} (hs : s.infinite) {k : ℕ} (hk : 0 < k) : ∃ (m ∈ s) (n ∈ s), m < n ∧ m ≡ n [MOD k] := hs.exists_lt_map_eq_of_maps_to (λ n _, show n % k ∈ Iio k, from nat.mod_lt n hk) $ finite_lt_nat k end nat
0a679d7048455dce5ff8692b71248a25f3e652c7
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/algebra/group/with_one/basic.lean
303a93390afdaac535cc1162b6f80ee90c1b2e13
[ "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
4,278
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johan Commelin -/ import algebra.group.with_one.defs import algebra.hom.equiv.basic /-! # More operations on `with_one` and `with_zero` > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines various bundled morphisms on `with_one` and `with_zero` that were not available in `algebra/group/with_one/defs`. ## Main definitions * `with_one.lift`, `with_zero.lift` * `with_one.map`, `with_zero.map` -/ universes u v w variables {α : Type u} {β : Type v} {γ : Type w} namespace with_one section -- workaround: we make `with_one`/`with_zero` irreducible for this definition, otherwise `simps` -- will unfold it in the statement of the lemma it generates. local attribute [irreducible] with_one with_zero /-- `coe` as a bundled morphism -/ @[to_additive "`coe` as a bundled morphism", simps apply] def coe_mul_hom [has_mul α] : α →ₙ* (with_one α) := { to_fun := coe, map_mul' := λ x y, rfl } end section lift local attribute [semireducible] with_one with_zero variables [has_mul α] [mul_one_class β] /-- Lift a semigroup homomorphism `f` to a bundled monoid homorphism. -/ @[to_additive "Lift an add_semigroup homomorphism `f` to a bundled add_monoid homorphism."] def lift : (α →ₙ* β) ≃ (with_one α →* β) := { to_fun := λ f, { to_fun := λ x, option.cases_on x 1 f, map_one' := rfl, map_mul' := λ x y, with_one.cases_on x (by { rw one_mul, exact (one_mul _).symm }) $ λ x, with_one.cases_on y (by { rw mul_one, exact (mul_one _).symm }) $ λ y, f.map_mul x y }, inv_fun := λ F, F.to_mul_hom.comp coe_mul_hom, left_inv := λ f, mul_hom.ext $ λ x, rfl, right_inv := λ F, monoid_hom.ext $ λ x, with_one.cases_on x F.map_one.symm $ λ x, rfl } variables (f : α →ₙ* β) @[simp, to_additive] lemma lift_coe (x : α) : lift f x = f x := rfl @[simp, to_additive] lemma lift_one : lift f 1 = 1 := rfl @[to_additive] theorem lift_unique (f : with_one α →* β) : f = lift (f.to_mul_hom.comp coe_mul_hom) := (lift.apply_symm_apply f).symm end lift section map variables [has_mul α] [has_mul β] [has_mul γ] /-- Given a multiplicative map from `α → β` returns a monoid homomorphism from `with_one α` to `with_one β` -/ @[to_additive "Given an additive map from `α → β` returns an add_monoid homomorphism from `with_zero α` to `with_zero β`"] def map (f : α →ₙ* β) : with_one α →* with_one β := lift (coe_mul_hom.comp f) @[simp, to_additive] lemma map_coe (f : α →ₙ* β) (a : α) : map f (a : with_one α) = f a := lift_coe _ _ @[simp, to_additive] lemma map_id : map (mul_hom.id α) = monoid_hom.id (with_one α) := by { ext, induction x using with_one.cases_on; refl } @[to_additive] lemma map_map (f : α →ₙ* β) (g : β →ₙ* γ) (x) : map g (map f x) = map (g.comp f) x := by { induction x using with_one.cases_on; refl } @[simp, to_additive] lemma map_comp (f : α →ₙ* β) (g : β →ₙ* γ) : map (g.comp f) = (map g).comp (map f) := monoid_hom.ext $ λ x, (map_map f g x).symm /-- A version of `equiv.option_congr` for `with_one`. -/ @[to_additive "A version of `equiv.option_congr` for `with_zero`.", simps apply] def _root_.mul_equiv.with_one_congr (e : α ≃* β) : with_one α ≃* with_one β := { to_fun := map e.to_mul_hom, inv_fun := map e.symm.to_mul_hom, left_inv := λ x, (map_map _ _ _).trans $ by induction x using with_one.cases_on; { simp }, right_inv := λ x, (map_map _ _ _).trans $ by induction x using with_one.cases_on; { simp }, .. map e.to_mul_hom } @[simp] lemma _root_.mul_equiv.with_one_congr_refl : (mul_equiv.refl α).with_one_congr = mul_equiv.refl _ := mul_equiv.to_monoid_hom_injective map_id @[simp] lemma _root_.mul_equiv.with_one_congr_symm (e : α ≃* β) : e.with_one_congr.symm = e.symm.with_one_congr := rfl @[simp] lemma _root_.mul_equiv.with_one_congr_trans (e₁ : α ≃* β) (e₂ : β ≃* γ) : e₁.with_one_congr.trans e₂.with_one_congr = (e₁.trans e₂).with_one_congr := mul_equiv.to_monoid_hom_injective (map_comp _ _).symm end map end with_one
64d7c40a839e36a6bdf17206cd1b0b402914afac
9dc8cecdf3c4634764a18254e94d43da07142918
/src/algebra/support.lean
07661bf500dbc37ef1d84f4de5081f79e967b8a6
[ "Apache-2.0" ]
permissive
jcommelin/mathlib
d8456447c36c176e14d96d9e76f39841f69d2d9b
ee8279351a2e434c2852345c51b728d22af5a156
refs/heads/master
1,664,782,136,488
1,663,638,983,000
1,663,638,983,000
132,563,656
0
0
Apache-2.0
1,663,599,929,000
1,525,760,539,000
Lean
UTF-8
Lean
false
false
12,393
lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import order.conditionally_complete_lattice import algebra.big_operators.basic import algebra.group.prod import algebra.group.pi import algebra.module.pi /-! # Support of a function In this file we define `function.support f = {x | f x ≠ 0}` and prove its basic properties. We also define `function.mul_support f = {x | f x ≠ 1}`. -/ open set open_locale big_operators namespace function variables {α β A B M N P R S G M₀ G₀ : Type*} {ι : Sort*} section has_one variables [has_one M] [has_one N] [has_one P] /-- `support` of a function is the set of points `x` such that `f x ≠ 0`. -/ def support [has_zero A] (f : α → A) : set α := {x | f x ≠ 0} /-- `mul_support` of a function is the set of points `x` such that `f x ≠ 1`. -/ @[to_additive] def mul_support (f : α → M) : set α := {x | f x ≠ 1} @[to_additive] lemma mul_support_eq_preimage (f : α → M) : mul_support f = f ⁻¹' {1}ᶜ := rfl @[to_additive] lemma nmem_mul_support {f : α → M} {x : α} : x ∉ mul_support f ↔ f x = 1 := not_not @[to_additive] lemma compl_mul_support {f : α → M} : (mul_support f)ᶜ = {x | f x = 1} := ext $ λ x, nmem_mul_support @[simp, to_additive] lemma mem_mul_support {f : α → M} {x : α} : x ∈ mul_support f ↔ f x ≠ 1 := iff.rfl @[simp, to_additive] lemma mul_support_subset_iff {f : α → M} {s : set α} : mul_support f ⊆ s ↔ ∀ x, f x ≠ 1 → x ∈ s := iff.rfl @[to_additive] lemma mul_support_subset_iff' {f : α → M} {s : set α} : mul_support f ⊆ s ↔ ∀ x ∉ s, f x = 1 := forall_congr $ λ x, not_imp_comm @[to_additive] lemma mul_support_disjoint_iff {f : α → M} {s : set α} : disjoint (mul_support f) s ↔ eq_on f 1 s := by simp_rw [←subset_compl_iff_disjoint_right, mul_support_subset_iff', not_mem_compl_iff, eq_on, pi.one_apply] @[to_additive] lemma disjoint_mul_support_iff {f : α → M} {s : set α} : disjoint s (mul_support f) ↔ eq_on f 1 s := by rw [disjoint.comm, mul_support_disjoint_iff] @[simp, to_additive] lemma mul_support_eq_empty_iff {f : α → M} : mul_support f = ∅ ↔ f = 1 := by { simp_rw [← subset_empty_iff, mul_support_subset_iff', funext_iff], simp } @[simp, to_additive] lemma mul_support_nonempty_iff {f : α → M} : (mul_support f).nonempty ↔ f ≠ 1 := by rw [← ne_empty_iff_nonempty, ne.def, mul_support_eq_empty_iff] @[to_additive] lemma range_subset_insert_image_mul_support (f : α → M) : range f ⊆ insert 1 (f '' mul_support f) := begin intros y hy, rcases eq_or_ne y 1 with rfl|h2y, { exact mem_insert _ _ }, { obtain ⟨x, rfl⟩ := hy, refine mem_insert_of_mem _ ⟨x, h2y, rfl⟩ } end @[simp, to_additive] lemma mul_support_one' : mul_support (1 : α → M) = ∅ := mul_support_eq_empty_iff.2 rfl @[simp, to_additive] lemma mul_support_one : mul_support (λ x : α, (1 : M)) = ∅ := mul_support_one' @[to_additive] lemma mul_support_const {c : M} (hc : c ≠ 1) : mul_support (λ x : α, c) = set.univ := by { ext x, simp [hc] } @[to_additive] lemma mul_support_binop_subset (op : M → N → P) (op1 : op 1 1 = 1) (f : α → M) (g : α → N) : mul_support (λ x, op (f x) (g x)) ⊆ mul_support f ∪ mul_support g := λ x hx, classical.by_cases (λ hf : f x = 1, or.inr $ λ hg, hx $ by simp only [hf, hg, op1]) or.inl @[to_additive] lemma mul_support_sup [semilattice_sup M] (f g : α → M) : mul_support (λ x, f x ⊔ g x) ⊆ mul_support f ∪ mul_support g := mul_support_binop_subset (⊔) sup_idem f g @[to_additive] lemma mul_support_inf [semilattice_inf M] (f g : α → M) : mul_support (λ x, f x ⊓ g x) ⊆ mul_support f ∪ mul_support g := mul_support_binop_subset (⊓) inf_idem f g @[to_additive] lemma mul_support_max [linear_order M] (f g : α → M) : mul_support (λ x, max (f x) (g x)) ⊆ mul_support f ∪ mul_support g := mul_support_sup f g @[to_additive] lemma mul_support_min [linear_order M] (f g : α → M) : mul_support (λ x, min (f x) (g x)) ⊆ mul_support f ∪ mul_support g := mul_support_inf f g @[to_additive] lemma mul_support_supr [conditionally_complete_lattice M] [nonempty ι] (f : ι → α → M) : mul_support (λ x, ⨆ i, f i x) ⊆ ⋃ i, mul_support (f i) := begin rw mul_support_subset_iff', simp only [mem_Union, not_exists, nmem_mul_support], intros x hx, simp only [hx, csupr_const] end @[to_additive] lemma mul_support_infi [conditionally_complete_lattice M] [nonempty ι] (f : ι → α → M) : mul_support (λ x, ⨅ i, f i x) ⊆ ⋃ i, mul_support (f i) := @mul_support_supr _ Mᵒᵈ ι ⟨(1:M)⟩ _ _ f @[to_additive] lemma mul_support_comp_subset {g : M → N} (hg : g 1 = 1) (f : α → M) : mul_support (g ∘ f) ⊆ mul_support f := λ x, mt $ λ h, by simp only [(∘), *] @[to_additive] lemma mul_support_subset_comp {g : M → N} (hg : ∀ {x}, g x = 1 → x = 1) (f : α → M) : mul_support f ⊆ mul_support (g ∘ f) := λ x, mt hg @[to_additive] lemma mul_support_comp_eq (g : M → N) (hg : ∀ {x}, g x = 1 ↔ x = 1) (f : α → M) : mul_support (g ∘ f) = mul_support f := set.ext $ λ x, not_congr hg @[to_additive] lemma mul_support_comp_eq_preimage (g : β → M) (f : α → β) : mul_support (g ∘ f) = f ⁻¹' mul_support g := rfl @[to_additive support_prod_mk] lemma mul_support_prod_mk (f : α → M) (g : α → N) : mul_support (λ x, (f x, g x)) = mul_support f ∪ mul_support g := set.ext $ λ x, by simp only [mul_support, not_and_distrib, mem_union_eq, mem_set_of_eq, prod.mk_eq_one, ne.def] @[to_additive support_prod_mk'] lemma mul_support_prod_mk' (f : α → M × N) : mul_support f = mul_support (λ x, (f x).1) ∪ mul_support (λ x, (f x).2) := by simp only [← mul_support_prod_mk, prod.mk.eta] @[to_additive] lemma mul_support_along_fiber_subset (f : α × β → M) (a : α) : mul_support (λ b, f (a, b)) ⊆ (mul_support f).image prod.snd := by tidy @[simp, to_additive] lemma mul_support_along_fiber_finite_of_finite (f : α × β → M) (a : α) (h : (mul_support f).finite) : (mul_support (λ b, f (a, b))).finite := (h.image prod.snd).subset (mul_support_along_fiber_subset f a) end has_one @[to_additive] lemma mul_support_mul [mul_one_class M] (f g : α → M) : mul_support (λ x, f x * g x) ⊆ mul_support f ∪ mul_support g := mul_support_binop_subset (*) (one_mul _) f g @[to_additive] lemma mul_support_pow [monoid M] (f : α → M) (n : ℕ) : mul_support (λ x, f x ^ n) ⊆ mul_support f := begin induction n with n hfn, { simpa only [pow_zero, mul_support_one] using empty_subset _ }, { simpa only [pow_succ] using subset_trans (mul_support_mul f _) (union_subset (subset.refl _) hfn) } end section division_monoid variables [division_monoid G] (f g : α → G) @[simp, to_additive] lemma mul_support_inv : mul_support (λ x, (f x)⁻¹) = mul_support f := ext $ λ _, inv_ne_one @[simp, to_additive] lemma mul_support_inv' : mul_support f⁻¹ = mul_support f := mul_support_inv f @[to_additive] lemma mul_support_mul_inv : mul_support (λ x, f x * (g x)⁻¹) ⊆ mul_support f ∪ mul_support g := mul_support_binop_subset (λ a b, a * b⁻¹) (by simp) f g @[to_additive] lemma mul_support_div : mul_support (λ x, f x / g x) ⊆ mul_support f ∪ mul_support g := mul_support_binop_subset (/) one_div_one f g end division_monoid @[simp] lemma support_mul [mul_zero_class R] [no_zero_divisors R] (f g : α → R) : support (λ x, f x * g x) = support f ∩ support g := set.ext $ λ x, by simp only [mem_support, mul_ne_zero_iff, mem_inter_eq, not_or_distrib] @[simp] lemma support_mul_subset_left [mul_zero_class R] (f g : α → R) : support (λ x, f x * g x) ⊆ support f := λ x hfg hf, hfg $ by simp only [hf, zero_mul] @[simp] lemma support_mul_subset_right [mul_zero_class R] (f g : α → R) : support (λ x, f x * g x) ⊆ support g := λ x hfg hg, hfg $ by simp only [hg, mul_zero] lemma support_smul_subset_right [add_monoid A] [monoid B] [distrib_mul_action B A] (b : B) (f : α → A) : support (b • f) ⊆ support f := λ x hbf hf, hbf $ by rw [pi.smul_apply, hf, smul_zero] lemma support_smul_subset_left [has_zero M] [has_zero β] [smul_with_zero M β] (f : α → M) (g : α → β) : support (f • g) ⊆ support f := λ x hfg hf, hfg $ by rw [pi.smul_apply', hf, zero_smul] lemma support_smul [semiring R] [add_comm_monoid M] [module R M] [no_zero_smul_divisors R M] (f : α → R) (g : α → M) : support (f • g) = support f ∩ support g := ext $ λ x, smul_ne_zero lemma support_const_smul_of_ne_zero [semiring R] [add_comm_monoid M] [module R M] [no_zero_smul_divisors R M] (c : R) (g : α → M) (hc : c ≠ 0) : support (c • g) = support g := ext $ λ x, by simp only [hc, mem_support, pi.smul_apply, ne.def, smul_eq_zero, false_or] @[simp] lemma support_inv [group_with_zero G₀] (f : α → G₀) : support (λ x, (f x)⁻¹) = support f := set.ext $ λ x, not_congr inv_eq_zero @[simp] lemma support_div [group_with_zero G₀] (f g : α → G₀) : support (λ x, f x / g x) = support f ∩ support g := by simp [div_eq_mul_inv] @[to_additive] lemma mul_support_prod [comm_monoid M] (s : finset α) (f : α → β → M) : mul_support (λ x, ∏ i in s, f i x) ⊆ ⋃ i ∈ s, mul_support (f i) := begin rw mul_support_subset_iff', simp only [mem_Union, not_exists, nmem_mul_support], exact λ x, finset.prod_eq_one end lemma support_prod_subset [comm_monoid_with_zero A] (s : finset α) (f : α → β → A) : support (λ x, ∏ i in s, f i x) ⊆ ⋂ i ∈ s, support (f i) := λ x hx, mem_Inter₂.2 $ λ i hi H, hx $ finset.prod_eq_zero hi H lemma support_prod [comm_monoid_with_zero A] [no_zero_divisors A] [nontrivial A] (s : finset α) (f : α → β → A) : support (λ x, ∏ i in s, f i x) = ⋂ i ∈ s, support (f i) := set.ext $ λ x, by simp only [support, ne.def, finset.prod_eq_zero_iff, mem_set_of_eq, set.mem_Inter, not_exists] lemma mul_support_one_add [has_one R] [add_left_cancel_monoid R] (f : α → R) : mul_support (λ x, 1 + f x) = support f := set.ext $ λ x, not_congr add_right_eq_self lemma mul_support_one_add' [has_one R] [add_left_cancel_monoid R] (f : α → R) : mul_support (1 + f) = support f := mul_support_one_add f lemma mul_support_add_one [has_one R] [add_right_cancel_monoid R] (f : α → R) : mul_support (λ x, f x + 1) = support f := set.ext $ λ x, not_congr add_left_eq_self lemma mul_support_add_one' [has_one R] [add_right_cancel_monoid R] (f : α → R) : mul_support (f + 1) = support f := mul_support_add_one f lemma mul_support_one_sub' [has_one R] [add_group R] (f : α → R) : mul_support (1 - f) = support f := by rw [sub_eq_add_neg, mul_support_one_add', support_neg'] lemma mul_support_one_sub [has_one R] [add_group R] (f : α → R) : mul_support (λ x, 1 - f x) = support f := mul_support_one_sub' f end function namespace set open function variables {α β M : Type*} [has_one M] {f : α → M} @[to_additive] lemma image_inter_mul_support_eq {s : set β} {g : β → α} : (g '' s ∩ mul_support f) = g '' (s ∩ mul_support (f ∘ g)) := by rw [mul_support_comp_eq_preimage f g, image_inter_preimage] end set namespace pi variables {A : Type*} {B : Type*} [decidable_eq A] [has_zero B] {a : A} {b : B} lemma support_single_zero : function.support (pi.single a (0 : B)) = ∅ := by simp @[simp] lemma support_single_of_ne (h : b ≠ 0) : function.support (pi.single a b) = {a} := begin ext, simp only [mem_singleton_iff, ne.def, function.mem_support], split, { contrapose!, exact λ h', single_eq_of_ne h' b }, { rintro rfl, rw single_eq_same, exact h } end lemma support_single [decidable_eq B] : function.support (pi.single a b) = if b = 0 then ∅ else {a} := by { split_ifs with h; simp [h] } lemma support_single_subset : function.support (pi.single a b) ⊆ {a} := begin classical, rw support_single, split_ifs; simp end lemma support_single_disjoint {b' : B} (hb : b ≠ 0) (hb' : b' ≠ 0) {i j : A} : disjoint (function.support (single i b)) (function.support (single j b')) ↔ i ≠ j := by rw [support_single_of_ne hb, support_single_of_ne hb', disjoint_singleton] end pi
cec24054f44c6f72614da911d8cde00c38a0ee71
928e43dd755d83a0986ba91420df8ad05b8d7c9f
/3_propositions.lean
76a41bf9eea6e57d7d637b30b2b5a9d80e81098c
[]
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
17,684
lean
-- Высказывания, связки и аксиомы namespace props constant and' : Prop → Prop → Prop -- все высказывания в Lean живут в специальной вселенной Prop -- таким образом различными операциями над высказываниями являются -- просто функции над Prop constant or' : Prop → Prop → Prop constant not' : Prop → Prop constant impl' : Prop → Prop → Prop variables a b c : Prop #check and' a (or' b c) -- Prop -- поведение таких функций абсолютно аналогично населяющим вселенные Type u constant Proof : Prop → Type -- введем тип доказательств: для любого (a : Prop), Proof a будет содержать доказательство a constant and_comm' : Π a b : Prop, -- тогда аксиомы - это просто константы типа Proof от некоторого аксиоматичного высказывания Proof (impl' (and' a b) (and' b a)) #check and_comm' a b -- Proof (impl' (and' a b) (and' b a)) -- "доказывает" или устанавливает аксиоматичность (a ∧ b) → (b ∧ a) constant modus_ponens : Π a b : Prop, -- задает правило Modes Ponens, выводящее b из (a → b) и истиности a Proof (impl' a b) → Proof a → Proof b end props -- Теоремы namespace theorems constants p q : Prop theorem t1 : p → q → p := -- для красоты записи доказательств, функции над Prop называют теоремами λ (hp : p), λ (hq : q), hp -- изоморфизм Карри-Говарда говорит, что если тип обитаем, то это то же, что -- изоморфное ему высказывание истино; здесь элементарно доказывается первая аксиома -- Гильберта theorem t1' : p → q → p := assume hp : p, -- для красоты записи теорем вводится синтаксический сахар: assume hq : q, -- assume x : α == λ (x : α) hp -- assume - предположим, допустим, рассмотрим theorem t1'' : p → q → p := assume hp : p, assume hq : q, show p, from hp -- так как в результате требуется доказать p, вводится специальный сахар -- show {type}, from {expr} lemma l1 : p → q → p := -- слово theorem можно заменить на lemma в любом месте assume hp : p, assume hq : q, show p, from hp lemma l1a (hp : p) (hq : q) : p := hp -- аналогично функциям, аргументы можно явно поименовать axiom hp : p -- еще один синтаксический сахар - слово axiom, которым можно заменять constant theorem t2 : q → p := t1 hp -- леммы и теоремы можно так же применять к аргументам для получения нужных значений theorem t1_common : ∀ (p q : Prop), -- наша оригинальная теорема работает только для конкретных p и q p → q → p := -- её можно записать для любых высказываний, введя квантор ∀ (\forall), assume p : Prop, -- который является полной аналогией Π для Prop assume q : Prop, -- в этом случае также требуется вводить через λ-абстракцию/assume сами высказывания assume hp : p, assume hq : q, show p, from hp variables p' q' r' s' : Prop -- как и в функциях, все можно повыносить в общие переменные theorem t1_common_var : p' → q' → p' := -- поведение теорем и лемм в этом случае также полностью аналогично функциям assume hp : p', assume hq : q', show p', from hp #check t1_common p' q' -- p' → q' → p' -- обобщение нашей теоремы позволяет использовать её на любых высказываниях #check t1_common r' s' -- r' → s' → r' #check t1_common (p' → q') (s' → r') -- (p' → q') → (s' → r') → p' → q' #check t1_common p q hp -- q → p -- подстановка аксиомы в теорему как и прежде позволила выдать новое утверждение theorem t3 : ∀ {p q r : Prop}, -- в теоремах также можно использовать неявные аргументы (q → r) → (p → q) → p → r := assume p q r : Prop, -- как и в функциях, их нужно вводить, и, кстати, assume тоже поддерживает сахар assume h₁ : q → r, -- для множества переменных одного типа assume h₂ : p → q, -- красивые нижние индексы получаются через \_{символ} (например, h\_1 или h\_2) assume h₃ : p, show r, from h₁ (h₂ h₃) #check @t3 -- ∀ {p q r : Prop}, (q → r) → (p → q) → p → r example : p → q → p := -- чтоб доказать что-то, но не засорять пространство имен, можно воспользоваться assume hp : p, -- "примером", вводимым командой example assume hq : q, show p, from hp example (hp : p) (hq : q) : p := hp -- примеры, как и все прочее поддерживают передачу именованных аргументов example : ∀ {p q r : Prop}, (q → r) → (p → q) → p → r := assume p q r : Prop, assume hqr : q → r, assume hpq : p → q, assume hp : p, -- можно установить промежуточное утверждение благодаря конструкции have hq : q, from hpq hp, -- have {var : type}, from {expr}, аналогичной show show r, from hqr hq -- далее его можно удобно использовать по ходу доказательства -- по сути сахар (have x : p, from e, t) превращается в -- (λ (x : p), t) e example : ∀ {p q r : Prop}, (q → r) → (p → q) → p → r := assume p q r : Prop, assume hqr : q → r, assume hpq : p → q, assume hp : p, have q, from hpq hp, -- have может быть и анонимным (только тип, без терма) show r, from hqr this -- чтоб использовать такой have можно применять слово this, оно обращается -- к последнему have; в данном случае (this : q) example : ∀ {p q r : Prop}, -- возможна также конструкция suffices to show, строящая утверждение на том, (q → r) → (p → q) → -- что достаточно доказать подцель, чтоб получить цель (на мой взгляд, не очень удобно) p → r := -- синтаксические просто переписывается в (have x : p, from e, t) assume p q r : Prop, assume hqr : q → r, assume hpq : p → q, assume hp : p, suffices hq : q, from hqr hq, -- читаем: достаточно доказать найти доказательсто hq для q, чтоб дальше show q, from hpq hp -- показать искомое через hqr hq, что мы и делаем доказывая q через hpq hp example : ∀ {p q r : Prop}, -- полная дешугаризация нашей теоремы будет выглядеть жутковато, (q → r) → (p → q) → -- хотя доказывается в ней ровно то же самое p → r := λ p : Prop, λ q : Prop, λ r : Prop, λ hpr : q → r, λ hpq : p → q, λ hp : p, (λ hq : q, hpr hq) (hpq hp) end theorems -- Логика в стандартной библиотеке namespace stdlib_logic variables a b : Prop #check a → b → a ∧ b -- Prop -- связки → (\r), ∧ (\and), ∨ (\or), ¬ (\not), ↔ (\iff), #check ¬a → a ↔ false -- Prop -- а также константы true и false уже определены в стандартной библиотеке #check a ∨ b → b ∨ a -- Prop end stdlib_logic -- and namespace stdlib_and variables p q : Prop example (hp : p) (hq : q) : p ∧ q := -- в стандартной библиотеке определено огромное количество полезных теорем и лемм, and.intro hp hq -- которые можно и нужно активно использовать example : p ∧ q → p := assume hpq : p ∧ q, show p, from and.elim_left hpq example : p ∧ q → q := assume hpq : p ∧ q, show q, from and.elim_right hpq #check @and.intro -- ∀ {a b : Prop}, a → b → a ∧ b #check @and.elim_left -- ∀ {a b : Prop}, a ∧ b → a #check @and.elim_right -- ∀ {a b : Prop}, a ∧ b → b example : p ∧ q → q ∧ p := -- многие вещи встречаются в стандартной библиотеке по нескольку раз для удобства assume hpq : p ∧ q, -- так, and.left == and.elim_left, а and.right == and.elim_right show q ∧ p, from ⟨and.right hpq, and.left hpq⟩ -- and.intro можно заменить на ⟨,⟩ (\< и \>) example : p ∧ q → q ∧ p := assume hpq : p ∧ q, show q ∧ p, from ⟨hpq.right, hpq.left⟩-- еще немного сахара, and.left hpq можно заменить на hpq.left и т.д. example (hpq : p ∧ q) : q ∧ p := -- наиболее короткая, но, imho, малопонятная запись доказательства ⟨hpq.right, hpq.left⟩ -- каждый выбирает сам, но, кажется, в доказательстве теорем решает вербозность end stdlib_and -- or namespace stdlib_or variables p q : Prop example : p → p ∨ q := -- аналогичные вещи есть для и ∨ (и кучи других вещей) assume hp : p, show p ∨ q, from or.intro_left q hp example : q → p ∨ q := assume hq : q, show p ∨ q, from or.intro_right p hq example : p ∨ q → q ∨ p := assume hpq : p ∨ q, or.elim hpq -- or.elim (x : a ∨ b) предлагат рассмотреть два случая: истинность а и b (assume hp : p, -- если в обоих случаях удается привести доказательство, то общее утверждение доказано show q ∨ p, from or.inr hp) (assume hq : q, -- or.inr и or.inl являются аналогами intro_*, но с обоими неявными аргументами show q ∨ p, from or.inl hq) #check @or.elim -- ∀ {a b c : Prop}, a ∨ b → (a → c) → (b → c) #check @or.intro_left -- ∀ (a : Prop) {b : Prop}, a → a ∨ b #check @or.intro_right -- ∀ {a : Prop} (b : Prop), b → a ∨ b #check @or.inl -- ∀ {a b : Prop}, a → a ∨ b #check @or.inr -- ∀ {a b : Prop}, b → a ∨ b end stdlib_or -- not namespace stdlib_not variables p q : Prop example : (p → q) → ¬q → ¬p := -- not играет роль обычной унарной функции типа p → false assume h₁ : p → q, -- в связи с этим в assume последнего отрицания можно писать assume h₂ : ¬q, -- assume h : p, и тогда останется доказать только false assume h₃ : p, show false, from h₂ (h₁ h₃) example : p → ¬p → q := -- false.elim позволяет вывести что угодно из лжи assume hp : p, assume hnp : ¬p, false.elim (hnp hp) example : p → ¬p → q := -- аналогичным поведением обладает absurd, принимающий утверждение и его отрицание, assume hp : p, -- и возвращающий что угодно assume hnp : ¬p, absurd hp hnp #check @false.elim -- Π {c : Type u}, false → c #check @absurd -- Π {a : Prop} {c : Type u}, a → ¬a → c end stdlib_not -- equiv namespace stdlib_equiv variables p q : Prop theorem and_swap : p ∧ q ↔ q ∧ p := iff.intro -- для введения эквивалентности требуется доказать импликацию в каждую сторону (assume hpq : p ∧ q, show q ∧ p, from and.swap hpq) (assume hqp : q ∧ p, show p ∧ q, from and.swap hqp) #check @iff.intro -- ∀ {a b : Prop}, (a → b) → (b → a) → (a ↔ b) #check @and.swap -- ∀ {a b : Prop}, a ∧ b → b ∧ a #check and_swap p q -- p ∧ q ↔ q ∧ p example (h : p ∧ q) : q ∧ p := -- очень полезным бывает получение импликации из эквиваленции: (a ↔ b) → a → b, iff.mp (and_swap p q) h -- то есть применение эквиваленции в одну сторону; для этого есть две полезные -- функции: iff.mp и iff.mpr (modus ponens и modus ponens reverse) #check @iff.mp -- ∀ {a b : Prop}, (a ↔ b) → a → b #check @iff.mpr -- ∀ {a b : Prop}, (a ↔ b) → b → a end stdlib_equiv -- classical namespace stdlib_classical -- несмотря на то, что правильная логика — интуиционистская, open classical -- мы можем пользоваться и классической, импортировав её из classical #check em -- ∀ {p : Prop}, p ∨ ¬p -- основная аксиома, которая есть в классической логике и отсуствует в нормальной theorem dne {p : Prop} (h : ¬¬p) : p := -- докажем закон снятия двойного отрицания (double negation elimination) or.elim (em p) -- рассмотрим случаи истинности и ложности p с помощью уже знакомого or.elim (assume hp : p, show p, from hp) -- если p истино, то все тривиально (assume hnp : ¬p, show p, from absurd hnp h) -- иначе у нас есть и ¬p и его отрицание ¬(¬p), что дает нам что угодно example {p : Prop} (h : ¬¬p) : p := -- аналогичное доказательство можно построить, используя конструкцию by_cases, by_cases -- являющейся комбинацией or.elim и em (assume hp : p, show p, from hp) (assume hnp : ¬p, show p, from absurd hnp h) #check @by_cases -- ∀ {p q : Prop}, (p → q) → (¬p → q) → q example {p : Prop} (h : ¬¬p) : p := -- еще один элигантный способ: доказательство от противного, где мы получаем отрицание того, by_contradiction -- что хотим доказать, и должны вывести false (assume hnp : ¬p, show false, from h hnp) #check @by_contradiction -- ∀ {p : Prop}, (¬p → false) → p end stdlib_classical
7ab13c02016cf2bb850bb53d3a3871817e10d3ed
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/topology/algebra/group.lean
21d66dff1eb088dacac79848d2f1f8ddf125fc6d
[ "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
20,831
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, Mario Carneiro, Patrick Massot Theory of topological groups. -/ import order.filter.pointwise import group_theory.quotient_group import topology.algebra.monoid import topology.homeomorph open classical set filter topological_space open_locale classical topological_space universes u v w variables {α : Type u} {β : Type v} {γ : Type w} section topological_group section prio set_option default_priority 100 -- see Note [default priority] /-- A topological (additive) group is a group in which the addition and negation operations are continuous. -/ class topological_add_group (α : Type u) [topological_space α] [add_group α] extends has_continuous_add α : Prop := (continuous_neg : continuous (λa:α, -a)) /-- A topological group is a group in which the multiplication and inversion operations are continuous. -/ @[to_additive topological_add_group] class topological_group (α : Type*) [topological_space α] [group α] extends has_continuous_mul α : Prop := (continuous_inv : continuous (λa:α, a⁻¹)) end prio variables [topological_space α] [group α] @[to_additive] lemma continuous_inv [topological_group α] : continuous (λx:α, x⁻¹) := topological_group.continuous_inv @[to_additive, continuity] lemma continuous.inv [topological_group α] [topological_space β] {f : β → α} (hf : continuous f) : continuous (λx, (f x)⁻¹) := continuous_inv.comp hf attribute [continuity] continuous.neg @[to_additive] lemma continuous_on_inv [topological_group α] {s : set α} : continuous_on (λx:α, x⁻¹) s := continuous_inv.continuous_on @[to_additive] lemma continuous_on.inv [topological_group α] [topological_space β] {f : β → α} {s : set β} (hf : continuous_on f s) : continuous_on (λx, (f x)⁻¹) s := continuous_inv.comp_continuous_on hf @[to_additive] lemma tendsto_inv {α : Type*} [group α] [topological_space α] [topological_group α] (a : α) : tendsto (λ x, x⁻¹) (nhds a) (nhds (a⁻¹)) := continuous_inv.tendsto a /-- If a function converges to a value in a multiplicative topological group, then its inverse converges to the inverse of this value. For the version in normed fields assuming additionally that the limit is nonzero, use `tendsto.inv'`. -/ @[to_additive] lemma filter.tendsto.inv [topological_group α] {f : β → α} {x : filter β} {a : α} (hf : tendsto f x (𝓝 a)) : tendsto (λx, (f x)⁻¹) x (𝓝 a⁻¹) := tendsto.comp (continuous_iff_continuous_at.mp topological_group.continuous_inv a) hf @[to_additive] lemma continuous_at.inv [topological_group α] [topological_space β] {f : β → α} {x : β} (hf : continuous_at f x) : continuous_at (λx, (f x)⁻¹) x := hf.inv @[to_additive] lemma continuous_within_at.inv [topological_group α] [topological_space β] {f : β → α} {s : set β} {x : β} (hf : continuous_within_at f s x) : continuous_within_at (λx, (f x)⁻¹) s x := hf.inv @[to_additive topological_add_group] instance [topological_group α] [topological_space β] [group β] [topological_group β] : topological_group (α × β) := { continuous_inv := continuous_fst.inv.prod_mk continuous_snd.inv } attribute [instance] prod.topological_add_group @[to_additive] protected def homeomorph.mul_left [topological_group α] (a : α) : α ≃ₜ α := { continuous_to_fun := continuous_const.mul continuous_id, continuous_inv_fun := continuous_const.mul continuous_id, .. equiv.mul_left a } @[to_additive] lemma is_open_map_mul_left [topological_group α] (a : α) : is_open_map (λ x, a * x) := (homeomorph.mul_left a).is_open_map @[to_additive] lemma is_closed_map_mul_left [topological_group α] (a : α) : is_closed_map (λ x, a * x) := (homeomorph.mul_left a).is_closed_map @[to_additive] protected def homeomorph.mul_right {α : Type*} [topological_space α] [group α] [topological_group α] (a : α) : α ≃ₜ α := { continuous_to_fun := continuous_id.mul continuous_const, continuous_inv_fun := continuous_id.mul continuous_const, .. equiv.mul_right a } @[to_additive] lemma is_open_map_mul_right [topological_group α] (a : α) : is_open_map (λ x, x * a) := (homeomorph.mul_right a).is_open_map @[to_additive] lemma is_closed_map_mul_right [topological_group α] (a : α) : is_closed_map (λ x, x * a) := (homeomorph.mul_right a).is_closed_map @[to_additive] protected def homeomorph.inv (α : Type*) [topological_space α] [group α] [topological_group α] : α ≃ₜ α := { continuous_to_fun := continuous_inv, continuous_inv_fun := continuous_inv, .. equiv.inv α } @[to_additive exists_nhds_half] lemma exists_nhds_split [topological_group α] {s : set α} (hs : s ∈ 𝓝 (1 : α)) : ∃ V ∈ 𝓝 (1 : α), ∀ v w ∈ V, v * w ∈ s := begin have : ((λa:α×α, a.1 * a.2) ⁻¹' s) ∈ 𝓝 ((1, 1) : α × α) := tendsto_mul (by simpa using hs), rw nhds_prod_eq at this, rcases mem_prod_iff.1 this with ⟨V₁, H₁, V₂, H₂, H⟩, exact ⟨V₁ ∩ V₂, inter_mem_sets H₁ H₂, assume v w ⟨hv, _⟩ ⟨_, hw⟩, @H (v, w) ⟨hv, hw⟩⟩ end @[to_additive exists_nhds_half_neg] lemma exists_nhds_split_inv [topological_group α] {s : set α} (hs : s ∈ 𝓝 (1 : α)) : ∃ V ∈ 𝓝 (1 : α), ∀ v w ∈ V, v * w⁻¹ ∈ s := begin have : tendsto (λa:α×α, a.1 * (a.2)⁻¹) ((𝓝 (1:α)).prod (𝓝 (1:α))) (𝓝 1), { simpa using (@tendsto_fst α α (𝓝 1) (𝓝 1)).mul tendsto_snd.inv }, have : ((λa:α×α, a.1 * (a.2)⁻¹) ⁻¹' s) ∈ (𝓝 (1:α)).prod (𝓝 (1:α)) := this (by simpa using hs), rcases mem_prod_iff.1 this with ⟨V₁, H₁, V₂, H₂, H⟩, exact ⟨V₁ ∩ V₂, inter_mem_sets H₁ H₂, assume v w ⟨hv, _⟩ ⟨_, hw⟩, @H (v, w) ⟨hv, hw⟩⟩ end @[to_additive exists_nhds_quarter] lemma exists_nhds_split4 [topological_group α] {u : set α} (hu : u ∈ 𝓝 (1 : α)) : ∃ V ∈ 𝓝 (1 : α), ∀ {v w s t}, v ∈ V → w ∈ V → s ∈ V → t ∈ V → v * w * s * t ∈ u := begin rcases exists_nhds_split hu with ⟨W, W_nhd, h⟩, rcases exists_nhds_split W_nhd with ⟨V, V_nhd, h'⟩, existsi [V, V_nhd], intros v w s t v_in w_in s_in t_in, simpa [mul_assoc] using h _ _ (h' v w v_in w_in) (h' s t s_in t_in) end section variable (α) @[to_additive] lemma nhds_one_symm [topological_group α] : comap (λr:α, r⁻¹) (𝓝 (1 : α)) = 𝓝 (1 : α) := begin have lim : tendsto (λr:α, r⁻¹) (𝓝 1) (𝓝 1), { simpa using (@tendsto_id α (𝓝 1)).inv }, refine comap_eq_of_inverse _ _ lim lim, { funext x, simp }, end end @[to_additive] lemma nhds_translation_mul_inv [topological_group α] (x : α) : comap (λy:α, y * x⁻¹) (𝓝 1) = 𝓝 x := begin refine comap_eq_of_inverse (λy:α, y * x) _ _ _, { funext x; simp }, { suffices : tendsto (λy:α, y * x⁻¹) (𝓝 x) (𝓝 (x * x⁻¹)), { simpa }, exact tendsto_id.mul tendsto_const_nhds }, { suffices : tendsto (λy:α, y * x) (𝓝 1) (𝓝 (1 * x)), { simpa }, exact tendsto_id.mul tendsto_const_nhds } end @[to_additive] lemma topological_group.ext {G : Type*} [group G] {t t' : topological_space G} (tg : @topological_group G t _) (tg' : @topological_group G t' _) (h : @nhds G t 1 = @nhds G t' 1) : t = t' := eq_of_nhds_eq_nhds $ λ x, by rw [← @nhds_translation_mul_inv G t _ _ x , ← @nhds_translation_mul_inv G t' _ _ x , ← h] end topological_group section quotient_topological_group variables [topological_space α] [group α] [topological_group α] (N : set α) [normal_subgroup N] @[to_additive] instance {α : Type u} [group α] [topological_space α] (N : set α) [normal_subgroup N] : topological_space (quotient_group.quotient N) := by dunfold quotient_group.quotient; apply_instance open quotient_group @[to_additive quotient_add_group_saturate] lemma quotient_group_saturate {α : Type u} [group α] (N : set α) [normal_subgroup N] (s : set α) : (coe : α → quotient N) ⁻¹' ((coe : α → quotient N) '' s) = (⋃ x : N, (λ y, y*x.1) '' s) := begin ext x, simp only [mem_preimage, mem_image, mem_Union, quotient_group.eq], split, { exact assume ⟨a, a_in, h⟩, ⟨⟨_, h⟩, a, a_in, mul_inv_cancel_left _ _⟩ }, { exact assume ⟨⟨i, hi⟩, a, ha, eq⟩, ⟨a, ha, by simp only [eq.symm, (mul_assoc _ _ _).symm, inv_mul_cancel_left, hi]⟩ } end @[to_additive] lemma quotient_group.open_coe : is_open_map (coe : α → quotient N) := begin intros s s_op, change is_open ((coe : α → quotient N) ⁻¹' (coe '' s)), rw quotient_group_saturate N s, apply is_open_Union, rintro ⟨n, _⟩, exact is_open_map_mul_right n s s_op end @[to_additive topological_add_group_quotient] instance topological_group_quotient : topological_group (quotient N) := { continuous_mul := begin have cont : continuous ((coe : α → quotient N) ∘ (λ (p : α × α), p.fst * p.snd)) := continuous_quot_mk.comp continuous_mul, have quot : quotient_map (λ p : α × α, ((p.1:quotient N), (p.2:quotient N))), { apply is_open_map.to_quotient_map, { exact is_open_map.prod (quotient_group.open_coe N) (quotient_group.open_coe N) }, { exact (continuous_quot_mk.comp continuous_fst).prod_mk (continuous_quot_mk.comp continuous_snd) }, { rintro ⟨⟨x⟩, ⟨y⟩⟩, exact ⟨(x, y), rfl⟩ } }, exact (quotient_map.continuous_iff quot).2 cont, end, continuous_inv := begin apply continuous_quotient_lift, change continuous ((coe : α → quotient N) ∘ (λ (a : α), a⁻¹)), exact continuous_quot_mk.comp continuous_inv end } attribute [instance] topological_add_group_quotient end quotient_topological_group section topological_add_group variables [topological_space α] [add_group α] @[continuity] lemma continuous.sub [topological_add_group α] [topological_space β] {f : β → α} {g : β → α} (hf : continuous f) (hg : continuous g) : continuous (λx, f x - g x) := by simp [sub_eq_add_neg]; exact hf.add hg.neg lemma continuous_sub [topological_add_group α] : continuous (λp:α×α, p.1 - p.2) := continuous_fst.sub continuous_snd lemma continuous_on.sub [topological_add_group α] [topological_space β] {f : β → α} {g : β → α} {s : set β} (hf : continuous_on f s) (hg : continuous_on g s) : continuous_on (λx, f x - g x) s := continuous_sub.comp_continuous_on (hf.prod hg) lemma filter.tendsto.sub [topological_add_group α] {f : β → α} {g : β → α} {x : filter β} {a b : α} (hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) : tendsto (λx, f x - g x) x (𝓝 (a - b)) := by simp [sub_eq_add_neg]; exact hf.add hg.neg lemma nhds_translation [topological_add_group α] (x : α) : comap (λy:α, y - x) (𝓝 0) = 𝓝 x := nhds_translation_add_neg x end topological_add_group section prio set_option default_priority 100 -- see Note [default priority] /-- additive group with a neighbourhood around 0. Only used to construct a topology and uniform space. This is currently only available for commutative groups, but it can be extended to non-commutative groups too. -/ class add_group_with_zero_nhd (α : Type u) extends add_comm_group α := (Z [] : filter α) (zero_Z : pure 0 ≤ Z) (sub_Z : tendsto (λp:α×α, p.1 - p.2) (Z.prod Z) Z) end prio namespace add_group_with_zero_nhd variables (α) [add_group_with_zero_nhd α] local notation `Z` := add_group_with_zero_nhd.Z @[priority 100] -- see Note [lower instance priority] instance : topological_space α := topological_space.mk_of_nhds $ λa, map (λx, x + a) (Z α) variables {α} lemma neg_Z : tendsto (λa:α, - a) (Z α) (Z α) := have tendsto (λa, (0:α)) (Z α) (Z α), by refine le_trans (assume h, _) zero_Z; simp [univ_mem_sets'] {contextual := tt}, have tendsto (λa:α, 0 - a) (Z α) (Z α), from sub_Z.comp (tendsto.prod_mk this tendsto_id), by simpa lemma add_Z : tendsto (λp:α×α, p.1 + p.2) ((Z α).prod (Z α)) (Z α) := suffices tendsto (λp:α×α, p.1 - -p.2) ((Z α).prod (Z α)) (Z α), by simpa [sub_eq_add_neg], sub_Z.comp (tendsto.prod_mk tendsto_fst (neg_Z.comp tendsto_snd)) lemma exists_Z_half {s : set α} (hs : s ∈ Z α) : ∃ V ∈ Z α, ∀ v w ∈ V, v + w ∈ s := begin have : ((λa:α×α, a.1 + a.2) ⁻¹' s) ∈ (Z α).prod (Z α) := add_Z (by simpa using hs), rcases mem_prod_iff.1 this with ⟨V₁, H₁, V₂, H₂, H⟩, exact ⟨V₁ ∩ V₂, inter_mem_sets H₁ H₂, assume v w ⟨hv, _⟩ ⟨_, hw⟩, @H (v, w) ⟨hv, hw⟩⟩ end lemma nhds_eq (a : α) : 𝓝 a = map (λx, x + a) (Z α) := topological_space.nhds_mk_of_nhds _ _ (assume a, calc pure a = map (λx, x + a) (pure 0) : by simp ... ≤ _ : map_mono zero_Z) (assume b s hs, let ⟨t, ht, eqt⟩ := exists_Z_half hs in have t0 : (0:α) ∈ t, by simpa using zero_Z ht, begin refine ⟨(λx:α, x + b) '' t, image_mem_map ht, _, _⟩, { refine set.image_subset_iff.2 (assume b hbt, _), simpa using eqt 0 b t0 hbt }, { rintros _ ⟨c, hb, rfl⟩, refine (Z α).sets_of_superset ht (assume x hxt, _), simpa [add_assoc] using eqt _ _ hxt hb } end) lemma nhds_zero_eq_Z : 𝓝 0 = Z α := by simp [nhds_eq]; exact filter.map_id @[priority 100] -- see Note [lower instance priority] instance : has_continuous_add α := ⟨ continuous_iff_continuous_at.2 $ assume ⟨a, b⟩, begin rw [continuous_at, nhds_prod_eq, nhds_eq, nhds_eq, nhds_eq, filter.prod_map_map_eq, tendsto_map'_iff], suffices : tendsto ((λx:α, (a + b) + x) ∘ (λp:α×α,p.1 + p.2)) (filter.prod (Z α) (Z α)) (map (λx:α, (a + b) + x) (Z α)), { simpa [(∘), add_comm, add_left_comm] }, exact tendsto_map.comp add_Z end ⟩ @[priority 100] -- see Note [lower instance priority] instance : topological_add_group α := ⟨continuous_iff_continuous_at.2 $ assume a, begin rw [continuous_at, nhds_eq, nhds_eq, tendsto_map'_iff], suffices : tendsto ((λx:α, x - a) ∘ (λx:α, -x)) (Z α) (map (λx:α, x - a) (Z α)), { simpa [(∘), add_comm, sub_eq_add_neg] using this }, exact tendsto_map.comp neg_Z end⟩ end add_group_with_zero_nhd section filter_mul section variables [topological_space α] [group α] [topological_group α] @[to_additive] lemma is_open_mul_left {s t : set α} : is_open t → is_open (s * t) := λ ht, begin have : ∀a, is_open ((λ (x : α), a * x) '' t), assume a, apply is_open_map_mul_left, exact ht, rw ← Union_mul_left_image, exact is_open_Union (λa, is_open_Union $ λha, this _), end @[to_additive] lemma is_open_mul_right {s t : set α} : is_open s → is_open (s * t) := λ hs, begin have : ∀a, is_open ((λ (x : α), x * a) '' s), assume a, apply is_open_map_mul_right, exact hs, rw ← Union_mul_right_image, exact is_open_Union (λa, is_open_Union $ λha, this _), end variables (α) lemma topological_group.t1_space (h : @is_closed α _ {1}) : t1_space α := ⟨assume x, by { convert is_closed_map_mul_right x _ h, simp }⟩ lemma topological_group.regular_space [t1_space α] : regular_space α := ⟨assume s a hs ha, let f := λ p : α × α, p.1 * (p.2)⁻¹ in have hf : continuous f := continuous_mul.comp (continuous_fst.prod_mk (continuous_inv.comp continuous_snd)), -- a ∈ -s implies f (a, 1) ∈ -s, and so (a, 1) ∈ f⁻¹' (-s); -- and so can find t₁ t₂ open such that a ∈ t₁ × t₂ ⊆ f⁻¹' (-s) let ⟨t₁, t₂, ht₁, ht₂, a_mem_t₁, one_mem_t₂, t_subset⟩ := is_open_prod_iff.1 (hf _ (is_open_compl_iff.2 hs)) a (1:α) (by simpa [f]) in begin use s * t₂, use is_open_mul_left ht₂, use λ x hx, ⟨x, 1, hx, one_mem_t₂, mul_one _⟩, apply inf_principal_eq_bot, rw mem_nhds_sets_iff, refine ⟨t₁, _, ht₁, a_mem_t₁⟩, rintros x hx ⟨y, z, hy, hz, yz⟩, have : x * z⁻¹ ∈ sᶜ := (prod_subset_iff.1 t_subset) x hx z hz, have : x * z⁻¹ ∈ s, rw ← yz, simpa, contradiction end⟩ local attribute [instance] topological_group.regular_space lemma topological_group.t2_space [t1_space α] : t2_space α := regular_space.t2_space α end section /-! Some results about an open set containing the product of two sets in a topological group. -/ variables [topological_space α] [group α] [topological_group α] /-- Given a open neighborhood `U` of `1` there is a open neighborhood `V` of `1` such that `VV ⊆ U`. -/ @[to_additive "Given a open neighborhood `U` of `0` there is a open neighborhood `V` of `0` such that `V + V ⊆ U`."] lemma one_open_separated_mul {U : set α} (h1U : is_open U) (h2U : (1 : α) ∈ U) : ∃ V : set α, is_open V ∧ (1 : α) ∈ V ∧ V * V ⊆ U := begin rcases exists_nhds_square (continuous_mul U h1U) (by simp only [mem_preimage, one_mul, h2U] : ((1 : α), (1 : α)) ∈ (λ p : α × α, p.1 * p.2) ⁻¹' U) with ⟨V, h1V, h2V, h3V⟩, refine ⟨V, h1V, h2V, _⟩, rwa [← image_subset_iff, image_mul_prod] at h3V end /-- Given a compact set `K` inside an open set `U`, there is a open neighborhood `V` of `1` such that `KV ⊆ U`. -/ @[to_additive "Given a compact set `K` inside an open set `U`, there is a open neighborhood `V` of `0` such that `K + V ⊆ U`."] lemma compact_open_separated_mul {K U : set α} (hK : is_compact K) (hU : is_open U) (hKU : K ⊆ U) : ∃ V : set α, is_open V ∧ (1 : α) ∈ V ∧ K * V ⊆ U := begin let W : α → set α := λ x, (λ y, x * y) ⁻¹' U, have h1W : ∀ x, is_open (W x) := λ x, continuous_mul_left x U hU, have h2W : ∀ x ∈ K, (1 : α) ∈ W x := λ x hx, by simp only [mem_preimage, mul_one, hKU hx], choose V hV using λ x : K, one_open_separated_mul (h1W x) (h2W x.1 x.2), let X : K → set α := λ x, (λ y, (x : α)⁻¹ * y) ⁻¹' (V x), cases hK.elim_finite_subcover X (λ x, continuous_mul_left x⁻¹ (V x) (hV x).1) _ with t ht, swap, { intros x hx, rw [mem_Union], use ⟨x, hx⟩, rw [mem_preimage], convert (hV _).2.1, simp only [mul_left_inv, subtype.coe_mk] }, refine ⟨⋂ x ∈ t, V x, is_open_bInter (finite_mem_finset _) (λ x hx, (hV x).1), _, _⟩, { simp only [mem_Inter], intros x hx, exact (hV x).2.1 }, rintro _ ⟨x, y, hx, hy, rfl⟩, simp only [mem_Inter] at hy, have := ht hx, simp only [mem_Union, mem_preimage] at this, rcases this with ⟨z, h1z, h2z⟩, have : (z : α)⁻¹ * x * y ∈ W z := (hV z).2.2 (mul_mem_mul h2z (hy z h1z)), rw [mem_preimage] at this, convert this using 1, simp only [mul_assoc, mul_inv_cancel_left] end /-- A compact set is covered by finitely many left multiplicative translates of a set with non-empty interior. -/ @[to_additive "A compact set is covered by finitely many left additive translates of a set with non-empty interior."] lemma compact_covered_by_mul_left_translates {K V : set α} (hK : is_compact K) (hV : (interior V).nonempty) : ∃ t : finset α, K ⊆ ⋃ g ∈ t, (λ h, g * h) ⁻¹' V := begin cases hV with g₀ hg₀, rcases is_compact.elim_finite_subcover hK (λ x : α, interior $ (λ h, x * h) ⁻¹' V) _ _ with ⟨t, ht⟩, { refine ⟨t, subset.trans ht _⟩, apply Union_subset_Union, intro g, apply Union_subset_Union, intro hg, apply interior_subset }, { intro g, apply is_open_interior }, { intros g hg, rw [mem_Union], use g₀ * g⁻¹, apply preimage_interior_subset_interior_preimage, exact continuous_const.mul continuous_id, rwa [mem_preimage, inv_mul_cancel_right] } end end section variables [topological_space α] [comm_group α] [topological_group α] @[to_additive] lemma nhds_mul (x y : α) : 𝓝 (x * y) = 𝓝 x * 𝓝 y := filter_eq $ set.ext $ assume s, begin rw [← nhds_translation_mul_inv x, ← nhds_translation_mul_inv y, ← nhds_translation_mul_inv (x*y)], split, { rintros ⟨t, ht, ts⟩, rcases exists_nhds_split ht with ⟨V, V_mem, h⟩, refine ⟨(λa, a * x⁻¹) ⁻¹' V, (λa, a * y⁻¹) ⁻¹' V, ⟨V, V_mem, subset.refl _⟩, ⟨V, V_mem, subset.refl _⟩, _⟩, rintros a ⟨v, w, v_mem, w_mem, rfl⟩, apply ts, simpa [mul_comm, mul_assoc, mul_left_comm] using h (v * x⁻¹) (w * y⁻¹) v_mem w_mem }, { rintros ⟨a, c, ⟨b, hb, ba⟩, ⟨d, hd, dc⟩, ac⟩, refine ⟨b ∩ d, inter_mem_sets hb hd, assume v, _⟩, simp only [preimage_subset_iff, mul_inv_rev, mem_preimage] at *, rintros ⟨vb, vd⟩, refine ac ⟨v * y⁻¹, y, _, _, _⟩, { rw ← mul_assoc _ _ _ at vb, exact ba _ vb }, { apply dc y, rw mul_right_inv, exact mem_of_nhds hd }, { simp only [inv_mul_cancel_right] } } end @[to_additive] lemma nhds_is_mul_hom : is_mul_hom (λx:α, 𝓝 x) := ⟨λ_ _, nhds_mul _ _⟩ end end filter_mul
a03e129b305ce0e350dff252ccd0f786966a2df1
5e3548e65f2c037cb94cd5524c90c623fbd6d46a
/src_icannos_totilas/applications_lineaires/cpge_applin_10.lean
f66051746b26428eb2619a25220b6186a28acb82
[]
no_license
ahayat16/lean_exos
d4f08c30adb601a06511a71b5ffb4d22d12ef77f
682f2552d5b04a8c8eb9e4ab15f875a91b03845c
refs/heads/main
1,693,101,073,585
1,636,479,336,000
1,636,479,336,000
415,000,441
0
0
null
null
null
null
UTF-8
Lean
false
false
457
lean
import algebra.module.linear_map import linear_algebra.basic import data.real.basic import linear_algebra.affine_space.finite_dimensional import linear_algebra.affine_space.affine_map open_locale affine theorem cpge_applin_10 (k : Type*) {V : Type*} {E : Type*} [field k] [add_comm_group V] [module k V] [affine_space V E] (f : E →ᵃ[k] E): (∀ x, collinear k ({x, f x} : set E)) ↔ ∃ c : E, ∃ s : k, (affine_map.homothety c s) = f := sorry
58665137814330617fefa0f27b43cd2371e97f5c
4727251e0cd73359b15b664c3170e5d754078599
/src/data/list/indexes.lean
f8aa55881c805b8d30a80ee440bedacf39a56d8d
[ "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
7,705
lean
/- Copyright (c) 2020 Jannis Limperg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jannis Limperg -/ import data.list.range /-! # Lemmas about list.*_with_index functions. Some specification lemmas for `list.map_with_index`, `list.mmap_with_index`, `list.foldl_with_index` and `list.foldr_with_index`. -/ universes u v open function namespace list variables {α : Type u} {β : Type v} section map_with_index @[simp] lemma map_with_index_nil {α β} (f : ℕ → α → β) : map_with_index f [] = [] := rfl lemma map_with_index_core_eq (l : list α) (f : ℕ → α → β) (n : ℕ) : l.map_with_index_core f n = l.map_with_index (λ i a, f (i + n) a) := begin induction l with hd tl hl generalizing f n, { simpa }, { rw [map_with_index], simp [map_with_index_core, hl, add_left_comm, add_assoc, add_comm] } end lemma map_with_index_eq_enum_map (l : list α) (f : ℕ → α → β) : l.map_with_index f = l.enum.map (function.uncurry f) := begin induction l with hd tl hl generalizing f, { simp [list.enum_eq_zip_range] }, { rw [map_with_index, map_with_index_core, map_with_index_core_eq, hl], simp [enum_eq_zip_range, range_succ_eq_map, zip_with_map_left, map_uncurry_zip_eq_zip_with] } end @[simp] lemma map_with_index_cons {α β} (l : list α) (f : ℕ → α → β) (a : α) : map_with_index f (a :: l) = f 0 a :: map_with_index (λ i, f (i + 1)) l := by simp [map_with_index_eq_enum_map, enum_eq_zip_range, map_uncurry_zip_eq_zip_with, range_succ_eq_map, zip_with_map_left] @[simp] lemma length_map_with_index {α β} (l : list α) (f : ℕ → α → β) : (l.map_with_index f).length = l.length := begin induction l with hd tl IH generalizing f, { simp }, { simp [IH] } end @[simp] lemma nth_le_map_with_index {α β} (l : list α) (f : ℕ → α → β) (i : ℕ) (h : i < l.length) (h' : i < (l.map_with_index f).length := h.trans_le (l.length_map_with_index f).ge): (l.map_with_index f).nth_le i h' = f i (l.nth_le i h) := by simp [map_with_index_eq_enum_map, enum_eq_zip_range] lemma map_with_index_eq_of_fn {α β} (l : list α) (f : ℕ → α → β) : l.map_with_index f = of_fn (λ (i : fin l.length), f (i : ℕ) (l.nth_le i i.is_lt)) := begin induction l with hd tl IH generalizing f, { simp }, { simpa [IH] } end end map_with_index section foldr_with_index /-- Specification of `foldr_with_index_aux`. -/ def foldr_with_index_aux_spec (f : ℕ → α → β → β) (start : ℕ) (b : β) (as : list α) : β := foldr (uncurry f) b $ enum_from start as theorem foldr_with_index_aux_spec_cons (f : ℕ → α → β → β) (start b a as) : foldr_with_index_aux_spec f start b (a :: as) = f start a (foldr_with_index_aux_spec f (start + 1) b as) := rfl theorem foldr_with_index_aux_eq_foldr_with_index_aux_spec (f : ℕ → α → β → β) (start b as) : foldr_with_index_aux f start b as = foldr_with_index_aux_spec f start b as := begin induction as generalizing start, { refl }, { simp only [foldr_with_index_aux, foldr_with_index_aux_spec_cons, *] } end theorem foldr_with_index_eq_foldr_enum (f : ℕ → α → β → β) (b : β) (as : list α) : foldr_with_index f b as = foldr (uncurry f) b (enum as) := by simp only [foldr_with_index, foldr_with_index_aux_spec, foldr_with_index_aux_eq_foldr_with_index_aux_spec, enum] end foldr_with_index theorem indexes_values_eq_filter_enum (p : α → Prop) [decidable_pred p] (as : list α) : indexes_values p as = filter (p ∘ prod.snd) (enum as) := by simp [indexes_values, foldr_with_index_eq_foldr_enum, uncurry, filter_eq_foldr] theorem find_indexes_eq_map_indexes_values (p : α → Prop) [decidable_pred p] (as : list α) : find_indexes p as = map prod.fst (indexes_values p as) := by simp only [indexes_values_eq_filter_enum, map_filter_eq_foldr, find_indexes, foldr_with_index_eq_foldr_enum, uncurry] section foldl_with_index /-- Specification of `foldl_with_index_aux`. -/ def foldl_with_index_aux_spec (f : ℕ → α → β → α) (start : ℕ) (a : α) (bs : list β) : α := foldl (λ a (p : ℕ × β), f p.fst a p.snd) a $ enum_from start bs theorem foldl_with_index_aux_spec_cons (f : ℕ → α → β → α) (start a b bs) : foldl_with_index_aux_spec f start a (b :: bs) = foldl_with_index_aux_spec f (start + 1) (f start a b) bs := rfl theorem foldl_with_index_aux_eq_foldl_with_index_aux_spec (f : ℕ → α → β → α) (start a bs) : foldl_with_index_aux f start a bs = foldl_with_index_aux_spec f start a bs := begin induction bs generalizing start a, { refl }, { simp [foldl_with_index_aux, foldl_with_index_aux_spec_cons, *] } end theorem foldl_with_index_eq_foldl_enum (f : ℕ → α → β → α) (a : α) (bs : list β) : foldl_with_index f a bs = foldl (λ a (p : ℕ × β), f p.fst a p.snd) a (enum bs) := by simp only [foldl_with_index, foldl_with_index_aux_spec, foldl_with_index_aux_eq_foldl_with_index_aux_spec, enum] end foldl_with_index section mfold_with_index variables {m : Type u → Type v} [monad m] theorem mfoldr_with_index_eq_mfoldr_enum {α β} (f : ℕ → α → β → m β) (b : β) (as : list α) : mfoldr_with_index f b as = mfoldr (uncurry f) b (enum as) := by simp only [mfoldr_with_index, mfoldr_eq_foldr, foldr_with_index_eq_foldr_enum, uncurry] theorem mfoldl_with_index_eq_mfoldl_enum [is_lawful_monad m] {α β} (f : ℕ → β → α → m β) (b : β) (as : list α) : mfoldl_with_index f b as = mfoldl (λ b (p : ℕ × α), f p.fst b p.snd) b (enum as) := by rw [mfoldl_with_index, mfoldl_eq_foldl, foldl_with_index_eq_foldl_enum] end mfold_with_index section mmap_with_index variables {m : Type u → Type v} [applicative m] /-- Specification of `mmap_with_index_aux`. -/ def mmap_with_index_aux_spec {α β} (f : ℕ → α → m β) (start : ℕ) (as : list α) : m (list β) := list.traverse (uncurry f) $ enum_from start as -- Note: `traverse` the class method would require a less universe-polymorphic -- `m : Type u → Type u`. theorem mmap_with_index_aux_spec_cons {α β} (f : ℕ → α → m β) (start : ℕ) (a : α) (as : list α) : mmap_with_index_aux_spec f start (a :: as) = list.cons <$> f start a <*> mmap_with_index_aux_spec f (start + 1) as := rfl theorem mmap_with_index_aux_eq_mmap_with_index_aux_spec {α β} (f : ℕ → α → m β) (start : ℕ) (as : list α) : mmap_with_index_aux f start as = mmap_with_index_aux_spec f start as := begin induction as generalizing start, { refl }, { simp [mmap_with_index_aux, mmap_with_index_aux_spec_cons, *] } end theorem mmap_with_index_eq_mmap_enum {α β} (f : ℕ → α → m β) (as : list α) : mmap_with_index f as = list.traverse (uncurry f) (enum as) := by simp only [mmap_with_index, mmap_with_index_aux_spec, mmap_with_index_aux_eq_mmap_with_index_aux_spec, enum ] end mmap_with_index section mmap_with_index' variables {m : Type u → Type v} [applicative m] [is_lawful_applicative m] theorem mmap_with_index'_aux_eq_mmap_with_index_aux {α} (f : ℕ → α → m punit) (start : ℕ) (as : list α) : mmap_with_index'_aux f start as = mmap_with_index_aux f start as *> pure punit.star := by induction as generalizing start; simp [mmap_with_index'_aux, mmap_with_index_aux, *, seq_right_eq, const, -comp_const] with functor_norm theorem mmap_with_index'_eq_mmap_with_index {α} (f : ℕ → α → m punit) (as : list α) : mmap_with_index' f as = mmap_with_index f as *> pure punit.star := by apply mmap_with_index'_aux_eq_mmap_with_index_aux end mmap_with_index' end list
f9700d0442a0f0d26ec0bb4d68360dcd53b81406
ea4aee6b11f86433e69bb5e50d0259e056d0ae61
/src/tidy/monadic_chain.lean
160379e66b9fb7ff5ce4db6b5fd5c7599cebeb34
[]
no_license
timjb/lean-tidy
e18feff0b7f0aad08c614fb4d34aaf527bf21e20
e767e259bf76c69edfd4ab8af1b76e6f1ed67f48
refs/heads/master
1,624,861,693,182
1,504,411,006,000
1,504,411,006,000
103,740,824
0
0
null
1,505,553,968,000
1,505,553,968,000
null
UTF-8
Lean
false
false
5,137
lean
-- Copyright (c) 2017 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Scott Morrison import .if_then_else import .tactic_states import .loop_detection import .recover open nat tactic universe variables u meta def interaction_monad.done {σ : Type} [underlying_tactic_state σ] : interaction_monad σ unit := λ s, (done_no_metavariables (underlying_tactic_state.to_tactic_state s)).map(λ s', s) private meta structure chain_progress ( σ α : Type ) := ( iteration_limit : nat ) ( results : list α ) ( remaining_tactics : list (interaction_monad (tactic_state × σ) α) ) private meta def monadic_chain_core' { σ α : Type } ( tactics : list (interaction_monad (tactic_state × σ) α) ) : chain_progress σ α → interaction_monad (tactic_state × σ) (list α) | ⟨ 0 , _ , _ ⟩ := interaction_monad.fail "chain iteration limit exceeded" | ⟨ _ , results, [] ⟩ := pure results | ⟨ succ n, results, t :: ts ⟩ := if_then_else interaction_monad.done (pure results) (dependent_if_then_else t (λ result, (monadic_chain_core' ⟨ n, result :: results, tactics ⟩ )) (monadic_chain_core' ⟨ succ n, results, ts ⟩) ) -- meta def monadic_repeat_at_most_core { σ : Type } { α : Type u } ( t : interaction_monad σ α ) : nat → (list α) → interaction_monad σ (list α) -- | 0 results := pure results -- | (succ n) results := (do r ← t, monadic_repeat_at_most_core n (r :: results)) <|> pure results -- meta def monadic_repeat_at_most { σ : Type } { α : Type u } ( limit : nat ) ( t : interaction_monad σ α ) : interaction_monad σ (list α) := monadic_repeat_at_most_core t limit [] -- /-- `first [t_1, ..., t_n]` applies the first tactic that doesn't fail. -- The tactic fails if all t_i's fail. -/ -- meta def monadic_first { σ : Type } { α : Type u } : list (interaction_monad σ α) → interaction_monad σ α -- | [] := monadic_fail "first tactic failed, no more alternatives" -- | (t::ts) := t <|> monadic_first ts structure chain_cfg := ( max_steps : nat := 500 ) ( trace_steps : bool := ff ) ( allowed_collisions : nat := 0 ) ( fail_on_loop : bool := tt ) meta def monadic_chain_core { σ α : Type } [ tactic_lift σ ] ( cfg : chain_cfg ) ( tactics : list (interaction_monad (tactic_state × σ) α) ) : interaction_monad (tactic_state × σ) (list α) := monadic_chain_core' tactics ⟨ cfg.max_steps, [], tactics ⟩ private meta def monadic_chain_handle_looping { σ α : Type } [ tactic_lift σ ] [ has_to_format α ] ( cfg : chain_cfg ) ( tactics : list (interaction_monad (tactic_state × σ) α) ) : interaction_monad (tactic_state × σ) (list α) := if cfg.fail_on_loop then let instrumented_tactics := tactics.map(λ t, pack_states (instrument_for_loop_detection t)) in detect_looping (unpack_states (monadic_chain_core cfg instrumented_tactics)) cfg.allowed_collisions else monadic_chain_core cfg tactics meta def trace_output { σ α : Type } [ tactic_lift σ ] [ has_to_format α ] ( t : interaction_monad (tactic_state × σ ) α ) : interaction_monad (tactic_state × σ ) α := do r ← t, trace format!"succeeded with result: {r}", pure r private meta def monadic_chain_handle_trace { σ α : Type } [ tactic_lift σ ] [ has_to_format α ] ( cfg : chain_cfg ) ( tactics : list (interaction_monad (tactic_state × σ) α) ) : interaction_monad (tactic_state × σ) (list α) := if cfg.trace_steps then monadic_chain_handle_looping cfg (tactics.map trace_output) else monadic_chain_handle_looping cfg tactics meta def monadic_chain { σ α : Type } [ tactic_lift σ ] [ has_to_format α ] ( tactics : list (interaction_monad (tactic_state × σ) α) ) ( cfg : chain_cfg := {} ) : interaction_monad (tactic_state × σ) (list α) := do sequence ← monadic_chain_handle_trace cfg tactics, guard (sequence.length > 0) <|> fail "chain tactic made no progress", pure sequence.reverse meta def chain { α : Type } [ has_to_format α ] ( tactics : list (tactic α) ) ( cfg : chain_cfg := {} ) : tactic (list α) := @monadic_chain unit _ _ _ (tactics.map(λ t, t)) cfg def chain_test_simp_succeeded : 1 = 1 := begin chain [ interactive_simp ] end def chain_test_without_loop_detection_skip_does_nothing : 1 = 1 := begin success_if_fail { chain [ skip ] { fail_on_loop := ff } }, -- fails because 'chain iteration limit exceeded' refl end def chain_test_without_loop_detection_skip_does_nothing' : 1 = 1 := begin success_if_fail { chain [ skip, interactive_simp ] { fail_on_loop := ff } }, -- fails because 'chain iteration limit exceeded' refl end def chain_test_loop_detection : 1 = 1 := begin chain [ skip, interactive_simp ] {} end def chain_test_loop_detection' : 1 = 1 := begin chain [ skip, interactive_simp ] { allowed_collisions := 5, trace_steps := tt } end
b165404f8285435ec2bdc9747a010e8d22cb5aa1
c777c32c8e484e195053731103c5e52af26a25d1
/src/category_theory/abelian/projective.lean
68156ef0055fd60328b31652f96732f803b4097a
[ "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
4,165
lean
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Scott Morrison, Jakob von Raumer -/ import algebra.homology.quasi_iso import category_theory.preadditive.projective_resolution import category_theory.preadditive.yoneda.limits import category_theory.preadditive.yoneda.projective /-! # Abelian categories with enough projectives have projective resolutions When `C` is abelian `projective.d f` and `f` are exact. Hence, starting from an epimorphism `P ⟶ X`, where `P` is projective, we can apply `projective.d` repeatedly to obtain a projective resolution of `X`. -/ noncomputable theory open category_theory open category_theory.limits open opposite universes v u v' u' namespace category_theory open category_theory.projective variables {C : Type u} [category.{v} C] [abelian C] /-- When `C` is abelian, `projective.d f` and `f` are exact. -/ lemma exact_d_f [enough_projectives C] {X Y : C} (f : X ⟶ Y) : exact (d f) f := (abelian.exact_iff _ _).2 $ ⟨by simp, zero_of_epi_comp (π _) $ by rw [←category.assoc, cokernel.condition]⟩ /-- The preadditive Co-Yoneda functor on `P` preserves colimits if `P` is projective. -/ def preserves_finite_colimits_preadditive_coyoneda_obj_of_projective (P : C) [hP : projective P] : preserves_finite_colimits (preadditive_coyoneda_obj (op P)) := begin letI := (projective_iff_preserves_epimorphisms_preadditive_coyoneda_obj' P).mp hP, apply functor.preserves_finite_colimits_of_preserves_epis_and_kernels, end /-- An object is projective if its preadditive Co-Yoneda functor preserves finite colimits. -/ lemma projective_of_preserves_finite_colimits_preadditive_coyoneda_obj (P : C) [hP : preserves_finite_colimits (preadditive_coyoneda_obj (op P))] : projective P := begin rw projective_iff_preserves_epimorphisms_preadditive_coyoneda_obj', apply_instance end namespace ProjectiveResolution /-! Our goal is to define `ProjectiveResolution.of Z : ProjectiveResolution Z`. The `0`-th object in this resolution will just be `projective.over Z`, i.e. an arbitrarily chosen projective object with a map to `Z`. After that, we build the `n+1`-st object as `projective.syzygies` applied to the previously constructed morphism, and the map to the `n`-th object as `projective.d`. -/ variables [enough_projectives C] /-- Auxiliary definition for `ProjectiveResolution.of`. -/ @[simps] def of_complex (Z : C) : chain_complex C ℕ := chain_complex.mk' (projective.over Z) (projective.syzygies (projective.π Z)) (projective.d (projective.π Z)) (λ ⟨X, Y, f⟩, ⟨projective.syzygies f, projective.d f, (exact_d_f f).w⟩) /-- In any abelian category with enough projectives, `ProjectiveResolution.of Z` constructs a projective resolution of the object `Z`. -/ @[irreducible] def of (Z : C) : ProjectiveResolution Z := { complex := of_complex Z, π := chain_complex.mk_hom _ _ (projective.π Z) 0 (by { simp, exact (exact_d_f (projective.π Z)).w.symm, }) (λ n _, ⟨0, by ext⟩), projective := by { rintros (_|_|_|n); apply projective.projective_over, }, exact₀ := by simpa using exact_d_f (projective.π Z), exact := by { rintros (_|n); { simp, apply exact_d_f, }, }, epi := projective.π_epi Z, } @[priority 100] instance (Z : C) : has_projective_resolution Z := { out := ⟨of Z⟩ } @[priority 100] instance : has_projective_resolutions C := { out := λ Z, by apply_instance } end ProjectiveResolution end category_theory namespace homological_complex.hom variables {C : Type u} [category.{v} C] [abelian C] /-- If `X` is a chain complex of projective objects and we have a quasi-isomorphism `f : X ⟶ Y[0]`, then `X` is a projective resolution of `Y.` -/ def to_single₀_ProjectiveResolution {X : chain_complex C ℕ} {Y : C} (f : X ⟶ (chain_complex.single₀ C).obj Y) [quasi_iso f] (H : ∀ n, projective (X.X n)) : ProjectiveResolution Y := { complex := X, π := f, projective := H, exact₀ := f.to_single₀_exact_d_f_at_zero, exact := f.to_single₀_exact_at_succ, epi := f.to_single₀_epi_at_zero } end homological_complex.hom
9b0f433cf93a0fd18aff183ccae13d4cfbbbaa07
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/hott/types/pullback.hlean
f2ae1ca65b9b1c9c48cb12fec3986c183b060e8a
[ "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
6,151
hlean
/- Copyright (c) 2015 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Floris van Doorn Theorems about pullbacks -/ import cubical.square open eq equiv is_equiv function prod unit is_trunc sigma variables {A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ : Type} (f₁₀ : A₀₀ → A₂₀) (f₃₀ : A₂₀ → A₄₀) (f₀₁ : A₀₀ → A₀₂) (f₂₁ : A₂₀ → A₂₂) (f₄₁ : A₄₀ → A₄₂) (f₁₂ : A₀₂ → A₂₂) (f₃₂ : A₂₂ → A₄₂) structure pullback (f₂₁ : A₂₀ → A₂₂) (f₁₂ : A₀₂ → A₂₂) := (pr1 : A₂₀) (pr2 : A₀₂) (pr1_pr2 : f₂₁ pr1 = f₁₂ pr2) namespace pullback protected definition sigma_char [constructor] : pullback f₂₁ f₁₂ ≃ Σ(a₂₀ : A₂₀) (a₀₂ : A₀₂), f₂₁ a₂₀ = f₁₂ a₀₂ := begin fapply equiv.MK, { intro x, induction x with a₂₀ a₀₂ p, exact ⟨a₂₀, a₀₂, p⟩}, { intro x, induction x with a₂₀ y, induction y with a₀₂ p, exact pullback.mk a₂₀ a₀₂ p}, { intro x, induction x with a₂₀ y, induction y with a₀₂ p, reflexivity}, { intro x, induction x with a₂₀ a₀₂ p, reflexivity}, end variables {f₁₀ f₃₀ f₀₁ f₂₁ f₄₁ f₁₂ f₃₂} definition pullback_corec [constructor] (p : Πa, f₂₁ (f₁₀ a) = f₁₂ (f₀₁ a)) (a : A₀₀) : pullback f₂₁ f₁₂ := pullback.mk (f₁₀ a) (f₀₁ a) (p a) definition pullback_eq {x y : pullback f₂₁ f₁₂} (p1 : pr1 x = pr1 y) (p2 : pr2 x = pr2 y) (r : square (pr1_pr2 x) (pr1_pr2 y) (ap f₂₁ p1) (ap f₁₂ p2)) : x = y := by induction y; induction x; esimp at *; induction p1; induction p2; exact ap (pullback.mk _ _) (eq_of_vdeg_square r) definition pullback_comm_equiv [constructor] : pullback f₁₂ f₂₁ ≃ pullback f₂₁ f₁₂ := begin fapply equiv.MK, { intro v, induction v with x y p, exact pullback.mk y x p⁻¹}, { intro v, induction v with x y p, exact pullback.mk y x p⁻¹}, { intro v, induction v, esimp, exact ap _ !inv_inv}, { intro v, induction v, esimp, exact ap _ !inv_inv}, end definition pullback_unit_equiv [constructor] : pullback (λ(x : A₀₂), star) (λ(x : A₂₀), star) ≃ A₀₂ × A₂₀ := begin fapply equiv.MK, { intro v, induction v with x y p, exact (x, y)}, { intro v, induction v with x y, exact pullback.mk x y idp}, { intro v, induction v, reflexivity}, { intro v, induction v, esimp, apply ap _ !is_prop.elim}, end definition pullback_along {f : A₂₀ → A₂₂} (g : A₀₂ → A₂₂) : pullback f g → A₂₀ := pr1 postfix `^*`:(max+1) := pullback_along variables (f₁₀ f₃₀ f₀₁ f₂₁ f₄₁ f₁₂ f₃₂) structure pullback_square (f₁₀ : A₀₀ → A₂₀) (f₁₂ : A₀₂ → A₂₂) (f₀₁ : A₀₀ → A₀₂) (f₂₁ : A₂₀ → A₂₂) : Type := (comm : Πa, f₂₁ (f₁₀ a) = f₁₂ (f₀₁ a)) (is_pullback : is_equiv (pullback_corec comm : A₀₀ → pullback f₂₁ f₁₂)) attribute pullback_square.is_pullback [instance] definition pbs_comm [unfold 9] := @pullback_square.comm definition pullback_square_pullback : pullback_square (pr1 : pullback f₂₁ f₁₂ → A₂₀) f₁₂ pr2 f₂₁ := pullback_square.mk pr1_pr2 (adjointify _ (λf, f) (λf, by induction f; reflexivity) (λg, by induction g; reflexivity)) variables {f₁₀ f₃₀ f₀₁ f₂₁ f₄₁ f₁₂ f₃₂} definition pullback_square_equiv [constructor] (s : pullback_square f₁₀ f₁₂ f₀₁ f₂₁) : A₀₀ ≃ pullback f₂₁ f₁₂ := equiv.mk _ (pullback_square.is_pullback s) definition of_pullback [unfold 9] (s : pullback_square f₁₀ f₁₂ f₀₁ f₂₁) (x : pullback f₂₁ f₁₂) : A₀₀ := (pullback_square_equiv s)⁻¹ x definition right_of_pullback (s : pullback_square f₁₀ f₁₂ f₀₁ f₂₁) (x : pullback f₂₁ f₁₂) : f₁₀ (of_pullback s x) = pr1 x := ap pr1 (to_right_inv (pullback_square_equiv s) x) definition down_of_pullback (s : pullback_square f₁₀ f₁₂ f₀₁ f₂₁) (x : pullback f₂₁ f₁₂) : f₀₁ (of_pullback s x) = pr2 x := ap pr2 (to_right_inv (pullback_square_equiv s) x) -- definition pullback_square_compose_inverse (s : pullback_square f₁₀ f₁₂ f₀₁ f₂₁) -- (t : pullback_square f₃₀ f₃₂ f₂₁ f₄₁) (x : pullback f₄₁ (f₃₂ ∘ f₁₂)) : A₀₀ := -- let a₂₀' : pullback f₄₁ f₃₂ := -- pullback.mk (pr1 x) (f₁₂ (pr2 x)) (pr1_pr2 x) in -- let a₂₀ : A₂₀ := -- of_pullback t a₂₀' in -- have a₀₀' : pullback f₂₁ f₁₂, -- from pullback.mk a₂₀ (pr2 x) !down_of_pullback, -- show A₀₀, -- from of_pullback s a₀₀' -- local attribute pullback_square_compose_inverse [reducible] -- definition down_psci (s : pullback_square f₁₀ f₁₂ f₀₁ f₂₁) -- (t : pullback_square f₃₀ f₃₂ f₂₁ f₄₁) (x : pullback f₄₁ (f₃₂ ∘ f₁₂)) : -- f₀₁ (pullback_square_compose_inverse s t x) = pr2 x := -- by apply down_of_pullback -- definition pullback_square_compose [constructor] (s : pullback_square f₁₀ f₁₂ f₀₁ f₂₁) -- (t : pullback_square f₃₀ f₃₂ f₂₁ f₄₁) : pullback_square (f₃₀ ∘ f₁₀) (f₃₂ ∘ f₁₂) f₀₁ f₄₁ := -- pullback_square.mk -- (λa, pbs_comm t (f₁₀ a) ⬝ ap f₃₂ (pbs_comm s a)) -- (adjointify _ -- (pullback_square_compose_inverse s t) -- begin -- intro x, induction x with x y p, esimp, -- fapply pullback_eq: esimp, -- { exact ap f₃₀ !right_of_pullback ⬝ !right_of_pullback}, -- { apply down_of_pullback}, -- { esimp, exact sorry } -- end -- begin -- intro x, esimp, exact sorry -- end) end pullback
d53867f0b72c72e98afa81e5e0d816bcb903c677
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/qpf/multivariate/default.lean
79a873f15ed4b72ffefcc96d7d2944a2fef0d6c3
[]
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
540
lean
import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.qpf.multivariate.basic import Mathlib.data.qpf.multivariate.constructions.fix import Mathlib.data.qpf.multivariate.constructions.cofix import Mathlib.data.qpf.multivariate.constructions.comp import Mathlib.data.qpf.multivariate.constructions.quot import Mathlib.data.qpf.multivariate.constructions.prj import Mathlib.data.qpf.multivariate.constructions.const import Mathlib.data.qpf.multivariate.constructions.sigma import Mathlib.PostPort namespace Mathlib
528d0e9ef7e5e6491752390a18e330f020bc17a7
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/analysis/normed_space/indicator_function.lean
51563fb366e9f7482dbcf0f0207961aa9df5d038
[]
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,910
lean
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.indicator_function import Mathlib.analysis.normed_space.basic import Mathlib.PostPort universes u_1 u_2 namespace Mathlib /-! # Indicator function and norm This file contains a few simple lemmas about `set.indicator` and `norm`. ## Tags indicator, norm -/ theorem norm_indicator_eq_indicator_norm {α : Type u_1} {E : Type u_2} [normed_group E] {s : set α} (f : α → E) (a : α) : norm (set.indicator s f a) = set.indicator s (fun (a : α) => norm (f a)) a := flip congr_fun a (Eq.symm (set.indicator_comp_of_zero norm_zero)) theorem nnnorm_indicator_eq_indicator_nnnorm {α : Type u_1} {E : Type u_2} [normed_group E] {s : set α} (f : α → E) (a : α) : nnnorm (set.indicator s f a) = set.indicator s (fun (a : α) => nnnorm (f a)) a := flip congr_fun a (Eq.symm (set.indicator_comp_of_zero nnnorm_zero)) theorem norm_indicator_le_of_subset {α : Type u_1} {E : Type u_2} [normed_group E] {s : set α} {t : set α} (h : s ⊆ t) (f : α → E) (a : α) : norm (set.indicator s f a) ≤ norm (set.indicator t f a) := sorry theorem indicator_norm_le_norm_self {α : Type u_1} {E : Type u_2} [normed_group E] {s : set α} (f : α → E) (a : α) : set.indicator s (fun (a : α) => norm (f a)) a ≤ norm (f a) := set.indicator_le_self' (fun (_x : α) (_x : ¬_x ∈ s) => norm_nonneg (f a)) a theorem norm_indicator_le_norm_self {α : Type u_1} {E : Type u_2} [normed_group E] {s : set α} (f : α → E) (a : α) : norm (set.indicator s f a) ≤ norm (f a) := eq.mpr (id (Eq._oldrec (Eq.refl (norm (set.indicator s f a) ≤ norm (f a))) (norm_indicator_eq_indicator_norm f a))) (indicator_norm_le_norm_self (fun (a : α) => f a) a)
92cc0488ed361afa6bb4a48098928c7996b1c16e
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/category_theory/instances/groups.lean
6a927a4dd54fb62eb031070049c73708907cbb73
[ "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
2,014
lean
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin Introduce Group -- the category of groups. Currently only the basic setup. Copied from monoids.lean. -/ import algebra.punit_instances import category_theory.concrete_category universes u v open category_theory namespace category_theory.instances /-- The category of groups and group morphisms. -/ @[reducible] def Group : Type (u+1) := bundled group instance (G : Group) : group G := G.str instance concrete_is_group_hom : concrete_category @is_group_hom := ⟨by introsI α ia; apply_instance, by introsI α β γ ia ib ic f g hf hg; apply_instance⟩ instance Group_hom_is_group_hom {G₁ G₂ : Group} (f : G₁ ⟶ G₂) : is_group_hom (f : G₁ → G₂) := f.2 instance : has_one Group := ⟨{ α := punit, str := infer_instance }⟩ /-- The category of additive commutative groups and group morphisms. -/ @[reducible] def AddCommGroup : Type (u+1) := bundled add_comm_group instance (A : AddCommGroup) : add_comm_group A := A.str @[reducible] def is_add_comm_group_hom {α β} [add_comm_group α] [add_comm_group β] (f : α → β) : Prop := is_add_group_hom f instance concrete_is_comm_group_hom : concrete_category @is_add_comm_group_hom := ⟨by introsI α ia; apply_instance, by introsI α β γ ia ib ic f g hf hg; apply_instance⟩ instance AddCommGroup_hom_is_comm_group_hom {A₁ A₂ : AddCommGroup} (f : A₁ ⟶ A₂) : is_add_comm_group_hom (f : A₁ → A₂) := f.2 namespace AddCommGroup /-- The forgetful functor from additive commutative groups to groups. -/ def forget_to_Group : AddCommGroup ⥤ Group := { obj := λ A₁, ⟨multiplicative A₁, infer_instance⟩, map := λ A₁ A₂ f, ⟨f, multiplicative.is_group_hom f⟩ } instance : faithful (forget_to_Group) := {} instance : has_zero AddCommGroup := ⟨{ α := punit, str := infer_instance }⟩ end AddCommGroup end category_theory.instances
49e50241f7bc1fd82daaa33eb28230fa590575c4
206422fb9edabf63def0ed2aa3f489150fb09ccb
/src/linear_algebra/eigenspace.lean
dcaf76cfc43677fd631f3bbfd444cb1bef8f86ce
[ "Apache-2.0" ]
permissive
hamdysalah1/mathlib
b915f86b2503feeae268de369f1b16932321f097
95454452f6b3569bf967d35aab8d852b1ddf8017
refs/heads/master
1,677,154,116,545
1,611,797,994,000
1,611,797,994,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
24,174
lean
/- Copyright (c) 2020 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Alexander Bentkamp. -/ import field_theory.algebraic_closure import linear_algebra.finsupp import linear_algebra.matrix /-! # Eigenvectors and eigenvalues This file defines eigenspaces, eigenvalues, and eigenvalues, as well as their generalized counterparts. We follow Axler's approach [axler2015] because it allows us to derive many properties without choosing a basis and without using matrices. An eigenspace of a linear map `f` for a scalar `μ` is the kernel of the map `(f - μ • id)`. The nonzero elements of an eigenspace are eigenvectors `x`. They have the property `f x = μ • x`. If there are eigenvectors for a scalar `μ`, the scalar `μ` is called an eigenvalue. There is no consensus in the literature whether `0` is an eigenvector. Our definition of `has_eigenvector` permits only nonzero vectors. For an eigenvector `x` that may also be `0`, we write `x ∈ f.eigenspace μ`. A generalized eigenspace of a linear map `f` for a natural number `k` and a scalar `μ` is the kernel of the map `(f - μ • id) ^ k`. The nonzero elements of a generalized eigenspace are generalized eigenvectors `x`. If there are generalized eigenvectors for a natural number `k` and a scalar `μ`, the scalar `μ` is called a generalized eigenvalue. ## References * [Sheldon Axler, *Linear Algebra Done Right*][axler2015] * https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors ## Tags eigenspace, eigenvector, eigenvalue, eigen -/ universes u v w namespace module namespace End open vector_space principal_ideal_ring polynomial finite_dimensional variables {K R : Type v} {V M : Type w} [comm_ring R] [add_comm_group M] [module R M] [field K] [add_comm_group V] [vector_space K V] /-- The submodule `eigenspace f μ` for a linear map `f` and a scalar `μ` consists of all vectors `x` such that `f x = μ • x`. (Def 5.36 of [axler2015])-/ def eigenspace (f : End R M) (μ : R) : submodule R M := (f - algebra_map R (End R M) μ).ker /-- A nonzero element of an eigenspace is an eigenvector. (Def 5.7 of [axler2015]) -/ def has_eigenvector (f : End R M) (μ : R) (x : M) : Prop := x ≠ 0 ∧ x ∈ eigenspace f μ /-- A scalar `μ` is an eigenvalue for a linear map `f` if there are nonzero vectors `x` such that `f x = μ • x`. (Def 5.5 of [axler2015]) -/ def has_eigenvalue (f : End R M) (a : R) : Prop := eigenspace f a ≠ ⊥ lemma mem_eigenspace_iff {f : End R M} {μ : R} {x : M} : x ∈ eigenspace f μ ↔ f x = μ • x := by rw [eigenspace, linear_map.mem_ker, linear_map.sub_apply, algebra_map_End_apply, sub_eq_zero] lemma eigenspace_div (f : End K V) (a b : K) (hb : b ≠ 0) : eigenspace f (a / b) = (b • f - algebra_map K (End K V) a).ker := calc eigenspace f (a / b) = eigenspace f (b⁻¹ * a) : by { rw [div_eq_mul_inv, mul_comm] } ... = (f - (b⁻¹ * a) • linear_map.id).ker : rfl ... = (f - b⁻¹ • a • linear_map.id).ker : by rw smul_smul ... = (f - b⁻¹ • algebra_map K (End K V) a).ker : rfl ... = (b • (f - b⁻¹ • algebra_map K (End K V) a)).ker : by rw linear_map.ker_smul _ b hb ... = (b • f - algebra_map K (End K V) a).ker : by rw [smul_sub, smul_inv_smul' hb] lemma eigenspace_aeval_polynomial_degree_1 (f : End K V) (q : polynomial K) (hq : degree q = 1) : eigenspace f (- q.coeff 0 / q.leading_coeff) = (aeval f q).ker := calc eigenspace f (- q.coeff 0 / q.leading_coeff) = (q.leading_coeff • f - algebra_map K (End K V) (- q.coeff 0)).ker : by { rw eigenspace_div, intro h, rw leading_coeff_eq_zero_iff_deg_eq_bot.1 h at hq, cases hq } ... = (aeval f (C q.leading_coeff * X + C (q.coeff 0))).ker : by { rw [C_mul', aeval_def], simpa [algebra_map, algebra.to_ring_hom], } ... = (aeval f q).ker : by { congr, apply (eq_X_add_C_of_degree_eq_one hq).symm } lemma ker_aeval_ring_hom'_unit_polynomial (f : End K V) (c : units (polynomial K)) : (aeval f (c : polynomial K)).ker = ⊥ := begin rw polynomial.eq_C_of_degree_eq_zero (degree_coe_units c), simp only [aeval_def, eval₂_C], apply ker_algebra_map_End, apply coeff_coe_units_zero_ne_zero c end theorem aeval_apply_of_has_eigenvector {f : End K V} {p : polynomial K} {μ : K} {x : V} (h : f.has_eigenvector μ x) : aeval f p x = (p.eval μ) • x := begin apply p.induction_on, { intro a, simp [module.algebra_map_End_apply] }, { intros p q hp hq, simp [hp, hq, add_smul] }, { intros n a hna, rw [mul_comm, pow_succ, mul_assoc, alg_hom.map_mul, linear_map.mul_app, mul_comm, hna], simp [algebra_map_End_apply, mem_eigenspace_iff.1 h.2, smul_smul, mul_comm] } end section minpoly theorem is_root_of_has_eigenvalue {f : End K V} {μ : K} (h : f.has_eigenvalue μ) : (minpoly K f).is_root μ := begin rcases (submodule.ne_bot_iff _).1 h with ⟨w, ⟨H, ne0⟩⟩, refine or.resolve_right (smul_eq_zero.1 _) ne0, simp [← aeval_apply_of_has_eigenvector ⟨ne0, H⟩, minpoly.aeval K f], end variables [finite_dimensional K V] (f : End K V) protected theorem is_integral : is_integral K f := is_integral_of_noetherian (by apply_instance) f variables {f} {μ : K} theorem has_eigenvalue_of_is_root (h : (minpoly K f).is_root μ) : f.has_eigenvalue μ := begin cases dvd_iff_is_root.2 h with p hp, rw [has_eigenvalue, eigenspace], intro con, cases (linear_map.is_unit_iff _).2 con with u hu, have p_ne_0 : p ≠ 0, { intro con, apply minpoly.ne_zero f.is_integral, rw [hp, con, mul_zero] }, have h_deg := minpoly.degree_le_of_ne_zero K f p_ne_0 _, { rw [hp, degree_mul, degree_X_sub_C, polynomial.degree_eq_nat_degree p_ne_0] at h_deg, norm_cast at h_deg, linarith, }, { have h_aeval := minpoly.aeval K f, revert h_aeval, simp [hp, ← hu] }, end theorem has_eigenvalue_iff_is_root : f.has_eigenvalue μ ↔ (minpoly K f).is_root μ := ⟨is_root_of_has_eigenvalue, has_eigenvalue_of_is_root⟩ end minpoly /-- Every linear operator on a vector space over an algebraically closed field has an eigenvalue. (Lemma 5.21 of [axler2015]) -/ lemma exists_eigenvalue [is_alg_closed K] [finite_dimensional K V] [nontrivial V] (f : End K V) : ∃ (c : K), f.has_eigenvalue c := begin classical, -- Choose a nonzero vector `v`. obtain ⟨v, hv⟩ : ∃ v : V, v ≠ 0 := exists_ne (0 : V), -- The infinitely many vectors v, f v, f (f v), ... cannot be linearly independent -- because the vector space is finite dimensional. have h_lin_dep : ¬ linear_independent K (λ n : ℕ, (f ^ n) v), { apply not_linear_independent_of_infinite, }, -- Therefore, there must be a nonzero polynomial `p` such that `p(f) v = 0`. obtain ⟨p, ⟨h_mon, h_eval_p⟩⟩ := f.is_integral, have h_eval_p_not_unit : aeval f p ∉ is_unit.submonoid (End K V), { rw [is_unit.mem_submonoid_iff, linear_map.is_unit_iff, linear_map.ker_eq_bot'], intro h, apply hv (h v _), rw [aeval_def, h_eval_p, linear_map.zero_apply] }, -- Hence, there must be a factor `q` of `p` such that `q(f)` is not invertible. obtain ⟨q, hq_factor, hq_nonunit⟩ : ∃ q, q ∈ factors p ∧ ¬ is_unit (aeval f q), { simp only [←not_imp, (is_unit.mem_submonoid_iff _).symm], apply not_forall.1 (λ h, h_eval_p_not_unit (ring_hom_mem_submonoid_of_factors_subset_of_units_subset (eval₂_ring_hom' (algebra_map _ _) f _) (is_unit.submonoid (End K V)) p h_mon.ne_zero h _)), simp only [is_unit.mem_submonoid_iff, linear_map.is_unit_iff], apply ker_aeval_ring_hom'_unit_polynomial }, -- Since the field is algebraically closed, `q` has degree 1. have h_deg_q : q.degree = 1 := is_alg_closed.degree_eq_one_of_irreducible _ (ne_zero_of_mem_factors h_mon.ne_zero hq_factor) ((factors_spec p h_mon.ne_zero).1 q hq_factor), -- Then the kernel of `q(f)` is an eigenspace. have h_eigenspace: eigenspace f (-q.coeff 0 / q.leading_coeff) = (aeval f q).ker, from eigenspace_aeval_polynomial_degree_1 f q h_deg_q, -- Since `q(f)` is not invertible, the kernel is not `⊥`, and thus there exists an eigenvalue. show ∃ (c : K), f.has_eigenvalue c, { use -q.coeff 0 / q.leading_coeff, rw [has_eigenvalue, h_eigenspace], intro h_eval_ker, exact hq_nonunit ((linear_map.is_unit_iff (aeval f q)).2 h_eval_ker) } end /-- Eigenvectors corresponding to distinct eigenvalues of a linear operator are linearly independent. (Lemma 5.10 of [axler2015]) We use the eigenvalues as indexing set to ensure that there is only one eigenvector for each eigenvalue in the image of `xs`. -/ lemma eigenvectors_linear_independent (f : End K V) (μs : set K) (xs : μs → V) (h_eigenvec : ∀ μ : μs, f.has_eigenvector μ (xs μ)) : linear_independent K xs := begin classical, -- We need to show that if a linear combination `l` of the eigenvectors `xs` is `0`, then all -- its coefficients are zero. suffices : ∀ l, finsupp.total μs V K xs l = 0 → l = 0, { rw linear_independent_iff, apply this }, intros l hl, -- We apply induction on the finite set of eigenvalues whose eigenvectors have nonzero -- coefficients, i.e. on the support of `l`. induction h_l_support : l.support using finset.induction with μ₀ l_support' hμ₀ ih generalizing l, -- If the support is empty, all coefficients are zero and we are done. { exact finsupp.support_eq_empty.1 h_l_support }, -- Now assume that the support of `l` contains at least one eigenvalue `μ₀`. We define a new -- linear combination `l'` to apply the induction hypothesis on later. The linear combination `l'` -- is derived from `l` by multiplying the coefficient of the eigenvector with eigenvalue `μ` -- by `μ - μ₀`. -- To get started, we define `l'` as a function `l'_f : μs → K` with potentially infinite support. { let l'_f : μs → K := (λ μ : μs, (↑μ - ↑μ₀) * l μ), -- The support of `l'_f` is the support of `l` without `μ₀`. have h_l_support' : ∀ (μ : μs), μ ∈ l_support' ↔ l'_f μ ≠ 0 , { intro μ, suffices : μ ∈ l_support' → μ ≠ μ₀, { simp [l'_f, ← finsupp.not_mem_support_iff, h_l_support, sub_eq_zero, ←subtype.ext_iff], tauto }, rintro hμ rfl, contradiction }, -- Now we can define `l'_f` as an actual linear combination `l'` because we know that the -- support is finite. let l' : μs →₀ K := { to_fun := l'_f, support := l_support', mem_support_to_fun := h_l_support' }, -- The linear combination `l'` over `xs` adds up to `0`. have total_l' : finsupp.total μs V K xs l' = 0, { let g := f - algebra_map K (End K V) μ₀, have h_gμ₀: g (l μ₀ • xs μ₀) = 0, by rw [linear_map.map_smul, linear_map.sub_apply, mem_eigenspace_iff.1 (h_eigenvec _).2, algebra_map_End_apply, sub_self, smul_zero], have h_useless_filter : finset.filter (λ (a : μs), l'_f a ≠ 0) l_support' = l_support', { rw finset.filter_congr _, { apply finset.filter_true }, { apply_instance }, exact λ μ hμ, (iff_true _).mpr ((h_l_support' μ).1 hμ) }, have bodies_eq : ∀ (μ : μs), l'_f μ • xs μ = g (l μ • xs μ), { intro μ, dsimp only [g, l'_f], rw [linear_map.map_smul, linear_map.sub_apply, mem_eigenspace_iff.1 (h_eigenvec _).2, algebra_map_End_apply, ←sub_smul, smul_smul, mul_comm] }, rw [←linear_map.map_zero g, ←hl, finsupp.total_apply, finsupp.total_apply, finsupp.sum, finsupp.sum, linear_map.map_sum, h_l_support, finset.sum_insert hμ₀, h_gμ₀, zero_add], refine finset.sum_congr rfl (λ μ _, _), apply bodies_eq }, -- Therefore, by the induction hypothesis, all coefficients in `l'` are zero. have l'_eq_0 : l' = 0 := ih l' total_l' rfl, -- By the defintion of `l'`, this means that `(μ - μ₀) * l μ = 0` for all `μ`. have h_mul_eq_0 : ∀ μ : μs, (↑μ - ↑μ₀) * l μ = 0, { intro μ, calc (↑μ - ↑μ₀) * l μ = l' μ : rfl ... = 0 : by { rw [l'_eq_0], refl } }, -- Thus, the coefficients in `l` for all `μ ≠ μ₀` are `0`. have h_lμ_eq_0 : ∀ μ : μs, μ ≠ μ₀ → l μ = 0, { intros μ hμ, apply or_iff_not_imp_left.1 (mul_eq_zero.1 (h_mul_eq_0 μ)), rwa [sub_eq_zero, ←subtype.ext_iff] }, -- So if we sum over all these coefficients, we obtain `0`. have h_sum_l_support'_eq_0 : finset.sum l_support' (λ (μ : ↥μs), l μ • xs μ) = 0, { rw ←finset.sum_const_zero, apply finset.sum_congr rfl, intros μ hμ, rw h_lμ_eq_0, apply zero_smul, intro h, rw h at hμ, contradiction }, -- The only potentially nonzero coefficient in `l` is the one corresponding to `μ₀`. But since -- the overall sum is `0` by assumption, this coefficient must also be `0`. have : l μ₀ = 0, { rw [finsupp.total_apply, finsupp.sum, h_l_support, finset.sum_insert hμ₀, h_sum_l_support'_eq_0, add_zero] at hl, by_contra h, exact (h_eigenvec μ₀).1 ((smul_eq_zero.1 hl).resolve_left h) }, -- Thus, all coefficients in `l` are `0`. show l = 0, { ext μ, by_cases h_cases : μ = μ₀, { rw h_cases, assumption }, exact h_lμ_eq_0 μ h_cases } } end /-- The generalized eigenspace for a linear map `f`, a scalar `μ`, and an exponent `k ∈ ℕ` is the kernel of `(f - μ • id) ^ k`. (Def 8.10 of [axler2015])-/ def generalized_eigenspace (f : End R M) (μ : R) (k : ℕ) : submodule R M := ((f - algebra_map R (End R M) μ) ^ k).ker /-- A nonzero element of a generalized eigenspace is a generalized eigenvector. (Def 8.9 of [axler2015])-/ def has_generalized_eigenvector (f : End R M) (μ : R) (k : ℕ) (x : M) : Prop := x ≠ 0 ∧ x ∈ generalized_eigenspace f μ k /-- A scalar `μ` is a generalized eigenvalue for a linear map `f` and an exponent `k ∈ ℕ` if there are generalized eigenvectors for `f`, `k`, and `μ`. -/ def has_generalized_eigenvalue (f : End R M) (μ : R) (k : ℕ) : Prop := generalized_eigenspace f μ k ≠ ⊥ /-- The generalized eigenrange for a linear map `f`, a scalar `μ`, and an exponent `k ∈ ℕ` is the range of `(f - μ • id) ^ k`. -/ def generalized_eigenrange (f : End R M) (μ : R) (k : ℕ) : submodule R M := ((f - algebra_map R (End R M) μ) ^ k).range /-- The exponent of a generalized eigenvalue is never 0. -/ lemma exp_ne_zero_of_has_generalized_eigenvalue {f : End R M} {μ : R} {k : ℕ} (h : f.has_generalized_eigenvalue μ k) : k ≠ 0 := begin rintro rfl, exact h linear_map.ker_id end /-- A generalized eigenspace for some exponent `k` is contained in the generalized eigenspace for exponents larger than `k`. -/ lemma generalized_eigenspace_mono {f : End K V} {μ : K} {k : ℕ} {m : ℕ} (hm : k ≤ m) : f.generalized_eigenspace μ k ≤ f.generalized_eigenspace μ m := begin simp only [generalized_eigenspace, ←pow_sub_mul_pow _ hm], exact linear_map.ker_le_ker_comp ((f - algebra_map K (End K V) μ) ^ k) ((f - algebra_map K (End K V) μ) ^ (m - k)) end /-- A generalized eigenvalue for some exponent `k` is also a generalized eigenvalue for exponents larger than `k`. -/ lemma has_generalized_eigenvalue_of_has_generalized_eigenvalue_of_le {f : End K V} {μ : K} {k : ℕ} {m : ℕ} (hm : k ≤ m) (hk : f.has_generalized_eigenvalue μ k) : f.has_generalized_eigenvalue μ m := begin unfold has_generalized_eigenvalue at *, contrapose! hk, rw [←le_bot_iff, ←hk], exact generalized_eigenspace_mono hm end /-- The eigenspace is a subspace of the generalized eigenspace. -/ lemma eigenspace_le_generalized_eigenspace {f : End K V} {μ : K} {k : ℕ} (hk : 0 < k) : f.eigenspace μ ≤ f.generalized_eigenspace μ k := generalized_eigenspace_mono (nat.succ_le_of_lt hk) /-- All eigenvalues are generalized eigenvalues. -/ lemma has_generalized_eigenvalue_of_has_eigenvalue {f : End K V} {μ : K} {k : ℕ} (hk : 0 < k) (hμ : f.has_eigenvalue μ) : f.has_generalized_eigenvalue μ k := begin apply has_generalized_eigenvalue_of_has_generalized_eigenvalue_of_le hk, rwa [has_generalized_eigenvalue, generalized_eigenspace, pow_one] end /-- Every generalized eigenvector is a generalized eigenvector for exponent `findim K V`. (Lemma 8.11 of [axler2015]) -/ lemma generalized_eigenspace_le_generalized_eigenspace_findim [finite_dimensional K V] (f : End K V) (μ : K) (k : ℕ) : f.generalized_eigenspace μ k ≤ f.generalized_eigenspace μ (findim K V) := ker_pow_le_ker_pow_findim _ _ /-- Generalized eigenspaces for exponents at least `findim K V` are equal to each other. -/ lemma generalized_eigenspace_eq_generalized_eigenspace_findim_of_le [finite_dimensional K V] (f : End K V) (μ : K) {k : ℕ} (hk : findim K V ≤ k) : f.generalized_eigenspace μ k = f.generalized_eigenspace μ (findim K V) := ker_pow_eq_ker_pow_findim_of_le hk /-- If `f` maps a subspace `p` into itself, then the generalized eigenspace of the restriction of `f` to `p` is the part of the generalized eigenspace of `f` that lies in `p`. -/ lemma generalized_eigenspace_restrict (f : End K V) (p : submodule K V) (k : ℕ) (μ : K) (hfp : ∀ (x : V), x ∈ p → f x ∈ p) : generalized_eigenspace (linear_map.restrict f hfp) μ k = submodule.comap p.subtype (f.generalized_eigenspace μ k) := begin rw [generalized_eigenspace, generalized_eigenspace, ←linear_map.ker_comp], induction k with k ih, { rw [pow_zero,pow_zero], convert linear_map.ker_id, apply submodule.ker_subtype }, { erw [pow_succ', pow_succ', linear_map.ker_comp, ih, ←linear_map.ker_comp, linear_map.comp_assoc], } end /-- Generalized eigenrange and generalized eigenspace for exponent `findim K V` are disjoint. -/ lemma generalized_eigenvec_disjoint_range_ker [finite_dimensional K V] (f : End K V) (μ : K) : disjoint (f.generalized_eigenrange μ (findim K V)) (f.generalized_eigenspace μ (findim K V)) := begin have h := calc submodule.comap ((f - algebra_map _ _ μ) ^ findim K V) (f.generalized_eigenspace μ (findim K V)) = ((f - algebra_map _ _ μ) ^ findim K V * (f - algebra_map K (End K V) μ) ^ findim K V).ker : by { rw [generalized_eigenspace, ←linear_map.ker_comp], refl } ... = f.generalized_eigenspace μ (findim K V + findim K V) : by { rw ←pow_add, refl } ... = f.generalized_eigenspace μ (findim K V) : by { rw generalized_eigenspace_eq_generalized_eigenspace_findim_of_le, linarith }, rw [disjoint, generalized_eigenrange, linear_map.range, submodule.map_inf_eq_map_inf_comap, top_inf_eq, h], apply submodule.map_comap_le end /-- The generalized eigenspace of an eigenvalue has positive dimension for positive exponents. -/ lemma pos_findim_generalized_eigenspace_of_has_eigenvalue [finite_dimensional K V] {f : End K V} {k : ℕ} {μ : K} (hx : f.has_eigenvalue μ) (hk : 0 < k): 0 < findim K (f.generalized_eigenspace μ k) := calc 0 = findim K (⊥ : submodule K V) : by rw findim_bot ... < findim K (f.eigenspace μ) : submodule.findim_lt_findim_of_lt (bot_lt_iff_ne_bot.2 hx) ... ≤ findim K (f.generalized_eigenspace μ k) : submodule.findim_mono (generalized_eigenspace_mono (nat.succ_le_of_lt hk)) /-- A linear map maps a generalized eigenrange into itself. -/ lemma map_generalized_eigenrange_le {f : End K V} {μ : K} {n : ℕ} : submodule.map f (f.generalized_eigenrange μ n) ≤ f.generalized_eigenrange μ n := calc submodule.map f (f.generalized_eigenrange μ n) = (f * ((f - algebra_map _ _ μ) ^ n)).range : (linear_map.range_comp _ _).symm ... = (((f - algebra_map _ _ μ) ^ n) * f).range : by rw algebra.mul_sub_algebra_map_pow_commutes ... = submodule.map ((f - algebra_map _ _ μ) ^ n) f.range : linear_map.range_comp _ _ ... ≤ f.generalized_eigenrange μ n : linear_map.map_le_range /-- The generalized eigenvectors span the entire vector space (Lemma 8.21 of [axler2015]). -/ lemma supr_generalized_eigenspace_eq_top [is_alg_closed K] [finite_dimensional K V] (f : End K V) : (⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k) = ⊤ := begin tactic.unfreeze_local_instances, -- We prove the claim by strong induction on the dimension of the vector space. induction h_dim : findim K V using nat.strong_induction_on with n ih generalizing V, cases n, -- If the vector space is 0-dimensional, the result is trivial. { rw ←top_le_iff, simp only [findim_eq_zero.1 (eq.trans findim_top h_dim), bot_le] }, -- Otherwise the vector space is nontrivial. { haveI : nontrivial V := findim_pos_iff.1 (by { rw h_dim, apply nat.zero_lt_succ }), -- Hence, `f` has an eigenvalue `μ₀`. obtain ⟨μ₀, hμ₀⟩ : ∃ μ₀, f.has_eigenvalue μ₀ := exists_eigenvalue f, -- We define `ES` to be the generalized eigenspace let ES := f.generalized_eigenspace μ₀ (findim K V), -- and `ER` to be the generalized eigenrange. let ER := f.generalized_eigenrange μ₀ (findim K V), -- `f` maps `ER` into itself. have h_f_ER : ∀ (x : V), x ∈ ER → f x ∈ ER, from λ x hx, map_generalized_eigenrange_le (submodule.mem_map_of_mem hx), -- Therefore, we can define the restriction `f'` of `f` to `ER`. let f' : End K ER := f.restrict h_f_ER, -- The dimension of `ES` is positive have h_dim_ES_pos : 0 < findim K ES, { dsimp only [ES], rw h_dim, apply pos_findim_generalized_eigenspace_of_has_eigenvalue hμ₀ (nat.zero_lt_succ n) }, -- and the dimensions of `ES` and `ER` add up to `findim K V`. have h_dim_add : findim K ER + findim K ES = findim K V, { apply linear_map.findim_range_add_findim_ker }, -- Therefore the dimension `ER` mus be smaller than `findim K V`. have h_dim_ER : findim K ER < n.succ, by omega, -- This allows us to apply the induction hypothesis on `ER`: have ih_ER : (⨆ (μ : K) (k : ℕ), f'.generalized_eigenspace μ k) = ⊤, from ih (findim K ER) h_dim_ER f' rfl, -- The induction hypothesis gives us a statement about subspaces of `ER`. We can transfer this -- to a statement about subspaces of `V` via `submodule.subtype`: have ih_ER' : (⨆ (μ : K) (k : ℕ), (f'.generalized_eigenspace μ k).map ER.subtype) = ER, by simp only [(submodule.map_supr _ _).symm, ih_ER, submodule.map_subtype_top ER], -- Moreover, every generalized eigenspace of `f'` is contained in the corresponding generalized -- eigenspace of `f`. have hff' : ∀ μ k, (f'.generalized_eigenspace μ k).map ER.subtype ≤ f.generalized_eigenspace μ k, { intros, rw generalized_eigenspace_restrict, apply submodule.map_comap_le }, -- It follows that `ER` is contained in the span of all generalized eigenvectors. have hER : ER ≤ ⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k, { rw ← ih_ER', apply supr_le_supr _, exact λ μ, supr_le_supr (λ k, hff' μ k), }, -- `ES` is contained in this span by definition. have hES : ES ≤ ⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k, from le_trans (le_supr (λ k, f.generalized_eigenspace μ₀ k) (findim K V)) (le_supr (λ (μ : K), ⨆ (k : ℕ), f.generalized_eigenspace μ k) μ₀), -- Moreover, we know that `ER` and `ES` are disjoint. have h_disjoint : disjoint ER ES, from generalized_eigenvec_disjoint_range_ker f μ₀, -- Since the dimensions of `ER` and `ES` add up to the dimension of `V`, it follows that the -- span of all generalized eigenvectors is all of `V`. show (⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k) = ⊤, { rw [←top_le_iff, ←submodule.eq_top_of_disjoint ER ES h_dim_add h_disjoint], apply sup_le hER hES } } end end End end module variables {K V : Type*} [field K] [add_comm_group V] [vector_space K V] [finite_dimensional K V] protected lemma linear_map.is_integral (f : V →ₗ[K] V) : is_integral K f := module.End.is_integral f
d5608d6b8581b1ac3e89e3450f48cb8999dbefaa
94e33a31faa76775069b071adea97e86e218a8ee
/src/algebraic_topology/simplex_category.lean
36815db57f061b34ad9a9d4229fea2aa844a4bec
[ "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
27,246
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Scott Morrison, Adam Topaz -/ import category_theory.skeletal import tactic.linarith import data.fintype.sort import order.category.NonemptyFinLinOrd import category_theory.functor.reflects_isomorphisms /-! # The simplex category We construct a skeletal model of the simplex category, with objects `ℕ` and the morphism `n ⟶ m` being the monotone maps from `fin (n+1)` to `fin (m+1)`. We show that this category is equivalent to `NonemptyFinLinOrd`. ## Remarks The definitions `simplex_category` and `simplex_category.hom` are marked as irreducible. We provide the following functions to work with these objects: 1. `simplex_category.mk` creates an object of `simplex_category` out of a natural number. Use the notation `[n]` in the `simplicial` locale. 2. `simplex_category.len` gives the "length" of an object of `simplex_category`, as a natural. 3. `simplex_category.hom.mk` makes a morphism out of a monotone map between `fin`'s. 4. `simplex_category.hom.to_order_hom` gives the underlying monotone map associated to a term of `simplex_category.hom`. -/ universe v open category_theory /-- The simplex category: * objects are natural numbers `n : ℕ` * morphisms from `n` to `m` are monotone functions `fin (n+1) → fin (m+1)` -/ @[derive inhabited, irreducible] def simplex_category := ℕ namespace simplex_category section local attribute [semireducible] simplex_category -- TODO: Make `mk` irreducible. /-- Interpet a natural number as an object of the simplex category. -/ def mk (n : ℕ) : simplex_category := n localized "notation `[`n`]` := simplex_category.mk n" in simplicial -- TODO: Make `len` irreducible. /-- The length of an object of `simplex_category`. -/ def len (n : simplex_category) : ℕ := n @[ext] lemma ext (a b : simplex_category) : a.len = b.len → a = b := id @[simp] lemma len_mk (n : ℕ) : [n].len = n := rfl @[simp] lemma mk_len (n : simplex_category) : [n.len] = n := rfl /-- Morphisms in the simplex_category. -/ @[irreducible, nolint has_inhabited_instance] protected def hom (a b : simplex_category) := fin (a.len + 1) →o fin (b.len + 1) namespace hom local attribute [semireducible] simplex_category.hom /-- Make a moprhism in `simplex_category` from a monotone map of fin's. -/ def mk {a b : simplex_category} (f : fin (a.len + 1) →o fin (b.len + 1)) : simplex_category.hom a b := f /-- Recover the monotone map from a morphism in the simplex category. -/ def to_order_hom {a b : simplex_category} (f : simplex_category.hom a b) : fin (a.len + 1) →o fin (b.len + 1) := f @[ext] lemma ext {a b : simplex_category} (f g : simplex_category.hom a b) : f.to_order_hom = g.to_order_hom → f = g := id @[simp] lemma mk_to_order_hom {a b : simplex_category} (f : simplex_category.hom a b) : mk (f.to_order_hom) = f := rfl @[simp] lemma to_order_hom_mk {a b : simplex_category} (f : fin (a.len + 1) →o fin (b.len + 1)) : (mk f).to_order_hom = f := rfl lemma mk_to_order_hom_apply {a b : simplex_category} (f : fin (a.len + 1) →o fin (b.len + 1)) (i : fin (a.len + 1)) : (mk f).to_order_hom i = f i := rfl /-- Identity morphisms of `simplex_category`. -/ @[simp] def id (a : simplex_category) : simplex_category.hom a a := mk order_hom.id /-- Composition of morphisms of `simplex_category`. -/ @[simp] def comp {a b c : simplex_category} (f : simplex_category.hom b c) (g : simplex_category.hom a b) : simplex_category.hom a c := mk $ f.to_order_hom.comp g.to_order_hom end hom @[simps] instance small_category : small_category.{0} simplex_category := { hom := λ n m, simplex_category.hom n m, id := λ m, simplex_category.hom.id _, comp := λ _ _ _ f g, simplex_category.hom.comp g f, } /-- The constant morphism from [0]. -/ def const (x : simplex_category) (i : fin (x.len+1)) : [0] ⟶ x := hom.mk $ ⟨λ _, i, by tauto⟩ @[simp] lemma const_comp (x y : simplex_category) (i : fin (x.len + 1)) (f : x ⟶ y) : const x i ≫ f = const y (f.to_order_hom i) := rfl /-- Make a morphism `[n] ⟶ [m]` from a monotone map between fin's. This is useful for constructing morphisms beetween `[n]` directly without identifying `n` with `[n].len`. -/ @[simp] def mk_hom {n m : ℕ} (f : (fin (n+1)) →o (fin (m+1))) : [n] ⟶ [m] := simplex_category.hom.mk f lemma hom_zero_zero (f : [0] ⟶ [0]) : f = 𝟙 _ := by { ext : 2, dsimp, apply subsingleton.elim } end open_locale simplicial section generators /-! ## Generating maps for the simplex category TODO: prove that the simplex category is equivalent to one given by the following generators and relations. -/ /-- The `i`-th face map from `[n]` to `[n+1]` -/ def δ {n} (i : fin (n+2)) : [n] ⟶ [n+1] := mk_hom (fin.succ_above i).to_order_hom /-- The `i`-th degeneracy map from `[n+1]` to `[n]` -/ def σ {n} (i : fin (n+1)) : [n+1] ⟶ [n] := mk_hom { to_fun := fin.pred_above i, monotone' := fin.pred_above_right_monotone i } /-- The generic case of the first simplicial identity -/ lemma δ_comp_δ {n} {i j : fin (n+2)} (H : i ≤ j) : δ i ≫ δ j.succ = δ j ≫ δ i.cast_succ := begin ext k, dsimp [δ, fin.succ_above], simp only [order_embedding.to_order_hom_coe, order_embedding.coe_of_strict_mono, function.comp_app, simplex_category.hom.to_order_hom_mk, order_hom.comp_coe], rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, rcases k with ⟨k, _⟩, split_ifs; { simp at *; linarith }, end /-- The special case of the first simplicial identity -/ lemma δ_comp_δ_self {n} {i : fin (n+2)} : δ i ≫ δ i.cast_succ = δ i ≫ δ i.succ := (δ_comp_δ (le_refl i)).symm /-- The second simplicial identity -/ lemma δ_comp_σ_of_le {n} {i : fin (n+2)} {j : fin (n+1)} (H : i ≤ j.cast_succ) : δ i.cast_succ ≫ σ j.succ = σ j ≫ δ i := begin ext k, suffices : ite (j.succ.cast_succ < ite (k < i) k.cast_succ k.succ) (ite (k < i) (k:ℕ) (k + 1) - 1) (ite (k < i) k (k + 1)) = ite ((if h : (j:ℕ) < k then k.pred (by { rintro rfl, exact nat.not_lt_zero _ h }) else k.cast_lt (by { cases j, cases k, simp only [len_mk], linarith })).cast_succ < i) (ite (j.cast_succ < k) (k - 1) k) (ite (j.cast_succ < k) (k - 1) k + 1), { dsimp [δ, σ, fin.succ_above, fin.pred_above], simp [fin.pred_above] with push_cast, convert rfl }, rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, rcases k with ⟨k, _⟩, simp only [subtype.mk_le_mk, fin.cast_succ_mk] at H, dsimp, split_ifs, -- Most of the goals can now be handled by `linarith`, -- but we have to deal with two of them by hand. swap 8, { exact (nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) ‹_›)).symm, }, swap 7, { have : k ≤ i := nat.le_of_pred_lt ‹_›, linarith, }, -- Hope for the best from `linarith`: all_goals { try { refl <|> simp at * }; linarith, }, end /-- The first part of the third simplicial identity -/ lemma δ_comp_σ_self {n} {i : fin (n+1)} : δ i.cast_succ ≫ σ i = 𝟙 [n] := begin ext j, suffices : ite (fin.cast_succ i < ite (j < i) (fin.cast_succ j) j.succ) (ite (j < i) (j:ℕ) (j + 1) - 1) (ite (j < i) j (j + 1)) = j, { dsimp [δ, σ, fin.succ_above, fin.pred_above], simpa [fin.pred_above] with push_cast }, rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, dsimp, split_ifs; { simp at *; linarith, }, end /-- The second part of the third simplicial identity -/ lemma δ_comp_σ_succ {n} {i : fin (n+1)} : δ i.succ ≫ σ i = 𝟙 [n] := begin ext j, rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, dsimp [δ, σ, fin.succ_above, fin.pred_above], simp [fin.pred_above] with push_cast, split_ifs; { simp at *; linarith, }, end /-- The fourth simplicial identity -/ lemma δ_comp_σ_of_gt {n} {i : fin (n+2)} {j : fin (n+1)} (H : j.cast_succ < i) : δ i.succ ≫ σ j.cast_succ = σ j ≫ δ i := begin ext k, dsimp [δ, σ, fin.succ_above, fin.pred_above], rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, rcases k with ⟨k, _⟩, simp only [subtype.mk_lt_mk, fin.cast_succ_mk] at H, suffices : ite (_ < ite (k < i + 1) _ _) _ _ = ite _ (ite (j < k) (k - 1) k) (ite (j < k) (k - 1) k + 1), { simpa [apply_dite fin.cast_succ, fin.pred_above] with push_cast, }, split_ifs, -- Most of the goals can now be handled by `linarith`, -- but we have to deal with three of them by hand. swap 2, { simp only [subtype.mk_lt_mk] at h_1, simp only [not_lt] at h_2, simp only [self_eq_add_right, one_ne_zero], exact lt_irrefl (k - 1) (lt_of_lt_of_le (nat.pred_lt (ne_of_lt (lt_of_le_of_lt (zero_le _) h_1)).symm) (le_trans (nat.le_of_lt_succ h) h_2)) }, swap 4, { simp only [subtype.mk_lt_mk] at h_1, simp only [not_lt] at h, simp only [nat.add_succ_sub_one, add_zero], exfalso, exact lt_irrefl _ (lt_of_le_of_lt (nat.le_pred_of_lt (nat.lt_of_succ_le h)) h_3), }, swap 4, { simp only [subtype.mk_lt_mk] at h_1, simp only [not_lt] at h_3, simp only [nat.add_succ_sub_one, add_zero], exact (nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) h_2)).symm, }, -- Hope for the best from `linarith`: all_goals { simp at h_1 h_2 ⊢; linarith, }, end local attribute [simp] fin.pred_mk /-- The fifth simplicial identity -/ lemma σ_comp_σ {n} {i j : fin (n+1)} (H : i ≤ j) : σ i.cast_succ ≫ σ j = σ j.succ ≫ σ i := begin ext k, dsimp [σ, fin.pred_above], rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, rcases k with ⟨k, _⟩, simp only [subtype.mk_le_mk] at H, -- At this point `simp with push_cast` makes good progress, but neither `simp?` nor `squeeze_simp` -- return usable sets of lemmas. -- To avoid using a non-terminal simp, we make a `suffices` statement indicating the shape -- of the goal we're looking for, and then use `simpa with push_cast`. -- I'm not sure this is actually much more robust that a non-terminal simp. suffices : ite (_ < dite (i < k) _ _) _ _ = ite (_ < dite (j + 1 < k) _ _) _ _, { simpa [fin.pred_above] with push_cast, }, split_ifs, -- `split_ifs` created 12 goals. -- Most of them are dealt with `by simp at *; linarith`, -- but we pull out two harder ones to do by hand. swap 3, { simp only [not_lt] at h_2, exact false.elim (lt_irrefl (k - 1) (lt_of_lt_of_le (nat.pred_lt (id (ne_of_lt (lt_of_le_of_lt (zero_le i) h)).symm)) (le_trans h_2 (nat.succ_le_of_lt h_1)))) }, swap 3, { simp only [subtype.mk_lt_mk, not_lt] at h_1, exact false.elim (lt_irrefl j (lt_of_lt_of_le (nat.pred_lt_pred (nat.succ_ne_zero j) h_2) h_1)) }, -- Deal with the rest automatically. all_goals { simp at *; linarith, }, end end generators section skeleton /-- The functor that exhibits `simplex_category` as skeleton of `NonemptyFinLinOrd` -/ @[simps obj map] def skeletal_functor : simplex_category ⥤ NonemptyFinLinOrd.{v} := { obj := λ a, NonemptyFinLinOrd.of $ ulift (fin (a.len + 1)), map := λ a b f, ⟨λ i, ulift.up (f.to_order_hom i.down), λ i j h, f.to_order_hom.monotone h⟩, map_id' := λ a, by { ext, simp, }, map_comp' := λ a b c f g, by { ext, simp, }, } lemma skeletal : skeletal simplex_category := λ X Y ⟨I⟩, begin suffices : fintype.card (fin (X.len+1)) = fintype.card (fin (Y.len+1)), { ext, simpa }, { apply fintype.card_congr, refine equiv.ulift.symm.trans (((skeletal_functor ⋙ forget _).map_iso I).to_equiv.trans _), apply equiv.ulift } end namespace skeletal_functor instance : full skeletal_functor.{v} := { preimage := λ a b f, simplex_category.hom.mk ⟨λ i, (f (ulift.up i)).down, λ i j h, f.monotone h⟩, witness' := by { intros m n f, dsimp at *, ext1 ⟨i⟩, ext1, ext1, cases x, simp, } } instance : faithful skeletal_functor.{v} := { map_injective' := λ m n f g h, begin ext1, ext1, ext1 i, apply ulift.up.inj, change (skeletal_functor.map f) ⟨i⟩ = (skeletal_functor.map g) ⟨i⟩, rw h, end } instance : ess_surj skeletal_functor.{v} := { mem_ess_image := λ X, ⟨mk (fintype.card X - 1 : ℕ), ⟨begin have aux : fintype.card X = fintype.card X - 1 + 1, { exact (nat.succ_pred_eq_of_pos $ fintype.card_pos_iff.mpr ⟨⊥⟩).symm, }, let f := mono_equiv_of_fin X aux, have hf := (finset.univ.order_emb_of_fin aux).strict_mono, refine { hom := ⟨λ i, f i.down, _⟩, inv := ⟨λ i, ⟨f.symm i⟩, _⟩, hom_inv_id' := _, inv_hom_id' := _ }, { rintro ⟨i⟩ ⟨j⟩ h, show f i ≤ f j, exact hf.monotone h, }, { intros i j h, show f.symm i ≤ f.symm j, rw ← hf.le_iff_le, show f (f.symm i) ≤ f (f.symm j), simpa only [order_iso.apply_symm_apply], }, { ext1, ext1 ⟨i⟩, ext1, exact f.symm_apply_apply i }, { ext1, ext1 i, exact f.apply_symm_apply i }, end⟩⟩, } noncomputable instance is_equivalence : is_equivalence (skeletal_functor.{v}) := equivalence.of_fully_faithfully_ess_surj skeletal_functor end skeletal_functor /-- The equivalence that exhibits `simplex_category` as skeleton of `NonemptyFinLinOrd` -/ noncomputable def skeletal_equivalence : simplex_category ≌ NonemptyFinLinOrd.{v} := functor.as_equivalence skeletal_functor end skeleton /-- `simplex_category` is a skeleton of `NonemptyFinLinOrd`. -/ noncomputable def is_skeleton_of : is_skeleton_of NonemptyFinLinOrd simplex_category skeletal_functor.{v} := { skel := skeletal, eqv := skeletal_functor.is_equivalence } /-- The truncated simplex category. -/ @[derive small_category] def truncated (n : ℕ) := {a : simplex_category // a.len ≤ n} namespace truncated instance {n} : inhabited (truncated n) := ⟨⟨[0],by simp⟩⟩ /-- The fully faithful inclusion of the truncated simplex category into the usual simplex category. -/ @[derive [full, faithful]] def inclusion {n : ℕ} : simplex_category.truncated n ⥤ simplex_category := full_subcategory_inclusion _ end truncated section concrete instance : concrete_category.{0} simplex_category := { forget := { obj := λ i, fin (i.len + 1), map := λ i j f, f.to_order_hom }, forget_faithful := {} } end concrete section epi_mono /-- A morphism in `simplex_category` is a monomorphism precisely when it is an injective function -/ theorem mono_iff_injective {n m : simplex_category} {f : n ⟶ m} : mono f ↔ function.injective f.to_order_hom := begin split, { introsI m x y h, have H : const n x ≫ f = const n y ≫ f, { dsimp, rw h }, change (n.const x).to_order_hom 0 = (n.const y).to_order_hom 0, rw cancel_mono f at H, rw H }, { exact concrete_category.mono_of_injective f } end /-- A morphism in `simplex_category` is an epimorphism if and only if it is a surjective function -/ lemma epi_iff_surjective {n m : simplex_category} {f: n ⟶ m} : epi f ↔ function.surjective f.to_order_hom := begin split, { introsI hyp_f_epi x, by_contra' h_ab, -- The proof is by contradiction: assume f is not surjective, -- then introduce two non-equal auxiliary functions equalizing f, and get a contradiction. -- First we define the two auxiliary functions. set chi_1 : m ⟶ [1] := hom.mk ⟨λ u, if u ≤ x then 0 else 1, begin intros a b h, dsimp only [], split_ifs with h1 h2 h3, any_goals { exact le_rfl }, { exact bot_le }, { exact false.elim (h1 (le_trans h h3)) } end ⟩, set chi_2 : m ⟶ [1] := hom.mk ⟨λ u, if u < x then 0 else 1, begin intros a b h, dsimp only [], split_ifs with h1 h2 h3, any_goals { exact le_rfl }, { exact bot_le }, { exact false.elim (h1 (lt_of_le_of_lt h h3)) } end ⟩, -- The two auxiliary functions equalize f have f_comp_chi_i : f ≫ chi_1 = f ≫ chi_2, { dsimp, ext, simp [le_iff_lt_or_eq, h_ab x_1] }, -- We now just have to show the two auxiliary functions are not equal. rw category_theory.cancel_epi f at f_comp_chi_i, rename f_comp_chi_i eq_chi_i, apply_fun (λ e, e.to_order_hom x) at eq_chi_i, suffices : (0 : fin 2) = 1, by exact bot_ne_top this, simpa using eq_chi_i }, { exact concrete_category.epi_of_surjective f } end /-- A monomorphism in `simplex_category` must increase lengths-/ lemma len_le_of_mono {x y : simplex_category} {f : x ⟶ y} : mono f → (x.len ≤ y.len) := begin intro hyp_f_mono, have f_inj : function.injective f.to_order_hom.to_fun, { exact mono_iff_injective.elim_left (hyp_f_mono) }, simpa using fintype.card_le_of_injective f.to_order_hom.to_fun f_inj, end lemma le_of_mono {n m : ℕ} {f : [n] ⟶ [m]} : (category_theory.mono f) → (n ≤ m) := len_le_of_mono /-- An epimorphism in `simplex_category` must decrease lengths-/ lemma len_le_of_epi {x y : simplex_category} {f : x ⟶ y} : epi f → y.len ≤ x.len := begin intro hyp_f_epi, have f_surj : function.surjective f.to_order_hom.to_fun, { exact epi_iff_surjective.elim_left (hyp_f_epi) }, simpa using fintype.card_le_of_surjective f.to_order_hom.to_fun f_surj, end lemma le_of_epi {n m : ℕ} {f : [n] ⟶ [m]} : epi f → (m ≤ n) := len_le_of_epi instance {n : ℕ} {i : fin (n+2)} : mono (δ i) := begin rw mono_iff_injective, exact fin.succ_above_right_injective, end instance {n : ℕ} {i : fin (n+1)} : epi (σ i) := begin rw epi_iff_surjective, intro b, simp only [σ, mk_hom, hom.to_order_hom_mk, order_hom.coe_fun_mk], by_cases b ≤ i, { use b, rw fin.pred_above_below i b (by simpa only [fin.coe_eq_cast_succ] using h), simp only [fin.coe_eq_cast_succ, fin.cast_pred_cast_succ], }, { use b.succ, rw [fin.pred_above_above i b.succ _, fin.pred_succ], rw not_le at h, rw fin.lt_iff_coe_lt_coe at h ⊢, simpa only [fin.coe_succ, fin.coe_cast_succ] using nat.lt.step h, } end instance : reflects_isomorphisms (forget simplex_category) := ⟨begin intros x y f, introI, exact is_iso.of_iso { hom := f, inv := hom.mk { to_fun := inv ((forget simplex_category).map f), monotone' :=λ y₁ y₂ h, begin by_cases h' : y₁ < y₂, { by_contradiction h'', have eq := λ i, congr_hom (iso.inv_hom_id (as_iso ((forget _).map f))) i, have ineq := f.to_order_hom.monotone' (le_of_not_ge h''), dsimp at ineq, erw [eq, eq] at ineq, exact not_le.mpr h' ineq, }, { rw eq_of_le_of_not_lt h h', } end, }, hom_inv_id' := by { ext1, ext1, exact iso.hom_inv_id (as_iso ((forget _).map f)), }, inv_hom_id' := by { ext1, ext1, exact iso.inv_hom_id (as_iso ((forget _).map f)), }, }, end⟩ lemma is_iso_of_bijective {x y : simplex_category} {f : x ⟶ y} (hf : function.bijective (f.to_order_hom.to_fun)) : is_iso f := begin haveI : is_iso ((forget simplex_category).map f) := (is_iso_iff_bijective _).mpr hf, exact is_iso_of_reflects_iso f (forget simplex_category), end /-- An isomorphism in `simplex_category` induces an `order_iso`. -/ @[simp] def order_iso_of_iso {x y : simplex_category} (e : x ≅ y) : fin (x.len+1) ≃o fin (y.len+1) := equiv.to_order_iso { to_fun := e.hom.to_order_hom, inv_fun := e.inv.to_order_hom, left_inv := λ i, by simpa only using congr_arg (λ φ, (hom.to_order_hom φ) i) e.hom_inv_id', right_inv := λ i, by simpa only using congr_arg (λ φ, (hom.to_order_hom φ) i) e.inv_hom_id', } e.hom.to_order_hom.monotone e.inv.to_order_hom.monotone lemma iso_eq_iso_refl {x : simplex_category} (e : x ≅ x) : e = iso.refl x := begin have h : (finset.univ : finset (fin (x.len+1))).card = x.len+1 := finset.card_fin (x.len+1), have eq₁ := finset.order_emb_of_fin_unique' h (λ i, finset.mem_univ ((order_iso_of_iso e) i)), have eq₂ := finset.order_emb_of_fin_unique' h (λ i, finset.mem_univ ((order_iso_of_iso (iso.refl x)) i)), ext1, ext1, convert congr_arg (λ φ, (order_embedding.to_order_hom φ)) (eq₁.trans eq₂.symm), ext1, ext1 i, refl, end lemma eq_id_of_is_iso {x : simplex_category} {f : x ⟶ x} (hf : is_iso f) : f = 𝟙 _ := congr_arg (λ (φ : _ ≅ _), φ.hom) (iso_eq_iso_refl (as_iso f)) lemma eq_σ_comp_of_not_injective' {n : ℕ} {Δ' : simplex_category} (θ : mk (n+1) ⟶ Δ') (i : fin (n+1)) (hi : θ.to_order_hom i.cast_succ = θ.to_order_hom i.succ): ∃ (θ' : mk n ⟶ Δ'), θ = σ i ≫ θ' := begin use δ i.succ ≫ θ, ext1, ext1, ext1 x, simp only [hom.to_order_hom_mk, function.comp_app, order_hom.comp_coe, hom.comp, small_category_comp, σ, mk_hom, order_hom.coe_fun_mk], by_cases h' : x ≤ i.cast_succ, { rw fin.pred_above_below i x h', have eq := fin.cast_succ_cast_pred (gt_of_gt_of_ge (fin.cast_succ_lt_last i) h'), erw fin.succ_above_below i.succ x.cast_pred _, swap, { rwa [eq, ← fin.le_cast_succ_iff], }, rw eq, }, { simp only [not_le] at h', let y := x.pred begin intro h, rw h at h', simpa only [fin.lt_iff_coe_lt_coe, nat.not_lt_zero, fin.coe_zero] using h', end, simp only [show x = y.succ, by rw fin.succ_pred] at h' ⊢, rw [fin.pred_above_above i y.succ h', fin.pred_succ], by_cases h'' : y = i, { rw h'', convert hi.symm, erw fin.succ_above_below i.succ _, exact fin.lt_succ, }, { erw fin.succ_above_above i.succ _, simp only [fin.lt_iff_coe_lt_coe, fin.le_iff_coe_le_coe, fin.coe_succ, fin.coe_cast_succ, nat.lt_succ_iff, fin.ext_iff] at h' h'' ⊢, cases nat.le.dest h' with c hc, cases c, { exfalso, rw [add_zero] at hc, rw [hc] at h'', exact h'' rfl, }, { rw ← hc, simp only [add_le_add_iff_left, nat.succ_eq_add_one, le_add_iff_nonneg_left, zero_le], }, }, } end lemma eq_σ_comp_of_not_injective {n : ℕ} {Δ' : simplex_category} (θ : mk (n+1) ⟶ Δ') (hθ : ¬function.injective θ.to_order_hom) : ∃ (i : fin (n+1)) (θ' : mk n ⟶ Δ'), θ = σ i ≫ θ' := begin simp only [function.injective, exists_prop, not_forall] at hθ, -- as θ is not injective, there exists `x<y` such that `θ x = θ y` -- and then, `θ x = θ (x+1)` have hθ₂ : ∃ (x y : fin (n+2)), (hom.to_order_hom θ) x = (hom.to_order_hom θ) y ∧ x<y, { rcases hθ with ⟨x, y, ⟨h₁, h₂⟩⟩, by_cases x<y, { exact ⟨x, y, ⟨h₁, h⟩⟩, }, { refine ⟨y, x, ⟨h₁.symm, _⟩⟩, cases lt_or_eq_of_le (not_lt.mp h) with h' h', { exact h', }, { exfalso, exact h₂ h'.symm, }, }, }, rcases hθ₂ with ⟨x, y, ⟨h₁, h₂⟩⟩, let z := x.cast_pred, use z, simp only [← (show z.cast_succ = x, by exact fin.cast_succ_cast_pred (lt_of_lt_of_le h₂ (fin.le_last y)))] at h₁ h₂, apply eq_σ_comp_of_not_injective', rw fin.cast_succ_lt_iff_succ_le at h₂, apply le_antisymm, { exact θ.to_order_hom.monotone (le_of_lt (fin.cast_succ_lt_succ z)), }, { rw h₁, exact θ.to_order_hom.monotone h₂, }, end lemma eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : simplex_category} (θ : Δ ⟶ mk (n+1)) (i : fin (n+2)) (hi : ∀ x, θ.to_order_hom x ≠ i) : ∃ (θ' : Δ ⟶ (mk n)), θ = θ' ≫ δ i := begin by_cases i < fin.last (n+1), { use θ ≫ σ (fin.cast_pred i), ext1, ext1, ext1 x, simp only [hom.to_order_hom_mk, function.comp_app, order_hom.comp_coe, hom.comp, small_category_comp], by_cases h' : θ.to_order_hom x ≤ i, { simp only [σ, mk_hom, hom.to_order_hom_mk, order_hom.coe_fun_mk], rw fin.pred_above_below (fin.cast_pred i) (θ.to_order_hom x) (by simpa [fin.cast_succ_cast_pred h] using h'), erw fin.succ_above_below i, swap, { simp only [fin.lt_iff_coe_lt_coe, fin.coe_cast_succ], exact lt_of_le_of_lt (fin.coe_cast_pred_le_self _) (fin.lt_iff_coe_lt_coe.mp ((ne.le_iff_lt (hi x)).mp h')), }, rw fin.cast_succ_cast_pred, apply lt_of_le_of_lt h' h, }, { simp only [not_le] at h', simp only [σ, mk_hom, hom.to_order_hom_mk, order_hom.coe_fun_mk, fin.pred_above_above (fin.cast_pred i) (θ.to_order_hom x) (by simpa only [fin.cast_succ_cast_pred h] using h')], erw [fin.succ_above_above i _, fin.succ_pred], simpa only [fin.le_iff_coe_le_coe, fin.coe_cast_succ, fin.coe_pred] using nat.le_pred_of_lt (fin.lt_iff_coe_lt_coe.mp h'), }, }, { obtain rfl := le_antisymm (fin.le_last i) (not_lt.mp h), use θ ≫ σ (fin.last _), ext1, ext1, ext1 x, simp only [hom.to_order_hom_mk, function.comp_app, order_hom.comp_coe, hom.comp, small_category_comp, σ, δ, mk_hom, order_hom.coe_fun_mk, order_embedding.to_order_hom_coe, fin.pred_above_last, fin.succ_above_last, fin.cast_succ_cast_pred ((ne.le_iff_lt (hi x)).mp (fin.le_last _))], }, end lemma eq_comp_δ_of_not_surjective {n : ℕ} {Δ : simplex_category} (θ : Δ ⟶ mk (n+1)) (hθ : ¬function.surjective θ.to_order_hom) : ∃ (i : fin (n+2)) (θ' : Δ ⟶ (mk n)), θ = θ' ≫ δ i := begin cases not_forall.mp hθ with i hi, use i, exact eq_comp_δ_of_not_surjective' θ i (not_exists.mp hi), end lemma eq_id_of_mono {x : simplex_category} (i : x ⟶ x) [mono i] : i = 𝟙 _ := begin apply eq_id_of_is_iso, apply is_iso_of_bijective, dsimp, rw [fintype.bijective_iff_injective_and_card i.to_order_hom, ← mono_iff_injective, eq_self_iff_true, and_true], apply_instance, end lemma eq_id_of_epi {x : simplex_category} (i : x ⟶ x) [epi i] : i = 𝟙 _ := begin apply eq_id_of_is_iso, apply is_iso_of_bijective, dsimp, rw [fintype.bijective_iff_surjective_and_card i.to_order_hom, ← epi_iff_surjective, eq_self_iff_true, and_true], apply_instance, end lemma eq_σ_of_epi {n : ℕ} (θ : mk (n+1) ⟶ mk n) [epi θ] : ∃ (i : fin (n+1)), θ = σ i := begin rcases eq_σ_comp_of_not_injective θ _ with ⟨i, θ', h⟩, swap, { by_contradiction, simpa only [nat.one_ne_zero, add_le_iff_nonpos_right, nonpos_iff_eq_zero] using le_of_mono (mono_iff_injective.mpr h), }, use i, haveI : epi (σ i ≫ θ') := by { rw ← h, apply_instance, }, haveI := category_theory.epi_of_epi (σ i) θ', rw [h, eq_id_of_epi θ', category.comp_id], end lemma eq_δ_of_mono {n : ℕ} (θ : mk n ⟶ mk (n+1)) [mono θ] : ∃ (i : fin (n+2)), θ = δ i := begin rcases eq_comp_δ_of_not_surjective θ _ with ⟨i, θ', h⟩, swap, { by_contradiction, simpa only [add_le_iff_nonpos_right, nonpos_iff_eq_zero] using le_of_epi (epi_iff_surjective.mpr h), }, use i, haveI : mono (θ' ≫ δ i) := by { rw ← h, apply_instance, }, haveI := category_theory.mono_of_mono θ' (δ i), rw [h, eq_id_of_mono θ', category.id_comp], end end epi_mono /-- This functor `simplex_category ⥤ Cat` sends `[n]` (for `n : ℕ`) to the category attached to the ordered set `{0, 1, ..., n}` -/ @[simps obj map] def to_Cat : simplex_category ⥤ Cat.{0} := simplex_category.skeletal_functor ⋙ forget₂ NonemptyFinLinOrd LinearOrder ⋙ forget₂ LinearOrder Lattice ⋙ forget₂ Lattice PartialOrder ⋙ forget₂ PartialOrder Preorder ⋙ Preorder_to_Cat end simplex_category
bce2c75c2fb596cf9ecf97afd7e76058f5b75795
9dc8cecdf3c4634764a18254e94d43da07142918
/src/data/multiset/basic.lean
515aed2fffe644b5296ef55a67ce4cdf78247e93
[ "Apache-2.0" ]
permissive
jcommelin/mathlib
d8456447c36c176e14d96d9e76f39841f69d2d9b
ee8279351a2e434c2852345c51b728d22af5a156
refs/heads/master
1,664,782,136,488
1,663,638,983,000
1,663,638,983,000
132,563,656
0
0
Apache-2.0
1,663,599,929,000
1,525,760,539,000
Lean
UTF-8
Lean
false
false
95,603
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import data.bool.all_any import data.list.perm /-! # Multisets These are implemented as the quotient of a list by permutations. ## Notation We define the global infix notation `::ₘ` for `multiset.cons`. -/ open list subtype nat variables {α : Type*} {β : Type*} {γ : Type*} /-- `multiset α` is the quotient of `list α` by list permutation. The result is a type of finite sets with duplicates allowed. -/ def {u} multiset (α : Type u) : Type u := quotient (list.is_setoid α) namespace multiset instance : has_coe (list α) (multiset α) := ⟨quot.mk _⟩ @[simp] theorem quot_mk_to_coe (l : list α) : @eq (multiset α) ⟦l⟧ l := rfl @[simp] theorem quot_mk_to_coe' (l : list α) : @eq (multiset α) (quot.mk (≈) l) l := rfl @[simp] theorem quot_mk_to_coe'' (l : list α) : @eq (multiset α) (quot.mk setoid.r l) l := rfl @[simp] theorem coe_eq_coe {l₁ l₂ : list α} : (l₁ : multiset α) = l₂ ↔ l₁ ~ l₂ := quotient.eq instance has_decidable_eq [decidable_eq α] : decidable_eq (multiset α) | s₁ s₂ := quotient.rec_on_subsingleton₂ s₁ s₂ $ λ l₁ l₂, decidable_of_iff' _ quotient.eq /-- defines a size for a multiset by referring to the size of the underlying list -/ protected def sizeof [has_sizeof α] (s : multiset α) : ℕ := quot.lift_on s sizeof $ λ l₁ l₂, perm.sizeof_eq_sizeof instance has_sizeof [has_sizeof α] : has_sizeof (multiset α) := ⟨multiset.sizeof⟩ /-! ### Empty multiset -/ /-- `0 : multiset α` is the empty set -/ protected def zero : multiset α := @nil α instance : has_zero (multiset α) := ⟨multiset.zero⟩ instance : has_emptyc (multiset α) := ⟨0⟩ instance inhabited_multiset : inhabited (multiset α) := ⟨0⟩ @[simp] theorem coe_nil : (@nil α : multiset α) = 0 := rfl @[simp] theorem empty_eq_zero : (∅ : multiset α) = 0 := rfl @[simp] theorem coe_eq_zero (l : list α) : (l : multiset α) = 0 ↔ l = [] := iff.trans coe_eq_coe perm_nil lemma coe_eq_zero_iff_empty (l : list α) : (l : multiset α) = 0 ↔ l.empty := iff.trans (coe_eq_zero l) (empty_iff_eq_nil).symm /-! ### `multiset.cons` -/ /-- `cons a s` is the multiset which contains `s` plus one more instance of `a`. -/ def cons (a : α) (s : multiset α) : multiset α := quot.lift_on s (λ l, (a :: l : multiset α)) (λ l₁ l₂ p, quot.sound (p.cons a)) infixr ` ::ₘ `:67 := multiset.cons instance : has_insert α (multiset α) := ⟨cons⟩ @[simp] theorem insert_eq_cons (a : α) (s : multiset α) : insert a s = a ::ₘ s := rfl @[simp] theorem cons_coe (a : α) (l : list α) : (a ::ₘ l : multiset α) = (a::l : list α) := rfl @[simp] theorem cons_inj_left {a b : α} (s : multiset α) : a ::ₘ s = b ::ₘ s ↔ a = b := ⟨quot.induction_on s $ λ l e, have [a] ++ l ~ [b] ++ l, from quotient.exact e, singleton_perm_singleton.1 $ (perm_append_right_iff _).1 this, congr_arg _⟩ @[simp] theorem cons_inj_right (a : α) : ∀{s t : multiset α}, a ::ₘ s = a ::ₘ t ↔ s = t := by rintros ⟨l₁⟩ ⟨l₂⟩; simp @[recursor 5] protected theorem induction {p : multiset α → Prop} (h₁ : p 0) (h₂ : ∀ ⦃a : α⦄ {s : multiset α}, p s → p (a ::ₘ s)) : ∀s, p s := by rintros ⟨l⟩; induction l with _ _ ih; [exact h₁, exact h₂ ih] @[elab_as_eliminator] protected theorem induction_on {p : multiset α → Prop} (s : multiset α) (h₁ : p 0) (h₂ : ∀ ⦃a : α⦄ {s : multiset α}, p s → p (a ::ₘ s)) : p s := multiset.induction h₁ h₂ s theorem cons_swap (a b : α) (s : multiset α) : a ::ₘ b ::ₘ s = b ::ₘ a ::ₘ s := quot.induction_on s $ λ l, quotient.sound $ perm.swap _ _ _ section rec variables {C : multiset α → Sort*} /-- Dependent recursor on multisets. TODO: should be @[recursor 6], but then the definition of `multiset.pi` fails with a stack overflow in `whnf`. -/ protected def rec (C_0 : C 0) (C_cons : Πa m, C m → C (a ::ₘ m)) (C_cons_heq : ∀ a a' m b, C_cons a (a' ::ₘ m) (C_cons a' m b) == C_cons a' (a ::ₘ m) (C_cons a m b)) (m : multiset α) : C m := quotient.hrec_on m (@list.rec α (λl, C ⟦l⟧) C_0 (λa l b, C_cons a ⟦l⟧ b)) $ assume l l' h, h.rec_heq (assume a l l' b b' hl, have ⟦l⟧ = ⟦l'⟧, from quot.sound hl, by cc) (assume a a' l, C_cons_heq a a' ⟦l⟧) /-- Companion to `multiset.rec` with more convenient argument order. -/ @[elab_as_eliminator] protected def rec_on (m : multiset α) (C_0 : C 0) (C_cons : Πa m, C m → C (a ::ₘ m)) (C_cons_heq : ∀a a' m b, C_cons a (a' ::ₘ m) (C_cons a' m b) == C_cons a' (a ::ₘ m) (C_cons a m b)) : C m := multiset.rec C_0 C_cons C_cons_heq m variables {C_0 : C 0} {C_cons : Πa m, C m → C (a ::ₘ m)} {C_cons_heq : ∀a a' m b, C_cons a (a' ::ₘ m) (C_cons a' m b) == C_cons a' (a ::ₘ m) (C_cons a m b)} @[simp] lemma rec_on_0 : @multiset.rec_on α C (0:multiset α) C_0 C_cons C_cons_heq = C_0 := rfl @[simp] lemma rec_on_cons (a : α) (m : multiset α) : (a ::ₘ m).rec_on C_0 C_cons C_cons_heq = C_cons a m (m.rec_on C_0 C_cons C_cons_heq) := quotient.induction_on m $ assume l, rfl end rec section mem /-- `a ∈ s` means that `a` has nonzero multiplicity in `s`. -/ def mem (a : α) (s : multiset α) : Prop := quot.lift_on s (λ l, a ∈ l) (λ l₁ l₂ (e : l₁ ~ l₂), propext $ e.mem_iff) instance : has_mem α (multiset α) := ⟨mem⟩ @[simp] lemma mem_coe {a : α} {l : list α} : a ∈ (l : multiset α) ↔ a ∈ l := iff.rfl instance decidable_mem [decidable_eq α] (a : α) (s : multiset α) : decidable (a ∈ s) := quot.rec_on_subsingleton s $ list.decidable_mem a @[simp] theorem mem_cons {a b : α} {s : multiset α} : a ∈ b ::ₘ s ↔ a = b ∨ a ∈ s := quot.induction_on s $ λ l, iff.rfl lemma mem_cons_of_mem {a b : α} {s : multiset α} (h : a ∈ s) : a ∈ b ::ₘ s := mem_cons.2 $ or.inr h @[simp] theorem mem_cons_self (a : α) (s : multiset α) : a ∈ a ::ₘ s := mem_cons.2 (or.inl rfl) theorem forall_mem_cons {p : α → Prop} {a : α} {s : multiset α} : (∀ x ∈ (a ::ₘ s), p x) ↔ p a ∧ ∀ x ∈ s, p x := quotient.induction_on' s $ λ L, list.forall_mem_cons theorem exists_cons_of_mem {s : multiset α} {a : α} : a ∈ s → ∃ t, s = a ::ₘ t := quot.induction_on s $ λ l (h : a ∈ l), let ⟨l₁, l₂, e⟩ := mem_split h in e.symm ▸ ⟨(l₁++l₂ : list α), quot.sound perm_middle⟩ @[simp] theorem not_mem_zero (a : α) : a ∉ (0 : multiset α) := id theorem eq_zero_of_forall_not_mem {s : multiset α} : (∀x, x ∉ s) → s = 0 := quot.induction_on s $ λ l H, by rw eq_nil_iff_forall_not_mem.mpr H; refl theorem eq_zero_iff_forall_not_mem {s : multiset α} : s = 0 ↔ ∀ a, a ∉ s := ⟨λ h, h.symm ▸ λ _, not_false, eq_zero_of_forall_not_mem⟩ theorem exists_mem_of_ne_zero {s : multiset α} : s ≠ 0 → ∃ a : α, a ∈ s := quot.induction_on s $ assume l hl, match l, hl with | [] := assume h, false.elim $ h rfl | (a :: l) := assume _, ⟨a, by simp⟩ end lemma empty_or_exists_mem (s : multiset α) : s = 0 ∨ ∃ a, a ∈ s := or_iff_not_imp_left.mpr multiset.exists_mem_of_ne_zero @[simp] lemma zero_ne_cons {a : α} {m : multiset α} : 0 ≠ a ::ₘ m := assume h, have a ∈ (0:multiset α), from h.symm ▸ mem_cons_self _ _, not_mem_zero _ this @[simp] lemma cons_ne_zero {a : α} {m : multiset α} : a ::ₘ m ≠ 0 := zero_ne_cons.symm lemma cons_eq_cons {a b : α} {as bs : multiset α} : a ::ₘ as = b ::ₘ bs ↔ ((a = b ∧ as = bs) ∨ (a ≠ b ∧ ∃cs, as = b ::ₘ cs ∧ bs = a ::ₘ cs)) := begin haveI : decidable_eq α := classical.dec_eq α, split, { assume eq, by_cases a = b, { subst h, simp * at * }, { have : a ∈ b ::ₘ bs, from eq ▸ mem_cons_self _ _, have : a ∈ bs, by simpa [h], rcases exists_cons_of_mem this with ⟨cs, hcs⟩, simp [h, hcs], have : a ::ₘ as = b ::ₘ a ::ₘ cs, by simp [eq, hcs], have : a ::ₘ as = a ::ₘ b ::ₘ cs, by rwa [cons_swap], simpa using this } }, { assume h, rcases h with ⟨eq₁, eq₂⟩ | ⟨h, cs, eq₁, eq₂⟩, { simp * }, { simp [*, cons_swap a b] } } end end mem /-! ### Singleton -/ instance : has_singleton α (multiset α) := ⟨λ a, a ::ₘ 0⟩ instance : is_lawful_singleton α (multiset α) := ⟨λ a, rfl⟩ @[simp] theorem cons_zero (a : α) : a ::ₘ 0 = {a} := rfl @[simp] theorem coe_singleton (a : α) : ([a] : multiset α) = {a} := rfl @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : multiset α) ↔ b = a := by simp only [←cons_zero, mem_cons, iff_self, or_false, not_mem_zero] theorem mem_singleton_self (a : α) : a ∈ ({a} : multiset α) := by { rw ←cons_zero, exact mem_cons_self _ _ } @[simp] theorem singleton_inj {a b : α} : ({a} : multiset α) = {b} ↔ a = b := by { simp_rw [←cons_zero], exact cons_inj_left _ } @[simp] lemma singleton_eq_cons_iff {a b : α} (m : multiset α) : {a} = b ::ₘ m ↔ a = b ∧ m = 0 := by { rw [←cons_zero, cons_eq_cons], simp [eq_comm] } theorem pair_comm (x y : α) : ({x, y} : multiset α) = {y, x} := cons_swap x y 0 /-! ### `multiset.subset` -/ section subset /-- `s ⊆ t` is the lift of the list subset relation. It means that any element with nonzero multiplicity in `s` has nonzero multiplicity in `t`, but it does not imply that the multiplicity of `a` in `s` is less or equal than in `t`; see `s ≤ t` for this relation. -/ protected def subset (s t : multiset α) : Prop := ∀ ⦃a : α⦄, a ∈ s → a ∈ t instance : has_subset (multiset α) := ⟨multiset.subset⟩ instance : has_ssubset (multiset α) := ⟨λ s t, s ⊆ t ∧ ¬ t ⊆ s⟩ @[simp] theorem coe_subset {l₁ l₂ : list α} : (l₁ : multiset α) ⊆ l₂ ↔ l₁ ⊆ l₂ := iff.rfl @[simp] theorem subset.refl (s : multiset α) : s ⊆ s := λ a h, h theorem subset.trans {s t u : multiset α} : s ⊆ t → t ⊆ u → s ⊆ u := λ h₁ h₂ a m, h₂ (h₁ m) theorem subset_iff {s t : multiset α} : s ⊆ t ↔ (∀⦃x⦄, x ∈ s → x ∈ t) := iff.rfl theorem mem_of_subset {s t : multiset α} {a : α} (h : s ⊆ t) : a ∈ s → a ∈ t := @h _ @[simp] theorem zero_subset (s : multiset α) : 0 ⊆ s := λ a, (not_mem_nil a).elim lemma subset_cons (s : multiset α) (a : α) : s ⊆ a ::ₘ s := λ _, mem_cons_of_mem lemma ssubset_cons {s : multiset α} {a : α} (ha : a ∉ s) : s ⊂ a ::ₘ s := ⟨subset_cons _ _, λ h, ha $ h $ mem_cons_self _ _⟩ @[simp] theorem cons_subset {a : α} {s t : multiset α} : (a ::ₘ s) ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp [subset_iff, or_imp_distrib, forall_and_distrib] lemma cons_subset_cons {a : α} {s t : multiset α} : s ⊆ t → a ::ₘ s ⊆ a ::ₘ t := quotient.induction_on₂ s t $ λ _ _, cons_subset_cons _ theorem eq_zero_of_subset_zero {s : multiset α} (h : s ⊆ 0) : s = 0 := eq_zero_of_forall_not_mem h theorem subset_zero {s : multiset α} : s ⊆ 0 ↔ s = 0 := ⟨eq_zero_of_subset_zero, λ xeq, xeq.symm ▸ subset.refl 0⟩ lemma induction_on' {p : multiset α → Prop} (S : multiset α) (h₁ : p 0) (h₂ : ∀ {a s}, a ∈ S → s ⊆ S → p s → p (insert a s)) : p S := @multiset.induction_on α (λ T, T ⊆ S → p T) S (λ _, h₁) (λ a s hps hs, let ⟨hS, sS⟩ := cons_subset.1 hs in h₂ hS sS (hps sS)) (subset.refl S) end subset /-! ### `multiset.to_list` -/ section to_list /-- Produces a list of the elements in the multiset using choice. -/ noncomputable def to_list (s : multiset α) := s.out' @[simp, norm_cast] lemma coe_to_list (s : multiset α) : (s.to_list : multiset α) = s := s.out_eq' @[simp] lemma to_list_eq_nil {s : multiset α} : s.to_list = [] ↔ s = 0 := by rw [← coe_eq_zero, coe_to_list] @[simp] lemma empty_to_list {s : multiset α} : s.to_list.empty ↔ s = 0 := empty_iff_eq_nil.trans to_list_eq_nil @[simp] lemma to_list_zero : (multiset.to_list 0 : list α) = [] := to_list_eq_nil.mpr rfl @[simp] lemma mem_to_list {a : α} {s : multiset α} : a ∈ s.to_list ↔ a ∈ s := by rw [← mem_coe, coe_to_list] end to_list /-! ### Partial order on `multiset`s -/ /-- `s ≤ t` means that `s` is a sublist of `t` (up to permutation). Equivalently, `s ≤ t` means that `count a s ≤ count a t` for all `a`. -/ protected def le (s t : multiset α) : Prop := quotient.lift_on₂ s t (<+~) $ λ v₁ v₂ w₁ w₂ p₁ p₂, propext (p₂.subperm_left.trans p₁.subperm_right) instance : partial_order (multiset α) := { le := multiset.le, le_refl := by rintros ⟨l⟩; exact subperm.refl _, le_trans := by rintros ⟨l₁⟩ ⟨l₂⟩ ⟨l₃⟩; exact @subperm.trans _ _ _ _, le_antisymm := by rintros ⟨l₁⟩ ⟨l₂⟩ h₁ h₂; exact quot.sound (subperm.antisymm h₁ h₂) } section variables {s t : multiset α} {a : α} lemma subset_of_le : s ≤ t → s ⊆ t := quotient.induction_on₂ s t $ λ l₁ l₂, subperm.subset alias subset_of_le ← le.subset lemma mem_of_le (h : s ≤ t) : a ∈ s → a ∈ t := mem_of_subset (subset_of_le h) lemma not_mem_mono (h : s ⊆ t) : a ∉ t → a ∉ s := mt $ @h _ @[simp] theorem coe_le {l₁ l₂ : list α} : (l₁ : multiset α) ≤ l₂ ↔ l₁ <+~ l₂ := iff.rfl @[elab_as_eliminator] theorem le_induction_on {C : multiset α → multiset α → Prop} {s t : multiset α} (h : s ≤ t) (H : ∀ {l₁ l₂ : list α}, l₁ <+ l₂ → C l₁ l₂) : C s t := quotient.induction_on₂ s t (λ l₁ l₂ ⟨l, p, s⟩, (show ⟦l⟧ = ⟦l₁⟧, from quot.sound p) ▸ H s) h theorem zero_le (s : multiset α) : 0 ≤ s := quot.induction_on s $ λ l, (nil_sublist l).subperm instance : order_bot (multiset α) := ⟨0, zero_le⟩ /-- This is a `rfl` and `simp` version of `bot_eq_zero`. -/ @[simp] theorem bot_eq_zero : (⊥ : multiset α) = 0 := rfl lemma le_zero : s ≤ 0 ↔ s = 0 := le_bot_iff theorem lt_cons_self (s : multiset α) (a : α) : s < a ::ₘ s := quot.induction_on s $ λ l, suffices l <+~ a :: l ∧ (¬l ~ a :: l), by simpa [lt_iff_le_and_ne], ⟨(sublist_cons _ _).subperm, λ p, ne_of_lt (lt_succ_self (length l)) p.length_eq⟩ theorem le_cons_self (s : multiset α) (a : α) : s ≤ a ::ₘ s := le_of_lt $ lt_cons_self _ _ lemma cons_le_cons_iff (a : α) : a ::ₘ s ≤ a ::ₘ t ↔ s ≤ t := quotient.induction_on₂ s t $ λ l₁ l₂, subperm_cons a lemma cons_le_cons (a : α) : s ≤ t → a ::ₘ s ≤ a ::ₘ t := (cons_le_cons_iff a).2 lemma le_cons_of_not_mem (m : a ∉ s) : s ≤ a ::ₘ t ↔ s ≤ t := begin refine ⟨_, λ h, le_trans h $ le_cons_self _ _⟩, suffices : ∀ {t'} (_ : s ≤ t') (_ : a ∈ t'), a ::ₘ s ≤ t', { exact λ h, (cons_le_cons_iff a).1 (this h (mem_cons_self _ _)) }, introv h, revert m, refine le_induction_on h _, introv s m₁ m₂, rcases mem_split m₂ with ⟨r₁, r₂, rfl⟩, exact perm_middle.subperm_left.2 ((subperm_cons _).2 $ ((sublist_or_mem_of_sublist s).resolve_right m₁).subperm) end @[simp] theorem singleton_ne_zero (a : α) : ({a} : multiset α) ≠ 0 := ne_of_gt (lt_cons_self _ _) @[simp] theorem singleton_le {a : α} {s : multiset α} : {a} ≤ s ↔ a ∈ s := ⟨λ h, mem_of_le h (mem_singleton_self _), λ h, let ⟨t, e⟩ := exists_cons_of_mem h in e.symm ▸ cons_le_cons _ (zero_le _)⟩ end /-! ### Additive monoid -/ /-- The sum of two multisets is the lift of the list append operation. This adds the multiplicities of each element, i.e. `count a (s + t) = count a s + count a t`. -/ protected def add (s₁ s₂ : multiset α) : multiset α := quotient.lift_on₂ s₁ s₂ (λ l₁ l₂, ((l₁ ++ l₂ : list α) : multiset α)) $ λ v₁ v₂ w₁ w₂ p₁ p₂, quot.sound $ p₁.append p₂ instance : has_add (multiset α) := ⟨multiset.add⟩ @[simp] theorem coe_add (s t : list α) : (s + t : multiset α) = (s ++ t : list α) := rfl @[simp] theorem singleton_add (a : α) (s : multiset α) : {a} + s = a ::ₘ s := rfl private theorem add_le_add_iff_left' {s t u : multiset α} : s + t ≤ s + u ↔ t ≤ u := quotient.induction_on₃ s t u $ λ l₁ l₂ l₃, subperm_append_left _ instance : covariant_class (multiset α) (multiset α) (+) (≤) := ⟨λ s t u, add_le_add_iff_left'.2⟩ instance : contravariant_class (multiset α) (multiset α) (+) (≤) := ⟨λ s t u, add_le_add_iff_left'.1⟩ instance : ordered_cancel_add_comm_monoid (multiset α) := { zero := 0, add := (+), add_comm := λ s t, quotient.induction_on₂ s t $ λ l₁ l₂, quot.sound perm_append_comm, add_assoc := λ s₁ s₂ s₃, quotient.induction_on₃ s₁ s₂ s₃ $ λ l₁ l₂ l₃, congr_arg coe $ append_assoc l₁ l₂ l₃, zero_add := λ s, quot.induction_on s $ λ l, rfl, add_zero := λ s, quotient.induction_on s $ λ l, congr_arg coe $ append_nil l, add_le_add_left := λ s₁ s₂, add_le_add_left, le_of_add_le_add_left := λ s₁ s₂ s₃, le_of_add_le_add_left, ..@multiset.partial_order α } theorem le_add_right (s t : multiset α) : s ≤ s + t := by simpa using add_le_add_left (zero_le t) s theorem le_add_left (s t : multiset α) : s ≤ t + s := by simpa using add_le_add_right (zero_le t) s theorem le_iff_exists_add {s t : multiset α} : s ≤ t ↔ ∃ u, t = s + u := ⟨λ h, le_induction_on h $ λ l₁ l₂ s, let ⟨l, p⟩ := s.exists_perm_append in ⟨l, quot.sound p⟩, λ ⟨u, e⟩, e.symm ▸ le_add_right _ _⟩ instance : canonically_ordered_add_monoid (multiset α) := { le_self_add := le_add_right, exists_add_of_le := λ a b h, le_induction_on h $ λ l₁ l₂ s, let ⟨l, p⟩ := s.exists_perm_append in ⟨l, quot.sound p⟩, ..multiset.order_bot, ..multiset.ordered_cancel_add_comm_monoid } @[simp] theorem cons_add (a : α) (s t : multiset α) : a ::ₘ s + t = a ::ₘ (s + t) := by rw [← singleton_add, ← singleton_add, add_assoc] @[simp] theorem add_cons (a : α) (s t : multiset α) : s + a ::ₘ t = a ::ₘ (s + t) := by rw [add_comm, cons_add, add_comm] @[simp] theorem mem_add {a : α} {s t : multiset α} : a ∈ s + t ↔ a ∈ s ∨ a ∈ t := quotient.induction_on₂ s t $ λ l₁ l₂, mem_append lemma mem_of_mem_nsmul {a : α} {s : multiset α} {n : ℕ} (h : a ∈ n • s) : a ∈ s := begin induction n with n ih, { rw zero_nsmul at h, exact absurd h (not_mem_zero _) }, { rw [succ_nsmul, mem_add] at h, exact h.elim id ih }, end @[simp] lemma mem_nsmul {a : α} {s : multiset α} {n : ℕ} (h0 : n ≠ 0) : a ∈ n • s ↔ a ∈ s := begin refine ⟨mem_of_mem_nsmul, λ h, _⟩, obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero h0, rw [succ_nsmul, mem_add], exact or.inl h end lemma nsmul_cons {s : multiset α} (n : ℕ) (a : α) : n • (a ::ₘ s) = n • {a} + n • s := by rw [←singleton_add, nsmul_add] /-! ### Cardinality -/ /-- The cardinality of a multiset is the sum of the multiplicities of all its elements, or simply the length of the underlying list. -/ def card : multiset α →+ ℕ := { to_fun := λ s, quot.lift_on s length $ λ l₁ l₂, perm.length_eq, map_zero' := rfl, map_add' := λ s t, quotient.induction_on₂ s t length_append } @[simp] theorem coe_card (l : list α) : card (l : multiset α) = length l := rfl @[simp] theorem length_to_list (s : multiset α) : s.to_list.length = s.card := by rw [← coe_card, coe_to_list] @[simp] theorem card_zero : @card α 0 = 0 := rfl theorem card_add (s t : multiset α) : card (s + t) = card s + card t := card.map_add s t lemma card_nsmul (s : multiset α) (n : ℕ) : (n • s).card = n * s.card := by rw [card.map_nsmul s n, nat.nsmul_eq_mul] @[simp] theorem card_cons (a : α) (s : multiset α) : card (a ::ₘ s) = card s + 1 := quot.induction_on s $ λ l, rfl @[simp] theorem card_singleton (a : α) : card ({a} : multiset α) = 1 := by simp only [←cons_zero, card_zero, eq_self_iff_true, zero_add, card_cons] lemma card_pair (a b : α) : ({a, b} : multiset α).card = 2 := by rw [insert_eq_cons, card_cons, card_singleton] theorem card_eq_one {s : multiset α} : card s = 1 ↔ ∃ a, s = {a} := ⟨quot.induction_on s $ λ l h, (list.length_eq_one.1 h).imp $ λ a, congr_arg coe, λ ⟨a, e⟩, e.symm ▸ rfl⟩ theorem card_le_of_le {s t : multiset α} (h : s ≤ t) : card s ≤ card t := le_induction_on h $ λ l₁ l₂, length_le_of_sublist @[mono] theorem card_mono : monotone (@card α) := λ a b, card_le_of_le theorem eq_of_le_of_card_le {s t : multiset α} (h : s ≤ t) : card t ≤ card s → s = t := le_induction_on h $ λ l₁ l₂ s h₂, congr_arg coe $ eq_of_sublist_of_length_le s h₂ theorem card_lt_of_lt {s t : multiset α} (h : s < t) : card s < card t := lt_of_not_ge $ λ h₂, ne_of_lt h $ eq_of_le_of_card_le (le_of_lt h) h₂ theorem lt_iff_cons_le {s t : multiset α} : s < t ↔ ∃ a, a ::ₘ s ≤ t := ⟨quotient.induction_on₂ s t $ λ l₁ l₂ h, subperm.exists_of_length_lt (le_of_lt h) (card_lt_of_lt h), λ ⟨a, h⟩, lt_of_lt_of_le (lt_cons_self _ _) h⟩ @[simp] theorem card_eq_zero {s : multiset α} : card s = 0 ↔ s = 0 := ⟨λ h, (eq_of_le_of_card_le (zero_le _) (le_of_eq h)).symm, λ e, by simp [e]⟩ theorem card_pos {s : multiset α} : 0 < card s ↔ s ≠ 0 := pos_iff_ne_zero.trans $ not_congr card_eq_zero theorem card_pos_iff_exists_mem {s : multiset α} : 0 < card s ↔ ∃ a, a ∈ s := quot.induction_on s $ λ l, length_pos_iff_exists_mem lemma card_eq_two {s : multiset α} : s.card = 2 ↔ ∃ x y, s = {x, y} := ⟨quot.induction_on s (λ l h, (list.length_eq_two.mp h).imp (λ a, Exists.imp (λ b, congr_arg coe))), λ ⟨a, b, e⟩, e.symm ▸ rfl⟩ lemma card_eq_three {s : multiset α} : s.card = 3 ↔ ∃ x y z, s = {x, y, z} := ⟨quot.induction_on s (λ l h, (list.length_eq_three.mp h).imp (λ a, Exists.imp (λ b, Exists.imp (λ c, congr_arg coe)))), λ ⟨a, b, c, e⟩, e.symm ▸ rfl⟩ /-! ### Induction principles -/ /-- A strong induction principle for multisets: If you construct a value for a particular multiset given values for all strictly smaller multisets, you can construct a value for any multiset. -/ @[elab_as_eliminator] def strong_induction_on {p : multiset α → Sort*} : ∀ (s : multiset α), (∀ s, (∀t < s, p t) → p s) → p s | s := λ ih, ih s $ λ t h, have card t < card s, from card_lt_of_lt h, strong_induction_on t ih using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf card⟩]} theorem strong_induction_eq {p : multiset α → Sort*} (s : multiset α) (H) : @strong_induction_on _ p s H = H s (λ t h, @strong_induction_on _ p t H) := by rw [strong_induction_on] @[elab_as_eliminator] lemma case_strong_induction_on {p : multiset α → Prop} (s : multiset α) (h₀ : p 0) (h₁ : ∀ a s, (∀t ≤ s, p t) → p (a ::ₘ s)) : p s := multiset.strong_induction_on s $ assume s, multiset.induction_on s (λ _, h₀) $ λ a s _ ih, h₁ _ _ $ λ t h, ih _ $ lt_of_le_of_lt h $ lt_cons_self _ _ /-- Suppose that, given that `p t` can be defined on all supersets of `s` of cardinality less than `n`, one knows how to define `p s`. Then one can inductively define `p s` for all multisets `s` of cardinality less than `n`, starting from multisets of card `n` and iterating. This can be used either to define data, or to prove properties. -/ def strong_downward_induction {p : multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : multiset α}, t₂.card ≤ n → t₁ < t₂ → p t₂) → t₁.card ≤ n → p t₁) : ∀ (s : multiset α), s.card ≤ n → p s | s := H s (λ t ht h, have n - card t < n - card s, from (tsub_lt_tsub_iff_left_of_le ht).2 (card_lt_of_lt h), strong_downward_induction t ht) using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ (t : multiset α), n - t.card)⟩]} lemma strong_downward_induction_eq {p : multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : multiset α}, t₂.card ≤ n → t₁ < t₂ → p t₂) → t₁.card ≤ n → p t₁) (s : multiset α) : strong_downward_induction H s = H s (λ t ht hst, strong_downward_induction H t ht) := by rw strong_downward_induction /-- Analogue of `strong_downward_induction` with order of arguments swapped. -/ @[elab_as_eliminator] def strong_downward_induction_on {p : multiset α → Sort*} {n : ℕ} : ∀ (s : multiset α), (∀ t₁, (∀ {t₂ : multiset α}, t₂.card ≤ n → t₁ < t₂ → p t₂) → t₁.card ≤ n → p t₁) → s.card ≤ n → p s := λ s H, strong_downward_induction H s lemma strong_downward_induction_on_eq {p : multiset α → Sort*} (s : multiset α) {n : ℕ} (H : ∀ t₁, (∀ {t₂ : multiset α}, t₂.card ≤ n → t₁ < t₂ → p t₂) → t₁.card ≤ n → p t₁) : s.strong_downward_induction_on H = H s (λ t ht h, t.strong_downward_induction_on H ht) := by { dunfold strong_downward_induction_on, rw strong_downward_induction } /-- Another way of expressing `strong_induction_on`: the `(<)` relation is well-founded. -/ lemma well_founded_lt : well_founded ((<) : multiset α → multiset α → Prop) := subrelation.wf (λ _ _, multiset.card_lt_of_lt) (measure_wf multiset.card) /-! ### `multiset.repeat` -/ /-- `repeat a n` is the multiset containing only `a` with multiplicity `n`. -/ def repeat (a : α) (n : ℕ) : multiset α := repeat a n @[simp] lemma repeat_zero (a : α) : repeat a 0 = 0 := rfl @[simp] lemma repeat_succ (a : α) (n) : repeat a (n+1) = a ::ₘ repeat a n := by simp [repeat] @[simp] lemma repeat_one (a : α) : repeat a 1 = {a} := by simp only [repeat_succ, ←cons_zero, eq_self_iff_true, repeat_zero, cons_inj_right] @[simp] lemma card_repeat : ∀ (a : α) n, card (repeat a n) = n := length_repeat lemma mem_repeat {a b : α} {n : ℕ} : b ∈ repeat a n ↔ n ≠ 0 ∧ b = a := mem_repeat theorem eq_of_mem_repeat {a b : α} {n} : b ∈ repeat a n → b = a := eq_of_mem_repeat theorem eq_repeat' {a : α} {s : multiset α} : s = repeat a s.card ↔ ∀ b ∈ s, b = a := quot.induction_on s $ λ l, iff.trans ⟨λ h, (perm_repeat.1 $ (quotient.exact h)), congr_arg coe⟩ eq_repeat' theorem eq_repeat_of_mem {a : α} {s : multiset α} : (∀ b ∈ s, b = a) → s = repeat a s.card := eq_repeat'.2 theorem eq_repeat {a : α} {n} {s : multiset α} : s = repeat a n ↔ card s = n ∧ ∀ b ∈ s, b = a := ⟨λ h, h.symm ▸ ⟨card_repeat _ _, λ b, eq_of_mem_repeat⟩, λ ⟨e, al⟩, e ▸ eq_repeat_of_mem al⟩ lemma repeat_left_injective {n : ℕ} (hn : n ≠ 0) : function.injective (λ a : α, repeat a n) := λ a b h, (eq_repeat.1 h).2 _ $ mem_repeat.2 ⟨hn, rfl⟩ @[simp] lemma repeat_left_inj {a b : α} {n : ℕ} (h : n ≠ 0) : repeat a n = repeat b n ↔ a = b := (repeat_left_injective h).eq_iff theorem repeat_injective (a : α) : function.injective (repeat a) := λ m n h, by rw [← (eq_repeat.1 h).1, card_repeat] theorem repeat_subset_singleton : ∀ (a : α) n, repeat a n ⊆ {a} := repeat_subset_singleton theorem repeat_le_coe {a : α} {n} {l : list α} : repeat a n ≤ l ↔ list.repeat a n <+ l := ⟨λ ⟨l', p, s⟩, (perm_repeat.1 p) ▸ s, sublist.subperm⟩ theorem nsmul_singleton (a : α) (n) : n • ({a} : multiset α) = repeat a n := begin refine eq_repeat.mpr ⟨_, λ b hb, mem_singleton.mp (mem_of_mem_nsmul hb)⟩, rw [card_nsmul, card_singleton, mul_one] end lemma nsmul_repeat {a : α} (n m : ℕ) : n • (repeat a m) = repeat a (n * m) := begin rw eq_repeat, split, { rw [card_nsmul, card_repeat] }, { exact λ b hb, eq_of_mem_repeat (mem_of_mem_nsmul hb) }, end /-! ### Erasing one copy of an element -/ section erase variables [decidable_eq α] {s t : multiset α} {a b : α} /-- `erase s a` is the multiset that subtracts 1 from the multiplicity of `a`. -/ def erase (s : multiset α) (a : α) : multiset α := quot.lift_on s (λ l, (l.erase a : multiset α)) (λ l₁ l₂ p, quot.sound (p.erase a)) @[simp] theorem coe_erase (l : list α) (a : α) : erase (l : multiset α) a = l.erase a := rfl @[simp] theorem erase_zero (a : α) : (0 : multiset α).erase a = 0 := rfl @[simp] theorem erase_cons_head (a : α) (s : multiset α) : (a ::ₘ s).erase a = s := quot.induction_on s $ λ l, congr_arg coe $ erase_cons_head a l @[simp, priority 990] theorem erase_cons_tail {a b : α} (s : multiset α) (h : b ≠ a) : (b ::ₘ s).erase a = b ::ₘ s.erase a := quot.induction_on s $ λ l, congr_arg coe $ erase_cons_tail l h @[simp] theorem erase_singleton (a : α) : ({a} : multiset α).erase a = 0 := erase_cons_head a 0 @[simp, priority 980] theorem erase_of_not_mem {a : α} {s : multiset α} : a ∉ s → s.erase a = s := quot.induction_on s $ λ l h, congr_arg coe $ erase_of_not_mem h @[simp, priority 980] theorem cons_erase {s : multiset α} {a : α} : a ∈ s → a ::ₘ s.erase a = s := quot.induction_on s $ λ l h, quot.sound (perm_cons_erase h).symm theorem le_cons_erase (s : multiset α) (a : α) : s ≤ a ::ₘ s.erase a := if h : a ∈ s then le_of_eq (cons_erase h).symm else by rw erase_of_not_mem h; apply le_cons_self lemma add_singleton_eq_iff {s t : multiset α} {a : α} : s + {a} = t ↔ a ∈ t ∧ s = t.erase a := begin rw [add_comm, singleton_add], split, { rintro rfl, exact ⟨s.mem_cons_self a, (s.erase_cons_head a).symm⟩ }, { rintro ⟨h, rfl⟩, exact cons_erase h }, end theorem erase_add_left_pos {a : α} {s : multiset α} (t) : a ∈ s → (s + t).erase a = s.erase a + t := quotient.induction_on₂ s t $ λ l₁ l₂ h, congr_arg coe $ erase_append_left l₂ h theorem erase_add_right_pos {a : α} (s) {t : multiset α} (h : a ∈ t) : (s + t).erase a = s + t.erase a := by rw [add_comm, erase_add_left_pos s h, add_comm] theorem erase_add_right_neg {a : α} {s : multiset α} (t) : a ∉ s → (s + t).erase a = s + t.erase a := quotient.induction_on₂ s t $ λ l₁ l₂ h, congr_arg coe $ erase_append_right l₂ h theorem erase_add_left_neg {a : α} (s) {t : multiset α} (h : a ∉ t) : (s + t).erase a = s.erase a + t := by rw [add_comm, erase_add_right_neg s h, add_comm] theorem erase_le (a : α) (s : multiset α) : s.erase a ≤ s := quot.induction_on s $ λ l, (erase_sublist a l).subperm @[simp] theorem erase_lt {a : α} {s : multiset α} : s.erase a < s ↔ a ∈ s := ⟨λ h, not_imp_comm.1 erase_of_not_mem (ne_of_lt h), λ h, by simpa [h] using lt_cons_self (s.erase a) a⟩ theorem erase_subset (a : α) (s : multiset α) : s.erase a ⊆ s := subset_of_le (erase_le a s) theorem mem_erase_of_ne {a b : α} {s : multiset α} (ab : a ≠ b) : a ∈ s.erase b ↔ a ∈ s := quot.induction_on s $ λ l, list.mem_erase_of_ne ab theorem mem_of_mem_erase {a b : α} {s : multiset α} : a ∈ s.erase b → a ∈ s := mem_of_subset (erase_subset _ _) theorem erase_comm (s : multiset α) (a b : α) : (s.erase a).erase b = (s.erase b).erase a := quot.induction_on s $ λ l, congr_arg coe $ l.erase_comm a b theorem erase_le_erase {s t : multiset α} (a : α) (h : s ≤ t) : s.erase a ≤ t.erase a := le_induction_on h $ λ l₁ l₂ h, (h.erase _).subperm theorem erase_le_iff_le_cons {s t : multiset α} {a : α} : s.erase a ≤ t ↔ s ≤ a ::ₘ t := ⟨λ h, le_trans (le_cons_erase _ _) (cons_le_cons _ h), λ h, if m : a ∈ s then by rw ← cons_erase m at h; exact (cons_le_cons_iff _).1 h else le_trans (erase_le _ _) ((le_cons_of_not_mem m).1 h)⟩ @[simp] theorem card_erase_of_mem {a : α} {s : multiset α} : a ∈ s → card (s.erase a) = pred (card s) := quot.induction_on s $ λ l, length_erase_of_mem @[simp] lemma card_erase_add_one {a : α} {s : multiset α} : a ∈ s → (s.erase a).card + 1 = s.card := quot.induction_on s $ λ l, length_erase_add_one theorem card_erase_lt_of_mem {a : α} {s : multiset α} : a ∈ s → card (s.erase a) < card s := λ h, card_lt_of_lt (erase_lt.mpr h) theorem card_erase_le {a : α} {s : multiset α} : card (s.erase a) ≤ card s := card_le_of_le (erase_le a s) theorem card_erase_eq_ite {a : α} {s : multiset α} : card (s.erase a) = if a ∈ s then pred (card s) else card s := begin by_cases h : a ∈ s, { rwa [card_erase_of_mem h, if_pos] }, { rwa [erase_of_not_mem h, if_neg] } end end erase @[simp] theorem coe_reverse (l : list α) : (reverse l : multiset α) = l := quot.sound $ reverse_perm _ /-! ### `multiset.map` -/ /-- `map f s` is the lift of the list `map` operation. The multiplicity of `b` in `map f s` is the number of `a ∈ s` (counting multiplicity) such that `f a = b`. -/ def map (f : α → β) (s : multiset α) : multiset β := quot.lift_on s (λ l : list α, (l.map f : multiset β)) (λ l₁ l₂ p, quot.sound (p.map f)) @[congr] theorem map_congr {f g : α → β} {s t : multiset α} : s = t → (∀ x ∈ t, f x = g x) → map f s = map g t := begin rintros rfl h, induction s using quot.induction_on, exact congr_arg coe (map_congr h) end lemma map_hcongr {β' : Type*} {m : multiset α} {f : α → β} {f' : α → β'} (h : β = β') (hf : ∀a∈m, f a == f' a) : map f m == map f' m := begin subst h, simp at hf, simp [map_congr rfl hf] end theorem forall_mem_map_iff {f : α → β} {p : β → Prop} {s : multiset α} : (∀ y ∈ s.map f, p y) ↔ (∀ x ∈ s, p (f x)) := quotient.induction_on' s $ λ L, list.forall_mem_map_iff @[simp] theorem coe_map (f : α → β) (l : list α) : map f ↑l = l.map f := rfl @[simp] theorem map_zero (f : α → β) : map f 0 = 0 := rfl @[simp] theorem map_cons (f : α → β) (a s) : map f (a ::ₘ s) = f a ::ₘ map f s := quot.induction_on s $ λ l, rfl theorem map_comp_cons (f : α → β) (t) : map f ∘ cons t = cons (f t) ∘ map f := by { ext, simp } @[simp] theorem map_singleton (f : α → β) (a : α) : ({a} : multiset α).map f = {f a} := rfl theorem map_repeat (f : α → β) (a : α) (k : ℕ) : (repeat a k).map f = repeat (f a) k := by { induction k, simp, simpa } @[simp] theorem map_add (f : α → β) (s t) : map f (s + t) = map f s + map f t := quotient.induction_on₂ s t $ λ l₁ l₂, congr_arg coe $ map_append _ _ _ /-- If each element of `s : multiset α` can be lifted to `β`, then `s` can be lifted to `multiset β`. -/ instance [can_lift α β] : can_lift (multiset α) (multiset β) := { cond := λ s, ∀ x ∈ s, can_lift.cond β x, coe := map can_lift.coe, prf := by { rintro ⟨l⟩ hl, lift l to list β using hl, exact ⟨l, coe_map _ _⟩ } } /-- `multiset.map` as an `add_monoid_hom`. -/ def map_add_monoid_hom (f : α → β) : multiset α →+ multiset β := { to_fun := map f, map_zero' := map_zero _, map_add' := map_add _ } @[simp] lemma coe_map_add_monoid_hom (f : α → β) : (map_add_monoid_hom f : multiset α → multiset β) = map f := rfl theorem map_nsmul (f : α → β) (n : ℕ) (s) : map f (n • s) = n • (map f s) := (map_add_monoid_hom f).map_nsmul _ _ @[simp] theorem mem_map {f : α → β} {b : β} {s : multiset α} : b ∈ map f s ↔ ∃ a, a ∈ s ∧ f a = b := quot.induction_on s $ λ l, mem_map @[simp] theorem card_map (f : α → β) (s) : card (map f s) = card s := quot.induction_on s $ λ l, length_map _ _ @[simp] theorem map_eq_zero {s : multiset α} {f : α → β} : s.map f = 0 ↔ s = 0 := by rw [← multiset.card_eq_zero, multiset.card_map, multiset.card_eq_zero] theorem mem_map_of_mem (f : α → β) {a : α} {s : multiset α} (h : a ∈ s) : f a ∈ map f s := mem_map.2 ⟨_, h, rfl⟩ lemma map_eq_singleton {f : α → β} {s : multiset α} {b : β} : map f s = {b} ↔ ∃ a : α, s = {a} ∧ f a = b := begin split, { intro h, obtain ⟨a, ha⟩ : ∃ a, s = {a}, { rw [←card_eq_one, ←card_map, h, card_singleton] }, refine ⟨a, ha, _⟩, rw [←mem_singleton, ←h, ha, map_singleton, mem_singleton] }, { rintro ⟨a, rfl, rfl⟩, simp } end lemma map_eq_cons [decidable_eq α] (f : α → β) (s : multiset α) (t : multiset β) (b : β) : (∃ a ∈ s, f a = b ∧ (s.erase a).map f = t) ↔ s.map f = b ::ₘ t := begin split, { rintro ⟨a, ha, rfl, rfl⟩, rw [←map_cons, multiset.cons_erase ha] }, { intro h, have : b ∈ s.map f, { rw h, exact mem_cons_self _ _ }, obtain ⟨a, h1, rfl⟩ := mem_map.mp this, obtain ⟨u, rfl⟩ := exists_cons_of_mem h1, rw [map_cons, cons_inj_right] at h, refine ⟨a, mem_cons_self _ _, rfl, _⟩, rw [multiset.erase_cons_head, h] } end theorem mem_map_of_injective {f : α → β} (H : function.injective f) {a : α} {s : multiset α} : f a ∈ map f s ↔ a ∈ s := quot.induction_on s $ λ l, mem_map_of_injective H @[simp] theorem map_map (g : β → γ) (f : α → β) (s : multiset α) : map g (map f s) = map (g ∘ f) s := quot.induction_on s $ λ l, congr_arg coe $ list.map_map _ _ _ theorem map_id (s : multiset α) : map id s = s := quot.induction_on s $ λ l, congr_arg coe $ map_id _ @[simp] lemma map_id' (s : multiset α) : map (λx, x) s = s := map_id s @[simp] theorem map_const (s : multiset α) (b : β) : map (function.const α b) s = repeat b s.card := quot.induction_on s $ λ l, congr_arg coe $ map_const _ _ theorem eq_of_mem_map_const {b₁ b₂ : β} {l : list α} (h : b₁ ∈ map (function.const α b₂) l) : b₁ = b₂ := eq_of_mem_repeat $ by rwa map_const at h @[simp] theorem map_le_map {f : α → β} {s t : multiset α} (h : s ≤ t) : map f s ≤ map f t := le_induction_on h $ λ l₁ l₂ h, (h.map f).subperm @[simp] lemma map_lt_map {f : α → β} {s t : multiset α} (h : s < t) : s.map f < t.map f := begin refine (map_le_map h.le).lt_of_not_le (λ H, h.ne $ eq_of_le_of_card_le h.le _), rw [←s.card_map f, ←t.card_map f], exact card_le_of_le H, end lemma map_mono (f : α → β) : monotone (map f) := λ _ _, map_le_map lemma map_strict_mono (f : α → β) : strict_mono (map f) := λ _ _, map_lt_map @[simp] theorem map_subset_map {f : α → β} {s t : multiset α} (H : s ⊆ t) : map f s ⊆ map f t := λ b m, let ⟨a, h, e⟩ := mem_map.1 m in mem_map.2 ⟨a, H h, e⟩ lemma map_erase [decidable_eq α] [decidable_eq β] (f : α → β) (hf : function.injective f) (x : α) (s : multiset α) : (s.erase x).map f = (s.map f).erase (f x) := begin induction s using multiset.induction_on with y s ih, { simp }, by_cases hxy : y = x, { cases hxy, simp }, { rw [s.erase_cons_tail hxy, map_cons, map_cons, (s.map f).erase_cons_tail (hf.ne hxy), ih] } end lemma map_surjective_of_surjective {f : α → β} (hf : function.surjective f) : function.surjective (map f) := begin intro s, induction s using multiset.induction_on with x s ih, { exact ⟨0, map_zero _⟩ }, { obtain ⟨y, rfl⟩ := hf x, obtain ⟨t, rfl⟩ := ih, exact ⟨y ::ₘ t, map_cons _ _ _⟩ } end /-! ### `multiset.fold` -/ /-- `foldl f H b s` is the lift of the list operation `foldl f b l`, which folds `f` over the multiset. It is well defined when `f` is right-commutative, that is, `f (f b a₁) a₂ = f (f b a₂) a₁`. -/ def foldl (f : β → α → β) (H : right_commutative f) (b : β) (s : multiset α) : β := quot.lift_on s (λ l, foldl f b l) (λ l₁ l₂ p, p.foldl_eq H b) @[simp] theorem foldl_zero (f : β → α → β) (H b) : foldl f H b 0 = b := rfl @[simp] theorem foldl_cons (f : β → α → β) (H b a s) : foldl f H b (a ::ₘ s) = foldl f H (f b a) s := quot.induction_on s $ λ l, rfl @[simp] theorem foldl_add (f : β → α → β) (H b s t) : foldl f H b (s + t) = foldl f H (foldl f H b s) t := quotient.induction_on₂ s t $ λ l₁ l₂, foldl_append _ _ _ _ /-- `foldr f H b s` is the lift of the list operation `foldr f b l`, which folds `f` over the multiset. It is well defined when `f` is left-commutative, that is, `f a₁ (f a₂ b) = f a₂ (f a₁ b)`. -/ def foldr (f : α → β → β) (H : left_commutative f) (b : β) (s : multiset α) : β := quot.lift_on s (λ l, foldr f b l) (λ l₁ l₂ p, p.foldr_eq H b) @[simp] theorem foldr_zero (f : α → β → β) (H b) : foldr f H b 0 = b := rfl @[simp] theorem foldr_cons (f : α → β → β) (H b a s) : foldr f H b (a ::ₘ s) = f a (foldr f H b s) := quot.induction_on s $ λ l, rfl @[simp] theorem foldr_singleton (f : α → β → β) (H b a) : foldr f H b ({a} : multiset α) = f a b := rfl @[simp] theorem foldr_add (f : α → β → β) (H b s t) : foldr f H b (s + t) = foldr f H (foldr f H b t) s := quotient.induction_on₂ s t $ λ l₁ l₂, foldr_append _ _ _ _ @[simp] theorem coe_foldr (f : α → β → β) (H : left_commutative f) (b : β) (l : list α) : foldr f H b l = l.foldr f b := rfl @[simp] theorem coe_foldl (f : β → α → β) (H : right_commutative f) (b : β) (l : list α) : foldl f H b l = l.foldl f b := rfl theorem coe_foldr_swap (f : α → β → β) (H : left_commutative f) (b : β) (l : list α) : foldr f H b l = l.foldl (λ x y, f y x) b := (congr_arg (foldr f H b) (coe_reverse l)).symm.trans $ foldr_reverse _ _ _ theorem foldr_swap (f : α → β → β) (H : left_commutative f) (b : β) (s : multiset α) : foldr f H b s = foldl (λ x y, f y x) (λ x y z, (H _ _ _).symm) b s := quot.induction_on s $ λ l, coe_foldr_swap _ _ _ _ theorem foldl_swap (f : β → α → β) (H : right_commutative f) (b : β) (s : multiset α) : foldl f H b s = foldr (λ x y, f y x) (λ x y z, (H _ _ _).symm) b s := (foldr_swap _ _ _ _).symm lemma foldr_induction' (f : α → β → β) (H : left_commutative f) (x : β) (q : α → Prop) (p : β → Prop) (s : multiset α) (hpqf : ∀ a b, q a → p b → p (f a b)) (px : p x) (q_s : ∀ a ∈ s, q a) : p (foldr f H x s) := begin revert s, refine multiset.induction (by simp [px]) _, intros a s hs hsa, rw foldr_cons, have hps : ∀ (x : α), x ∈ s → q x, from λ x hxs, hsa x (mem_cons_of_mem hxs), exact hpqf a (foldr f H x s) (hsa a (mem_cons_self a s)) (hs hps), end lemma foldr_induction (f : α → α → α) (H : left_commutative f) (x : α) (p : α → Prop) (s : multiset α) (p_f : ∀ a b, p a → p b → p (f a b)) (px : p x) (p_s : ∀ a ∈ s, p a) : p (foldr f H x s) := foldr_induction' f H x p p s p_f px p_s lemma foldl_induction' (f : β → α → β) (H : right_commutative f) (x : β) (q : α → Prop) (p : β → Prop) (s : multiset α) (hpqf : ∀ a b, q a → p b → p (f b a)) (px : p x) (q_s : ∀ a ∈ s, q a) : p (foldl f H x s) := begin rw foldl_swap, exact foldr_induction' (λ x y, f y x) (λ x y z, (H _ _ _).symm) x q p s hpqf px q_s, end lemma foldl_induction (f : α → α → α) (H : right_commutative f) (x : α) (p : α → Prop) (s : multiset α) (p_f : ∀ a b, p a → p b → p (f b a)) (px : p x) (p_s : ∀ a ∈ s, p a) : p (foldl f H x s) := foldl_induction' f H x p p s p_f px p_s /-! ### Map for partial functions -/ /-- Lift of the list `pmap` operation. Map a partial function `f` over a multiset `s` whose elements are all in the domain of `f`. -/ def pmap {p : α → Prop} (f : Π a, p a → β) (s : multiset α) : (∀ a ∈ s, p a) → multiset β := quot.rec_on s (λ l H, ↑(pmap f l H)) $ λ l₁ l₂ (pp : l₁ ~ l₂), funext $ λ (H₂ : ∀ a ∈ l₂, p a), have H₁ : ∀ a ∈ l₁, p a, from λ a h, H₂ a (pp.subset h), have ∀ {s₂ e H}, @eq.rec (multiset α) l₁ (λ s, (∀ a ∈ s, p a) → multiset β) (λ _, ↑(pmap f l₁ H₁)) s₂ e H = ↑(pmap f l₁ H₁), by intros s₂ e _; subst e, this.trans $ quot.sound $ pp.pmap f @[simp] theorem coe_pmap {p : α → Prop} (f : Π a, p a → β) (l : list α) (H : ∀ a ∈ l, p a) : pmap f l H = l.pmap f H := rfl @[simp] lemma pmap_zero {p : α → Prop} (f : Π a, p a → β) (h : ∀a∈(0:multiset α), p a) : pmap f 0 h = 0 := rfl @[simp] lemma pmap_cons {p : α → Prop} (f : Π a, p a → β) (a : α) (m : multiset α) : ∀(h : ∀b∈a ::ₘ m, p b), pmap f (a ::ₘ m) h = f a (h a (mem_cons_self a m)) ::ₘ pmap f m (λa ha, h a $ mem_cons_of_mem ha) := quotient.induction_on m $ assume l h, rfl /-- "Attach" a proof that `a ∈ s` to each element `a` in `s` to produce a multiset on `{x // x ∈ s}`. -/ def attach (s : multiset α) : multiset {x // x ∈ s} := pmap subtype.mk s (λ a, id) @[simp] theorem coe_attach (l : list α) : @eq (multiset {x // x ∈ l}) (@attach α l) l.attach := rfl theorem sizeof_lt_sizeof_of_mem [has_sizeof α] {x : α} {s : multiset α} (hx : x ∈ s) : sizeof x < sizeof s := by { induction s with l a b, exact list.sizeof_lt_sizeof_of_mem hx, refl } theorem pmap_eq_map (p : α → Prop) (f : α → β) (s : multiset α) : ∀ H, @pmap _ _ p (λ a _, f a) s H = map f s := quot.induction_on s $ λ l H, congr_arg coe $ pmap_eq_map p f l H theorem pmap_congr {p q : α → Prop} {f : Π a, p a → β} {g : Π a, q a → β} (s : multiset α) {H₁ H₂} : (∀ (a ∈ s) h₁ h₂, f a h₁ = g a h₂) → pmap f s H₁ = pmap g s H₂ := quot.induction_on s (λ l H₁ H₂ h, congr_arg coe $ pmap_congr l h) H₁ H₂ theorem map_pmap {p : α → Prop} (g : β → γ) (f : Π a, p a → β) (s) : ∀ H, map g (pmap f s H) = pmap (λ a h, g (f a h)) s H := quot.induction_on s $ λ l H, congr_arg coe $ map_pmap g f l H theorem pmap_eq_map_attach {p : α → Prop} (f : Π a, p a → β) (s) : ∀ H, pmap f s H = s.attach.map (λ x, f x.1 (H _ x.2)) := quot.induction_on s $ λ l H, congr_arg coe $ pmap_eq_map_attach f l H theorem attach_map_val (s : multiset α) : s.attach.map subtype.val = s := quot.induction_on s $ λ l, congr_arg coe $ attach_map_val l @[simp] theorem mem_attach (s : multiset α) : ∀ x, x ∈ s.attach := quot.induction_on s $ λ l, mem_attach _ @[simp] theorem mem_pmap {p : α → Prop} {f : Π a, p a → β} {s H b} : b ∈ pmap f s H ↔ ∃ a (h : a ∈ s), f a (H a h) = b := quot.induction_on s (λ l H, mem_pmap) H @[simp] theorem card_pmap {p : α → Prop} (f : Π a, p a → β) (s H) : card (pmap f s H) = card s := quot.induction_on s (λ l H, length_pmap) H @[simp] theorem card_attach {m : multiset α} : card (attach m) = card m := card_pmap _ _ _ @[simp] lemma attach_zero : (0 : multiset α).attach = 0 := rfl lemma attach_cons (a : α) (m : multiset α) : (a ::ₘ m).attach = ⟨a, mem_cons_self a m⟩ ::ₘ (m.attach.map $ λp, ⟨p.1, mem_cons_of_mem p.2⟩) := quotient.induction_on m $ assume l, congr_arg coe $ congr_arg (list.cons _) $ by rw [list.map_pmap]; exact list.pmap_congr _ (λ _ _ _ _, subtype.eq rfl) @[simp] lemma attach_map_coe (m : multiset α) : multiset.map (coe : _ → α) m.attach = m := m.attach_map_val section decidable_pi_exists variables {m : multiset α} /-- If `p` is a decidable predicate, so is the predicate that all elements of a multiset satisfy `p`. -/ protected def decidable_forall_multiset {p : α → Prop} [hp : ∀ a, decidable (p a)] : decidable (∀ a ∈ m, p a) := quotient.rec_on_subsingleton m (λl, decidable_of_iff (∀a ∈ l, p a) $ by simp) instance decidable_dforall_multiset {p : Π a ∈ m, Prop} [hp : ∀ a (h : a ∈ m), decidable (p a h)] : decidable (∀ a (h : a ∈ m), p a h) := decidable_of_decidable_of_iff (@multiset.decidable_forall_multiset {a // a ∈ m} m.attach (λa, p a.1 a.2) _) (iff.intro (assume h a ha, h ⟨a, ha⟩ (mem_attach _ _)) (assume h ⟨a, ha⟩ _, h _ _)) /-- decidable equality for functions whose domain is bounded by multisets -/ instance decidable_eq_pi_multiset {β : α → Type*} [h : ∀ a, decidable_eq (β a)] : decidable_eq (Π a ∈ m, β a) := assume f g, decidable_of_iff (∀ a (h : a ∈ m), f a h = g a h) (by simp [function.funext_iff]) /-- If `p` is a decidable predicate, so is the existence of an element in a multiset satisfying `p`. -/ protected def decidable_exists_multiset {p : α → Prop} [decidable_pred p] : decidable (∃ x ∈ m, p x) := quotient.rec_on_subsingleton m (λl, decidable_of_iff (∃ a ∈ l, p a) $ by simp) instance decidable_dexists_multiset {p : Π a ∈ m, Prop} [hp : ∀ a (h : a ∈ m), decidable (p a h)] : decidable (∃ a (h : a ∈ m), p a h) := decidable_of_decidable_of_iff (@multiset.decidable_exists_multiset {a // a ∈ m} m.attach (λa, p a.1 a.2) _) (iff.intro (λ ⟨⟨a, ha₁⟩, _, ha₂⟩, ⟨a, ha₁, ha₂⟩) (λ ⟨a, ha₁, ha₂⟩, ⟨⟨a, ha₁⟩, mem_attach _ _, ha₂⟩)) end decidable_pi_exists /-! ### Subtraction -/ section variables [decidable_eq α] {s t u : multiset α} {a b : α} /-- `s - t` is the multiset such that `count a (s - t) = count a s - count a t` for all `a` (note that it is truncated subtraction, so it is `0` if `count a t ≥ count a s`). -/ protected def sub (s t : multiset α) : multiset α := quotient.lift_on₂ s t (λ l₁ l₂, (l₁.diff l₂ : multiset α)) $ λ v₁ v₂ w₁ w₂ p₁ p₂, quot.sound $ p₁.diff p₂ instance : has_sub (multiset α) := ⟨multiset.sub⟩ @[simp] theorem coe_sub (s t : list α) : (s - t : multiset α) = (s.diff t : list α) := rfl /-- This is a special case of `tsub_zero`, which should be used instead of this. This is needed to prove `has_ordered_sub (multiset α)`. -/ protected theorem sub_zero (s : multiset α) : s - 0 = s := quot.induction_on s $ λ l, rfl @[simp] theorem sub_cons (a : α) (s t : multiset α) : s - a ::ₘ t = s.erase a - t := quotient.induction_on₂ s t $ λ l₁ l₂, congr_arg coe $ diff_cons _ _ _ /-- This is a special case of `tsub_le_iff_right`, which should be used instead of this. This is needed to prove `has_ordered_sub (multiset α)`. -/ protected theorem sub_le_iff_le_add : s - t ≤ u ↔ s ≤ u + t := by revert s; exact multiset.induction_on t (by simp [multiset.sub_zero]) (λ a t IH s, by simp [IH, erase_le_iff_le_cons]) instance : has_ordered_sub (multiset α) := ⟨λ n m k, multiset.sub_le_iff_le_add⟩ lemma cons_sub_of_le (a : α) {s t : multiset α} (h : t ≤ s) : a ::ₘ s - t = a ::ₘ (s - t) := by rw [←singleton_add, ←singleton_add, add_tsub_assoc_of_le h] theorem sub_eq_fold_erase (s t : multiset α) : s - t = foldl erase erase_comm s t := quotient.induction_on₂ s t $ λ l₁ l₂, show ↑(l₁.diff l₂) = foldl erase erase_comm ↑l₁ ↑l₂, by { rw diff_eq_foldl l₁ l₂, symmetry, exact foldl_hom _ _ _ _ _ (λ x y, rfl) } @[simp] theorem card_sub {s t : multiset α} (h : t ≤ s) : card (s - t) = card s - card t := (tsub_eq_of_eq_add_rev $ by rw [add_comm, ← card_add, tsub_add_cancel_of_le h]).symm /-! ### Union -/ /-- `s ∪ t` is the lattice join operation with respect to the multiset `≤`. The multiplicity of `a` in `s ∪ t` is the maximum of the multiplicities in `s` and `t`. -/ def union (s t : multiset α) : multiset α := s - t + t instance : has_union (multiset α) := ⟨union⟩ theorem union_def (s t : multiset α) : s ∪ t = s - t + t := rfl theorem le_union_left (s t : multiset α) : s ≤ s ∪ t := le_tsub_add theorem le_union_right (s t : multiset α) : t ≤ s ∪ t := le_add_left _ _ theorem eq_union_left : t ≤ s → s ∪ t = s := tsub_add_cancel_of_le theorem union_le_union_right (h : s ≤ t) (u) : s ∪ u ≤ t ∪ u := add_le_add_right (tsub_le_tsub_right h _) u theorem union_le (h₁ : s ≤ u) (h₂ : t ≤ u) : s ∪ t ≤ u := by rw ← eq_union_left h₂; exact union_le_union_right h₁ t @[simp] theorem mem_union : a ∈ s ∪ t ↔ a ∈ s ∨ a ∈ t := ⟨λ h, (mem_add.1 h).imp_left (mem_of_le tsub_le_self), or.rec (mem_of_le $ le_union_left _ _) (mem_of_le $ le_union_right _ _)⟩ @[simp] theorem map_union [decidable_eq β] {f : α → β} (finj : function.injective f) {s t : multiset α} : map f (s ∪ t) = map f s ∪ map f t := quotient.induction_on₂ s t $ λ l₁ l₂, congr_arg coe (by rw [list.map_append f, list.map_diff finj]) /-! ### Intersection -/ /-- `s ∩ t` is the lattice meet operation with respect to the multiset `≤`. The multiplicity of `a` in `s ∩ t` is the minimum of the multiplicities in `s` and `t`. -/ def inter (s t : multiset α) : multiset α := quotient.lift_on₂ s t (λ l₁ l₂, (l₁.bag_inter l₂ : multiset α)) $ λ v₁ v₂ w₁ w₂ p₁ p₂, quot.sound $ p₁.bag_inter p₂ instance : has_inter (multiset α) := ⟨inter⟩ @[simp] theorem inter_zero (s : multiset α) : s ∩ 0 = 0 := quot.induction_on s $ λ l, congr_arg coe l.bag_inter_nil @[simp] theorem zero_inter (s : multiset α) : 0 ∩ s = 0 := quot.induction_on s $ λ l, congr_arg coe l.nil_bag_inter @[simp] theorem cons_inter_of_pos {a} (s : multiset α) {t} : a ∈ t → (a ::ₘ s) ∩ t = a ::ₘ s ∩ t.erase a := quotient.induction_on₂ s t $ λ l₁ l₂ h, congr_arg coe $ cons_bag_inter_of_pos _ h @[simp] theorem cons_inter_of_neg {a} (s : multiset α) {t} : a ∉ t → (a ::ₘ s) ∩ t = s ∩ t := quotient.induction_on₂ s t $ λ l₁ l₂ h, congr_arg coe $ cons_bag_inter_of_neg _ h theorem inter_le_left (s t : multiset α) : s ∩ t ≤ s := quotient.induction_on₂ s t $ λ l₁ l₂, (bag_inter_sublist_left _ _).subperm theorem inter_le_right (s : multiset α) : ∀ t, s ∩ t ≤ t := multiset.induction_on s (λ t, (zero_inter t).symm ▸ zero_le _) $ λ a s IH t, if h : a ∈ t then by simpa [h] using cons_le_cons a (IH (t.erase a)) else by simp [h, IH] theorem le_inter (h₁ : s ≤ t) (h₂ : s ≤ u) : s ≤ t ∩ u := begin revert s u, refine multiset.induction_on t _ (λ a t IH, _); intros, { simp [h₁] }, by_cases a ∈ u, { rw [cons_inter_of_pos _ h, ← erase_le_iff_le_cons], exact IH (erase_le_iff_le_cons.2 h₁) (erase_le_erase _ h₂) }, { rw cons_inter_of_neg _ h, exact IH ((le_cons_of_not_mem $ mt (mem_of_le h₂) h).1 h₁) h₂ } end @[simp] theorem mem_inter : a ∈ s ∩ t ↔ a ∈ s ∧ a ∈ t := ⟨λ h, ⟨mem_of_le (inter_le_left _ _) h, mem_of_le (inter_le_right _ _) h⟩, λ ⟨h₁, h₂⟩, by rw [← cons_erase h₁, cons_inter_of_pos _ h₂]; apply mem_cons_self⟩ instance : lattice (multiset α) := { sup := (∪), sup_le := @union_le _ _, le_sup_left := le_union_left, le_sup_right := le_union_right, inf := (∩), le_inf := @le_inter _ _, inf_le_left := inter_le_left, inf_le_right := inter_le_right, ..@multiset.partial_order α } @[simp] theorem sup_eq_union (s t : multiset α) : s ⊔ t = s ∪ t := rfl @[simp] theorem inf_eq_inter (s t : multiset α) : s ⊓ t = s ∩ t := rfl @[simp] theorem le_inter_iff : s ≤ t ∩ u ↔ s ≤ t ∧ s ≤ u := le_inf_iff @[simp] theorem union_le_iff : s ∪ t ≤ u ↔ s ≤ u ∧ t ≤ u := sup_le_iff theorem union_comm (s t : multiset α) : s ∪ t = t ∪ s := sup_comm theorem inter_comm (s t : multiset α) : s ∩ t = t ∩ s := inf_comm theorem eq_union_right (h : s ≤ t) : s ∪ t = t := by rw [union_comm, eq_union_left h] theorem union_le_union_left (h : s ≤ t) (u) : u ∪ s ≤ u ∪ t := sup_le_sup_left h _ theorem union_le_add (s t : multiset α) : s ∪ t ≤ s + t := union_le (le_add_right _ _) (le_add_left _ _) theorem union_add_distrib (s t u : multiset α) : (s ∪ t) + u = (s + u) ∪ (t + u) := by simpa [(∪), union, eq_comm, add_assoc] using show s + u - (t + u) = s - t, by rw [add_comm t, tsub_add_eq_tsub_tsub, add_tsub_cancel_right] theorem add_union_distrib (s t u : multiset α) : s + (t ∪ u) = (s + t) ∪ (s + u) := by rw [add_comm, union_add_distrib, add_comm s, add_comm s] theorem cons_union_distrib (a : α) (s t : multiset α) : a ::ₘ (s ∪ t) = (a ::ₘ s) ∪ (a ::ₘ t) := by simpa using add_union_distrib (a ::ₘ 0) s t theorem inter_add_distrib (s t u : multiset α) : (s ∩ t) + u = (s + u) ∩ (t + u) := begin by_contra h, cases lt_iff_cons_le.1 (lt_of_le_of_ne (le_inter (add_le_add_right (inter_le_left s t) u) (add_le_add_right (inter_le_right s t) u)) h) with a hl, rw ← cons_add at hl, exact not_le_of_lt (lt_cons_self (s ∩ t) a) (le_inter (le_of_add_le_add_right (le_trans hl (inter_le_left _ _))) (le_of_add_le_add_right (le_trans hl (inter_le_right _ _)))) end theorem add_inter_distrib (s t u : multiset α) : s + (t ∩ u) = (s + t) ∩ (s + u) := by rw [add_comm, inter_add_distrib, add_comm s, add_comm s] theorem cons_inter_distrib (a : α) (s t : multiset α) : a ::ₘ (s ∩ t) = (a ::ₘ s) ∩ (a ::ₘ t) := by simp theorem union_add_inter (s t : multiset α) : s ∪ t + s ∩ t = s + t := begin apply le_antisymm, { rw union_add_distrib, refine union_le (add_le_add_left (inter_le_right _ _) _) _, rw add_comm, exact add_le_add_right (inter_le_left _ _) _ }, { rw [add_comm, add_inter_distrib], refine le_inter (add_le_add_right (le_union_right _ _) _) _, rw add_comm, exact add_le_add_right (le_union_left _ _) _ } end theorem sub_add_inter (s t : multiset α) : s - t + s ∩ t = s := begin rw [inter_comm], revert s, refine multiset.induction_on t (by simp) (λ a t IH s, _), by_cases a ∈ s, { rw [cons_inter_of_pos _ h, sub_cons, add_cons, IH, cons_erase h] }, { rw [cons_inter_of_neg _ h, sub_cons, erase_of_not_mem h, IH] } end theorem sub_inter (s t : multiset α) : s - (s ∩ t) = s - t := add_right_cancel $ by rw [sub_add_inter s t, tsub_add_cancel_of_le (inter_le_left s t)] end /-! ### `multiset.filter` -/ section variables (p : α → Prop) [decidable_pred p] /-- `filter p s` returns the elements in `s` (with the same multiplicities) which satisfy `p`, and removes the rest. -/ def filter (s : multiset α) : multiset α := quot.lift_on s (λ l, (filter p l : multiset α)) (λ l₁ l₂ h, quot.sound $ h.filter p) @[simp] theorem coe_filter (l : list α) : filter p (↑l) = l.filter p := rfl @[simp] theorem filter_zero : filter p 0 = 0 := rfl lemma filter_congr {p q : α → Prop} [decidable_pred p] [decidable_pred q] {s : multiset α} : (∀ x ∈ s, p x ↔ q x) → filter p s = filter q s := quot.induction_on s $ λ l h, congr_arg coe $ filter_congr' h @[simp] theorem filter_add (s t : multiset α) : filter p (s + t) = filter p s + filter p t := quotient.induction_on₂ s t $ λ l₁ l₂, congr_arg coe $ filter_append _ _ @[simp] theorem filter_le (s : multiset α) : filter p s ≤ s := quot.induction_on s $ λ l, (filter_sublist _).subperm @[simp] theorem filter_subset (s : multiset α) : filter p s ⊆ s := subset_of_le $ filter_le _ _ theorem filter_le_filter {s t} (h : s ≤ t) : filter p s ≤ filter p t := le_induction_on h $ λ l₁ l₂ h, (h.filter p).subperm lemma monotone_filter_left : monotone (filter p) := λ s t, filter_le_filter p lemma monotone_filter_right (s : multiset α) ⦃p q : α → Prop⦄ [decidable_pred p] [decidable_pred q] (h : p ≤ q) : s.filter p ≤ s.filter q := quotient.induction_on s (λ l, (l.monotone_filter_right h).subperm) variable {p} @[simp] theorem filter_cons_of_pos {a : α} (s) : p a → filter p (a ::ₘ s) = a ::ₘ filter p s := quot.induction_on s $ λ l h, congr_arg coe $ filter_cons_of_pos l h @[simp] theorem filter_cons_of_neg {a : α} (s) : ¬ p a → filter p (a ::ₘ s) = filter p s := quot.induction_on s $ λ l h, @congr_arg _ _ _ _ coe $ filter_cons_of_neg l h @[simp] theorem mem_filter {a : α} {s} : a ∈ filter p s ↔ a ∈ s ∧ p a := quot.induction_on s $ λ l, mem_filter theorem of_mem_filter {a : α} {s} (h : a ∈ filter p s) : p a := (mem_filter.1 h).2 theorem mem_of_mem_filter {a : α} {s} (h : a ∈ filter p s) : a ∈ s := (mem_filter.1 h).1 theorem mem_filter_of_mem {a : α} {l} (m : a ∈ l) (h : p a) : a ∈ filter p l := mem_filter.2 ⟨m, h⟩ theorem filter_eq_self {s} : filter p s = s ↔ ∀ a ∈ s, p a := quot.induction_on s $ λ l, iff.trans ⟨λ h, eq_of_sublist_of_length_eq (filter_sublist _) (@congr_arg _ _ _ _ card h), congr_arg coe⟩ filter_eq_self theorem filter_eq_nil {s} : filter p s = 0 ↔ ∀ a ∈ s, ¬p a := quot.induction_on s $ λ l, iff.trans ⟨λ h, eq_nil_of_length_eq_zero (@congr_arg _ _ _ _ card h), congr_arg coe⟩ filter_eq_nil theorem le_filter {s t} : s ≤ filter p t ↔ s ≤ t ∧ ∀ a ∈ s, p a := ⟨λ h, ⟨le_trans h (filter_le _ _), λ a m, of_mem_filter (mem_of_le h m)⟩, λ ⟨h, al⟩, filter_eq_self.2 al ▸ filter_le_filter p h⟩ theorem filter_cons {a : α} (s : multiset α) : filter p (a ::ₘ s) = (if p a then {a} else 0) + filter p s := begin split_ifs with h, { rw [filter_cons_of_pos _ h, singleton_add] }, { rw [filter_cons_of_neg _ h, zero_add] }, end lemma filter_singleton {a : α} (p : α → Prop) [decidable_pred p] : filter p {a} = if p a then {a} else ∅ := by simp only [singleton, filter_cons, filter_zero, add_zero, empty_eq_zero] lemma filter_nsmul (s : multiset α) (n : ℕ) : filter p (n • s) = n • filter p s := begin refine s.induction_on _ _, { simp only [filter_zero, nsmul_zero] }, { intros a ha ih, rw [nsmul_cons, filter_add, ih, filter_cons, nsmul_add], congr, split_ifs with hp; { simp only [filter_eq_self, nsmul_zero, filter_eq_nil], intros b hb, rwa (mem_singleton.mp (mem_of_mem_nsmul hb)) } } end variable (p) @[simp] theorem filter_sub [decidable_eq α] (s t : multiset α) : filter p (s - t) = filter p s - filter p t := begin revert s, refine multiset.induction_on t (by simp) (λ a t IH s, _), rw [sub_cons, IH], by_cases p a, { rw [filter_cons_of_pos _ h, sub_cons], congr, by_cases m : a ∈ s, { rw [← cons_inj_right a, ← filter_cons_of_pos _ h, cons_erase (mem_filter_of_mem m h), cons_erase m] }, { rw [erase_of_not_mem m, erase_of_not_mem (mt mem_of_mem_filter m)] } }, { rw [filter_cons_of_neg _ h], by_cases m : a ∈ s, { rw [(by rw filter_cons_of_neg _ h : filter p (erase s a) = filter p (a ::ₘ erase s a)), cons_erase m] }, { rw [erase_of_not_mem m] } } end @[simp] theorem filter_union [decidable_eq α] (s t : multiset α) : filter p (s ∪ t) = filter p s ∪ filter p t := by simp [(∪), union] @[simp] theorem filter_inter [decidable_eq α] (s t : multiset α) : filter p (s ∩ t) = filter p s ∩ filter p t := le_antisymm (le_inter (filter_le_filter _ $ inter_le_left _ _) (filter_le_filter _ $ inter_le_right _ _)) $ le_filter.2 ⟨inf_le_inf (filter_le _ _) (filter_le _ _), λ a h, of_mem_filter (mem_of_le (inter_le_left _ _) h)⟩ @[simp] theorem filter_filter (q) [decidable_pred q] (s : multiset α) : filter p (filter q s) = filter (λ a, p a ∧ q a) s := quot.induction_on s $ λ l, congr_arg coe $ filter_filter p q l theorem filter_add_filter (q) [decidable_pred q] (s : multiset α) : filter p s + filter q s = filter (λ a, p a ∨ q a) s + filter (λ a, p a ∧ q a) s := multiset.induction_on s rfl $ λ a s IH, by by_cases p a; by_cases q a; simp * theorem filter_add_not (s : multiset α) : filter p s + filter (λ a, ¬ p a) s = s := by rw [filter_add_filter, filter_eq_self.2, filter_eq_nil.2]; simp [decidable.em] theorem map_filter (f : β → α) (s : multiset β) : filter p (map f s) = map f (filter (p ∘ f) s) := quot.induction_on s (λ l, by simp [map_filter]) /-! ### Simultaneously filter and map elements of a multiset -/ /-- `filter_map f s` is a combination filter/map operation on `s`. The function `f : α → option β` is applied to each element of `s`; if `f a` is `some b` then `b` is added to the result, otherwise `a` is removed from the resulting multiset. -/ def filter_map (f : α → option β) (s : multiset α) : multiset β := quot.lift_on s (λ l, (filter_map f l : multiset β)) (λ l₁ l₂ h, quot.sound $ h.filter_map f) @[simp] theorem coe_filter_map (f : α → option β) (l : list α) : filter_map f l = l.filter_map f := rfl @[simp] theorem filter_map_zero (f : α → option β) : filter_map f 0 = 0 := rfl @[simp] theorem filter_map_cons_none {f : α → option β} (a : α) (s : multiset α) (h : f a = none) : filter_map f (a ::ₘ s) = filter_map f s := quot.induction_on s $ λ l, @congr_arg _ _ _ _ coe $ filter_map_cons_none a l h @[simp] theorem filter_map_cons_some (f : α → option β) (a : α) (s : multiset α) {b : β} (h : f a = some b) : filter_map f (a ::ₘ s) = b ::ₘ filter_map f s := quot.induction_on s $ λ l, @congr_arg _ _ _ _ coe $ filter_map_cons_some f a l h theorem filter_map_eq_map (f : α → β) : filter_map (some ∘ f) = map f := funext $ λ s, quot.induction_on s $ λ l, @congr_arg _ _ _ _ coe $ congr_fun (filter_map_eq_map f) l theorem filter_map_eq_filter : filter_map (option.guard p) = filter p := funext $ λ s, quot.induction_on s $ λ l, @congr_arg _ _ _ _ coe $ congr_fun (filter_map_eq_filter p) l theorem filter_map_filter_map (f : α → option β) (g : β → option γ) (s : multiset α) : filter_map g (filter_map f s) = filter_map (λ x, (f x).bind g) s := quot.induction_on s $ λ l, congr_arg coe $ filter_map_filter_map f g l theorem map_filter_map (f : α → option β) (g : β → γ) (s : multiset α) : map g (filter_map f s) = filter_map (λ x, (f x).map g) s := quot.induction_on s $ λ l, congr_arg coe $ map_filter_map f g l theorem filter_map_map (f : α → β) (g : β → option γ) (s : multiset α) : filter_map g (map f s) = filter_map (g ∘ f) s := quot.induction_on s $ λ l, congr_arg coe $ filter_map_map f g l theorem filter_filter_map (f : α → option β) (p : β → Prop) [decidable_pred p] (s : multiset α) : filter p (filter_map f s) = filter_map (λ x, (f x).filter p) s := quot.induction_on s $ λ l, congr_arg coe $ filter_filter_map f p l theorem filter_map_filter (f : α → option β) (s : multiset α) : filter_map f (filter p s) = filter_map (λ x, if p x then f x else none) s := quot.induction_on s $ λ l, congr_arg coe $ filter_map_filter p f l @[simp] theorem filter_map_some (s : multiset α) : filter_map some s = s := quot.induction_on s $ λ l, congr_arg coe $ filter_map_some l @[simp] theorem mem_filter_map (f : α → option β) (s : multiset α) {b : β} : b ∈ filter_map f s ↔ ∃ a, a ∈ s ∧ f a = some b := quot.induction_on s $ λ l, mem_filter_map f l theorem map_filter_map_of_inv (f : α → option β) (g : β → α) (H : ∀ x : α, (f x).map g = some x) (s : multiset α) : map g (filter_map f s) = s := quot.induction_on s $ λ l, congr_arg coe $ map_filter_map_of_inv f g H l theorem filter_map_le_filter_map (f : α → option β) {s t : multiset α} (h : s ≤ t) : filter_map f s ≤ filter_map f t := le_induction_on h $ λ l₁ l₂ h, (h.filter_map _).subperm /-! ### countp -/ /-- `countp p s` counts the number of elements of `s` (with multiplicity) that satisfy `p`. -/ def countp (s : multiset α) : ℕ := quot.lift_on s (countp p) (λ l₁ l₂, perm.countp_eq p) @[simp] theorem coe_countp (l : list α) : countp p l = l.countp p := rfl @[simp] theorem countp_zero : countp p 0 = 0 := rfl variable {p} @[simp] theorem countp_cons_of_pos {a : α} (s) : p a → countp p (a ::ₘ s) = countp p s + 1 := quot.induction_on s $ countp_cons_of_pos p @[simp] theorem countp_cons_of_neg {a : α} (s) : ¬ p a → countp p (a ::ₘ s) = countp p s := quot.induction_on s $ countp_cons_of_neg p variable (p) theorem countp_cons (b : α) (s) : countp p (b ::ₘ s) = countp p s + (if p b then 1 else 0) := quot.induction_on s $ by simp [list.countp_cons] theorem countp_eq_card_filter (s) : countp p s = card (filter p s) := quot.induction_on s $ λ l, l.countp_eq_length_filter p theorem countp_le_card (s) : countp p s ≤ card s := quot.induction_on s $ λ l, countp_le_length p @[simp] theorem countp_add (s t) : countp p (s + t) = countp p s + countp p t := by simp [countp_eq_card_filter] @[simp] theorem countp_nsmul (s) (n : ℕ) : countp p (n • s) = n * countp p s := by induction n; simp [*, succ_nsmul', succ_mul, zero_nsmul] theorem card_eq_countp_add_countp (s) : card s = countp p s + countp (λ x, ¬ p x) s := quot.induction_on s $ λ l, by simp [l.length_eq_countp_add_countp p] /-- `countp p`, the number of elements of a multiset satisfying `p`, promoted to an `add_monoid_hom`. -/ def countp_add_monoid_hom : multiset α →+ ℕ := { to_fun := countp p, map_zero' := countp_zero _, map_add' := countp_add _ } @[simp] lemma coe_countp_add_monoid_hom : (countp_add_monoid_hom p : multiset α → ℕ) = countp p := rfl @[simp] theorem countp_sub [decidable_eq α] {s t : multiset α} (h : t ≤ s) : countp p (s - t) = countp p s - countp p t := by simp [countp_eq_card_filter, h, filter_le_filter] theorem countp_le_of_le {s t} (h : s ≤ t) : countp p s ≤ countp p t := by simpa [countp_eq_card_filter] using card_le_of_le (filter_le_filter p h) @[simp] theorem countp_filter (q) [decidable_pred q] (s : multiset α) : countp p (filter q s) = countp (λ a, p a ∧ q a) s := by simp [countp_eq_card_filter] theorem countp_eq_countp_filter_add (s) (p q : α → Prop) [decidable_pred p] [decidable_pred q] : countp p s = (filter q s).countp p + (filter (λ a, ¬ q a) s).countp p := quot.induction_on s $ λ l, l.countp_eq_countp_filter_add _ _ @[simp] lemma countp_true {s : multiset α} : countp (λ _, true) s = card s := quot.induction_on s $ λ l, list.countp_true @[simp] lemma countp_false {s : multiset α} : countp (λ _, false) s = 0 := quot.induction_on s $ λ l, list.countp_false theorem countp_map (f : α → β) (s : multiset α) (p : β → Prop) [decidable_pred p] : countp p (map f s) = (s.filter (λ a, p (f a))).card := begin refine multiset.induction_on s _ (λ a t IH, _), { rw [map_zero, countp_zero, filter_zero, card_zero] }, { rw [map_cons, countp_cons, IH, filter_cons, card_add, apply_ite card, card_zero, card_singleton, add_comm] }, end variable {p} theorem countp_pos {s} : 0 < countp p s ↔ ∃ a ∈ s, p a := quot.induction_on s $ λ l, list.countp_pos p theorem countp_eq_zero {s} : countp p s = 0 ↔ ∀ a ∈ s, ¬ p a := quot.induction_on s $ λ l, list.countp_eq_zero p theorem countp_eq_card {s} : countp p s = card s ↔ ∀ a ∈ s, p a := quot.induction_on s $ λ l, list.countp_eq_length p theorem countp_pos_of_mem {s a} (h : a ∈ s) (pa : p a) : 0 < countp p s := countp_pos.2 ⟨_, h, pa⟩ theorem countp_congr {s s' : multiset α} (hs : s = s') {p p' : α → Prop} [decidable_pred p] [decidable_pred p'] (hp : ∀ x ∈ s, p x = p' x) : s.countp p = s'.countp p' := quot.induction_on₂ s s' (λ l l' hs hp, begin simp only [quot_mk_to_coe'', coe_eq_coe] at hs, exact hs.countp_congr hp, end) hs hp end /-! ### Multiplicity of an element -/ section variable [decidable_eq α] /-- `count a s` is the multiplicity of `a` in `s`. -/ def count (a : α) : multiset α → ℕ := countp (eq a) @[simp] theorem coe_count (a : α) (l : list α) : count a (↑l) = l.count a := coe_countp _ _ @[simp] theorem count_zero (a : α) : count a 0 = 0 := rfl @[simp] theorem count_cons_self (a : α) (s : multiset α) : count a (a ::ₘ s) = succ (count a s) := countp_cons_of_pos _ rfl @[simp, priority 990] theorem count_cons_of_ne {a b : α} (h : a ≠ b) (s : multiset α) : count a (b ::ₘ s) = count a s := countp_cons_of_neg _ h theorem count_le_card (a : α) (s) : count a s ≤ card s := countp_le_card _ _ theorem count_le_of_le (a : α) {s t} : s ≤ t → count a s ≤ count a t := countp_le_of_le _ theorem count_le_count_cons (a b : α) (s : multiset α) : count a s ≤ count a (b ::ₘ s) := count_le_of_le _ (le_cons_self _ _) theorem count_cons (a b : α) (s : multiset α) : count a (b ::ₘ s) = count a s + (if a = b then 1 else 0) := countp_cons _ _ _ theorem count_singleton_self (a : α) : count a ({a} : multiset α) = 1 := count_eq_one_of_mem (nodup_singleton a) $ mem_singleton_self a theorem count_singleton (a b : α) : count a ({b} : multiset α) = if a = b then 1 else 0 := by simp only [count_cons, ←cons_zero, count_zero, zero_add] @[simp] theorem count_add (a : α) : ∀ s t, count a (s + t) = count a s + count a t := countp_add _ /-- `count a`, the multiplicity of `a` in a multiset, promoted to an `add_monoid_hom`. -/ def count_add_monoid_hom (a : α) : multiset α →+ ℕ := countp_add_monoid_hom (eq a) @[simp] lemma coe_count_add_monoid_hom {a : α} : (count_add_monoid_hom a : multiset α → ℕ) = count a := rfl @[simp] theorem count_nsmul (a : α) (n s) : count a (n • s) = n * count a s := by induction n; simp [*, succ_nsmul', succ_mul, zero_nsmul] theorem count_pos {a : α} {s : multiset α} : 0 < count a s ↔ a ∈ s := by simp [count, countp_pos] theorem one_le_count_iff_mem {a : α} {s : multiset α} : 1 ≤ count a s ↔ a ∈ s := by rw [succ_le_iff, count_pos] @[simp, priority 980] theorem count_eq_zero_of_not_mem {a : α} {s : multiset α} (h : a ∉ s) : count a s = 0 := by_contradiction $ λ h', h $ count_pos.1 (nat.pos_of_ne_zero h') @[simp] theorem count_eq_zero {a : α} {s : multiset α} : count a s = 0 ↔ a ∉ s := iff_not_comm.1 $ count_pos.symm.trans pos_iff_ne_zero theorem count_ne_zero {a : α} {s : multiset α} : count a s ≠ 0 ↔ a ∈ s := by simp [ne.def, count_eq_zero] theorem count_eq_card {a : α} {s} : count a s = card s ↔ ∀ (x ∈ s), a = x := countp_eq_card @[simp] theorem count_repeat_self (a : α) (n : ℕ) : count a (repeat a n) = n := by simp [repeat] theorem count_repeat (a b : α) (n : ℕ) : count a (repeat b n) = if (a = b) then n else 0 := begin split_ifs with h₁, { rw [h₁, count_repeat_self] }, { rw [count_eq_zero], apply mt eq_of_mem_repeat h₁ }, end @[simp] theorem count_erase_self (a : α) (s : multiset α) : count a (erase s a) = pred (count a s) := begin by_cases a ∈ s, { rw [(by rw cons_erase h : count a s = count a (a ::ₘ erase s a)), count_cons_self]; refl }, { rw [erase_of_not_mem h, count_eq_zero.2 h]; refl } end @[simp, priority 980] theorem count_erase_of_ne {a b : α} (ab : a ≠ b) (s : multiset α) : count a (erase s b) = count a s := begin by_cases b ∈ s, { rw [← count_cons_of_ne ab, cons_erase h] }, { rw [erase_of_not_mem h] } end @[simp] theorem count_sub (a : α) (s t : multiset α) : count a (s - t) = count a s - count a t := begin revert s, refine multiset.induction_on t (by simp) (λ b t IH s, _), rw [sub_cons, IH], by_cases ab : a = b, { subst b, rw [count_erase_self, count_cons_self, sub_succ, pred_sub] }, { rw [count_erase_of_ne ab, count_cons_of_ne ab] } end @[simp] theorem count_union (a : α) (s t : multiset α) : count a (s ∪ t) = max (count a s) (count a t) := by simp [(∪), union, tsub_add_eq_max, -add_comm] @[simp] theorem count_inter (a : α) (s t : multiset α) : count a (s ∩ t) = min (count a s) (count a t) := begin apply @nat.add_left_cancel (count a (s - t)), rw [← count_add, sub_add_inter, count_sub, tsub_add_min], end theorem le_count_iff_repeat_le {a : α} {s : multiset α} {n : ℕ} : n ≤ count a s ↔ repeat a n ≤ s := quot.induction_on s $ λ l, le_count_iff_repeat_sublist.trans repeat_le_coe.symm @[simp] theorem count_filter_of_pos {p} [decidable_pred p] {a} {s : multiset α} (h : p a) : count a (filter p s) = count a s := quot.induction_on s $ λ l, count_filter h @[simp] theorem count_filter_of_neg {p} [decidable_pred p] {a} {s : multiset α} (h : ¬ p a) : count a (filter p s) = 0 := multiset.count_eq_zero_of_not_mem (λ t, h (of_mem_filter t)) theorem count_filter {p} [decidable_pred p] {a} {s : multiset α} : count a (filter p s) = if p a then count a s else 0 := begin split_ifs with h, { exact count_filter_of_pos h }, { exact count_filter_of_neg h }, end theorem ext {s t : multiset α} : s = t ↔ ∀ a, count a s = count a t := quotient.induction_on₂ s t $ λ l₁ l₂, quotient.eq.trans perm_iff_count @[ext] theorem ext' {s t : multiset α} : (∀ a, count a s = count a t) → s = t := ext.2 @[simp] theorem coe_inter (s t : list α) : (s ∩ t : multiset α) = (s.bag_inter t : list α) := by ext; simp theorem le_iff_count {s t : multiset α} : s ≤ t ↔ ∀ a, count a s ≤ count a t := ⟨λ h a, count_le_of_le a h, λ al, by rw ← (ext.2 (λ a, by simp [max_eq_right (al a)]) : s ∪ t = t); apply le_union_left⟩ instance : distrib_lattice (multiset α) := { le_sup_inf := λ s t u, le_of_eq $ eq.symm $ ext.2 $ λ a, by simp only [max_min_distrib_left, multiset.count_inter, multiset.sup_eq_union, multiset.count_union, multiset.inf_eq_inter], ..multiset.lattice } theorem repeat_inf (s : multiset α) (a : α) (n : ℕ) : (repeat a n) ⊓ s = repeat a (min (s.count a) n) := begin ext x, rw [inf_eq_inter, count_inter, count_repeat, count_repeat], by_cases x = a, simp only [min_comm, h, if_true, eq_self_iff_true], simp only [h, if_false, zero_min], end theorem count_map {α β : Type*} (f : α → β) (s : multiset α) [decidable_eq β] (b : β) : count b (map f s) = (s.filter (λ a, b = f a)).card := countp_map _ _ _ /-- `multiset.map f` preserves `count` if `f` is injective on the set of elements contained in the multiset -/ theorem count_map_eq_count [decidable_eq β] (f : α → β) (s : multiset α) (hf : set.inj_on f {x : α | x ∈ s}) (x ∈ s) : (s.map f).count (f x) = s.count x := begin suffices : (filter (λ (a : α), f x = f a) s).count x = card (filter (λ (a : α), f x = f a) s), { rw [count, countp_map, ← this], exact count_filter_of_pos rfl }, { rw eq_repeat.2 ⟨rfl, λ b hb, eq_comm.1 ((hf H (mem_filter.1 hb).left) (mem_filter.1 hb).right)⟩, simp only [count_repeat, eq_self_iff_true, if_true, card_repeat]}, end /-- `multiset.map f` preserves `count` if `f` is injective -/ theorem count_map_eq_count' [decidable_eq β] (f : α → β) (s : multiset α) (hf : function.injective f) (x : α) : (s.map f).count (f x) = s.count x := begin by_cases H : x ∈ s, { exact count_map_eq_count f _ (set.inj_on_of_injective hf _) _ H, }, { rw [count_eq_zero_of_not_mem H, count_eq_zero, mem_map], rintro ⟨k, hks, hkx⟩, rw hf hkx at *, contradiction } end @[simp] lemma attach_count_eq_count_coe (m : multiset α) (a) : m.attach.count a = m.count (a : α) := calc m.attach.count a = (m.attach.map (coe : _ → α)).count (a : α) : (multiset.count_map_eq_count' _ _ subtype.coe_injective _).symm ... = m.count (a : α) : congr_arg _ m.attach_map_coe lemma filter_eq' (s : multiset α) (b : α) : s.filter (= b) = repeat b (count b s) := begin ext a, rw [count_repeat, count_filter], exact if_ctx_congr iff.rfl (λ h, congr_arg _ h) (λ h, rfl), end lemma filter_eq (s : multiset α) (b : α) : s.filter (eq b) = repeat b (count b s) := by simp_rw [←filter_eq', eq_comm] @[simp] lemma repeat_inter (x : α) (n : ℕ) (s : multiset α) : repeat x n ∩ s = repeat x (min n (s.count x)) := begin refine le_antisymm _ _, { simp only [le_iff_count, count_inter, count_repeat], intro a, split_ifs with h, { rw h }, { rw [nat.zero_min] } }, simp only [le_inter_iff, ← le_count_iff_repeat_le, count_inter, count_repeat_self], end @[simp] lemma inter_repeat (s : multiset α) (x : α) (n : ℕ) : s ∩ repeat x n = repeat x (min (s.count x) n) := by rw [inter_comm, repeat_inter, min_comm] end section embedding @[simp] lemma map_le_map_iff {f : α → β} (hf : function.injective f) {s t : multiset α} : s.map f ≤ t.map f ↔ s ≤ t := begin classical, refine ⟨λ h, le_iff_count.mpr (λ a, _), map_le_map⟩, simpa [count_map_eq_count' f _ hf] using le_iff_count.mp h (f a), end /-- Associate to an embedding `f` from `α` to `β` the order embedding that maps a multiset to its image under `f`. -/ @[simps] def map_embedding (f : α ↪ β) : multiset α ↪o multiset β := order_embedding.of_map_le_iff (map f) (λ _ _, map_le_map_iff f.inj') end embedding lemma count_eq_card_filter_eq [decidable_eq α] (s : multiset α) (a : α) : s.count a = (s.filter (eq a)).card := by rw [count, countp_eq_card_filter] /-- Mapping a multiset through a predicate and counting the `true`s yields the cardinality of the set filtered by the predicate. Note that this uses the notion of a multiset of `Prop`s - due to the decidability requirements of `count`, the decidability instance on the LHS is different from the RHS. In particular, the decidability instance on the left leaks `classical.dec_eq`. See [here](https://github.com/leanprover-community/mathlib/pull/11306#discussion_r782286812) for more discussion. -/ @[simp] lemma map_count_true_eq_filter_card (s : multiset α) (p : α → Prop) [decidable_pred p] : (s.map p).count true = (s.filter p).card := by simp only [count_eq_card_filter_eq, map_filter, card_map, function.comp.left_id, eq_true_eq_id] /-! ### Lift a relation to `multiset`s -/ section rel /-- `rel r s t` -- lift the relation `r` between two elements to a relation between `s` and `t`, s.t. there is a one-to-one mapping betweem elements in `s` and `t` following `r`. -/ @[mk_iff] inductive rel (r : α → β → Prop) : multiset α → multiset β → Prop | zero : rel 0 0 | cons {a b as bs} : r a b → rel as bs → rel (a ::ₘ as) (b ::ₘ bs) variables {δ : Type*} {r : α → β → Prop} {p : γ → δ → Prop} private lemma rel_flip_aux {s t} (h : rel r s t) : rel (flip r) t s := rel.rec_on h rel.zero (assume _ _ _ _ h₀ h₁ ih, rel.cons h₀ ih) lemma rel_flip {s t} : rel (flip r) s t ↔ rel r t s := ⟨rel_flip_aux, rel_flip_aux⟩ lemma rel_refl_of_refl_on {m : multiset α} {r : α → α → Prop} : (∀ x ∈ m, r x x) → rel r m m := begin apply m.induction_on, { intros, apply rel.zero }, { intros a m ih h, exact rel.cons (h _ (mem_cons_self _ _)) (ih (λ _ ha, h _ (mem_cons_of_mem ha))) } end lemma rel_eq_refl {s : multiset α} : rel (=) s s := rel_refl_of_refl_on (λ x hx, rfl) lemma rel_eq {s t : multiset α} : rel (=) s t ↔ s = t := begin split, { assume h, induction h; simp * }, { assume h, subst h, exact rel_eq_refl } end lemma rel.mono {r p : α → β → Prop} {s t} (hst : rel r s t) (h : ∀(a ∈ s) (b ∈ t), r a b → p a b) : rel p s t := begin induction hst, case rel.zero { exact rel.zero }, case rel.cons : a b s t hab hst ih { apply rel.cons (h a (mem_cons_self _ _) b (mem_cons_self _ _) hab), exact ih (λ a' ha' b' hb' h', h a' (mem_cons_of_mem ha') b' (mem_cons_of_mem hb') h') } end lemma rel.add {s t u v} (hst : rel r s t) (huv : rel r u v) : rel r (s + u) (t + v) := begin induction hst, case rel.zero { simpa using huv }, case rel.cons : a b s t hab hst ih { simpa using ih.cons hab } end lemma rel_flip_eq {s t : multiset α} : rel (λa b, b = a) s t ↔ s = t := show rel (flip (=)) s t ↔ s = t, by rw [rel_flip, rel_eq, eq_comm] @[simp] lemma rel_zero_left {b : multiset β} : rel r 0 b ↔ b = 0 := by rw [rel_iff]; simp @[simp] lemma rel_zero_right {a : multiset α} : rel r a 0 ↔ a = 0 := by rw [rel_iff]; simp lemma rel_cons_left {a as bs} : rel r (a ::ₘ as) bs ↔ (∃b bs', r a b ∧ rel r as bs' ∧ bs = b ::ₘ bs') := begin split, { generalize hm : a ::ₘ as = m, assume h, induction h generalizing as, case rel.zero { simp at hm, contradiction }, case rel.cons : a' b as' bs ha'b h ih { rcases cons_eq_cons.1 hm with ⟨eq₁, eq₂⟩ | ⟨h, cs, eq₁, eq₂⟩, { subst eq₁, subst eq₂, exact ⟨b, bs, ha'b, h, rfl⟩ }, { rcases ih eq₂.symm with ⟨b', bs', h₁, h₂, eq⟩, exact ⟨b', b ::ₘ bs', h₁, eq₁.symm ▸ rel.cons ha'b h₂, eq.symm ▸ cons_swap _ _ _⟩ } } }, { exact assume ⟨b, bs', hab, h, eq⟩, eq.symm ▸ rel.cons hab h } end lemma rel_cons_right {as b bs} : rel r as (b ::ₘ bs) ↔ (∃a as', r a b ∧ rel r as' bs ∧ as = a ::ₘ as') := begin rw [← rel_flip, rel_cons_left], refine exists₂_congr (λ a as', _), rw [rel_flip, flip] end lemma rel_add_left {as₀ as₁} : ∀{bs}, rel r (as₀ + as₁) bs ↔ (∃bs₀ bs₁, rel r as₀ bs₀ ∧ rel r as₁ bs₁ ∧ bs = bs₀ + bs₁) := multiset.induction_on as₀ (by simp) begin assume a s ih bs, simp only [ih, cons_add, rel_cons_left], split, { assume h, rcases h with ⟨b, bs', hab, h, rfl⟩, rcases h with ⟨bs₀, bs₁, h₀, h₁, rfl⟩, exact ⟨b ::ₘ bs₀, bs₁, ⟨b, bs₀, hab, h₀, rfl⟩, h₁, by simp⟩ }, { assume h, rcases h with ⟨bs₀, bs₁, h, h₁, rfl⟩, rcases h with ⟨b, bs, hab, h₀, rfl⟩, exact ⟨b, bs + bs₁, hab, ⟨bs, bs₁, h₀, h₁, rfl⟩, by simp⟩ } end lemma rel_add_right {as bs₀ bs₁} : rel r as (bs₀ + bs₁) ↔ (∃as₀ as₁, rel r as₀ bs₀ ∧ rel r as₁ bs₁ ∧ as = as₀ + as₁) := by rw [← rel_flip, rel_add_left]; simp [rel_flip] lemma rel_map_left {s : multiset γ} {f : γ → α} : ∀{t}, rel r (s.map f) t ↔ rel (λa b, r (f a) b) s t := multiset.induction_on s (by simp) (by simp [rel_cons_left] {contextual := tt}) lemma rel_map_right {s : multiset α} {t : multiset γ} {f : γ → β} : rel r s (t.map f) ↔ rel (λa b, r a (f b)) s t := by rw [← rel_flip, rel_map_left, ← rel_flip]; refl lemma rel_map {s : multiset α} {t : multiset β} {f : α → γ} {g : β → δ} : rel p (s.map f) (t.map g) ↔ rel (λa b, p (f a) (g b)) s t := rel_map_left.trans rel_map_right lemma card_eq_card_of_rel {r : α → β → Prop} {s : multiset α} {t : multiset β} (h : rel r s t) : card s = card t := by induction h; simp [*] lemma exists_mem_of_rel_of_mem {r : α → β → Prop} {s : multiset α} {t : multiset β} (h : rel r s t) : ∀ {a : α} (ha : a ∈ s), ∃ b ∈ t, r a b := begin induction h with x y s t hxy hst ih, { simp }, { assume a ha, cases mem_cons.1 ha with ha ha, { exact ⟨y, mem_cons_self _ _, ha.symm ▸ hxy⟩ }, { rcases ih ha with ⟨b, hbt, hab⟩, exact ⟨b, mem_cons.2 (or.inr hbt), hab⟩ } } end lemma rel_of_forall {m1 m2 : multiset α} {r : α → α → Prop} (h : ∀ a b, a ∈ m1 → b ∈ m2 → r a b) (hc : card m1 = card m2) : m1.rel r m2 := begin revert m1, apply m2.induction_on, { intros m h hc, rw [rel_zero_right, ← card_eq_zero, hc, card_zero] }, { intros a t ih m h hc, rw card_cons at hc, obtain ⟨b, hb⟩ := card_pos_iff_exists_mem.1 (show 0 < card m, from hc.symm ▸ (nat.succ_pos _)), obtain ⟨m', rfl⟩ := exists_cons_of_mem hb, refine rel_cons_right.mpr ⟨b, m', h _ _ hb (mem_cons_self _ _), ih _ _, rfl⟩, { exact λ _ _ ha hb, h _ _ (mem_cons_of_mem ha) (mem_cons_of_mem hb) }, { simpa using hc } } end lemma rel_repeat_left {m : multiset α} {a : α} {r : α → α → Prop} {n : ℕ} : (repeat a n).rel r m ↔ m.card = n ∧ ∀ x, x ∈ m → r a x := ⟨λ h, ⟨(card_eq_card_of_rel h).symm.trans (card_repeat _ _), λ x hx, begin obtain ⟨b, hb1, hb2⟩ := exists_mem_of_rel_of_mem (rel_flip.2 h) hx, rwa eq_of_mem_repeat hb1 at hb2, end⟩, λ h, rel_of_forall (λ x y hx hy, (eq_of_mem_repeat hx).symm ▸ (h.2 _ hy)) (eq.trans (card_repeat _ _) h.1.symm)⟩ lemma rel_repeat_right {m : multiset α} {a : α} {r : α → α → Prop} {n : ℕ} : m.rel r (repeat a n) ↔ m.card = n ∧ ∀ x, x ∈ m → r x a := by { rw [← rel_flip], exact rel_repeat_left } lemma rel.trans (r : α → α → Prop) [is_trans α r] {s t u : multiset α} (r1 : rel r s t) (r2 : rel r t u) : rel r s u := begin induction t using multiset.induction_on with x t ih generalizing s u, { rw [rel_zero_right.mp r1, rel_zero_left.mp r2, rel_zero_left] }, { obtain ⟨a, as, ha1, ha2, rfl⟩ := rel_cons_right.mp r1, obtain ⟨b, bs, hb1, hb2, rfl⟩ := rel_cons_left.mp r2, exact multiset.rel.cons (trans ha1 hb1) (ih ha2 hb2) } end lemma rel.countp_eq (r : α → α → Prop) [is_trans α r] [is_symm α r] {s t : multiset α} (x : α) [decidable_pred (r x)] (h : rel r s t) : countp (r x) s = countp (r x) t := begin induction s using multiset.induction_on with y s ih generalizing t, { rw rel_zero_left.mp h, }, { obtain ⟨b, bs, hb1, hb2, rfl⟩ := rel_cons_left.mp h, rw [countp_cons, countp_cons, ih hb2], exact congr_arg _ (if_congr ⟨λ h, trans h hb1, λ h, trans h (symm hb1)⟩ rfl rfl) }, end end rel section map theorem map_eq_map {f : α → β} (hf : function.injective f) {s t : multiset α} : s.map f = t.map f ↔ s = t := by { rw [← rel_eq, ← rel_eq, rel_map], simp only [hf.eq_iff] } theorem map_injective {f : α → β} (hf : function.injective f) : function.injective (multiset.map f) := assume x y, (map_eq_map hf).1 end map section quot theorem map_mk_eq_map_mk_of_rel {r : α → α → Prop} {s t : multiset α} (hst : s.rel r t) : s.map (quot.mk r) = t.map (quot.mk r) := rel.rec_on hst rfl $ assume a b s t hab hst ih, by simp [ih, quot.sound hab] theorem exists_multiset_eq_map_quot_mk {r : α → α → Prop} (s : multiset (quot r)) : ∃t:multiset α, s = t.map (quot.mk r) := multiset.induction_on s ⟨0, rfl⟩ $ assume a s ⟨t, ht⟩, quot.induction_on a $ assume a, ht.symm ▸ ⟨a ::ₘ t, (map_cons _ _ _).symm⟩ theorem induction_on_multiset_quot {r : α → α → Prop} {p : multiset (quot r) → Prop} (s : multiset (quot r)) : (∀s:multiset α, p (s.map (quot.mk r))) → p s := match s, exists_multiset_eq_map_quot_mk s with _, ⟨t, rfl⟩ := assume h, h _ end end quot /-! ### Disjoint multisets -/ /-- `disjoint s t` means that `s` and `t` have no elements in common. -/ def disjoint (s t : multiset α) : Prop := ∀ ⦃a⦄, a ∈ s → a ∈ t → false @[simp] theorem coe_disjoint (l₁ l₂ : list α) : @disjoint α l₁ l₂ ↔ l₁.disjoint l₂ := iff.rfl theorem disjoint.symm {s t : multiset α} (d : disjoint s t) : disjoint t s | a i₂ i₁ := d i₁ i₂ theorem disjoint_comm {s t : multiset α} : disjoint s t ↔ disjoint t s := ⟨disjoint.symm, disjoint.symm⟩ theorem disjoint_left {s t : multiset α} : disjoint s t ↔ ∀ {a}, a ∈ s → a ∉ t := iff.rfl theorem disjoint_right {s t : multiset α} : disjoint s t ↔ ∀ {a}, a ∈ t → a ∉ s := disjoint_comm theorem disjoint_iff_ne {s t : multiset α} : disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b := by simp [disjoint_left, imp_not_comm] theorem disjoint_of_subset_left {s t u : multiset α} (h : s ⊆ u) (d : disjoint u t) : disjoint s t | x m₁ := d (h m₁) theorem disjoint_of_subset_right {s t u : multiset α} (h : t ⊆ u) (d : disjoint s u) : disjoint s t | x m m₁ := d m (h m₁) theorem disjoint_of_le_left {s t u : multiset α} (h : s ≤ u) : disjoint u t → disjoint s t := disjoint_of_subset_left (subset_of_le h) theorem disjoint_of_le_right {s t u : multiset α} (h : t ≤ u) : disjoint s u → disjoint s t := disjoint_of_subset_right (subset_of_le h) @[simp] theorem zero_disjoint (l : multiset α) : disjoint 0 l | a := (not_mem_nil a).elim @[simp, priority 1100] theorem singleton_disjoint {l : multiset α} {a : α} : disjoint {a} l ↔ a ∉ l := by simp [disjoint]; refl @[simp, priority 1100] theorem disjoint_singleton {l : multiset α} {a : α} : disjoint l {a} ↔ a ∉ l := by rw [disjoint_comm, singleton_disjoint] @[simp] theorem disjoint_add_left {s t u : multiset α} : disjoint (s + t) u ↔ disjoint s u ∧ disjoint t u := by simp [disjoint, or_imp_distrib, forall_and_distrib] @[simp] theorem disjoint_add_right {s t u : multiset α} : disjoint s (t + u) ↔ disjoint s t ∧ disjoint s u := by rw [disjoint_comm, disjoint_add_left]; tauto @[simp] theorem disjoint_cons_left {a : α} {s t : multiset α} : disjoint (a ::ₘ s) t ↔ a ∉ t ∧ disjoint s t := (@disjoint_add_left _ {a} s t).trans $ by rw singleton_disjoint @[simp] theorem disjoint_cons_right {a : α} {s t : multiset α} : disjoint s (a ::ₘ t) ↔ a ∉ s ∧ disjoint s t := by rw [disjoint_comm, disjoint_cons_left]; tauto theorem inter_eq_zero_iff_disjoint [decidable_eq α] {s t : multiset α} : s ∩ t = 0 ↔ disjoint s t := by rw ← subset_zero; simp [subset_iff, disjoint] @[simp] theorem disjoint_union_left [decidable_eq α] {s t u : multiset α} : disjoint (s ∪ t) u ↔ disjoint s u ∧ disjoint t u := by simp [disjoint, or_imp_distrib, forall_and_distrib] @[simp] theorem disjoint_union_right [decidable_eq α] {s t u : multiset α} : disjoint s (t ∪ u) ↔ disjoint s t ∧ disjoint s u := by simp [disjoint, or_imp_distrib, forall_and_distrib] lemma add_eq_union_iff_disjoint [decidable_eq α] {s t : multiset α} : s + t = s ∪ t ↔ disjoint s t := by simp_rw [←inter_eq_zero_iff_disjoint, ext, count_add, count_union, count_inter, count_zero, nat.min_eq_zero_iff, nat.add_eq_max_iff] lemma disjoint_map_map {f : α → γ} {g : β → γ} {s : multiset α} {t : multiset β} : disjoint (s.map f) (t.map g) ↔ (∀a∈s, ∀b∈t, f a ≠ g b) := by { simp [disjoint, @eq_comm _ (f _) (g _)], refl } /-- `pairwise r m` states that there exists a list of the elements s.t. `r` holds pairwise on this list. -/ def pairwise (r : α → α → Prop) (m : multiset α) : Prop := ∃l:list α, m = l ∧ l.pairwise r @[simp] lemma pairwise_nil (r : α → α → Prop) : multiset.pairwise r 0 := ⟨[], rfl, list.pairwise.nil⟩ lemma pairwise_coe_iff {r : α → α → Prop} {l : list α} : multiset.pairwise r l ↔ ∃ l' : list α, l ~ l' ∧ l'.pairwise r := exists_congr $ by simp lemma pairwise_coe_iff_pairwise {r : α → α → Prop} (hr : symmetric r) {l : list α} : multiset.pairwise r l ↔ l.pairwise r := iff.intro (assume ⟨l', eq, h⟩, ((quotient.exact eq).pairwise_iff hr).2 h) (assume h, ⟨l, rfl, h⟩) end multiset namespace multiset section choose variables (p : α → Prop) [decidable_pred p] (l : multiset α) /-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `choose_x p l hp` returns that `a` together with proofs of `a ∈ l` and `p a`. -/ def choose_x : Π hp : (∃! a, a ∈ l ∧ p a), { a // a ∈ l ∧ p a } := quotient.rec_on l (λ l' ex_unique, list.choose_x p l' (exists_of_exists_unique ex_unique)) begin intros, funext hp, suffices all_equal : ∀ x y : { t // t ∈ b ∧ p t }, x = y, { apply all_equal }, { rintros ⟨x, px⟩ ⟨y, py⟩, rcases hp with ⟨z, ⟨z_mem_l, pz⟩, z_unique⟩, congr, calc x = z : z_unique x px ... = y : (z_unique y py).symm } end /-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `choose p l hp` returns that `a`. -/ def choose (hp : ∃! a, a ∈ l ∧ p a) : α := choose_x p l hp lemma choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (choose_x p l hp).property lemma choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 lemma choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end choose variable (α) /-- The equivalence between lists and multisets of a subsingleton type. -/ def subsingleton_equiv [subsingleton α] : list α ≃ multiset α := { to_fun := coe, inv_fun := quot.lift id $ λ (a b : list α) (h : a ~ b), list.ext_le h.length_eq $ λ n h₁ h₂, subsingleton.elim _ _, left_inv := λ l, rfl, right_inv := λ m, quot.induction_on m $ λ l, rfl } variable {α} @[simp] lemma coe_subsingleton_equiv [subsingleton α] : (subsingleton_equiv α : list α → multiset α) = coe := rfl end multiset
ec8c40e89062ff1182acc14ecc2aa448b5684d26
4727251e0cd73359b15b664c3170e5d754078599
/src/algebra/algebraic_card.lean
cf43779263e5d8e693a4da0fd468b459d3a17a78
[ "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
3,672
lean
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import data.polynomial.cardinal import ring_theory.algebraic /-! ### Cardinality of algebraic numbers In this file, we prove variants of the following result: the cardinality of algebraic numbers under an R-algebra is at most `# polynomial R * ω`. Although this can be used to prove that real or complex transcendental numbers exist, a more direct proof is given by `liouville.is_transcendental`. -/ universes u v open cardinal polynomial open_locale cardinal namespace algebraic theorem omega_le_cardinal_mk_of_char_zero (R A : Type*) [comm_ring R] [is_domain R] [ring A] [algebra R A] [char_zero A] : ω ≤ #{x : A | is_algebraic R x} := @mk_le_of_injective (ulift ℕ) {x : A | is_algebraic R x} (λ n, ⟨_, is_algebraic_nat n.down⟩) (λ m n hmn, by simpa using hmn) section lift variables (R : Type u) (A : Type v) [comm_ring R] [comm_ring A] [is_domain A] [algebra R A] [no_zero_smul_divisors R A] theorem cardinal_mk_lift_le_mul : cardinal.lift.{u v} (#{x : A | is_algebraic R x}) ≤ cardinal.lift.{v u} (#(polynomial R)) * ω := begin rw [←mk_ulift, ←mk_ulift], let g : ulift.{u} {x : A | is_algebraic R x} → ulift.{v} (polynomial R) := λ x, ulift.up (classical.some x.1.2), apply cardinal.mk_le_mk_mul_of_mk_preimage_le g (λ f, _), suffices : fintype (g ⁻¹' {f}), { exact @mk_le_omega _ (@fintype.to_encodable _ this) }, by_cases hf : f.1 = 0, { convert set.fintype_empty, apply set.eq_empty_iff_forall_not_mem.2 (λ x hx, _), simp only [set.mem_preimage, set.mem_singleton_iff] at hx, apply_fun ulift.down at hx, rw hf at hx, exact (classical.some_spec x.1.2).1 hx }, let h : g ⁻¹' {f} → f.down.root_set A := λ x, ⟨x.1.1.1, (mem_root_set_iff hf x.1.1.1).2 begin have key' : g x = f := x.2, simp_rw ← key', exact (classical.some_spec x.1.1.2).2 end⟩, apply fintype.of_injective h (λ _ _ H, _), simp only [subtype.val_eq_coe, subtype.mk_eq_mk] at H, exact subtype.ext (ulift.down_injective (subtype.ext H)) end theorem cardinal_mk_lift_le_max : cardinal.lift.{u v} (#{x : A | is_algebraic R x}) ≤ max (cardinal.lift.{v u} (#R)) ω := (cardinal_mk_lift_le_mul R A).trans $ (mul_le_mul_right' (lift_le.2 cardinal_mk_le_max) _).trans $ by simp [le_total] theorem cardinal_mk_lift_le_of_infinite [infinite R] : cardinal.lift.{u v} (#{x : A | is_algebraic R x}) ≤ cardinal.lift.{v u} (#R) := (cardinal_mk_lift_le_max R A).trans $ by simp variable [encodable R] @[simp] theorem countable_of_encodable : set.countable {x : A | is_algebraic R x} := begin rw [←mk_set_le_omega, ←lift_le], apply (cardinal_mk_lift_le_max R A).trans, simp end @[simp] theorem cardinal_mk_of_encodable_of_char_zero [char_zero A] [is_domain R] : #{x : A | is_algebraic R x} = ω := le_antisymm (by simp) (omega_le_cardinal_mk_of_char_zero R A) end lift section non_lift variables (R A : Type u) [comm_ring R] [comm_ring A] [is_domain A] [algebra R A] [no_zero_smul_divisors R A] theorem cardinal_mk_le_mul : #{x : A | is_algebraic R x} ≤ #(polynomial R) * ω := by { rw [←lift_id (#_), ←lift_id (#(polynomial R))], exact cardinal_mk_lift_le_mul R A } theorem cardinal_mk_le_max : #{x : A | is_algebraic R x} ≤ max (#R) ω := by { rw [←lift_id (#_), ←lift_id (#R)], exact cardinal_mk_lift_le_max R A } theorem cardinal_mk_le_of_infinite [infinite R] : #{x : A | is_algebraic R x} ≤ #R := (cardinal_mk_le_max R A).trans $ by simp end non_lift end algebraic
f6dc0a8b21208a280842580c8a354912e8c3df0a
09b3e1beaeff2641ac75019c9f735d79d508071d
/Mathlib/Tactic/Spread.lean
2bd592fa14dc7102a0cb9aaf3fddaa62db7ff29a
[ "Apache-2.0" ]
permissive
abentkamp/mathlib4
b819079cc46426b3c5c77413504b07541afacc19
f8294a67548f8f3d1f5913677b070a2ef5bcf120
refs/heads/master
1,685,309,252,764
1,623,232,534,000
1,623,232,534,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,000
lean
/- Copyright (c) 2021 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Gabriel Ebner -/ import Lean open Lean Meta Elab Term Parser.Term /- This adds support for structure instance spread syntax. ```lean instance : Foo α where __ := instSomething -- include fields from `instSomething` example : Foo α := { __ := instSomething -- include fields from `instSomething` } ``` -/ namespace Lean.Term.Elab @[termElab structInst] def elabSpread : TermElab | `({ $[$src? with]? $[$fields $[,]?]* $[: $ty?]? }), expectedType => do let mut spreads := #[] let mut newFieldNames : Std.HashSet Name := {} let mut newFields : Array Syntax := {} for field in fields do match field with | `(structInstField| $name:ident := $arg) => if name.getId.eraseMacroScopes == `__ then do spreads := spreads.push <|<- withRef arg do withFreshMacroScope do let arg ← elabTerm arg none let argType ← whnf (← inferType arg) let argTypeC ← getStructureName argType let stxMVar ← `(?spread) assignExprMVar (← elabTerm stxMVar argType).mvarId! arg (argTypeC, field, stxMVar) else newFields := newFields.push field newFieldNames := newFieldNames.insert name.getId.eraseMacroScopes | `(structInstFieldAbbrev| $name:ident) => newFields := newFields.push field newFieldNames := newFieldNames.insert name.getId.eraseMacroScopes | _ => throwUnsupportedSyntax if spreads.isEmpty then throwUnsupportedSyntax if expectedType.isNone then throwError "expected type required for `__ := ...` syntax" let expectedStructName ← getStructureName expectedType.get! let expectedFields ← getStructureFieldsFlattened (← getEnv) expectedStructName (includeSubobjectFields := false) for (spreadType, spreadField, spread) in spreads do let mut used := false for field in ← getStructureFieldsFlattened (← getEnv) spreadType (includeSubobjectFields := false) do if newFieldNames.contains field then continue if !expectedFields.contains field then continue newFieldNames := newFieldNames.insert field newFields := newFields.push <|<- `(structInstField| $(mkCIdent field):ident := ($spread).$(mkCIdent field):ident) used := true if !used then withRef spreadField do throwError "no fields used from spread" let stx' ← `({ $[$src? with]? $[$newFields]* $[: $ty?]? }) elabTerm stx' expectedType | _, _ => throwUnsupportedSyntax where getStructureName (ty : Expr) : TermElabM Name := do if ty.getAppFn.isConst then let tyC ← ty.getAppFn.constName! if isStructureLike (← getEnv) tyC then return tyC throwError "expected structure type, but got{indentExpr ty}"
8fb7f9a9f9239992066a4c307247fb1e3742b3d0
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/analysis/normed_space/bounded_linear_maps.lean
ffc43eca1571c34ab6130dad00e2641b2a0b5437
[ "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
19,228
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 Continuous linear functions -- functions between normed vector spaces which are bounded and linear. -/ import analysis.normed_space.multilinear noncomputable theory open_locale classical filter big_operators open filter (tendsto) open metric variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] variables {E : Type*} [normed_group E] [normed_space 𝕜 E] variables {F : Type*} [normed_group F] [normed_space 𝕜 F] variables {G : Type*} [normed_group G] [normed_space 𝕜 G] /-- A function `f` satisfies `is_bounded_linear_map 𝕜 f` if it is linear and satisfies the inequality `∥ f x ∥ ≤ M * ∥ x ∥` for some positive constant `M`. -/ structure is_bounded_linear_map (𝕜 : Type*) [normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] {F : Type*} [normed_group F] [normed_space 𝕜 F] (f : E → F) extends is_linear_map 𝕜 f : Prop := (bound : ∃ M, 0 < M ∧ ∀ x : E, ∥ f x ∥ ≤ M * ∥ x ∥) lemma is_linear_map.with_bound {f : E → F} (hf : is_linear_map 𝕜 f) (M : ℝ) (h : ∀ x : E, ∥ f x ∥ ≤ M * ∥ x ∥) : is_bounded_linear_map 𝕜 f := ⟨ hf, classical.by_cases (assume : M ≤ 0, ⟨1, zero_lt_one, assume x, le_trans (h x) $ mul_le_mul_of_nonneg_right (le_trans this zero_le_one) (norm_nonneg x)⟩) (assume : ¬ M ≤ 0, ⟨M, lt_of_not_ge this, h⟩)⟩ /-- A continuous linear map satisfies `is_bounded_linear_map` -/ lemma continuous_linear_map.is_bounded_linear_map (f : E →L[𝕜] F) : is_bounded_linear_map 𝕜 f := { bound := f.bound, ..f.to_linear_map.is_linear } namespace is_bounded_linear_map /-- Construct a linear map from a function `f` satisfying `is_bounded_linear_map 𝕜 f`. -/ def to_linear_map (f : E → F) (h : is_bounded_linear_map 𝕜 f) : E →ₗ[𝕜] F := (is_linear_map.mk' _ h.to_is_linear_map) /-- Construct a continuous linear map from is_bounded_linear_map -/ def to_continuous_linear_map {f : E → F} (hf : is_bounded_linear_map 𝕜 f) : E →L[𝕜] F := { cont := let ⟨C, Cpos, hC⟩ := hf.bound in linear_map.continuous_of_bound _ C hC, ..to_linear_map f hf} lemma zero : is_bounded_linear_map 𝕜 (λ (x:E), (0:F)) := (0 : E →ₗ F).is_linear.with_bound 0 $ by simp [le_refl] lemma id : is_bounded_linear_map 𝕜 (λ (x:E), x) := linear_map.id.is_linear.with_bound 1 $ by simp [le_refl] lemma fst : is_bounded_linear_map 𝕜 (λ x : E × F, x.1) := begin refine (linear_map.fst 𝕜 E F).is_linear.with_bound 1 (λx, _), rw one_mul, exact le_max_left _ _ end lemma snd : is_bounded_linear_map 𝕜 (λ x : E × F, x.2) := begin refine (linear_map.snd 𝕜 E F).is_linear.with_bound 1 (λx, _), rw one_mul, exact le_max_right _ _ end variables { f g : E → F } lemma smul (c : 𝕜) (hf : is_bounded_linear_map 𝕜 f) : is_bounded_linear_map 𝕜 (λ e, c • f e) := let ⟨hlf, M, hMp, hM⟩ := hf in (c • hlf.mk' f).is_linear.with_bound (∥c∥ * M) $ assume x, calc ∥c • f x∥ = ∥c∥ * ∥f x∥ : norm_smul c (f x) ... ≤ ∥c∥ * (M * ∥x∥) : mul_le_mul_of_nonneg_left (hM _) (norm_nonneg _) ... = (∥c∥ * M) * ∥x∥ : (mul_assoc _ _ _).symm lemma neg (hf : is_bounded_linear_map 𝕜 f) : is_bounded_linear_map 𝕜 (λ e, -f e) := begin rw show (λ e, -f e) = (λ e, (-1 : 𝕜) • f e), { funext, simp }, exact smul (-1) hf end lemma add (hf : is_bounded_linear_map 𝕜 f) (hg : is_bounded_linear_map 𝕜 g) : is_bounded_linear_map 𝕜 (λ e, f e + g e) := let ⟨hlf, Mf, hMfp, hMf⟩ := hf in let ⟨hlg, Mg, hMgp, hMg⟩ := hg in (hlf.mk' _ + hlg.mk' _).is_linear.with_bound (Mf + Mg) $ assume x, calc ∥f x + g x∥ ≤ Mf * ∥x∥ + Mg * ∥x∥ : norm_add_le_of_le (hMf x) (hMg x) ... ≤ (Mf + Mg) * ∥x∥ : by rw add_mul lemma sub (hf : is_bounded_linear_map 𝕜 f) (hg : is_bounded_linear_map 𝕜 g) : is_bounded_linear_map 𝕜 (λ e, f e - g e) := add hf (neg hg) lemma comp {g : F → G} (hg : is_bounded_linear_map 𝕜 g) (hf : is_bounded_linear_map 𝕜 f) : is_bounded_linear_map 𝕜 (g ∘ f) := (hg.to_continuous_linear_map.comp hf.to_continuous_linear_map).is_bounded_linear_map lemma tendsto (x : E) (hf : is_bounded_linear_map 𝕜 f) : f →_{x} (f x) := let ⟨hf, M, hMp, hM⟩ := hf in tendsto_iff_norm_tendsto_zero.2 $ squeeze_zero (assume e, norm_nonneg _) (assume e, calc ∥f e - f x∥ = ∥hf.mk' f (e - x)∥ : by rw (hf.mk' _).map_sub e x; refl ... ≤ M * ∥e - x∥ : hM (e - x)) (suffices (λ (e : E), M * ∥e - x∥) →_{x} (M * 0), by simpa, tendsto_const_nhds.mul (lim_norm _)) lemma continuous (hf : is_bounded_linear_map 𝕜 f) : continuous f := continuous_iff_continuous_at.2 $ λ _, hf.tendsto _ lemma lim_zero_bounded_linear_map (hf : is_bounded_linear_map 𝕜 f) : (f →_{0} 0) := (hf.1.mk' _).map_zero ▸ continuous_iff_continuous_at.1 hf.continuous 0 section open asymptotics filter theorem is_O_id {f : E → F} (h : is_bounded_linear_map 𝕜 f) (l : filter E) : is_O f (λ x, x) l := let ⟨M, hMp, hM⟩ := h.bound in is_O.of_bound _ (mem_sets_of_superset univ_mem_sets (λ x _, hM x)) theorem is_O_comp {E : Type*} {g : F → G} (hg : is_bounded_linear_map 𝕜 g) {f : E → F} (l : filter E) : is_O (λ x', g (f x')) f l := (hg.is_O_id ⊤).comp_tendsto le_top theorem is_O_sub {f : E → F} (h : is_bounded_linear_map 𝕜 f) (l : filter E) (x : E) : is_O (λ x', f (x' - x)) (λ x', x' - x) l := is_O_comp h l end end is_bounded_linear_map section variables {ι : Type*} [decidable_eq ι] [fintype ι] /-- Taking the cartesian product of two continuous linear maps is a bounded linear operation. -/ lemma is_bounded_linear_map_prod_iso : is_bounded_linear_map 𝕜 (λ(p : (E →L[𝕜] F) × (E →L[𝕜] G)), (p.1.prod p.2 : (E →L[𝕜] (F × G)))) := begin refine is_linear_map.with_bound ⟨λu v, rfl, λc u, rfl⟩ 1 (λp, _), simp only [norm, one_mul], refine continuous_linear_map.op_norm_le_bound _ (le_trans (norm_nonneg _) (le_max_left _ _)) (λu, _), simp only [norm, continuous_linear_map.prod, max_le_iff], split, { calc ∥p.1 u∥ ≤ ∥p.1∥ * ∥u∥ : continuous_linear_map.le_op_norm _ _ ... ≤ max (∥p.1∥) (∥p.2∥) * ∥u∥ : mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg _) }, { calc ∥p.2 u∥ ≤ ∥p.2∥ * ∥u∥ : continuous_linear_map.le_op_norm _ _ ... ≤ max (∥p.1∥) (∥p.2∥) * ∥u∥ : mul_le_mul_of_nonneg_right (le_max_right _ _) (norm_nonneg _) } end /-- Taking the cartesian product of two continuous multilinear maps is a bounded linear operation. -/ lemma is_bounded_linear_map_prod_multilinear {E : ι → Type*} [∀i, normed_group (E i)] [∀i, normed_space 𝕜 (E i)] : is_bounded_linear_map 𝕜 (λ p : (continuous_multilinear_map 𝕜 E F) × (continuous_multilinear_map 𝕜 E G), p.1.prod p.2) := { map_add := λ p₁ p₂, by { ext1 m, refl }, map_smul := λ c p, by { ext1 m, refl }, bound := ⟨1, zero_lt_one, λ p, begin rw one_mul, apply continuous_multilinear_map.op_norm_le_bound _ (norm_nonneg _) (λ m, _), rw [continuous_multilinear_map.prod_apply, norm_prod_le_iff], split, { exact le_trans (p.1.le_op_norm m) (mul_le_mul_of_nonneg_right (norm_fst_le p) (finset.prod_nonneg (λ i hi, norm_nonneg _))) }, { exact le_trans (p.2.le_op_norm m) (mul_le_mul_of_nonneg_right (norm_snd_le p) (finset.prod_nonneg (λ i hi, norm_nonneg _))) }, end⟩ } /-- Given a fixed continuous linear map `g`, associating to a continuous multilinear map `f` the continuous multilinear map `f (g m₁, ..., g mₙ)` is a bounded linear operation. -/ lemma is_bounded_linear_map_continuous_multilinear_map_comp_linear (g : G →L[𝕜] E) : is_bounded_linear_map 𝕜 (λ f : continuous_multilinear_map 𝕜 (λ (i : ι), E) F, f.comp_continuous_linear_map 𝕜 E g) := begin refine is_linear_map.with_bound ⟨λ f₁ f₂, by { ext m, refl }, λ c f, by { ext m, refl }⟩ (∥g∥ ^ (fintype.card ι)) (λ f, _), apply continuous_multilinear_map.op_norm_le_bound _ _ (λ m, _), { apply_rules [mul_nonneg, pow_nonneg, norm_nonneg] }, calc ∥f (g ∘ m)∥ ≤ ∥f∥ * ∏ i, ∥g (m i)∥ : f.le_op_norm _ ... ≤ ∥f∥ * ∏ i, (∥g∥ * ∥m i∥) : begin apply mul_le_mul_of_nonneg_left _ (norm_nonneg _), exact finset.prod_le_prod (λ i hi, norm_nonneg _) (λ i hi, g.le_op_norm _) end ... = ∥g∥ ^ fintype.card ι * ∥f∥ * ∏ i, ∥m i∥ : by { simp [finset.prod_mul_distrib, finset.card_univ], ring } end end section bilinear_map variable (𝕜) /-- A map `f : E × F → G` satisfies `is_bounded_bilinear_map 𝕜 f` if it is bilinear and continuous. -/ structure is_bounded_bilinear_map (f : E × F → G) : Prop := (add_left : ∀(x₁ x₂ : E) (y : F), f (x₁ + x₂, y) = f (x₁, y) + f (x₂, y)) (smul_left : ∀(c : 𝕜) (x : E) (y : F), f (c • x, y) = c • f (x,y)) (add_right : ∀(x : E) (y₁ y₂ : F), f (x, y₁ + y₂) = f (x, y₁) + f (x, y₂)) (smul_right : ∀(c : 𝕜) (x : E) (y : F), f (x, c • y) = c • f (x,y)) (bound : ∃C>0, ∀(x : E) (y : F), ∥f (x, y)∥ ≤ C * ∥x∥ * ∥y∥) variable {𝕜} variable {f : E × F → G} protected lemma is_bounded_bilinear_map.is_O (h : is_bounded_bilinear_map 𝕜 f) : asymptotics.is_O f (λ p : E × F, ∥p.1∥ * ∥p.2∥) ⊤ := let ⟨C, Cpos, hC⟩ := h.bound in asymptotics.is_O.of_bound _ $ filter.eventually_of_forall $ λ ⟨x, y⟩, by simpa [mul_assoc] using hC x y lemma is_bounded_bilinear_map.is_O_comp {α : Type*} (H : is_bounded_bilinear_map 𝕜 f) {g : α → E} {h : α → F} {l : filter α} : asymptotics.is_O (λ x, f (g x, h x)) (λ x, ∥g x∥ * ∥h x∥) l := H.is_O.comp_tendsto le_top protected lemma is_bounded_bilinear_map.is_O' (h : is_bounded_bilinear_map 𝕜 f) : asymptotics.is_O f (λ p : E × F, ∥p∥ * ∥p∥) ⊤ := h.is_O.trans (asymptotics.is_O_fst_prod'.norm_norm.mul asymptotics.is_O_snd_prod'.norm_norm) lemma is_bounded_bilinear_map.map_sub_left (h : is_bounded_bilinear_map 𝕜 f) {x y : E} {z : F} : f (x - y, z) = f (x, z) - f(y, z) := calc f (x - y, z) = f (x + (-1 : 𝕜) • y, z) : by simp [sub_eq_add_neg] ... = f (x, z) + (-1 : 𝕜) • f (y, z) : by simp only [h.add_left, h.smul_left] ... = f (x, z) - f (y, z) : by simp [sub_eq_add_neg] lemma is_bounded_bilinear_map.map_sub_right (h : is_bounded_bilinear_map 𝕜 f) {x : E} {y z : F} : f (x, y - z) = f (x, y) - f (x, z) := calc f (x, y - z) = f (x, y + (-1 : 𝕜) • z) : by simp [sub_eq_add_neg] ... = f (x, y) + (-1 : 𝕜) • f (x, z) : by simp only [h.add_right, h.smul_right] ... = f (x, y) - f (x, z) : by simp [sub_eq_add_neg] lemma is_bounded_bilinear_map.is_bounded_linear_map_left (h : is_bounded_bilinear_map 𝕜 f) (y : F) : is_bounded_linear_map 𝕜 (λ x, f (x, y)) := { map_add := λ x x', h.add_left _ _ _, map_smul := λ c x, h.smul_left _ _ _, bound := begin rcases h.bound with ⟨C, C_pos, hC⟩, refine ⟨C * (∥y∥ + 1), mul_pos C_pos (lt_of_lt_of_le (zero_lt_one) (by simp)), λ x, _⟩, have : ∥y∥ ≤ ∥y∥ + 1, by simp [zero_le_one], calc ∥f (x, y)∥ ≤ C * ∥x∥ * ∥y∥ : hC x y ... ≤ C * ∥x∥ * (∥y∥ + 1) : by apply_rules [norm_nonneg, mul_le_mul_of_nonneg_left, le_of_lt C_pos, mul_nonneg] ... = C * (∥y∥ + 1) * ∥x∥ : by ring end } lemma is_bounded_bilinear_map.is_bounded_linear_map_right (h : is_bounded_bilinear_map 𝕜 f) (x : E) : is_bounded_linear_map 𝕜 (λ y, f (x, y)) := { map_add := λ y y', h.add_right _ _ _, map_smul := λ c y, h.smul_right _ _ _, bound := begin rcases h.bound with ⟨C, C_pos, hC⟩, refine ⟨C * (∥x∥ + 1), mul_pos C_pos (lt_of_lt_of_le (zero_lt_one) (by simp)), λ y, _⟩, have : ∥x∥ ≤ ∥x∥ + 1, by simp [zero_le_one], calc ∥f (x, y)∥ ≤ C * ∥x∥ * ∥y∥ : hC x y ... ≤ C * (∥x∥ + 1) * ∥y∥ : by apply_rules [mul_le_mul_of_nonneg_right, norm_nonneg, mul_le_mul_of_nonneg_left, le_of_lt C_pos] end } lemma is_bounded_bilinear_map_smul : is_bounded_bilinear_map 𝕜 (λ (p : 𝕜 × E), p.1 • p.2) := { add_left := add_smul, smul_left := λc x y, by simp [smul_smul], add_right := smul_add, smul_right := λc x y, by simp [smul_smul, mul_comm], bound := ⟨1, zero_lt_one, λx y, by simp [norm_smul]⟩ } lemma is_bounded_bilinear_map_mul : is_bounded_bilinear_map 𝕜 (λ (p : 𝕜 × 𝕜), p.1 * p.2) := is_bounded_bilinear_map_smul lemma is_bounded_bilinear_map_comp : is_bounded_bilinear_map 𝕜 (λ(p : (E →L[𝕜] F) × (F →L[𝕜] G)), p.2.comp p.1) := { add_left := λx₁ x₂ y, begin ext z, change y (x₁ z + x₂ z) = y (x₁ z) + y (x₂ z), rw y.map_add end, smul_left := λc x y, begin ext z, change y (c • (x z)) = c • y (x z), rw continuous_linear_map.map_smul end, add_right := λx y₁ y₂, rfl, smul_right := λc x y, rfl, bound := ⟨1, zero_lt_one, λx y, calc ∥continuous_linear_map.comp ((x, y).snd) ((x, y).fst)∥ ≤ ∥y∥ * ∥x∥ : continuous_linear_map.op_norm_comp_le _ _ ... = 1 * ∥x∥ * ∥ y∥ : by ring ⟩ } lemma continuous_linear_map.is_bounded_linear_map_comp_left (g : continuous_linear_map 𝕜 F G) : is_bounded_linear_map 𝕜 (λ(f : E →L[𝕜] F), continuous_linear_map.comp g f) := is_bounded_bilinear_map_comp.is_bounded_linear_map_left _ lemma continuous_linear_map.is_bounded_linear_map_comp_right (f : continuous_linear_map 𝕜 E F) : is_bounded_linear_map 𝕜 (λ(g : F →L[𝕜] G), continuous_linear_map.comp g f) := is_bounded_bilinear_map_comp.is_bounded_linear_map_right _ lemma is_bounded_bilinear_map_apply : is_bounded_bilinear_map 𝕜 (λp : (E →L[𝕜] F) × E, p.1 p.2) := { add_left := by simp, smul_left := by simp, add_right := by simp, smul_right := by simp, bound := ⟨1, zero_lt_one, by simp [continuous_linear_map.le_op_norm]⟩ } /-- The function `continuous_linear_map.smul_right`, associating to a continuous linear map `f : E → 𝕜` and a scalar `c : F` the tensor product `f ⊗ c` as a continuous linear map from `E` to `F`, is a bounded bilinear map. -/ lemma is_bounded_bilinear_map_smul_right : is_bounded_bilinear_map 𝕜 (λp, (continuous_linear_map.smul_right : (E →L[𝕜] 𝕜) → F → (E →L[𝕜] F)) p.1 p.2) := { add_left := λm₁ m₂ f, by { ext z, simp [add_smul] }, smul_left := λc m f, by { ext z, simp [mul_smul] }, add_right := λm f₁ f₂, by { ext z, simp [smul_add] }, smul_right := λc m f, by { ext z, simp [smul_smul, mul_comm] }, bound := ⟨1, zero_lt_one, λm f, by simp⟩ } /-- The composition of a continuous linear map with a continuous multilinear map is a bounded bilinear operation. -/ lemma is_bounded_bilinear_map_comp_multilinear {ι : Type*} {E : ι → Type*} [decidable_eq ι] [fintype ι] [∀i, normed_group (E i)] [∀i, normed_space 𝕜 (E i)] : is_bounded_bilinear_map 𝕜 (λ p : (F →L[𝕜] G) × (continuous_multilinear_map 𝕜 E F), p.1.comp_continuous_multilinear_map p.2) := { add_left := λ g₁ g₂ f, by { ext m, refl }, smul_left := λ c g f, by { ext m, refl }, add_right := λ g f₁ f₂, by { ext m, simp }, smul_right := λ c g f, by { ext m, simp }, bound := ⟨1, zero_lt_one, λ g f, begin apply continuous_multilinear_map.op_norm_le_bound _ _ (λm, _), { apply_rules [mul_nonneg, zero_le_one, norm_nonneg] }, calc ∥g (f m)∥ ≤ ∥g∥ * ∥f m∥ : g.le_op_norm _ ... ≤ ∥g∥ * (∥f∥ * ∏ i, ∥m i∥) : mul_le_mul_of_nonneg_left (f.le_op_norm _) (norm_nonneg _) ... = 1 * ∥g∥ * ∥f∥ * ∏ i, ∥m i∥ : by ring end⟩ } /-- Definition of the derivative of a bilinear map `f`, given at a point `p` by `q ↦ f(p.1, q.2) + f(q.1, p.2)` as in the standard formula for the derivative of a product. We define this function here a bounded linear map from `E × F` to `G`. The fact that this is indeed the derivative of `f` is proved in `is_bounded_bilinear_map.has_fderiv_at` in `fderiv.lean`-/ def is_bounded_bilinear_map.linear_deriv (h : is_bounded_bilinear_map 𝕜 f) (p : E × F) : (E × F) →ₗ[𝕜] G := { to_fun := λq, f (p.1, q.2) + f (q.1, p.2), map_add' := λq₁ q₂, begin change f (p.1, q₁.2 + q₂.2) + f (q₁.1 + q₂.1, p.2) = f (p.1, q₁.2) + f (q₁.1, p.2) + (f (p.1, q₂.2) + f (q₂.1, p.2)), simp [h.add_left, h.add_right], abel end, map_smul' := λc q, begin change f (p.1, c • q.2) + f (c • q.1, p.2) = c • (f (p.1, q.2) + f (q.1, p.2)), simp [h.smul_left, h.smul_right, smul_add] end } /-- The derivative of a bounded bilinear map at a point `p : E × F`, as a continuous linear map from `E × F` to `G`. -/ def is_bounded_bilinear_map.deriv (h : is_bounded_bilinear_map 𝕜 f) (p : E × F) : (E × F) →L[𝕜] G := (h.linear_deriv p).mk_continuous_of_exists_bound $ begin rcases h.bound with ⟨C, Cpos, hC⟩, refine ⟨C * ∥p.1∥ + C * ∥p.2∥, λq, _⟩, calc ∥f (p.1, q.2) + f (q.1, p.2)∥ ≤ C * ∥p.1∥ * ∥q.2∥ + C * ∥q.1∥ * ∥p.2∥ : norm_add_le_of_le (hC _ _) (hC _ _) ... ≤ C * ∥p.1∥ * ∥q∥ + C * ∥q∥ * ∥p.2∥ : begin apply add_le_add, exact mul_le_mul_of_nonneg_left (le_max_right _ _) (mul_nonneg (le_of_lt Cpos) (norm_nonneg _)), apply mul_le_mul_of_nonneg_right _ (norm_nonneg _), exact mul_le_mul_of_nonneg_left (le_max_left _ _) (le_of_lt Cpos), end ... = (C * ∥p.1∥ + C * ∥p.2∥) * ∥q∥ : by ring end @[simp] lemma is_bounded_bilinear_map_deriv_coe (h : is_bounded_bilinear_map 𝕜 f) (p q : E × F) : h.deriv p q = f (p.1, q.2) + f (q.1, p.2) := rfl /-- Given a bounded bilinear map `f`, the map associating to a point `p` the derivative of `f` at `p` is itself a bounded linear map. -/ lemma is_bounded_bilinear_map.is_bounded_linear_map_deriv (h : is_bounded_bilinear_map 𝕜 f) : is_bounded_linear_map 𝕜 (λp : E × F, h.deriv p) := begin rcases h.bound with ⟨C, Cpos, hC⟩, refine is_linear_map.with_bound ⟨λp₁ p₂, _, λc p, _⟩ (C + C) (λp, _), { ext q, simp [h.add_left, h.add_right], abel }, { ext q, simp [h.smul_left, h.smul_right, smul_add] }, { refine continuous_linear_map.op_norm_le_bound _ (mul_nonneg (add_nonneg (le_of_lt Cpos) (le_of_lt Cpos)) (norm_nonneg _)) (λq, _), calc ∥f (p.1, q.2) + f (q.1, p.2)∥ ≤ C * ∥p.1∥ * ∥q.2∥ + C * ∥q.1∥ * ∥p.2∥ : norm_add_le_of_le (hC _ _) (hC _ _) ... ≤ C * ∥p∥ * ∥q∥ + C * ∥q∥ * ∥p∥ : by apply_rules [add_le_add, mul_le_mul, norm_nonneg, le_of_lt Cpos, le_refl, le_max_left, le_max_right, mul_nonneg] ... = (C + C) * ∥p∥ * ∥q∥ : by ring }, end end bilinear_map
002125135fb93169ba61536a1cb9ee821b312c69
8c3de0f4873364ba4a1bb0f7791f3a52876ecea2
/src/maclane_birkhoff_survey_modern_algebra_sections_1.3.lean
008306f171b3d1b795444a8c80b83521d086f1c0
[ "Apache-2.0" ]
permissive
catskillsresearch/grundbegriffe
7c2d410fabe59b8cbc19af694ec5cf30ee3ffa93
e8aa4fe66308d9e6e85d5bdedd9d981af99f17f7
refs/heads/master
1,677,131,919,219
1,611,887,691,000
1,611,887,691,000
318,888,979
1
0
null
null
null
null
UTF-8
Lean
false
false
5,646
lean
import tactic import tactic.slim_check import algebra.ordered_ring universe u -- 1.3. Properties of Ordered Domains -- closest match to Birkhoff-Mac Lane "ordered domain is" #check linear_ordered_comm_ring -- Mario Carneiro -- Exercises for section 1.3 theorem ex_1_3_1_a (α: Type u) [linear_ordered_comm_ring α] (a b c : α) (h: a < b): a + c < b + c := add_lt_add_right h c theorem ex_1_3_1_b (α: Type u) [linear_ordered_comm_ring α] (a x y : α): a-x < a-y ↔ x > y := sub_lt_sub_iff_left a lemma lt0_lt_flip (α: Type*) [linear_ordered_ring α] -- Ruben Van de Velde (a x : α) (hx: a * x < 0) (ha: a < 0) : 0 < x := pos_of_mul_neg_right hx ha.le theorem ex_1_3_1_c (α: Type u) [linear_ordered_comm_ring α] (a x y : α) (h: a < 0): a*x > a* y ↔ x < y := begin split, { intro h0, have h1 := sub_lt_zero.mpr h0, apply sub_lt_zero.1, rw ← mul_sub at h1, have h2 := lt0_lt_flip α a (y-x) h1 h, rw (neg_sub x y).symm at h2, exact neg_pos.1 h2, }, { intro h0, apply sub_lt_zero.1, rw ← mul_sub, have h1 := sub_pos.2 h0, exact mul_neg_of_neg_of_pos h h1, } end theorem ex_1_3_1_d (α: Type u) [linear_ordered_comm_ring α] (a b c : α) (ha: 0 < c) (hacbc: a*c < b*c): a < b := (mul_lt_mul_right ha).mp hacbc theorem ex_1_3_1_e (α: Type u) [linear_ordered_comm_ring α] (x : α) (h: x + x + x + x = 0) : x = 0 := begin rw (add_assoc (x+x) x x) at h, exact bit0_eq_zero.mp (bit0_eq_zero.mp h), end lemma together (α: Type u) [linear_ordered_comm_ring α] (a b: α) (h: a-b = 0) : a = b := sub_eq_zero.mp h lemma factor_expr (α: Type u) [linear_ordered_comm_ring α] (a b : α) : a * (b ^ 2 * -3) + (a ^ 2 * (b * 3)) = 3*a*b*(a - b) := begin apply (together α (a * (b ^ 2 * -3) + (a ^ 2 * (b * 3))) (3*a*b*(a - b))), ring, end lemma move_cubes_left (α: Type u) [linear_ordered_comm_ring α] (a b : α) (h: 0 < a * (b ^ 2 * -3) + (a ^ 2 * (b * 3) + (-a ^ 3 + b ^ 3))) : a^3- b^3 < a * (b ^ 2 * -3) + (a ^ 2 * (b * 3)) := begin linarith, end lemma negneg (α: Type u) [linear_ordered_comm_ring α] (a b : α): a - b = - (b - a):= begin linarith, end lemma this_is_negative (α: Type u) [linear_ordered_comm_ring α] (a b : α) (h1: 0 < b - a) (hha: a > 0) (hhb: b > 0) : 3 * a * b * (a - b) < 0 := begin rw negneg α a b, have h3 := zero_lt_three, have h4 := mul_pos h3 hha, have h5 := mul_pos h4 hhb, simp, have h6 := neg_lt_zero.mpr h1, have h7 := neg_sub b a, rw h7 at h6, exact linarith.mul_neg h6 h5, exact nontrivial_of_lt 0 (b - a) h1, end lemma this_is_positive (α: Type u) [linear_ordered_comm_ring α] (a b : α) (h1: 0 < b - a) (hb: b > 0) (alt0: a < 0) : 0 < 3 * a * b * (a - b) := begin have h3 := zero_lt_three, have h4 := mul_neg_of_pos_of_neg h3 alt0, have h5 := mul_neg_of_neg_of_pos h4 hb, have h6 := neg_lt_zero.mpr h1, have h7 := mul_pos_of_neg_of_neg h5 h6, have h8 := neg_sub b a, rw h8 at h7, exact h7, exact nontrivial_of_lt 0 (b - a) h1, end lemma simp_pow (α: Type u) [linear_ordered_comm_ring α]: (0:α)^3 = 0 := tactic.ring_exp.pow_p_pf_zero rfl rfl lemma is_lt_0 (α: Type u) [linear_ordered_comm_ring α] (b : α) (hb: ¬b > 0) (hb0: ¬b = 0): b < 0 := (ne.le_iff_lt hb0).mp (not_lt.mp hb) lemma odd_pos_neg_neg (α: Type u) [linear_ordered_comm_ring α] (a : α) (h: a < 0) : a^3 < 0 := pow_bit1_neg_iff.mpr h lemma this_be_negative (α: Type u) [linear_ordered_comm_ring α] (a b : α) (h1: a < b) (halt0: a < 0) (hblt0: b < 0) : 3 * a * b * (a - b) < 0 := begin have h3 := zero_lt_three, have h4 := sub_lt_zero.mpr h1, have h5 := mul_pos_of_neg_of_neg halt0 hblt0, have h6 := mul_pos h3 h5, have h7 := sub_lt_zero.mpr h1, have h8 := linarith.mul_neg h7 h6, finish, exact nontrivial_of_lt a b h1, end theorem ex_1_3_1_f (α: Type u) [linear_ordered_comm_ring α] (a b : α) (h: a < b): a^3 < b^3 := begin have h1 := sub_pos.2 h, have h2 := pow_pos h1 3, repeat { rw pow_succ' at h2, }, simp at h2, rw sub_eq_neg_add at h2, repeat { rw right_distrib at h2, rw left_distrib at h2, }, ring_exp at h2, have h3 := move_cubes_left α a b h2, rw factor_expr α a b at h3, by_cases ha : a > 0, { by_cases hb : b > 0, { have h4 := this_is_negative α a b h1 ha hb, have h5 := lt_trans h3 h4, exact sub_lt_zero.1 h5, }, { exfalso, exact hb (lt_trans ha h), }, }, by_cases ha0: a = 0, { rw ha0 at *, simp at *, assumption, }, { have halt0 := is_lt_0 α a ha ha0, have h3alt0 := odd_pos_neg_neg α a halt0, by_cases hb : b > 0, { have h3bgt0 := pow_pos hb 3, exact lt_trans h3alt0 h3bgt0, }, by_cases hb0 : b = 0, { rw hb0, rw simp_pow, assumption, }, { have hblt0 := is_lt_0 α b hb hb0, have hf := this_be_negative α a b h halt0 hblt0, have hf1 := lt_trans h3 hf, finish, } } end -- 1.4. Well-Ordering Principle -- Exercises for section 1.4 -- 1.5. Finite Induction; Laws of Exponents -- Exercises for section 1.5 -- 1.6. Divisibility -- Exercises for section 1.6 -- 1.7. The Euclidean Algorithm -- Exercises for section 1.7 -- 1.8. Fundamental Theorem of Arithmetic -- Exercises for section 1.8 -- 1.9. Congruences -- Exercises for section 1.9 -- 1.10. The Rings ℤn -- Exercises for section 1.10 -- 1.11. Sets, Functions, and Relations -- Exercises for section 1.11 -- 1.12. Isomorphisms and Automorphisms -- Exercises for section 1.12
ed55f9e59d6e8621d2f47ccb83604e7fbe5e2563
37683ecbb27d7c2037bfd9ad7e06d662f460a005
/move_to_lib.hlean
8b1b09406745fd72e2e730a6afe5d86f70eeb81e
[ "Apache-2.0" ]
permissive
GRSEB9S/Spectral-1
b2443b09cae7aac1247b1f88c846c532ac802b8e
dd14277e0bfc6270a488eb3b9ec231484065b9d8
refs/heads/master
1,631,315,269,407
1,522,048,315,000
1,522,799,803,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
94,086
hlean
-- definitions, theorems and attributes which should be moved to files in the HoTT library import homotopy.sphere2 homotopy.cofiber homotopy.wedge hit.prop_trunc hit.set_quotient eq2 types.pointed2 algebra.graph algebra.category.functor.equivalence open eq nat int susp pointed sigma is_equiv equiv fiber algebra trunc pi group is_trunc function unit prod bool attribute pType.sigma_char sigma_pi_equiv_pi_sigma sigma.coind_unc [constructor] attribute ap1_gen [unfold 8 9 10] attribute ap010 [unfold 7] attribute tro_invo_tro [unfold 9] -- TODO: move -- TODO: homotopy_of_eq and apd10 should be the same -- TODO: there is also apd10_eq_of_homotopy in both pi and eq(?) universe variable u namespace algebra variables {A : Type} [add_ab_inf_group A] definition add_sub_cancel_middle (a b : A) : a + (b - a) = b := !add.comm ⬝ !sub_add_cancel end algebra namespace eq -- this should maybe replace whisker_left_idp and whisker_left_idp_con definition whisker_left_idp_square {A : Type} {a a' : A} {p q : a = a'} (r : p = q) : square (whisker_left idp r) r (idp_con p) (idp_con q) := begin induction r, exact hrfl end definition ap_con_idp_left {A B : Type} (f : A → B) {a a' : A} (p : a = a') : square (ap_con f idp p) idp (ap02 f (idp_con p)) (idp_con (ap f p)) := begin induction p, exact ids end definition pathover_tr_pathover_idp_of_eq {A : Type} {B : A → Type} {a a' : A} {b : B a} {b' : B a'} {p : a = a'} (q : b =[p] b') : pathover_tr p b ⬝o pathover_idp_of_eq (tr_eq_of_pathover q) = q := begin induction q; reflexivity end -- rename pathover_of_tr_eq_idp definition pathover_of_tr_eq_idp' {A : Type} {B : A → Type} {a a₂ : A} (p : a = a₂) (b : B a) : pathover_of_tr_eq idp = pathover_tr p b := by induction p; constructor definition homotopy.symm_symm {A : Type} {P : A → Type} {f g : Πx, P x} (H : f ~ g) : H⁻¹ʰᵗʸ⁻¹ʰᵗʸ = H := begin apply eq_of_homotopy, intro x, apply inv_inv end definition apd10_prepostcompose_nondep {A B C D : Type} (h : C → D) {g g' : B → C} (p : g = g') (f : A → B) (a : A) : apd10 (ap (λg a, h (g (f a))) p) a = ap h (apd10 p (f a)) := begin induction p, reflexivity end definition apd10_prepostcompose {A B : Type} {C : B → Type} {D : A → Type} (f : A → B) (h : Πa, C (f a) → D a) {g g' : Πb, C b} (p : g = g') (a : A) : apd10 (ap (λg a, h a (g (f a))) p) a = ap (h a) (apd10 p (f a)) := begin induction p, reflexivity end definition eq.rec_to {A : Type} {a₀ : A} {P : Π⦃a₁⦄, a₀ = a₁ → Type} {a₁ : A} (p₀ : a₀ = a₁) (H : P p₀) ⦃a₂ : A⦄ (p : a₀ = a₂) : P p := begin induction p₀, induction p, exact H end definition eq.rec_to2 {A : Type} {P : Π⦃a₀ a₁⦄, a₀ = a₁ → Type} {a₀ a₀' a₁' : A} (p' : a₀' = a₁') (p₀ : a₀ = a₀') (H : P p') ⦃a₁ : A⦄ (p : a₀ = a₁) : P p := begin induction p₀, induction p', induction p, exact H end definition eq.rec_right_inv {A : Type} (f : A ≃ A) {P : Π⦃a₀ a₁⦄, f a₀ = a₁ → Type} (H : Πa, P (right_inv f a)) ⦃a₀ a₁ : A⦄ (p : f a₀ = a₁) : P p := begin revert a₀ p, refine equiv_rect f⁻¹ᵉ _ _, intro a₀ p, exact eq.rec_to (right_inv f a₀) (H a₀) p, end definition eq.rec_equiv {A B : Type} {a₀ : A} (f : A ≃ B) {P : Π{a₁}, f a₀ = f a₁ → Type} (H : P (idpath (f a₀))) ⦃a₁ : A⦄ (p : f a₀ = f a₁) : P p := begin assert qr : Σ(q : a₀ = a₁), ap f q = p, { exact ⟨eq_of_fn_eq_fn f p, ap_eq_of_fn_eq_fn' f p⟩ }, cases qr with q r, apply transport P r, induction q, exact H end definition eq.rec_equiv_symm {A B : Type} {a₁ : A} (f : A ≃ B) {P : Π{a₀}, f a₀ = f a₁ → Type} (H : P (idpath (f a₁))) ⦃a₀ : A⦄ (p : f a₀ = f a₁) : P p := begin assert qr : Σ(q : a₀ = a₁), ap f q = p, { exact ⟨eq_of_fn_eq_fn f p, ap_eq_of_fn_eq_fn' f p⟩ }, cases qr with q r, apply transport P r, induction q, exact H end definition eq.rec_equiv_to_same {A B : Type} {a₀ : A} (f : A ≃ B) {P : Π{a₁}, f a₀ = f a₁ → Type} ⦃a₁' : A⦄ (p' : f a₀ = f a₁') (H : P p') ⦃a₁ : A⦄ (p : f a₀ = f a₁) : P p := begin revert a₁' p' H a₁ p, refine eq.rec_equiv f _, exact eq.rec_equiv f end definition eq.rec_equiv_to {A A' B : Type} {a₀ : A} (f : A ≃ B) (g : A' ≃ B) {P : Π{a₁}, f a₀ = g a₁ → Type} ⦃a₁' : A'⦄ (p' : f a₀ = g a₁') (H : P p') ⦃a₁ : A'⦄ (p : f a₀ = g a₁) : P p := begin assert qr : Σ(q : g⁻¹ (f a₀) = a₁), (right_inv g (f a₀))⁻¹ ⬝ ap g q = p, { exact ⟨eq_of_fn_eq_fn g (right_inv g (f a₀) ⬝ p), whisker_left _ (ap_eq_of_fn_eq_fn' g _) ⬝ !inv_con_cancel_left⟩ }, assert q'r' : Σ(q' : g⁻¹ (f a₀) = a₁'), (right_inv g (f a₀))⁻¹ ⬝ ap g q' = p', { exact ⟨eq_of_fn_eq_fn g (right_inv g (f a₀) ⬝ p'), whisker_left _ (ap_eq_of_fn_eq_fn' g _) ⬝ !inv_con_cancel_left⟩ }, induction qr with q r, induction q'r' with q' r', induction q, induction q', induction r, induction r', exact H end definition eq.rec_grading {A A' B : Type} {a : A} (f : A ≃ B) (g : A' ≃ B) {P : Π{b}, f a = b → Type} {a' : A'} (p' : f a = g a') (H : P p') ⦃b : B⦄ (p : f a = b) : P p := begin revert b p, refine equiv_rect g _ _, exact eq.rec_equiv_to f g p' H end definition eq.rec_grading_unbased {A B B' C : Type} (f : A ≃ B) (g : B ≃ C) (h : B' ≃ C) {P : Π{b c}, g b = c → Type} {a' : A} {b' : B'} (p' : g (f a') = h b') (H : P p') ⦃b : B⦄ ⦃c : C⦄ (q : f a' = b) (p : g b = c) : P p := begin induction q, exact eq.rec_grading (f ⬝e g) h p' H p end -- definition homotopy_group_homomorphism_pinv (n : ℕ) {A B : Type*} (f : A ≃* B) : -- π→g[n+1] f⁻¹ᵉ* ~ (homotopy_group_isomorphism_of_pequiv n f)⁻¹ᵍ := -- begin -- -- refine ptrunc_functor_phomotopy 0 !apn_pinv ⬝hty _, -- -- intro x, esimp, -- end -- definition natural_square_tr_eq {A B : Type} {a a' : A} {f g : A → B} -- (p : f ~ g) (q : a = a') : natural_square p q = square_of_pathover (apd p q) := -- idp lemma homotopy_group_isomorphism_of_ptrunc_pequiv {A B : Type*} (n k : ℕ) (H : n+1 ≤[ℕ] k) (f : ptrunc k A ≃* ptrunc k B) : πg[n+1] A ≃g πg[n+1] B := (ghomotopy_group_ptrunc_of_le H A)⁻¹ᵍ ⬝g homotopy_group_isomorphism_of_pequiv n f ⬝g ghomotopy_group_ptrunc_of_le H B definition fundamental_group_isomorphism {X : Type*} {G : Group} (e : Ω X ≃ G) (hom_e : Πp q, e (p ⬝ q) = e p * e q) : π₁ X ≃g G := isomorphism_of_equiv (trunc_equiv_trunc 0 e ⬝e (trunc_equiv 0 G)) begin intro p q, induction p with p, induction q with q, exact hom_e p q end definition equiv_pathover2 {A : Type} {a a' : A} (p : a = a') {B : A → Type} {C : A → Type} (f : B a ≃ C a) (g : B a' ≃ C a') (r : to_fun f =[p] to_fun g) : f =[p] g := begin fapply pathover_of_fn_pathover_fn, { intro a, apply equiv.sigma_char }, { apply sigma_pathover _ _ _ r, apply is_prop.elimo } end definition equiv_pathover_inv {A : Type} {a a' : A} (p : a = a') {B : A → Type} {C : A → Type} (f : B a ≃ C a) (g : B a' ≃ C a') (r : to_inv f =[p] to_inv g) : f =[p] g := begin /- this proof is a bit weird, but it works -/ apply equiv_pathover2, change f⁻¹ᶠ⁻¹ᶠ =[p] g⁻¹ᶠ⁻¹ᶠ, apply apo (λ(a: A) (h : C a ≃ B a), h⁻¹ᶠ), apply equiv_pathover2, exact r end definition transport_lemma {A : Type} {C : A → Type} {g₁ : A → A} {x y : A} (p : x = y) (f : Π⦃x⦄, C x → C (g₁ x)) (z : C x) : transport C (ap g₁ p)⁻¹ (f (transport C p z)) = f z := by induction p; reflexivity definition transport_lemma2 {A : Type} {C : A → Type} {g₁ : A → A} {x y : A} (p : x = y) (f : Π⦃x⦄, C x → C (g₁ x)) (z : C x) : transport C (ap g₁ p) (f z) = f (transport C p z) := by induction p; reflexivity definition eq_of_pathover_apo {A C : Type} {B : A → Type} {a a' : A} {b : B a} {b' : B a'} {p : a = a'} (g : Πa, B a → C) (q : b =[p] b') : eq_of_pathover (apo g q) = apd011 g p q := by induction q; reflexivity definition apd02 [unfold 8] {A : Type} {B : A → Type} (f : Πa, B a) {a a' : A} {p q : a = a'} (r : p = q) : change_path r (apd f p) = apd f q := by induction r; reflexivity definition pathover_ap_cono {A A' : Type} {a₁ a₂ a₃ : A} {p₁ : a₁ = a₂} {p₂ : a₂ = a₃} (B' : A' → Type) (f : A → A') {b₁ : B' (f a₁)} {b₂ : B' (f a₂)} {b₃ : B' (f a₃)} (q₁ : b₁ =[p₁] b₂) (q₂ : b₂ =[p₂] b₃) : pathover_ap B' f (q₁ ⬝o q₂) = change_path !ap_con⁻¹ (pathover_ap B' f q₁ ⬝o pathover_ap B' f q₂) := by induction q₁; induction q₂; reflexivity definition concato_eq_eq {A : Type} {B : A → Type} {a₁ a₂ : A} {p₁ : a₁ = a₂} {b₁ : B a₁} {b₂ b₂' : B a₂} (r : b₁ =[p₁] b₂) (q : b₂ = b₂') : r ⬝op q = r ⬝o pathover_idp_of_eq q := by induction q; reflexivity definition ap_apd0111 {A₁ A₂ A₃ : Type} {B : A₁ → Type} {C : Π⦃a⦄, B a → Type} {a a₂ : A₁} {b : B a} {b₂ : B a₂} {c : C b} {c₂ : C b₂} (g : A₂ → A₃) (f : Πa b, C b → A₂) (Ha : a = a₂) (Hb : b =[Ha] b₂) (Hc : c =[apd011 C Ha Hb] c₂) : ap g (apd0111 f Ha Hb Hc) = apd0111 (λa b c, (g (f a b c))) Ha Hb Hc := by induction Hb; induction Hc using idp_rec_on; reflexivity section squareover variables {A A' : Type} {B : A → Type} {a a' a'' a₀₀ a₂₀ a₄₀ a₀₂ a₂₂ a₂₄ a₀₄ a₄₂ a₄₄ : A} /-a₀₀-/ {p₁₀ : a₀₀ = a₂₀} /-a₂₀-/ {p₃₀ : a₂₀ = a₄₀} /-a₄₀-/ {p₀₁ : a₀₀ = a₀₂} /-s₁₁-/ {p₂₁ : a₂₀ = a₂₂} /-s₃₁-/ {p₄₁ : a₄₀ = a₄₂} /-a₀₂-/ {p₁₂ : a₀₂ = a₂₂} /-a₂₂-/ {p₃₂ : a₂₂ = a₄₂} /-a₄₂-/ {p₀₃ : a₀₂ = a₀₄} /-s₁₃-/ {p₂₃ : a₂₂ = a₂₄} /-s₃₃-/ {p₄₃ : a₄₂ = a₄₄} /-a₀₄-/ {p₁₄ : a₀₄ = a₂₄} /-a₂₄-/ {p₃₄ : a₂₄ = a₄₄} /-a₄₄-/ {s₁₁ : square p₁₀ p₁₂ p₀₁ p₂₁} {s₃₁ : square p₃₀ p₃₂ p₂₁ p₄₁} {s₁₃ : square p₁₂ p₁₄ p₀₃ p₂₃} {s₃₃ : square p₃₂ p₃₄ p₂₃ p₄₃} {b : B a} {b₀₀ : B a₀₀} {b₂₀ : B a₂₀} {b₄₀ : B a₄₀} {b₀₂ : B a₀₂} {b₂₂ : B a₂₂} {b₄₂ : B a₄₂} {b₀₄ : B a₀₄} {b₂₄ : B a₂₄} {b₄₄ : B a₄₄} /-b₀₀-/ {q₁₀ : b₀₀ =[p₁₀] b₂₀} /-b₂₀-/ {q₃₀ : b₂₀ =[p₃₀] b₄₀} /-b₄₀-/ /-b₀₂-/ {q₁₂ : b₀₂ =[p₁₂] b₂₂} /-b₂₂-/ {q₃₂ : b₂₂ =[p₃₂] b₄₂} /-b₄₂-/ /-b₀₄-/ {q₁₄ : b₀₄ =[p₁₄] b₂₄} /-b₂₄-/ {q₃₄ : b₂₄ =[p₃₄] b₄₄} /-b₄₄-/ {q₀₁ : b₀₀ =[p₀₁] b₀₂} /-t₁₁-/ {q₂₁ : b₂₀ =[p₂₁] b₂₂} /-t₃₁-/ {q₄₁ : b₄₀ =[p₄₁] b₄₂} {q₀₃ : b₀₂ =[p₀₃] b₀₄} /-t₁₃-/ {q₂₃ : b₂₂ =[p₂₃] b₂₄} /-t₃₃-/ {q₄₃ : b₄₂ =[p₄₃] b₄₄} definition move_right_of_top_over {p : a₀₀ = a} {p' : a = a₂₀} {s : square p p₁₂ p₀₁ (p' ⬝ p₂₁)} {q : b₀₀ =[p] b} {q' : b =[p'] b₂₀} (t : squareover B (move_top_of_right s) (q ⬝o q') q₁₂ q₀₁ q₂₁) : squareover B s q q₁₂ q₀₁ (q' ⬝o q₂₁) := begin induction q', induction q, induction q₂₁, exact t end /- TODO: replace the version in the library by this -/ definition hconcato_pathover' {p : a₂₀ = a₂₂} {sp : p = p₂₁} {s : square p₁₀ p₁₂ p₀₁ p} {q : b₂₀ =[p] b₂₂} (t₁₁ : squareover B (s ⬝hp sp) q₁₀ q₁₂ q₀₁ q₂₁) (r : change_path sp q = q₂₁) : squareover B s q₁₀ q₁₂ q₀₁ q := by induction sp; induction r; exact t₁₁ variables (s₁₁ q₀₁ q₁₀ q₂₁ q₁₂) definition squareover_fill_t : Σ (q : b₀₀ =[p₁₀] b₂₀), squareover B s₁₁ q q₁₂ q₀₁ q₂₁ := begin induction s₁₁, induction q₀₁ using idp_rec_on, induction q₂₁ using idp_rec_on, induction q₁₂ using idp_rec_on, exact ⟨idpo, idso⟩ end definition squareover_fill_b : Σ (q : b₀₂ =[p₁₂] b₂₂), squareover B s₁₁ q₁₀ q q₀₁ q₂₁ := begin induction s₁₁, induction q₀₁ using idp_rec_on, induction q₂₁ using idp_rec_on, induction q₁₀ using idp_rec_on, exact ⟨idpo, idso⟩ end definition squareover_fill_l : Σ (q : b₀₀ =[p₀₁] b₀₂), squareover B s₁₁ q₁₀ q₁₂ q q₂₁ := begin induction s₁₁, induction q₁₀ using idp_rec_on, induction q₂₁ using idp_rec_on, induction q₁₂ using idp_rec_on, exact ⟨idpo, idso⟩ end definition squareover_fill_r : Σ (q : b₂₀ =[p₂₁] b₂₂) , squareover B s₁₁ q₁₀ q₁₂ q₀₁ q := begin induction s₁₁, induction q₀₁ using idp_rec_on, induction q₁₀ using idp_rec_on, induction q₁₂ using idp_rec_on, exact ⟨idpo, idso⟩ end end squareover /- move this to types.eq, and replace the proof there -/ section parameters {A : Type} (a₀ : A) (code : A → Type) (H : is_contr (Σa, code a)) (c₀ : code a₀) include H c₀ protected definition encode2 {a : A} (q : a₀ = a) : code a := transport code q c₀ protected definition decode2' {a : A} (c : code a) : a₀ = a := have ⟨a₀, c₀⟩ = ⟨a, c⟩ :> Σa, code a, from !is_prop.elim, this..1 protected definition decode2 {a : A} (c : code a) : a₀ = a := (decode2' c₀)⁻¹ ⬝ decode2' c open sigma.ops definition total_space_method2 (a : A) : (a₀ = a) ≃ code a := begin fapply equiv.MK, { exact encode2 }, { exact decode2 }, { intro c, unfold [encode2, decode2, decode2'], rewrite [is_prop_elim_self, ▸*, idp_con], apply tr_eq_of_pathover, apply eq_pr2 }, { intro q, induction q, esimp, apply con.left_inv, }, end end definition total_space_method2_refl {A : Type} (a₀ : A) (code : A → Type) (H : is_contr (Σa, code a)) (c₀ : code a₀) : total_space_method2 a₀ code H c₀ a₀ idp = c₀ := begin reflexivity end section hsquare variables {A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ A₀₄ A₂₄ A₄₄ : Type} {f₁₀ : A₀₀ → A₂₀} {f₃₀ : A₂₀ → A₄₀} {f₀₁ : A₀₀ → A₀₂} {f₂₁ : A₂₀ → A₂₂} {f₄₁ : A₄₀ → A₄₂} {f₁₂ : A₀₂ → A₂₂} {f₃₂ : A₂₂ → A₄₂} {f₀₃ : A₀₂ → A₀₄} {f₂₃ : A₂₂ → A₂₄} {f₄₃ : A₄₂ → A₄₄} {f₁₄ : A₀₄ → A₂₄} {f₃₄ : A₂₄ → A₄₄} definition trunc_functor_hsquare (n : ℕ₋₂) (h : hsquare f₁₀ f₁₂ f₀₁ f₂₁) : hsquare (trunc_functor n f₁₀) (trunc_functor n f₁₂) (trunc_functor n f₀₁) (trunc_functor n f₂₁) := λa, !trunc_functor_compose⁻¹ ⬝ trunc_functor_homotopy n h a ⬝ !trunc_functor_compose attribute hhconcat hvconcat [unfold_full] definition rfl_hhconcat (q : hsquare f₃₀ f₃₂ f₂₁ f₄₁) : homotopy.rfl ⬝htyh q ~ q := homotopy.rfl definition hhconcat_rfl (q : hsquare f₃₀ f₃₂ f₂₁ f₄₁) : q ⬝htyh homotopy.rfl ~ q := λx, !idp_con ⬝ ap_id (q x) definition rfl_hvconcat (q : hsquare f₃₀ f₃₂ f₂₁ f₄₁) : homotopy.rfl ⬝htyv q ~ q := λx, !idp_con definition hvconcat_rfl (q : hsquare f₃₀ f₃₂ f₂₁ f₄₁) : q ⬝htyv homotopy.rfl ~ q := λx, !ap_id end hsquare definition homotopy_group_succ_in_natural (n : ℕ) {A B : Type*} (f : A →* B) : hsquare (homotopy_group_succ_in A n) (homotopy_group_succ_in B n) (π→[n+1] f) (π→[n] (Ω→ f)) := trunc_functor_hsquare _ (loopn_succ_in_natural n f)⁻¹* definition homotopy2.refl {A} {B : A → Type} {C : Π⦃a⦄, B a → Type} (f : Πa (b : B a), C b) : f ~2 f := λa b, idp definition homotopy2.rfl [refl] {A} {B : A → Type} {C : Π⦃a⦄, B a → Type} {f : Πa (b : B a), C b} : f ~2 f := λa b, idp definition homotopy3.refl {A} {B : A → Type} {C : Πa, B a → Type} {D : Π⦃a⦄ ⦃b : B a⦄, C a b → Type} (f : Πa b (c : C a b), D c) : f ~3 f := λa b c, idp definition homotopy3.rfl {A} {B : A → Type} {C : Πa, B a → Type} {D : Π⦃a⦄ ⦃b : B a⦄, C a b → Type} {f : Πa b (c : C a b), D c} : f ~3 f := λa b c, idp definition eq_tr_of_pathover_con_tr_eq_of_pathover {A : Type} {B : A → Type} {a₁ a₂ : A} (p : a₁ = a₂) {b₁ : B a₁} {b₂ : B a₂} (q : b₁ =[p] b₂) : eq_tr_of_pathover q ⬝ tr_eq_of_pathover q⁻¹ᵒ = idp := by induction q; reflexivity end eq open eq namespace nat protected definition rec_down (P : ℕ → Type) (s : ℕ) (H0 : P s) (Hs : Πn, P (n+1) → P n) : P 0 := begin induction s with s IH, { exact H0 }, { exact IH (Hs s H0) } end definition rec_down_le (P : ℕ → Type) (s : ℕ) (H0 : Πn, s ≤ n → P n) (Hs : Πn, P (n+1) → P n) : Πn, P n := begin induction s with s IH: intro n, { exact H0 n (zero_le n) }, { apply IH, intro n' H, induction H with n' H IH2, apply Hs, exact H0 _ !le.refl, exact H0 _ (succ_le_succ H) } end definition rec_down_le_univ {P : ℕ → Type} {s : ℕ} {H0 : Π⦃n⦄, s ≤ n → P n} {Hs : Π⦃n⦄, P (n+1) → P n} (Q : Π⦃n⦄, P n → P (n + 1) → Type) (HQ0 : Πn (H : s ≤ n), Q (H0 H) (H0 (le.step H))) (HQs : Πn (p : P (n+1)), Q (Hs p) p) : Πn, Q (rec_down_le P s H0 Hs n) (rec_down_le P s H0 Hs (n + 1)) := begin induction s with s IH: intro n, { apply HQ0 }, { apply IH, intro n' H, induction H with n' H IH2, { esimp, apply HQs }, { apply HQ0 }} end definition rec_down_le_beta_ge (P : ℕ → Type) (s : ℕ) (H0 : Πn, s ≤ n → P n) (Hs : Πn, P (n+1) → P n) (n : ℕ) (Hn : s ≤ n) : rec_down_le P s H0 Hs n = H0 n Hn := begin revert n Hn, induction s with s IH: intro n Hn, { exact ap (H0 n) !is_prop.elim }, { have Hn' : s ≤ n, from le.trans !self_le_succ Hn, refine IH _ _ Hn' ⬝ _, induction Hn' with n Hn' IH', { exfalso, exact not_succ_le_self Hn }, { exact ap (H0 (succ n)) !is_prop.elim }} end definition rec_down_le_beta_lt (P : ℕ → Type) (s : ℕ) (H0 : Πn, s ≤ n → P n) (Hs : Πn, P (n+1) → P n) (n : ℕ) (Hn : n < s) : rec_down_le P s H0 Hs n = Hs n (rec_down_le P s H0 Hs (n+1)) := begin revert n Hn, induction s with s IH: intro n Hn, { exfalso, exact not_succ_le_zero n Hn }, { have Hn' : n ≤ s, from le_of_succ_le_succ Hn, --esimp [rec_down_le], exact sorry -- induction Hn' with s Hn IH, -- { }, -- { } } end /- this generalizes iterate_commute -/ definition iterate_hsquare {A B : Type} {f : A → A} {g : B → B} (h : A → B) (p : hsquare f g h h) (n : ℕ) : hsquare (f^[n]) (g^[n]) h h := begin induction n with n q, exact homotopy.rfl, exact q ⬝htyh p end definition iterate_equiv2 {A : Type} {C : A → Type} (f : A → A) (h : Πa, C a ≃ C (f a)) (k : ℕ) (a : A) : C a ≃ C (f^[k] a) := begin induction k with k IH, reflexivity, exact IH ⬝e h (f^[k] a) end /- replace proof of le_of_succ_le by this -/ definition le_step_left {n m : ℕ} (H : succ n ≤ m) : n ≤ m := by induction H with H m H'; exact le_succ n; exact le.step H' /- TODO: make proof of le_succ_of_le simpler -/ definition nat.add_le_add_left2 {n m : ℕ} (H : n ≤ m) (k : ℕ) : k + n ≤ k + m := by induction H with m H H₂; reflexivity; exact le.step H₂ end nat namespace trunc_index open is_conn nat trunc is_trunc lemma minus_two_add_plus_two (n : ℕ₋₂) : -2+2+n = n := by induction n with n p; reflexivity; exact ap succ p protected definition of_nat_monotone {n k : ℕ} : n ≤ k → of_nat n ≤ of_nat k := begin intro H, induction H with k H K, { apply le.tr_refl }, { apply le.step K } end lemma add_plus_two_comm (n k : ℕ₋₂) : n +2+ k = k +2+ n := begin induction n with n IH, { exact minus_two_add_plus_two k }, { exact !succ_add_plus_two ⬝ ap succ IH} end lemma sub_one_add_plus_two_sub_one (n m : ℕ) : n.-1 +2+ m.-1 = of_nat (n + m) := begin induction m with m IH, { reflexivity }, { exact ap succ IH } end end trunc_index namespace int private definition maxm2_le.lemma₁ {n k : ℕ} : n+(1:int) + -[1+ k] ≤ n := le.intro ( calc n + 1 + -[1+ k] + k = n + 1 + (-(k + 1)) + k : by reflexivity ... = n + 1 + (- 1 - k) + k : by krewrite (neg_add_rev k 1) ... = n + 1 + (- 1 - k + k) : add.assoc ... = n + 1 + (- 1 + -k + k) : by reflexivity ... = n + 1 + (- 1 + (-k + k)) : add.assoc ... = n + 1 + (- 1 + 0) : add.left_inv ... = n + (1 + (- 1 + 0)) : add.assoc ... = n : int.add_zero) private definition maxm2_le.lemma₂ {n : ℕ} {k : ℤ} : -[1+ n] + 1 + k ≤ k := le.intro ( calc -[1+ n] + 1 + k + n = - (n + 1) + 1 + k + n : by reflexivity ... = -n - 1 + 1 + k + n : by rewrite (neg_add n 1) ... = -n + (- 1 + 1) + k + n : by krewrite (int.add_assoc (-n) (- 1) 1) ... = -n + 0 + k + n : add.left_inv 1 ... = -n + k + n : int.add_zero ... = k + -n + n : int.add_comm ... = k + (-n + n) : int.add_assoc ... = k + 0 : add.left_inv n ... = k : int.add_zero) open trunc_index /- The function from integers to truncation indices which sends positive numbers to themselves, and negative numbers to negative 2. In particular -1 is sent to -2, but since we only work with pointed types, that doesn't matter for us -/ definition maxm2 [unfold 1] : ℤ → ℕ₋₂ := λ n, int.cases_on n trunc_index.of_nat (λk, -2) -- we also need the max -1 - function definition maxm1 [unfold 1] : ℤ → ℕ₋₂ := λ n, int.cases_on n trunc_index.of_nat (λk, -1) definition maxm2_le_maxm1 (n : ℤ) : maxm2 n ≤ maxm1 n := begin induction n with n n, { exact le.tr_refl n }, { exact minus_two_le -1 } end -- the is maxm1 minus 1 definition maxm1m1 [unfold 1] : ℤ → ℕ₋₂ := λ n, int.cases_on n (λ k, k.-1) (λ k, -2) definition maxm1_eq_succ (n : ℤ) : maxm1 n = (maxm1m1 n).+1 := begin induction n with n n, { reflexivity }, { reflexivity } end definition maxm2_le_maxm0 (n : ℤ) : maxm2 n ≤ max0 n := begin induction n with n n, { exact le.tr_refl n }, { exact minus_two_le 0 } end definition max0_le_of_le {n : ℤ} {m : ℕ} (H : n ≤ of_nat m) : nat.le (max0 n) m := begin induction n with n n, { exact le_of_of_nat_le_of_nat H }, { exact nat.zero_le m } end definition not_neg_succ_le_of_nat {n m : ℕ} : ¬m ≤ -[1+n] := by cases m: exact id definition maxm2_monotone {n m : ℤ} (H : n ≤ m) : maxm2 n ≤ maxm2 m := begin induction n with n n, { induction m with m m, { apply of_nat_le_of_nat, exact le_of_of_nat_le_of_nat H }, { exfalso, exact not_neg_succ_le_of_nat H }}, { apply minus_two_le } end definition sub_nat_le (n : ℤ) (m : ℕ) : n - m ≤ n := le.intro !sub_add_cancel definition sub_nat_lt (n : ℤ) (m : ℕ) : n - m < n + 1 := add_le_add_right (sub_nat_le n m) 1 definition sub_one_le (n : ℤ) : n - 1 ≤ n := sub_nat_le n 1 definition le_add_nat (n : ℤ) (m : ℕ) : n ≤ n + m := le.intro rfl definition le_add_one (n : ℤ) : n ≤ n + 1:= le_add_nat n 1 open trunc_index definition maxm2_le (n k : ℤ) : maxm2 (n+1+k) ≤ (maxm1m1 n).+1+2+(maxm1m1 k) := begin rewrite [-(maxm1_eq_succ n)], induction n with n n, { induction k with k k, { induction k with k IH, { apply le.tr_refl }, { exact succ_le_succ IH } }, { exact trunc_index.le_trans (maxm2_monotone maxm2_le.lemma₁) (maxm2_le_maxm1 n) } }, { krewrite (add_plus_two_comm -1 (maxm1m1 k)), rewrite [-(maxm1_eq_succ k)], exact trunc_index.le_trans (maxm2_monotone maxm2_le.lemma₂) (maxm2_le_maxm1 k) } end end int open int namespace pmap /- rename: pmap_eta in namespace pointed -/ definition eta {A B : Type*} (f : A →* B) : pmap.mk f (respect_pt f) = f := begin induction f, reflexivity end end pmap namespace lift definition is_trunc_plift [instance] [priority 1450] (A : Type*) (n : ℕ₋₂) [H : is_trunc n A] : is_trunc n (plift A) := is_trunc_lift A n definition lift_functor2 {A B C : Type} (f : A → B → C) (x : lift A) (y : lift B) : lift C := up (f (down x) (down y)) end lift -- definition ppi_eq_equiv_internal : (k = l) ≃ (k ~* l) := -- calc (k = l) ≃ ppi.sigma_char P p₀ k = ppi.sigma_char P p₀ l -- : eq_equiv_fn_eq (ppi.sigma_char P p₀) k l -- ... ≃ Σ(p : k = l), -- pathover (λh, h pt = p₀) (respect_pt k) p (respect_pt l) -- : sigma_eq_equiv _ _ -- ... ≃ Σ(p : k = l), -- respect_pt k = ap (λh, h pt) p ⬝ respect_pt l -- : sigma_equiv_sigma_right -- (λp, eq_pathover_equiv_Fl p (respect_pt k) (respect_pt l)) -- ... ≃ Σ(p : k = l), -- respect_pt k = apd10 p pt ⬝ respect_pt l -- : sigma_equiv_sigma_right -- (λp, equiv_eq_closed_right _ (whisker_right _ (ap_eq_apd10 p _))) -- ... ≃ Σ(p : k ~ l), respect_pt k = p pt ⬝ respect_pt l -- : sigma_equiv_sigma_left' eq_equiv_homotopy -- ... ≃ Σ(p : k ~ l), p pt ⬝ respect_pt l = respect_pt k -- : sigma_equiv_sigma_right (λp, eq_equiv_eq_symm _ _) -- ... ≃ (k ~* l) : phomotopy.sigma_char k l namespace pointed /- move to pointed -/ open sigma.ops definition pType.sigma_char' [constructor] : pType.{u} ≃ Σ(X : Type.{u}), X := begin fapply equiv.MK, { intro X, exact ⟨X, pt⟩ }, { intro X, exact pointed.MK X.1 X.2 }, { intro x, induction x with X x, reflexivity }, { intro x, induction x with X x, reflexivity }, end definition ap_equiv_eq {X Y : Type} {e e' : X ≃ Y} (p : e ~ e') (x : X) : ap (λ(e : X ≃ Y), e x) (equiv_eq p) = p x := begin cases e with e He, cases e' with e' He', esimp at *, esimp [equiv_eq], refine homotopy.rec_on' p _, intro q, induction q, esimp [equiv_eq', equiv_mk_eq], assert H : He = He', apply is_prop.elim, induction H, rewrite [is_prop_elimo_self] end definition pequiv.sigma_char_equiv [constructor] (X Y : Type*) : (X ≃* Y) ≃ Σ(e : X ≃ Y), e pt = pt := begin fapply equiv.MK, { intro e, exact ⟨equiv_of_pequiv e, respect_pt e⟩ }, { intro e, exact pequiv_of_equiv e.1 e.2 }, { intro e, induction e with e p, fapply sigma_eq, apply equiv_eq, reflexivity, esimp, apply eq_pathover_constant_right, esimp, refine _ ⬝ph vrfl, apply ap_equiv_eq }, { intro e, apply pequiv_eq, fapply phomotopy.mk, intro x, reflexivity, refine !idp_con ⬝ _, reflexivity }, end definition pequiv.sigma_char_pmap [constructor] (X Y : Type*) : (X ≃* Y) ≃ Σ(f : X →* Y), is_equiv f := begin fapply equiv.MK, { intro e, exact ⟨ pequiv.to_pmap e , pequiv.to_is_equiv e ⟩ }, { intro w, exact pequiv_of_pmap w.1 w.2 }, { intro w, induction w with f p, fapply sigma_eq, { reflexivity }, { apply is_prop.elimo } }, { intro e, apply pequiv_eq, fapply phomotopy.mk, { intro x, reflexivity }, { refine !idp_con ⬝ _, reflexivity } } end definition pType_eq_equiv (X Y : Type*) : (X = Y) ≃ (X ≃* Y) := begin refine eq_equiv_fn_eq pType.sigma_char' X Y ⬝e !sigma_eq_equiv ⬝e _, esimp, transitivity Σ(p : X = Y), cast p pt = pt, apply sigma_equiv_sigma_right, intro p, apply pathover_equiv_tr_eq, transitivity Σ(e : X ≃ Y), e pt = pt, refine sigma_equiv_sigma (eq_equiv_equiv X Y) (λp, equiv.rfl), exact (pequiv.sigma_char_equiv X Y)⁻¹ᵉ end end pointed open pointed namespace trunc open trunc_index sigma.ops definition ptrunctype.sigma_char [constructor] (n : ℕ₋₂) : n-Type* ≃ Σ(X : Type*), is_trunc n X := equiv.MK (λX, ⟨ptrunctype.to_pType X, _⟩) (λX, ptrunctype.mk (carrier X.1) X.2 pt) begin intro X, induction X with X HX, induction X, reflexivity end begin intro X, induction X, reflexivity end definition is_embedding_ptrunctype_to_pType (n : ℕ₋₂) : is_embedding (@ptrunctype.to_pType n) := begin intro X Y, fapply is_equiv_of_equiv_of_homotopy, { exact eq_equiv_fn_eq (ptrunctype.sigma_char n) _ _ ⬝e subtype_eq_equiv _ _ }, intro p, induction p, reflexivity end definition ptrunctype_eq_equiv {n : ℕ₋₂} (X Y : n-Type*) : (X = Y) ≃ (X ≃* Y) := equiv.mk _ (is_embedding_ptrunctype_to_pType n X Y) ⬝e pType_eq_equiv X Y /- replace trunc_trunc_equiv_left by this -/ definition trunc_trunc_equiv_left' [constructor] (A : Type) {n m : ℕ₋₂} (H : n ≤ m) : trunc n (trunc m A) ≃ trunc n A := begin note H2 := is_trunc_of_le (trunc n A) H, fapply equiv.MK, { intro x, induction x with x, induction x with x, exact tr x }, { exact trunc_functor n tr }, { intro x, induction x with x, reflexivity}, { intro x, induction x with x, induction x with x, reflexivity} end definition is_equiv_ptrunc_functor_ptr [constructor] (A : Type*) {n m : ℕ₋₂} (H : n ≤ m) : is_equiv (ptrunc_functor n (ptr m A)) := to_is_equiv (trunc_trunc_equiv_left' A H)⁻¹ᵉ definition Prop_eq {P Q : Prop} (H : P ↔ Q) : P = Q := tua (equiv_of_is_prop (iff.mp H) (iff.mpr H)) definition trunc_index_equiv_nat [constructor] : ℕ₋₂ ≃ ℕ := equiv.MK add_two sub_two add_two_sub_two sub_two_add_two definition is_set_trunc_index [instance] : is_set ℕ₋₂ := is_trunc_equiv_closed_rev 0 trunc_index_equiv_nat definition is_contr_ptrunc_minus_one (A : Type*) : is_contr (ptrunc -1 A) := is_contr_of_inhabited_prop pt -- TODO: redefine loopn_ptrunc_pequiv definition apn_ptrunc_functor (n : ℕ₋₂) (k : ℕ) {A B : Type*} (f : A →* B) : Ω→[k] (ptrunc_functor (n+k) f) ∘* (loopn_ptrunc_pequiv n k A)⁻¹ᵉ* ~* (loopn_ptrunc_pequiv n k B)⁻¹ᵉ* ∘* ptrunc_functor n (Ω→[k] f) := begin revert n, induction k with k IH: intro n, { reflexivity }, { exact sorry } end definition ptrunc_pequiv_natural [constructor] (n : ℕ₋₂) {A B : Type*} (f : A →* B) [is_trunc n A] [is_trunc n B] : f ∘* ptrunc_pequiv n A ~* ptrunc_pequiv n B ∘* ptrunc_functor n f := begin fapply phomotopy.mk, { intro a, induction a with a, reflexivity }, { refine !idp_con ⬝ _ ⬝ !idp_con⁻¹, refine !ap_compose'⁻¹ ⬝ _, apply ap_id } end definition ptr_natural [constructor] (n : ℕ₋₂) {A B : Type*} (f : A →* B) : ptrunc_functor n f ∘* ptr n A ~* ptr n B ∘* f := begin fapply phomotopy.mk, { intro a, reflexivity }, { reflexivity } end definition ptrunc_elim_pcompose (n : ℕ₋₂) {A B C : Type*} (g : B →* C) (f : A →* B) [is_trunc n B] [is_trunc n C] : ptrunc.elim n (g ∘* f) ~* g ∘* ptrunc.elim n f := begin fapply phomotopy.mk, { intro a, induction a with a, reflexivity }, { apply idp_con } end definition ptrunc_elim_ptr_phomotopy_pid (n : ℕ₋₂) (A : Type*): ptrunc.elim n (ptr n A) ~* pid (ptrunc n A) := begin fapply phomotopy.mk, { intro a, induction a with a, reflexivity }, { apply idp_con } end definition is_trunc_ptrunc_of_is_trunc [instance] [priority 500] (A : Type*) (n m : ℕ₋₂) [H : is_trunc n A] : is_trunc n (ptrunc m A) := is_trunc_trunc_of_is_trunc A n m definition ptrunc_pequiv_ptrunc_of_is_trunc {n m k : ℕ₋₂} {A : Type*} (H1 : n ≤ m) (H2 : n ≤ k) (H : is_trunc n A) : ptrunc m A ≃* ptrunc k A := have is_trunc m A, from is_trunc_of_le A H1, have is_trunc k A, from is_trunc_of_le A H2, pequiv.MK (ptrunc.elim _ (ptr k A)) (ptrunc.elim _ (ptr m A)) abstract begin refine !ptrunc_elim_pcompose⁻¹* ⬝* _, exact ptrunc_elim_phomotopy _ !ptrunc_elim_ptr ⬝* !ptrunc_elim_ptr_phomotopy_pid, end end abstract begin refine !ptrunc_elim_pcompose⁻¹* ⬝* _, exact ptrunc_elim_phomotopy _ !ptrunc_elim_ptr ⬝* !ptrunc_elim_ptr_phomotopy_pid, end end definition ptrunc_change_index {k l : ℕ₋₂} (p : k = l) (X : Type*) : ptrunc k X ≃* ptrunc l X := pequiv_ap (λ n, ptrunc n X) p definition ptrunc_functor_le {k l : ℕ₋₂} (p : l ≤ k) (X : Type*) : ptrunc k X →* ptrunc l X := have is_trunc k (ptrunc l X), from is_trunc_of_le _ p, ptrunc.elim _ (ptr l X) definition trunc_index.pred [unfold 1] (n : ℕ₋₂) : ℕ₋₂ := begin cases n with n, exact -2, exact n end /- A more general version of ptrunc_elim_phomotopy, where the proofs of truncatedness might be different -/ definition ptrunc_elim_phomotopy2 [constructor] (k : ℕ₋₂) {A B : Type*} {f g : A →* B} (H₁ : is_trunc k B) (H₂ : is_trunc k B) (p : f ~* g) : @ptrunc.elim k A B H₁ f ~* @ptrunc.elim k A B H₂ g := begin fapply phomotopy.mk, { intro x, induction x with a, exact p a }, { exact to_homotopy_pt p } end definition pmap_ptrunc_equiv [constructor] (n : ℕ₋₂) (A B : Type*) [H : is_trunc n B] : (ptrunc n A →* B) ≃ (A →* B) := begin fapply equiv.MK, { intro g, exact g ∘* ptr n A }, { exact ptrunc.elim n }, { intro f, apply eq_of_phomotopy, apply ptrunc_elim_ptr }, { intro g, apply eq_of_phomotopy, exact ptrunc_elim_pcompose n g (ptr n A) ⬝* pwhisker_left g (ptrunc_elim_ptr_phomotopy_pid n A) ⬝* pcompose_pid g } end definition pmap_ptrunc_pequiv [constructor] (n : ℕ₋₂) (A B : Type*) [H : is_trunc n B] : ppmap (ptrunc n A) B ≃* ppmap A B := pequiv_of_equiv (pmap_ptrunc_equiv n A B) (eq_of_phomotopy (pconst_pcompose (ptr n A))) definition loopn_ptrunc_pequiv_nat (n : ℕ) (k : ℕ) (A : Type*) : Ω[k] (ptrunc (n+k) A) ≃* ptrunc n (Ω[k] A) := loopn_pequiv_loopn k (ptrunc_change_index (of_nat_add_of_nat n k)⁻¹ A) ⬝e* loopn_ptrunc_pequiv n k A end trunc open trunc namespace is_trunc open trunc_index is_conn lemma is_trunc_loopn_nat (m n : ℕ) (A : Type*) [H : is_trunc (n + m) A] : is_trunc n (Ω[m] A) := @is_trunc_loopn n m A (transport (λk, is_trunc k _) (of_nat_add_of_nat n m)⁻¹ H) lemma is_trunc_loop_nat (n : ℕ) (A : Type*) [H : is_trunc (n + 1) A] : is_trunc n (Ω A) := is_trunc_loop A n definition is_trunc_of_eq {n m : ℕ₋₂} (p : n = m) {A : Type} (H : is_trunc n A) : is_trunc m A := transport (λk, is_trunc k A) p H definition is_trunc_succ_succ_of_is_trunc_loop (n : ℕ₋₂) (A : Type*) (H : is_trunc (n.+1) (Ω A)) (H2 : is_conn 0 A) : is_trunc (n.+2) A := begin apply is_trunc_succ_of_is_trunc_loop, apply minus_one_le_succ, refine is_conn.elim -1 _ _, exact H end lemma is_trunc_of_is_trunc_loopn (m n : ℕ) (A : Type*) (H : is_trunc n (Ω[m] A)) (H2 : is_conn (m.-1) A) : is_trunc (m + n) A := begin revert A H H2; induction m with m IH: intro A H H2, { rewrite [nat.zero_add], exact H }, rewrite [succ_add], apply is_trunc_succ_succ_of_is_trunc_loop, { apply IH, { apply is_trunc_equiv_closed _ !loopn_succ_in }, apply is_conn_loop }, exact is_conn_of_le _ (zero_le_of_nat m) end lemma is_trunc_of_is_set_loopn (m : ℕ) (A : Type*) (H : is_set (Ω[m] A)) (H2 : is_conn (m.-1) A) : is_trunc m A := is_trunc_of_is_trunc_loopn m 0 A H H2 end is_trunc namespace sigma open sigma.ops definition sigma_functor2 [constructor] {A₁ A₂ A₃ : Type} {B₁ : A₁ → Type} {B₂ : A₂ → Type} {B₃ : A₃ → Type} (f : A₁ → A₂ → A₃) (g : Π⦃a₁ a₂⦄, B₁ a₁ → B₂ a₂ → B₃ (f a₁ a₂)) (x₁ : Σa₁, B₁ a₁) (x₂ : Σa₂, B₂ a₂) : Σa₃, B₃ a₃ := ⟨f x₁.1 x₂.1, g x₁.2 x₂.2⟩ definition eq.rec_sigma {A : Type} {B : A → Type} {a : A} {b : B a} (P : Π⦃a'⦄ {b' : B a'}, ⟨a, b⟩ = ⟨a', b'⟩ → Type) (IH : P idp) ⦃a' : A⦄ {b' : B a'} (p : ⟨a, b⟩ = ⟨a', b'⟩) : P p := begin apply transport (λp, P p) (to_left_inv !sigma_eq_equiv p), generalize !sigma_eq_equiv p, esimp, intro q, induction q with q₁ q₂, induction q₂, exact IH end definition ap_dpair_eq_dpair_pr {A A' : Type} {B : A → Type} {a a' : A} {b : B a} {b' : B a'} (f : Πa, B a → A') (p : a = a') (q : b =[p] b') : ap (λx, f x.1 x.2) (dpair_eq_dpair p q) = apd011 f p q := by induction q; reflexivity definition sigma_eq_equiv_of_is_prop_right [constructor] {A : Type} {B : A → Type} (u v : Σa, B a) [H : Π a, is_prop (B a)] : u = v ≃ u.1 = v.1 := !sigma_eq_equiv ⬝e !sigma_equiv_of_is_contr_right definition ap_sigma_pr1 {A B : Type} {C : B → Type} {a₁ a₂ : A} (f : A → B) (g : Πa, C (f a)) (p : a₁ = a₂) : (ap (λa, ⟨f a, g a⟩) p)..1 = ap f p := by induction p; reflexivity definition ap_sigma_pr2 {A B : Type} {C : B → Type} {a₁ a₂ : A} (f : A → B) (g : Πa, C (f a)) (p : a₁ = a₂) : (ap (λa, ⟨f a, g a⟩) p)..2 = change_path (ap_sigma_pr1 f g p)⁻¹ (pathover_ap C f (apd g p)) := by induction p; reflexivity definition ap_sigma_functor_sigma_eq {A A' : Type} {B : A → Type} {B' : A' → Type} {a a' : A} {b : B a} {b' : B a'} (f : A → A') (g : Πa, B a → B' (f a)) (p : a = a') (q : b =[p] b') : ap (sigma_functor f g) (sigma_eq p q) = sigma_eq (ap f p) (pathover_ap B' f (apo g q)) := by induction q; reflexivity definition ap_sigma_functor_id_sigma_eq {A : Type} {B B' : A → Type} {a a' : A} {b : B a} {b' : B a'} (g : Πa, B a → B' a) (p : a = a') (q : b =[p] b') : ap (sigma_functor id g) (sigma_eq p q) = sigma_eq p (apo g q) := by induction q; reflexivity definition sigma_eq_pr2_constant {A B : Type} {a a' : A} {b b' : B} (p : a = a') (q : b =[p] b') : ap pr2 (sigma_eq p q) = (eq_of_pathover q) := by induction q; reflexivity definition sigma_eq_pr2_constant2 {A B : Type} {a a' : A} {b b' : B} (p : a = a') (q : b = b') : ap pr2 (sigma_eq p (pathover_of_eq p q)) = q := by induction p; induction q; reflexivity definition sigma_eq_concato_eq {A : Type} {B : A → Type} {a a' : A} {b : B a} {b₁ b₂ : B a'} (p : a = a') (q : b =[p] b₁) (q' : b₁ = b₂) : sigma_eq p (q ⬝op q') = sigma_eq p q ⬝ ap (dpair a') q' := by induction q'; reflexivity -- open sigma.ops -- definition eq.rec_sigma {A : Type} {B : A → Type} {a₀ : A} {b₀ : B a₀} -- {P : Π(a : A) (b : B a), ⟨a₀, b₀⟩ = ⟨a, b⟩ → Type} (H : P a₀ b₀ idp) {a : A} {b : B a} -- (p : ⟨a₀, b₀⟩ = ⟨a, b⟩) : P a b p := -- sorry -- definition sigma_pathover_equiv_of_is_prop {A : Type} {B : A → Type} {C : Πa, B a → Type} -- {a a' : A} {p : a = a'} {b : B a} {b' : B a'} {c : C a b} {c' : C a' b'} -- [Πa b, is_prop (C a b)] : ⟨b, c⟩ =[p] ⟨b', c'⟩ ≃ b =[p] b' := -- begin -- fapply equiv.MK, -- { exact pathover_pr1 }, -- { intro q, induction q, apply pathover_idp_of_eq, exact sigma_eq idp !is_prop.elimo }, -- { intro q, induction q, -- have c = c', from !is_prop.elim, induction this, -- rewrite [▸*, is_prop_elimo_self (C a) c] }, -- { esimp, generalize ⟨b, c⟩, intro x q, } -- end --rexact @(ap pathover_pr1) _ idpo _, definition sigma_functor_compose {A A' A'' : Type} {B : A → Type} {B' : A' → Type} {B'' : A'' → Type} {f' : A' → A''} {f : A → A'} (g' : Πa, B' a → B'' (f' a)) (g : Πa, B a → B' (f a)) (x : Σa, B a) : sigma_functor f' g' (sigma_functor f g x) = sigma_functor (f' ∘ f) (λa, g' (f a) ∘ g a) x := begin reflexivity end definition sigma_functor_homotopy {A A' : Type} {B : A → Type} {B' : A' → Type} {f f' : A → A'} {g : Πa, B a → B' (f a)} {g' : Πa, B a → B' (f' a)} (h : f ~ f') (k : Πa b, g a b =[h a] g' a b) (x : Σa, B a) : sigma_functor f g x = sigma_functor f' g' x := sigma_eq (h x.1) (k x.1 x.2) variables {A₀₀ A₂₀ A₀₂ A₂₂ : Type} {B₀₀ : A₀₀ → Type} {B₂₀ : A₂₀ → Type} {B₀₂ : A₀₂ → Type} {B₂₂ : A₂₂ → Type} {f₁₀ : A₀₀ → A₂₀} {f₁₂ : A₀₂ → A₂₂} {f₀₁ : A₀₀ → A₀₂} {f₂₁ : A₂₀ → A₂₂} {g₁₀ : Πa, B₀₀ a → B₂₀ (f₁₀ a)} {g₁₂ : Πa, B₀₂ a → B₂₂ (f₁₂ a)} {g₀₁ : Πa, B₀₀ a → B₀₂ (f₀₁ a)} {g₂₁ : Πa, B₂₀ a → B₂₂ (f₂₁ a)} definition sigma_functor_hsquare (h : hsquare f₁₀ f₁₂ f₀₁ f₂₁) (k : Πa (b : B₀₀ a), g₂₁ _ (g₁₀ _ b) =[h a] g₁₂ _ (g₀₁ _ b)) : hsquare (sigma_functor f₁₀ g₁₀) (sigma_functor f₁₂ g₁₂) (sigma_functor f₀₁ g₀₁) (sigma_functor f₂₁ g₂₁) := λx, sigma_functor_compose g₂₁ g₁₀ x ⬝ sigma_functor_homotopy h k x ⬝ (sigma_functor_compose g₁₂ g₀₁ x)⁻¹ definition sigma_equiv_of_is_embedding_left_fun [constructor] {X Y : Type} {P : Y → Type} {f : X → Y} (H : Πy, P y → fiber f y) (v : Σy, P y) : Σx, P (f x) := ⟨fiber.point (H v.1 v.2), transport P (point_eq (H v.1 v.2))⁻¹ v.2⟩ definition sigma_equiv_of_is_embedding_left_prop [constructor] {X Y : Type} {P : Y → Type} (f : X → Y) (Hf : is_embedding f) (HP : Πx, is_prop (P (f x))) (H : Πy, P y → fiber f y) : (Σy, P y) ≃ Σx, P (f x) := begin apply equiv.MK (sigma_equiv_of_is_embedding_left_fun H) (sigma_functor f (λa, id)), { intro v, induction v with x p, esimp [sigma_equiv_of_is_embedding_left_fun], fapply sigma_eq, apply @is_injective_of_is_embedding _ _ f, exact point_eq (H (f x) p), apply is_prop.elimo }, { intro v, induction v with y p, esimp, fapply sigma_eq, exact point_eq (H y p), apply tr_pathover } end definition sigma_equiv_of_is_embedding_left_contr [constructor] {X Y : Type} {P : Y → Type} (f : X → Y) (Hf : is_embedding f) (HP : Πx, is_contr (P (f x))) (H : Πy, P y → fiber f y) : (Σy, P y) ≃ X := sigma_equiv_of_is_embedding_left_prop f Hf _ H ⬝e !sigma_equiv_of_is_contr_right end sigma open sigma namespace group definition isomorphism.MK [constructor] {G H : Group} (φ : G →g H) (ψ : H →g G) (p : φ ∘g ψ ~ gid H) (q : ψ ∘g φ ~ gid G) : G ≃g H := isomorphism.mk φ (adjointify φ ψ p q) protected definition homomorphism.sigma_char [constructor] (A B : Group) : (A →g B) ≃ Σ(f : A → B), is_mul_hom f := begin fapply equiv.MK, {intro F, exact ⟨F, _⟩ }, {intro p, cases p with f H, exact (homomorphism.mk f H) }, {intro p, cases p, reflexivity }, {intro F, cases F, reflexivity }, end definition homomorphism_pathover {A : Type} {a a' : A} (p : a = a') {B : A → Group} {C : A → Group} (f : B a →g C a) (g : B a' →g C a') (r : homomorphism.φ f =[p] homomorphism.φ g) : f =[p] g := begin fapply pathover_of_fn_pathover_fn, { intro a, apply homomorphism.sigma_char }, { fapply sigma_pathover, exact r, apply is_prop.elimo } end protected definition isomorphism.sigma_char [constructor] (A B : Group) : (A ≃g B) ≃ Σ(f : A →g B), is_equiv f := begin fapply equiv.MK, {intro F, exact ⟨F, _⟩ }, {intro p, cases p with f H, exact (isomorphism.mk f H) }, {intro p, cases p, reflexivity }, {intro F, cases F, reflexivity }, end definition isomorphism_pathover {A : Type} {a a' : A} (p : a = a') {B : A → Group} {C : A → Group} (f : B a ≃g C a) (g : B a' ≃g C a') (r : pathover (λa, B a → C a) f p g) : f =[p] g := begin fapply pathover_of_fn_pathover_fn, { intro a, apply isomorphism.sigma_char }, { fapply sigma_pathover, apply homomorphism_pathover, exact r, apply is_prop.elimo } end -- definition is_equiv_isomorphism -- some extra instances for type class inference -- definition is_mul_hom_comm_homomorphism [instance] {G G' : AbGroup} (φ : G →g G') -- : @is_mul_hom G G' (@ab_group.to_group _ (AbGroup.struct G)) -- (@ab_group.to_group _ (AbGroup.struct G')) φ := -- homomorphism.struct φ -- definition is_mul_hom_comm_homomorphism1 [instance] {G G' : AbGroup} (φ : G →g G') -- : @is_mul_hom G G' _ -- (@ab_group.to_group _ (AbGroup.struct G')) φ := -- homomorphism.struct φ -- definition is_mul_hom_comm_homomorphism2 [instance] {G G' : AbGroup} (φ : G →g G') -- : @is_mul_hom G G' (@ab_group.to_group _ (AbGroup.struct G)) _ φ := -- homomorphism.struct φ definition pgroup_of_Group (X : Group) : pgroup X := pgroup_of_group _ idp definition isomorphism_ap {A : Type} (F : A → Group) {a b : A} (p : a = b) : F a ≃g F b := isomorphism_of_eq (ap F p) definition interchange (G : AbGroup) (a b c d : G) : (a * b) * (c * d) = (a * c) * (b * d) := calc (a * b) * (c * d) = a * (b * (c * d)) : by exact mul.assoc a b (c * d) ... = a * ((b * c) * d) : by exact ap (λ bcd, a * bcd) (mul.assoc b c d)⁻¹ ... = a * ((c * b) * d) : by exact ap (λ bc, a * (bc * d)) (mul.comm b c) ... = a * (c * (b * d)) : by exact ap (λ bcd, a * bcd) (mul.assoc c b d) ... = (a * c) * (b * d) : by exact (mul.assoc a c (b * d))⁻¹ definition homomorphism_comp_compute {G H K : Group} (g : H →g K) (f : G →g H) (x : G) : (g ∘g f) x = g (f x) := begin reflexivity end open option definition add_point_AbGroup [unfold 3] {X : Type} (G : X → AbGroup) : X₊ → AbGroup | (some x) := G x | none := trivial_ab_group_lift definition isomorphism_of_is_contr {G H : Group} (hG : is_contr G) (hH : is_contr H) : G ≃g H := trivial_group_of_is_contr G ⬝g (trivial_group_of_is_contr H)⁻¹ᵍ definition trunc_isomorphism_of_equiv {A B : Type} [inf_group A] [inf_group B] (f : A ≃ B) (h : is_mul_hom f) : Group.mk (trunc 0 A) (trunc_group A) ≃g Group.mk (trunc 0 B) (trunc_group B) := begin apply isomorphism_of_equiv (equiv.mk (trunc_functor 0 f) (is_equiv_trunc_functor 0 f)), intros x x', induction x with a, induction x' with a', apply ap tr, exact h a a' end /----------------- The following are properties for ∞-groups ----------------/ local attribute InfGroup_of_Group [coercion] /- left and right actions -/ definition is_equiv_mul_right_inf [constructor] {A : InfGroup} (a : A) : is_equiv (λb, b * a) := adjointify _ (λb : A, b * a⁻¹) (λb, !inv_mul_cancel_right) (λb, !mul_inv_cancel_right) definition right_action_inf [constructor] {A : InfGroup} (a : A) : A ≃ A := equiv.mk _ (is_equiv_mul_right_inf a) /- homomorphisms -/ structure inf_homomorphism (G₁ G₂ : InfGroup) : Type := (φ : G₁ → G₂) (p : is_mul_hom φ) infix ` →∞g `:55 := inf_homomorphism abbreviation inf_group_fun [unfold 3] [coercion] [reducible] := @inf_homomorphism.φ definition inf_homomorphism.struct [unfold 3] [instance] [priority 900] {G₁ G₂ : InfGroup} (φ : G₁ →∞g G₂) : is_mul_hom φ := inf_homomorphism.p φ definition homomorphism_of_inf_homomorphism [constructor] {G H : Group} (φ : G →∞g H) : G →g H := homomorphism.mk φ (inf_homomorphism.struct φ) definition inf_homomorphism_of_homomorphism [constructor] {G H : Group} (φ : G →g H) : G →∞g H := inf_homomorphism.mk φ (homomorphism.struct φ) variables {G G₁ G₂ G₃ : InfGroup} {g h : G₁} {ψ : G₂ →∞g G₃} {φ₁ φ₂ : G₁ →∞g G₂} (φ : G₁ →∞g G₂) definition to_respect_mul_inf /- φ -/ (g h : G₁) : φ (g * h) = φ g * φ h := respect_mul φ g h theorem to_respect_one_inf /- φ -/ : φ 1 = 1 := have φ 1 * φ 1 = φ 1 * 1, by rewrite [-to_respect_mul_inf φ, +mul_one], eq_of_mul_eq_mul_left' this theorem to_respect_inv_inf /- φ -/ (g : G₁) : φ g⁻¹ = (φ g)⁻¹ := have φ (g⁻¹) * φ g = 1, by rewrite [-to_respect_mul_inf φ, mul.left_inv, to_respect_one_inf φ], eq_inv_of_mul_eq_one this definition pmap_of_inf_homomorphism [constructor] /- φ -/ : G₁ →* G₂ := pmap.mk φ begin esimp, exact to_respect_one_inf φ end definition inf_homomorphism_change_fun [constructor] {G₁ G₂ : InfGroup} (φ : G₁ →∞g G₂) (f : G₁ → G₂) (p : φ ~ f) : G₁ →∞g G₂ := inf_homomorphism.mk f (λg h, (p (g * h))⁻¹ ⬝ to_respect_mul_inf φ g h ⬝ ap011 mul (p g) (p h)) /- categorical structure of groups + homomorphisms -/ definition inf_homomorphism_compose [constructor] [trans] [reducible] (ψ : G₂ →∞g G₃) (φ : G₁ →∞g G₂) : G₁ →∞g G₃ := inf_homomorphism.mk (ψ ∘ φ) (is_mul_hom_compose _ _) variable (G) definition inf_homomorphism_id [constructor] [refl] : G →∞g G := inf_homomorphism.mk (@id G) (is_mul_hom_id G) variable {G} abbreviation inf_gid [constructor] := @inf_homomorphism_id infixr ` ∘∞g `:75 := inf_homomorphism_compose structure inf_isomorphism (A B : InfGroup) := (to_hom : A →∞g B) (is_equiv_to_hom : is_equiv to_hom) infix ` ≃∞g `:25 := inf_isomorphism attribute inf_isomorphism.to_hom [coercion] attribute inf_isomorphism.is_equiv_to_hom [instance] attribute inf_isomorphism._trans_of_to_hom [unfold 3] definition equiv_of_inf_isomorphism [constructor] (φ : G₁ ≃∞g G₂) : G₁ ≃ G₂ := equiv.mk φ _ definition pequiv_of_inf_isomorphism [constructor] (φ : G₁ ≃∞g G₂) : G₁ ≃* G₂ := pequiv.mk φ begin esimp, exact _ end begin esimp, exact to_respect_one_inf φ end definition inf_isomorphism_of_equiv [constructor] (φ : G₁ ≃ G₂) (p : Πg₁ g₂, φ (g₁ * g₂) = φ g₁ * φ g₂) : G₁ ≃∞g G₂ := inf_isomorphism.mk (inf_homomorphism.mk φ p) !to_is_equiv definition inf_isomorphism_of_eq [constructor] {G₁ G₂ : InfGroup} (φ : G₁ = G₂) : G₁ ≃∞g G₂ := inf_isomorphism_of_equiv (equiv_of_eq (ap InfGroup.carrier φ)) begin intros, induction φ, reflexivity end definition to_ginv_inf [constructor] (φ : G₁ ≃∞g G₂) : G₂ →∞g G₁ := inf_homomorphism.mk φ⁻¹ abstract begin intro g₁ g₂, apply eq_of_fn_eq_fn' φ, rewrite [respect_mul φ, +right_inv φ] end end variable (G) definition inf_isomorphism.refl [refl] [constructor] : G ≃∞g G := inf_isomorphism.mk !inf_gid !is_equiv_id variable {G} definition inf_isomorphism.symm [symm] [constructor] (φ : G₁ ≃∞g G₂) : G₂ ≃∞g G₁ := inf_isomorphism.mk (to_ginv_inf φ) !is_equiv_inv definition inf_isomorphism.trans [trans] [constructor] (φ : G₁ ≃∞g G₂) (ψ : G₂ ≃∞g G₃) : G₁ ≃∞g G₃ := inf_isomorphism.mk (ψ ∘∞g φ) !is_equiv_compose definition inf_isomorphism.eq_trans [trans] [constructor] {G₁ G₂ : InfGroup} {G₃ : InfGroup} (φ : G₁ = G₂) (ψ : G₂ ≃∞g G₃) : G₁ ≃∞g G₃ := proof inf_isomorphism.trans (inf_isomorphism_of_eq φ) ψ qed definition inf_isomorphism.trans_eq [trans] [constructor] {G₁ : InfGroup} {G₂ G₃ : InfGroup} (φ : G₁ ≃∞g G₂) (ψ : G₂ = G₃) : G₁ ≃∞g G₃ := inf_isomorphism.trans φ (inf_isomorphism_of_eq ψ) postfix `⁻¹ᵍ⁸`:(max + 1) := inf_isomorphism.symm infixl ` ⬝∞g `:75 := inf_isomorphism.trans infixl ` ⬝∞gp `:75 := inf_isomorphism.trans_eq infixl ` ⬝∞pg `:75 := inf_isomorphism.eq_trans definition pmap_of_inf_isomorphism [constructor] (φ : G₁ ≃∞g G₂) : G₁ →* G₂ := pequiv_of_inf_isomorphism φ definition to_fun_inf_isomorphism_trans {G H K : InfGroup} (φ : G ≃∞g H) (ψ : H ≃∞g K) : φ ⬝∞g ψ ~ ψ ∘ φ := by reflexivity definition inf_homomorphism_mul [constructor] {G H : AbInfGroup} (φ ψ : G →∞g H) : G →∞g H := inf_homomorphism.mk (λg, φ g * ψ g) abstract begin intro g g', refine ap011 mul !to_respect_mul_inf !to_respect_mul_inf ⬝ _, refine !mul.assoc ⬝ ap (mul _) (!mul.assoc⁻¹ ⬝ ap (λx, x * _) !mul.comm ⬝ !mul.assoc) ⬝ !mul.assoc⁻¹ end end definition trivial_inf_homomorphism (A B : InfGroup) : A →∞g B := inf_homomorphism.mk (λa, 1) (λa a', (mul_one 1)⁻¹) /- given an equivalence A ≃ B we can transport a group structure on A to a group structure on B -/ section parameters {A B : Type} (f : A ≃ B) [inf_group A] definition inf_group_equiv_mul (b b' : B) : B := f (f⁻¹ᶠ b * f⁻¹ᶠ b') definition inf_group_equiv_one : B := f one definition inf_group_equiv_inv (b : B) : B := f (f⁻¹ᶠ b)⁻¹ local infix * := inf_group_equiv_mul local postfix ^ := inf_group_equiv_inv local notation 1 := inf_group_equiv_one theorem inf_group_equiv_mul_assoc (b₁ b₂ b₃ : B) : (b₁ * b₂) * b₃ = b₁ * (b₂ * b₃) := by rewrite [↑inf_group_equiv_mul, +left_inv f, mul.assoc] theorem inf_group_equiv_one_mul (b : B) : 1 * b = b := by rewrite [↑inf_group_equiv_mul, ↑inf_group_equiv_one, left_inv f, one_mul, right_inv f] theorem inf_group_equiv_mul_one (b : B) : b * 1 = b := by rewrite [↑inf_group_equiv_mul, ↑inf_group_equiv_one, left_inv f, mul_one, right_inv f] theorem inf_group_equiv_mul_left_inv (b : B) : b^ * b = 1 := by rewrite [↑inf_group_equiv_mul, ↑inf_group_equiv_one, ↑inf_group_equiv_inv, +left_inv f, mul.left_inv] definition inf_group_equiv_closed : inf_group B := ⦃inf_group, mul := inf_group_equiv_mul, mul_assoc := inf_group_equiv_mul_assoc, one := inf_group_equiv_one, one_mul := inf_group_equiv_one_mul, mul_one := inf_group_equiv_mul_one, inv := inf_group_equiv_inv, mul_left_inv := inf_group_equiv_mul_left_inv⦄ end section variables {A B : Type} (f : A ≃ B) [ab_inf_group A] definition inf_group_equiv_mul_comm (b b' : B) : inf_group_equiv_mul f b b' = inf_group_equiv_mul f b' b := by rewrite [↑inf_group_equiv_mul, mul.comm] definition ab_inf_group_equiv_closed : ab_inf_group B := ⦃ab_inf_group, inf_group_equiv_closed f, mul_comm := inf_group_equiv_mul_comm f⦄ end variable (G) /- the trivial ∞-group -/ open unit definition inf_group_unit [constructor] : inf_group unit := inf_group.mk (λx y, star) (λx y z, idp) star (unit.rec idp) (unit.rec idp) (λx, star) (λx, idp) definition ab_inf_group_unit [constructor] : ab_inf_group unit := ⦃ab_inf_group, inf_group_unit, mul_comm := λx y, idp⦄ definition trivial_inf_group [constructor] : InfGroup := InfGroup.mk _ inf_group_unit definition AbInfGroup_of_InfGroup (G : InfGroup.{u}) (H : Π x y : G, x * y = y * x) : AbInfGroup.{u} := begin induction G, fapply AbInfGroup.mk, assumption, exact ⦃ab_inf_group, struct', mul_comm := H⦄ end definition trivial_ab_inf_group : AbInfGroup.{0} := begin fapply AbInfGroup_of_InfGroup trivial_inf_group, intro x y, reflexivity end definition trivial_inf_group_of_is_contr [H : is_contr G] : G ≃∞g trivial_inf_group := begin fapply inf_isomorphism_of_equiv, { apply equiv_unit_of_is_contr}, { intros, reflexivity} end definition ab_inf_group_of_is_contr (A : Type) [is_contr A] : ab_inf_group A := have ab_inf_group unit, from ab_inf_group_unit, ab_inf_group_equiv_closed (equiv_unit_of_is_contr A)⁻¹ᵉ definition inf_group_of_is_contr (A : Type) [is_contr A] : inf_group A := have ab_inf_group A, from ab_inf_group_of_is_contr A, by apply _ definition ab_inf_group_lift_unit : ab_inf_group (lift unit) := ab_inf_group_of_is_contr (lift unit) definition trivial_ab_inf_group_lift : AbInfGroup := AbInfGroup.mk _ ab_inf_group_lift_unit definition from_trivial_ab_inf_group (A : AbInfGroup) : trivial_ab_inf_group →∞g A := trivial_inf_homomorphism trivial_ab_inf_group A definition to_trivial_ab_inf_group (A : AbInfGroup) : A →∞g trivial_ab_inf_group := trivial_inf_homomorphism A trivial_ab_inf_group end group open group namespace fiber open pointed sigma sigma.ops definition loopn_pfiber [constructor] {A B : Type*} (n : ℕ) (f : A →* B) : Ω[n] (pfiber f) ≃* pfiber (Ω→[n] f) := begin induction n with n IH, reflexivity, exact loop_pequiv_loop IH ⬝e* loop_pfiber (Ω→[n] f), end definition fiber_eq_pr2 {A B : Type} {f : A → B} {b : B} {x y : fiber f b} (p : x = y) : point_eq x = ap f (ap point p) ⬝ point_eq y := begin induction p, exact !idp_con⁻¹ end definition fiber_eq_eta {A B : Type} {f : A → B} {b : B} {x y : fiber f b} (p : x = y) : p = fiber_eq (ap point p) (fiber_eq_pr2 p) := begin induction p, induction x with a q, induction q, reflexivity end definition fiber_eq_con {A B : Type} {f : A → B} {b : B} {x y z : fiber f b} (p1 : point x = point y) (p2 : point y = point z) (q1 : point_eq x = ap f p1 ⬝ point_eq y) (q2 : point_eq y = ap f p2 ⬝ point_eq z) : fiber_eq p1 q1 ⬝ fiber_eq p2 q2 = fiber_eq (p1 ⬝ p2) (q1 ⬝ whisker_left (ap f p1) q2 ⬝ !con.assoc⁻¹ ⬝ whisker_right (point_eq z) (ap_con f p1 p2)⁻¹) := begin induction x with a₁ r₁, induction y with a₂ r₂, induction z with a₃ r₃, esimp at *, induction q2 using eq.rec_symm, induction q1 using eq.rec_symm, induction p2, induction p1, induction r₃, reflexivity end definition fiber_eq_equiv' [constructor] {A B : Type} {f : A → B} {b : B} (x y : fiber f b) : (x = y) ≃ (Σ(p : point x = point y), point_eq x = ap f p ⬝ point_eq y) := @equiv_change_inv _ _ (fiber_eq_equiv x y) (λpq, fiber_eq pq.1 pq.2) begin intro pq, cases pq, reflexivity end definition is_contr_pfiber_pid (A : Type*) : is_contr (pfiber (pid A)) := is_contr.mk pt begin intro x, induction x with a p, esimp at p, cases p, reflexivity end definition fiber_functor [constructor] {A A' B B' : Type} {f : A → B} {f' : A' → B'} {b : B} {b' : B'} (g : A → A') (h : B → B') (H : hsquare g h f f') (p : h b = b') (x : fiber f b) : fiber f' b' := fiber.mk (g (point x)) (H (point x) ⬝ ap h (point_eq x) ⬝ p) definition pfiber_functor [constructor] {A A' B B' : Type*} {f : A →* B} {f' : A' →* B'} (g : A →* A') (h : B →* B') (H : psquare g h f f') : pfiber f →* pfiber f' := pmap.mk (fiber_functor g h H (respect_pt h)) begin fapply fiber_eq, exact respect_pt g, exact !con.assoc ⬝ to_homotopy_pt H end definition ppoint_natural {A A' B B' : Type*} {f : A →* B} {f' : A' →* B'} (g : A →* A') (h : B →* B') (H : psquare g h f f') : psquare (ppoint f) (ppoint f') (pfiber_functor g h H) g := begin fapply phomotopy.mk, { intro x, reflexivity }, { refine !idp_con ⬝ _ ⬝ !idp_con⁻¹, esimp, apply point_fiber_eq } end /- if we need this: do pfiber_functor_pcompose and so on first -/ -- definition psquare_pfiber_functor [constructor] {A₁ A₂ A₃ A₄ B₁ B₂ B₃ B₄ : Type*} -- {f₁ : A₁ →* B₁} {f₂ : A₂ →* B₂} {f₃ : A₃ →* B₃} {f₄ : A₄ →* B₄} -- {g₁₂ : A₁ →* A₂} {g₃₄ : A₃ →* A₄} {g₁₃ : A₁ →* A₃} {g₂₄ : A₂ →* A₄} -- {h₁₂ : B₁ →* B₂} {h₃₄ : B₃ →* B₄} {h₁₃ : B₁ →* B₃} {h₂₄ : B₂ →* B₄} -- (H₁₂ : psquare g₁₂ h₁₂ f₁ f₂) (H₃₄ : psquare g₃₄ h₃₄ f₃ f₄) -- (H₁₃ : psquare g₁₃ h₁₃ f₁ f₃) (H₂₄ : psquare g₂₄ h₂₄ f₂ f₄) -- (G : psquare g₁₂ g₃₄ g₁₃ g₂₄) (H : psquare h₁₂ h₃₄ h₁₃ h₂₄) -- /- pcube H₁₂ H₃₄ H₁₃ H₂₄ G H -/ : -- psquare (pfiber_functor g₁₂ h₁₂ H₁₂) (pfiber_functor g₃₄ h₃₄ H₃₄) -- (pfiber_functor g₁₃ h₁₃ H₁₃) (pfiber_functor g₂₄ h₂₄ H₂₄) := -- begin -- fapply phomotopy.mk, -- { intro x, induction x with x p, induction B₁ with B₁ b₁₀, induction f₁ with f₁ f₁₀, esimp at *, -- induction p, esimp [fiber_functor], }, -- { } -- end -- TODO: use this in pfiber_pequiv_of_phomotopy definition fiber_equiv_of_homotopy {A B : Type} {f g : A → B} (h : f ~ g) (b : B) : fiber f b ≃ fiber g b := begin refine (fiber.sigma_char f b ⬝e _ ⬝e (fiber.sigma_char g b)⁻¹ᵉ), apply sigma_equiv_sigma_right, intros a, apply equiv_eq_closed_left, apply h end definition fiber_equiv_of_square {A B C D : Type} {b : B} {d : D} {f : A → B} {g : C → D} (h : A ≃ C) (k : B ≃ D) (s : k ∘ f ~ g ∘ h) (p : k b = d) : fiber f b ≃ fiber g d := calc fiber f b ≃ fiber (k ∘ f) (k b) : fiber.equiv_postcompose ... ≃ fiber (k ∘ f) d : transport_fiber_equiv (k ∘ f) p ... ≃ fiber (g ∘ h) d : fiber_equiv_of_homotopy s d ... ≃ fiber g d : fiber.equiv_precompose definition fiber_equiv_of_triangle {A B C : Type} {b : B} {f : A → B} {g : C → B} (h : A ≃ C) (s : f ~ g ∘ h) : fiber f b ≃ fiber g b := fiber_equiv_of_square h erfl s idp definition is_trunc_fun_id (k : ℕ₋₂) (A : Type) : is_trunc_fun k (@id A) := λa, is_trunc_of_is_contr _ _ definition is_conn_fun_id (k : ℕ₋₂) (A : Type) : is_conn_fun k (@id A) := λa, _ open sigma.ops is_conn definition fiber_compose {A B C : Type} (g : B → C) (f : A → B) (c : C) : fiber (g ∘ f) c ≃ Σ(x : fiber g c), fiber f (point x) := begin fapply equiv.MK, { intro x, exact ⟨fiber.mk (f (point x)) (point_eq x), fiber.mk (point x) idp⟩ }, { intro x, exact fiber.mk (point x.2) (ap g (point_eq x.2) ⬝ point_eq x.1) }, { intro x, induction x with x₁ x₂, induction x₁ with b p, induction x₂ with a q, induction p, esimp at q, induction q, reflexivity }, { intro x, induction x with a p, induction p, reflexivity } end definition is_trunc_fun_compose (k : ℕ₋₂) {A B C : Type} {g : B → C} {f : A → B} (Hg : is_trunc_fun k g) (Hf : is_trunc_fun k f) : is_trunc_fun k (g ∘ f) := λc, is_trunc_equiv_closed_rev k (fiber_compose g f c) definition is_conn_fun_compose (k : ℕ₋₂) {A B C : Type} {g : B → C} {f : A → B} (Hg : is_conn_fun k g) (Hf : is_conn_fun k f) : is_conn_fun k (g ∘ f) := λc, is_conn_equiv_closed_rev k (fiber_compose g f c) _ end fiber open fiber namespace fin definition lift_succ2 [constructor] ⦃n : ℕ⦄ (x : fin n) : fin (nat.succ n) := fin.mk x (le.step (is_lt x)) end fin namespace function variables {A B : Type} {f f' : A → B} open is_conn sigma.ops definition is_contr_of_is_surjective (f : A → B) (H : is_surjective f) (HA : is_contr A) (HB : is_set B) : is_contr B := is_contr.mk (f !center) begin intro b, induction H b, exact ap f !is_prop.elim ⬝ p end definition is_surjective_of_is_contr [constructor] (f : A → B) (a : A) (H : is_contr B) : is_surjective f := λb, image.mk a !eq_of_is_contr definition is_contr_of_is_embedding (f : A → B) (H : is_embedding f) (HB : is_prop B) (a₀ : A) : is_contr A := is_contr.mk a₀ (λa, is_injective_of_is_embedding (is_prop.elim (f a₀) (f a))) definition merely_constant {A B : Type} (f : A → B) : Type := Σb, Πa, merely (f a = b) definition merely_constant_pmap {A B : Type*} {f : A →* B} (H : merely_constant f) (a : A) : merely (f a = pt) := tconcat (tconcat (H.2 a) (tinverse (H.2 pt))) (tr (respect_pt f)) definition merely_constant_of_is_conn {A B : Type*} (f : A →* B) [is_conn 0 A] : merely_constant f := ⟨pt, is_conn.elim -1 _ (tr (respect_pt f))⟩ definition homotopy_group_isomorphism_of_is_embedding (n : ℕ) [H : is_succ n] {A B : Type*} (f : A →* B) [H2 : is_embedding f] : πg[n] A ≃g πg[n] B := begin apply isomorphism.mk (homotopy_group_homomorphism n f), induction H with n, apply is_equiv_of_equiv_of_homotopy (ptrunc_pequiv_ptrunc 0 (loopn_pequiv_loopn_of_is_embedding (n+1) f)), exact sorry end end function open function namespace is_conn open unit trunc_index nat is_trunc pointed.ops sigma.ops prod.ops definition is_conn_of_eq {n m : ℕ₋₂} (p : n = m) {A : Type} (H : is_conn n A) : is_conn m A := transport (λk, is_conn k A) p H -- todo: make trunc_equiv_trunc_of_is_conn_fun a def. definition ptrunc_pequiv_ptrunc_of_is_conn_fun {A B : Type*} (n : ℕ₋₂) (f : A →* B) [H : is_conn_fun n f] : ptrunc n A ≃* ptrunc n B := pequiv_of_pmap (ptrunc_functor n f) (is_equiv_trunc_functor_of_is_conn_fun n f) definition is_conn_zero {A : Type} (a₀ : trunc 0 A) (p : Πa a' : A, ∥ a = a' ∥) : is_conn 0 A := is_conn_succ_intro a₀ (λa a', is_conn_minus_one _ (p a a')) definition is_conn_zero_pointed {A : Type*} (p : Πa a' : A, ∥ a = a' ∥) : is_conn 0 A := is_conn_zero (tr pt) p definition is_conn_zero_pointed' {A : Type*} (p : Πa : A, ∥ a = pt ∥) : is_conn 0 A := is_conn_zero_pointed (λa a', tconcat (p a) (tinverse (p a'))) definition is_conn_fiber (n : ℕ₋₂) {A B : Type} (f : A → B) (b : B) [is_conn n A] [is_conn (n.+1) B] : is_conn n (fiber f b) := is_conn_equiv_closed_rev _ !fiber.sigma_char _ definition is_conn_succ_of_is_conn_loop {n : ℕ₋₂} {A : Type*} (H : is_conn 0 A) (H2 : is_conn n (Ω A)) : is_conn (n.+1) A := begin apply is_conn_succ_intro, exact tr pt, intros a a', induction merely_of_minus_one_conn (is_conn_eq -1 a a') with p, induction p, induction merely_of_minus_one_conn (is_conn_eq -1 pt a) with p, induction p, exact H2 end definition is_conn_fun_compose {n : ℕ₋₂} {A B C : Type} (g : B → C) (f : A → B) (H : is_conn_fun n g) (K : is_conn_fun n f) : is_conn_fun n (g ∘ f) := sorry definition pconntype.sigma_char [constructor] (k : ℕ₋₂) : Type*[k] ≃ Σ(X : Type*), is_conn k X := equiv.MK (λX, ⟨pconntype.to_pType X, _⟩) (λX, pconntype.mk (carrier X.1) X.2 pt) begin intro X, induction X with X HX, induction X, reflexivity end begin intro X, induction X, reflexivity end definition is_embedding_pconntype_to_pType (k : ℕ₋₂) : is_embedding (@pconntype.to_pType k) := begin intro X Y, fapply is_equiv_of_equiv_of_homotopy, { exact eq_equiv_fn_eq (pconntype.sigma_char k) _ _ ⬝e subtype_eq_equiv _ _ }, intro p, induction p, reflexivity end definition pconntype_eq_equiv {k : ℕ₋₂} (X Y : Type*[k]) : (X = Y) ≃ (X ≃* Y) := equiv.mk _ (is_embedding_pconntype_to_pType k X Y) ⬝e pType_eq_equiv X Y definition pconntype_eq {k : ℕ₋₂} {X Y : Type*[k]} (e : X ≃* Y) : X = Y := (pconntype_eq_equiv X Y)⁻¹ᵉ e definition ptruncconntype.sigma_char [constructor] (n k : ℕ₋₂) : n-Type*[k] ≃ Σ(X : Type*), is_trunc n X × is_conn k X := equiv.MK (λX, ⟨ptruncconntype._trans_of_to_pconntype_1 X, (_, _)⟩) (λX, ptruncconntype.mk (carrier X.1) X.2.1 pt X.2.2) begin intro X, induction X with X HX, induction HX, induction X, reflexivity end begin intro X, induction X, reflexivity end definition ptruncconntype.sigma_char_pconntype [constructor] (n k : ℕ₋₂) : n-Type*[k] ≃ Σ(X : Type*[k]), is_trunc n X := equiv.MK (λX, ⟨ptruncconntype.to_pconntype X, _⟩) (λX, ptruncconntype.mk (pconntype._trans_of_to_pType X.1) X.2 pt _) begin intro X, induction X with X HX, induction HX, induction X, reflexivity end begin intro X, induction X, reflexivity end definition is_embedding_ptruncconntype_to_pconntype (n k : ℕ₋₂) : is_embedding (@ptruncconntype.to_pconntype n k) := begin intro X Y, fapply is_equiv_of_equiv_of_homotopy, { exact eq_equiv_fn_eq (ptruncconntype.sigma_char_pconntype n k) _ _ ⬝e subtype_eq_equiv _ _ }, intro p, induction p, reflexivity end definition ptruncconntype_eq_equiv {n k : ℕ₋₂} (X Y : n-Type*[k]) : (X = Y) ≃ (X ≃* Y) := equiv.mk _ (is_embedding_ptruncconntype_to_pconntype n k X Y) ⬝e pconntype_eq_equiv X Y /- duplicate -/ definition ptruncconntype_eq {n k : ℕ₋₂} {X Y : n-Type*[k]} (e : X ≃* Y) : X = Y := (ptruncconntype_eq_equiv X Y)⁻¹ᵉ e definition ptruncconntype_functor [constructor] {n n' k k' : ℕ₋₂} (p : n = n') (q : k = k') (X : n-Type*[k]) : n'-Type*[k'] := ptruncconntype.mk X (is_trunc_of_eq p _) pt (is_conn_of_eq q _) definition ptruncconntype_equiv [constructor] {n n' k k' : ℕ₋₂} (p : n = n') (q : k = k') : n-Type*[k] ≃ n'-Type*[k'] := equiv.MK (ptruncconntype_functor p q) (ptruncconntype_functor p⁻¹ q⁻¹) (λX, ptruncconntype_eq pequiv.rfl) (λX, ptruncconntype_eq pequiv.rfl) -- definition is_conn_pfiber_of_equiv_on_homotopy_groups (n : ℕ) {A B : pType.{u}} (f : A →* B) -- [H : is_conn 0 A] -- (H1 : Πk, k ≤ n → is_equiv (π→[k] f)) -- (H2 : is_surjective (π→[succ n] f)) : -- is_conn n (pfiber f) := -- _ -- definition is_conn_pelim [constructor] {k : ℕ} {X : Type*} (Y : Type*) (H : is_conn k X) : -- (X →* connect k Y) ≃ (X →* Y) := /- the k-connected cover of X, the fiber of the map X → ∥X∥ₖ. -/ definition connect (k : ℕ) (X : Type*) : Type* := pfiber (ptr k X) definition is_conn_connect (k : ℕ) (X : Type*) : is_conn k (connect k X) := is_conn_fun_tr k X (tr pt) definition connconnect [constructor] (k : ℕ) (X : Type*) : Type*[k] := pconntype.mk (connect k X) (is_conn_connect k X) pt definition connect_intro [constructor] {k : ℕ} {X : Type*} {Y : Type*} (H : is_conn k X) (f : X →* Y) : X →* connect k Y := pmap.mk (λx, fiber.mk (f x) (is_conn.elim (k.-1) _ (ap tr (respect_pt f)) x)) begin fapply fiber_eq, exact respect_pt f, apply is_conn.elim_β end definition ppoint_connect_intro [constructor] {k : ℕ} {X : Type*} {Y : Type*} (H : is_conn k X) (f : X →* Y) : ppoint (ptr k Y) ∘* connect_intro H f ~* f := begin induction f with f f₀, induction Y with Y y₀, esimp at (f,f₀), induction f₀, fapply phomotopy.mk, { intro x, reflexivity }, { symmetry, esimp, apply point_fiber_eq } end definition connect_intro_ppoint [constructor] {k : ℕ} {X : Type*} {Y : Type*} (H : is_conn k X) (f : X →* connect k Y) : connect_intro H (ppoint (ptr k Y) ∘* f) ~* f := begin cases f with f f₀, fapply phomotopy.mk, { intro x, fapply fiber_eq, reflexivity, refine @is_conn.elim (k.-1) _ _ _ (λx', !is_trunc_eq) _ x, refine !is_conn.elim_β ⬝ _, refine _ ⬝ !idp_con⁻¹, symmetry, refine _ ⬝ !con_idp, exact fiber_eq_pr2 f₀ }, { esimp, refine whisker_left _ !fiber_eq_eta ⬝ !fiber_eq_con ⬝ apd011 fiber_eq !idp_con _, esimp, apply eq_pathover_constant_left, refine whisker_right _ (whisker_right _ (whisker_right _ !is_conn.elim_β)) ⬝pv _, esimp [connect], refine _ ⬝vp !con_idp, apply move_bot_of_left, refine !idp_con ⬝ !con_idp⁻¹ ⬝ph _, refine !con.assoc ⬝ !con.assoc ⬝pv _, apply whisker_tl, note r := eq_bot_of_square (transpose (whisker_left_idp_square (fiber_eq_pr2 f₀))⁻¹ᵛ), refine !con.assoc⁻¹ ⬝ whisker_right _ r⁻¹ ⬝pv _, clear r, apply move_top_of_left, refine whisker_right_idp (ap_con tr idp (ap point f₀))⁻¹ᵖ ⬝pv _, exact (ap_con_idp_left tr (ap point f₀))⁻¹ʰ } end definition connect_intro_equiv [constructor] {k : ℕ} {X : Type*} (Y : Type*) (H : is_conn k X) : (X →* connect k Y) ≃ (X →* Y) := begin fapply equiv.MK, { intro f, exact ppoint (ptr k Y) ∘* f }, { intro g, exact connect_intro H g }, { intro g, apply eq_of_phomotopy, exact ppoint_connect_intro H g }, { intro f, apply eq_of_phomotopy, exact connect_intro_ppoint H f } end definition connect_intro_pequiv [constructor] {k : ℕ} {X : Type*} (Y : Type*) (H : is_conn k X) : ppmap X (connect k Y) ≃* ppmap X Y := pequiv_of_equiv (connect_intro_equiv Y H) (eq_of_phomotopy !pcompose_pconst) definition connect_pequiv {k : ℕ} {X : Type*} (H : is_conn k X) : connect k X ≃* X := @pfiber_pequiv_of_is_contr _ _ (ptr k X) H definition loop_connect (k : ℕ) (X : Type*) : Ω (connect (k+1) X) ≃* connect k (Ω X) := loop_pfiber (ptr (k+1) X) ⬝e* pfiber_pequiv_of_square pequiv.rfl (loop_ptrunc_pequiv k X) (phomotopy_of_phomotopy_pinv_left (ap1_ptr k X)) definition loopn_connect (k : ℕ) (X : Type*) : Ω[k+1] (connect k X) ≃* Ω[k+1] X := loopn_pfiber (k+1) (ptr k X) ⬝e* @pfiber_pequiv_of_is_contr _ _ _ (@is_contr_loop_of_is_trunc (k+1) _ !is_trunc_trunc) definition is_conn_of_is_conn_succ_nat (n : ℕ) (A : Type) [is_conn (n+1) A] : is_conn n A := is_conn_of_is_conn_succ n A definition connect_functor (k : ℕ) {X Y : Type*} (f : X →* Y) : connect k X →* connect k Y := pfiber_functor f (ptrunc_functor k f) (ptr_natural k f)⁻¹* definition connect_intro_pequiv_natural {k : ℕ} {X X' : Type*} {Y Y' : Type*} (f : X' →* X) (g : Y →* Y') (H : is_conn k X) (H' : is_conn k X') : psquare (connect_intro_pequiv Y H) (connect_intro_pequiv Y' H') (ppcompose_left (connect_functor k g) ∘* ppcompose_right f) (ppcompose_left g ∘* ppcompose_right f) := begin refine _ ⬝v* _, exact connect_intro_pequiv Y H', { fapply phomotopy.mk, { intro h, apply eq_of_phomotopy, apply passoc }, { xrewrite [▸*, pcompose_right_eq_of_phomotopy, pcompose_left_eq_of_phomotopy, -+eq_of_phomotopy_trans], apply ap eq_of_phomotopy, apply passoc_pconst_middle }}, { fapply phomotopy.mk, { intro h, apply eq_of_phomotopy, refine !passoc⁻¹* ⬝* pwhisker_right h (ppoint_natural _ _ _) ⬝* !passoc }, { xrewrite [▸*, +pcompose_left_eq_of_phomotopy, -+eq_of_phomotopy_trans], apply ap eq_of_phomotopy, refine !trans_assoc ⬝ idp ◾** !passoc_pconst_right ⬝ _, refine !trans_assoc ⬝ idp ◾** !pcompose_pconst_phomotopy ⬝ _, apply symm_trans_eq_of_eq_trans, symmetry, apply passoc_pconst_right }} end end is_conn namespace misc open is_conn open sigma.ops pointed trunc_index /- this is equivalent to pfiber (A → ∥A∥₀) ≡ connect 0 A -/ definition component [constructor] (A : Type*) : Type* := pType.mk (Σ(a : A), merely (pt = a)) ⟨pt, tr idp⟩ lemma is_conn_component [instance] (A : Type*) : is_conn 0 (component A) := is_conn_zero_pointed' begin intro x, induction x with a p, induction p with p, induction p, exact tidp end definition component_incl [constructor] (A : Type*) : component A →* A := pmap.mk pr1 idp definition is_embedding_component_incl [instance] (A : Type*) : is_embedding (component_incl A) := is_embedding_pr1 _ definition component_intro [constructor] {A B : Type*} (f : A →* B) (H : merely_constant f) : A →* component B := begin fapply pmap.mk, { intro a, refine ⟨f a, _⟩, exact tinverse (merely_constant_pmap H a) }, exact subtype_eq !respect_pt end definition component_functor [constructor] {A B : Type*} (f : A →* B) : component A →* component B := component_intro (f ∘* component_incl A) !merely_constant_of_is_conn -- definition component_elim [constructor] {A B : Type*} (f : A →* B) (H : merely_constant f) : -- A →* component B := -- begin -- fapply pmap.mk, -- { intro a, refine ⟨f a, _⟩, exact tinverse (merely_constant_pmap H a) }, -- exact subtype_eq !respect_pt -- end definition loop_component (A : Type*) : Ω (component A) ≃* Ω A := loop_pequiv_loop_of_is_embedding (component_incl A) lemma loopn_component (n : ℕ) (A : Type*) : Ω[n+1] (component A) ≃* Ω[n+1] A := !loopn_succ_in ⬝e* loopn_pequiv_loopn n (loop_component A) ⬝e* !loopn_succ_in⁻¹ᵉ* -- lemma fundamental_group_component (A : Type*) : π₁ (component A) ≃g π₁ A := -- isomorphism_of_equiv (trunc_equiv_trunc 0 (loop_component A)) _ lemma homotopy_group_component (n : ℕ) (A : Type*) : πg[n+1] (component A) ≃g πg[n+1] A := homotopy_group_isomorphism_of_is_embedding (n+1) (component_incl A) definition is_trunc_component [instance] (n : ℕ₋₂) (A : Type*) [is_trunc n A] : is_trunc n (component A) := begin apply @is_trunc_sigma, intro a, cases n with n, { apply is_contr_of_inhabited_prop, exact tr !is_prop.elim }, { apply is_trunc_succ_of_is_prop }, end definition ptrunc_component' (n : ℕ₋₂) (A : Type*) : ptrunc (n.+2) (component A) ≃* component (ptrunc (n.+2) A) := begin fapply pequiv.MK', { exact ptrunc.elim (n.+2) (component_functor !ptr) }, { intro x, cases x with x p, induction x with a, refine tr ⟨a, _⟩, note q := trunc_functor -1 !tr_eq_tr_equiv p, exact trunc_trunc_equiv_left _ !minus_one_le_succ q }, { exact sorry }, { exact sorry } end definition ptrunc_component (n : ℕ₋₂) (A : Type*) : ptrunc n (component A) ≃* component (ptrunc n A) := begin cases n with n, exact sorry, cases n with n, exact sorry, exact ptrunc_component' n A end definition break_into_components (A : Type) : A ≃ Σ(x : trunc 0 A), Σ(a : A), ∥ tr a = x ∥ := calc A ≃ Σ(a : A) (x : trunc 0 A), tr a = x : by exact (@sigma_equiv_of_is_contr_right _ _ (λa, !is_contr_sigma_eq))⁻¹ᵉ ... ≃ Σ(x : trunc 0 A) (a : A), tr a = x : by apply sigma_comm_equiv ... ≃ Σ(x : trunc 0 A), Σ(a : A), ∥ tr a = x ∥ : by exact sigma_equiv_sigma_right (λx, sigma_equiv_sigma_right (λa, !trunc_equiv⁻¹ᵉ)) definition pfiber_pequiv_component_of_is_contr [constructor] {A B : Type*} (f : A →* B) [is_contr B] /- extra condition, something like trunc_functor 0 f is an embedding -/ : pfiber f ≃* component A := sorry end misc namespace sphere -- definition constant_sphere_map_sphere {n m : ℕ} (H : n < m) (f : S n →* S m) : -- f ~* pconst (S n) (S m) := -- begin -- assert H : is_contr (Ω[n] (S m)), -- { apply homotopy_group_sphere_le, }, -- apply phomotopy_of_eq, -- apply eq_of_fn_eq_fn !sphere_pmap_pequiv, -- apply @is_prop.elim -- end end sphere section injective_surjective open trunc fiber image /- do we want to prove this without funext before we move it? -/ variables {A B C : Type} (f : A → B) definition is_embedding_factor [is_set A] [is_set B] (g : B → C) (h : A → C) (H : g ∘ f ~ h) : is_embedding h → is_embedding f := begin induction H using homotopy.rec_on_idp, intro E, fapply is_embedding_of_is_injective, intro x y p, fapply @is_injective_of_is_embedding _ _ _ E _ _ (ap g p) end definition is_surjective_factor (g : B → C) (h : A → C) (H : g ∘ f ~ h) : is_surjective h → is_surjective g := begin induction H using homotopy.rec_on_idp, intro S, intro c, note p := S c, induction p, apply tr, fapply fiber.mk, exact f a, exact p end end injective_surjective -- Yuri Sulyma's code from HoTT MRC notation `⅀→`:(max+5) := susp_functor notation `⅀⇒`:(max+5) := susp_functor_phomotopy notation `Ω⇒`:(max+5) := ap1_phomotopy definition ap1_phomotopy_symm {A B : Type*} {f g : A →* B} (p : f ~* g) : (Ω⇒ p)⁻¹* = Ω⇒ (p⁻¹*) := begin induction p using phomotopy_rec_idp, rewrite ap1_phomotopy_refl, xrewrite [+refl_symm], rewrite ap1_phomotopy_refl end definition ap1_phomotopy_trans {A B : Type*} {f g h : A →* B} (q : g ~* h) (p : f ~* g) : Ω⇒ (p ⬝* q) = Ω⇒ p ⬝* Ω⇒ q := begin induction p using phomotopy_rec_idp, induction q using phomotopy_rec_idp, rewrite trans_refl, rewrite [+ap1_phomotopy_refl], rewrite trans_refl end namespace pointed definition pbool_pequiv_add_point_unit [constructor] : pbool ≃* unit₊ := pequiv_of_equiv (bool_equiv_option_unit) idp definition to_homotopy_pt_mk {A B : Type*} {f g : A →* B} (h : f ~ g) (p : h pt ⬝ respect_pt g = respect_pt f) : to_homotopy_pt (phomotopy.mk h p) = p := to_right_inv !eq_con_inv_equiv_con_eq p variables {A₀₀ A₂₀ A₀₂ A₂₂ : Type*} {f₁₀ : A₀₀ →* A₂₀} {f₁₂ : A₀₂ →* A₂₂} {f₀₁ : A₀₀ →* A₀₂} {f₂₁ : A₂₀ →* A₂₂} definition psquare_transpose (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) : psquare f₀₁ f₂₁ f₁₀ f₁₂ := p⁻¹* end pointed namespace pi definition pi_bool_left_nat {A B : bool → Type} (g : Πx, A x -> B x) : hsquare (pi_bool_left A) (pi_bool_left B) (pi_functor_right g) (prod_functor (g ff) (g tt)) := begin intro h, esimp end definition pi_bool_left_inv_nat {A B : bool → Type} (g : Πx, A x -> B x) : hsquare (pi_bool_left A)⁻¹ᵉ (pi_bool_left B)⁻¹ᵉ (prod_functor (g ff) (g tt)) (pi_functor_right g) := hhinverse (pi_bool_left_nat g) end pi namespace sum infix ` +→ `:62 := sum_functor variables {A₀₀ A₂₀ A₀₂ A₂₂ B₀₀ B₂₀ B₀₂ B₂₂ A A' B B' C C' : Type} {f₁₀ : A₀₀ → A₂₀} {f₁₂ : A₀₂ → A₂₂} {f₀₁ : A₀₀ → A₀₂} {f₂₁ : A₂₀ → A₂₂} {g₁₀ : B₀₀ → B₂₀} {g₁₂ : B₀₂ → B₂₂} {g₀₁ : B₀₀ → B₀₂} {g₂₁ : B₂₀ → B₂₂} {h₀₁ : B₀₀ → A₀₂} {h₂₁ : B₂₀ → A₂₂} definition flip_flip (x : A ⊎ B) : flip (flip x) = x := begin induction x: reflexivity end definition sum_rec_hsquare [unfold 16] (h : hsquare f₁₀ f₁₂ f₀₁ f₂₁) (k : hsquare g₁₀ f₁₂ h₀₁ h₂₁) : hsquare (f₁₀ +→ g₁₀) f₁₂ (sum.rec f₀₁ h₀₁) (sum.rec f₂₁ h₂₁) := begin intro x, induction x with a b, exact h a, exact k b end definition sum_functor_hsquare [unfold 19] (h : hsquare f₁₀ f₁₂ f₀₁ f₂₁) (k : hsquare g₁₀ g₁₂ g₀₁ g₂₁) : hsquare (f₁₀ +→ g₁₀) (f₁₂ +→ g₁₂) (f₀₁ +→ g₀₁) (f₂₁ +→ g₂₁) := sum_rec_hsquare (λa, ap inl (h a)) (λb, ap inr (k b)) definition sum_functor_compose (g : B → C) (f : A → B) (g' : B' → C') (f' : A' → B') : (g ∘ f) +→ (g' ∘ f') ~ g +→ g' ∘ f +→ f' := begin intro x, induction x with a a': reflexivity end definition sum_rec_sum_functor (g : B → C) (g' : B' → C) (f : A → B) (f' : A' → B') : sum.rec g g' ∘ sum_functor f f' ~ sum.rec (g ∘ f) (g' ∘ f') := begin intro x, induction x with a a': reflexivity end definition sum_rec_same_compose (g : B → C) (f : A → B) : sum.rec (g ∘ f) (g ∘ f) ~ g ∘ sum.rec f f := begin intro x, induction x with a a': reflexivity end definition sum_rec_same (f : A → B) : sum.rec f f ~ f ∘ sum.rec id id := sum_rec_same_compose f id end sum namespace prod infix ` ×→ `:63 := prod_functor infix ` ×≃ `:63 := prod_equiv_prod end prod namespace equiv definition rec_eq_of_equiv {A : Type} {P : A → A → Type} (e : Πa a', a = a' ≃ P a a') {a a' : A} (Q : P a a' → Type) (H : Π(q : a = a'), Q (e a a' q)) : Π(p : P a a'), Q p := equiv_rect (e a a') Q H definition rec_idp_of_equiv {A : Type} {P : A → A → Type} (e : Πa a', a = a' ≃ P a a') {a : A} (r : P a a) (s : e a a idp = r) (Q : Πa', P a a' → Type) (H : Q a r) ⦃a' : A⦄ (p : P a a') : Q a' p := rec_eq_of_equiv e _ begin intro q, induction q, induction s, exact H end p definition rec_idp_of_equiv_idp {A : Type} {P : A → A → Type} (e : Πa a', a = a' ≃ P a a') {a : A} (r : P a a) (s : e a a idp = r) (Q : Πa', P a a' → Type) (H : Q a r) : rec_idp_of_equiv e r s Q H r = H := begin induction s, refine !is_equiv_rect_comp ⬝ _, reflexivity end end equiv namespace paths variables {A : Type} {R : A → A → Type} {a₁ a₂ a₃ a₄ : A} inductive all (T : Π⦃a₁ a₂ : A⦄, R a₁ a₂ → Type) : Π⦃a₁ a₂ : A⦄, paths R a₁ a₂ → Type := | nil {} : Π{a : A}, all T (@nil A R a) | cons : Π{a₁ a₂ a₃ : A} {r : R a₂ a₃} {p : paths R a₁ a₂}, T r → all T p → all T (cons r p) inductive Exists (T : Π⦃a₁ a₂ : A⦄, R a₁ a₂ → Type) : Π⦃a₁ a₂ : A⦄, paths R a₁ a₂ → Type := | base : Π{a₁ a₂ a₃ : A} {r : R a₂ a₃} (p : paths R a₁ a₂), T r → Exists T (cons r p) | cons : Π{a₁ a₂ a₃ : A} (r : R a₂ a₃) {p : paths R a₁ a₂}, Exists T p → Exists T (cons r p) inductive mem (l : R a₃ a₄) : Π⦃a₁ a₂ : A⦄, paths R a₁ a₂ → Type := | base : Π{a₂ : A} (p : paths R a₂ a₃), mem l (cons l p) | cons : Π{a₁ a₂ a₃ : A} (r : R a₂ a₃) {p : paths R a₁ a₂}, mem l p → mem l (cons r p) definition len (p : paths R a₁ a₂) : ℕ := begin induction p with a a₁ a₂ a₃ r p IH, { exact 0 }, { exact nat.succ IH } end definition mem_equiv_Exists (l : R a₁ a₂) (p : paths R a₃ a₄) : mem l p ≃ Exists (λa a' r, ⟨a₁, a₂, l⟩ = ⟨a, a', r⟩) p := sorry end paths namespace list open is_trunc trunc sigma.ops prod.ops lift variables {A B X : Type} definition foldl_homotopy {f g : A → B → A} (h : f ~2 g) (a : A) : foldl f a ~ foldl g a := begin intro bs, revert a, induction bs with b bs p: intro a, reflexivity, esimp [foldl], exact p (f a b) ⬝ ap010 (foldl g) (h a b) bs end definition cons_eq_cons {x x' : X} {l l' : list X} (p : x::l = x'::l') : x = x' × l = l' := begin refine lift.down (list.no_confusion p _), intro q r, split, exact q, exact r end definition concat_neq_nil (x : X) (l : list X) : concat x l ≠ nil := begin intro p, cases l: cases p, end definition concat_eq_singleton {x x' : X} {l : list X} (p : concat x l = [x']) : x = x' × l = [] := begin cases l with x₂ l, { cases cons_eq_cons p with q r, subst q, split: reflexivity }, { exfalso, esimp [concat] at p, apply concat_neq_nil x l, revert p, generalize (concat x l), intro l' p, cases cons_eq_cons p with q r, exact r } end definition foldr_concat (f : A → B → B) (b : B) (a : A) (l : list A) : foldr f b (concat a l) = foldr f (f a b) l := begin induction l with a' l p, reflexivity, rewrite [concat_cons, foldr_cons, p] end definition iterated_prod (X : Type.{u}) (n : ℕ) : Type.{u} := iterate (prod X) n (lift unit) definition is_trunc_iterated_prod {k : ℕ₋₂} {X : Type} {n : ℕ} (H : is_trunc k X) : is_trunc k (iterated_prod X n) := begin induction n with n IH, { apply is_trunc_of_is_contr, apply is_trunc_lift }, { exact @is_trunc_prod _ _ _ H IH } end definition list_of_iterated_prod {n : ℕ} (x : iterated_prod X n) : list X := begin induction n with n IH, { exact [] }, { exact x.1::IH x.2 } end definition list_of_iterated_prod_succ {n : ℕ} (x : X) (xs : iterated_prod X n) : @list_of_iterated_prod X (succ n) (x, xs) = x::list_of_iterated_prod xs := by reflexivity definition iterated_prod_of_list (l : list X) : Σn, iterated_prod X n := begin induction l with x l IH, { exact ⟨0, up ⋆⟩ }, { exact ⟨succ IH.1, (x, IH.2)⟩ } end definition iterated_prod_of_list_cons (x : X) (l : list X) : iterated_prod_of_list (x::l) = ⟨succ (iterated_prod_of_list l).1, (x, (iterated_prod_of_list l).2)⟩ := by reflexivity protected definition sigma_char [constructor] (X : Type) : list X ≃ Σ(n : ℕ), iterated_prod X n := begin apply equiv.MK iterated_prod_of_list (λv, list_of_iterated_prod v.2), { intro x, induction x with n x, esimp, induction n with n IH, { induction x with x, induction x, reflexivity }, { revert x, change Π(x : X × iterated_prod X n), _, intro xs, cases xs with x xs, rewrite [list_of_iterated_prod_succ, iterated_prod_of_list_cons], apply sigma_eq (ap succ (IH xs)..1), apply pathover_ap, refine prod_pathover _ _ _ _ (IH xs)..2, apply pathover_of_eq, reflexivity }}, { intro l, induction l with x l IH, { reflexivity }, { exact ap011 cons idp IH }} end local attribute [instance] is_trunc_iterated_prod definition is_trunc_list [instance] {n : ℕ₋₂} {X : Type} (H : is_trunc (n.+2) X) : is_trunc (n.+2) (list X) := begin assert H : is_trunc (n.+2) (Σ(k : ℕ), iterated_prod X k), { apply is_trunc_sigma, apply is_trunc_succ_succ_of_is_set, intro, exact is_trunc_iterated_prod H }, apply is_trunc_equiv_closed_rev _ (list.sigma_char X), end end list namespace susp open trunc_index /- move to freudenthal -/ definition freudenthal_pequiv_trunc_index' (A : Type*) (n : ℕ) (k : ℕ₋₂) [HA : is_conn n A] (H : k ≤ of_nat (2 * n)) : ptrunc k A ≃* ptrunc k (Ω (susp A)) := begin assert lem : Π(l : ℕ₋₂), l ≤ 0 → ptrunc l A ≃* ptrunc l (Ω (susp A)), { intro l H', exact ptrunc_pequiv_ptrunc_of_le H' (freudenthal_pequiv A (zero_le (2 * n))) }, cases k with k, { exact lem -2 (minus_two_le 0) }, cases k with k, { exact lem -1 (succ_le_succ (minus_two_le -1)) }, rewrite [-of_nat_add_two at *, add_two_sub_two at HA], exact freudenthal_pequiv A (le_of_of_nat_le_of_nat H) end end susp /- namespace logic? -/ namespace decidable definition double_neg_elim {A : Type} (H : decidable A) (p : ¬ ¬ A) : A := begin induction H, assumption, contradiction end definition dite_true {C : Type} [H : decidable C] {A : Type} {t : C → A} {e : ¬ C → A} (c : C) (H' : is_prop C) : dite C t e = t c := begin induction H with H H, exact ap t !is_prop.elim, contradiction end definition dite_false {C : Type} [H : decidable C] {A : Type} {t : C → A} {e : ¬ C → A} (c : ¬ C) : dite C t e = e c := begin induction H with H H, contradiction, exact ap e !is_prop.elim, end definition decidable_eq_of_is_prop (A : Type) [is_prop A] : decidable_eq A := λa a', decidable.inl !is_prop.elim definition decidable_eq_sigma [instance] {A : Type} (B : A → Type) [HA : decidable_eq A] [HB : Πa, decidable_eq (B a)] : decidable_eq (Σa, B a) := begin intro v v', induction v with a b, induction v' with a' b', cases HA a a' with p np, { induction p, cases HB a b b' with q nq, induction q, exact decidable.inl idp, apply decidable.inr, intro p, apply nq, apply @eq_of_pathover_idp A B, exact change_path !is_prop.elim p..2 }, { apply decidable.inr, intro p, apply np, exact p..1 } end open sum definition decidable_eq_sum [instance] (A B : Type) [HA : decidable_eq A] [HB : decidable_eq B] : decidable_eq (A ⊎ B) := begin intro v v', induction v with a b: induction v' with a' b', { cases HA a a' with p np, { exact decidable.inl (ap sum.inl p) }, { apply decidable.inr, intro p, cases p, apply np, reflexivity }}, { apply decidable.inr, intro p, cases p }, { apply decidable.inr, intro p, cases p }, { cases HB b b' with p np, { exact decidable.inl (ap sum.inr p) }, { apply decidable.inr, intro p, cases p, apply np, reflexivity }}, end end decidable namespace category open functor /- shortening pullback to pb to keep names relatively short -/ definition pb_precategory [constructor] {A B : Type} (f : A → B) (C : precategory B) : precategory A := precategory.mk (λa a', hom (f a) (f a')) (λa a' a'' h g, h ∘ g) (λa, ID (f a)) (λa a' a'' a''' k h g, assoc k h g) (λa a' g, id_left g) (λa a' g, id_right g) definition pb_Precategory [constructor] {A : Type} (C : Precategory) (f : A → C) : Precategory := Precategory.mk A (pb_precategory f C) definition pb_Precategory_functor [constructor] {A : Type} (C : Precategory) (f : A → C) : pb_Precategory C f ⇒ C := functor.mk f (λa a' g, g) proof (λa, idp) qed proof (λa a' a'' h g, idp) qed definition fully_faithful_pb_Precategory_functor {A : Type} (C : Precategory) (f : A → C) : fully_faithful (pb_Precategory_functor C f) := begin intro a a', apply is_equiv_id end definition split_essentially_surjective_pb_Precategory_functor {A : Type} (C : Precategory) (f : A → C) (H : is_split_surjective f) : split_essentially_surjective (pb_Precategory_functor C f) := begin intro c, cases H c with a p, exact ⟨a, iso.iso_of_eq p⟩ end definition is_equivalence_pb_Precategory_functor {A : Type} (C : Precategory) (f : A → C) (H : is_split_surjective f) : is_equivalence (pb_Precategory_functor C f) := @(is_equivalence_of_fully_faithful_of_split_essentially_surjective _) (fully_faithful_pb_Precategory_functor C f) (split_essentially_surjective_pb_Precategory_functor C f H) definition pb_Precategory_equivalence [constructor] {A : Type} (C : Precategory) (f : A → C) (H : is_split_surjective f) : pb_Precategory C f ≃c C := equivalence.mk _ (is_equivalence_pb_Precategory_functor C f H) definition pb_Precategory_equivalence_of_equiv [constructor] {A : Type} (C : Precategory) (f : A ≃ C) : pb_Precategory C f ≃c C := pb_Precategory_equivalence C f (is_split_surjective_of_is_retraction f) definition is_isomorphism_pb_Precategory_functor [constructor] {A : Type} (C : Precategory) (f : A ≃ C) : is_isomorphism (pb_Precategory_functor C f) := (fully_faithful_pb_Precategory_functor C f, to_is_equiv f) definition pb_Precategory_isomorphism [constructor] {A : Type} (C : Precategory) (f : A ≃ C) : pb_Precategory C f ≅c C := isomorphism.mk _ (is_isomorphism_pb_Precategory_functor C f) end category
d02fd658678701338af34a00e168ec3f2cae3c08
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/data/list/of_fn.lean
44aba8e1e482fc096517e159e295086e15b289e9
[ "Apache-2.0" ]
permissive
lacker/mathlib
f2439c743c4f8eb413ec589430c82d0f73b2d539
ddf7563ac69d42cfa4a1bfe41db1fed521bd795f
refs/heads/master
1,671,948,326,773
1,601,479,268,000
1,601,479,268,000
298,686,743
0
0
Apache-2.0
1,601,070,794,000
1,601,070,794,000
null
UTF-8
Lean
false
false
3,221
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import data.list.basic import data.fin universes u variables {α : Type u} open nat namespace list /- of_fn -/ theorem length_of_fn_aux {n} (f : fin n → α) : ∀ m h l, length (of_fn_aux f m h l) = length l + m | 0 h l := rfl | (succ m) h l := (length_of_fn_aux m _ _).trans (succ_add _ _) @[simp] theorem length_of_fn {n} (f : fin n → α) : length (of_fn f) = n := (length_of_fn_aux f _ _ _).trans (zero_add _) theorem nth_of_fn_aux {n} (f : fin n → α) (i) : ∀ m h l, (∀ i, nth l i = of_fn_nth_val f (i + m)) → nth (of_fn_aux f m h l) i = of_fn_nth_val f i | 0 h l H := H i | (succ m) h l H := nth_of_fn_aux m _ _ begin intro j, cases j with j, { simp only [nth, of_fn_nth_val, zero_add, dif_pos (show m < n, from h)] }, { simp only [nth, H, succ_add] } end @[simp] theorem nth_of_fn {n} (f : fin n → α) (i) : nth (of_fn f) i = of_fn_nth_val f i := nth_of_fn_aux f _ _ _ _ $ λ i, by simp only [of_fn_nth_val, dif_neg (not_lt.2 (le_add_left n i))]; refl theorem nth_le_of_fn {n} (f : fin n → α) (i : fin n) : nth_le (of_fn f) i ((length_of_fn f).symm ▸ i.2) = f i := option.some.inj $ by rw [← nth_le_nth]; simp only [list.nth_of_fn, of_fn_nth_val, fin.eta, dif_pos i.is_lt] @[simp] theorem nth_le_of_fn' {n} (f : fin n → α) {i : ℕ} (h : i < (of_fn f).length) : nth_le (of_fn f) i h = f ⟨i, ((length_of_fn f) ▸ h)⟩ := nth_le_of_fn f ⟨i, ((length_of_fn f) ▸ h)⟩ @[simp] lemma map_of_fn {β : Type*} {n : ℕ} (f : fin n → α) (g : α → β) : map g (of_fn f) = of_fn (g ∘ f) := ext_le (by simp) (λ i h h', by simp) theorem array_eq_of_fn {n} (a : array n α) : a.to_list = of_fn a.read := suffices ∀ {m h l}, d_array.rev_iterate_aux a (λ i, cons) m h l = of_fn_aux (d_array.read a) m h l, from this, begin intros, induction m with m IH generalizing l, {refl}, simp only [d_array.rev_iterate_aux, of_fn_aux, IH] end theorem of_fn_zero (f : fin 0 → α) : of_fn f = [] := rfl theorem of_fn_succ {n} (f : fin (succ n) → α) : of_fn f = f 0 :: of_fn (λ i, f i.succ) := suffices ∀ {m h l}, of_fn_aux f (succ m) (succ_le_succ h) l = f 0 :: of_fn_aux (λ i, f i.succ) m h l, from this, begin intros, induction m with m IH generalizing l, {refl}, rw [of_fn_aux, IH], refl end theorem of_fn_nth_le : ∀ l : list α, of_fn (λ i, nth_le l i i.2) = l | [] := rfl | (a::l) := by { rw of_fn_succ, congr, simp only [fin.coe_succ], exact of_fn_nth_le l } -- not registered as a simp lemma, as otherwise it fires before `forall_mem_of_fn_iff` which -- is much more useful lemma mem_of_fn {n} (f : fin n → α) (a : α) : a ∈ of_fn f ↔ a ∈ set.range f := begin simp only [mem_iff_nth_le, set.mem_range, nth_le_of_fn'], exact ⟨λ ⟨i, hi, h⟩, ⟨_, h⟩, λ ⟨i, hi⟩, ⟨i.1, (length_of_fn f).symm ▸ i.2, by simpa using hi⟩⟩ end @[simp] lemma forall_mem_of_fn_iff {n : ℕ} {f : fin n → α} {P : α → Prop} : (∀ i ∈ of_fn f, P i) ↔ ∀ j : fin n, P (f j) := by simp only [mem_of_fn, set.forall_range_iff] end list
4c1679c673a8b9679642b2608e816b13d313fd8a
dc06cc9775d64d571bf4778459ec6fde1f344116
/src/ring_theory/ideals.lean
078a201e7cad1ac86372271f832ade6dbb7f9e06
[ "Apache-2.0" ]
permissive
mgubi/mathlib
8c1ea39035776ad52cf189a7af8cc0eee7dea373
7c09ed5eec8434176fbc493e0115555ccc4c8f99
refs/heads/master
1,642,222,572,514
1,563,782,424,000
1,563,782,424,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
18,751
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import algebra.associated linear_algebra.basic order.zorn universes u v variables {α : Type u} {β : Type v} {a b : α} open set function lattice local attribute [instance] classical.prop_decidable namespace ideal variables [comm_ring α] (I : ideal α) @[extensionality] lemma ext {I J : ideal α} (h : ∀ x, x ∈ I ↔ x ∈ J) : I = J := submodule.ext h theorem eq_top_of_unit_mem (x y : α) (hx : x ∈ I) (h : y * x = 1) : I = ⊤ := eq_top_iff.2 $ λ z _, calc z = z * (y * x) : by simp [h] ... = (z * y) * x : eq.symm $ mul_assoc z y x ... ∈ I : I.mul_mem_left hx theorem eq_top_of_is_unit_mem {x} (hx : x ∈ I) (h : is_unit x) : I = ⊤ := let ⟨y, hy⟩ := is_unit_iff_exists_inv'.1 h in eq_top_of_unit_mem I x y hx hy theorem eq_top_iff_one : I = ⊤ ↔ (1:α) ∈ I := ⟨by rintro rfl; trivial, λ h, eq_top_of_unit_mem _ _ 1 h (by simp)⟩ theorem ne_top_iff_one : I ≠ ⊤ ↔ (1:α) ∉ I := not_congr I.eq_top_iff_one def span (s : set α) : ideal α := submodule.span α s lemma subset_span {s : set α} : s ⊆ span s := submodule.subset_span lemma span_le {s : set α} {I} : span s ≤ I ↔ s ⊆ I := submodule.span_le lemma span_mono {s t : set α} : s ⊆ t → span s ≤ span t := submodule.span_mono @[simp] lemma span_eq : span (I : set α) = I := submodule.span_eq _ @[simp] lemma span_singleton_one : span ({1} : set α) = ⊤ := (eq_top_iff_one _).2 $ subset_span $ mem_singleton _ lemma mem_span_insert {s : set α} {x y} : x ∈ span (insert y s) ↔ ∃ a (z ∈ span s), x = a * y + z := submodule.mem_span_insert lemma mem_span_insert' {s : set α} {x y} : x ∈ span (insert y s) ↔ ∃a, x + a * y ∈ span s := submodule.mem_span_insert' lemma mem_span_singleton' {x y : α} : x ∈ span ({y} : set α) ↔ ∃ a, a * y = x := submodule.mem_span_singleton lemma mem_span_singleton {x y : α} : x ∈ span ({y} : set α) ↔ y ∣ x := mem_span_singleton'.trans $ exists_congr $ λ _, by rw [eq_comm, mul_comm]; refl lemma span_singleton_le_span_singleton {x y : α} : span ({x} : set α) ≤ span ({y} : set α) ↔ y ∣ x := span_le.trans $ singleton_subset_iff.trans mem_span_singleton lemma span_eq_bot {s : set α} : span s = ⊥ ↔ ∀ x ∈ s, (x:α) = 0 := submodule.span_eq_bot lemma span_singleton_eq_bot {x} : span ({x} : set α) = ⊥ ↔ x = 0 := submodule.span_singleton_eq_bot lemma span_singleton_eq_top {x} : span ({x} : set α) = ⊤ ↔ is_unit x := by rw [is_unit_iff_dvd_one, ← span_singleton_le_span_singleton, span_singleton_one, eq_top_iff] @[class] def is_prime (I : ideal α) : Prop := I ≠ ⊤ ∧ ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I theorem is_prime.mem_or_mem {I : ideal α} (hI : I.is_prime) : ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I := hI.2 theorem is_prime.mem_or_mem_of_mul_eq_zero {I : ideal α} (hI : I.is_prime) {x y : α} (h : x * y = 0) : x ∈ I ∨ y ∈ I := hI.2 (h.symm ▸ I.zero_mem) theorem is_prime.mem_of_pow_mem {I : ideal α} (hI : I.is_prime) {r : α} (n : ℕ) (H : r^n ∈ I) : r ∈ I := begin induction n with n ih, { exact (mt (eq_top_iff_one _).2 hI.1).elim H }, exact or.cases_on (hI.mem_or_mem H) id ih end @[class] def zero_ne_one_of_proper {I : ideal α} (h : I ≠ ⊤) : (0:α) ≠ 1 := λ hz, I.ne_top_iff_one.1 h $ hz ▸ I.zero_mem theorem span_singleton_prime {p : α} (hp : p ≠ 0) : is_prime (span ({p} : set α)) ↔ prime p := by simp [is_prime, prime, span_singleton_eq_top, hp, mem_span_singleton] @[class] def is_maximal (I : ideal α) : Prop := I ≠ ⊤ ∧ ∀ J, I < J → J = ⊤ theorem is_maximal_iff {I : ideal α} : I.is_maximal ↔ (1:α) ∉ I ∧ ∀ (J : ideal α) x, I ≤ J → x ∉ I → x ∈ J → (1:α) ∈ J := and_congr I.ne_top_iff_one $ forall_congr $ λ J, by rw [lt_iff_le_not_le]; exact ⟨λ H x h hx₁ hx₂, J.eq_top_iff_one.1 $ H ⟨h, not_subset.2 ⟨_, hx₂, hx₁⟩⟩, λ H ⟨h₁, h₂⟩, let ⟨x, xJ, xI⟩ := not_subset.1 h₂ in J.eq_top_iff_one.2 $ H x h₁ xI xJ⟩ theorem is_maximal.eq_of_le {I J : ideal α} (hI : I.is_maximal) (hJ : J ≠ ⊤) (IJ : I ≤ J) : I = J := eq_iff_le_not_lt.2 ⟨IJ, λ h, hJ (hI.2 _ h)⟩ theorem is_maximal.exists_inv {I : ideal α} (hI : I.is_maximal) {x} (hx : x ∉ I) : ∃ y, y * x - 1 ∈ I := begin cases is_maximal_iff.1 hI with H₁ H₂, rcases mem_span_insert'.1 (H₂ (span (insert x I)) x (set.subset.trans (subset_insert _ _) subset_span) hx (subset_span (mem_insert _ _))) with ⟨y, hy⟩, rw [span_eq, ← neg_mem_iff, add_comm, neg_add', neg_mul_eq_neg_mul] at hy, exact ⟨-y, hy⟩ end theorem is_maximal.is_prime {I : ideal α} (H : I.is_maximal) : I.is_prime := ⟨H.1, λ x y hxy, or_iff_not_imp_left.2 $ λ hx, begin cases H.exists_inv hx with z hz, have := I.mul_mem_left hz, rw [mul_sub, mul_one, mul_comm, mul_assoc] at this, exact I.neg_mem_iff.1 ((I.add_mem_iff_right $ I.mul_mem_left hxy).1 this) end⟩ instance is_maximal.is_prime' (I : ideal α) : ∀ [H : I.is_maximal], I.is_prime := is_maximal.is_prime theorem exists_le_maximal (I : ideal α) (hI : I ≠ ⊤) : ∃ M : ideal α, M.is_maximal ∧ I ≤ M := begin rcases zorn.zorn_partial_order₀ { J : ideal α | J ≠ ⊤ } _ I hI with ⟨M, M0, IM, h⟩, { refine ⟨M, ⟨M0, λ J hJ, by_contradiction $ λ J0, _⟩, IM⟩, cases h J J0 (le_of_lt hJ), exact lt_irrefl _ hJ }, { intros S SC cC I IS, refine ⟨Sup S, λ H, _, λ _, le_Sup⟩, rcases submodule.mem_Sup_of_directed ((eq_top_iff_one _).1 H) I IS cC.directed_on with ⟨J, JS, J0⟩, exact SC JS ((eq_top_iff_one _).2 J0) } end def is_coprime (x y : α) : Prop := span ({x, y} : set α) = ⊤ theorem mem_span_pair [comm_ring α] {x y z : α} : z ∈ span (insert y {x} : set α) ↔ ∃ a b, a * x + b * y = z := begin simp only [mem_span_insert, mem_span_singleton', exists_prop], split, { rintros ⟨a, b, ⟨c, hc⟩, h⟩, exact ⟨c, a, by simp [h, hc]⟩ }, { rintro ⟨b, c, e⟩, exact ⟨c, b * x, ⟨b, rfl⟩, by simp [e.symm]⟩ } end theorem is_coprime_def [comm_ring α] {x y : α} : is_coprime x y ↔ ∀ z, ∃ a b, a * x + b * y = z := by simp [is_coprime, submodule.eq_top_iff', mem_span_pair] theorem is_coprime_self [comm_ring α] (x y : α) : is_coprime x x ↔ is_unit x := by rw [← span_singleton_eq_top]; simp [is_coprime] lemma span_singleton_lt_span_singleton [integral_domain β] {x y : β} : span ({x} : set β) < span ({y} : set β) ↔ y ≠ 0 ∧ ∃ d : β, ¬ is_unit d ∧ x = y * d := by rw [lt_iff_le_not_le, span_singleton_le_span_singleton, span_singleton_le_span_singleton, dvd_and_not_dvd_iff] def quotient (I : ideal α) := I.quotient namespace quotient variables {I} {x y : α} def mk (I : ideal α) (a : α) : I.quotient := submodule.quotient.mk a protected theorem eq : mk I x = mk I y ↔ x - y ∈ I := submodule.quotient.eq I instance (I : ideal α) : has_one I.quotient := ⟨mk I 1⟩ @[simp] lemma mk_one (I : ideal α) : mk I 1 = 1 := rfl instance (I : ideal α) : has_mul I.quotient := ⟨λ a b, quotient.lift_on₂' a b (λ a b, mk I (a * b)) $ λ a₁ a₂ b₁ b₂ h₁ h₂, quot.sound $ begin refine calc a₁ * a₂ - b₁ * b₂ = a₂ * (a₁ - b₁) + (a₂ - b₂) * b₁ : _ ... ∈ I : I.add_mem (I.mul_mem_left h₁) (I.mul_mem_right h₂), rw [mul_sub, sub_mul, sub_add_sub_cancel, mul_comm, mul_comm b₁] end⟩ @[simp] theorem mk_mul : mk I (x * y) = mk I x * mk I y := rfl instance (I : ideal α) : comm_ring I.quotient := { mul := (*), one := 1, mul_assoc := λ a b c, quotient.induction_on₃' a b c $ λ a b c, congr_arg (mk _) (mul_assoc a b c), mul_comm := λ a b, quotient.induction_on₂' a b $ λ a b, congr_arg (mk _) (mul_comm a b), one_mul := λ a, quotient.induction_on' a $ λ a, congr_arg (mk _) (one_mul a), mul_one := λ a, quotient.induction_on' a $ λ a, congr_arg (mk _) (mul_one a), left_distrib := λ a b c, quotient.induction_on₃' a b c $ λ a b c, congr_arg (mk _) (left_distrib a b c), right_distrib := λ a b c, quotient.induction_on₃' a b c $ λ a b c, congr_arg (mk _) (right_distrib a b c), ..submodule.quotient.add_comm_group I } instance is_ring_hom_mk (I : ideal α) : is_ring_hom (mk I) := ⟨rfl, λ _ _, rfl, λ _ _, rfl⟩ def map_mk (I J : ideal α) : ideal I.quotient := { carrier := mk I '' J, zero := ⟨0, J.zero_mem, rfl⟩, add := by rintro _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩; exact ⟨x + y, J.add_mem hx hy, rfl⟩, smul := by rintro ⟨c⟩ _ ⟨x, hx, rfl⟩; exact ⟨c * x, J.mul_mem_left hx, rfl⟩ } @[simp] lemma mk_zero (I : ideal α) : mk I 0 = 0 := rfl @[simp] lemma mk_add (I : ideal α) (a b : α) : mk I (a + b) = mk I a + mk I b := rfl @[simp] lemma mk_neg (I : ideal α) (a : α) : mk I (-a : α) = -mk I a := rfl @[simp] lemma mk_sub (I : ideal α) (a b : α) : mk I (a - b : α) = mk I a - mk I b := rfl @[simp] lemma mk_pow (I : ideal α) (a : α) (n : ℕ) : mk I (a ^ n : α) = mk I a ^ n := by induction n; simp [*, pow_succ] lemma eq_zero_iff_mem {I : ideal α} : mk I a = 0 ↔ a ∈ I := by conv {to_rhs, rw ← sub_zero a }; exact quotient.eq' theorem zero_eq_one_iff {I : ideal α} : (0 : I.quotient) = 1 ↔ I = ⊤ := eq_comm.trans $ eq_zero_iff_mem.trans (eq_top_iff_one _).symm theorem zero_ne_one_iff {I : ideal α} : (0 : I.quotient) ≠ 1 ↔ I ≠ ⊤ := not_congr zero_eq_one_iff protected def nonzero_comm_ring {I : ideal α} (hI : I ≠ ⊤) : nonzero_comm_ring I.quotient := { zero_ne_one := zero_ne_one_iff.2 hI, ..quotient.comm_ring I } instance (I : ideal α) [hI : I.is_prime] : integral_domain I.quotient := { eq_zero_or_eq_zero_of_mul_eq_zero := λ a b, quotient.induction_on₂' a b $ λ a b hab, (hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim (or.inl ∘ eq_zero_iff_mem.2) (or.inr ∘ eq_zero_iff_mem.2), ..quotient.nonzero_comm_ring hI.1 } lemma exists_inv {I : ideal α} [hI : I.is_maximal] : ∀ {a : I.quotient}, a ≠ 0 → ∃ b : I.quotient, a * b = 1 := begin rintro ⟨a⟩ h, cases hI.exists_inv (mt eq_zero_iff_mem.2 h) with b hb, rw [mul_comm] at hb, exact ⟨mk _ b, quot.sound hb⟩ end /-- quotient by maximal ideal is a field. def rather than instance, since users will have computable inverses in some applications -/ protected noncomputable def field (I : ideal α) [hI : I.is_maximal] : discrete_field I.quotient := { inv := λ a, if ha : a = 0 then 0 else classical.some (exists_inv ha), mul_inv_cancel := λ a (ha : a ≠ 0), show a * dite _ _ _ = _, by rw dif_neg ha; exact classical.some_spec (exists_inv ha), inv_mul_cancel := λ a (ha : a ≠ 0), show dite _ _ _ * a = _, by rw [mul_comm, dif_neg ha]; exact classical.some_spec (exists_inv ha), inv_zero := dif_pos rfl, has_decidable_eq := classical.dec_eq _, ..quotient.integral_domain I } variable [comm_ring β] def lift (S : ideal α) (f : α → β) [is_ring_hom f] (H : ∀ (a : α), a ∈ S → f a = 0) : quotient S → β := λ x, quotient.lift_on' x f $ λ (a b) (h : _ ∈ _), eq_of_sub_eq_zero (by simpa only [is_ring_hom.map_sub f] using H _ h) variables {S : ideal α} {f : α → β} [is_ring_hom f] {H : ∀ (a : α), a ∈ S → f a = 0} @[simp] lemma lift_mk : lift S f H (mk S a) = f a := rfl instance : is_ring_hom (lift S f H) := { map_one := by show lift S f H (mk S 1) = 1; simp [is_ring_hom.map_one f, - mk_one], map_add := λ a₁ a₂, quotient.induction_on₂' a₁ a₂ $ λ a₁ a₂, begin show lift S f H (mk S a₁ + mk S a₂) = lift S f H (mk S a₁) + lift S f H (mk S a₂), have := ideal.quotient.is_ring_hom_mk S, rw ← this.map_add, show lift S f H (mk S (a₁ + a₂)) = lift S f H (mk S a₁) + lift S f H (mk S a₂), simp only [lift_mk, is_ring_hom.map_add f], end, map_mul := λ a₁ a₂, quotient.induction_on₂' a₁ a₂ $ λ a₁ a₂, begin show lift S f H (mk S a₁ * mk S a₂) = lift S f H (mk S a₁) * lift S f H (mk S a₂), have := ideal.quotient.is_ring_hom_mk S, rw ← this.map_mul, show lift S f H (mk S (a₁ * a₂)) = lift S f H (mk S a₁) * lift S f H (mk S a₂), simp only [lift_mk, is_ring_hom.map_mul f], end } end quotient lemma eq_bot_or_top {K : Type u} [discrete_field K] (I : ideal K) : I = ⊥ ∨ I = ⊤ := begin rw classical.or_iff_not_imp_right, change _ ≠ _ → _, rw ideal.ne_top_iff_one, intro h1, rw eq_bot_iff, intros r hr, by_cases H : r = 0, {simpa}, simpa [H, h1] using submodule.smul_mem I r⁻¹ hr, end lemma eq_bot_of_prime {K : Type u} [discrete_field K] (I : ideal K) [h : I.is_prime] : I = ⊥ := classical.or_iff_not_imp_right.mp I.eq_bot_or_top h.1 end ideal def nonunits (α : Type u) [monoid α] : set α := { a | ¬is_unit a } @[simp] theorem mem_nonunits_iff [comm_monoid α] : a ∈ nonunits α ↔ ¬ is_unit a := iff.rfl theorem mul_mem_nonunits_right [comm_monoid α] : b ∈ nonunits α → a * b ∈ nonunits α := mt is_unit_of_mul_is_unit_right theorem mul_mem_nonunits_left [comm_monoid α] : a ∈ nonunits α → a * b ∈ nonunits α := mt is_unit_of_mul_is_unit_left theorem zero_mem_nonunits [semiring α] : 0 ∈ nonunits α ↔ (0:α) ≠ 1 := not_congr is_unit_zero_iff @[simp] theorem one_not_mem_nonunits [monoid α] : (1:α) ∉ nonunits α := not_not_intro is_unit_one theorem coe_subset_nonunits [comm_ring α] {I : ideal α} (h : I ≠ ⊤) : (I : set α) ⊆ nonunits α := λ x hx hu, h $ I.eq_top_of_is_unit_mem hx hu lemma exists_max_ideal_of_mem_nonunits [comm_ring α] (h : a ∈ nonunits α) : ∃ I : ideal α, I.is_maximal ∧ a ∈ I := begin have : ideal.span ({a} : set α) ≠ ⊤, { intro H, rw ideal.span_singleton_eq_top at H, contradiction }, rcases ideal.exists_le_maximal _ this with ⟨I, Imax, H⟩, use [I, Imax], apply H, apply ideal.subset_span, exact set.mem_singleton a end class local_ring (α : Type u) extends nonzero_comm_ring α := (is_local : ∀ (a : α), (is_unit a) ∨ (is_unit (1 - a))) namespace local_ring variable [local_ring α] instance : comm_ring α := by apply_instance lemma is_unit_or_is_unit_one_sub_self (a : α) : (is_unit a) ∨ (is_unit (1 - a)) := is_local a lemma is_unit_of_mem_nonunits_one_sub_self (a : α) (h : (1 - a) ∈ nonunits α) : is_unit a := or_iff_not_imp_right.1 (is_local a) h lemma is_unit_one_sub_self_of_mem_nonunits (a : α) (h : a ∈ nonunits α) : is_unit (1 - a) := or_iff_not_imp_left.1 (is_local a) h lemma nonunits_add {x y} (hx : x ∈ nonunits α) (hy : y ∈ nonunits α) : x + y ∈ nonunits α := begin rintros ⟨u, hu⟩, apply hy, suffices : is_unit ((↑u⁻¹ : α) * y), { rcases this with ⟨s, hs⟩, use u * s, convert congr_arg (λ z, (u : α) * z) hs, rw ← mul_assoc, simp }, rw show (↑u⁻¹ * y) = (1 - ↑u⁻¹ * x), { rw eq_sub_iff_add_eq, replace hu := congr_arg (λ z, (↑u⁻¹ : α) * z) hu, simpa [mul_add] using hu }, apply is_unit_one_sub_self_of_mem_nonunits, exact mul_mem_nonunits_right hx end variable (α) def nonunits_ideal : ideal α := { carrier := nonunits α, zero := zero_mem_nonunits.2 $ zero_ne_one, add := λ x y hx hy, nonunits_add hx hy, smul := λ a x, mul_mem_nonunits_right } instance nonunits_ideal.is_maximal : (nonunits_ideal α).is_maximal := begin rw ideal.is_maximal_iff, split, { intro h, apply h, exact is_unit_one }, { intros I x hI hx H, erw not_not at hx, rcases hx with ⟨u,rfl⟩, simpa using I.smul_mem ↑u⁻¹ H } end lemma max_ideal_unique : ∃! I : ideal α, I.is_maximal := ⟨nonunits_ideal α, nonunits_ideal.is_maximal α, λ I hI, hI.eq_of_le (nonunits_ideal.is_maximal α).1 $ λ x hx, hI.1 ∘ I.eq_top_of_is_unit_mem hx⟩ variable {α} @[simp] lemma mem_nonunits_ideal (x) : x ∈ nonunits_ideal α ↔ x ∈ nonunits α := iff.rfl end local_ring def is_local_ring (α : Type u) [comm_ring α] : Prop := ((0:α) ≠ 1) ∧ ∀ (a : α), (is_unit a) ∨ (is_unit (1 - a)) def local_of_is_local_ring [comm_ring α] (h : is_local_ring α) : local_ring α := { zero_ne_one := h.1, is_local := h.2, .. ‹comm_ring α› } def local_of_unit_or_unit_one_sub [comm_ring α] (hnze : (0:α) ≠ 1) (h : ∀ x : α, is_unit x ∨ is_unit (1 - x)) : local_ring α := local_of_is_local_ring ⟨hnze, h⟩ def local_of_nonunits_ideal [comm_ring α] (hnze : (0:α) ≠ 1) (h : ∀ x y ∈ nonunits α, x + y ∈ nonunits α) : local_ring α := local_of_is_local_ring ⟨hnze, λ x, or_iff_not_imp_left.mpr $ λ hx, begin by_contra H, apply h _ _ hx H, simp [-sub_eq_add_neg, add_sub_cancel'_right] end⟩ def local_of_unique_max_ideal [comm_ring α] (h : ∃! I : ideal α, I.is_maximal) : local_ring α := local_of_nonunits_ideal (let ⟨I, Imax, _⟩ := h in (λ (H : 0 = 1), Imax.1 $ I.eq_top_iff_one.2 $ H ▸ I.zero_mem)) $ λ x y hx hy H, let ⟨I, Imax, Iuniq⟩ := h in let ⟨Ix, Ixmax, Hx⟩ := exists_max_ideal_of_mem_nonunits hx in let ⟨Iy, Iymax, Hy⟩ := exists_max_ideal_of_mem_nonunits hy in have xmemI : x ∈ I, from ((Iuniq Ix Ixmax) ▸ Hx), have ymemI : y ∈ I, from ((Iuniq Iy Iymax) ▸ Hy), Imax.1 $ I.eq_top_of_is_unit_mem (I.add_mem xmemI ymemI) H class is_local_ring_hom [comm_ring α] [comm_ring β] (f : α → β) extends is_ring_hom f : Prop := (map_nonunit : ∀ a, is_unit (f a) → is_unit a) @[simp] lemma is_unit_of_map_unit [comm_ring α] [comm_ring β] (f : α → β) [is_local_ring_hom f] (a) (h : is_unit (f a)) : is_unit a := is_local_ring_hom.map_nonunit a h section open local_ring variables [local_ring α] [local_ring β] variables (f : α → β) [is_local_ring_hom f] lemma map_nonunit (a) (h : a ∈ nonunits_ideal α) : f a ∈ nonunits_ideal β := λ H, h $ is_unit_of_map_unit f a H end namespace local_ring variables [local_ring α] [local_ring β] variable (α) def residue_field := (nonunits_ideal α).quotient namespace residue_field noncomputable instance : discrete_field (residue_field α) := ideal.quotient.field (nonunits_ideal α) variables {α β} noncomputable def map (f : α → β) [is_local_ring_hom f] : residue_field α → residue_field β := ideal.quotient.lift (nonunits_ideal α) (ideal.quotient.mk _ ∘ f) $ λ a ha, begin erw ideal.quotient.eq_zero_iff_mem, exact map_nonunit f a ha end instance map.is_field_hom (f : α → β) [is_local_ring_hom f] : is_field_hom (map f) := ideal.quotient.is_ring_hom end residue_field end local_ring
e9e0920bc39b6524b22d5a842a7b6e2e605b3962
d9ed0fce1c218297bcba93e046cb4e79c83c3af8
/library/tools/super/factoring.lean
628d97c6be3b33f15aa34c62a1fe872c116a6fa4
[ "Apache-2.0" ]
permissive
leodemoura/lean_clone
005c63aa892a6492f2d4741ee3c2cb07a6be9d7f
cc077554b584d39bab55c360bc12a6fe7957afe6
refs/heads/master
1,610,506,475,484
1,482,348,354,000
1,482,348,543,000
77,091,586
0
0
null
null
null
null
UTF-8
Lean
false
false
1,664
lean
/- Copyright (c) 2016 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner -/ import .clause .prover_state .subsumption open tactic expr monad namespace super variable gt : expr → expr → bool meta def inst_lit (c : clause) (i : nat) (e : expr) : tactic clause := do opened ← clause.open_constn c i, return $ clause.close_constn (clause.inst opened.1 e) opened.2 private meta def try_factor' (c : clause) (i j : nat) : tactic clause := do qf ← clause.open_metan c c^.num_quants, unify_lit (qf.1^.get_lit i) (qf.1^.get_lit j), qfi ← clause.inst_mvars qf.1, guard $ clause.is_maximal gt qfi i, at_j ← clause.open_constn qf.1 j, hyp_i ← option.to_monad (list.nth at_j.2 i), clause.meta_closure qf.2 $ (at_j.1^.inst hyp_i)^.close_constn at_j.2 meta def try_factor (c : clause) (i j : nat) : tactic clause := if i > j then try_factor' gt c j i else try_factor' gt c i j meta def try_infer_factor (c : derived_clause) (i j : nat) : prover unit := do f ← ♯ try_factor gt c^.c i j, ss ← ♯ does_subsume f c^.c, if ss then do f ← mk_derived f c^.sc^.sched_now, add_inferred f, remove_redundant c^.id [f] else do inf_score 1 [c^.sc] >>= mk_derived f >>= add_inferred @[super.inf] meta def factor_inf : inf_decl := inf_decl.mk 40 $ take given, do gt ← get_term_order, sequence' $ do i ← given^.selected, j ← list.range given^.c^.num_lits, return $ try_infer_factor gt given i j <|> return () meta def factor_dup_lits_pre := preprocessing_rule $ take new, do ♯ for new $ λdc, do dist ← dc^.c^.distinct, return { dc with c := dist } end super
08d84b42efbcc7a2ade0730e9d3cb854120a3272
626e312b5c1cb2d88fca108f5933076012633192
/src/algebra/module/basic.lean
350ae5b2ed84f1d1c3dead21818b788a27187ce9
[ "Apache-2.0" ]
permissive
Bioye97/mathlib
9db2f9ee54418d29dd06996279ba9dc874fd6beb
782a20a27ee83b523f801ff34efb1a9557085019
refs/heads/master
1,690,305,956,488
1,631,067,774,000
1,631,067,774,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
20,186
lean
/- Copyright (c) 2015 Nathaniel Thomas. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro -/ import algebra.big_operators.basic import algebra.smul_with_zero import group_theory.group_action.group /-! # Modules over a ring In this file we define * `module R M` : an additive commutative monoid `M` is a `module` over a `semiring R` if for `r : R` and `x : M` their "scalar multiplication `r • x : M` is defined, and the operation `•` satisfies some natural associativity and distributivity axioms similar to those on a ring. ## Implementation notes In typical mathematical usage, our definition of `module` corresponds to "semimodule", and the word "module" is reserved for `module R M` where `R` is a `ring` and `M` an `add_comm_group`. If `R` is a `field` and `M` an `add_comm_group`, `M` would be called an `R`-vector space. Since those assumptions can be made by changing the typeclasses applied to `R` and `M`, without changing the axioms in `module`, mathlib calls everything a `module`. In older versions of mathlib, we had separate `semimodule` and `vector_space` abbreviations. This caused inference issues in some cases, while not providing any real advantages, so we decided to use a canonical `module` typeclass throughout. ## Tags semimodule, module, vector space -/ open function open_locale big_operators universes u u' v w x y z variables {R : Type u} {k : Type u'} {S : Type v} {M : Type w} {M₂ : Type x} {M₃ : Type y} {ι : Type z} /-- A module is a generalization of vector spaces to a scalar semiring. It consists of a scalar semiring `R` and an additive monoid of "vectors" `M`, connected by a "scalar multiplication" operation `r • x : M` (where `r : R` and `x : M`) with some natural associativity and distributivity axioms similar to those on a ring. -/ @[protect_proj] class module (R : Type u) (M : Type v) [semiring R] [add_comm_monoid M] extends distrib_mul_action R M := (add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x) (zero_smul : ∀x : M, (0 : R) • x = 0) section add_comm_monoid variables [semiring R] [add_comm_monoid M] [module R M] (r s : R) (x y : M) /-- A module over a semiring automatically inherits a `mul_action_with_zero` structure. -/ @[priority 100] -- see Note [lower instance priority] instance module.to_mul_action_with_zero : mul_action_with_zero R M := { smul_zero := smul_zero, zero_smul := module.zero_smul, ..(infer_instance : mul_action R M) } instance add_comm_monoid.nat_module : module ℕ M := { one_smul := one_nsmul, mul_smul := λ m n a, mul_nsmul a m n, smul_add := λ n a b, nsmul_add a b n, smul_zero := nsmul_zero, zero_smul := zero_nsmul, add_smul := λ r s x, add_nsmul x r s } theorem add_smul : (r + s) • x = r • x + s • x := module.add_smul r s x variables (R) theorem two_smul : (2 : R) • x = x + x := by rw [bit0, add_smul, one_smul] theorem two_smul' : (2 : R) • x = bit0 x := two_smul R x /-- Pullback a `module` structure along an injective additive monoid homomorphism. See note [reducible non-instances]. -/ @[reducible] protected def function.injective.module [add_comm_monoid M₂] [has_scalar R M₂] (f : M₂ →+ M) (hf : injective f) (smul : ∀ (c : R) x, f (c • x) = c • f x) : module R M₂ := { smul := (•), add_smul := λ c₁ c₂ x, hf $ by simp only [smul, f.map_add, add_smul], zero_smul := λ x, hf $ by simp only [smul, zero_smul, f.map_zero], .. hf.distrib_mul_action f smul } /-- Pushforward a `module` structure along a surjective additive monoid homomorphism. -/ protected def function.surjective.module [add_comm_monoid M₂] [has_scalar R M₂] (f : M →+ M₂) (hf : surjective f) (smul : ∀ (c : R) x, f (c • x) = c • f x) : module R M₂ := { smul := (•), add_smul := λ c₁ c₂ x, by { rcases hf x with ⟨x, rfl⟩, simp only [add_smul, ← smul, ← f.map_add] }, zero_smul := λ x, by { rcases hf x with ⟨x, rfl⟩, simp only [← f.map_zero, ← smul, zero_smul] }, .. hf.distrib_mul_action f smul } variables {R} (M) /-- Compose a `module` with a `ring_hom`, with action `f s • m`. See note [reducible non-instances]. -/ @[reducible] def module.comp_hom [semiring S] (f : S →+* R) : module S M := { smul := has_scalar.comp.smul f, add_smul := λ r s x, by simp [add_smul], .. mul_action_with_zero.comp_hom M f.to_monoid_with_zero_hom, .. distrib_mul_action.comp_hom M (f : S →* R) } variables (R) (M) /-- `(•)` as an `add_monoid_hom`. -/ def smul_add_hom : R →+ M →+ M := { to_fun := distrib_mul_action.to_add_monoid_hom M, map_zero' := add_monoid_hom.ext $ λ r, by simp, map_add' := λ x y, add_monoid_hom.ext $ λ r, by simp [add_smul] } variables {R M} @[simp] lemma smul_add_hom_apply (r : R) (x : M) : smul_add_hom R M r x = r • x := rfl @[simp] lemma smul_add_hom_one {R M : Type*} [semiring R] [add_comm_monoid M] [module R M] : smul_add_hom R M 1 = add_monoid_hom.id _ := (distrib_mul_action.to_add_monoid_End R M).map_one lemma module.eq_zero_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : x = 0 := by rw [←one_smul R x, ←zero_eq_one, zero_smul] lemma list.sum_smul {l : list R} {x : M} : l.sum • x = (l.map (λ r, r • x)).sum := ((smul_add_hom R M).flip x).map_list_sum l lemma multiset.sum_smul {l : multiset R} {x : M} : l.sum • x = (l.map (λ r, r • x)).sum := ((smul_add_hom R M).flip x).map_multiset_sum l lemma finset.sum_smul {f : ι → R} {s : finset ι} {x : M} : (∑ i in s, f i) • x = (∑ i in s, (f i) • x) := ((smul_add_hom R M).flip x).map_sum f s end add_comm_monoid variables (R) /-- An `add_comm_monoid` that is a `module` over a `ring` carries a natural `add_comm_group` structure. See note [reducible non-instances]. -/ @[reducible] def module.add_comm_monoid_to_add_comm_group [ring R] [add_comm_monoid M] [module R M] : add_comm_group M := { neg := λ a, (-1 : R) • a, add_left_neg := λ a, show (-1 : R) • a + a = 0, by { nth_rewrite 1 ← one_smul _ a, rw [← add_smul, add_left_neg, zero_smul] }, ..(infer_instance : add_comm_monoid M), } variables {R} section add_comm_group variables (R M) [semiring R] [add_comm_group M] instance add_comm_group.int_module : module ℤ M := { one_smul := one_gsmul, mul_smul := λ m n a, mul_gsmul a m n, smul_add := λ n a b, gsmul_add a b n, smul_zero := gsmul_zero, zero_smul := zero_gsmul, add_smul := λ r s x, add_gsmul x r s } /-- A structure containing most informations as in a module, except the fields `zero_smul` and `smul_zero`. As these fields can be deduced from the other ones when `M` is an `add_comm_group`, this provides a way to construct a module structure by checking less properties, in `module.of_core`. -/ @[nolint has_inhabited_instance] structure module.core extends has_scalar R M := (smul_add : ∀(r : R) (x y : M), r • (x + y) = r • x + r • y) (add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x) (mul_smul : ∀(r s : R) (x : M), (r * s) • x = r • s • x) (one_smul : ∀x : M, (1 : R) • x = x) variables {R M} /-- Define `module` without proving `zero_smul` and `smul_zero` by using an auxiliary structure `module.core`, when the underlying space is an `add_comm_group`. -/ def module.of_core (H : module.core R M) : module R M := by letI := H.to_has_scalar; exact { zero_smul := λ x, (add_monoid_hom.mk' (λ r : R, r • x) (λ r s, H.add_smul r s x)).map_zero, smul_zero := λ r, (add_monoid_hom.mk' ((•) r) (H.smul_add r)).map_zero, ..H } end add_comm_group /-- To prove two module structures on a fixed `add_comm_monoid` agree, it suffices to check the scalar multiplications agree. -/ -- We'll later use this to show `module ℕ M` and `module ℤ M` are subsingletons. @[ext] lemma module_ext {R : Type*} [semiring R] {M : Type*} [add_comm_monoid M] (P Q : module R M) (w : ∀ (r : R) (m : M), by { haveI := P, exact r • m } = by { haveI := Q, exact r • m }) : P = Q := begin unfreezingI { rcases P with ⟨⟨⟨⟨P⟩⟩⟩⟩, rcases Q with ⟨⟨⟨⟨Q⟩⟩⟩⟩ }, congr, funext r m, exact w r m, all_goals { apply proof_irrel_heq }, end section module variables [ring R] [add_comm_group M] [module R M] (r s : R) (x y : M) @[simp] theorem neg_smul : -r • x = - (r • x) := eq_neg_of_add_eq_zero (by rw [← add_smul, add_left_neg, zero_smul]) @[simp] theorem units.neg_smul (u : units R) (x : M) : -u • x = - (u • x) := by rw [units.smul_def, units.coe_neg, neg_smul, units.smul_def] variables (R) theorem neg_one_smul (x : M) : (-1 : R) • x = -x := by simp variables {R} theorem sub_smul (r s : R) (y : M) : (r - s) • y = r • y - s • y := by simp [add_smul, sub_eq_add_neg] end module /-- A module over a `subsingleton` semiring is a `subsingleton`. We cannot register this as an instance because Lean has no way to guess `R`. -/ protected theorem module.subsingleton (R M : Type*) [semiring R] [subsingleton R] [add_comm_monoid M] [module R M] : subsingleton M := ⟨λ x y, by rw [← one_smul R x, ← one_smul R y, subsingleton.elim (1:R) 0, zero_smul, zero_smul]⟩ @[priority 910] -- see Note [lower instance priority] instance semiring.to_module [semiring R] : module R R := { smul_add := mul_add, add_smul := add_mul, zero_smul := zero_mul, smul_zero := mul_zero } @[priority 910] -- see Note [lower instance priority] instance semiring.to_opposite_module [semiring R] : module Rᵒᵖ R := { smul_add := λ r x y, add_mul _ _ _, add_smul := λ r x y, mul_add _ _ _, ..monoid_with_zero.to_opposite_mul_action_with_zero R} /-- A ring homomorphism `f : R →+* M` defines a module structure by `r • x = f r * x`. -/ def ring_hom.to_module [semiring R] [semiring S] (f : R →+* S) : module R S := module.comp_hom S f /-- The tautological action by `R →+* R` on `R`. This generalizes `function.End.apply_mul_action`. -/ instance ring_hom.apply_distrib_mul_action [semiring R] : distrib_mul_action (R →+* R) R := { smul := ($), smul_zero := ring_hom.map_zero, smul_add := ring_hom.map_add, one_smul := λ _, rfl, mul_smul := λ _ _ _, rfl } @[simp] protected lemma ring_hom.smul_def [semiring R] (f : R →+* R) (a : R) : f • a = f a := rfl /-- `ring_hom.apply_distrib_mul_action` is faithful. -/ instance ring_hom.apply_has_faithful_scalar [semiring R] : has_faithful_scalar (R →+* R) R := ⟨ring_hom.ext⟩ section add_comm_monoid variables [semiring R] [add_comm_monoid M] [module R M] section variables (R) /-- `nsmul` is equal to any other module structure via a cast. -/ lemma nsmul_eq_smul_cast (n : ℕ) (b : M) : n • b = (n : R) • b := begin induction n with n ih, { rw [nat.cast_zero, zero_smul, zero_smul] }, { rw [nat.succ_eq_add_one, nat.cast_succ, add_smul, add_smul, one_smul, ih, one_smul], } end end /-- Convert back any exotic `ℕ`-smul to the canonical instance. This should not be needed since in mathlib all `add_comm_monoid`s should normally have exactly one `ℕ`-module structure by design. -/ lemma nat_smul_eq_nsmul (h : module ℕ M) (n : ℕ) (x : M) : @has_scalar.smul ℕ M h.to_has_scalar n x = n • x := by rw [nsmul_eq_smul_cast ℕ n x, nat.cast_id] /-- All `ℕ`-module structures are equal. Not an instance since in mathlib all `add_comm_monoid` should normally have exactly one `ℕ`-module structure by design. -/ def add_comm_monoid.nat_module.unique : unique (module ℕ M) := { default := by apply_instance, uniq := λ P, module_ext P _ $ λ n, nat_smul_eq_nsmul P n } instance add_comm_monoid.nat_is_scalar_tower : is_scalar_tower ℕ R M := { smul_assoc := λ n x y, nat.rec_on n (by simp only [zero_smul]) (λ n ih, by simp only [nat.succ_eq_add_one, add_smul, one_smul, ih]) } instance add_comm_monoid.nat_smul_comm_class : smul_comm_class ℕ R M := { smul_comm := λ n r m, nat.rec_on n (by simp only [zero_smul, smul_zero]) (λ n ih, by simp only [nat.succ_eq_add_one, add_smul, one_smul, ←ih, smul_add]) } -- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop instance add_comm_monoid.nat_smul_comm_class' : smul_comm_class R ℕ M := smul_comm_class.symm _ _ _ end add_comm_monoid section add_comm_group variables [semiring S] [ring R] [add_comm_group M] [module S M] [module R M] section variables (R) /-- `gsmul` is equal to any other module structure via a cast. -/ lemma gsmul_eq_smul_cast (n : ℤ) (b : M) : n • b = (n : R) • b := begin induction n using int.induction_on with p hp n hn, { rw [int.cast_zero, zero_smul, zero_smul] }, { rw [int.cast_add, int.cast_one, add_smul, add_smul, one_smul, one_smul, hp] }, { rw [int.cast_sub, int.cast_one, sub_smul, sub_smul, one_smul, one_smul, hn] }, end end /-- Convert back any exotic `ℤ`-smul to the canonical instance. This should not be needed since in mathlib all `add_comm_group`s should normally have exactly one `ℤ`-module structure by design. -/ lemma int_smul_eq_gsmul (h : module ℤ M) (n : ℤ) (x : M) : @has_scalar.smul ℤ M h.to_has_scalar n x = n • x := by rw [gsmul_eq_smul_cast ℤ n x, int.cast_id] /-- All `ℤ`-module structures are equal. Not an instance since in mathlib all `add_comm_group` should normally have exactly one `ℤ`-module structure by design. -/ def add_comm_group.int_module.unique : unique (module ℤ M) := { default := by apply_instance, uniq := λ P, module_ext P _ $ λ n, int_smul_eq_gsmul P n } instance add_comm_group.int_is_scalar_tower : is_scalar_tower ℤ R M := { smul_assoc := λ n x y, int.induction_on n (by simp only [zero_smul]) (λ n ih, by simp only [one_smul, add_smul, ih]) (λ n ih, by simp only [one_smul, sub_smul, ih]) } instance add_comm_group.int_smul_comm_class : smul_comm_class ℤ S M := { smul_comm := λ n x y, int.induction_on n (by simp only [zero_smul, smul_zero]) (λ n ih, by simp only [one_smul, add_smul, smul_add, ih]) (λ n ih, by simp only [one_smul, sub_smul, smul_sub, ih]) } -- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop instance add_comm_group.int_smul_comm_class' : smul_comm_class S ℤ M := smul_comm_class.symm _ _ _ end add_comm_group namespace add_monoid_hom lemma map_nat_module_smul [add_comm_monoid M] [add_comm_monoid M₂] (f : M →+ M₂) (x : ℕ) (a : M) : f (x • a) = x • f a := by simp only [f.map_nsmul] lemma map_int_module_smul [add_comm_group M] [add_comm_group M₂] (f : M →+ M₂) (x : ℤ) (a : M) : f (x • a) = x • f a := by simp only [f.map_gsmul] lemma map_int_cast_smul [ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂] (f : M →+ M₂) (x : ℤ) (a : M) : f ((x : R) • a) = (x : R) • f a := by simp only [←gsmul_eq_smul_cast, f.map_gsmul] lemma map_nat_cast_smul [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [module R M] [module R M₂] (f : M →+ M₂) (x : ℕ) (a : M) : f ((x : R) • a) = (x : R) • f a := by simp only [←nsmul_eq_smul_cast, f.map_nsmul] lemma map_rat_cast_smul {R : Type*} [division_ring R] [char_zero R] {E : Type*} [add_comm_group E] [module R E] {F : Type*} [add_comm_group F] [module R F] (f : E →+ F) (c : ℚ) (x : E) : f ((c : R) • x) = (c : R) • f x := begin have : ∀ (x : E) (n : ℕ), 0 < n → f (((n⁻¹ : ℚ) : R) • x) = ((n⁻¹ : ℚ) : R) • f x, { intros x n hn, replace hn : (n : R) ≠ 0 := nat.cast_ne_zero.2 (ne_of_gt hn), conv_rhs { congr, skip, rw [← one_smul R x, ← mul_inv_cancel hn, mul_smul] }, rw [f.map_nat_cast_smul, smul_smul, rat.cast_inv, rat.cast_coe_nat, inv_mul_cancel hn, one_smul] }, refine c.num_denom_cases_on (λ m n hn hmn, _), rw [rat.mk_eq_div, div_eq_mul_inv, rat.cast_mul, int.cast_coe_nat, mul_smul, mul_smul, rat.cast_coe_int, f.map_int_cast_smul, this _ n hn] end lemma map_rat_module_smul {E : Type*} [add_comm_group E] [module ℚ E] {F : Type*} [add_comm_group F] [module ℚ F] (f : E →+ F) (c : ℚ) (x : E) : f (c • x) = c • f x := rat.cast_id c ▸ f.map_rat_cast_smul c x end add_monoid_hom section no_zero_smul_divisors /-! ### `no_zero_smul_divisors` This section defines the `no_zero_smul_divisors` class, and includes some tests for the vanishing of elements (especially in modules over division rings). -/ /-- `no_zero_smul_divisors R M` states that a scalar multiple is `0` only if either argument is `0`. This a version of saying that `M` is torsion free, without assuming `R` is zero-divisor free. The main application of `no_zero_smul_divisors R M`, when `M` is a module, is the result `smul_eq_zero`: a scalar multiple is `0` iff either argument is `0`. It is a generalization of the `no_zero_divisors` class to heterogeneous multiplication. -/ class no_zero_smul_divisors (R M : Type*) [has_zero R] [has_zero M] [has_scalar R M] : Prop := (eq_zero_or_eq_zero_of_smul_eq_zero : ∀ {c : R} {x : M}, c • x = 0 → c = 0 ∨ x = 0) export no_zero_smul_divisors (eq_zero_or_eq_zero_of_smul_eq_zero) section module variables [semiring R] [add_comm_monoid M] [module R M] instance no_zero_smul_divisors.of_no_zero_divisors [no_zero_divisors R] : no_zero_smul_divisors R R := ⟨λ c x, no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero⟩ @[simp] theorem smul_eq_zero [no_zero_smul_divisors R M] {c : R} {x : M} : c • x = 0 ↔ c = 0 ∨ x = 0 := ⟨eq_zero_or_eq_zero_of_smul_eq_zero, λ h, h.elim (λ h, h.symm ▸ zero_smul R x) (λ h, h.symm ▸ smul_zero c)⟩ theorem smul_ne_zero [no_zero_smul_divisors R M] {c : R} {x : M} : c • x ≠ 0 ↔ c ≠ 0 ∧ x ≠ 0 := by simp only [ne.def, smul_eq_zero, not_or_distrib] section nat variables (R) (M) [no_zero_smul_divisors R M] [char_zero R] include R lemma nat.no_zero_smul_divisors : no_zero_smul_divisors ℕ M := ⟨by { intros c x, rw [nsmul_eq_smul_cast R, smul_eq_zero], simp }⟩ variables {M} lemma eq_zero_of_smul_two_eq_zero {v : M} (hv : 2 • v = 0) : v = 0 := by haveI := nat.no_zero_smul_divisors R M; exact (smul_eq_zero.mp hv).resolve_left (by norm_num) end nat end module section add_comm_group -- `R` can still be a semiring here variables [semiring R] [add_comm_group M] [module R M] section smul_injective variables (M) lemma smul_right_injective [no_zero_smul_divisors R M] {c : R} (hc : c ≠ 0) : function.injective (λ (x : M), c • x) := λ x y h, sub_eq_zero.mp ((smul_eq_zero.mp (calc c • (x - y) = c • x - c • y : smul_sub c x y ... = 0 : sub_eq_zero.mpr h)).resolve_left hc) end smul_injective section nat variables (R) [no_zero_smul_divisors R M] [char_zero R] include R lemma eq_zero_of_eq_neg {v : M} (hv : v = - v) : v = 0 := begin haveI := nat.no_zero_smul_divisors R M, refine eq_zero_of_smul_two_eq_zero R _, rw two_smul, exact add_eq_zero_iff_eq_neg.mpr hv end end nat end add_comm_group section module variables [ring R] [add_comm_group M] [module R M] [no_zero_smul_divisors R M] section smul_injective variables (R) lemma smul_left_injective {x : M} (hx : x ≠ 0) : function.injective (λ (c : R), c • x) := λ c d h, sub_eq_zero.mp ((smul_eq_zero.mp (calc (c - d) • x = c • x - d • x : sub_smul c d x ... = 0 : sub_eq_zero.mpr h)).resolve_right hx) end smul_injective section nat variables [char_zero R] lemma ne_neg_of_ne_zero [no_zero_divisors R] {v : R} (hv : v ≠ 0) : v ≠ -v := λ h, hv (eq_zero_of_eq_neg R h) end nat end module section division_ring variables [division_ring R] [add_comm_group M] [module R M] @[priority 100] -- see note [lower instance priority] instance no_zero_smul_divisors.of_division_ring : no_zero_smul_divisors R M := ⟨λ c x h, or_iff_not_imp_left.2 $ λ hc, (smul_eq_zero_iff_eq' hc).1 h⟩ end division_ring end no_zero_smul_divisors @[simp] lemma nat.smul_one_eq_coe {R : Type*} [semiring R] (m : ℕ) : m • (1 : R) = ↑m := by rw [nsmul_eq_mul, mul_one] @[simp] lemma int.smul_one_eq_coe {R : Type*} [ring R] (m : ℤ) : m • (1 : R) = ↑m := by rw [gsmul_eq_mul, mul_one]
768e0f37c27dbd6b722435b7941873eec8698559
05b503addd423dd68145d68b8cde5cd595d74365
/src/data/fintype/basic.lean
187c986044b3cd516aa636eb9d8593e09c2b5b6f
[ "Apache-2.0" ]
permissive
aestriplex/mathlib
77513ff2b176d74a3bec114f33b519069788811d
e2fa8b2b1b732d7c25119229e3cdfba8370cb00f
refs/heads/master
1,621,969,960,692
1,586,279,279,000
1,586,279,279,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
39,395
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro Finite types. -/ import data.finset data.array.lemmas logic.unique import tactic.wlog universes u v variables {α : Type*} {β : Type*} {γ : Type*} /-- `fintype α` means that `α` is finite, i.e. there are only finitely many distinct elements of type `α`. The evidence of this is a finset `elems` (a list up to permutation without duplicates), together with a proof that everything of type `α` is in the list. -/ class fintype (α : Type*) := (elems : finset α) (complete : ∀ x : α, x ∈ elems) namespace finset variable [fintype α] /-- `univ` is the universal finite set of type `finset α` implied from the assumption `fintype α`. -/ def univ : finset α := fintype.elems α @[simp] theorem mem_univ (x : α) : x ∈ (univ : finset α) := fintype.complete x @[simp] theorem mem_univ_val : ∀ x, x ∈ (univ : finset α).1 := mem_univ @[simp] lemma coe_univ : ↑(univ : finset α) = (set.univ : set α) := by ext; simp theorem subset_univ (s : finset α) : s ⊆ univ := λ a _, mem_univ a theorem eq_univ_iff_forall {s : finset α} : s = univ ↔ ∀ x, x ∈ s := by simp [ext] @[simp] lemma piecewise_univ [∀i : α, decidable (i ∈ (univ : finset α))] {δ : α → Sort*} (f g : Πi, δ i) : univ.piecewise f g = f := by { ext i, simp [piecewise] } end finset open finset function namespace fintype instance decidable_pi_fintype {α} {β : α → Type*} [∀a, decidable_eq (β a)] [fintype α] : decidable_eq (Πa, β a) := assume f g, decidable_of_iff (∀ a ∈ fintype.elems α, f a = g a) (by simp [function.funext_iff, fintype.complete]) instance decidable_forall_fintype {p : α → Prop} [decidable_pred p] [fintype α] : decidable (∀ a, p a) := decidable_of_iff (∀ a ∈ @univ α _, p a) (by simp) instance decidable_exists_fintype {p : α → Prop} [decidable_pred p] [fintype α] : decidable (∃ a, p a) := decidable_of_iff (∃ a ∈ @univ α _, p a) (by simp) instance decidable_eq_equiv_fintype [decidable_eq β] [fintype α] : decidable_eq (α ≃ β) := λ a b, decidable_of_iff (a.1 = b.1) ⟨λ h, equiv.ext _ _ (congr_fun h), congr_arg _⟩ instance decidable_injective_fintype [decidable_eq α] [decidable_eq β] [fintype α] : decidable_pred (injective : (α → β) → Prop) := λ x, by unfold injective; apply_instance instance decidable_surjective_fintype [decidable_eq β] [fintype α] [fintype β] : decidable_pred (surjective : (α → β) → Prop) := λ x, by unfold surjective; apply_instance instance decidable_bijective_fintype [decidable_eq α] [decidable_eq β] [fintype α] [fintype β] : decidable_pred (bijective : (α → β) → Prop) := λ x, by unfold bijective; apply_instance instance decidable_left_inverse_fintype [decidable_eq α] [fintype α] (f : α → β) (g : β → α) : decidable (function.right_inverse f g) := show decidable (∀ x, g (f x) = x), by apply_instance instance decidable_right_inverse_fintype [decidable_eq β] [fintype β] (f : α → β) (g : β → α) : decidable (function.left_inverse f g) := show decidable (∀ x, f (g x) = x), by apply_instance /-- Construct a proof of `fintype α` from a universal multiset -/ def of_multiset [decidable_eq α] (s : multiset α) (H : ∀ x : α, x ∈ s) : fintype α := ⟨s.to_finset, by simpa using H⟩ /-- Construct a proof of `fintype α` from a universal list -/ def of_list [decidable_eq α] (l : list α) (H : ∀ x : α, x ∈ l) : fintype α := ⟨l.to_finset, by simpa using H⟩ theorem exists_univ_list (α) [fintype α] : ∃ l : list α, l.nodup ∧ ∀ x : α, x ∈ l := let ⟨l, e⟩ := quotient.exists_rep (@univ α _).1 in by have := and.intro univ.2 mem_univ_val; exact ⟨_, by rwa ← e at this⟩ /-- `card α` is the number of elements in `α`, defined when `α` is a fintype. -/ def card (α) [fintype α] : ℕ := (@univ α _).card /-- If `l` lists all the elements of `α` without duplicates, then `α ≃ fin (l.length)`. -/ def equiv_fin_of_forall_mem_list {α} [decidable_eq α] {l : list α} (h : ∀ x:α, x ∈ l) (nd : l.nodup) : α ≃ fin (l.length) := ⟨λ a, ⟨_, list.index_of_lt_length.2 (h a)⟩, λ i, l.nth_le i.1 i.2, λ a, by simp, λ ⟨i, h⟩, fin.eq_of_veq $ list.nodup_iff_nth_le_inj.1 nd _ _ (list.index_of_lt_length.2 (list.nth_le_mem _ _ _)) h $ by simp⟩ /-- There is (computably) a bijection between `α` and `fin n` where `n = card α`. Since it is not unique, and depends on which permutation of the universe list is used, the bijection is wrapped in `trunc` to preserve computability. -/ def equiv_fin (α) [fintype α] [decidable_eq α] : trunc (α ≃ fin (card α)) := by unfold card finset.card; exact quot.rec_on_subsingleton (@univ α _).1 (λ l (h : ∀ x:α, x ∈ l) (nd : l.nodup), trunc.mk (equiv_fin_of_forall_mem_list h nd)) mem_univ_val univ.2 theorem exists_equiv_fin (α) [fintype α] : ∃ n, nonempty (α ≃ fin n) := by haveI := classical.dec_eq α; exact ⟨card α, nonempty_of_trunc (equiv_fin α)⟩ /-- Given a linearly ordered fintype `α` of cardinal `k`, the equiv `mono_equiv_of_fin α h` is the increasing bijection between `fin k` and `α`. Here, `h` is a proof that the cardinality of `s` is `k`. We use this instead of a map `fin s.card → α` to avoid casting issues in further uses of this function. -/ noncomputable def mono_equiv_of_fin (α) [fintype α] [decidable_linear_order α] {k : ℕ} (h : fintype.card α = k) : fin k ≃ α := have A : bijective (mono_of_fin univ h) := begin apply set.bijective_iff_bij_on_univ.2, rw ← @coe_univ α _, exact bij_on_mono_of_fin (univ : finset α) h end, equiv.of_bijective A instance (α : Type*) : subsingleton (fintype α) := ⟨λ ⟨s₁, h₁⟩ ⟨s₂, h₂⟩, by congr; simp [finset.ext, h₁, h₂]⟩ protected def subtype {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x) : fintype {x // p x} := ⟨⟨multiset.pmap subtype.mk s.1 (λ x, (H x).1), multiset.nodup_pmap (λ a _ b _, congr_arg subtype.val) s.2⟩, λ ⟨x, px⟩, multiset.mem_pmap.2 ⟨x, (H x).2 px, rfl⟩⟩ theorem subtype_card {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x) : @card {x // p x} (fintype.subtype s H) = s.card := multiset.card_pmap _ _ _ theorem card_of_subtype {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x) [fintype {x // p x}] : card {x // p x} = s.card := by rw ← subtype_card s H; congr /-- Construct a fintype from a finset with the same elements. -/ def of_finset {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : fintype p := fintype.subtype s H @[simp] theorem card_of_finset {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : @fintype.card p (of_finset s H) = s.card := fintype.subtype_card s H theorem card_of_finset' {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) [fintype p] : fintype.card p = s.card := by rw ← card_of_finset s H; congr /-- If `f : α → β` is a bijection and `α` is a fintype, then `β` is also a fintype. -/ def of_bijective [fintype α] (f : α → β) (H : function.bijective f) : fintype β := ⟨univ.map ⟨f, H.1⟩, λ b, let ⟨a, e⟩ := H.2 b in e ▸ mem_map_of_mem _ (mem_univ _)⟩ /-- If `f : α → β` is a surjection and `α` is a fintype, then `β` is also a fintype. -/ def of_surjective [fintype α] [decidable_eq β] (f : α → β) (H : function.surjective f) : fintype β := ⟨univ.image f, λ b, let ⟨a, e⟩ := H b in e ▸ mem_image_of_mem _ (mem_univ _)⟩ noncomputable def of_injective [fintype β] (f : α → β) (H : function.injective f) : fintype α := by letI := classical.dec; exact if hα : nonempty α then by letI := classical.inhabited_of_nonempty hα; exact of_surjective (inv_fun f) (inv_fun_surjective H) else ⟨∅, λ x, (hα ⟨x⟩).elim⟩ /-- If `f : α ≃ β` and `α` is a fintype, then `β` is also a fintype. -/ def of_equiv (α : Type*) [fintype α] (f : α ≃ β) : fintype β := of_bijective _ f.bijective theorem of_equiv_card [fintype α] (f : α ≃ β) : @card β (of_equiv α f) = card α := multiset.card_map _ _ theorem card_congr {α β} [fintype α] [fintype β] (f : α ≃ β) : card α = card β := by rw ← of_equiv_card f; congr theorem card_eq {α β} [F : fintype α] [G : fintype β] : card α = card β ↔ nonempty (α ≃ β) := ⟨λ h, ⟨by classical; calc α ≃ fin (card α) : trunc.out (equiv_fin α) ... ≃ fin (card β) : by rw h ... ≃ β : (trunc.out (equiv_fin β)).symm⟩, λ ⟨f⟩, card_congr f⟩ def of_subsingleton (a : α) [subsingleton α] : fintype α := ⟨finset.singleton a, λ b, finset.mem_singleton.2 (subsingleton.elim _ _)⟩ @[simp] theorem univ_of_subsingleton (a : α) [subsingleton α] : @univ _ (of_subsingleton a) = finset.singleton a := rfl @[simp] theorem card_of_subsingleton (a : α) [subsingleton α] : @fintype.card _ (of_subsingleton a) = 1 := rfl end fintype namespace set /-- Construct a finset enumerating a set `s`, given a `fintype` instance. -/ def to_finset (s : set α) [fintype s] : finset α := ⟨(@finset.univ s _).1.map subtype.val, multiset.nodup_map (λ a b, subtype.eq) finset.univ.2⟩ @[simp] theorem mem_to_finset {s : set α} [fintype s] {a : α} : a ∈ s.to_finset ↔ a ∈ s := by simp [to_finset] @[simp] theorem mem_to_finset_val {s : set α} [fintype s] {a : α} : a ∈ s.to_finset.1 ↔ a ∈ s := mem_to_finset end set lemma finset.card_univ [fintype α] : (finset.univ : finset α).card = fintype.card α := rfl lemma finset.card_univ_diff [fintype α] [decidable_eq α] (s : finset α) : (finset.univ \ s).card = fintype.card α - s.card := finset.card_sdiff (subset_univ s) instance (n : ℕ) : fintype (fin n) := ⟨⟨list.fin_range n, list.nodup_fin_range n⟩, list.mem_fin_range⟩ @[simp] theorem fintype.card_fin (n : ℕ) : fintype.card (fin n) = n := list.length_fin_range n @[simp] lemma finset.card_fin (n : ℕ) : finset.card (finset.univ : finset (fin n)) = n := by rw [finset.card_univ, fintype.card_fin] lemma fin.univ_succ (n : ℕ) : (univ : finset (fin $ n+1)) = insert 0 (univ.image fin.succ) := begin ext m, simp only [mem_univ, mem_insert, true_iff, mem_image, exists_prop], exact fin.cases (or.inl rfl) (λ i, or.inr ⟨i, trivial, rfl⟩) m end lemma fin.univ_cast_succ (n : ℕ) : (univ : finset (fin $ n+1)) = insert (fin.last n) (univ.image fin.cast_succ) := begin ext m, simp only [mem_univ, mem_insert, true_iff, mem_image, exists_prop, true_and], by_cases h : m.val < n, { right, use fin.cast_lt m h, rw fin.cast_succ_cast_lt }, { left, exact fin.eq_last_of_not_lt h } end /-- Any increasing map between `fin k` and a finset of cardinality `k` has to coincide with the increasing bijection `mono_of_fin s h`. -/ lemma finset.mono_of_fin_unique' [decidable_linear_order α] {s : finset α} {k : ℕ} (h : s.card = k) {f : fin k → α} (fmap : set.maps_to f set.univ ↑s) (hmono : strict_mono f) : f = s.mono_of_fin h := begin have finj : set.inj_on f set.univ := hmono.injective.inj_on _, apply mono_of_fin_unique h (set.bij_on.mk fmap finj (λ y hy, _)) hmono, simp only [set.image_univ, set.mem_range], rcases surj_on_of_inj_on_of_card_le (λ i (hi : i ∈ finset.univ), f i) (λ i hi, fmap (set.mem_univ i)) (λ i j hi hj hij, finj (set.mem_univ i) (set.mem_univ j) hij) (by simp [h]) y hy with ⟨x, _, hx⟩, exact ⟨x, hx.symm⟩ end @[instance, priority 10] def unique.fintype {α : Type*} [unique α] : fintype α := ⟨finset.singleton (default α), λ x, by rw [unique.eq_default x]; simp⟩ @[simp] lemma univ_unique {α : Type*} [unique α] [f : fintype α] : @finset.univ α _ = {default α} := by rw [subsingleton.elim f (@unique.fintype α _)]; refl instance : fintype empty := ⟨∅, empty.rec _⟩ @[simp] theorem fintype.univ_empty : @univ empty _ = ∅ := rfl @[simp] theorem fintype.card_empty : fintype.card empty = 0 := rfl instance : fintype pempty := ⟨∅, pempty.rec _⟩ @[simp] theorem fintype.univ_pempty : @univ pempty _ = ∅ := rfl @[simp] theorem fintype.card_pempty : fintype.card pempty = 0 := rfl instance : fintype unit := fintype.of_subsingleton () theorem fintype.univ_unit : @univ unit _ = {()} := rfl theorem fintype.card_unit : fintype.card unit = 1 := rfl instance : fintype punit := fintype.of_subsingleton punit.star @[simp] theorem fintype.univ_punit : @univ punit _ = {punit.star} := rfl @[simp] theorem fintype.card_punit : fintype.card punit = 1 := rfl instance : fintype bool := ⟨⟨tt::ff::0, by simp⟩, λ x, by cases x; simp⟩ @[simp] theorem fintype.univ_bool : @univ bool _ = {ff, tt} := rfl instance units_int.fintype : fintype (units ℤ) := ⟨{1, -1}, λ x, by cases int.units_eq_one_or x; simp *⟩ instance additive.fintype : Π [fintype α], fintype (additive α) := id instance multiplicative.fintype : Π [fintype α], fintype (multiplicative α) := id @[simp] theorem fintype.card_units_int : fintype.card (units ℤ) = 2 := rfl noncomputable instance [monoid α] [fintype α] : fintype (units α) := by classical; exact fintype.of_injective units.val units.ext @[simp] theorem fintype.card_bool : fintype.card bool = 2 := rfl def finset.insert_none (s : finset α) : finset (option α) := ⟨none :: s.1.map some, multiset.nodup_cons.2 ⟨by simp, multiset.nodup_map (λ a b, option.some.inj) s.2⟩⟩ @[simp] theorem finset.mem_insert_none {s : finset α} : ∀ {o : option α}, o ∈ s.insert_none ↔ ∀ a ∈ o, a ∈ s | none := iff_of_true (multiset.mem_cons_self _ _) (λ a h, by cases h) | (some a) := multiset.mem_cons.trans $ by simp; refl theorem finset.some_mem_insert_none {s : finset α} {a : α} : some a ∈ s.insert_none ↔ a ∈ s := by simp instance {α : Type*} [fintype α] : fintype (option α) := ⟨univ.insert_none, λ a, by simp⟩ @[simp] theorem fintype.card_option {α : Type*} [fintype α] : fintype.card (option α) = fintype.card α + 1 := (multiset.card_cons _ _).trans (by rw multiset.card_map; refl) instance {α : Type*} (β : α → Type*) [fintype α] [∀ a, fintype (β a)] : fintype (sigma β) := ⟨univ.sigma (λ _, univ), λ ⟨a, b⟩, by simp⟩ instance (α β : Type*) [fintype α] [fintype β] : fintype (α × β) := ⟨univ.product univ, λ ⟨a, b⟩, by simp⟩ @[simp] theorem fintype.card_prod (α β : Type*) [fintype α] [fintype β] : fintype.card (α × β) = fintype.card α * fintype.card β := card_product _ _ def fintype.fintype_prod_left {α β} [decidable_eq α] [fintype (α × β)] [nonempty β] : fintype α := ⟨(fintype.elems (α × β)).image prod.fst, assume a, let ⟨b⟩ := ‹nonempty β› in by simp; exact ⟨b, fintype.complete _⟩⟩ def fintype.fintype_prod_right {α β} [decidable_eq β] [fintype (α × β)] [nonempty α] : fintype β := ⟨(fintype.elems (α × β)).image prod.snd, assume b, let ⟨a⟩ := ‹nonempty α› in by simp; exact ⟨a, fintype.complete _⟩⟩ instance (α : Type*) [fintype α] : fintype (ulift α) := fintype.of_equiv _ equiv.ulift.symm @[simp] theorem fintype.card_ulift (α : Type*) [fintype α] : fintype.card (ulift α) = fintype.card α := fintype.of_equiv_card _ instance (α : Type u) (β : Type v) [fintype α] [fintype β] : fintype (α ⊕ β) := @fintype.of_equiv _ _ (@sigma.fintype _ (λ b, cond b (ulift α) (ulift.{(max u v) v} β)) _ (λ b, by cases b; apply ulift.fintype)) ((equiv.sum_equiv_sigma_bool _ _).symm.trans (equiv.sum_congr equiv.ulift equiv.ulift)) lemma fintype.card_le_of_injective [fintype α] [fintype β] (f : α → β) (hf : function.injective f) : fintype.card α ≤ fintype.card β := by haveI := classical.prop_decidable; exact finset.card_le_card_of_inj_on f (λ _ _, finset.mem_univ _) (λ _ _ _ _ h, hf h) lemma fintype.card_eq_one_iff [fintype α] : fintype.card α = 1 ↔ (∃ x : α, ∀ y, y = x) := by rw [← fintype.card_unit, fintype.card_eq]; exact ⟨λ ⟨a⟩, ⟨a.symm (), λ y, a.injective (subsingleton.elim _ _)⟩, λ ⟨x, hx⟩, ⟨⟨λ _, (), λ _, x, λ _, (hx _).trans (hx _).symm, λ _, subsingleton.elim _ _⟩⟩⟩ lemma fintype.card_eq_zero_iff [fintype α] : fintype.card α = 0 ↔ (α → false) := ⟨λ h a, have e : α ≃ empty := classical.choice (fintype.card_eq.1 (by simp [h])), (e a).elim, λ h, have e : α ≃ empty := ⟨λ a, (h a).elim, λ a, a.elim, λ a, (h a).elim, λ a, a.elim⟩, by simp [fintype.card_congr e]⟩ lemma fintype.card_pos_iff [fintype α] : 0 < fintype.card α ↔ nonempty α := ⟨λ h, classical.by_contradiction (λ h₁, have fintype.card α = 0 := fintype.card_eq_zero_iff.2 (λ a, h₁ ⟨a⟩), lt_irrefl 0 $ by rwa this at h), λ ⟨a⟩, nat.pos_of_ne_zero (mt fintype.card_eq_zero_iff.1 (λ h, h a))⟩ lemma fintype.card_le_one_iff [fintype α] : fintype.card α ≤ 1 ↔ (∀ a b : α, a = b) := let n := fintype.card α in have hn : n = fintype.card α := rfl, match n, hn with | 0 := λ ha, ⟨λ h, λ a, (fintype.card_eq_zero_iff.1 ha.symm a).elim, λ _, ha ▸ nat.le_succ _⟩ | 1 := λ ha, ⟨λ h, λ a b, let ⟨x, hx⟩ := fintype.card_eq_one_iff.1 ha.symm in by rw [hx a, hx b], λ _, ha ▸ le_refl _⟩ | (n+2) := λ ha, ⟨λ h, by rw ← ha at h; exact absurd h dec_trivial, (λ h, fintype.card_unit ▸ fintype.card_le_of_injective (λ _, ()) (λ _ _ _, h _ _))⟩ end lemma fintype.exists_ne_of_one_lt_card [fintype α] (h : 1 < fintype.card α) (a : α) : ∃ b : α, b ≠ a := let ⟨b, hb⟩ := classical.not_forall.1 (mt fintype.card_le_one_iff.2 (not_le_of_gt h)) in let ⟨c, hc⟩ := classical.not_forall.1 hb in by haveI := classical.dec_eq α; exact if hba : b = a then ⟨c, by cc⟩ else ⟨b, hba⟩ lemma fintype.injective_iff_surjective [fintype α] {f : α → α} : injective f ↔ surjective f := by haveI := classical.prop_decidable; exact have ∀ {f : α → α}, injective f → surjective f, from λ f hinj x, have h₁ : image f univ = univ := eq_of_subset_of_card_le (subset_univ _) ((card_image_of_injective univ hinj).symm ▸ le_refl _), have h₂ : x ∈ image f univ := h₁.symm ▸ mem_univ _, exists_of_bex (mem_image.1 h₂), ⟨this, λ hsurj, injective_of_has_left_inverse ⟨surj_inv hsurj, left_inverse_of_surjective_of_right_inverse (this (injective_surj_inv _)) (right_inverse_surj_inv _)⟩⟩ lemma fintype.injective_iff_bijective [fintype α] {f : α → α} : injective f ↔ bijective f := by simp [bijective, fintype.injective_iff_surjective] lemma fintype.surjective_iff_bijective [fintype α] {f : α → α} : surjective f ↔ bijective f := by simp [bijective, fintype.injective_iff_surjective] lemma fintype.injective_iff_surjective_of_equiv [fintype α] {f : α → β} (e : α ≃ β) : injective f ↔ surjective f := have injective (e.symm ∘ f) ↔ surjective (e.symm ∘ f), from fintype.injective_iff_surjective, ⟨λ hinj, by simpa [function.comp] using surjective_comp e.surjective (this.1 (injective_comp e.symm.injective hinj)), λ hsurj, by simpa [function.comp] using injective_comp e.injective (this.2 (surjective_comp e.symm.surjective hsurj))⟩ lemma fintype.coe_image_univ [fintype α] [decidable_eq β] {f : α → β} : ↑(finset.image f finset.univ) = set.range f := by { ext x, simp } instance list.subtype.fintype [decidable_eq α] (l : list α) : fintype {x // x ∈ l} := fintype.of_list l.attach l.mem_attach instance multiset.subtype.fintype [decidable_eq α] (s : multiset α) : fintype {x // x ∈ s} := fintype.of_multiset s.attach s.mem_attach instance finset.subtype.fintype (s : finset α) : fintype {x // x ∈ s} := ⟨s.attach, s.mem_attach⟩ instance finset_coe.fintype (s : finset α) : fintype (↑s : set α) := finset.subtype.fintype s @[simp] lemma fintype.card_coe (s : finset α) : fintype.card (↑s : set α) = s.card := card_attach lemma finset.card_le_one_iff {s : finset α} : s.card ≤ 1 ↔ ∀ {x y}, x ∈ s → y ∈ s → x = y := begin let t : set α := ↑s, letI : fintype t := finset_coe.fintype s, have : fintype.card t = s.card := fintype.card_coe s, rw [← this, fintype.card_le_one_iff], split, { assume H x y hx hy, exact subtype.mk.inj (H ⟨x, hx⟩ ⟨y, hy⟩) }, { assume H x y, exact subtype.eq (H x.2 y.2) } end lemma finset.one_lt_card_iff {s : finset α} : 1 < s.card ↔ ∃ x y, (x ∈ s) ∧ (y ∈ s) ∧ x ≠ y := begin classical, rw ← not_iff_not, push_neg, simpa [classical.or_iff_not_imp_left] using finset.card_le_one_iff end instance plift.fintype (p : Prop) [decidable p] : fintype (plift p) := ⟨if h : p then finset.singleton ⟨h⟩ else ∅, λ ⟨h⟩, by simp [h]⟩ instance Prop.fintype : fintype Prop := ⟨⟨true::false::0, by simp [true_ne_false]⟩, classical.cases (by simp) (by simp)⟩ def set_fintype {α} [fintype α] (s : set α) [decidable_pred s] : fintype s := fintype.subtype (univ.filter (∈ s)) (by simp) namespace fintype variables [fintype α] [decidable_eq α] {δ : α → Type*} /-- Given for all `a : α` a finset `t a` of `δ a`, then one can define the finset `fintype.pi_finset t` of all functions taking values in `t a` for all `a`. This is the analogue of `finset.pi` where the base finset is `univ` (but formally they are not the same, as there is an additional condition `i ∈ finset.univ` in the `finset.pi` definition). -/ def pi_finset (t : Πa, finset (δ a)) : finset (Πa, δ a) := (finset.univ.pi t).map ⟨λ f a, f a (mem_univ a), λ _ _, by simp [function.funext_iff]⟩ @[simp] lemma mem_pi_finset {t : Πa, finset (δ a)} {f : Πa, δ a} : f ∈ pi_finset t ↔ (∀a, f a ∈ t a) := begin split, { simp only [pi_finset, mem_map, and_imp, forall_prop_of_true, exists_prop, mem_univ, exists_imp_distrib, mem_pi], assume g hg hgf a, rw ← hgf, exact hg a }, { simp only [pi_finset, mem_map, forall_prop_of_true, exists_prop, mem_univ, mem_pi], assume hf, exact ⟨λ a ha, f a, hf, rfl⟩ } end lemma pi_finset_subset (t₁ t₂ : Πa, finset (δ a)) (h : ∀ a, t₁ a ⊆ t₂ a) : pi_finset t₁ ⊆ pi_finset t₂ := λ g hg, mem_pi_finset.2 $ λ a, h a $ mem_pi_finset.1 hg a lemma pi_finset_disjoint_of_disjoint [∀ a, decidable_eq (δ a)] (t₁ t₂ : Πa, finset (δ a)) {a : α} (h : disjoint (t₁ a) (t₂ a)) : disjoint (pi_finset t₁) (pi_finset t₂) := disjoint_iff_ne.2 $ λ f₁ hf₁ f₂ hf₂ eq₁₂, disjoint_iff_ne.1 h (f₁ a) (mem_pi_finset.1 hf₁ a) (f₂ a) (mem_pi_finset.1 hf₂ a) (congr_fun eq₁₂ a) end fintype /-! ### pi -/ /-- A dependent product of fintypes, indexed by a fintype, is a fintype. -/ instance pi.fintype {α : Type*} {β : α → Type*} [decidable_eq α] [fintype α] [∀a, fintype (β a)] : fintype (Πa, β a) := ⟨fintype.pi_finset (λ _, univ), by simp⟩ @[simp] lemma fintype.pi_finset_univ {α : Type*} {β : α → Type*} [decidable_eq α] [fintype α] [∀a, fintype (β a)] : fintype.pi_finset (λ a : α, (finset.univ : finset (β a))) = (finset.univ : finset (Π a, β a)) := rfl instance d_array.fintype {n : ℕ} {α : fin n → Type*} [∀n, fintype (α n)] : fintype (d_array n α) := fintype.of_equiv _ (equiv.d_array_equiv_fin _).symm instance array.fintype {n : ℕ} {α : Type*} [fintype α] : fintype (array n α) := d_array.fintype instance vector.fintype {α : Type*} [fintype α] {n : ℕ} : fintype (vector α n) := fintype.of_equiv _ (equiv.vector_equiv_fin _ _).symm instance quotient.fintype [fintype α] (s : setoid α) [decidable_rel ((≈) : α → α → Prop)] : fintype (quotient s) := fintype.of_surjective quotient.mk (λ x, quotient.induction_on x (λ x, ⟨x, rfl⟩)) instance finset.fintype [fintype α] : fintype (finset α) := ⟨univ.powerset, λ x, finset.mem_powerset.2 (finset.subset_univ _)⟩ @[simp] lemma fintype.card_finset [fintype α] : fintype.card (finset α) = 2 ^ (fintype.card α) := finset.card_powerset finset.univ instance subtype.fintype (p : α → Prop) [decidable_pred p] [fintype α] : fintype {x // p x} := set_fintype _ theorem fintype.card_subtype_le [fintype α] (p : α → Prop) [decidable_pred p] : fintype.card {x // p x} ≤ fintype.card α := by rw fintype.subtype_card; exact card_le_of_subset (subset_univ _) theorem fintype.card_subtype_lt [fintype α] {p : α → Prop} [decidable_pred p] {x : α} (hx : ¬ p x) : fintype.card {x // p x} < fintype.card α := by rw [fintype.subtype_card]; exact finset.card_lt_card ⟨subset_univ _, classical.not_forall.2 ⟨x, by simp [*, set.mem_def]⟩⟩ instance psigma.fintype {α : Type*} {β : α → Type*} [fintype α] [∀ a, fintype (β a)] : fintype (Σ' a, β a) := fintype.of_equiv _ (equiv.psigma_equiv_sigma _).symm instance psigma.fintype_prop_left {α : Prop} {β : α → Type*} [decidable α] [∀ a, fintype (β a)] : fintype (Σ' a, β a) := if h : α then fintype.of_equiv (β h) ⟨λ x, ⟨h, x⟩, psigma.snd, λ _, rfl, λ ⟨_, _⟩, rfl⟩ else ⟨∅, λ x, h x.1⟩ instance psigma.fintype_prop_right {α : Type*} {β : α → Prop} [∀ a, decidable (β a)] [fintype α] : fintype (Σ' a, β a) := fintype.of_equiv {a // β a} ⟨λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, rfl, λ ⟨x, y⟩, rfl⟩ instance psigma.fintype_prop_prop {α : Prop} {β : α → Prop} [decidable α] [∀ a, decidable (β a)] : fintype (Σ' a, β a) := if h : ∃ a, β a then ⟨{⟨h.fst, h.snd⟩}, λ ⟨_, _⟩, by simp⟩ else ⟨∅, λ ⟨x, y⟩, h ⟨x, y⟩⟩ instance set.fintype [decidable_eq α] [fintype α] : fintype (set α) := pi.fintype instance pfun_fintype (p : Prop) [decidable p] (α : p → Type*) [Π hp, fintype (α hp)] : fintype (Π hp : p, α hp) := if hp : p then fintype.of_equiv (α hp) ⟨λ a _, a, λ f, f hp, λ _, rfl, λ _, rfl⟩ else ⟨singleton (λ h, (hp h).elim), by simp [hp, function.funext_iff]⟩ def quotient.fin_choice_aux {ι : Type*} [decidable_eq ι] {α : ι → Type*} [S : ∀ i, setoid (α i)] : ∀ (l : list ι), (∀ i ∈ l, quotient (S i)) → @quotient (Π i ∈ l, α i) (by apply_instance) | [] f := ⟦λ i, false.elim⟧ | (i::l) f := begin refine quotient.lift_on₂ (f i (list.mem_cons_self _ _)) (quotient.fin_choice_aux l (λ j h, f j (list.mem_cons_of_mem _ h))) _ _, exact λ a l, ⟦λ j h, if e : j = i then by rw e; exact a else l _ (h.resolve_left e)⟧, refine λ a₁ l₁ a₂ l₂ h₁ h₂, quotient.sound (λ j h, _), by_cases e : j = i; simp [e], { subst j, exact h₁ }, { exact h₂ _ _ } end theorem quotient.fin_choice_aux_eq {ι : Type*} [decidable_eq ι] {α : ι → Type*} [S : ∀ i, setoid (α i)] : ∀ (l : list ι) (f : ∀ i ∈ l, α i), quotient.fin_choice_aux l (λ i h, ⟦f i h⟧) = ⟦f⟧ | [] f := quotient.sound (λ i h, h.elim) | (i::l) f := begin simp [quotient.fin_choice_aux, quotient.fin_choice_aux_eq l], refine quotient.sound (λ j h, _), by_cases e : j = i; simp [e], subst j, refl end def quotient.fin_choice {ι : Type*} [fintype ι] [decidable_eq ι] {α : ι → Type*} [S : ∀ i, setoid (α i)] (f : ∀ i, quotient (S i)) : @quotient (Π i, α i) (by apply_instance) := quotient.lift_on (@quotient.rec_on _ _ (λ l : multiset ι, @quotient (Π i ∈ l, α i) (by apply_instance)) finset.univ.1 (λ l, quotient.fin_choice_aux l (λ i _, f i)) (λ a b h, begin have := λ a, quotient.fin_choice_aux_eq a (λ i h, quotient.out (f i)), simp [quotient.out_eq] at this, simp [this], let g := λ a:multiset ι, ⟦λ (i : ι) (h : i ∈ a), quotient.out (f i)⟧, refine eq_of_heq ((eq_rec_heq _ _).trans (_ : g a == g b)), congr' 1, exact quotient.sound h, end)) (λ f, ⟦λ i, f i (finset.mem_univ _)⟧) (λ a b h, quotient.sound $ λ i, h _ _) theorem quotient.fin_choice_eq {ι : Type*} [fintype ι] [decidable_eq ι] {α : ι → Type*} [∀ i, setoid (α i)] (f : ∀ i, α i) : quotient.fin_choice (λ i, ⟦f i⟧) = ⟦f⟧ := begin let q, swap, change quotient.lift_on q _ _ = _, have : q = ⟦λ i h, f i⟧, { dsimp [q], exact quotient.induction_on (@finset.univ ι _).1 (λ l, quotient.fin_choice_aux_eq _ _) }, simp [this], exact setoid.refl _ end section equiv open list equiv equiv.perm variables [decidable_eq α] [decidable_eq β] def perms_of_list : list α → list (perm α) | [] := [1] | (a :: l) := perms_of_list l ++ l.bind (λ b, (perms_of_list l).map (λ f, swap a b * f)) lemma length_perms_of_list : ∀ l : list α, length (perms_of_list l) = l.length.fact | [] := rfl | (a :: l) := begin rw [length_cons, nat.fact_succ], simp [perms_of_list, length_bind, length_perms_of_list, function.comp, nat.succ_mul], cc end lemma mem_perms_of_list_of_mem : ∀ {l : list α} {f : perm α} (h : ∀ x, f x ≠ x → x ∈ l), f ∈ perms_of_list l | [] f h := list.mem_singleton.2 $ equiv.ext _ _$ λ x, by simp [imp_false, *] at * | (a::l) f h := if hfa : f a = a then mem_append_left _ $ mem_perms_of_list_of_mem (λ x hx, mem_of_ne_of_mem (λ h, by rw h at hx; exact hx hfa) (h x hx)) else have hfa' : f (f a) ≠ f a, from mt (λ h, f.injective h) hfa, have ∀ (x : α), (swap a (f a) * f) x ≠ x → x ∈ l, from λ x hx, have hxa : x ≠ a, from λ h, by simpa [h, mul_apply] using hx, have hfxa : f x ≠ f a, from mt (λ h, f.injective h) hxa, list.mem_of_ne_of_mem hxa (h x (λ h, by simp [h, mul_apply, swap_apply_def] at hx; split_ifs at hx; cc)), suffices f ∈ perms_of_list l ∨ ∃ (b : α), b ∈ l ∧ ∃ g : perm α, g ∈ perms_of_list l ∧ swap a b * g = f, by simpa [perms_of_list], (@or_iff_not_imp_left _ _ (classical.prop_decidable _)).2 (λ hfl, ⟨f a, if hffa : f (f a) = a then mem_of_ne_of_mem hfa (h _ (mt (λ h, f.injective h) hfa)) else this _ $ by simp [mul_apply, swap_apply_def]; split_ifs; cc, ⟨swap a (f a) * f, mem_perms_of_list_of_mem this, by rw [← mul_assoc, mul_def (swap a (f a)) (swap a (f a)), swap_swap, ← equiv.perm.one_def, one_mul]⟩⟩) lemma mem_of_mem_perms_of_list : ∀ {l : list α} {f : perm α}, f ∈ perms_of_list l → ∀ {x}, f x ≠ x → x ∈ l | [] f h := have f = 1 := by simpa [perms_of_list] using h, by rw this; simp | (a::l) f h := (mem_append.1 h).elim (λ h x hx, mem_cons_of_mem _ (mem_of_mem_perms_of_list h hx)) (λ h x hx, let ⟨y, hy, hy'⟩ := list.mem_bind.1 h in let ⟨g, hg₁, hg₂⟩ := list.mem_map.1 hy' in if hxa : x = a then by simp [hxa] else if hxy : x = y then mem_cons_of_mem _ $ by rwa hxy else mem_cons_of_mem _ $ mem_of_mem_perms_of_list hg₁ $ by rw [eq_inv_mul_iff_mul_eq.2 hg₂, mul_apply, swap_inv, swap_apply_def]; split_ifs; cc) lemma mem_perms_of_list_iff {l : list α} {f : perm α} : f ∈ perms_of_list l ↔ ∀ {x}, f x ≠ x → x ∈ l := ⟨mem_of_mem_perms_of_list, mem_perms_of_list_of_mem⟩ lemma nodup_perms_of_list : ∀ {l : list α} (hl : l.nodup), (perms_of_list l).nodup | [] hl := by simp [perms_of_list] | (a::l) hl := have hl' : l.nodup, from nodup_of_nodup_cons hl, have hln' : (perms_of_list l).nodup, from nodup_perms_of_list hl', have hmeml : ∀ {f : perm α}, f ∈ perms_of_list l → f a = a, from λ f hf, not_not.1 (mt (mem_of_mem_perms_of_list hf) (nodup_cons.1 hl).1), by rw [perms_of_list, list.nodup_append, list.nodup_bind, pairwise_iff_nth_le]; exact ⟨hln', ⟨λ _ _, nodup_map (λ _ _, (mul_left_inj _).1) hln', λ i j hj hij x hx₁ hx₂, let ⟨f, hf⟩ := list.mem_map.1 hx₁ in let ⟨g, hg⟩ := list.mem_map.1 hx₂ in have hix : x a = nth_le l i (lt_trans hij hj), by rw [← hf.2, mul_apply, hmeml hf.1, swap_apply_left], have hiy : x a = nth_le l j hj, by rw [← hg.2, mul_apply, hmeml hg.1, swap_apply_left], absurd (hf.2.trans (hg.2.symm)) $ λ h, ne_of_lt hij $ nodup_iff_nth_le_inj.1 hl' i j (lt_trans hij hj) hj $ by rw [← hix, hiy]⟩, λ f hf₁ hf₂, let ⟨x, hx, hx'⟩ := list.mem_bind.1 hf₂ in let ⟨g, hg⟩ := list.mem_map.1 hx' in have hgxa : g⁻¹ x = a, from f.injective $ by rw [hmeml hf₁, ← hg.2]; simp, have hxa : x ≠ a, from λ h, (list.nodup_cons.1 hl).1 (h ▸ hx), (list.nodup_cons.1 hl).1 $ hgxa ▸ mem_of_mem_perms_of_list hg.1 (by rwa [apply_inv_self, hgxa])⟩ def perms_of_finset (s : finset α) : finset (perm α) := quotient.hrec_on s.1 (λ l hl, ⟨perms_of_list l, nodup_perms_of_list hl⟩) (λ a b hab, hfunext (congr_arg _ (quotient.sound hab)) (λ ha hb _, heq_of_eq $ finset.ext.2 $ by simp [mem_perms_of_list_iff,mem_of_perm hab])) s.2 lemma mem_perms_of_finset_iff : ∀ {s : finset α} {f : perm α}, f ∈ perms_of_finset s ↔ ∀ {x}, f x ≠ x → x ∈ s := by rintros ⟨⟨l⟩, hs⟩ f; exact mem_perms_of_list_iff lemma card_perms_of_finset : ∀ (s : finset α), (perms_of_finset s).card = s.card.fact := by rintros ⟨⟨l⟩, hs⟩; exact length_perms_of_list l def fintype_perm [fintype α] : fintype (perm α) := ⟨perms_of_finset (@finset.univ α _), by simp [mem_perms_of_finset_iff]⟩ instance [fintype α] [fintype β] : fintype (α ≃ β) := if h : fintype.card β = fintype.card α then trunc.rec_on_subsingleton (fintype.equiv_fin α) (λ eα, trunc.rec_on_subsingleton (fintype.equiv_fin β) (λ eβ, @fintype.of_equiv _ (perm α) fintype_perm (equiv_congr (equiv.refl α) (eα.trans (eq.rec_on h eβ.symm)) : (α ≃ α) ≃ (α ≃ β)))) else ⟨∅, λ x, false.elim (h (fintype.card_eq.2 ⟨x.symm⟩))⟩ lemma fintype.card_perm [fintype α] : fintype.card (perm α) = (fintype.card α).fact := subsingleton.elim (@fintype_perm α _ _) (@equiv.fintype α α _ _ _ _) ▸ card_perms_of_finset _ lemma fintype.card_equiv [fintype α] [fintype β] (e : α ≃ β) : fintype.card (α ≃ β) = (fintype.card α).fact := fintype.card_congr (equiv_congr (equiv.refl α) e) ▸ fintype.card_perm lemma univ_eq_singleton_of_card_one {α} [fintype α] (x : α) (h : fintype.card α = 1) : (univ : finset α) = finset.singleton x := begin apply symm, apply eq_of_subset_of_card_le (subset_univ (finset.singleton x)), apply le_of_eq, simp [h, finset.card_univ] end end equiv namespace fintype section choose open fintype open equiv variables [fintype α] [decidable_eq α] (p : α → Prop) [decidable_pred p] def choose_x (hp : ∃! a : α, p a) : {a // p a} := ⟨finset.choose p univ (by simp; exact hp), finset.choose_property _ _ _⟩ def choose (hp : ∃! a, p a) : α := choose_x p hp lemma choose_spec (hp : ∃! a, p a) : p (choose p hp) := (choose_x p hp).property end choose section bijection_inverse open function variables [fintype α] [decidable_eq α] variables [fintype β] [decidable_eq β] variables {f : α → β} /-- ` `bij_inv f` is the unique inverse to a bijection `f`. This acts as a computable alternative to `function.inv_fun`. -/ def bij_inv (f_bij : bijective f) (b : β) : α := fintype.choose (λ a, f a = b) begin rcases f_bij.right b with ⟨a', fa_eq_b⟩, rw ← fa_eq_b, exact ⟨a', ⟨rfl, (λ a h, f_bij.left h)⟩⟩ end lemma left_inverse_bij_inv (f_bij : bijective f) : left_inverse (bij_inv f_bij) f := λ a, f_bij.left (choose_spec (λ a', f a' = f a) _) lemma right_inverse_bij_inv (f_bij : bijective f) : right_inverse (bij_inv f_bij) f := λ b, choose_spec (λ a', f a' = b) _ lemma bijective_bij_inv (f_bij : bijective f) : bijective (bij_inv f_bij) := ⟨injective_of_left_inverse (right_inverse_bij_inv _), surjective_of_has_right_inverse ⟨f, left_inverse_bij_inv _⟩⟩ end bijection_inverse lemma well_founded_of_trans_of_irrefl [fintype α] (r : α → α → Prop) [is_trans α r] [is_irrefl α r] : well_founded r := by classical; exact have ∀ x y, r x y → (univ.filter (λ z, r z x)).card < (univ.filter (λ z, r z y)).card, from λ x y hxy, finset.card_lt_card $ by simp only [finset.lt_iff_ssubset.symm, lt_iff_le_not_le, finset.le_iff_subset, finset.subset_iff, mem_filter, true_and, mem_univ, hxy]; exact ⟨λ z hzx, trans hzx hxy, not_forall_of_exists_not ⟨x, not_imp.2 ⟨hxy, irrefl x⟩⟩⟩, subrelation.wf this (measure_wf _) lemma preorder.well_founded [fintype α] [preorder α] : well_founded ((<) : α → α → Prop) := well_founded_of_trans_of_irrefl _ @[instance, priority 10] lemma linear_order.is_well_order [fintype α] [linear_order α] : is_well_order α (<) := { wf := preorder.well_founded } end fintype class infinite (α : Type*) : Prop := (not_fintype : fintype α → false) @[simp] lemma not_nonempty_fintype {α : Type*} : ¬nonempty (fintype α) ↔ infinite α := ⟨λf, ⟨λ x, f ⟨x⟩⟩, λ⟨f⟩ ⟨x⟩, f x⟩ namespace infinite lemma exists_not_mem_finset [infinite α] (s : finset α) : ∃ x, x ∉ s := classical.not_forall.1 $ λ h, not_fintype ⟨s, h⟩ @[priority 100] -- see Note [lower instance priority] instance nonempty (α : Type*) [infinite α] : nonempty α := nonempty_of_exists (exists_not_mem_finset (∅ : finset α)) lemma of_injective [infinite β] (f : β → α) (hf : injective f) : infinite α := ⟨λ I, by exactI not_fintype (fintype.of_injective f hf)⟩ lemma of_surjective [infinite β] (f : α → β) (hf : surjective f) : infinite α := ⟨λ I, by classical; exactI not_fintype (fintype.of_surjective f hf)⟩ private noncomputable def nat_embedding_aux (α : Type*) [infinite α] : ℕ → α | n := by letI := classical.dec_eq α; exact classical.some (exists_not_mem_finset ((multiset.range n).pmap (λ m (hm : m < n), nat_embedding_aux m) (λ _, multiset.mem_range.1)).to_finset) private lemma nat_embedding_aux_injective (α : Type*) [infinite α] : function.injective (nat_embedding_aux α) := begin assume m n h, letI := classical.dec_eq α, wlog hmlen : m ≤ n using m n, by_contradiction hmn, have hmn : m < n, from lt_of_le_of_ne hmlen hmn, refine (classical.some_spec (exists_not_mem_finset ((multiset.range n).pmap (λ m (hm : m < n), nat_embedding_aux α m) (λ _, multiset.mem_range.1)).to_finset)) _, refine multiset.mem_to_finset.2 (multiset.mem_pmap.2 ⟨m, multiset.mem_range.2 hmn, _⟩), rw [h, nat_embedding_aux] end noncomputable def nat_embedding (α : Type*) [infinite α] : ℕ ↪ α := ⟨_, nat_embedding_aux_injective α⟩ end infinite lemma not_injective_infinite_fintype [infinite α] [fintype β] (f : α → β) : ¬ injective f := assume (hf : injective f), have H : fintype α := fintype.of_injective f hf, infinite.not_fintype H lemma not_surjective_fintype_infinite [fintype α] [infinite β] (f : α → β) : ¬ surjective f := assume (hf : surjective f), have H : infinite α := infinite.of_surjective f hf, @infinite.not_fintype _ H infer_instance instance nat.infinite : infinite ℕ := ⟨λ ⟨s, hs⟩, finset.not_mem_range_self $ s.subset_range_sup_succ (hs _)⟩ instance int.infinite : infinite ℤ := infinite.of_injective int.of_nat (λ _ _, int.of_nat_inj)
e021b6ad7bdb7e6f9db2d7fd7f7a2143691667b1
6fca17f8d5025f89be1b2d9d15c9e0c4b4900cbf
/src/game/world7/level5.lean
5a7b9d195fab8cceb97f98d314aa19a98d99e127
[ "Apache-2.0" ]
permissive
arolihas/natural_number_game
4f0c93feefec93b8824b2b96adff8b702b8b43ce
8e4f7b4b42888a3b77429f90cce16292bd288138
refs/heads/master
1,621,872,426,808
1,586,270,467,000
1,586,270,467,000
253,648,466
0
0
null
1,586,219,694,000
1,586,219,694,000
null
UTF-8
Lean
false
false
1,004
lean
/- # Advanced proposition world. ## Level 5: `iff_trans` easter eggs. Let's try ``iff_trans` again. Try proving it in other ways. ### A trick. Instead of using `cases` on `h : P ↔ Q` you can just access the proofs of `P → Q` and `Q → P` directly with `h.1` and `h.2`. So you can solve this level with ``` intros hpq hqr, split, intro p, apply hqr.1, ... ``` ### Another trick Instead of using `cases` on `h : P ↔ Q`, you can just `rw h`, and this will change all `P`s to `Q`s in the goal. You can use this to create a much shorter proof. Note that this is an argument for *not* running the `cases` tactic on an iff statement; you cannot rewrite one-way implications, but you can rewrite two-way implications. ### Another trick `cc` works on this sort of goal too. -/ /- Lemma : no-side-bar If $P$, $Q$ and $R$ are true/false statements, then `P ↔ Q` and `Q ↔ R` together imply `P ↔ R`. -/ lemma iff_trans (P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) := begin end
b4e0e2b9e6433227a4ddcd49b7ffe8ac5ba27847
4fa161becb8ce7378a709f5992a594764699e268
/src/topology/algebra/infinite_sum.lean
c92b7babbb5a0f59303614e4efcab866174adc8f
[ "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
35,744
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 Infinite sum over a topological monoid This sum is known as unconditionally convergent, as it sums to the same value under all possible permutations. For Euclidean spaces (finite dimensional Banach spaces) this is equivalent to absolute convergence. Note: There are summable sequences which are not unconditionally convergent! The other way holds generally, see `has_sum.tendsto_sum_nat`. Reference: * Bourbaki: General Topology (1995), Chapter 3 §5 (Infinite sums in commutative groups) -/ import topology.instances.real noncomputable theory open finset filter function classical open_locale topological_space classical big_operators variables {α : Type*} {β : Type*} {γ : Type*} section has_sum variables [add_comm_monoid α] [topological_space α] /-- Infinite sum on a topological monoid The `at_top` filter on `finset α` is the limit of all finite sets towards the entire type. So we sum up bigger and bigger sets. This sum operation is still invariant under reordering, and a absolute sum operator. This is based on Mario Carneiro's infinite sum in Metamath. For the definition or many statements, α does not need to be a topological monoid. We only add this assumption later, for the lemmas where it is relevant. -/ def has_sum (f : β → α) (a : α) : Prop := tendsto (λs:finset β, ∑ b in s, f b) at_top (𝓝 a) /-- `summable f` means that `f` has some (infinite) sum. Use `tsum` to get the value. -/ def summable (f : β → α) : Prop := ∃a, has_sum f a /-- `tsum f` is the sum of `f` it exists, or 0 otherwise -/ def tsum (f : β → α) := if h : summable f then classical.some h else 0 notation `∑'` binders `, ` r:(scoped f, tsum f) := r variables {f g : β → α} {a b : α} {s : finset β} lemma summable.has_sum (ha : summable f) : has_sum f (∑'b, f b) := by simp [ha, tsum]; exact some_spec ha lemma has_sum.summable (h : has_sum f a) : summable f := ⟨a, h⟩ /-- Constant zero function has sum `0` -/ lemma has_sum_zero : has_sum (λb, 0 : β → α) 0 := by simp [has_sum, tendsto_const_nhds] lemma summable_zero : summable (λb, 0 : β → α) := has_sum_zero.summable lemma tsum_eq_zero_of_not_summable (h : ¬ summable f) : (∑'b, f b) = 0 := by simp [tsum, h] /-- If a function `f` vanishes outside of a finite set `s`, then it `has_sum` `∑ b in s, f b`. -/ lemma has_sum_sum_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : has_sum f (∑ b in s, f b) := tendsto_infi' s $ tendsto.congr' (assume t (ht : s ⊆ t), show ∑ b in s, f b = ∑ b in t, f b, from sum_subset ht $ assume x _, hf _) tendsto_const_nhds lemma has_sum_fintype [fintype β] (f : β → α) : has_sum f (∑ b, f b) := has_sum_sum_of_ne_finset_zero $ λ a h, h.elim (mem_univ _) lemma summable_sum_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : summable f := (has_sum_sum_of_ne_finset_zero hf).summable lemma has_sum_single {f : β → α} (b : β) (hf : ∀b' ≠ b, f b' = 0) : has_sum f (f b) := suffices has_sum f (∑ b' in {b}, f b'), by simpa using this, has_sum_sum_of_ne_finset_zero $ by simpa [hf] lemma has_sum_ite_eq (b : β) (a : α) : has_sum (λb', if b' = b then a else 0) a := begin convert has_sum_single b _, { exact (if_pos rfl).symm }, assume b' hb', exact if_neg hb' end lemma has_sum_of_iso {j : γ → β} {i : β → γ} (hf : has_sum f a) (h₁ : ∀x, i (j x) = x) (h₂ : ∀x, j (i x) = x) : has_sum (f ∘ j) a := have ∀x y, j x = j y → x = y, from assume x y h, have i (j x) = i (j y), by rw [h], by rwa [h₁, h₁] at this, have (λs:finset γ, ∑ x in s, f (j x)) = (λs:finset β, ∑ b in s, f b) ∘ (λs:finset γ, s.image j), from funext $ assume s, (sum_image $ assume x _ y _, this x y).symm, show tendsto (λs:finset γ, ∑ x in s, f (j x)) at_top (𝓝 a), by rw [this]; apply hf.comp (tendsto_finset_image_at_top_at_top h₂) lemma has_sum_iff_has_sum_of_iso {j : γ → β} (i : β → γ) (h₁ : ∀x, i (j x) = x) (h₂ : ∀x, j (i x) = x) : has_sum (f ∘ j) a ↔ has_sum f a := iff.intro (assume hfj, have has_sum ((f ∘ j) ∘ i) a, from has_sum_of_iso hfj h₂ h₁, by simp [(∘), h₂] at this; assumption) (assume hf, has_sum_of_iso hf h₁ h₂) lemma equiv.has_sum_iff (e : γ ≃ β) : has_sum (f ∘ e) a ↔ has_sum f a := has_sum_iff_has_sum_of_iso e.symm e.left_inv e.right_inv lemma equiv.summable_iff (e : γ ≃ β) : summable (f ∘ e) ↔ summable f := ⟨λ H, (e.has_sum_iff.1 H.has_sum).summable, λ H, (e.has_sum_iff.2 H.has_sum).summable⟩ lemma has_sum_hom (g : α → γ) [add_comm_monoid γ] [topological_space γ] [is_add_monoid_hom g] (h₃ : continuous g) (hf : has_sum f a) : has_sum (g ∘ f) (g a) := have (λs:finset β, ∑ b in s, g (f b)) = g ∘ (λs:finset β, ∑ b in s, f b), from funext $ assume s, s.sum_hom g, show tendsto (λs:finset β, ∑ b in s, g (f b)) at_top (𝓝 (g a)), by rw [this]; exact tendsto.comp (continuous_iff_continuous_at.mp h₃ a) hf /-- If `f : ℕ → α` has sum `a`, then the partial sums `∑_{i=0}^{n-1} f i` converge to `a`. -/ lemma has_sum.tendsto_sum_nat {f : ℕ → α} (h : has_sum f a) : tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) := @tendsto.comp _ _ _ finset.range (λ s : finset ℕ, ∑ n in s, f n) _ _ _ h tendsto_finset_range lemma has_sum_unique {a₁ a₂ : α} [t2_space α] : has_sum f a₁ → has_sum f a₂ → a₁ = a₂ := tendsto_nhds_unique at_top_ne_bot lemma has_sum_iff_tendsto_nat_of_summable [t2_space α] {f : ℕ → α} {a : α} (hf : summable f) : has_sum f a ↔ tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) := begin refine ⟨λ h, h.tendsto_sum_nat, λ h, _⟩, rw tendsto_nhds_unique at_top_ne_bot h hf.has_sum.tendsto_sum_nat, exact hf.has_sum end variable [topological_add_monoid α] lemma has_sum.add (hf : has_sum f a) (hg : has_sum g b) : has_sum (λb, f b + g b) (a + b) := by simp [has_sum, sum_add_distrib]; exact hf.add hg lemma summable.add (hf : summable f) (hg : summable g) : summable (λb, f b + g b) := (hf.has_sum.add hg.has_sum).summable lemma has_sum_sum {f : γ → β → α} {a : γ → α} {s : finset γ} : (∀i∈s, has_sum (f i) (a i)) → has_sum (λb, ∑ i in s, f i b) (∑ i in s, a i) := finset.induction_on s (by simp [has_sum_zero]) (by simp [has_sum.add] {contextual := tt}) lemma summable_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) : summable (λb, ∑ i in s, f i b) := (has_sum_sum $ assume i hi, (hf i hi).has_sum).summable lemma has_sum.sigma [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α} {a : α} (ha : has_sum f a) (hf : ∀b, has_sum (λc, f ⟨b, c⟩) (g b)) : has_sum g a := assume s' hs', let ⟨s, hs, hss', hsc⟩ := nhds_is_closed hs', ⟨u, hu⟩ := mem_at_top_sets.mp $ ha hs, fsts := u.image sigma.fst, snds := λb, u.bind (λp, (if h : p.1 = b then {cast (congr_arg γ h) p.2} else ∅ : finset (γ b))) in have u_subset : u ⊆ fsts.sigma snds, from subset_iff.mpr $ assume ⟨b, c⟩ hu, have hb : b ∈ fsts, from finset.mem_image.mpr ⟨_, hu, rfl⟩, have hc : c ∈ snds b, from mem_bind.mpr ⟨_, hu, by simp; refl⟩, by simp [mem_sigma, hb, hc] , mem_at_top_sets.mpr $ exists.intro fsts $ assume bs (hbs : fsts ⊆ bs), have h : ∀cs : Π b ∈ bs, finset (γ b), ((⋂b (hb : b ∈ bs), (λp:Πb, finset (γ b), p b) ⁻¹' {cs' | cs b hb ⊆ cs' }) ∩ (λp, ∑ b in bs, ∑ c in p b, f ⟨b, c⟩) ⁻¹' s).nonempty, from assume cs, let cs' := λb, (if h : b ∈ bs then cs b h else ∅) ∪ snds b in have sum_eq : ∑ b in bs, ∑ c in cs' b, f ⟨b, c⟩ = ∑ x in bs.sigma cs', f x, from sum_sigma.symm, have ∑ x in bs.sigma cs', f x ∈ s, from hu _ $ finset.subset.trans u_subset $ sigma_mono hbs $ assume b, @finset.subset_union_right (γ b) _ _ _, exists.intro cs' $ by simp [sum_eq, this]; { intros b hb, simp [cs', hb, finset.subset_union_left] }, have tendsto (λp:(Πb:β, finset (γ b)), ∑ b in bs, ∑ c in p b, f ⟨b, c⟩) (⨅b (h : b ∈ bs), at_top.comap (λp, p b)) (𝓝 (∑ b in bs, g b)), from tendsto_finset_sum bs $ assume c hc, tendsto_infi' c $ tendsto_infi' hc $ by apply tendsto.comp (hf c) tendsto_comap, have ∑ b in bs, g b ∈ s, from mem_of_closed_of_tendsto' this hsc $ forall_sets_nonempty_iff_ne_bot.mp $ begin simp only [mem_inf_sets, exists_imp_distrib, forall_and_distrib, and_imp, filter.mem_infi_sets_finset, mem_comap_sets, mem_at_top_sets, and_comm, mem_principal_sets, set.preimage_subset_iff, exists_prop, skolem], intros s₁ s₂ s₃ hs₁ hs₃ p hs₂ p' hp cs hp', have : (⋂b (h : b ∈ bs), (λp:(Πb, finset (γ b)), p b) ⁻¹' {cs' | cs b h ⊆ cs' }) ≤ (⨅b∈bs, p b), from (infi_le_infi $ assume b, infi_le_infi $ assume hb, le_trans (set.preimage_mono $ hp' b hb) (hp b hb)), exact (h _).mono (set.subset.trans (set.inter_subset_inter (le_trans this hs₂) hs₃) hs₁) end, hss' this lemma summable.sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α} (ha : summable f) (hf : ∀b, summable (λc, f ⟨b, c⟩)) : summable (λb, ∑'c, f ⟨b, c⟩) := (ha.has_sum.sigma (assume b, (hf b).has_sum)).summable lemma has_sum.sigma_of_has_sum [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α} {a : α} (ha : has_sum g a) (hf : ∀b, has_sum (λc, f ⟨b, c⟩) (g b)) (hf' : summable f) : has_sum f a := by simpa [has_sum_unique (hf'.has_sum.sigma hf) ha] using hf'.has_sum end has_sum section has_sum_iff_has_sum_of_iso_ne_zero variables [add_comm_monoid α] [topological_space α] variables {f : β → α} {g : γ → α} {a : α} lemma has_sum.has_sum_of_sum_eq (h_eq : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ ∑ x in u', g x = ∑ b in v', f b) (hf : has_sum g a) : has_sum f a := suffices at_top.map (λs:finset β, ∑ b in s, f b) ≤ at_top.map (λs:finset γ, ∑ x in s, g x), from le_trans this hf, by rw [map_at_top_eq, map_at_top_eq]; from (le_infi $ assume b, let ⟨v, hv⟩ := h_eq b in infi_le_of_le v $ by simp [set.image_subset_iff]; exact hv) lemma has_sum_iff_has_sum (h₁ : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ ∑ x in u', g x = ∑ b in v', f b) (h₂ : ∀v:finset β, ∃u:finset γ, ∀u', u ⊆ u' → ∃v', v ⊆ v' ∧ ∑ b in v', f b = ∑ x in u', g x) : has_sum f a ↔ has_sum g a := ⟨has_sum.has_sum_of_sum_eq h₂, has_sum.has_sum_of_sum_eq h₁⟩ variables (i : Π⦃c⦄, g c ≠ 0 → β) (hi : ∀⦃c⦄ (h : g c ≠ 0), f (i h) ≠ 0) (j : Π⦃b⦄, f b ≠ 0 → γ) (hj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) ≠ 0) (hji : ∀⦃c⦄ (h : g c ≠ 0), j (hi h) = c) (hij : ∀⦃b⦄ (h : f b ≠ 0), i (hj h) = b) (hgj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) = f b) include hi hj hji hij hgj -- FIXME this causes a deterministic timeout with `-T50000` lemma has_sum.has_sum_ne_zero : has_sum g a → has_sum f a := have j_inj : ∀x y (hx : f x ≠ 0) (hy : f y ≠ 0), (j hx = j hy ↔ x = y), from assume x y hx hy, ⟨assume h, have i (hj hx) = i (hj hy), by simp [h], by rwa [hij, hij] at this; assumption, by simp {contextual := tt}⟩, let ii : finset γ → finset β := λu, u.bind $ λc, if h : g c = 0 then ∅ else {i h} in let jj : finset β → finset γ := λv, v.bind $ λb, if h : f b = 0 then ∅ else {j h} in has_sum.has_sum_of_sum_eq $ assume u, exists.intro (ii u) $ assume v hv, exists.intro (u ∪ jj v) $ and.intro (subset_union_left _ _) $ have ∀c:γ, c ∈ u ∪ jj v → c ∉ jj v → g c = 0, from assume c hc hnc, classical.by_contradiction $ assume h : g c ≠ 0, have c ∈ u, from (finset.mem_union.1 hc).resolve_right hnc, have i h ∈ v, from hv $ by simp [mem_bind]; existsi c; simp [h, this], have j (hi h) ∈ jj v, by simp [mem_bind]; existsi i h; simp [h, hi, this], by rw [hji h] at this; exact hnc this, calc ∑ x in u ∪ jj v, g x = ∑ x in jj v, g x : (sum_subset (subset_union_right _ _) this).symm ... = ∑ x in v, _ : sum_bind $ by intros x _ y _ _; by_cases f x = 0; by_cases f y = 0; simp [*]; cc ... = ∑ x in v, f x : sum_congr rfl $ by intros x hx; by_cases f x = 0; simp [*] lemma has_sum_iff_has_sum_of_ne_zero : has_sum f a ↔ has_sum g a := iff.intro (has_sum.has_sum_ne_zero j hj i hi hij hji $ assume b hb, by rw [←hgj (hi _), hji]) (has_sum.has_sum_ne_zero i hi j hj hji hij hgj) lemma summable_iff_summable_ne_zero : summable g ↔ summable f := exists_congr $ assume a, has_sum_iff_has_sum_of_ne_zero j hj i hi hij hji $ assume b hb, by rw [←hgj (hi _), hji] end has_sum_iff_has_sum_of_iso_ne_zero section has_sum_iff_has_sum_of_bij_ne_zero variables [add_comm_monoid α] [topological_space α] variables {f : β → α} {g : γ → α} {a : α} (i : Π⦃c⦄, g c ≠ 0 → β) (h₁ : ∀⦃c₁ c₂⦄ (h₁ : g c₁ ≠ 0) (h₂ : g c₂ ≠ 0), i h₁ = i h₂ → c₁ = c₂) (h₂ : ∀⦃b⦄, f b ≠ 0 → ∃c (h : g c ≠ 0), i h = b) (h₃ : ∀⦃c⦄ (h : g c ≠ 0), f (i h) = g c) include i h₁ h₂ h₃ lemma has_sum_iff_has_sum_of_ne_zero_bij : has_sum f a ↔ has_sum g a := have hi : ∀⦃c⦄ (h : g c ≠ 0), f (i h) ≠ 0, from assume c h, by simp [h₃, h], let j : Π⦃b⦄, f b ≠ 0 → γ := λb h, some $ h₂ h in have hj : ∀⦃b⦄ (h : f b ≠ 0), ∃(h : g (j h) ≠ 0), i h = b, from assume b h, some_spec $ h₂ h, have hj₁ : ∀⦃b⦄ (h : f b ≠ 0), g (j h) ≠ 0, from assume b h, let ⟨h₁, _⟩ := hj h in h₁, have hj₂ : ∀⦃b⦄ (h : f b ≠ 0), i (hj₁ h) = b, from assume b h, let ⟨h₁, h₂⟩ := hj h in h₂, has_sum_iff_has_sum_of_ne_zero i hi j hj₁ (assume c h, h₁ (hj₁ _) h $ hj₂ _) hj₂ (assume b h, by rw [←h₃ (hj₁ _), hj₂]) lemma summable_iff_summable_ne_zero_bij : summable f ↔ summable g := exists_congr $ assume a, has_sum_iff_has_sum_of_ne_zero_bij @i h₁ h₂ h₃ end has_sum_iff_has_sum_of_bij_ne_zero section subtype variables [add_comm_monoid α] [topological_space α] {s : finset β} {f : β → α} {a : α} lemma has_sum_subtype_iff_of_eq_zero (h : ∀ x ∈ s, f x = 0) : has_sum (λ b : {b // b ∉ s}, f b) a ↔ has_sum f a := begin symmetry, apply has_sum_iff_has_sum_of_ne_zero_bij (λ (b : {b // b ∉ s}) hb, (b : β)), { exact λ c₁ c₂ h₁ h₂ H, subtype.eq H }, { assume b hb, have : b ∉ s := λ H, hb (h b H), exact ⟨⟨b, this⟩, hb, rfl⟩ }, { dsimp, simp } end end subtype section tsum variables [add_comm_monoid α] [topological_space α] [t2_space α] variables {f g : β → α} {a a₁ a₂ : α} lemma tsum_eq_has_sum (ha : has_sum f a) : (∑'b, f b) = a := has_sum_unique (summable.has_sum ⟨a, ha⟩) ha lemma summable.has_sum_iff (h : summable f) : has_sum f a ↔ (∑'b, f b) = a := iff.intro tsum_eq_has_sum (assume eq, eq ▸ h.has_sum) @[simp] lemma tsum_zero : (∑'b:β, 0:α) = 0 := tsum_eq_has_sum has_sum_zero lemma tsum_eq_sum {f : β → α} {s : finset β} (hf : ∀b∉s, f b = 0) : (∑'b, f b) = ∑ b in s, f b := tsum_eq_has_sum $ has_sum_sum_of_ne_finset_zero hf lemma tsum_fintype [fintype β] (f : β → α) : (∑'b, f b) = ∑ b, f b := tsum_eq_has_sum $ has_sum_fintype f lemma tsum_eq_single {f : β → α} (b : β) (hf : ∀b' ≠ b, f b' = 0) : (∑'b, f b) = f b := tsum_eq_has_sum $ has_sum_single b hf @[simp] lemma tsum_ite_eq (b : β) (a : α) : (∑'b', if b' = b then a else 0) = a := tsum_eq_has_sum (has_sum_ite_eq b a) lemma tsum_eq_tsum_of_has_sum_iff_has_sum {f : β → α} {g : γ → α} (h : ∀{a}, has_sum f a ↔ has_sum g a) : (∑'b, f b) = (∑'c, g c) := by_cases (assume : ∃a, has_sum f a, let ⟨a, hfa⟩ := this in have hga : has_sum g a, from h.mp hfa, by rw [tsum_eq_has_sum hfa, tsum_eq_has_sum hga]) (assume hf : ¬ summable f, have hg : ¬ summable g, from assume ⟨a, hga⟩, hf ⟨a, h.mpr hga⟩, by simp [tsum, hf, hg]) lemma tsum_eq_tsum_of_ne_zero {f : β → α} {g : γ → α} (i : Π⦃c⦄, g c ≠ 0 → β) (hi : ∀⦃c⦄ (h : g c ≠ 0), f (i h) ≠ 0) (j : Π⦃b⦄, f b ≠ 0 → γ) (hj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) ≠ 0) (hji : ∀⦃c⦄ (h : g c ≠ 0), j (hi h) = c) (hij : ∀⦃b⦄ (h : f b ≠ 0), i (hj h) = b) (hgj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) = f b) : (∑'i, f i) = (∑'j, g j) := tsum_eq_tsum_of_has_sum_iff_has_sum $ assume a, has_sum_iff_has_sum_of_ne_zero i hi j hj hji hij hgj lemma tsum_eq_tsum_of_ne_zero_bij {f : β → α} {g : γ → α} (i : Π⦃c⦄, g c ≠ 0 → β) (h₁ : ∀⦃c₁ c₂⦄ (h₁ : g c₁ ≠ 0) (h₂ : g c₂ ≠ 0), i h₁ = i h₂ → c₁ = c₂) (h₂ : ∀⦃b⦄, f b ≠ 0 → ∃c (h : g c ≠ 0), i h = b) (h₃ : ∀⦃c⦄ (h : g c ≠ 0), f (i h) = g c) : (∑'i, f i) = (∑'j, g j) := tsum_eq_tsum_of_has_sum_iff_has_sum $ assume a, has_sum_iff_has_sum_of_ne_zero_bij i h₁ h₂ h₃ lemma tsum_eq_tsum_of_iso (j : γ → β) (i : β → γ) (h₁ : ∀x, i (j x) = x) (h₂ : ∀x, j (i x) = x) : (∑'c, f (j c)) = (∑'b, f b) := tsum_eq_tsum_of_has_sum_iff_has_sum $ assume a, has_sum_iff_has_sum_of_iso i h₁ h₂ lemma tsum_equiv (j : γ ≃ β) : (∑'c, f (j c)) = (∑'b, f b) := tsum_eq_tsum_of_iso j j.symm (by simp) (by simp) variable [topological_add_monoid α] lemma tsum_add (hf : summable f) (hg : summable g) : (∑'b, f b + g b) = (∑'b, f b) + (∑'b, g b) := tsum_eq_has_sum $ hf.has_sum.add hg.has_sum lemma tsum_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) : (∑'b, ∑ i in s, f i b) = ∑ i in s, ∑'b, f i b := tsum_eq_has_sum $ has_sum_sum $ assume i hi, (hf i hi).has_sum lemma tsum_sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α} (h₁ : ∀b, summable (λc, f ⟨b, c⟩)) (h₂ : summable f) : (∑'p, f p) = (∑'b c, f ⟨b, c⟩) := (tsum_eq_has_sum $ h₂.has_sum.sigma (assume b, (h₁ b).has_sum)).symm end tsum section topological_group variables [add_comm_group α] [topological_space α] [topological_add_group α] variables {f g : β → α} {a a₁ a₂ : α} lemma has_sum.neg : has_sum f a → has_sum (λb, - f b) (- a) := has_sum_hom has_neg.neg continuous_neg lemma summable.neg (hf : summable f) : summable (λb, - f b) := hf.has_sum.neg.summable lemma has_sum.sub (hf : has_sum f a₁) (hg : has_sum g a₂) : has_sum (λb, f b - g b) (a₁ - a₂) := by { simp [sub_eq_add_neg], exact hf.add hg.neg } lemma summable.sub (hf : summable f) (hg : summable g) : summable (λb, f b - g b) := (hf.has_sum.sub hg.has_sum).summable section tsum variables [t2_space α] lemma tsum_neg (hf : summable f) : (∑'b, - f b) = - (∑'b, f b) := tsum_eq_has_sum $ hf.has_sum.neg lemma tsum_sub (hf : summable f) (hg : summable g) : (∑'b, f b - g b) = (∑'b, f b) - (∑'b, g b) := tsum_eq_has_sum $ hf.has_sum.sub hg.has_sum lemma tsum_eq_zero_add {f : ℕ → α} (hf : summable f) : (∑'b, f b) = f 0 + (∑'b, f (b + 1)) := begin let f₁ : ℕ → α := λ n, nat.rec (f 0) (λ _ _, 0) n, let f₂ : ℕ → α := λ n, nat.rec 0 (λ k _, f (k+1)) n, have : f = λ n, f₁ n + f₂ n, { ext n, symmetry, cases n, apply add_zero, apply zero_add }, have hf₁ : summable f₁, { fapply summable_sum_of_ne_finset_zero, { exact {0} }, { rintros (_ | n) hn, { exfalso, apply hn, apply finset.mem_singleton_self }, { refl } } }, have hf₂ : summable f₂, { have : f₂ = λ n, f n - f₁ n, ext, rw [eq_sub_iff_add_eq', this], rw [this], apply hf.sub hf₁ }, conv_lhs { rw [this] }, rw [tsum_add hf₁ hf₂, tsum_eq_single 0], { congr' 1, fapply tsum_eq_tsum_of_ne_zero_bij (λ n _, n + 1), { intros _ _ _ _, exact nat.succ.inj }, { rintros (_ | n) h, { contradiction }, { exact ⟨n, h, rfl⟩ } }, { intros, refl }, { apply_instance } }, { rintros (_ | n) hn, { contradiction }, { refl } }, { apply_instance } end end tsum /-! ### Sums on subtypes If `s` is a finset of `α`, we show that the summability of `f` in the whole space and on the subtype `univ - s` are equivalent, and relate their sums. For a function defined on `ℕ`, we deduce the formula `(∑ i in range k, f i) + (∑' i, f (i + k)) = (∑' i, f i)`, in `sum_add_tsum_nat_add`. -/ section subtype variables {s : finset β} lemma has_sum_subtype_iff : has_sum (λ b : {b // b ∉ s}, f b) a ↔ has_sum f (a + ∑ b in s, f b) := begin let gs := λ b, if b ∈ s then f b else 0, let g := λ b, if b ∉ s then f b else 0, have f_sum_iff : has_sum f (a + ∑ b in s, f b) = has_sum (λ b, g b + gs b) (a + ∑ b in s, f b), { congr, ext i, simp [gs, g], split_ifs; simp }, have g_zero : ∀ b ∈ s, g b = 0, { assume b hb, dsimp [g], split_ifs, refl }, have gs_sum : has_sum gs (∑ b in s, f b), { have : (∑ b in s, f b) = (∑ b in s, gs b), { apply sum_congr rfl (λ b hb, _), dsimp [gs], split_ifs, { refl }, { exact false.elim (h hb) } }, rw this, apply has_sum_sum_of_ne_finset_zero (λ b hb, _), dsimp [gs], split_ifs, { exact false.elim (hb h) }, { refl } }, have : (λ b : {b // b ∉ s}, f b) = (λ b : {b // b ∉ s}, g b), { ext i, simp [g], split_ifs, { exact false.elim (i.2 h) }, { refl } }, rw [this, has_sum_subtype_iff_of_eq_zero g_zero, f_sum_iff], exact ⟨λ H, H.add gs_sum, λ H, by simpa using H.sub gs_sum⟩, end lemma has_sum_subtype_iff' : has_sum (λ b : {b // b ∉ s}, f b) (a - ∑ b in s, f b) ↔ has_sum f a := by simp [has_sum_subtype_iff] lemma summable_subtype_iff (s : finset β): summable (λ b : {b // b ∉ s}, f b) ↔ summable f := ⟨λ H, (has_sum_subtype_iff.1 H.has_sum).summable, λ H, (has_sum_subtype_iff'.2 H.has_sum).summable⟩ lemma sum_add_tsum_subtype [t2_space α] (s : finset β) (h : summable f) : (∑ b in s, f b) + (∑' (b : {b // b ∉ s}), f b) = (∑' b, f b) := by simpa [add_comm] using has_sum_unique (has_sum_subtype_iff.1 ((summable_subtype_iff s).2 h).has_sum) h.has_sum lemma summable_nat_add_iff {f : ℕ → α} (k : ℕ) : summable (λ n, f (n + k)) ↔ summable f := begin refine iff.trans _ (summable_subtype_iff (range k)), rw [← (not_mem_range_equiv k).symm.summable_iff], refl end lemma has_sum_nat_add_iff {f : ℕ → α} (k : ℕ) {a : α} : has_sum (λ n, f (n + k)) a ↔ has_sum f (a + ∑ i in range k, f i) := begin refine iff.trans _ has_sum_subtype_iff, rw [← (not_mem_range_equiv k).symm.has_sum_iff], refl end lemma has_sum_nat_add_iff' {f : ℕ → α} (k : ℕ) {a : α} : has_sum (λ n, f (n + k)) (a - ∑ i in range k, f i) ↔ has_sum f a := by simp [has_sum_nat_add_iff] lemma sum_add_tsum_nat_add [t2_space α] {f : ℕ → α} (k : ℕ) (h : summable f) : (∑ i in range k, f i) + (∑' i, f (i + k)) = (∑' i, f i) := by simpa [add_comm] using has_sum_unique ((has_sum_nat_add_iff k).1 ((summable_nat_add_iff k).2 h).has_sum) h.has_sum end subtype end topological_group section topological_semiring variables [semiring α] [topological_space α] [topological_semiring α] variables {f g : β → α} {a a₁ a₂ : α} lemma has_sum.mul_left (a₂) : has_sum f a₁ → has_sum (λb, a₂ * f b) (a₂ * a₁) := has_sum_hom _ (continuous_const.mul continuous_id) lemma has_sum.mul_right (a₂) (hf : has_sum f a₁) : has_sum (λb, f b * a₂) (a₁ * a₂) := @has_sum_hom _ _ _ _ _ f a₁ (λa, a * a₂) _ _ _ (continuous_id.mul continuous_const) hf lemma summable.mul_left (a) (hf : summable f) : summable (λb, a * f b) := (hf.has_sum.mul_left _).summable lemma summable.mul_right (a) (hf : summable f) : summable (λb, f b * a) := (hf.has_sum.mul_right _).summable section tsum variables [t2_space α] lemma tsum_mul_left (a) (hf : summable f) : (∑'b, a * f b) = a * (∑'b, f b) := tsum_eq_has_sum $ hf.has_sum.mul_left _ lemma tsum_mul_right (a) (hf : summable f) : (∑'b, f b * a) = (∑'b, f b) * a := tsum_eq_has_sum $ hf.has_sum.mul_right _ end tsum end topological_semiring section field variables [field α] [topological_space α] [topological_semiring α] {f g : β → α} {a a₁ a₂ : α} lemma has_sum_mul_left_iff (h : a₂ ≠ 0) : has_sum f a₁ ↔ has_sum (λb, a₂ * f b) (a₂ * a₁) := ⟨has_sum.mul_left _, λ H, by simpa [← mul_assoc, inv_mul_cancel h] using H.mul_left a₂⁻¹⟩ lemma has_sum_mul_right_iff (h : a₂ ≠ 0) : has_sum f a₁ ↔ has_sum (λb, f b * a₂) (a₁ * a₂) := by { simp only [mul_comm _ a₂], exact has_sum_mul_left_iff h } lemma summable_mul_left_iff (h : a ≠ 0) : summable f ↔ summable (λb, a * f b) := ⟨λ H, H.mul_left _, λ H, by simpa [← mul_assoc, inv_mul_cancel h] using H.mul_left a⁻¹⟩ lemma summable_mul_right_iff (h : a ≠ 0) : summable f ↔ summable (λb, f b * a) := by { simp only [mul_comm _ a], exact summable_mul_left_iff h } end field section order_topology variables [ordered_add_comm_monoid α] [topological_space α] [order_closed_topology α] variables {f g : β → α} {a a₁ a₂ : α} lemma has_sum_le (h : ∀b, f b ≤ g b) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ := le_of_tendsto_of_tendsto' at_top_ne_bot hf hg $ assume s, sum_le_sum $ assume b _, h b lemma has_sum_le_inj {g : γ → α} (i : β → γ) (hi : injective i) (hs : ∀c∉set.range i, 0 ≤ g c) (h : ∀b, f b ≤ g (i b)) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ := have has_sum (λc, (partial_inv i c).cases_on' 0 f) a₁, begin refine (has_sum_iff_has_sum_of_ne_zero_bij (λb _, i b) _ _ _).2 hf, { assume c₁ c₂ h₁ h₂ eq, exact hi eq }, { assume c hc, cases eq : partial_inv i c with b; rw eq at hc, { contradiction }, { rw [partial_inv_of_injective hi] at eq, exact ⟨b, hc, eq⟩ } }, { assume c hc, rw [partial_inv_left hi, option.cases_on'] } end, begin refine has_sum_le (assume c, _) this hg, by_cases c ∈ set.range i, { rcases h with ⟨b, rfl⟩, rw [partial_inv_left hi, option.cases_on'], exact h _ }, { have : partial_inv i c = none := dif_neg h, rw [this, option.cases_on'], exact hs _ h } end lemma tsum_le_tsum_of_inj {g : γ → α} (i : β → γ) (hi : injective i) (hs : ∀c∉set.range i, 0 ≤ g c) (h : ∀b, f b ≤ g (i b)) (hf : summable f) (hg : summable g) : tsum f ≤ tsum g := has_sum_le_inj i hi hs h hf.has_sum hg.has_sum lemma sum_le_has_sum {f : β → α} (s : finset β) (hs : ∀ b∉s, 0 ≤ f b) (hf : has_sum f a) : ∑ b in s, f b ≤ a := ge_of_tendsto at_top_ne_bot hf (eventually_at_top.2 ⟨s, λ t hst, sum_le_sum_of_subset_of_nonneg hst $ λ b hbt hbs, hs b hbs⟩) lemma sum_le_tsum {f : β → α} (s : finset β) (hs : ∀ b∉s, 0 ≤ f b) (hf : summable f) : ∑ b in s, f b ≤ tsum f := sum_le_has_sum s hs hf.has_sum lemma tsum_le_tsum (h : ∀b, f b ≤ g b) (hf : summable f) (hg : summable g) : (∑'b, f b) ≤ (∑'b, g b) := has_sum_le h hf.has_sum hg.has_sum lemma tsum_nonneg (h : ∀ b, 0 ≤ g b) : 0 ≤ (∑'b, g b) := begin by_cases hg : summable g, { simpa using tsum_le_tsum h summable_zero hg }, { simp [tsum_eq_zero_of_not_summable hg] } end lemma tsum_nonpos (h : ∀ b, f b ≤ 0) : (∑'b, f b) ≤ 0 := begin by_cases hf : summable f, { simpa using tsum_le_tsum h hf summable_zero}, { simp [tsum_eq_zero_of_not_summable hf] } end end order_topology section uniform_group variables [add_comm_group α] [uniform_space α] variables {f g : β → α} {a a₁ a₂ : α} lemma summable_iff_cauchy_seq_finset [complete_space α] : summable f ↔ cauchy_seq (λ (s : finset β), ∑ b in s, f b) := (cauchy_map_iff_exists_tendsto at_top_ne_bot).symm variable [uniform_add_group α] lemma cauchy_seq_finset_iff_vanishing : cauchy_seq (λ (s : finset β), ∑ b in s, f b) ↔ ∀ e ∈ 𝓝 (0:α), (∃s:finset β, ∀t, disjoint t s → ∑ b in t, f b ∈ e) := begin simp only [cauchy_seq, cauchy_map_iff, and_iff_right at_top_ne_bot, prod_at_top_at_top_eq, uniformity_eq_comap_nhds_zero α, tendsto_comap_iff, (∘)], rw [tendsto_at_top' (_ : finset β × finset β → α)], split, { assume h e he, rcases h e he with ⟨⟨s₁, s₂⟩, h⟩, use [s₁ ∪ s₂], assume t ht, specialize h (s₁ ∪ s₂, (s₁ ∪ s₂) ∪ t) ⟨le_sup_left, le_sup_left_of_le le_sup_right⟩, simpa only [finset.sum_union ht.symm, add_sub_cancel'] using h }, { assume h e he, rcases exists_nhds_half_neg he with ⟨d, hd, hde⟩, rcases h d hd with ⟨s, h⟩, use [(s, s)], rintros ⟨t₁, t₂⟩ ⟨ht₁, ht₂⟩, have : ∑ b in t₂, f b - ∑ b in t₁, f b = ∑ b in t₂ \ s, f b - ∑ b in t₁ \ s, f b, { simp only [(finset.sum_sdiff ht₁).symm, (finset.sum_sdiff ht₂).symm, add_sub_add_right_eq_sub] }, simp only [this], exact hde _ _ (h _ finset.sdiff_disjoint) (h _ finset.sdiff_disjoint) } end variable [complete_space α] lemma summable_iff_vanishing : summable f ↔ ∀ e ∈ 𝓝 (0:α), (∃s:finset β, ∀t, disjoint t s → ∑ b in t, f b ∈ e) := by rw [summable_iff_cauchy_seq_finset, cauchy_seq_finset_iff_vanishing] /- TODO: generalize to monoid with a uniform continuous subtraction operator: `(a + b) - b = a` -/ lemma summable.summable_of_eq_zero_or_self (hf : summable f) (h : ∀b, g b = 0 ∨ g b = f b) : summable g := summable_iff_vanishing.2 $ assume e he, let ⟨s, hs⟩ := summable_iff_vanishing.1 hf e he in ⟨s, assume t ht, have eq : ∑ b in t.filter (λb, g b = f b), f b = ∑ b in t, g b := calc ∑ b in t.filter (λb, g b = f b), f b = ∑ b in t.filter (λb, g b = f b), g b : finset.sum_congr rfl (assume b hb, (finset.mem_filter.1 hb).2.symm) ... = ∑ b in t, g b : begin refine finset.sum_subset (finset.filter_subset _) _, assume b hbt hb, simp only [(∉), finset.mem_filter, and_iff_right hbt] at hb, exact (h b).resolve_right hb end, eq ▸ hs _ $ finset.disjoint_of_subset_left (finset.filter_subset _) ht⟩ lemma summable.summable_comp_of_injective {i : γ → β} (hf : summable f) (hi : injective i) : summable (f ∘ i) := suffices summable (λb, if b ∈ set.range i then f b else 0), begin refine (summable_iff_summable_ne_zero_bij (λc _, i c) _ _ _).1 this, { assume c₁ c₂ hc₁ hc₂ eq, exact hi eq }, { assume b hb, split_ifs at hb, { rcases h with ⟨c, rfl⟩, exact ⟨c, hb, rfl⟩ }, { contradiction } }, { assume c hc, exact if_pos (set.mem_range_self _) } end, hf.summable_of_eq_zero_or_self $ assume b, by by_cases b ∈ set.range i; simp [h] lemma summable.sigma_factor {γ : β → Type*} {f : (Σb:β, γ b) → α} (ha : summable f) (b : β) : summable (λc, f ⟨b, c⟩) := ha.summable_comp_of_injective (λ x y hxy, by simpa using hxy) lemma summable.sigma' [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α} (ha : summable f) : summable (λb, ∑'c, f ⟨b, c⟩) := ha.sigma (λ b, ha.sigma_factor b) lemma tsum_sigma' [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α} (ha : summable f) : (∑'p, f p) = (∑'b c, f ⟨b, c⟩) := tsum_sigma (λ b, ha.sigma_factor b) ha end uniform_group section cauchy_seq open finset.Ico filter /-- If the extended distance between consequent points of a sequence is estimated by a summable series of `nnreal`s, then the original sequence is a Cauchy sequence. -/ lemma cauchy_seq_of_edist_le_of_summable [emetric_space α] {f : ℕ → α} (d : ℕ → nnreal) (hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : summable d) : cauchy_seq f := begin refine emetric.cauchy_seq_iff_nnreal.2 (λ ε εpos, _), -- Actually we need partial sums of `d` to be a Cauchy sequence replace hd : cauchy_seq (λ (n : ℕ), ∑ x in range n, d x) := let ⟨_, H⟩ := hd in cauchy_seq_of_tendsto_nhds _ H.tendsto_sum_nat, -- Now we take the same `N` as in one of the definitions of a Cauchy sequence refine (metric.cauchy_seq_iff'.1 hd ε (nnreal.coe_pos.2 εpos)).imp (λ N hN n hn, _), have hsum := hN n hn, -- We simplify the known inequality rw [dist_nndist, nnreal.nndist_eq, ← sum_range_add_sum_Ico _ hn, nnreal.add_sub_cancel'] at hsum, norm_cast at hsum, replace hsum := lt_of_le_of_lt (le_max_left _ _) hsum, rw edist_comm, -- Then use `hf` to simplify the goal to the same form apply lt_of_le_of_lt (edist_le_Ico_sum_of_edist_le hn (λ k _ _, hf k)), assumption_mod_cast end /-- If the distance between consequent points of a sequence is estimated by a summable series, then the original sequence is a Cauchy sequence. -/ lemma cauchy_seq_of_dist_le_of_summable [metric_space α] {f : ℕ → α} (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) : cauchy_seq f := begin refine metric.cauchy_seq_iff'.2 (λε εpos, _), replace hd : cauchy_seq (λ (n : ℕ), ∑ x in range n, d x) := let ⟨_, H⟩ := hd in cauchy_seq_of_tendsto_nhds _ H.tendsto_sum_nat, refine (metric.cauchy_seq_iff'.1 hd ε εpos).imp (λ N hN n hn, _), have hsum := hN n hn, rw [real.dist_eq, ← sum_Ico_eq_sub _ hn] at hsum, calc dist (f n) (f N) = dist (f N) (f n) : dist_comm _ _ ... ≤ ∑ x in Ico N n, d x : dist_le_Ico_sum_of_dist_le hn (λ k _ _, hf k) ... ≤ abs (∑ x in Ico N n, d x) : le_abs_self _ ... < ε : hsum end lemma cauchy_seq_of_summable_dist [metric_space α] {f : ℕ → α} (h : summable (λn, dist (f n) (f n.succ))) : cauchy_seq f := cauchy_seq_of_dist_le_of_summable _ (λ _, le_refl _) h lemma dist_le_tsum_of_dist_le_of_tendsto [metric_space α] {f : ℕ → α} (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) : dist (f n) a ≤ ∑' m, d (n + m) := begin refine le_of_tendsto at_top_ne_bot (tendsto_const_nhds.dist ha) (eventually_at_top.2 ⟨n, λ m hnm, _⟩), refine le_trans (dist_le_Ico_sum_of_dist_le hnm (λ k _ _, hf k)) _, rw [sum_Ico_eq_sum_range], refine sum_le_tsum (range _) (λ _ _, le_trans dist_nonneg (hf _)) _, exact hd.summable_comp_of_injective (add_right_injective n) end lemma dist_le_tsum_of_dist_le_of_tendsto₀ [metric_space α] {f : ℕ → α} (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) {a : α} (ha : tendsto f at_top (𝓝 a)) : dist (f 0) a ≤ tsum d := by simpa only [zero_add] using dist_le_tsum_of_dist_le_of_tendsto d hf hd ha 0 lemma dist_le_tsum_dist_of_tendsto [metric_space α] {f : ℕ → α} (h : summable (λn, dist (f n) (f n.succ))) {a : α} (ha : tendsto f at_top (𝓝 a)) (n) : dist (f n) a ≤ ∑' m, dist (f (n+m)) (f (n+m).succ) := show dist (f n) a ≤ ∑' m, (λx, dist (f x) (f x.succ)) (n + m), from dist_le_tsum_of_dist_le_of_tendsto (λ n, dist (f n) (f n.succ)) (λ _, le_refl _) h ha n lemma dist_le_tsum_dist_of_tendsto₀ [metric_space α] {f : ℕ → α} (h : summable (λn, dist (f n) (f n.succ))) {a : α} (ha : tendsto f at_top (𝓝 a)) : dist (f 0) a ≤ ∑' n, dist (f n) (f n.succ) := by simpa only [zero_add] using dist_le_tsum_dist_of_tendsto h ha 0 end cauchy_seq
20a644d30cab845b4863135eb73691cad9ba99c9
94e33a31faa76775069b071adea97e86e218a8ee
/src/linear_algebra/matrix/adjugate.lean
e082ee796431e80b94864a57cc456b8f0fa5c187
[ "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
18,994
lean
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import algebra.associated import algebra.regular.basic import linear_algebra.matrix.mv_polynomial import linear_algebra.matrix.polynomial import ring_theory.polynomial.basic import tactic.linarith import tactic.ring_exp /-! # Cramer's rule and adjugate matrices The adjugate matrix is the transpose of the cofactor matrix. It is calculated with Cramer's rule, which we introduce first. The vectors returned by Cramer's rule are given by the linear map `cramer`, which sends a matrix `A` and vector `b` to the vector consisting of the determinant of replacing the `i`th column of `A` with `b` at index `i` (written as `(A.update_column i b).det`). Using Cramer's rule, we can compute for each matrix `A` the matrix `adjugate A`. The entries of the adjugate are the determinants of each minor of `A`. Instead of defining a minor to be `A` with row `i` and column `j` deleted, we replace the `i`th row of `A` with the `j`th basis vector; this has the same determinant as the minor but more importantly equals Cramer's rule applied to `A` and the `j`th basis vector, simplifying the subsequent proofs. We prove the adjugate behaves like `det A • A⁻¹`. ## Main definitions * `matrix.cramer A b`: the vector output by Cramer's rule on `A` and `b`. * `matrix.adjugate A`: the adjugate (or classical adjoint) of the matrix `A`. ## References * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix ## Tags cramer, cramer's rule, adjugate -/ namespace matrix universes u v variables {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] open_locale matrix big_operators polynomial open equiv equiv.perm finset section cramer /-! ### `cramer` section Introduce the linear map `cramer` with values defined by `cramer_map`. After defining `cramer_map` and showing it is linear, we will restrict our proofs to using `cramer`. -/ variables (A : matrix n n α) (b : n → α) /-- `cramer_map A b i` is the determinant of the matrix `A` with column `i` replaced with `b`, and thus `cramer_map A b` is the vector output by Cramer's rule on `A` and `b`. If `A ⬝ x = b` has a unique solution in `x`, `cramer_map A` sends the vector `b` to `A.det • x`. Otherwise, the outcome of `cramer_map` is well-defined but not necessarily useful. -/ def cramer_map (i : n) : α := (A.update_column i b).det lemma cramer_map_is_linear (i : n) : is_linear_map α (λ b, cramer_map A b i) := { map_add := det_update_column_add _ _, map_smul := det_update_column_smul _ _ } lemma cramer_is_linear : is_linear_map α (cramer_map A) := begin split; intros; ext i, { apply (cramer_map_is_linear A i).1 }, { apply (cramer_map_is_linear A i).2 } end /-- `cramer A b i` is the determinant of the matrix `A` with column `i` replaced with `b`, and thus `cramer A b` is the vector output by Cramer's rule on `A` and `b`. If `A ⬝ x = b` has a unique solution in `x`, `cramer A` sends the vector `b` to `A.det • x`. Otherwise, the outcome of `cramer` is well-defined but not necessarily useful. -/ def cramer (A : matrix n n α) : (n → α) →ₗ[α] (n → α) := is_linear_map.mk' (cramer_map A) (cramer_is_linear A) lemma cramer_apply (i : n) : cramer A b i = (A.update_column i b).det := rfl lemma cramer_transpose_apply (i : n) : cramer Aᵀ b i = (A.update_row i b).det := by rw [cramer_apply, update_column_transpose, det_transpose] lemma cramer_transpose_row_self (i : n) : Aᵀ.cramer (A i) = pi.single i A.det := begin ext j, rw [cramer_apply, pi.single_apply], split_ifs with h, { -- i = j: this entry should be `A.det` subst h, simp only [update_column_transpose, det_transpose, update_row, function.update_eq_self] }, { -- i ≠ j: this entry should be 0 rw [update_column_transpose, det_transpose], apply det_zero_of_row_eq h, rw [update_row_self, update_row_ne (ne.symm h)] } end lemma cramer_row_self (i : n) (h : ∀ j, b j = A j i) : A.cramer b = pi.single i A.det := begin rw [← transpose_transpose A, det_transpose], convert cramer_transpose_row_self Aᵀ i, exact funext h end @[simp] lemma cramer_one : cramer (1 : matrix n n α) = 1 := begin ext i j, convert congr_fun (cramer_row_self (1 : matrix n n α) (pi.single i 1) i _) j, { simp }, { intros j, rw [matrix.one_eq_pi_single, pi.single_comm] } end lemma cramer_smul (r : α) (A : matrix n n α) : cramer (r • A) = r ^ (fintype.card n - 1) • cramer A := linear_map.ext $ λ b, funext $ λ _, det_update_column_smul' _ _ _ _ @[simp] lemma cramer_subsingleton_apply [subsingleton n] (A : matrix n n α) (b : n → α) (i : n) : cramer A b i = b i := by rw [cramer_apply, det_eq_elem_of_subsingleton _ i, update_column_self] lemma cramer_zero [nontrivial n] : cramer (0 : matrix n n α) = 0 := begin ext i j, obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j, apply det_eq_zero_of_column_eq_zero j', intro j'', simp [update_column_ne hj'], end /-- Use linearity of `cramer` to take it out of a summation. -/ lemma sum_cramer {β} (s : finset β) (f : β → n → α) : ∑ x in s, cramer A (f x) = cramer A (∑ x in s, f x) := (linear_map.map_sum (cramer A)).symm /-- Use linearity of `cramer` and vector evaluation to take `cramer A _ i` out of a summation. -/ lemma sum_cramer_apply {β} (s : finset β) (f : n → β → α) (i : n) : ∑ x in s, cramer A (λ j, f j x) i = cramer A (λ (j : n), ∑ x in s, f j x) i := calc ∑ x in s, cramer A (λ j, f j x) i = (∑ x in s, cramer A (λ j, f j x)) i : (finset.sum_apply i s _).symm ... = cramer A (λ (j : n), ∑ x in s, f j x) i : by { rw [sum_cramer, cramer_apply], congr' with j, apply finset.sum_apply } end cramer section adjugate /-! ### `adjugate` section Define the `adjugate` matrix and a few equations. These will hold for any matrix over a commutative ring. -/ /-- The adjugate matrix is the transpose of the cofactor matrix. Typically, the cofactor matrix is defined by taking the determinant of minors, i.e. the matrix with a row and column removed. However, the proof of `mul_adjugate` becomes a lot easier if we define the minor as replacing a column with a basis vector, since it allows us to use facts about the `cramer` map. -/ def adjugate (A : matrix n n α) : matrix n n α := λ i, cramer Aᵀ (pi.single i 1) lemma adjugate_def (A : matrix n n α) : adjugate A = λ i, cramer Aᵀ (pi.single i 1) := rfl lemma adjugate_apply (A : matrix n n α) (i j : n) : adjugate A i j = (A.update_row j (pi.single i 1)).det := by { rw adjugate_def, simp only, rw [cramer_apply, update_column_transpose, det_transpose], } lemma adjugate_transpose (A : matrix n n α) : (adjugate A)ᵀ = adjugate (Aᵀ) := begin ext i j, rw [transpose_apply, adjugate_apply, adjugate_apply, update_row_transpose, det_transpose], rw [det_apply', det_apply'], apply finset.sum_congr rfl, intros σ _, congr' 1, by_cases i = σ j, { -- Everything except `(i , j)` (= `(σ j , j)`) is given by A, and the rest is a single `1`. congr; ext j', subst h, have : σ j' = σ j ↔ j' = j := σ.injective.eq_iff, rw [update_row_apply, update_column_apply], simp_rw this, rw [←dite_eq_ite, ←dite_eq_ite], congr' 1 with rfl, rw [pi.single_eq_same, pi.single_eq_same], }, { -- Otherwise, we need to show that there is a `0` somewhere in the product. have : (∏ j' : n, update_column A j (pi.single i 1) (σ j') j') = 0, { apply prod_eq_zero (mem_univ j), rw [update_column_self, pi.single_eq_of_ne' h], }, rw this, apply prod_eq_zero (mem_univ (σ⁻¹ i)), erw [apply_symm_apply σ i, update_row_self], apply pi.single_eq_of_ne, intro h', exact h ((symm_apply_eq σ).mp h') } end /-- Since the map `b ↦ cramer A b` is linear in `b`, it must be multiplication by some matrix. This matrix is `A.adjugate`. -/ lemma cramer_eq_adjugate_mul_vec (A : matrix n n α) (b : n → α) : cramer A b = A.adjugate.mul_vec b := begin nth_rewrite 1 ← A.transpose_transpose, rw [← adjugate_transpose, adjugate_def], have : b = ∑ i, (b i) • (pi.single i 1), { refine (pi_eq_sum_univ b).trans _, congr' with j, simp [pi.single_apply, eq_comm] }, nth_rewrite 0 this, ext k, simp [mul_vec, dot_product, mul_comm], end lemma mul_adjugate_apply (A : matrix n n α) (i j k) : A i k * adjugate A k j = cramer Aᵀ (pi.single k (A i k)) j := begin erw [←smul_eq_mul, ←pi.smul_apply, ←linear_map.map_smul, ←pi.single_smul', smul_eq_mul, mul_one], end lemma mul_adjugate (A : matrix n n α) : A ⬝ adjugate A = A.det • 1 := begin ext i j, rw [mul_apply, pi.smul_apply, pi.smul_apply, one_apply, smul_eq_mul, mul_boole], simp [mul_adjugate_apply, sum_cramer_apply, cramer_transpose_row_self, pi.single_apply, eq_comm] end lemma adjugate_mul (A : matrix n n α) : adjugate A ⬝ A = A.det • 1 := calc adjugate A ⬝ A = (Aᵀ ⬝ (adjugate Aᵀ))ᵀ : by rw [←adjugate_transpose, ←transpose_mul, transpose_transpose] ... = A.det • 1 : by rw [mul_adjugate (Aᵀ), det_transpose, transpose_smul, transpose_one] lemma adjugate_smul (r : α) (A : matrix n n α) : adjugate (r • A) = r ^ (fintype.card n - 1) • adjugate A := begin rw [adjugate, adjugate, transpose_smul, cramer_smul], refl, end /-- A stronger form of **Cramer's rule** that allows us to solve some instances of `A ⬝ x = b` even if the determinant is not a unit. A sufficient (but still not necessary) condition is that `A.det` divides `b`. -/ @[simp] lemma mul_vec_cramer (A : matrix n n α) (b : n → α) : A.mul_vec (cramer A b) = A.det • b := by rw [cramer_eq_adjugate_mul_vec, mul_vec_mul_vec, mul_adjugate, smul_mul_vec_assoc, one_mul_vec] lemma adjugate_subsingleton [subsingleton n] (A : matrix n n α) : adjugate A = 1 := begin ext i j, simp [subsingleton.elim i j, adjugate_apply, det_eq_elem_of_subsingleton _ i] end lemma adjugate_eq_one_of_card_eq_one {A : matrix n n α} (h : fintype.card n = 1) : adjugate A = 1 := begin haveI : subsingleton n := fintype.card_le_one_iff_subsingleton.mp h.le, exact adjugate_subsingleton _ end @[simp] lemma adjugate_zero [nontrivial n] : adjugate (0 : matrix n n α) = 0 := begin ext i j, obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j, apply det_eq_zero_of_column_eq_zero j', intro j'', simp [update_column_ne hj'], end @[simp] lemma adjugate_one : adjugate (1 : matrix n n α) = 1 := by { ext, simp [adjugate_def, matrix.one_apply, pi.single_apply, eq_comm] } @[simp] lemma adjugate_diagonal (v : n → α) : adjugate (diagonal v) = diagonal (λ i, ∏ j in finset.univ.erase i, v j) := begin ext, simp only [adjugate_def, cramer_apply, diagonal_transpose], obtain rfl | hij := eq_or_ne i j, { rw [diagonal_apply_eq, diagonal_update_column_single, det_diagonal, prod_update_of_mem (finset.mem_univ _), sdiff_singleton_eq_erase, one_mul] }, { rw diagonal_apply_ne _ hij, refine det_eq_zero_of_row_eq_zero j (λ k, _), obtain rfl | hjk := eq_or_ne k j, { rw [update_column_self, pi.single_eq_of_ne' hij] }, { rw [update_column_ne hjk, diagonal_apply_ne' _ hjk]} }, end lemma _root_.ring_hom.map_adjugate {R S : Type*} [comm_ring R] [comm_ring S] (f : R →+* S) (M : matrix n n R) : f.map_matrix M.adjugate = matrix.adjugate (f.map_matrix M) := begin ext i k, have : pi.single i (1 : S) = f ∘ pi.single i 1, { rw ←f.map_one, exact pi.single_op (λ i, f) (λ i, f.map_zero) i (1 : R) }, rw [adjugate_apply, ring_hom.map_matrix_apply, map_apply, ring_hom.map_matrix_apply, this, ←map_update_row, ←ring_hom.map_matrix_apply, ←ring_hom.map_det, ←adjugate_apply] end lemma _root_.alg_hom.map_adjugate {R A B : Type*} [comm_semiring R] [comm_ring A] [comm_ring B] [algebra R A] [algebra R B] (f : A →ₐ[R] B) (M : matrix n n A) : f.map_matrix M.adjugate = matrix.adjugate (f.map_matrix M) := f.to_ring_hom.map_adjugate _ lemma det_adjugate (A : matrix n n α) : (adjugate A).det = A.det ^ (fintype.card n - 1) := begin -- get rid of the `- 1` cases (fintype.card n).eq_zero_or_pos with h_card h_card, { haveI : is_empty n := fintype.card_eq_zero_iff.mp h_card, rw [h_card, nat.zero_sub, pow_zero, adjugate_subsingleton, det_one] }, replace h_card := tsub_add_cancel_of_le h_card.nat_succ_le, -- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring -- where `A'.det` is non-zero. let A' := mv_polynomial_X n n ℤ, suffices : A'.adjugate.det = A'.det ^ (fintype.card n - 1), { rw [←mv_polynomial_X_map_matrix_aeval ℤ A, ←alg_hom.map_adjugate, ←alg_hom.map_det, ←alg_hom.map_det, ←alg_hom.map_pow, this] }, apply mul_left_cancel₀ (show A'.det ≠ 0, from det_mv_polynomial_X_ne_zero n ℤ), calc A'.det * A'.adjugate.det = (A' ⬝ adjugate A').det : (det_mul _ _).symm ... = A'.det ^ fintype.card n : by rw [mul_adjugate, det_smul, det_one, mul_one] ... = A'.det * A'.det ^ (fintype.card n - 1) : by rw [←pow_succ, h_card], end @[simp] lemma adjugate_fin_zero (A : matrix (fin 0) (fin 0) α) : adjugate A = 0 := @subsingleton.elim _ matrix.subsingleton_of_empty_left _ _ @[simp] lemma adjugate_fin_one (A : matrix (fin 1) (fin 1) α) : adjugate A = 1 := adjugate_subsingleton A lemma adjugate_fin_two (A : matrix (fin 2) (fin 2) α) : adjugate A = ![![A 1 1, -A 0 1], ![-A 1 0, A 0 0]] := begin ext i j, rw [adjugate_apply, det_fin_two], fin_cases i with [0, 1]; fin_cases j with [0, 1]; simp only [nat.one_ne_zero, one_mul, fin.one_eq_zero_iff, pi.single_eq_same, zero_mul, fin.zero_eq_one_iff, sub_zero, pi.single_eq_of_ne, ne.def, not_false_iff, update_row_self, update_row_ne, cons_val_zero, mul_zero, mul_one, zero_sub, cons_val_one, head_cons], end @[simp] lemma adjugate_fin_two' (a b c d : α) : adjugate ![![a, b], ![c, d]] = ![![d, -b], ![-c, a]] := adjugate_fin_two _ lemma adjugate_conj_transpose [star_ring α] (A : matrix n n α) : A.adjugateᴴ = adjugate (Aᴴ) := begin dsimp only [conj_transpose], have : Aᵀ.adjugate.map star = adjugate (Aᵀ.map star) := ((star_ring_end α).map_adjugate Aᵀ), rw [A.adjugate_transpose, this], end lemma is_regular_of_is_left_regular_det {A : matrix n n α} (hA : is_left_regular A.det) : is_regular A := begin split, { intros B C h, refine hA.matrix _, rw [←matrix.one_mul B, ←matrix.one_mul C, ←matrix.smul_mul, ←matrix.smul_mul, ←adjugate_mul, matrix.mul_assoc, matrix.mul_assoc, ←mul_eq_mul A, h, mul_eq_mul] }, { intros B C h, simp only [mul_eq_mul] at h, refine hA.matrix _, rw [←matrix.mul_one B, ←matrix.mul_one C, ←matrix.mul_smul, ←matrix.mul_smul, ←mul_adjugate, ←matrix.mul_assoc, ←matrix.mul_assoc, h] } end lemma adjugate_mul_distrib_aux (A B : matrix n n α) (hA : is_left_regular A.det) (hB : is_left_regular B.det) : adjugate (A ⬝ B) = adjugate B ⬝ adjugate A := begin have hAB : is_left_regular (A ⬝ B).det, { rw [det_mul], exact hA.mul hB }, refine (is_regular_of_is_left_regular_det hAB).left _, rw [mul_eq_mul, mul_adjugate, mul_eq_mul, matrix.mul_assoc, ←matrix.mul_assoc B, mul_adjugate, smul_mul, matrix.one_mul, mul_smul, mul_adjugate, smul_smul, mul_comm, ←det_mul] end /-- Proof follows from "The trace Cayley-Hamilton theorem" by Darij Grinberg, Section 5.3 -/ lemma adjugate_mul_distrib (A B : matrix n n α) : adjugate (A ⬝ B) = adjugate B ⬝ adjugate A := begin let g : matrix n n α → matrix n n α[X] := λ M, M.map polynomial.C + (polynomial.X : α[X]) • 1, let f' : matrix n n α[X] →+* matrix n n α := (polynomial.eval_ring_hom 0).map_matrix, have f'_inv : ∀ M, f' (g M) = M, { intro, ext, simp [f', g], }, have f'_adj : ∀ (M : matrix n n α), f' (adjugate (g M)) = adjugate M, { intro, rw [ring_hom.map_adjugate, f'_inv] }, have f'_g_mul : ∀ (M N : matrix n n α), f' (g M ⬝ g N) = M ⬝ N, { intros, rw [←mul_eq_mul, ring_hom.map_mul, f'_inv, f'_inv, mul_eq_mul] }, have hu : ∀ (M : matrix n n α), is_regular (g M).det, { intros M, refine polynomial.monic.is_regular _, simp only [g, polynomial.monic.def, ←polynomial.leading_coeff_det_X_one_add_C M, add_comm] }, rw [←f'_adj, ←f'_adj, ←f'_adj, ←mul_eq_mul (f' (adjugate (g B))), ←f'.map_mul, mul_eq_mul, ←adjugate_mul_distrib_aux _ _ (hu A).left (hu B).left, ring_hom.map_adjugate, ring_hom.map_adjugate, f'_inv, f'_g_mul] end @[simp] lemma adjugate_pow (A : matrix n n α) (k : ℕ) : adjugate (A ^ k) = (adjugate A) ^ k := begin induction k with k IH, { simp }, { rw [pow_succ', mul_eq_mul, adjugate_mul_distrib, IH, ←mul_eq_mul, pow_succ] } end lemma det_smul_adjugate_adjugate (A : matrix n n α) : det A • adjugate (adjugate A) = det A ^ (fintype.card n - 1) • A := begin have : A ⬝ (A.adjugate ⬝ A.adjugate.adjugate) = A ⬝ (A.det ^ (fintype.card n - 1) • 1), { rw [←adjugate_mul_distrib, adjugate_mul, adjugate_smul, adjugate_one], }, rwa [←matrix.mul_assoc, mul_adjugate, matrix.mul_smul, matrix.mul_one, matrix.smul_mul, matrix.one_mul] at this, end /-- Note that this is not true for `fintype.card n = 1` since `1 - 2 = 0` and not `-1`. -/ lemma adjugate_adjugate (A : matrix n n α) (h : fintype.card n ≠ 1) : adjugate (adjugate A) = det A ^ (fintype.card n - 2) • A := begin -- get rid of the `- 2` cases h_card : (fintype.card n) with n', { haveI : is_empty n := fintype.card_eq_zero_iff.mp h_card, exact @subsingleton.elim _ (matrix.subsingleton_of_empty_left) _ _, }, cases n', { exact (h h_card).elim }, rw ←h_card, -- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring -- where `A'.det` is non-zero. let A' := mv_polynomial_X n n ℤ, suffices : adjugate (adjugate A') = det A' ^ (fintype.card n - 2) • A', { rw [←mv_polynomial_X_map_matrix_aeval ℤ A, ←alg_hom.map_adjugate, ←alg_hom.map_adjugate, this, ←alg_hom.map_det, ← alg_hom.map_pow, alg_hom.map_matrix_apply, alg_hom.map_matrix_apply, matrix.map_smul' _ _ _ (_root_.map_mul _)] }, have h_card' : fintype.card n - 2 + 1 = fintype.card n - 1, { simp [h_card] }, have is_reg : is_smul_regular (mv_polynomial (n × n) ℤ) (det A') := λ x y, mul_left_cancel₀ (det_mv_polynomial_X_ne_zero n ℤ), apply is_reg.matrix, rw [smul_smul, ←pow_succ, h_card', det_smul_adjugate_adjugate], end /-- A weaker version of `matrix.adjugate_adjugate` that uses `nontrivial`. -/ lemma adjugate_adjugate' (A : matrix n n α) [nontrivial n] : adjugate (adjugate A) = det A ^ (fintype.card n - 2) • A := adjugate_adjugate _ $ fintype.one_lt_card.ne' end adjugate end matrix
5d63ca6a4bfd89a8dc665752118afca28f616780
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/category_theory/adjunction/basic.lean
f51e02b4f7f773f14b6b00980da138f044062af1
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
19,390
lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Johan Commelin, Bhavik Mehta -/ import category_theory.equivalence /-! # Adjunctions between functors `F ⊣ G` represents the data of an adjunction between two functors `F : C ⥤ D` and `G : D ⥤ C`. `F` is the left adjoint and `G` is the right adjoint. We provide various useful constructors: * `mk_of_hom_equiv` * `mk_of_unit_counit` * `left_adjoint_of_equiv` / `right_adjoint_of equiv` construct a left/right adjoint of a given functor given the action on objects and the relevant equivalence of morphism spaces. * `adjunction_of_equiv_left` / `adjunction_of_equiv_right` witness that these constructions give adjunctions. There are also typeclasses `is_left_adjoint` / `is_right_adjoint`, carrying data witnessing that a given functor is a left or right adjoint. Given `[is_left_adjoint F]`, a right adjoint of `F` can be constructed as `right_adjoint F`. `adjunction.comp` composes adjunctions. `to_equivalence` upgrades an adjunction to an equivalence, given witnesses that the unit and counit are pointwise isomorphisms. Conversely `equivalence.to_adjunction` recovers the underlying adjunction from an equivalence. -/ namespace category_theory open category -- declare the `v`'s first; see `category_theory.category` for an explanation universes v₁ v₂ v₃ u₁ u₂ u₃ local attribute [elab_simple] whisker_left whisker_right variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D] /-- `F ⊣ G` represents the data of an adjunction between two functors `F : C ⥤ D` and `G : D ⥤ C`. `F` is the left adjoint and `G` is the right adjoint. To construct an `adjunction` between two functors, it's often easier to instead use the constructors `mk_of_hom_equiv` or `mk_of_unit_counit`. To construct a left adjoint, there are also constructors `left_adjoint_of_equiv` and `adjunction_of_equiv_left` (as well as their duals) which can be simpler in practice. Uniqueness of adjoints is shown in `category_theory.adjunction.opposites`. See https://stacks.math.columbia.edu/tag/0037. -/ structure adjunction (F : C ⥤ D) (G : D ⥤ C) := (hom_equiv : Π (X Y), (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y)) (unit : 𝟭 C ⟶ F.comp G) (counit : G.comp F ⟶ 𝟭 D) (hom_equiv_unit' : Π {X Y f}, (hom_equiv X Y) f = (unit : _ ⟶ _).app X ≫ G.map f . obviously) (hom_equiv_counit' : Π {X Y g}, (hom_equiv X Y).symm g = F.map g ≫ counit.app Y . obviously) infix ` ⊣ `:15 := adjunction /-- A class giving a chosen right adjoint to the functor `left`. -/ class is_left_adjoint (left : C ⥤ D) := (right : D ⥤ C) (adj : left ⊣ right) /-- A class giving a chosen left adjoint to the functor `right`. -/ class is_right_adjoint (right : D ⥤ C) := (left : C ⥤ D) (adj : left ⊣ right) /-- Extract the left adjoint from the instance giving the chosen adjoint. -/ def left_adjoint (R : D ⥤ C) [is_right_adjoint R] : C ⥤ D := is_right_adjoint.left R /-- Extract the right adjoint from the instance giving the chosen adjoint. -/ def right_adjoint (L : C ⥤ D) [is_left_adjoint L] : D ⥤ C := is_left_adjoint.right L /-- The adjunction associated to a functor known to be a left adjoint. -/ def adjunction.of_left_adjoint (left : C ⥤ D) [is_left_adjoint left] : adjunction left (right_adjoint left) := is_left_adjoint.adj /-- The adjunction associated to a functor known to be a right adjoint. -/ def adjunction.of_right_adjoint (right : C ⥤ D) [is_right_adjoint right] : adjunction (left_adjoint right) right := is_right_adjoint.adj namespace adjunction restate_axiom hom_equiv_unit' restate_axiom hom_equiv_counit' attribute [simp, priority 10] hom_equiv_unit hom_equiv_counit section variables {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) {X' X : C} {Y Y' : D} lemma hom_equiv_id (X : C) : adj.hom_equiv X _ (𝟙 _) = adj.unit.app X := by simp lemma hom_equiv_symm_id (X : D) : (adj.hom_equiv _ X).symm (𝟙 _) = adj.counit.app X := by simp @[simp, priority 10] lemma hom_equiv_naturality_left_symm (f : X' ⟶ X) (g : X ⟶ G.obj Y) : (adj.hom_equiv X' Y).symm (f ≫ g) = F.map f ≫ (adj.hom_equiv X Y).symm g := by rw [hom_equiv_counit, F.map_comp, assoc, adj.hom_equiv_counit.symm] @[simp] lemma hom_equiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) : (adj.hom_equiv X' Y) (F.map f ≫ g) = f ≫ (adj.hom_equiv X Y) g := by rw [← equiv.eq_symm_apply]; simp [-hom_equiv_unit] @[simp, priority 10] lemma hom_equiv_naturality_right (f : F.obj X ⟶ Y) (g : Y ⟶ Y') : (adj.hom_equiv X Y') (f ≫ g) = (adj.hom_equiv X Y) f ≫ G.map g := by rw [hom_equiv_unit, G.map_comp, ← assoc, ←hom_equiv_unit] @[simp] lemma hom_equiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') : (adj.hom_equiv X Y').symm (f ≫ G.map g) = (adj.hom_equiv X Y).symm f ≫ g := by rw [equiv.symm_apply_eq]; simp [-hom_equiv_counit] @[simp] lemma left_triangle : (whisker_right adj.unit F) ≫ (whisker_left F adj.counit) = nat_trans.id _ := begin ext, dsimp, erw [← adj.hom_equiv_counit, equiv.symm_apply_eq, adj.hom_equiv_unit], simp end @[simp] lemma right_triangle : (whisker_left G adj.unit) ≫ (whisker_right adj.counit G) = nat_trans.id _ := begin ext, dsimp, erw [← adj.hom_equiv_unit, ← equiv.eq_symm_apply, adj.hom_equiv_counit], simp end @[simp, reassoc] lemma left_triangle_components : F.map (adj.unit.app X) ≫ adj.counit.app (F.obj X) = 𝟙 (F.obj X) := congr_arg (λ (t : nat_trans _ (𝟭 C ⋙ F)), t.app X) adj.left_triangle @[simp, reassoc] lemma right_triangle_components {Y : D} : adj.unit.app (G.obj Y) ≫ G.map (adj.counit.app Y) = 𝟙 (G.obj Y) := congr_arg (λ (t : nat_trans _ (G ⋙ 𝟭 C)), t.app Y) adj.right_triangle @[simp, reassoc] lemma counit_naturality {X Y : D} (f : X ⟶ Y) : F.map (G.map f) ≫ (adj.counit).app Y = (adj.counit).app X ≫ f := adj.counit.naturality f @[simp, reassoc] lemma unit_naturality {X Y : C} (f : X ⟶ Y) : (adj.unit).app X ≫ G.map (F.map f) = f ≫ (adj.unit).app Y := (adj.unit.naturality f).symm lemma hom_equiv_apply_eq {A : C} {B : D} (f : F.obj A ⟶ B) (g : A ⟶ G.obj B) : adj.hom_equiv A B f = g ↔ f = (adj.hom_equiv A B).symm g := ⟨λ h, by {cases h, simp}, λ h, by {cases h, simp}⟩ lemma eq_hom_equiv_apply {A : C} {B : D} (f : F.obj A ⟶ B) (g : A ⟶ G.obj B) : g = adj.hom_equiv A B f ↔ (adj.hom_equiv A B).symm g = f := ⟨λ h, by {cases h, simp}, λ h, by {cases h, simp}⟩ end end adjunction namespace adjunction /-- This is an auxiliary data structure useful for constructing adjunctions. See `adjunction.mk_of_hom_equiv`. This structure won't typically be used anywhere else. -/ @[nolint has_inhabited_instance] structure core_hom_equiv (F : C ⥤ D) (G : D ⥤ C) := (hom_equiv : Π (X Y), (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y)) (hom_equiv_naturality_left_symm' : Π {X' X Y} (f : X' ⟶ X) (g : X ⟶ G.obj Y), (hom_equiv X' Y).symm (f ≫ g) = F.map f ≫ (hom_equiv X Y).symm g . obviously) (hom_equiv_naturality_right' : Π {X Y Y'} (f : F.obj X ⟶ Y) (g : Y ⟶ Y'), (hom_equiv X Y') (f ≫ g) = (hom_equiv X Y) f ≫ G.map g . obviously) namespace core_hom_equiv restate_axiom hom_equiv_naturality_left_symm' restate_axiom hom_equiv_naturality_right' attribute [simp, priority 10] hom_equiv_naturality_left_symm hom_equiv_naturality_right variables {F : C ⥤ D} {G : D ⥤ C} (adj : core_hom_equiv F G) {X' X : C} {Y Y' : D} @[simp] lemma hom_equiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) : (adj.hom_equiv X' Y) (F.map f ≫ g) = f ≫ (adj.hom_equiv X Y) g := by rw [← equiv.eq_symm_apply]; simp @[simp] lemma hom_equiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') : (adj.hom_equiv X Y').symm (f ≫ G.map g) = (adj.hom_equiv X Y).symm f ≫ g := by rw [equiv.symm_apply_eq]; simp end core_hom_equiv /-- This is an auxiliary data structure useful for constructing adjunctions. See `adjunction.mk_of_unit_counit`. This structure won't typically be used anywhere else. -/ @[nolint has_inhabited_instance] structure core_unit_counit (F : C ⥤ D) (G : D ⥤ C) := (unit : 𝟭 C ⟶ F.comp G) (counit : G.comp F ⟶ 𝟭 D) (left_triangle' : whisker_right unit F ≫ (functor.associator F G F).hom ≫ whisker_left F counit = nat_trans.id (𝟭 C ⋙ F) . obviously) (right_triangle' : whisker_left G unit ≫ (functor.associator G F G).inv ≫ whisker_right counit G = nat_trans.id (G ⋙ 𝟭 C) . obviously) namespace core_unit_counit restate_axiom left_triangle' restate_axiom right_triangle' attribute [simp] left_triangle right_triangle end core_unit_counit variables {F : C ⥤ D} {G : D ⥤ C} /-- Construct an adjunction between `F` and `G` out of a natural bijection between each `F.obj X ⟶ Y` and `X ⟶ G.obj Y`. -/ @[simps] def mk_of_hom_equiv (adj : core_hom_equiv F G) : F ⊣ G := { unit := { app := λ X, (adj.hom_equiv X (F.obj X)) (𝟙 (F.obj X)), naturality' := begin intros, erw [← adj.hom_equiv_naturality_left, ← adj.hom_equiv_naturality_right], dsimp, simp -- See note [dsimp, simp]. end }, counit := { app := λ Y, (adj.hom_equiv _ _).inv_fun (𝟙 (G.obj Y)), naturality' := begin intros, erw [← adj.hom_equiv_naturality_left_symm, ← adj.hom_equiv_naturality_right_symm], dsimp, simp end }, hom_equiv_unit' := λ X Y f, by erw [← adj.hom_equiv_naturality_right]; simp, hom_equiv_counit' := λ X Y f, by erw [← adj.hom_equiv_naturality_left_symm]; simp, .. adj } /-- Construct an adjunction between functors `F` and `G` given a unit and counit for the adjunction satisfying the triangle identities. -/ @[simps] def mk_of_unit_counit (adj : core_unit_counit F G) : F ⊣ G := { hom_equiv := λ X Y, { to_fun := λ f, adj.unit.app X ≫ G.map f, inv_fun := λ g, F.map g ≫ adj.counit.app Y, left_inv := λ f, begin change F.map (_ ≫ _) ≫ _ = _, rw [F.map_comp, assoc, ←functor.comp_map, adj.counit.naturality, ←assoc], convert id_comp f, have t := congr_arg (λ t : nat_trans _ _, t.app _) adj.left_triangle, dsimp at t, simp only [id_comp] at t, exact t, end, right_inv := λ g, begin change _ ≫ G.map (_ ≫ _) = _, rw [G.map_comp, ←assoc, ←functor.comp_map, ←adj.unit.naturality, assoc], convert comp_id g, have t := congr_arg (λ t : nat_trans _ _, t.app _) adj.right_triangle, dsimp at t, simp only [id_comp] at t, exact t, end }, .. adj } /-- The adjunction between the identity functor on a category and itself. -/ def id : 𝟭 C ⊣ 𝟭 C := { hom_equiv := λ X Y, equiv.refl _, unit := 𝟙 _, counit := 𝟙 _ } -- Satisfy the inhabited linter. instance : inhabited (adjunction (𝟭 C) (𝟭 C)) := ⟨id⟩ /-- If F and G are naturally isomorphic functors, establish an equivalence of hom-sets. -/ @[simps] def equiv_homset_left_of_nat_iso {F F' : C ⥤ D} (iso : F ≅ F') {X : C} {Y : D} : (F.obj X ⟶ Y) ≃ (F'.obj X ⟶ Y) := { to_fun := λ f, iso.inv.app _ ≫ f, inv_fun := λ g, iso.hom.app _ ≫ g, left_inv := λ f, by simp, right_inv := λ g, by simp } /-- If G and H are naturally isomorphic functors, establish an equivalence of hom-sets. -/ @[simps] def equiv_homset_right_of_nat_iso {G G' : D ⥤ C} (iso : G ≅ G') {X : C} {Y : D} : (X ⟶ G.obj Y) ≃ (X ⟶ G'.obj Y) := { to_fun := λ f, f ≫ iso.hom.app _, inv_fun := λ g, g ≫ iso.inv.app _, left_inv := λ f, by simp, right_inv := λ g, by simp } /-- Transport an adjunction along an natural isomorphism on the left. -/ def of_nat_iso_left {F G : C ⥤ D} {H : D ⥤ C} (adj : F ⊣ H) (iso : F ≅ G) : G ⊣ H := adjunction.mk_of_hom_equiv { hom_equiv := λ X Y, (equiv_homset_left_of_nat_iso iso.symm).trans (adj.hom_equiv X Y) } /-- Transport an adjunction along an natural isomorphism on the right. -/ def of_nat_iso_right {F : C ⥤ D} {G H : D ⥤ C} (adj : F ⊣ G) (iso : G ≅ H) : F ⊣ H := adjunction.mk_of_hom_equiv { hom_equiv := λ X Y, (adj.hom_equiv X Y).trans (equiv_homset_right_of_nat_iso iso) } /-- Transport being a right adjoint along a natural isomorphism. -/ def right_adjoint_of_nat_iso {F G : C ⥤ D} (h : F ≅ G) [r : is_right_adjoint F] : is_right_adjoint G := { left := r.left, adj := of_nat_iso_right r.adj h } /-- Transport being a left adjoint along a natural isomorphism. -/ def left_adjoint_of_nat_iso {F G : C ⥤ D} (h : F ≅ G) [r : is_left_adjoint F] : is_left_adjoint G := { right := r.right, adj := of_nat_iso_left r.adj h } section variables {E : Type u₃} [ℰ : category.{v₃} E] (H : D ⥤ E) (I : E ⥤ D) /-- Composition of adjunctions. See https://stacks.math.columbia.edu/tag/0DV0. -/ def comp (adj₁ : F ⊣ G) (adj₂ : H ⊣ I) : F ⋙ H ⊣ I ⋙ G := { hom_equiv := λ X Z, equiv.trans (adj₂.hom_equiv _ _) (adj₁.hom_equiv _ _), unit := adj₁.unit ≫ (whisker_left F $ whisker_right adj₂.unit G) ≫ (functor.associator _ _ _).inv, counit := (functor.associator _ _ _).hom ≫ (whisker_left I $ whisker_right adj₁.counit H) ≫ adj₂.counit } /-- If `F` and `G` are left adjoints then `F ⋙ G` is a left adjoint too. -/ instance left_adjoint_of_comp {E : Type u₃} [ℰ : category.{v₃} E] (F : C ⥤ D) (G : D ⥤ E) [Fl : is_left_adjoint F] [Gl : is_left_adjoint G] : is_left_adjoint (F ⋙ G) := { right := Gl.right ⋙ Fl.right, adj := comp _ _ Fl.adj Gl.adj } /-- If `F` and `G` are right adjoints then `F ⋙ G` is a right adjoint too. -/ instance right_adjoint_of_comp {E : Type u₃} [ℰ : category.{v₃} E] {F : C ⥤ D} {G : D ⥤ E} [Fr : is_right_adjoint F] [Gr : is_right_adjoint G] : is_right_adjoint (F ⋙ G) := { left := Gr.left ⋙ Fr.left, adj := comp _ _ Gr.adj Fr.adj } end section construct_left -- Construction of a left adjoint. In order to construct a left -- adjoint to a functor G : D → C, it suffices to give the object part -- of a functor F : C → D together with isomorphisms Hom(FX, Y) ≃ -- Hom(X, GY) natural in Y. The action of F on morphisms can be -- constructed from this data. variables {F_obj : C → D} {G} variables (e : Π X Y, (F_obj X ⟶ Y) ≃ (X ⟶ G.obj Y)) variables (he : ∀ X Y Y' g h, e X Y' (h ≫ g) = e X Y h ≫ G.map g) include he private lemma he' {X Y Y'} (f g) : (e X Y').symm (f ≫ G.map g) = (e X Y).symm f ≫ g := by intros; rw [equiv.symm_apply_eq, he]; simp /-- Construct a left adjoint functor to `G`, given the functor's value on objects `F_obj` and a bijection `e` between `F_obj X ⟶ Y` and `X ⟶ G.obj Y` satisfying a naturality law `he : ∀ X Y Y' g h, e X Y' (h ≫ g) = e X Y h ≫ G.map g`. Dual to `right_adjoint_of_equiv`. -/ @[simps] def left_adjoint_of_equiv : C ⥤ D := { obj := F_obj, map := λ X X' f, (e X (F_obj X')).symm (f ≫ e X' (F_obj X') (𝟙 _)), map_comp' := λ X X' X'' f f', begin rw [equiv.symm_apply_eq, he, equiv.apply_symm_apply], conv { to_rhs, rw [assoc, ←he, id_comp, equiv.apply_symm_apply] }, simp end } /-- Show that the functor given by `left_adjoint_of_equiv` is indeed left adjoint to `G`. Dual to `adjunction_of_equiv_right`. -/ @[simps] def adjunction_of_equiv_left : left_adjoint_of_equiv e he ⊣ G := mk_of_hom_equiv { hom_equiv := e, hom_equiv_naturality_left_symm' := begin intros, erw [← he' e he, ← equiv.apply_eq_iff_eq], simp [(he _ _ _ _ _).symm] end } end construct_left section construct_right -- Construction of a right adjoint, analogous to the above. variables {F} {G_obj : D → C} variables (e : Π X Y, (F.obj X ⟶ Y) ≃ (X ⟶ G_obj Y)) variables (he : ∀ X' X Y f g, e X' Y (F.map f ≫ g) = f ≫ e X Y g) include he private lemma he' {X' X Y} (f g) : F.map f ≫ (e X Y).symm g = (e X' Y).symm (f ≫ g) := by intros; rw [equiv.eq_symm_apply, he]; simp /-- Construct a right adjoint functor to `F`, given the functor's value on objects `G_obj` and a bijection `e` between `F.obj X ⟶ Y` and `X ⟶ G_obj Y` satisfying a naturality law `he : ∀ X Y Y' g h, e X' Y (F.map f ≫ g) = f ≫ e X Y g`. Dual to `left_adjoint_of_equiv`. -/ @[simps] def right_adjoint_of_equiv : D ⥤ C := { obj := G_obj, map := λ Y Y' g, (e (G_obj Y) Y') ((e (G_obj Y) Y).symm (𝟙 _) ≫ g), map_comp' := λ Y Y' Y'' g g', begin rw [← equiv.eq_symm_apply, ← he' e he, equiv.symm_apply_apply], conv { to_rhs, rw [← assoc, he' e he, comp_id, equiv.symm_apply_apply] }, simp end } /-- Show that the functor given by `right_adjoint_of_equiv` is indeed right adjoint to `F`. Dual to `adjunction_of_equiv_left`. -/ @[simps] def adjunction_of_equiv_right : F ⊣ right_adjoint_of_equiv e he := mk_of_hom_equiv { hom_equiv := e, hom_equiv_naturality_left_symm' := by intros; rw [equiv.symm_apply_eq, he]; simp, hom_equiv_naturality_right' := begin intros X Y Y' g h, erw [←he, equiv.apply_eq_iff_eq, ←assoc, he' e he, comp_id, equiv.symm_apply_apply] end } end construct_right /-- If the unit and counit of a given adjunction are (pointwise) isomorphisms, then we can upgrade the adjunction to an equivalence. -/ @[simps] noncomputable def to_equivalence (adj : F ⊣ G) [∀ X, is_iso (adj.unit.app X)] [∀ Y, is_iso (adj.counit.app Y)] : C ≌ D := { functor := F, inverse := G, unit_iso := nat_iso.of_components (λ X, as_iso (adj.unit.app X)) (by simp), counit_iso := nat_iso.of_components (λ Y, as_iso (adj.counit.app Y)) (by simp) } /-- If the unit and counit for the adjunction corresponding to a right adjoint functor are (pointwise) isomorphisms, then the functor is an equivalence of categories. -/ @[simps] noncomputable def is_right_adjoint_to_is_equivalence [is_right_adjoint G] [∀ X, is_iso ((adjunction.of_right_adjoint G).unit.app X)] [∀ Y, is_iso ((adjunction.of_right_adjoint G).counit.app Y)] : is_equivalence G := is_equivalence.of_equivalence_inverse (adjunction.of_right_adjoint G).to_equivalence end adjunction open adjunction namespace equivalence /-- The adjunction given by an equivalence of categories. (To obtain the opposite adjunction, simply use `e.symm.to_adjunction`. -/ def to_adjunction (e : C ≌ D) : e.functor ⊣ e.inverse := mk_of_unit_counit ⟨e.unit, e.counit, by { ext, dsimp, simp only [id_comp], exact e.functor_unit_comp _, }, by { ext, dsimp, simp only [id_comp], exact e.unit_inverse_comp _, }⟩ end equivalence namespace functor /-- An equivalence `E` is left adjoint to its inverse. -/ def adjunction (E : C ⥤ D) [is_equivalence E] : E ⊣ E.inv := (E.as_equivalence).to_adjunction /-- If `F` is an equivalence, it's a left adjoint. -/ @[priority 10] instance left_adjoint_of_equivalence {F : C ⥤ D} [is_equivalence F] : is_left_adjoint F := { right := _, adj := functor.adjunction F } @[simp] lemma right_adjoint_of_is_equivalence {F : C ⥤ D} [is_equivalence F] : right_adjoint F = inv F := rfl /-- If `F` is an equivalence, it's a right adjoint. -/ @[priority 10] instance right_adjoint_of_equivalence {F : C ⥤ D} [is_equivalence F] : is_right_adjoint F := { left := _, adj := functor.adjunction F.inv } @[simp] lemma left_adjoint_of_is_equivalence {F : C ⥤ D} [is_equivalence F] : left_adjoint F = inv F := rfl end functor end category_theory
f4f4890c372467be2e900cec62967533cd110a0e
976d2334b51721ddc405deb2e1754016d454286e
/lean_at_mc2020_source/source/solutions/exercise_prime.lean
5c02821560f7c6175379c576d1982a91fa6c96d9
[]
no_license
kbuzzard/lean-at-MC2020
11bb6ac9ec38a6caace9d5d9a1705d6794d9f477
1f7ca65a7ba5cc17eb49f525c02dc6b0e65d6543
refs/heads/master
1,668,496,422,317
1,594,131,838,000
1,594,131,838,000
277,877,735
0
0
null
1,594,142,006,000
1,594,142,005,000
null
UTF-8
Lean
false
false
2,415
lean
import data.nat.prime import data.nat.parity import tactic example (P : Prop) : ¬ ¬ ¬ P → ¬ P := begin intros nnnp p, apply nnnp, intro np, apply np, apply p, end example (p : ℕ) : p.prime → p = 2 ∨ p % 2 = 1 := begin library_search, end #check @nat.prime.eq_two_or_odd lemma eq_two_of_even_prime {p : ℕ} (hp : nat.prime p) (h_even : nat.even p) : p = 2 := begin cases nat.prime.eq_two_or_odd hp, {assumption}, rw ← nat.not_even_iff at h, contradiction, end lemma even_of_odd_add_odd {a b : ℕ} (ha : ¬ nat.even a) (hb : ¬ nat.even b) : nat.even (a + b) := begin rw nat.even_add, tauto, end lemma one_lt_of_nontrivial_factor {b c : ℕ} (hb : b < b * c) : 1 < c := begin contrapose! hb, interval_cases c, -- ⊢ b * 0 ≤ b simp, -- ⊢ b * 1 ≤ b simp, end example (n : ℕ) : 0 < n ↔ n ≠ 0 := begin split, {intros, linarith,}, contrapose!, simp, end lemma nontrivial_product_of_not_prime {k : ℕ} (hk : ¬ k.prime) (two_le_k : 2 ≤ k) : ∃ a b < k, 1 < a ∧ 1 < b ∧ a * b = k := begin have h1 := nat.exists_dvd_of_not_prime2 two_le_k hk, rcases h1 with ⟨a, ⟨b, hb⟩, ha1, ha2⟩, use [a, b], norm_num, split, assumption, split, rw [hb, lt_mul_iff_one_lt_left], linarith, cases b, {linarith}, {simp}, split, linarith, split, rw hb at ha2, apply one_lt_of_nontrivial_factor ha2, rw hb, end -- norm_num, linarith theorem three_fac_of_sum_consecutive_primes {p q : ℕ} (hp : p.prime) (hq : q.prime) (hpq : p < q) (p_ne_2 : p ≠ 2) (q_ne_2 : q ≠ 2) (consecutive : ∀ k, p < k → k < q → ¬ k.prime) : ∃ a b c, p + q = a * b * c ∧ a > 1 ∧ b > 1 ∧ c > 1 := begin use 2, have h1 : nat.even (p + q), { apply even_of_odd_add_odd, contrapose! p_ne_2, apply eq_two_of_even_prime; assumption, contrapose! q_ne_2, apply eq_two_of_even_prime; assumption, }, cases h1 with k hk, have hk' : ¬ k.prime, { apply consecutive; linarith }, have h2k : 2 ≤ k, { have := nat.prime.two_le hp, linarith, }, have h2 := nat.exists_dvd_of_not_prime2 _ hk', swap, { exact h2k }, -- for some reason I think it's interesting to have the student remember that they've already proved this rcases nontrivial_product_of_not_prime hk' h2k with ⟨ b, c, hbk, hck, hb1, hc1, hbc⟩, use [b,c], split, { rw [hk, ← hbc], ring }, split, { norm_num }, split; assumption, end
8c2f60be91cbdea5427fe5c59bdfc31a0b415180
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/analysis/calculus/darboux.lean
83cc696ac08ef668647d2600ee5579ffd95ae526
[]
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
2,090
lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.analysis.calculus.mean_value import Mathlib.PostPort namespace Mathlib /-! # Darboux's theorem In this file we prove that the derivative of a differentiable function on an interval takes all intermediate values. The proof is based on the [Wikipedia](https://en.wikipedia.org/wiki/Darboux%27s_theorem_(analysis)) page about this theorem. -/ /-- Darboux's theorem: if `a ≤ b` and `f' a < m < f' b`, then `f' c = m` for some `c ∈ [a, b]`. -/ theorem exists_has_deriv_within_at_eq_of_gt_of_lt {a : ℝ} {b : ℝ} {f : ℝ → ℝ} {f' : ℝ → ℝ} (hab : a ≤ b) (hf : ∀ (x : ℝ), x ∈ set.Icc a b → has_deriv_within_at f (f' x) (set.Icc a b) x) {m : ℝ} (hma : f' a < m) (hmb : m < f' b) : m ∈ f' '' set.Icc a b := sorry /-- Darboux's theorem: if `a ≤ b` and `f' a > m > f' b`, then `f' c = m` for some `c ∈ [a, b]`. -/ theorem exists_has_deriv_within_at_eq_of_lt_of_gt {a : ℝ} {b : ℝ} {f : ℝ → ℝ} {f' : ℝ → ℝ} (hab : a ≤ b) (hf : ∀ (x : ℝ), x ∈ set.Icc a b → has_deriv_within_at f (f' x) (set.Icc a b) x) {m : ℝ} (hma : m < f' a) (hmb : f' b < m) : m ∈ f' '' set.Icc a b := sorry /-- Darboux's theorem: the image of a convex set under `f'` is a convex set. -/ theorem convex_image_has_deriv_at {f : ℝ → ℝ} {f' : ℝ → ℝ} {s : set ℝ} (hs : convex s) (hf : ∀ (x : ℝ), x ∈ s → has_deriv_at f (f' x) x) : convex (f' '' s) := sorry /-- If the derivative of a function is never equal to `m`, then either it is always greater than `m`, or it is always less than `m`. -/ theorem deriv_forall_lt_or_forall_gt_of_forall_ne {f : ℝ → ℝ} {f' : ℝ → ℝ} {s : set ℝ} (hs : convex s) (hf : ∀ (x : ℝ), x ∈ s → has_deriv_at f (f' x) x) {m : ℝ} (hf' : ∀ (x : ℝ), x ∈ s → f' x ≠ m) : (∀ (x : ℝ), x ∈ s → f' x < m) ∨ ∀ (x : ℝ), x ∈ s → m < f' x := sorry
3c1d2e41d17ef9bb425fbc6ff29147ce2c1ac8fe
a4673261e60b025e2c8c825dfa4ab9108246c32e
/stage0/src/Lean/Meta/Transform.lean
755f197b7583a0433887132fadff88ade162db8a
[ "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
5,341
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.Basic namespace Lean inductive TransformStep := | done (e : Expr) | visit (e : Expr) namespace Core /-- Tranform the expression `input` using `pre` and `post`. - `pre s` is invoked before visiting the children of subterm 's'. If the result is `TransformStep.visit sNew`, then `sNew` is traversed by transform. If the result is `TransformStep.visit sNew`, then `s` is just replaced with `sNew`. In both cases, `sNew` must be definitionally equal to `s` - `post s` is invoked after visiting the children of subterm `s`. The term `s` in both `pre s` and `post s` may contain loose bound variables. So, this method is not appropriate for if one needs to apply operations (e.g., `whnf`, `inferType`) that do not handle loose bound variables. Consider using `Meta.transform` to avoid loose bound variables. This method is useful for applying transformations such as beta-reduction and delta-reduction. -/ partial def transform {m} [Monad m] [MonadLiftT CoreM m] [MonadControlT CoreM m] (input : Expr) (pre : Expr → m TransformStep := fun e => return TransformStep.visit e) (post : Expr → m TransformStep := fun e => return TransformStep.done e) : m Expr := let inst : STWorld IO.RealWorld m := ⟨⟩ let inst : MonadLiftT (ST IO.RealWorld) m := { monadLift := fun x => liftM (m := CoreM) (liftM (m := ST IO.RealWorld) x) } let rec visit (e : Expr) : MonadCacheT Expr Expr m Expr := checkCache e fun e => Core.withIncRecDepth do let rec visitPost (e : Expr) : MonadCacheT Expr Expr m Expr := do match (← post e) with | TransformStep.done e => pure e | TransformStep.visit e => visit e match (← pre e) with | TransformStep.done e => pure e | TransformStep.visit e => match e with | Expr.forallE _ d b _ => visitPost (e.updateForallE! (← visit d) (← visit b)) | Expr.lam _ d b _ => visitPost (e.updateLambdaE! (← visit d) (← visit b)) | Expr.letE _ t v b _ => visitPost (e.updateLet! (← visit t) (← visit v) (← visit b)) | Expr.app .. => e.withApp fun f args => do visitPost (mkAppN (← visit f) (← args.mapM visit)) | Expr.mdata _ b _ => visitPost (e.updateMData! (← visit b)) | Expr.proj _ _ b _ => visitPost (e.updateProj! (← visit b)) | _ => visitPost e visit input |>.run end Core namespace Meta /-- Similar to `Core.transform`, but terms provided to `pre` and `post` do not contain loose bound variables. So, it is safe to use any `MetaM` method at `pre` and `post`. -/ partial def transform {m} [Monad m] [MonadLiftT MetaM m] [MonadControlT MetaM m] (input : Expr) (pre : Expr → m TransformStep := fun e => return TransformStep.visit e) (post : Expr → m TransformStep := fun e => return TransformStep.done e) : m Expr := let inst : STWorld IO.RealWorld m := ⟨⟩ let inst : MonadLiftT (ST IO.RealWorld) m := { monadLift := fun x => liftM (m := MetaM) (liftM (m := ST IO.RealWorld) x) } let rec visit (e : Expr) : MonadCacheT Expr Expr m Expr := checkCache e fun e => Meta.withIncRecDepth do let rec visitPost (e : Expr) : MonadCacheT Expr Expr m Expr := do match (← post e) with | TransformStep.done e => pure e | TransformStep.visit e => visit e let rec visitLambda (fvars : Array Expr) (e : Expr) : MonadCacheT Expr Expr m Expr := do match e with | Expr.lam n d b c => withLocalDecl n c.binderInfo (← visit (d.instantiateRev fvars)) fun x => visitLambda (fvars.push x) b | e => visitPost (← mkLambdaFVars fvars (← visit (e.instantiateRev fvars))) let rec visitForall (fvars : Array Expr) (e : Expr) : MonadCacheT Expr Expr m Expr := do match e with | Expr.forallE n d b c => withLocalDecl n c.binderInfo (← visit (d.instantiateRev fvars)) fun x => visitForall (fvars.push x) b | e => visitPost (← mkForallFVars fvars (← visit (e.instantiateRev fvars))) let rec visitLet (fvars : Array Expr) (e : Expr) : MonadCacheT Expr Expr m Expr := do match e with | Expr.letE n t v b _ => withLetDecl n (← visit (t.instantiateRev fvars)) (← visit (v.instantiateRev fvars)) fun x => visitLet (fvars.push x) b | e => visitPost (← mkLetFVars fvars (← visit (e.instantiateRev fvars))) let visitApp (e : Expr) : MonadCacheT Expr Expr m Expr := e.withApp fun f args => do visitPost (mkAppN (← visit f) (← args.mapM visit)) match (← pre e) with | TransformStep.done e => pure e | TransformStep.visit e => match e with | Expr.forallE .. => visitLambda #[] e | Expr.lam .. => visitForall #[] e | Expr.letE .. => visitLet #[] e | Expr.app .. => visitApp e | Expr.mdata _ b _ => visitPost (e.updateMData! (← visit b)) | Expr.proj _ _ b _ => visitPost (e.updateProj! (← visit b)) | _ => visitPost e visit input |>.run end Meta end Lean
28ff04c100ca00dcb9cf6c3fd4f7a4c5a762652c
c3f2fcd060adfa2ca29f924839d2d925e8f2c685
/tests/lean/fold.lean
f29e2ebba5ba0f9ac0fcd54fd208fa76112caff0
[ "Apache-2.0" ]
permissive
respu/lean
6582d19a2f2838a28ecd2b3c6f81c32d07b5341d
8c76419c60b63d0d9f7bc04ebb0b99812d0ec654
refs/heads/master
1,610,882,451,231
1,427,747,084,000
1,427,747,429,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
871
lean
prelude definition Prop := Type.{0} inductive true : Prop := intro : true inductive false : Prop constant num : Type inductive prod (A B : Type) := mk : A → B → prod A B infixl `×`:30 := prod variables a b c : num context notation `(` t:(foldr `,` (e r, prod.mk e r)) `)` := t check (a, false, b, true, c) set_option pp.notation false check (a, false, b, true, c) end context notation `(` t:(foldr `,` (e r, prod.mk r e)) `)` := t check (a, false, b, true, c) set_option pp.notation false check (a, false, b, true, c) end context notation `(` t:(foldl `,` (e r, prod.mk r e)) `)` := t check (a, false, b, true, c) set_option pp.notation false check (a, false, b, true, c) end context notation `(` t:(foldl `,` (e r, prod.mk e r)) `)` := t check (a, false, b, true, c) set_option pp.notation false check (a, false, b, true, c) end
c1225e8a1fb74c3850fe9c17778aa81ba415a1e5
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/topology/vector_bundle.lean
f5def52fdb1bfd10efcac890f2920ed310f6a396
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
17,732
lean
/- Copyright © 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Sebastien Gouezel -/ import topology.fiber_bundle import topology.algebra.module.basic /-! # Topological vector bundles In this file we define topological vector bundles. Let `B` be the base space. In our formalism, a topological vector bundle is by definition the type `bundle.total_space E` where `E : B → Type*` is a function associating to `x : B` the fiber over `x`. This type `bundle.total_space E` is just a type synonym for `Σ (x : B), E x`, with the interest that one can put another topology than on `Σ (x : B), E x` which has the disjoint union topology. To have a topological vector bundle structure on `bundle.total_space E`, one should addtionally have the following data: * `F` should be a topological space and a module over a semiring `R`; * There should be a topology on `bundle.total_space E`, for which the projection to `B` is a topological fiber bundle with fiber `F` (in particular, each fiber `E x` is homeomorphic to `F`); * For each `x`, the fiber `E x` should be a topological vector space over `R`, and the injection from `E x` to `bundle.total_space F E` should be an embedding; * The most important condition: around each point, there should be a bundle trivialization which is a continuous linear equiv in the fibers. If all these conditions are satisfied, we register the typeclass `topological_vector_bundle R F E`. We emphasize that the data is provided by other classes, and that the `topological_vector_bundle` class is `Prop`-valued. The point of this formalism is that it is unbundled in the sense that the total space of the bundle is a type with a topology, with which one can work or put further structure, and still one can perform operations on topological vector bundles (which are yet to be formalized). For instance, assume that `E₁ : B → Type*` and `E₂ : B → Type*` define two topological vector bundles over `R` with fiber models `F₁` and `F₂` which are normed spaces. Then one can construct the vector bundle of continuous linear maps from `E₁ x` to `E₂ x` with fiber `E x := (E₁ x →L[R] E₂ x)` (and with the topology inherited from the norm-topology on `F₁ →L[R] F₂`, without the need to define the strong topology on continuous linear maps between general topological vector spaces). Let `vector_bundle_continuous_linear_map R F₁ E₁ F₂ E₂ (x : B)` be a type synonym for `E₁ x →L[R] E₂ x`. Then one can endow `bundle.total_space (vector_bundle_continuous_linear_map R F₁ E₁ F₂ E₂)` with a topology and a topological vector bundle structure. Similar constructions can be done for tensor products of topological vector bundles, exterior algebras, and so on, where the topology can be defined using a norm on the fiber model if this helps. ## Tags Vector bundle -/ noncomputable theory open bundle set variables (R : Type*) {B : Type*} (F : Type*) (E : B → Type*) [semiring R] [∀ x, add_comm_monoid (E x)] [∀ x, module R (E x)] [topological_space F] [add_comm_monoid F] [module R F] [topological_space (total_space E)] [topological_space B] section /-- Local trivialization for vector bundles. -/ @[nolint has_inhabited_instance] structure topological_vector_bundle.trivialization extends to_fiber_bundle_trivialization : topological_fiber_bundle.trivialization F (proj E) := (linear : ∀ x ∈ base_set, is_linear_map R (λ y : (E x), (to_fun y).2)) open topological_vector_bundle instance : has_coe_to_fun (trivialization R F E) (λ _, total_space E → B × F) := ⟨λ e, e.to_fun⟩ instance : has_coe (trivialization R F E) (topological_fiber_bundle.trivialization F (proj E)) := ⟨topological_vector_bundle.trivialization.to_fiber_bundle_trivialization⟩ namespace topological_vector_bundle variables {R F E} lemma trivialization.mem_source (e : trivialization R F E) {x : total_space E} : x ∈ e.source ↔ proj E x ∈ e.base_set := topological_fiber_bundle.trivialization.mem_source e @[simp, mfld_simps] lemma trivialization.coe_coe (e : trivialization R F E) : ⇑e.to_local_homeomorph = e := rfl @[simp, mfld_simps] lemma trivialization.coe_fst (e : trivialization R F E) {x : total_space E} (ex : x ∈ e.source) : (e x).1 = (proj E) x := e.proj_to_fun x ex end topological_vector_bundle end variables [∀ x, topological_space (E x)] /-- The space `total_space E` (for `E : B → Type*` such that each `E x` is a topological vector space) has a topological vector space structure with fiber `F` (denoted with `topological_vector_bundle R F E`) if around every point there is a fiber bundle trivialization which is linear in the fibers. -/ class topological_vector_bundle : Prop := (inducing [] : ∀ (b : B), inducing (λ x : (E b), (id ⟨b, x⟩ : total_space E))) (locally_trivial [] : ∀ b : B, ∃ e : topological_vector_bundle.trivialization R F E, b ∈ e.base_set) variable [topological_vector_bundle R F E] namespace topological_vector_bundle /-- `trivialization_at R F E b` is some choice of trivialization of a vector bundle whose base set contains a given point `b`. -/ def trivialization_at : Π b : B, trivialization R F E := λ b, classical.some (locally_trivial R F E b) @[simp, mfld_simps] lemma mem_base_set_trivialization_at (b : B) : b ∈ (trivialization_at R F E b).base_set := classical.some_spec (locally_trivial R F E b) @[simp, mfld_simps] lemma mem_source_trivialization_at (z : total_space E) : z ∈ (trivialization_at R F E z.1).source := by { rw topological_fiber_bundle.trivialization.mem_source, apply mem_base_set_trivialization_at } variables {R F E} namespace trivialization /-- In a topological vector bundle, a trivialization in the fiber (which is a priori only linear) is in fact a continuous linear equiv between the fibers and the model fiber. -/ def continuous_linear_equiv_at (e : trivialization R F E) (b : B) (hb : b ∈ e.base_set) : E b ≃L[R] F := { to_fun := λ y, (e ⟨b, y⟩).2, inv_fun := λ z, begin have : ((e.to_local_homeomorph.symm) (b, z)).fst = b := topological_fiber_bundle.trivialization.proj_symm_apply' _ hb, have C : E ((e.to_local_homeomorph.symm) (b, z)).fst = E b, by rw this, exact cast C (e.to_local_homeomorph.symm (b, z)).2 end, left_inv := begin assume v, rw [← heq_iff_eq], apply (cast_heq _ _).trans, have A : (b, (e ⟨b, v⟩).snd) = e ⟨b, v⟩, { refine prod.ext _ rfl, symmetry, exact topological_fiber_bundle.trivialization.coe_fst' _ hb }, have B : e.to_local_homeomorph.symm (e ⟨b, v⟩) = ⟨b, v⟩, { apply local_homeomorph.left_inv_on, rw topological_fiber_bundle.trivialization.mem_source, exact hb }, rw [A, B], end, right_inv := begin assume v, have B : e (e.to_local_homeomorph.symm (b, v)) = (b, v), { apply local_homeomorph.right_inv_on, rw topological_fiber_bundle.trivialization.mem_target, exact hb }, have C : (e (e.to_local_homeomorph.symm (b, v))).2 = v, by rw [B], conv_rhs { rw ← C }, dsimp, congr, ext, { exact (topological_fiber_bundle.trivialization.proj_symm_apply' _ hb).symm }, { exact (cast_heq _ _).trans (by refl) }, end, map_add' := λ v w, (e.linear _ hb).map_add v w, map_smul' := λ c v, (e.linear _ hb).map_smul c v, continuous_to_fun := begin refine continuous_snd.comp _, apply continuous_on.comp_continuous e.to_local_homeomorph.continuous_on (topological_vector_bundle.inducing R F E b).continuous (λ x, _), rw topological_fiber_bundle.trivialization.mem_source, exact hb, end, continuous_inv_fun := begin rw (topological_vector_bundle.inducing R F E b).continuous_iff, dsimp, have : continuous (λ (z : F), e.to_fiber_bundle_trivialization.to_local_homeomorph.symm (b, z)), { apply e.to_local_homeomorph.symm.continuous_on.comp_continuous (continuous_const.prod_mk continuous_id') (λ z, _), simp only [topological_fiber_bundle.trivialization.mem_target, hb, local_equiv.symm_source, local_homeomorph.symm_to_local_equiv] }, convert this, ext z, { exact (topological_fiber_bundle.trivialization.proj_symm_apply' _ hb).symm }, { exact cast_heq _ _ }, end } @[simp] lemma continuous_linear_equiv_at_apply (e : trivialization R F E) (b : B) (hb : b ∈ e.base_set) (y : E b) : e.continuous_linear_equiv_at b hb y = (e ⟨b, y⟩).2 := rfl @[simp] lemma continuous_linear_equiv_at_apply' (e : trivialization R F E) (x : total_space E) (hx : x ∈ e.source) : e.continuous_linear_equiv_at (proj E x) (e.mem_source.1 hx) x.2 = (e x).2 := by { cases x, refl } end trivialization section local attribute [reducible] bundle.trivial instance {B : Type*} {F : Type*} [add_comm_monoid F] (b : B) : add_comm_monoid (bundle.trivial B F b) := ‹add_comm_monoid F› instance {B : Type*} {F : Type*} [add_comm_group F] (b : B) : add_comm_group (bundle.trivial B F b) := ‹add_comm_group F› instance {B : Type*} {F : Type*} [add_comm_monoid F] [module R F] (b : B) : module R (bundle.trivial B F b) := ‹module R F› end variables (R B F) /-- Local trivialization for trivial bundle. -/ def trivial_topological_vector_bundle.trivialization : trivialization R F (bundle.trivial B F) := { to_fun := λ x, (x.fst, x.snd), inv_fun := λ y, ⟨y.fst, y.snd⟩, source := univ, target := univ, map_source' := λ x h, mem_univ (x.fst, x.snd), map_target' :=λ y h, mem_univ ⟨y.fst, y.snd⟩, left_inv' := λ x h, sigma.eq rfl rfl, right_inv' := λ x h, prod.ext rfl rfl, open_source := is_open_univ, open_target := is_open_univ, continuous_to_fun := by { rw [←continuous_iff_continuous_on_univ, continuous_iff_le_induced], simp only [prod.topological_space, induced_inf, induced_compose], exact le_rfl, }, continuous_inv_fun := by { rw [←continuous_iff_continuous_on_univ, continuous_iff_le_induced], simp only [bundle.total_space.topological_space, induced_inf, induced_compose], exact le_rfl, }, base_set := univ, open_base_set := is_open_univ, source_eq := rfl, target_eq := by simp only [univ_prod_univ], proj_to_fun := λ y hy, rfl, linear := λ x hx, ⟨λ y z, rfl, λ c y, rfl⟩ } instance trivial_bundle.topological_vector_bundle : topological_vector_bundle R F (bundle.trivial B F) := { locally_trivial := λ x, ⟨trivial_topological_vector_bundle.trivialization R B F, mem_univ x⟩, inducing := λ b, ⟨begin have : (λ (x : trivial B F b), x) = @id F, by { ext x, refl }, simp only [total_space.topological_space, induced_inf, induced_compose, function.comp, proj, induced_const, top_inf_eq, trivial.proj_snd, id.def, trivial.topological_space, this, induced_id], end⟩ } variables {R B F} /- Not registered as an instance because of a metavariable. -/ lemma is_topological_vector_bundle_is_topological_fiber_bundle : is_topological_fiber_bundle F (proj E) := λ x, ⟨(trivialization_at R F E x).to_fiber_bundle_trivialization, mem_base_set_trivialization_at R F E x⟩ end topological_vector_bundle /-! ### Constructing topological vector bundles -/ variables (B) /-- Analogous construction of `topological_fiber_bundle_core` for vector bundles. This construction gives a way to construct vector bundles from a structure registering how trivialization changes act on fibers.-/ @[nolint has_inhabited_instance] structure topological_vector_bundle_core (ι : Type*) := (base_set : ι → set B) (is_open_base_set : ∀ i, is_open (base_set i)) (index_at : B → ι) (mem_base_set_at : ∀ x, x ∈ base_set (index_at x)) (coord_change : ι → ι → B → (F →ₗ[R] F)) (coord_change_self : ∀ i, ∀ x ∈ base_set i, ∀ v, coord_change i i x v = v) (coord_change_continuous : ∀ i j, continuous_on (λp : B × F, coord_change i j p.1 p.2) (((base_set i) ∩ (base_set j)) ×ˢ (univ : set F))) (coord_change_comp : ∀ i j k, ∀ x ∈ (base_set i) ∩ (base_set j) ∩ (base_set k), ∀ v, (coord_change j k x) (coord_change i j x v) = coord_change i k x v) attribute [simp, mfld_simps] topological_vector_bundle_core.mem_base_set_at namespace topological_vector_bundle_core variables {R B F} {ι : Type*} (Z : topological_vector_bundle_core R B F ι) /-- Natural identification to a `topological_fiber_bundle_core`. -/ def to_topological_vector_bundle_core : topological_fiber_bundle_core ι B F := { coord_change := λ i j b, Z.coord_change i j b, ..Z } instance to_topological_vector_bundle_core_coe : has_coe (topological_vector_bundle_core R B F ι) (topological_fiber_bundle_core ι B F) := ⟨to_topological_vector_bundle_core⟩ include Z lemma coord_change_linear_comp (i j k : ι): ∀ x ∈ (Z.base_set i) ∩ (Z.base_set j) ∩ (Z.base_set k), (Z.coord_change j k x).comp (Z.coord_change i j x) = Z.coord_change i k x := λ x hx, by { ext v, exact Z.coord_change_comp i j k x hx v } /-- The index set of a topological vector bundle core, as a convenience function for dot notation -/ @[nolint unused_arguments has_inhabited_instance] def index := ι /-- The base space of a topological vector bundle core, as a convenience function for dot notation-/ @[nolint unused_arguments, reducible] def base := B /-- The fiber of a topological vector bundle core, as a convenience function for dot notation and typeclass inference -/ @[nolint unused_arguments has_inhabited_instance] def fiber (x : B) := F section fiber_instances local attribute [reducible] fiber --just to record instances instance topological_space_fiber (x : B) : topological_space (Z.fiber x) := by apply_instance instance add_comm_monoid_fiber : ∀ (x : B), add_comm_monoid (Z.fiber x) := λ x, by apply_instance instance module_fiber : ∀ (x : B), module R (Z.fiber x) := λ x, by apply_instance end fiber_instances /-- The projection from the total space of a topological fiber bundle core, on its base. -/ @[reducible, simp, mfld_simps] def proj : total_space Z.fiber → B := bundle.proj Z.fiber /-- Local homeomorphism version of the trivialization change. -/ def triv_change (i j : ι) : local_homeomorph (B × F) (B × F) := topological_fiber_bundle_core.triv_change ↑Z i j @[simp, mfld_simps] lemma mem_triv_change_source (i j : ι) (p : B × F) : p ∈ (Z.triv_change i j).source ↔ p.1 ∈ Z.base_set i ∩ Z.base_set j := topological_fiber_bundle_core.mem_triv_change_source ↑Z i j p variable (ι) /-- Topological structure on the total space of a topological bundle created from core, designed so that all the local trivialization are continuous. -/ instance to_topological_space : topological_space (total_space Z.fiber) := topological_fiber_bundle_core.to_topological_space ι ↑Z variables {ι} (b : B) (a : F) @[simp, mfld_simps] lemma coe_cord_change (i j : ι) : topological_fiber_bundle_core.coord_change ↑Z i j b = Z.coord_change i j b := rfl /-- Extended version of the local trivialization of a fiber bundle constructed from core, registering additionally in its type that it is a local bundle trivialization. -/ def local_triv (i : ι) : topological_vector_bundle.trivialization R F Z.fiber := { linear := λ x hx, { map_add := λ v w, by simp only [linear_map.map_add] with mfld_simps, map_smul := λ r v, by simp only [linear_map.map_smul] with mfld_simps}, ..topological_fiber_bundle_core.local_triv ↑Z i } @[simp, mfld_simps] lemma mem_local_triv_source (i : ι) (p : total_space Z.fiber) : p ∈ (Z.local_triv i).source ↔ p.1 ∈ Z.base_set i := iff.rfl /-- Preferred local trivialization of a vector bundle constructed from core, at a given point, as a bundle trivialization -/ def local_triv_at (b : B) : topological_vector_bundle.trivialization R F Z.fiber := Z.local_triv (Z.index_at b) lemma mem_source_at : (⟨b, a⟩ : total_space Z.fiber) ∈ (Z.local_triv_at b).source := by { rw [local_triv_at, mem_local_triv_source], exact Z.mem_base_set_at b } @[simp, mfld_simps] lemma local_triv_at_apply : ((Z.local_triv_at b) ⟨b, a⟩) = ⟨b, a⟩ := topological_fiber_bundle_core.local_triv_at_apply Z b a instance : topological_vector_bundle R F Z.fiber := { inducing := λ b, ⟨ begin refine le_antisymm _ (λ s h, _), { rw ←continuous_iff_le_induced, exact topological_fiber_bundle_core.continuous_total_space_mk ↑Z b, }, { refine is_open_induced_iff.mpr ⟨(Z.local_triv_at b).source ∩ (Z.local_triv_at b) ⁻¹' ((Z.local_triv_at b).base_set ×ˢ s), (continuous_on_open_iff (Z.local_triv_at b).open_source).mp (Z.local_triv_at b).continuous_to_fun _ ((Z.local_triv_at b).open_base_set.prod h), _⟩, rw [preimage_inter, ←preimage_comp, function.comp], simp only [id.def], refine ext_iff.mpr (λ a, ⟨λ ha, _, λ ha, ⟨Z.mem_base_set_at b, _⟩⟩), { simp only [mem_prod, mem_preimage, mem_inter_eq, local_triv_at_apply] at ha, exact ha.2.2, }, { simp only [mem_prod, mem_preimage, mem_inter_eq, local_triv_at_apply], exact ⟨Z.mem_base_set_at b, ha⟩, } } end⟩, locally_trivial := λ b, ⟨Z.local_triv_at b, Z.mem_base_set_at b⟩, } /-- The projection on the base of a topological vector bundle created from core is continuous -/ @[continuity] lemma continuous_proj : continuous Z.proj := topological_fiber_bundle_core.continuous_proj Z /-- The projection on the base of a topological vector bundle created from core is an open map -/ lemma is_open_map_proj : is_open_map Z.proj := topological_fiber_bundle_core.is_open_map_proj Z end topological_vector_bundle_core
847b8abbf3e75a940dbdff1f35150fa9c0bd039d
b00eb947a9c4141624aa8919e94ce6dcd249ed70
/src/Lean/Meta/Tactic/Rewrite.lean
f057ee311d3b727376c41f6aa672877137d8c9be
[ "Apache-2.0" ]
permissive
gebner/lean4-old
a4129a041af2d4d12afb3a8d4deedabde727719b
ee51cdfaf63ee313c914d83264f91f414a0e3b6e
refs/heads/master
1,683,628,606,745
1,622,651,300,000
1,622,654,405,000
142,608,821
1
0
null
null
null
null
UTF-8
Lean
false
false
2,902
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.MatchUtil import Lean.Meta.KAbstract import Lean.Meta.Check import Lean.Meta.Tactic.Apply namespace Lean.Meta structure RewriteResult where eNew : Expr eqProof : Expr mvarIds : List MVarId -- new goals def rewrite (mvarId : MVarId) (e : Expr) (heq : Expr) (symm : Bool := false) (occs : Occurrences := Occurrences.all) (mode := TransparencyMode.reducible) : MetaM RewriteResult := withMVarContext mvarId do checkNotAssigned mvarId `rewrite let heqType ← inferType heq let (newMVars, binderInfos, heqType) ← forallMetaTelescopeReducing heqType let heq := mkAppN heq newMVars let cont (heq heqType : Expr) : MetaM RewriteResult := do match (← matchEq? heqType) with | none => throwTacticEx `rewrite mvarId m!"equality or iff proof expected{indentExpr heqType}" | some (α, lhs, rhs) => let cont (heq heqType lhs rhs : Expr) : MetaM RewriteResult := do if lhs.getAppFn.isMVar then throwTacticEx `rewrite mvarId m!"pattern is a metavariable{indentExpr lhs}\nfrom equation{indentExpr heqType}" let e ← instantiateMVars e let eAbst ← withTransparency mode <| kabstract e lhs occs unless eAbst.hasLooseBVars do throwTacticEx `rewrite mvarId m!"did not find instance of the pattern in the target expression{indentExpr lhs}" -- construct rewrite proof let eNew := eAbst.instantiate1 rhs let eNew ← instantiateMVars eNew let eEqE ← mkEq e e let eEqEAbst := mkApp eEqE.appFn! eAbst let motive := Lean.mkLambda `_a BinderInfo.default α eEqEAbst unless (← isTypeCorrect motive) do throwTacticEx `rewrite mvarId "motive is not type correct" let eqRefl ← mkEqRefl e let eqPrf ← mkEqNDRec motive eqRefl heq postprocessAppMVars `rewrite mvarId newMVars binderInfos let newMVarIds ← newMVars.map Expr.mvarId! |>.filterM (not <$> isExprMVarAssigned ·) let otherMVarIds ← getMVarsNoDelayed eqPrf let otherMVarIds := otherMVarIds.filter (!newMVarIds.contains ·) let newMVarIds := newMVarIds ++ otherMVarIds pure { eNew := eNew, eqProof := eqPrf, mvarIds := newMVarIds.toList } match symm with | false => cont heq heqType lhs rhs | true => do let heq ← mkEqSymm heq let heqType ← mkEq rhs lhs cont heq heqType rhs lhs match heqType.iff? with | some (lhs, rhs) => let heqType ← mkEq lhs rhs let heq := mkApp3 (mkConst `propext) lhs rhs heq cont heq heqType | none => cont heq heqType end Lean.Meta
c5599a28239d670ebb2bfb1dace0d6b67a9a8d27
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/algebra/order/monoid/to_mul_bot.lean
87b6ec8497284f7e66364a744d071d2777c9b999
[ "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,631
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import algebra.order.with_zero import algebra.order.monoid.with_top import algebra.order.monoid.type_tags /-! Making an additive monoid multiplicative then adding a zero is the same as adding a bottom element then making it multiplicative. -/ universe u variables {α : Type u} namespace with_zero local attribute [semireducible] with_zero variables [has_add α] /-- Making an additive monoid multiplicative then adding a zero is the same as adding a bottom element then making it multiplicative. -/ def to_mul_bot : with_zero (multiplicative α) ≃* multiplicative (with_bot α) := by exact mul_equiv.refl _ @[simp] lemma to_mul_bot_zero : to_mul_bot (0 : with_zero (multiplicative α)) = multiplicative.of_add ⊥ := rfl @[simp] lemma to_mul_bot_coe (x : multiplicative α) : to_mul_bot ↑x = multiplicative.of_add (x.to_add : with_bot α) := rfl @[simp] lemma to_mul_bot_symm_bot : to_mul_bot.symm (multiplicative.of_add (⊥ : with_bot α)) = 0 := rfl @[simp] lemma to_mul_bot_coe_of_add (x : α) : to_mul_bot.symm (multiplicative.of_add (x : with_bot α)) = multiplicative.of_add x := rfl variables [preorder α] (a b : with_zero (multiplicative α)) lemma to_mul_bot_strict_mono : strict_mono (@to_mul_bot α _) := λ x y, id @[simp] lemma to_mul_bot_le : to_mul_bot a ≤ to_mul_bot b ↔ a ≤ b := iff.rfl @[simp] lemma to_mul_bot_lt : to_mul_bot a < to_mul_bot b ↔ a < b := iff.rfl end with_zero
dc57ac3819249f691256625c9830f49a7477b2d6
80d0f8071ea62262937ab36f5887a61735adea09
/src/certigrad/program.lean
48889ef2eaf803bf70816e9e47b3f38388ff79c9
[ "Apache-2.0" ]
permissive
wudcscheme/certigrad
94805fa6a61f993c69a824429a103c9613a65a48
c9a06e93f1ec58196d6d3b8563b29868d916727f
refs/heads/master
1,679,386,475,077
1,551,651,022,000
1,551,651,022,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
9,204
lean
/- Copyright (c) 2017 Daniel Selsam. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Daniel Selsam A term language for conveniently constructing stochastic computation graphs. -/ import .tensor .graph .tactics .ops data.hash_map #print "compiling program..." namespace certigrad namespace program open list inductive unary_op : Type | neg : unary_op, exp, log, sqrt, softplus, sigmoid inductive binary_op : Type | add, sub, mul, div inductive term : Type | unary : unary_op → term → term | binary : binary_op → term → term → term | sum : term → term | scale : ℝ → term → term | gemm : term → term → term | mvn_kl : term → term → term | mvn_empirical_kl : term → term → term → term | bernoulli_neglogpdf : term → term → term | id : label → term instance : has_neg term := ⟨term.unary unary_op.neg⟩ instance : has_smul ℝ term := ⟨term.scale⟩ instance : has_add term := ⟨term.binary binary_op.add⟩ instance : has_sub term := ⟨term.binary binary_op.sub⟩ instance : has_mul term := ⟨term.binary binary_op.mul⟩ instance : has_div term := ⟨term.binary binary_op.div⟩ instance coe_id : has_coe label term := ⟨term.id⟩ def exp : term → term := term.unary unary_op.exp def log : term → term := term.unary unary_op.log def sqrt : term → term := term.unary unary_op.sqrt def softplus : term → term := term.unary unary_op.softplus def sigmoid : term → term := term.unary unary_op.sigmoid inductive rterm : Type | mvn : term → term → rterm | mvn_std : S → rterm inductive statement : Type | param : label → S → statement | input : label → S → statement | cost : label → statement | assign : label → term → statement | sample : label → rterm → statement structure state : Type := (next_id : ℕ) (shapes : hash_map label (λ x, S)) (nodes : list node) (costs : list ID) (targets inputs : list reference) def empty_state : state := ⟨0, mk_hash_map (λ (x : label), x^.to_nat), [], [], [], []⟩ def unary_to_op (shape : S) : unary_op → det.op [shape] shape | unary_op.neg := ops.neg shape | unary_op.exp := ops.exp shape | unary_op.log := ops.log shape | unary_op.sqrt := ops.sqrt shape | unary_op.softplus := ops.softplus shape | unary_op.sigmoid := ops.sigmoid shape def binary_to_op (shape : S) : binary_op → det.op [shape, shape] shape | binary_op.add := ops.add shape | binary_op.mul := ops.mul shape | binary_op.sub := ops.sub shape | binary_op.div := ops.div shape def get_id (next_id : ℕ) : option ID → ID | none := ID.nat next_id | (some ident) := ident def process_term : term → state → option ID → reference × state | (term.unary f t) st ident := match process_term t st none with | ((p₁, shape), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) := ((ID.nat $ next_id, shape), ⟨next_id+1, shapes, concat nodes ⟨(get_id next_id ident, shape), [(p₁, shape)], operator.det (unary_to_op shape f)⟩, costs, targets, inputs⟩) end | (term.binary f t₁ t₂) st ident := match process_term t₁ st none with | ((p₁, shape'), st') := match process_term t₂ st' none with | ((p₂, shape), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) := ((get_id next_id ident, shape), ⟨next_id+1, shapes, concat nodes ⟨(get_id next_id ident, shape), [(p₁, shape), (p₂, shape)], operator.det (binary_to_op shape f)⟩, costs, targets, inputs⟩) end end | (term.sum t) st ident := match process_term t st none with | ((p₁, shape), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) := ((get_id next_id ident, []), ⟨next_id+1, shapes, concat nodes ⟨(get_id next_id ident, []), [(p₁, shape)], operator.det (ops.sum shape)⟩, costs, targets, inputs⟩) end | (term.scale α t) st ident := match process_term t st none with | ((p₁, shape), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) := ((get_id next_id ident, shape), ⟨next_id+1, shapes, concat nodes ⟨(get_id next_id ident, shape), [(p₁, shape)], operator.det (ops.scale α shape)⟩, costs, targets, inputs⟩) end | (term.gemm t₁ t₂) st ident := match process_term t₁ st none with | ((p₁, shape₁), st') := match process_term t₂ st' none with | ((p₂, shape₂), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) := let m := shape₁.head, n := shape₂.head, p := shape₂.tail.head in ((get_id next_id ident, [m, p]), ⟨next_id+1, shapes, concat nodes ⟨(get_id next_id ident, [m, p]), [(p₁, [m, n]), (p₂, [n, p])], operator.det (ops.gemm _ _ _)⟩, costs, targets, inputs⟩) end end | (term.mvn_kl t₁ t₂) st ident := match process_term t₁ st none with | ((p₁, shape'), st') := match process_term t₂ st' none with | ((p₂, shape), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) := ((get_id next_id ident, []), ⟨next_id+1, shapes, concat nodes ⟨(get_id next_id ident, []), [(p₁, shape), (p₂, shape)], operator.det (ops.mvn_kl shape)⟩, costs, targets, inputs⟩) end end | (term.mvn_empirical_kl t₁ t₂ t₃) st ident := match process_term t₁ st none with | ((p₁, shape''), st') := match process_term t₂ st' none with | ((p₂, shape'), st'') := match process_term t₃ st'' none with | ((p₃, shape), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) := ((get_id next_id ident, []), ⟨next_id+1, shapes, concat nodes ⟨(get_id next_id ident, []), [(p₁, shape), (p₂, shape), (p₃, shape)], operator.det (det.op.mvn_empirical_kl shape)⟩, costs, targets, inputs⟩) end end end | (term.bernoulli_neglogpdf t₁ t₂) st ident := match process_term t₁ st none with | ((p₁, shape'), st') := match process_term t₂ st' none with | ((p₂, shape), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) := ((get_id next_id ident, []), ⟨next_id+1, shapes, concat nodes ⟨(get_id next_id ident, []), [(p₁, shape), (p₂, shape)], operator.det (ops.bernoulli_neglogpdf shape)⟩, costs, targets, inputs⟩) end end | (term.id s) ⟨next_id, shapes, nodes, costs, targets, inputs⟩ ident := match shapes^.find s with | (some shape) := ((ID.str s, shape), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) | none := (default _, empty_state) end def process_rterm : rterm → state → option ID → reference × state | (rterm.mvn t₁ t₂) st ident := match process_term t₁ st none with | ((p₁, shape'), st') := match process_term t₂ st' none with | ((p₂, shape), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) := ((get_id next_id ident, shape), ⟨next_id+1, shapes, concat nodes ⟨(get_id next_id ident, shape), [(p₁, shape), (p₂, shape)], operator.rand (rand.op.mvn shape)⟩, costs, targets, inputs⟩) end end | (rterm.mvn_std shape) ⟨next_id, shapes, nodes, costs, targets, inputs⟩ ident := ((get_id next_id ident, shape), ⟨next_id+1, shapes, nodes ++ [⟨(get_id next_id ident, shape), [], operator.rand (rand.op.mvn_std shape)⟩], costs, targets, inputs⟩) def program_to_graph_core : list statement → state → state | [] st := st | (statement.assign s t::statements) st := match process_term t st (some (ID.str s)) with | ((_, shape), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) := program_to_graph_core statements ⟨next_id, shapes^.insert s shape, nodes, costs, targets, inputs⟩ end | (statement.sample s t::statements) st := match process_rterm t st (some (ID.str s)) with | ((_, shape), ⟨next_id, shapes, nodes, costs, targets, inputs⟩) := program_to_graph_core statements ⟨next_id, shapes^.insert s shape, nodes, costs, targets, inputs⟩ end | (statement.param s shape::statements) ⟨next_id, shapes, nodes, costs, targets, inputs⟩ := program_to_graph_core statements ⟨next_id, shapes^.insert s shape, nodes, costs, concat targets (ID.str s, shape), concat inputs (ID.str s, shape)⟩ | (statement.input s shape::statements) ⟨next_id, shapes, nodes, costs, targets, inputs⟩ := program_to_graph_core statements ⟨next_id, shapes^.insert s shape, nodes, costs, targets, concat inputs (ID.str s, shape)⟩ | (statement.cost s::statements) ⟨next_id, shapes, nodes, costs, targets, inputs⟩ := program_to_graph_core statements ⟨next_id, shapes, nodes, concat costs (ID.str s), targets, inputs⟩ end program def program := list program.statement def program_to_graph : program → graph | prog := match program.program_to_graph_core prog program.empty_state with | ⟨next_id, shapes, nodes, costs, targets, inputs⟩ := ⟨nodes, costs, targets, inputs⟩ end def mk_inputs : Π (g : graph), dvec T g^.inputs^.p2 → env | g ws := env.insert_all g^.inputs ws end certigrad
25a85247a9728fa3e32df52248c06de1b3ddd308
f618aea02cb4104ad34ecf3b9713065cc0d06103
/src/topology/instances/ennreal.lean
207331eb3d1d1a894fd1d1077ea168bcb04eed3e
[ "Apache-2.0" ]
permissive
joehendrix/mathlib
84b6603f6be88a7e4d62f5b1b0cbb523bb82b9a5
c15eab34ad754f9ecd738525cb8b5a870e834ddc
refs/heads/master
1,589,606,591,630
1,555,946,393,000
1,555,946,393,000
182,813,854
0
0
null
1,555,946,309,000
1,555,946,308,000
null
UTF-8
Lean
false
false
28,883
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Johannes Hölzl Extended non-negative reals -/ import topology.instances.nnreal data.real.ennreal noncomputable theory open classical set lattice filter metric local attribute [instance] prop_decidable local attribute [instance, priority 0] nat.cast_coe local attribute [instance, priority 0] rat.cast_coe variables {α : Type*} {β : Type*} {γ : Type*} local notation `∞` := ennreal.infinity namespace ennreal variables {a b c d : ennreal} {r p q : nnreal} section topological_space open topological_space /-- Topology on `ennreal`. Note: this is different from the `emetric_space` topology. The `emetric_space` topology has `is_open {⊤}`, while this topology doesn't have singleton elements. -/ instance : topological_space ennreal := topological_space.generate_from {s | ∃a, s = {b | a < b} ∨ s = {b | b < a}} instance : orderable_topology ennreal := ⟨rfl⟩ instance : t2_space ennreal := by apply_instance instance : second_countable_topology ennreal := ⟨⟨⋃q ≥ (0:ℚ), {{a : ennreal | a < nnreal.of_real q}, {a : ennreal | ↑(nnreal.of_real q) < a}}, countable_bUnion (countable_encodable _) $ assume a ha, countable_insert (countable_singleton _), le_antisymm (generate_from_le $ λ s h, begin rcases h with ⟨a, hs | hs⟩; [ rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ a < nnreal.of_real q}, {b | ↑(nnreal.of_real q) < b}, from set.ext (assume b, by simp [hs, @ennreal.lt_iff_exists_rat_btwn a b, and_assoc]), rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ ↑(nnreal.of_real q) < a}, {b | b < ↑(nnreal.of_real q)}, from set.ext (assume b, by simp [hs, @ennreal.lt_iff_exists_rat_btwn b a, and_comm, and_assoc])]; { apply is_open_Union, intro q, apply is_open_Union, intro hq, exact generate_open.basic _ (mem_bUnion hq.1 $ by simp) } end) (generate_from_le $ by simp [or_imp_distrib, is_open_lt', is_open_gt'] {contextual := tt})⟩⟩ lemma embedding_coe : embedding (coe : nnreal → ennreal) := and.intro (assume a b, coe_eq_coe.1) $ begin refine le_antisymm _ _, { rw [orderable_topology.topology_eq_generate_intervals nnreal], refine generate_from_le (assume s ha, _), rcases ha with ⟨a, rfl | rfl⟩, exact ⟨{b : ennreal | ↑a < b}, @is_open_lt' ennreal ennreal.topological_space _ _ _, by simp⟩, exact ⟨{b : ennreal | b < ↑a}, @is_open_gt' ennreal ennreal.topological_space _ _ _, by simp⟩, }, { rw [orderable_topology.topology_eq_generate_intervals ennreal, induced_le_iff_le_coinduced], refine generate_from_le (assume s ha, _), rcases ha with ⟨a, rfl | rfl⟩, show is_open {b : nnreal | a < ↑b}, { cases a; simp [none_eq_top, some_eq_coe, is_open_lt'] }, show is_open {b : nnreal | ↑b < a}, { cases a; simp [none_eq_top, some_eq_coe, is_open_gt', is_open_const] } } end lemma is_open_ne_top : is_open {a : ennreal | a ≠ ⊤} := is_open_neg (is_closed_eq continuous_id continuous_const) lemma coe_range_mem_nhds : range (coe : nnreal → ennreal) ∈ nhds (r : ennreal) := have {a : ennreal | a ≠ ⊤} = range (coe : nnreal → ennreal), from set.ext $ assume a, by cases a; simp [none_eq_top, some_eq_coe], this ▸ mem_nhds_sets is_open_ne_top coe_ne_top lemma tendsto_coe {f : filter α} {m : α → nnreal} {a : nnreal} : tendsto (λa, (m a : ennreal)) f (nhds ↑a) ↔ tendsto m f (nhds a) := embedding_coe.tendsto_nhds_iff.symm lemma continuous_coe {α} [topological_space α] {f : α → nnreal} : continuous (λa, (f a : ennreal)) ↔ continuous f := embedding_coe.continuous_iff.symm lemma nhds_coe {r : nnreal} : nhds (r : ennreal) = (nhds r).map coe := by rw [embedding_coe.2, map_nhds_induced_eq coe_range_mem_nhds] lemma nhds_coe_coe {r p : nnreal} : nhds ((r : ennreal), (p : ennreal)) = (nhds (r, p)).map (λp:nnreal×nnreal, (p.1, p.2)) := begin rw [(embedding_prod_mk embedding_coe embedding_coe).map_nhds_eq], rw [← prod_range_range_eq], exact prod_mem_nhds_sets coe_range_mem_nhds coe_range_mem_nhds end lemma continuous_of_real : continuous ennreal.of_real := continuous.comp nnreal.continuous_of_real (continuous_coe.2 continuous_id) lemma tendsto_of_real {f : filter α} {m : α → ℝ} {a : ℝ} (h : tendsto m f (nhds a)) : tendsto (λa, ennreal.of_real (m a)) f (nhds (ennreal.of_real a)) := tendsto.comp h (continuous.tendsto continuous_of_real _) lemma tendsto_to_nnreal {a : ennreal} : a ≠ ⊤ → tendsto (ennreal.to_nnreal) (nhds a) (nhds a.to_nnreal) := begin cases a; simp [some_eq_coe, none_eq_top, nhds_coe, tendsto_map'_iff, (∘)], exact tendsto_id end lemma tendsto_nhds_top {m : α → ennreal} {f : filter α} (h : ∀n:ℕ, {a | ↑n < m a} ∈ f) : tendsto m f (nhds ⊤) := tendsto_nhds_generate_from $ assume s hs, match s, hs with | _, ⟨none, or.inl rfl⟩, hr := (lt_irrefl ⊤ hr).elim | _, ⟨some r, or.inl rfl⟩, hr := let ⟨n, hrn⟩ := exists_nat_gt r in mem_sets_of_superset (h n) $ assume a hnma, show ↑r < m a, from lt_trans (show (r : ennreal) < n, from (coe_nat n) ▸ coe_lt_coe.2 hrn) hnma | _, ⟨a, or.inr rfl⟩, hr := (not_top_lt $ show ⊤ < a, from hr).elim end lemma tendsto_coe_nnreal_nhds_top {α} {l : filter α} {f : α → nnreal} (h : tendsto f l at_top) : tendsto (λa, (f a : ennreal)) l (nhds (⊤:ennreal)) := tendsto_nhds_top $ assume n, have {a : α | ↑(n+1) ≤ f a} ∈ l := h $ mem_at_top _, mem_sets_of_superset this $ assume a (ha : ↑(n+1) ≤ f a), begin rw [← coe_nat], dsimp, exact coe_lt_coe.2 (lt_of_lt_of_le (nat.cast_lt.2 (nat.lt_succ_self _)) ha) end instance : topological_add_monoid ennreal := ⟨ continuous_iff_continuous_at.2 $ have hl : ∀a:ennreal, tendsto (λ (p : ennreal × ennreal), p.fst + p.snd) (nhds (⊤, a)) (nhds ⊤), from assume a, tendsto_nhds_top $ assume n, have set.prod {a | ↑n < a } univ ∈ nhds ((⊤:ennreal), a), from prod_mem_nhds_sets (lt_mem_nhds $ coe_nat n ▸ coe_lt_top) univ_mem_sets, show {a : ennreal × ennreal | ↑n < a.fst + a.snd} ∈ nhds (⊤, a), begin filter_upwards [this] assume ⟨a₁, a₂⟩ ⟨h₁, h₂⟩, lt_of_lt_of_le h₁ (le_add_right $ le_refl _) end, begin rintro ⟨a₁, a₂⟩, cases a₁, { simp [continuous_at, none_eq_top, hl a₂], }, cases a₂, { simp [continuous_at, none_eq_top, some_eq_coe, nhds_swap (a₁ : ennreal) ⊤, tendsto_map'_iff, (∘), hl ↑a₁] }, simp [continuous_at, some_eq_coe, nhds_coe_coe, tendsto_map'_iff, (∘)], simp only [coe_add.symm, tendsto_coe, tendsto_add'] end ⟩ protected lemma tendsto_mul' (ha : a ≠ 0 ∨ b ≠ ⊤) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λp:ennreal×ennreal, p.1 * p.2) (nhds (a, b)) (nhds (a * b)) := have ht : ∀b:ennreal, b ≠ 0 → tendsto (λp:ennreal×ennreal, p.1 * p.2) (nhds ((⊤:ennreal), b)) (nhds ⊤), begin refine assume b hb, tendsto_nhds_top $ assume n, _, rcases dense (zero_lt_iff_ne_zero.2 hb) with ⟨ε', hε', hεb'⟩, rcases ennreal.lt_iff_exists_coe.1 hεb' with ⟨ε, rfl, h⟩, rcases exists_nat_gt (↑n / ε) with ⟨m, hm⟩, have hε : ε > 0, from coe_lt_coe.1 hε', refine mem_sets_of_superset (prod_mem_nhds_sets (lt_mem_nhds $ @coe_lt_top m) (lt_mem_nhds $ h)) _, rintros ⟨a₁, a₂⟩ ⟨h₁, h₂⟩, dsimp at h₁ h₂ ⊢, calc (n:ennreal) = ↑(((n:nnreal) / ε) * ε) : begin simp [nnreal.div_def], rw [mul_assoc, ← coe_mul, nnreal.inv_mul_cancel, coe_one, ← coe_nat, mul_one], exact zero_lt_iff_ne_zero.1 hε end ... < (↑m * ε : nnreal) : coe_lt_coe.2 $ mul_lt_mul hm (le_refl _) hε (nat.cast_nonneg _) ... ≤ a₁ * a₂ : by rw [coe_mul]; exact canonically_ordered_semiring.mul_le_mul (le_of_lt h₁) (le_of_lt h₂) end, begin cases a, {simp [none_eq_top] at hb, simp [none_eq_top, ht b hb, top_mul, hb] }, cases b, { simp [none_eq_top] at ha, have ha' : a ≠ 0, from mt coe_eq_coe.2 ha, simp [*, nhds_swap (a : ennreal) ⊤, none_eq_top, some_eq_coe, top_mul, tendsto_map'_iff, (∘), mul_comm] }, simp [some_eq_coe, nhds_coe_coe, tendsto_map'_iff, (∘)], simp only [coe_mul.symm, tendsto_coe, tendsto_mul'] end protected lemma tendsto_mul {f : filter α} {ma : α → ennreal} {mb : α → ennreal} {a b : ennreal} (hma : tendsto ma f (nhds a)) (ha : a ≠ 0 ∨ b ≠ ⊤) (hmb : tendsto mb f (nhds b)) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λa, ma a * mb a) f (nhds (a * b)) := show tendsto ((λp:ennreal×ennreal, p.1 * p.2) ∘ (λa, (ma a, mb a))) f (nhds (a * b)), from tendsto.comp (tendsto_prod_mk_nhds hma hmb) (ennreal.tendsto_mul' ha hb) protected lemma tendsto_mul_right {f : filter α} {m : α → ennreal} {a b : ennreal} (hm : tendsto m f (nhds b)) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λb, a * m b) f (nhds (a * b)) := by_cases (assume : a = 0, by simp [this, tendsto_const_nhds]) (assume ha : a ≠ 0, ennreal.tendsto_mul tendsto_const_nhds (or.inl ha) hm hb) lemma Sup_add {s : set ennreal} (hs : s ≠ ∅) : Sup s + a = ⨆b∈s, b + a := have Sup ((λb, b + a) '' s) = Sup s + a, from is_lub_iff_Sup_eq.mp $ is_lub_of_is_lub_of_tendsto (assume x _ y _ h, add_le_add' h (le_refl _)) is_lub_Sup hs (tendsto_add (tendsto_id' inf_le_left) tendsto_const_nhds), by simp [Sup_image, -add_comm] at this; exact this.symm lemma supr_add {ι : Sort*} {s : ι → ennreal} [h : nonempty ι] : supr s + a = ⨆b, s b + a := let ⟨x⟩ := h in calc supr s + a = Sup (range s) + a : by simp [Sup_range] ... = (⨆b∈range s, b + a) : Sup_add $ ne_empty_iff_exists_mem.mpr ⟨s x, x, rfl⟩ ... = _ : by simp [supr_range, -mem_range] lemma add_supr {ι : Sort*} {s : ι → ennreal} [h : nonempty ι] : a + supr s = ⨆b, a + s b := by rw [add_comm, supr_add]; simp lemma supr_add_supr {ι : Sort*} {f g : ι → ennreal} (h : ∀i j, ∃k, f i + g j ≤ f k + g k) : supr f + supr g = (⨆ a, f a + g a) := begin by_cases hι : nonempty ι, { letI := hι, refine le_antisymm _ (supr_le $ λ a, add_le_add' (le_supr _ _) (le_supr _ _)), simpa [add_supr, supr_add] using λ i j:ι, show f i + g j ≤ ⨆ a, f a + g a, from let ⟨k, hk⟩ := h i j in le_supr_of_le k hk }, { have : ∀f:ι → ennreal, (⨆i, f i) = 0 := assume f, bot_unique (supr_le $ assume i, (hι ⟨i⟩).elim), rw [this, this, this, zero_add] } end lemma supr_add_supr_of_monotone {ι : Sort*} [semilattice_sup ι] {f g : ι → ennreal} (hf : monotone f) (hg : monotone g) : supr f + supr g = (⨆ a, f a + g a) := supr_add_supr $ assume i j, ⟨i ⊔ j, add_le_add' (hf $ le_sup_left) (hg $ le_sup_right)⟩ lemma finset_sum_supr_nat {α} {ι} [semilattice_sup ι] {s : finset α} {f : α → ι → ennreal} (hf : ∀a, monotone (f a)) : s.sum (λa, supr (f a)) = (⨆ n, s.sum (λa, f a n)) := begin refine finset.induction_on s _ _, { simp, exact (bot_unique $ supr_le $ assume i, le_refl ⊥).symm }, { assume a s has ih, simp only [finset.sum_insert has], rw [ih, supr_add_supr_of_monotone (hf a)], assume i j h, exact (finset.sum_le_sum' $ assume a ha, hf a h) } end lemma mul_Sup {s : set ennreal} {a : ennreal} : a * Sup s = ⨆i∈s, a * i := begin by_cases hs : ∀x∈s, x = (0:ennreal), { have h₁ : Sup s = 0 := (bot_unique $ Sup_le $ assume a ha, (hs a ha).symm ▸ le_refl 0), have h₂ : (⨆i ∈ s, a * i) = 0 := (bot_unique $ supr_le $ assume a, supr_le $ assume ha, by simp [hs a ha]), rw [h₁, h₂, mul_zero] }, { simp only [not_forall] at hs, rcases hs with ⟨x, hx, hx0⟩, have s₀ : s ≠ ∅ := not_eq_empty_iff_exists.2 ⟨x, hx⟩, have s₁ : Sup s ≠ 0 := zero_lt_iff_ne_zero.1 (lt_of_lt_of_le (zero_lt_iff_ne_zero.2 hx0) (le_Sup hx)), have : Sup ((λb, a * b) '' s) = a * Sup s := is_lub_iff_Sup_eq.mp (is_lub_of_is_lub_of_tendsto (assume x _ y _ h, canonically_ordered_semiring.mul_le_mul (le_refl _) h) is_lub_Sup s₀ (ennreal.tendsto_mul_right (tendsto_id' inf_le_left) (or.inl s₁))), rw [this.symm, Sup_image] } end lemma mul_supr {ι : Sort*} {f : ι → ennreal} {a : ennreal} : a * supr f = ⨆i, a * f i := by rw [← Sup_range, mul_Sup, supr_range] lemma supr_mul {ι : Sort*} {f : ι → ennreal} {a : ennreal} : supr f * a = ⨆i, f i * a := by rw [mul_comm, mul_supr]; congr; funext; rw [mul_comm] protected lemma tendsto_coe_sub : ∀{b:ennreal}, tendsto (λb:ennreal, ↑r - b) (nhds b) (nhds (↑r - b)) := begin refine (forall_ennreal.2 $ and.intro (assume a, _) _), { simp [@nhds_coe a, tendsto_map'_iff, (∘), tendsto_coe, coe_sub.symm], exact nnreal.tendsto_sub tendsto_const_nhds tendsto_id }, simp, exact (tendsto.congr' (mem_sets_of_superset (lt_mem_nhds $ @coe_lt_top r) $ by simp [le_of_lt] {contextual := tt})) tendsto_const_nhds end lemma sub_supr {ι : Sort*} [hι : nonempty ι] {b : ι → ennreal} (hr : a < ⊤) : a - (⨆i, b i) = (⨅i, a - b i) := let ⟨i⟩ := hι in let ⟨r, eq, _⟩ := lt_iff_exists_coe.mp hr in have Inf ((λb, ↑r - b) '' range b) = ↑r - (⨆i, b i), from is_glb_iff_Inf_eq.mp $ is_glb_of_is_lub_of_tendsto (assume x _ y _, sub_le_sub (le_refl _)) is_lub_supr (ne_empty_of_mem ⟨i, rfl⟩) (tendsto.comp (tendsto_id' inf_le_left) ennreal.tendsto_coe_sub), by rw [eq, ←this]; simp [Inf_image, infi_range, -mem_range]; exact le_refl _ end topological_space section tsum variables {f g : α → ennreal} protected lemma has_sum_coe {f : α → nnreal} {r : nnreal} : has_sum (λa, (f a : ennreal)) ↑r ↔ has_sum f r := have (λs:finset α, s.sum (coe ∘ f)) = (coe : nnreal → ennreal) ∘ (λs:finset α, s.sum f), from funext $ assume s, ennreal.coe_finset_sum.symm, by unfold has_sum; rw [this, tendsto_coe] protected lemma tsum_coe_eq {f : α → nnreal} (h : has_sum f r) : (∑a, (f a : ennreal)) = r := tsum_eq_has_sum $ ennreal.has_sum_coe.2 $ h protected lemma tsum_coe {f : α → nnreal} : summable f → (∑a, (f a : ennreal)) = ↑(tsum f) | ⟨r, hr⟩ := by rw [tsum_eq_has_sum hr, ennreal.tsum_coe_eq hr] protected lemma has_sum : has_sum f (⨆s:finset α, s.sum f) := tendsto_orderable.2 ⟨assume a' ha', let ⟨s, hs⟩ := lt_supr_iff.mp ha' in mem_at_top_sets.mpr ⟨s, assume t ht, lt_of_lt_of_le hs $ finset.sum_le_sum_of_subset ht⟩, assume a' ha', univ_mem_sets' $ assume s, have s.sum f ≤ ⨆(s : finset α), s.sum f, from le_supr (λ(s : finset α), s.sum f) s, lt_of_le_of_lt this ha'⟩ @[simp] protected lemma summable : summable f := ⟨_, ennreal.has_sum⟩ protected lemma tsum_eq_supr_sum : (∑a, f a) = (⨆s:finset α, s.sum f) := tsum_eq_has_sum ennreal.has_sum protected lemma tsum_sigma {β : α → Type*} (f : Πa, β a → ennreal) : (∑p:Σa, β a, f p.1 p.2) = (∑a b, f a b) := tsum_sigma (assume b, ennreal.summable) ennreal.summable protected lemma tsum_prod {f : α → β → ennreal} : (∑p:α×β, f p.1 p.2) = (∑a, ∑b, f a b) := let j : α × β → (Σa:α, β) := λp, sigma.mk p.1 p.2 in let i : (Σa:α, β) → α × β := λp, (p.1, p.2) in let f' : (Σa:α, β) → ennreal := λp, f p.1 p.2 in calc (∑p:α×β, f' (j p)) = (∑p:Σa:α, β, f p.1 p.2) : tsum_eq_tsum_of_iso j i (assume ⟨a, b⟩, rfl) (assume ⟨a, b⟩, rfl) ... = (∑a, ∑b, f a b) : ennreal.tsum_sigma f protected lemma tsum_comm {f : α → β → ennreal} : (∑a, ∑b, f a b) = (∑b, ∑a, f a b) := let f' : α×β → ennreal := λp, f p.1 p.2 in calc (∑a, ∑b, f a b) = (∑p:α×β, f' p) : ennreal.tsum_prod.symm ... = (∑p:β×α, f' (prod.swap p)) : (tsum_eq_tsum_of_iso prod.swap (@prod.swap α β) (assume ⟨a, b⟩, rfl) (assume ⟨a, b⟩, rfl)).symm ... = (∑b, ∑a, f' (prod.swap (b, a))) : @ennreal.tsum_prod β α (λb a, f' (prod.swap (b, a))) protected lemma tsum_add : (∑a, f a + g a) = (∑a, f a) + (∑a, g a) := tsum_add ennreal.summable ennreal.summable protected lemma tsum_le_tsum (h : ∀a, f a ≤ g a) : (∑a, f a) ≤ (∑a, g a) := tsum_le_tsum h ennreal.summable ennreal.summable protected lemma tsum_eq_supr_nat {f : ℕ → ennreal} : (∑i:ℕ, f i) = (⨆i:ℕ, (finset.range i).sum f) := calc _ = (⨆s:finset ℕ, s.sum f) : ennreal.tsum_eq_supr_sum ... = (⨆i:ℕ, (finset.range i).sum f) : le_antisymm (supr_le_supr2 $ assume s, let ⟨n, hn⟩ := finset.exists_nat_subset_range s in ⟨n, finset.sum_le_sum_of_subset hn⟩) (supr_le_supr2 $ assume i, ⟨finset.range i, le_refl _⟩) protected lemma le_tsum (a : α) : f a ≤ (∑a, f a) := calc f a = ({a} : finset α).sum f : by simp ... ≤ (⨆s:finset α, s.sum f) : le_supr (λs:finset α, s.sum f) _ ... = (∑a, f a) : by rw [ennreal.tsum_eq_supr_sum] protected lemma mul_tsum : (∑i, a * f i) = a * (∑i, f i) := if h : ∀i, f i = 0 then by simp [h] else let ⟨i, (hi : f i ≠ 0)⟩ := classical.not_forall.mp h in have sum_ne_0 : (∑i, f i) ≠ 0, from ne_of_gt $ calc 0 < f i : lt_of_le_of_ne (zero_le _) hi.symm ... ≤ (∑i, f i) : ennreal.le_tsum _, have tendsto (λs:finset α, s.sum ((*) a ∘ f)) at_top (nhds (a * (∑i, f i))), by rw [← show (*) a ∘ (λs:finset α, s.sum f) = λs, s.sum ((*) a ∘ f), from funext $ λ s, finset.mul_sum]; exact ennreal.tendsto_mul_right (has_sum_tsum ennreal.summable) (or.inl sum_ne_0), tsum_eq_has_sum this protected lemma tsum_mul : (∑i, f i * a) = (∑i, f i) * a := by simp [mul_comm, ennreal.mul_tsum] @[simp] lemma tsum_supr_eq {α : Type*} (a : α) {f : α → ennreal} : (∑b:α, ⨆ (h : a = b), f b) = f a := le_antisymm (by rw [ennreal.tsum_eq_supr_sum]; exact supr_le (assume s, calc s.sum (λb, ⨆ (h : a = b), f b) ≤ (finset.singleton a).sum (λb, ⨆ (h : a = b), f b) : finset.sum_le_sum_of_ne_zero $ assume b _ hb, suffices a = b, by simpa using this.symm, classical.by_contradiction $ assume h, by simpa [h] using hb ... = f a : by simp)) (calc f a ≤ (⨆ (h : a = a), f a) : le_supr (λh:a=a, f a) rfl ... ≤ (∑b:α, ⨆ (h : a = b), f b) : ennreal.le_tsum _) lemma has_sum_iff_tendsto_nat {f : ℕ → ennreal} (r : ennreal) : has_sum f r ↔ tendsto (λn:ℕ, (finset.range n).sum f) at_top (nhds r) := begin refine ⟨tendsto_sum_nat_of_has_sum, assume h, _⟩, rw [← supr_eq_of_tendsto _ h, ← ennreal.tsum_eq_supr_nat], { exact has_sum_tsum ennreal.summable }, { exact assume s t hst, finset.sum_le_sum_of_subset (finset.range_subset.2 hst) } end end tsum end ennreal namespace nnreal lemma exists_le_has_sum_of_le {f g : β → nnreal} {r : nnreal} (hgf : ∀b, g b ≤ f b) (hfr : has_sum f r) : ∃p≤r, has_sum g p := have (∑b, (g b : ennreal)) ≤ r, begin refine has_sum_le (assume b, _) (has_sum_tsum ennreal.summable) (ennreal.has_sum_coe.2 hfr), exact ennreal.coe_le_coe.2 (hgf _) end, let ⟨p, eq, hpr⟩ := ennreal.le_coe_iff.1 this in ⟨p, hpr, ennreal.has_sum_coe.1 $ eq ▸ has_sum_tsum ennreal.summable⟩ lemma summable_of_le {f g : β → nnreal} (hgf : ∀b, g b ≤ f b) : summable f → summable g | ⟨r, hfr⟩ := let ⟨p, _, hp⟩ := exists_le_has_sum_of_le hgf hfr in summable_spec hp lemma has_sum_iff_tendsto_nat {f : ℕ → nnreal} (r : nnreal) : has_sum f r ↔ tendsto (λn:ℕ, (finset.range n).sum f) at_top (nhds r) := begin rw [← ennreal.has_sum_coe, ennreal.has_sum_iff_tendsto_nat], simp only [ennreal.coe_finset_sum.symm], exact ennreal.tendsto_coe end end nnreal lemma summable_of_nonneg_of_le {f g : β → ℝ} (hg : ∀b, 0 ≤ g b) (hgf : ∀b, g b ≤ f b) (hf : summable f) : summable g := let f' (b : β) : nnreal := ⟨f b, le_trans (hg b) (hgf b)⟩ in let g' (b : β) : nnreal := ⟨g b, hg b⟩ in have summable f', from nnreal.summable_coe.1 hf, have summable g', from nnreal.summable_of_le (assume b, (@nnreal.coe_le (g' b) (f' b)).2 $ hgf b) this, show summable (λb, g' b : β → ℝ), from nnreal.summable_coe.2 this lemma has_sum_iff_tendsto_nat_of_nonneg {f : ℕ → ℝ} (hf : ∀i, 0 ≤ f i) (r : ℝ) : has_sum f r ↔ tendsto (λn:ℕ, (finset.range n).sum f) at_top (nhds r) := ⟨tendsto_sum_nat_of_has_sum, assume hfr, have 0 ≤ r := ge_of_tendsto at_top_ne_bot hfr $ univ_mem_sets' $ assume i, show 0 ≤ (finset.range i).sum f, from finset.zero_le_sum $ assume i _, hf i, let f' (n : ℕ) : nnreal := ⟨f n, hf n⟩, r' : nnreal := ⟨r, this⟩ in have f_eq : f = (λi:ℕ, (f' i : ℝ)) := rfl, have r_eq : r = r' := rfl, begin rw [f_eq, r_eq, nnreal.has_sum_coe, nnreal.has_sum_iff_tendsto_nat, ← nnreal.tendsto_coe], simp only [nnreal.sum_coe], exact hfr end⟩ lemma infi_real_pos_eq_infi_nnreal_pos {α : Type*} [complete_lattice α] {f : ℝ → α} : (⨅(n:ℝ) (h : n > 0), f n) = (⨅(n:nnreal) (h : n > 0), f n) := le_antisymm (le_infi $ assume n, le_infi $ assume hn, infi_le_of_le n $ infi_le _ (nnreal.coe_pos.2 hn)) (le_infi $ assume r, le_infi $ assume hr, infi_le_of_le ⟨r, le_of_lt hr⟩ $ infi_le _ hr) section variables [emetric_space β] open lattice ennreal filter emetric /-- In an emetric ball, the distance between points is everywhere finite -/ lemma edist_ne_top_of_mem_ball {a : β} {r : ennreal} (x y : ball a r) : edist x.1 y.1 ≠ ⊤ := lt_top_iff_ne_top.1 $ calc edist x y ≤ edist a x + edist a y : edist_triangle_left x.1 y.1 a ... < r + r : by rw [edist_comm a x, edist_comm a y]; exact add_lt_add x.2 y.2 ... ≤ ⊤ : le_top /-- Each ball in an extended metric space gives us a metric space, as the edist is everywhere finite. -/ def metric_space_emetric_ball (a : β) (r : ennreal) : metric_space (ball a r) := emetric_space.to_metric_space edist_ne_top_of_mem_ball local attribute [instance] metric_space_emetric_ball lemma nhds_eq_nhds_emetric_ball (a x : β) (r : ennreal) (h : x ∈ ball a r) : nhds x = map (coe : ball a r → β) (nhds ⟨x, h⟩) := (map_nhds_subtype_val_eq _ $ mem_nhds_sets emetric.is_open_ball h).symm end section variable [emetric_space α] open emetric /-- Yet another metric characterization of Cauchy sequences on integers. This one is often the most efficient. -/ lemma emetric.cauchy_seq_iff_le_tendsto_0 [inhabited β] [semilattice_sup β] {s : β → α} : cauchy_seq s ↔ (∃ (b: β → ennreal), (∀ n m N : β, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N) ∧ (tendsto b at_top (nhds 0))) := ⟨begin assume hs, rw emetric.cauchy_seq_iff at hs, /- `s` is Cauchy sequence. The sequence `b` will be constructed by taking the supremum of the distances between `s n` and `s m` for `n m ≥ N`-/ let b := λN, Sup ((λ(p : β × β), edist (s p.1) (s p.2))''{p | p.1 ≥ N ∧ p.2 ≥ N}), --Prove that it bounds the distances of points in the Cauchy sequence have C : ∀ n m N, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N, { refine λm n N hm hn, le_Sup _, use (prod.mk m n), simp only [and_true, eq_self_iff_true, set.mem_set_of_eq], exact ⟨hm, hn⟩ }, --Prove that it tends to `0`, by using the Cauchy property of `s` have D : tendsto b at_top (nhds 0), { refine tendsto_orderable.2 ⟨λa ha, absurd ha (ennreal.not_lt_zero), λε εpos, _⟩, rcases dense εpos with ⟨δ, δpos, δlt⟩, rcases hs δ δpos with ⟨N, hN⟩, refine filter.mem_at_top_sets.2 ⟨N, λn hn, _⟩, have : b n ≤ δ := Sup_le begin simp only [and_imp, set.mem_image, set.mem_set_of_eq, exists_imp_distrib, prod.exists], intros d p q hp hq hd, rw ← hd, exact le_of_lt (hN q p (le_trans hn hq) (le_trans hn hp)) end, simpa using lt_of_le_of_lt this δlt }, -- Conclude exact ⟨b, ⟨C, D⟩⟩ end, begin rintros ⟨b, ⟨b_bound, b_lim⟩⟩, /-b : ℕ → ℝ, b_bound : ∀ (n m N : ℕ), N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N, b_lim : tendsto b at_top (nhds 0)-/ refine emetric.cauchy_seq_iff.2 (λε εpos, _), have : {n | b n < ε} ∈ at_top := (tendsto_orderable.1 b_lim ).2 _ εpos, rcases filter.mem_at_top_sets.1 this with ⟨N, hN⟩, exact ⟨N, λm n hm hn, calc edist (s n) (s m) ≤ b N : b_bound n m N hn hm ... < ε : (hN _ (le_refl N)) ⟩ end⟩ lemma continuous_of_le_add_edist {f : α → ennreal} (C : ennreal) (hC : C ≠ ⊤) (h : ∀x y, f x ≤ f y + C * edist x y) : continuous f := begin refine continuous_iff_continuous_at.2 (λx, tendsto_orderable.2 ⟨_, _⟩), show ∀e, e < f x → {y : α | e < f y} ∈ nhds x, { assume e he, let ε := min (f x - e) 1, have : ε < ⊤ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]), have : 0 < ε := by simp [ε, hC, he, ennreal.zero_lt_one], have : 0 < C⁻¹ * (ε/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, ennreal.mul_eq_zero]), have I : C * (C⁻¹ * (ε/2)) < ε, { by_cases C_zero : C = 0, { simp [C_zero, ‹0 < ε›] }, { calc C * (C⁻¹ * (ε/2)) = (C * C⁻¹) * (ε/2) : by simp [mul_assoc] ... = ε/2 : by simp [ennreal.mul_inv_cancel C_zero hC] ... < ε : ennreal.half_lt_self (bot_lt_iff_ne_bot.1 ‹0 < ε›) (lt_top_iff_ne_top.1 ‹ε < ⊤›) }}, have : ball x (C⁻¹ * (ε/2)) ⊆ {y : α | e < f y}, { rintros y hy, by_cases htop : f y = ⊤, { simp [htop, lt_top_iff_ne_top, ne_top_of_lt he] }, { simp at hy, have : e + ε < f y + ε := calc e + ε ≤ e + (f x - e) : add_le_add_left' (min_le_left _ _) ... = f x : by simp [le_of_lt he] ... ≤ f y + C * edist x y : h x y ... = f y + C * edist y x : by simp [edist_comm] ... ≤ f y + C * (C⁻¹ * (ε/2)) : add_le_add_left' $ canonically_ordered_semiring.mul_le_mul (le_refl _) (le_of_lt hy) ... < f y + ε : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I, show e < f y, from (ennreal.add_lt_add_iff_right ‹ε < ⊤›).1 this }}, apply filter.mem_sets_of_superset (ball_mem_nhds _ (‹0 < C⁻¹ * (ε/2)›)) this }, show ∀e, f x < e → {y : α | f y < e} ∈ nhds x, { assume e he, let ε := min (e - f x) 1, have : ε < ⊤ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]), have : 0 < ε := by simp [ε, he, ennreal.zero_lt_one], have : 0 < C⁻¹ * (ε/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, ennreal.mul_eq_zero]), have I : C * (C⁻¹ * (ε/2)) < ε, { by_cases C_zero : C = 0, simp [C_zero, ‹0 < ε›], calc C * (C⁻¹ * (ε/2)) = (C * C⁻¹) * (ε/2) : by simp [mul_assoc] ... = ε/2 : by simp [ennreal.mul_inv_cancel C_zero hC] ... < ε : ennreal.half_lt_self (bot_lt_iff_ne_bot.1 ‹0 < ε›) (lt_top_iff_ne_top.1 ‹ε < ⊤›) }, have : ball x (C⁻¹ * (ε/2)) ⊆ {y : α | f y < e}, { rintros y hy, have htop : f x ≠ ⊤ := ne_top_of_lt he, show f y < e, from calc f y ≤ f x + C * edist y x : h y x ... ≤ f x + C * (C⁻¹ * (ε/2)) : add_le_add_left' $ canonically_ordered_semiring.mul_le_mul (le_refl _) (le_of_lt hy) ... < f x + ε : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I ... ≤ f x + (e - f x) : add_le_add_left' (min_le_left _ _) ... = e : by simp [le_of_lt he] }, apply filter.mem_sets_of_superset (ball_mem_nhds _ (‹0 < C⁻¹ * (ε/2)›)) this }, end theorem continuous_edist' : continuous (λp:α×α, edist p.1 p.2) := begin apply continuous_of_le_add_edist 2 (by simp), rintros ⟨x, y⟩ ⟨x', y'⟩, calc edist x y ≤ edist x x' + edist x' y' + edist y' y : edist_triangle4 _ _ _ _ ... = edist x' y' + (edist x x' + edist y y') : by simp [add_comm, edist_comm] ... ≤ edist x' y' + (edist (x, y) (x', y') + edist (x, y) (x', y')) : add_le_add_left' (add_le_add' (by simp [edist, le_refl]) (by simp [edist, le_refl])) ... = edist x' y' + 2 * edist (x, y) (x', y') : by rw [← mul_two, mul_comm] end theorem continuous_edist [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : continuous (λb, edist (f b) (g b)) := (hf.prod_mk hg).comp continuous_edist' theorem tendsto_edist {f g : β → α} {x : filter β} {a b : α} (hf : tendsto f x (nhds a)) (hg : tendsto g x (nhds b)) : tendsto (λx, edist (f x) (g x)) x (nhds (edist a b)) := have tendsto (λp:α×α, edist p.1 p.2) (nhds (a, b)) (nhds (edist a b)), from continuous_iff_continuous_at.mp continuous_edist' (a, b), (hf.prod_mk hg).comp (by rw [nhds_prod_eq] at this; exact this) end --section
fa523345f25c047036efa2aaf983fc32c2e09aa8
367134ba5a65885e863bdc4507601606690974c1
/src/linear_algebra/eigenspace.lean
d26cb8b24512c06b0154286ddc756424426fb118
[ "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
24,179
lean
/- Copyright (c) 2020 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Alexander Bentkamp. -/ import field_theory.algebraic_closure import linear_algebra.finsupp import linear_algebra.matrix /-! # Eigenvectors and eigenvalues This file defines eigenspaces, eigenvalues, and eigenvalues, as well as their generalized counterparts. We follow Axler's approach [axler2015] because it allows us to derive many properties without choosing a basis and without using matrices. An eigenspace of a linear map `f` for a scalar `μ` is the kernel of the map `(f - μ • id)`. The nonzero elements of an eigenspace are eigenvectors `x`. They have the property `f x = μ • x`. If there are eigenvectors for a scalar `μ`, the scalar `μ` is called an eigenvalue. There is no consensus in the literature whether `0` is an eigenvector. Our definition of `has_eigenvector` permits only nonzero vectors. For an eigenvector `x` that may also be `0`, we write `x ∈ f.eigenspace μ`. A generalized eigenspace of a linear map `f` for a natural number `k` and a scalar `μ` is the kernel of the map `(f - μ • id) ^ k`. The nonzero elements of a generalized eigenspace are generalized eigenvectors `x`. If there are generalized eigenvectors for a natural number `k` and a scalar `μ`, the scalar `μ` is called a generalized eigenvalue. ## References * [Sheldon Axler, *Linear Algebra Done Right*][axler2015] * https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors ## Tags eigenspace, eigenvector, eigenvalue, eigen -/ universes u v w namespace module namespace End open vector_space principal_ideal_ring polynomial finite_dimensional variables {K R : Type v} {V M : Type w} [comm_ring R] [add_comm_group M] [module R M] [field K] [add_comm_group V] [vector_space K V] /-- The submodule `eigenspace f μ` for a linear map `f` and a scalar `μ` consists of all vectors `x` such that `f x = μ • x`. (Def 5.36 of [axler2015])-/ def eigenspace (f : End R M) (μ : R) : submodule R M := (f - algebra_map R (End R M) μ).ker /-- A nonzero element of an eigenspace is an eigenvector. (Def 5.7 of [axler2015]) -/ def has_eigenvector (f : End R M) (μ : R) (x : M) : Prop := x ≠ 0 ∧ x ∈ eigenspace f μ /-- A scalar `μ` is an eigenvalue for a linear map `f` if there are nonzero vectors `x` such that `f x = μ • x`. (Def 5.5 of [axler2015]) -/ def has_eigenvalue (f : End R M) (a : R) : Prop := eigenspace f a ≠ ⊥ lemma mem_eigenspace_iff {f : End R M} {μ : R} {x : M} : x ∈ eigenspace f μ ↔ f x = μ • x := by rw [eigenspace, linear_map.mem_ker, linear_map.sub_apply, algebra_map_End_apply, sub_eq_zero] lemma eigenspace_div (f : End K V) (a b : K) (hb : b ≠ 0) : eigenspace f (a / b) = (b • f - algebra_map K (End K V) a).ker := calc eigenspace f (a / b) = eigenspace f (b⁻¹ * a) : by { rw [div_eq_mul_inv, mul_comm] } ... = (f - (b⁻¹ * a) • linear_map.id).ker : rfl ... = (f - b⁻¹ • a • linear_map.id).ker : by rw smul_smul ... = (f - b⁻¹ • algebra_map K (End K V) a).ker : rfl ... = (b • (f - b⁻¹ • algebra_map K (End K V) a)).ker : by rw linear_map.ker_smul _ b hb ... = (b • f - algebra_map K (End K V) a).ker : by rw [smul_sub, smul_inv_smul' hb] lemma eigenspace_aeval_polynomial_degree_1 (f : End K V) (q : polynomial K) (hq : degree q = 1) : eigenspace f (- q.coeff 0 / q.leading_coeff) = (aeval f q).ker := calc eigenspace f (- q.coeff 0 / q.leading_coeff) = (q.leading_coeff • f - algebra_map K (End K V) (- q.coeff 0)).ker : by { rw eigenspace_div, intro h, rw leading_coeff_eq_zero_iff_deg_eq_bot.1 h at hq, cases hq } ... = (aeval f (C q.leading_coeff * X + C (q.coeff 0))).ker : by { rw [C_mul', aeval_def], simpa [algebra_map, algebra.to_ring_hom], } ... = (aeval f q).ker : by { congr, apply (eq_X_add_C_of_degree_eq_one hq).symm } lemma ker_aeval_ring_hom'_unit_polynomial (f : End K V) (c : units (polynomial K)) : (aeval f (c : polynomial K)).ker = ⊥ := begin rw polynomial.eq_C_of_degree_eq_zero (degree_coe_units c), simp only [aeval_def, eval₂_C], apply ker_algebra_map_End, apply coeff_coe_units_zero_ne_zero c end theorem aeval_apply_of_has_eigenvector {f : End K V} {p : polynomial K} {μ : K} {x : V} (h : f.has_eigenvector μ x) : aeval f p x = (p.eval μ) • x := begin apply p.induction_on, { intro a, simp [module.algebra_map_End_apply] }, { intros p q hp hq, simp [hp, hq, add_smul] }, { intros n a hna, rw [mul_comm, pow_succ, mul_assoc, alg_hom.map_mul, linear_map.mul_apply, mul_comm, hna], simp [algebra_map_End_apply, mem_eigenspace_iff.1 h.2, smul_smul, mul_comm] } end section minpoly theorem is_root_of_has_eigenvalue {f : End K V} {μ : K} (h : f.has_eigenvalue μ) : (minpoly K f).is_root μ := begin rcases (submodule.ne_bot_iff _).1 h with ⟨w, ⟨H, ne0⟩⟩, refine or.resolve_right (smul_eq_zero.1 _) ne0, simp [← aeval_apply_of_has_eigenvector ⟨ne0, H⟩, minpoly.aeval K f], end variables [finite_dimensional K V] (f : End K V) protected theorem is_integral : is_integral K f := is_integral_of_noetherian (by apply_instance) f variables {f} {μ : K} theorem has_eigenvalue_of_is_root (h : (minpoly K f).is_root μ) : f.has_eigenvalue μ := begin cases dvd_iff_is_root.2 h with p hp, rw [has_eigenvalue, eigenspace], intro con, cases (linear_map.is_unit_iff _).2 con with u hu, have p_ne_0 : p ≠ 0, { intro con, apply minpoly.ne_zero f.is_integral, rw [hp, con, mul_zero] }, have h_deg := minpoly.degree_le_of_ne_zero K f p_ne_0 _, { rw [hp, degree_mul, degree_X_sub_C, polynomial.degree_eq_nat_degree p_ne_0] at h_deg, norm_cast at h_deg, linarith, }, { have h_aeval := minpoly.aeval K f, revert h_aeval, simp [hp, ← hu] }, end theorem has_eigenvalue_iff_is_root : f.has_eigenvalue μ ↔ (minpoly K f).is_root μ := ⟨is_root_of_has_eigenvalue, has_eigenvalue_of_is_root⟩ end minpoly /-- Every linear operator on a vector space over an algebraically closed field has an eigenvalue. (Lemma 5.21 of [axler2015]) -/ lemma exists_eigenvalue [is_alg_closed K] [finite_dimensional K V] [nontrivial V] (f : End K V) : ∃ (c : K), f.has_eigenvalue c := begin classical, -- Choose a nonzero vector `v`. obtain ⟨v, hv⟩ : ∃ v : V, v ≠ 0 := exists_ne (0 : V), -- The infinitely many vectors v, f v, f (f v), ... cannot be linearly independent -- because the vector space is finite dimensional. have h_lin_dep : ¬ linear_independent K (λ n : ℕ, (f ^ n) v), { apply not_linear_independent_of_infinite, }, -- Therefore, there must be a nonzero polynomial `p` such that `p(f) v = 0`. obtain ⟨p, ⟨h_mon, h_eval_p⟩⟩ := f.is_integral, have h_eval_p_not_unit : aeval f p ∉ is_unit.submonoid (End K V), { rw [is_unit.mem_submonoid_iff, linear_map.is_unit_iff, linear_map.ker_eq_bot'], intro h, apply hv (h v _), rw [aeval_def, h_eval_p, linear_map.zero_apply] }, -- Hence, there must be a factor `q` of `p` such that `q(f)` is not invertible. obtain ⟨q, hq_factor, hq_nonunit⟩ : ∃ q, q ∈ factors p ∧ ¬ is_unit (aeval f q), { simp only [←not_imp, (is_unit.mem_submonoid_iff _).symm], apply not_forall.1 (λ h, h_eval_p_not_unit (ring_hom_mem_submonoid_of_factors_subset_of_units_subset (eval₂_ring_hom' (algebra_map _ _) f _) (is_unit.submonoid (End K V)) p h_mon.ne_zero h _)), simp only [is_unit.mem_submonoid_iff, linear_map.is_unit_iff], apply ker_aeval_ring_hom'_unit_polynomial }, -- Since the field is algebraically closed, `q` has degree 1. have h_deg_q : q.degree = 1 := is_alg_closed.degree_eq_one_of_irreducible _ (ne_zero_of_mem_factors h_mon.ne_zero hq_factor) ((factors_spec p h_mon.ne_zero).1 q hq_factor), -- Then the kernel of `q(f)` is an eigenspace. have h_eigenspace: eigenspace f (-q.coeff 0 / q.leading_coeff) = (aeval f q).ker, from eigenspace_aeval_polynomial_degree_1 f q h_deg_q, -- Since `q(f)` is not invertible, the kernel is not `⊥`, and thus there exists an eigenvalue. show ∃ (c : K), f.has_eigenvalue c, { use -q.coeff 0 / q.leading_coeff, rw [has_eigenvalue, h_eigenspace], intro h_eval_ker, exact hq_nonunit ((linear_map.is_unit_iff (aeval f q)).2 h_eval_ker) } end /-- Eigenvectors corresponding to distinct eigenvalues of a linear operator are linearly independent. (Lemma 5.10 of [axler2015]) We use the eigenvalues as indexing set to ensure that there is only one eigenvector for each eigenvalue in the image of `xs`. -/ lemma eigenvectors_linear_independent (f : End K V) (μs : set K) (xs : μs → V) (h_eigenvec : ∀ μ : μs, f.has_eigenvector μ (xs μ)) : linear_independent K xs := begin classical, -- We need to show that if a linear combination `l` of the eigenvectors `xs` is `0`, then all -- its coefficients are zero. suffices : ∀ l, finsupp.total μs V K xs l = 0 → l = 0, { rw linear_independent_iff, apply this }, intros l hl, -- We apply induction on the finite set of eigenvalues whose eigenvectors have nonzero -- coefficients, i.e. on the support of `l`. induction h_l_support : l.support using finset.induction with μ₀ l_support' hμ₀ ih generalizing l, -- If the support is empty, all coefficients are zero and we are done. { exact finsupp.support_eq_empty.1 h_l_support }, -- Now assume that the support of `l` contains at least one eigenvalue `μ₀`. We define a new -- linear combination `l'` to apply the induction hypothesis on later. The linear combination `l'` -- is derived from `l` by multiplying the coefficient of the eigenvector with eigenvalue `μ` -- by `μ - μ₀`. -- To get started, we define `l'` as a function `l'_f : μs → K` with potentially infinite support. { let l'_f : μs → K := (λ μ : μs, (↑μ - ↑μ₀) * l μ), -- The support of `l'_f` is the support of `l` without `μ₀`. have h_l_support' : ∀ (μ : μs), μ ∈ l_support' ↔ l'_f μ ≠ 0 , { intro μ, suffices : μ ∈ l_support' → μ ≠ μ₀, { simp [l'_f, ← finsupp.not_mem_support_iff, h_l_support, sub_eq_zero, ←subtype.ext_iff], tauto }, rintro hμ rfl, contradiction }, -- Now we can define `l'_f` as an actual linear combination `l'` because we know that the -- support is finite. let l' : μs →₀ K := { to_fun := l'_f, support := l_support', mem_support_to_fun := h_l_support' }, -- The linear combination `l'` over `xs` adds up to `0`. have total_l' : finsupp.total μs V K xs l' = 0, { let g := f - algebra_map K (End K V) μ₀, have h_gμ₀: g (l μ₀ • xs μ₀) = 0, by rw [linear_map.map_smul, linear_map.sub_apply, mem_eigenspace_iff.1 (h_eigenvec _).2, algebra_map_End_apply, sub_self, smul_zero], have h_useless_filter : finset.filter (λ (a : μs), l'_f a ≠ 0) l_support' = l_support', { rw finset.filter_congr _, { apply finset.filter_true }, { apply_instance }, exact λ μ hμ, (iff_true _).mpr ((h_l_support' μ).1 hμ) }, have bodies_eq : ∀ (μ : μs), l'_f μ • xs μ = g (l μ • xs μ), { intro μ, dsimp only [g, l'_f], rw [linear_map.map_smul, linear_map.sub_apply, mem_eigenspace_iff.1 (h_eigenvec _).2, algebra_map_End_apply, ←sub_smul, smul_smul, mul_comm] }, rw [←linear_map.map_zero g, ←hl, finsupp.total_apply, finsupp.total_apply, finsupp.sum, finsupp.sum, linear_map.map_sum, h_l_support, finset.sum_insert hμ₀, h_gμ₀, zero_add], refine finset.sum_congr rfl (λ μ _, _), apply bodies_eq }, -- Therefore, by the induction hypothesis, all coefficients in `l'` are zero. have l'_eq_0 : l' = 0 := ih l' total_l' rfl, -- By the defintion of `l'`, this means that `(μ - μ₀) * l μ = 0` for all `μ`. have h_mul_eq_0 : ∀ μ : μs, (↑μ - ↑μ₀) * l μ = 0, { intro μ, calc (↑μ - ↑μ₀) * l μ = l' μ : rfl ... = 0 : by { rw [l'_eq_0], refl } }, -- Thus, the coefficients in `l` for all `μ ≠ μ₀` are `0`. have h_lμ_eq_0 : ∀ μ : μs, μ ≠ μ₀ → l μ = 0, { intros μ hμ, apply or_iff_not_imp_left.1 (mul_eq_zero.1 (h_mul_eq_0 μ)), rwa [sub_eq_zero, ←subtype.ext_iff] }, -- So if we sum over all these coefficients, we obtain `0`. have h_sum_l_support'_eq_0 : finset.sum l_support' (λ (μ : ↥μs), l μ • xs μ) = 0, { rw ←finset.sum_const_zero, apply finset.sum_congr rfl, intros μ hμ, rw h_lμ_eq_0, apply zero_smul, intro h, rw h at hμ, contradiction }, -- The only potentially nonzero coefficient in `l` is the one corresponding to `μ₀`. But since -- the overall sum is `0` by assumption, this coefficient must also be `0`. have : l μ₀ = 0, { rw [finsupp.total_apply, finsupp.sum, h_l_support, finset.sum_insert hμ₀, h_sum_l_support'_eq_0, add_zero] at hl, by_contra h, exact (h_eigenvec μ₀).1 ((smul_eq_zero.1 hl).resolve_left h) }, -- Thus, all coefficients in `l` are `0`. show l = 0, { ext μ, by_cases h_cases : μ = μ₀, { rw h_cases, assumption }, exact h_lμ_eq_0 μ h_cases } } end /-- The generalized eigenspace for a linear map `f`, a scalar `μ`, and an exponent `k ∈ ℕ` is the kernel of `(f - μ • id) ^ k`. (Def 8.10 of [axler2015])-/ def generalized_eigenspace (f : End R M) (μ : R) (k : ℕ) : submodule R M := ((f - algebra_map R (End R M) μ) ^ k).ker /-- A nonzero element of a generalized eigenspace is a generalized eigenvector. (Def 8.9 of [axler2015])-/ def has_generalized_eigenvector (f : End R M) (μ : R) (k : ℕ) (x : M) : Prop := x ≠ 0 ∧ x ∈ generalized_eigenspace f μ k /-- A scalar `μ` is a generalized eigenvalue for a linear map `f` and an exponent `k ∈ ℕ` if there are generalized eigenvectors for `f`, `k`, and `μ`. -/ def has_generalized_eigenvalue (f : End R M) (μ : R) (k : ℕ) : Prop := generalized_eigenspace f μ k ≠ ⊥ /-- The generalized eigenrange for a linear map `f`, a scalar `μ`, and an exponent `k ∈ ℕ` is the range of `(f - μ • id) ^ k`. -/ def generalized_eigenrange (f : End R M) (μ : R) (k : ℕ) : submodule R M := ((f - algebra_map R (End R M) μ) ^ k).range /-- The exponent of a generalized eigenvalue is never 0. -/ lemma exp_ne_zero_of_has_generalized_eigenvalue {f : End R M} {μ : R} {k : ℕ} (h : f.has_generalized_eigenvalue μ k) : k ≠ 0 := begin rintro rfl, exact h linear_map.ker_id end /-- A generalized eigenspace for some exponent `k` is contained in the generalized eigenspace for exponents larger than `k`. -/ lemma generalized_eigenspace_mono {f : End K V} {μ : K} {k : ℕ} {m : ℕ} (hm : k ≤ m) : f.generalized_eigenspace μ k ≤ f.generalized_eigenspace μ m := begin simp only [generalized_eigenspace, ←pow_sub_mul_pow _ hm], exact linear_map.ker_le_ker_comp ((f - algebra_map K (End K V) μ) ^ k) ((f - algebra_map K (End K V) μ) ^ (m - k)) end /-- A generalized eigenvalue for some exponent `k` is also a generalized eigenvalue for exponents larger than `k`. -/ lemma has_generalized_eigenvalue_of_has_generalized_eigenvalue_of_le {f : End K V} {μ : K} {k : ℕ} {m : ℕ} (hm : k ≤ m) (hk : f.has_generalized_eigenvalue μ k) : f.has_generalized_eigenvalue μ m := begin unfold has_generalized_eigenvalue at *, contrapose! hk, rw [←le_bot_iff, ←hk], exact generalized_eigenspace_mono hm end /-- The eigenspace is a subspace of the generalized eigenspace. -/ lemma eigenspace_le_generalized_eigenspace {f : End K V} {μ : K} {k : ℕ} (hk : 0 < k) : f.eigenspace μ ≤ f.generalized_eigenspace μ k := generalized_eigenspace_mono (nat.succ_le_of_lt hk) /-- All eigenvalues are generalized eigenvalues. -/ lemma has_generalized_eigenvalue_of_has_eigenvalue {f : End K V} {μ : K} {k : ℕ} (hk : 0 < k) (hμ : f.has_eigenvalue μ) : f.has_generalized_eigenvalue μ k := begin apply has_generalized_eigenvalue_of_has_generalized_eigenvalue_of_le hk, rwa [has_generalized_eigenvalue, generalized_eigenspace, pow_one] end /-- Every generalized eigenvector is a generalized eigenvector for exponent `findim K V`. (Lemma 8.11 of [axler2015]) -/ lemma generalized_eigenspace_le_generalized_eigenspace_findim [finite_dimensional K V] (f : End K V) (μ : K) (k : ℕ) : f.generalized_eigenspace μ k ≤ f.generalized_eigenspace μ (findim K V) := ker_pow_le_ker_pow_findim _ _ /-- Generalized eigenspaces for exponents at least `findim K V` are equal to each other. -/ lemma generalized_eigenspace_eq_generalized_eigenspace_findim_of_le [finite_dimensional K V] (f : End K V) (μ : K) {k : ℕ} (hk : findim K V ≤ k) : f.generalized_eigenspace μ k = f.generalized_eigenspace μ (findim K V) := ker_pow_eq_ker_pow_findim_of_le hk /-- If `f` maps a subspace `p` into itself, then the generalized eigenspace of the restriction of `f` to `p` is the part of the generalized eigenspace of `f` that lies in `p`. -/ lemma generalized_eigenspace_restrict (f : End K V) (p : submodule K V) (k : ℕ) (μ : K) (hfp : ∀ (x : V), x ∈ p → f x ∈ p) : generalized_eigenspace (linear_map.restrict f hfp) μ k = submodule.comap p.subtype (f.generalized_eigenspace μ k) := begin rw [generalized_eigenspace, generalized_eigenspace, ←linear_map.ker_comp], induction k with k ih, { rw [pow_zero,pow_zero], convert linear_map.ker_id, apply submodule.ker_subtype }, { erw [pow_succ', pow_succ', linear_map.ker_comp, ih, ←linear_map.ker_comp, linear_map.comp_assoc], } end /-- Generalized eigenrange and generalized eigenspace for exponent `findim K V` are disjoint. -/ lemma generalized_eigenvec_disjoint_range_ker [finite_dimensional K V] (f : End K V) (μ : K) : disjoint (f.generalized_eigenrange μ (findim K V)) (f.generalized_eigenspace μ (findim K V)) := begin have h := calc submodule.comap ((f - algebra_map _ _ μ) ^ findim K V) (f.generalized_eigenspace μ (findim K V)) = ((f - algebra_map _ _ μ) ^ findim K V * (f - algebra_map K (End K V) μ) ^ findim K V).ker : by { rw [generalized_eigenspace, ←linear_map.ker_comp], refl } ... = f.generalized_eigenspace μ (findim K V + findim K V) : by { rw ←pow_add, refl } ... = f.generalized_eigenspace μ (findim K V) : by { rw generalized_eigenspace_eq_generalized_eigenspace_findim_of_le, linarith }, rw [disjoint, generalized_eigenrange, linear_map.range, submodule.map_inf_eq_map_inf_comap, top_inf_eq, h], apply submodule.map_comap_le end /-- The generalized eigenspace of an eigenvalue has positive dimension for positive exponents. -/ lemma pos_findim_generalized_eigenspace_of_has_eigenvalue [finite_dimensional K V] {f : End K V} {k : ℕ} {μ : K} (hx : f.has_eigenvalue μ) (hk : 0 < k): 0 < findim K (f.generalized_eigenspace μ k) := calc 0 = findim K (⊥ : submodule K V) : by rw findim_bot ... < findim K (f.eigenspace μ) : submodule.findim_lt_findim_of_lt (bot_lt_iff_ne_bot.2 hx) ... ≤ findim K (f.generalized_eigenspace μ k) : submodule.findim_mono (generalized_eigenspace_mono (nat.succ_le_of_lt hk)) /-- A linear map maps a generalized eigenrange into itself. -/ lemma map_generalized_eigenrange_le {f : End K V} {μ : K} {n : ℕ} : submodule.map f (f.generalized_eigenrange μ n) ≤ f.generalized_eigenrange μ n := calc submodule.map f (f.generalized_eigenrange μ n) = (f * ((f - algebra_map _ _ μ) ^ n)).range : (linear_map.range_comp _ _).symm ... = (((f - algebra_map _ _ μ) ^ n) * f).range : by rw algebra.mul_sub_algebra_map_pow_commutes ... = submodule.map ((f - algebra_map _ _ μ) ^ n) f.range : linear_map.range_comp _ _ ... ≤ f.generalized_eigenrange μ n : linear_map.map_le_range /-- The generalized eigenvectors span the entire vector space (Lemma 8.21 of [axler2015]). -/ lemma supr_generalized_eigenspace_eq_top [is_alg_closed K] [finite_dimensional K V] (f : End K V) : (⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k) = ⊤ := begin tactic.unfreeze_local_instances, -- We prove the claim by strong induction on the dimension of the vector space. induction h_dim : findim K V using nat.strong_induction_on with n ih generalizing V, cases n, -- If the vector space is 0-dimensional, the result is trivial. { rw ←top_le_iff, simp only [findim_eq_zero.1 (eq.trans findim_top h_dim), bot_le] }, -- Otherwise the vector space is nontrivial. { haveI : nontrivial V := findim_pos_iff.1 (by { rw h_dim, apply nat.zero_lt_succ }), -- Hence, `f` has an eigenvalue `μ₀`. obtain ⟨μ₀, hμ₀⟩ : ∃ μ₀, f.has_eigenvalue μ₀ := exists_eigenvalue f, -- We define `ES` to be the generalized eigenspace let ES := f.generalized_eigenspace μ₀ (findim K V), -- and `ER` to be the generalized eigenrange. let ER := f.generalized_eigenrange μ₀ (findim K V), -- `f` maps `ER` into itself. have h_f_ER : ∀ (x : V), x ∈ ER → f x ∈ ER, from λ x hx, map_generalized_eigenrange_le (submodule.mem_map_of_mem hx), -- Therefore, we can define the restriction `f'` of `f` to `ER`. let f' : End K ER := f.restrict h_f_ER, -- The dimension of `ES` is positive have h_dim_ES_pos : 0 < findim K ES, { dsimp only [ES], rw h_dim, apply pos_findim_generalized_eigenspace_of_has_eigenvalue hμ₀ (nat.zero_lt_succ n) }, -- and the dimensions of `ES` and `ER` add up to `findim K V`. have h_dim_add : findim K ER + findim K ES = findim K V, { apply linear_map.findim_range_add_findim_ker }, -- Therefore the dimension `ER` mus be smaller than `findim K V`. have h_dim_ER : findim K ER < n.succ, by linarith, -- This allows us to apply the induction hypothesis on `ER`: have ih_ER : (⨆ (μ : K) (k : ℕ), f'.generalized_eigenspace μ k) = ⊤, from ih (findim K ER) h_dim_ER f' rfl, -- The induction hypothesis gives us a statement about subspaces of `ER`. We can transfer this -- to a statement about subspaces of `V` via `submodule.subtype`: have ih_ER' : (⨆ (μ : K) (k : ℕ), (f'.generalized_eigenspace μ k).map ER.subtype) = ER, by simp only [(submodule.map_supr _ _).symm, ih_ER, submodule.map_subtype_top ER], -- Moreover, every generalized eigenspace of `f'` is contained in the corresponding generalized -- eigenspace of `f`. have hff' : ∀ μ k, (f'.generalized_eigenspace μ k).map ER.subtype ≤ f.generalized_eigenspace μ k, { intros, rw generalized_eigenspace_restrict, apply submodule.map_comap_le }, -- It follows that `ER` is contained in the span of all generalized eigenvectors. have hER : ER ≤ ⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k, { rw ← ih_ER', apply supr_le_supr _, exact λ μ, supr_le_supr (λ k, hff' μ k), }, -- `ES` is contained in this span by definition. have hES : ES ≤ ⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k, from le_trans (le_supr (λ k, f.generalized_eigenspace μ₀ k) (findim K V)) (le_supr (λ (μ : K), ⨆ (k : ℕ), f.generalized_eigenspace μ k) μ₀), -- Moreover, we know that `ER` and `ES` are disjoint. have h_disjoint : disjoint ER ES, from generalized_eigenvec_disjoint_range_ker f μ₀, -- Since the dimensions of `ER` and `ES` add up to the dimension of `V`, it follows that the -- span of all generalized eigenvectors is all of `V`. show (⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k) = ⊤, { rw [←top_le_iff, ←submodule.eq_top_of_disjoint ER ES h_dim_add h_disjoint], apply sup_le hER hES } } end end End end module variables {K V : Type*} [field K] [add_comm_group V] [vector_space K V] [finite_dimensional K V] protected lemma linear_map.is_integral (f : V →ₗ[K] V) : is_integral K f := module.End.is_integral f
ace71b57fd7a430e167440d044cb6771372fb1a8
fc086f79b20cf002d6f34b023749998408e94fbf
/src/tidy/transport.lean
a9a5f729a24aac329dc0f86a923d407e504ef0b0
[]
no_license
semorrison/lean-tidy
f039460136b898fb282f75efedd92f2d5c5d90f8
6c1d46de6cff05e1c2c4c9692af812bca3e13b6c
refs/heads/master
1,624,461,332,392
1,559,655,744,000
1,559,655,744,000
96,569,994
9
4
null
1,538,287,895,000
1,499,455,306,000
Lean
UTF-8
Lean
false
false
3,149
lean
-- Copyright (c) 2017 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Scott Morrison definition {u v} transport {A : Type u} { P : A → Type v} {x y : A} (u : P x) (p : x = y) : P y := by induction p; exact u @[simp] lemma {u v} congr_arg_refl {α : Sort u} {β : Sort v} (f : α → β) (a : α) : congr_arg f (eq.refl a) = eq.refl (f a) := begin refl, end @[simp] lemma {u v} congr_fun_refl {α : Sort u} {β : Sort v} (f : α → β) (a : α) : congr_fun (eq.refl f) a = eq.refl (f a) := begin refl, end @[simp] lemma {u v} congr_refl_arg {α : Sort u} {f₁ f₂ : α → Prop} (h₁ : f₁ = f₂) (a : α) : congr h₁ (eq.refl a) = congr_fun h₁ a := begin refl, end @[simp] lemma {u v} congr_refl_fun {α : Sort u} {f : α → Prop} (a b : α) (h : a = b) : congr (eq.refl f) h = congr_arg f h := begin refl, end @[simp] lemma symm_propext {a b : Prop} (p : a ↔ b) : eq.symm (propext p) = propext (p.symm) := by refl @[simp] lemma {u} symm_refl {α : Sort u} (a : α) : eq.symm (eq.refl a) = eq.refl a := by refl @[simp] lemma {u v} symm_congr {α : Sort u} {β : Sort v} {f g : α → β} (h : f = g) {a b : α} (h' : a = b) : eq.symm (congr h h') = congr (eq.symm h) (eq.symm h') := begin refl, end @[simp] lemma {u v} symm_congr_fun {α : Sort u} {β : α → Sort v} {f g : Π x, β x} (h : f = g) (a : α) : eq.symm (congr_fun h a) = congr_fun (eq.symm h) a := begin refl, end @[simp] lemma {u v} symm_congr_arg {α : Sort u} {β : Sort v} {f : α → β} (a b : α) (h : a = b) : eq.symm (congr_arg f h) = congr_arg f (eq.symm h) := begin refl, end @[simp] lemma {u} symm_trans (a b c : Prop) (p : a = b) (q : b = c) : @eq.symm Prop a c (eq.trans p q) = @eq.trans Prop c b a (eq.symm q) (eq.symm p) := by refl @[simp] lemma {u v w} eq.rec.congr_arg {α : Sort u} {β : Sort v} (f : α → β) {x y : α} {C : β → Sort w} (p : C (f x)) (w : x = y): @eq.rec β (f x) C p _ (congr_arg f w) = @eq.rec α x (λ z, C (f z)) p _ w := begin induction w, refl, end @[simp] lemma {u v} parallel_transport_for_trivial_bundles {α : Sort u} {a b : α} {β : Sort v} (p : a = b) (x : β) : @eq.rec α a (λ a, β) x b p = x := begin induction p, refl, end @[simp] lemma {u l} eq.rec.trans {a b c : Prop} {C : Prop → Sort l} (z : C a) (p : a = b) (q : b = c) : @eq.rec _ a C z c (eq.trans p q) = @eq.rec _ b C (@eq.rec _ a C z b p) c q := begin induction p, induction q, refl, end @[simp] lemma {u} eq.rec.refl {α : Sort u} (a : α) (p : true = (a = a)): @eq.rec Prop true (λ (_x : Prop), _x) trivial (@eq α a a) p = eq.refl a := by refl @[simp] lemma eq.mpr.trans {α β γ: Prop} (p : α = β) (q : β = γ) (g : γ) : eq.mpr (eq.trans p q) g = eq.mpr p (eq.mpr q g) := begin induction p, induction q, refl, end @[simp] lemma {u} eq.mpr.propext {α : Sort u} (a : α) : eq.mpr (propext (eq_self_iff_true a)) trivial = eq.refl a := begin refl, end @[simp] lemma {u} eq.mpr.refl {α : Sort u} (a b : α) (p : a = b) : (eq.mpr (congr_fun (congr_arg eq p) b) (eq.refl b)) = p := begin induction p, refl, end
dfd8335544d01e11699601923a8b2c10b152cc70
302c785c90d40ad3d6be43d33bc6a558354cc2cf
/src/geometry/manifold/bump_function.lean
a181524df70cb1cb6a944d978b06d33a1aebc45a
[ "Apache-2.0" ]
permissive
ilitzroth/mathlib
ea647e67f1fdfd19a0f7bdc5504e8acec6180011
5254ef14e3465f6504306132fe3ba9cec9ffff16
refs/heads/master
1,680,086,661,182
1,617,715,647,000
1,617,715,647,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
28,052
lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import analysis.calculus.specific_functions import geometry.manifold.diffeomorph import geometry.manifold.instances.real /-! # Smooth bump functions on a smooth manifold In this file we define `smooth_bump_function I c` to be a bundled smooth "bump" function centered at `c`. It is a structure that consists of two real numbers `0 < r < R` with small enough `R`. We define a coercion to function for this type, and for `f : smooth_bump_function I c`, the function `⇑f` written in the extended chart at `f.c` has the following properties: * `f x = 1` in the closed euclidean ball of radius `f.r` centered at `f.c`; * `f x = 0` outside of the euclidean ball of radius `f.R` centered at `f.c`; * `0 ≤ f x ≤ 1` for all `x`. The actual statements involve (pre)images under `ext_chart_at I f.c` and are given as lemmas in the `smooth_bump_function` namespace. We also define `smooth_bump_covering` of a set `s : set M` to be a collection of `smooth_bump_function`s such that their supports is a locally finite family of sets, and for each point `x ∈ s` there exists a bump function `f i` in the collection such that `f i =ᶠ[𝓝 x] 1`. This structure is the main building block in the construction of a smooth partition of unity (see TODO), and can be used instead of a partition of unity in some proofs. We say that `f : smooth_bump_covering I s` is *subordinate* to a map `U : M → set M` if for each index `i`, we have `closure (support (f i)) ⊆ U (f i).c`. This notion is a bit more general than being subordinate to an open covering of `M`, because we make no assumption about the way `U x` depends on `x`. We prove that on a smooth finitely dimensional real manifold with `σ`-compact Hausdorff topology, for any `U : M → set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `smooth_bump_covering I s` subordinate to `U`. Then we use this fact to prove a version of the Whitney embedding theorem: any compact real manifold can be embedded into `ℝ^n` for large enough `n`. ## TODO * Prove the weak Whitney embedding theorem: any `σ`-compact smooth `m`-dimensional manifold can be embedded into `ℝ^(2m+1)`. This requires a version of Sard's theorem: for a locally Lipschitz continuous map `f : ℝ^m → ℝ^n`, `m < n`, the range has Hausdorff dimension at most `m`, hence it has measure zero. * Construct a smooth partition of unity. While we can do it now, the formulas will be much nicer if we wait for `finprod` and `finsum` coming in #6355. * Deduce some corollaries from existence of a smooth partition of unity. - Prove that for any disjoint closed sets `s`, `t` there exists a smooth function `f` suth that `f` equals zero on `s` and `f` equals one on `t`. - Build a framework for to transfer local definitions to global using partition of unity and use it to define, e.g., the integral of a differential form over a manifold. ## Tags manifold, smooth bump function, partition of unity, Whitney theorem -/ universes uE uF uH uM variables {E : Type uE} [normed_group E] [normed_space ℝ E] [finite_dimensional ℝ E] {H : Type uH} [topological_space H] (I : model_with_corners ℝ E H) {M : Type uM} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] open function filter finite_dimensional set open_locale topological_space manifold classical filter big_operators noncomputable theory /-! ### Smooth bump function In this section we define a structure for a bundled smooth bump function and prove its properties. -/ /-- Given a smooth manifold modelled on a finite dimensional space `E`, `f : smooth_bump_function I M` is a smooth function on `M` such that in the extended chart `e` at `f.c`: * `f x = 1` in the closed euclidean ball of radius `f.r` centered at `f.c`; * `f x = 0` outside of the euclidean ball of radius `f.R` centered at `f.c`; * `0 ≤ f x ≤ 1` for all `x`. The structure contains data required to construct a function with these properties. The function is available as `⇑f` or `f x`. Formal statements of the properties listed above involve some (pre)images under `ext_chart_at I f.c` and are given as lemmas in the `msmooth_bump_function` namespace. -/ structure smooth_bump_function (c : M) extends times_cont_diff_bump (ext_chart_at I c c) := (closed_ball_subset : (euclidean.closed_ball (ext_chart_at I c c) R) ∩ range I ⊆ (ext_chart_at I c).target) variable {M} namespace smooth_bump_function open euclidean (renaming dist -> eudist) variables {c : M} (f : smooth_bump_function I c) {x : M} {I} /-- The function defined by `f : smooth_bump_function c`. Use automatic coercion to function instead. -/ def to_fun : M → ℝ := indicator (chart_at H c).source (f.to_times_cont_diff_bump ∘ ext_chart_at I c) instance : has_coe_to_fun (smooth_bump_function I c) := ⟨_, to_fun⟩ lemma coe_def : ⇑f = indicator (chart_at H c).source (f.to_times_cont_diff_bump ∘ ext_chart_at I c) := rfl lemma R_pos : 0 < f.R := f.to_times_cont_diff_bump.R_pos lemma ball_subset : ball (ext_chart_at I c c) f.R ∩ range I ⊆ (ext_chart_at I c).target := subset.trans (inter_subset_inter_left _ ball_subset_closed_ball) f.closed_ball_subset lemma eq_on_source : eq_on f (f.to_times_cont_diff_bump ∘ ext_chart_at I c) (chart_at H c).source := eq_on_indicator lemma eventually_eq_of_mem_source (hx : x ∈ (chart_at H c).source) : f =ᶠ[𝓝 x] f.to_times_cont_diff_bump ∘ ext_chart_at I c := f.eq_on_source.eventually_eq_of_mem $ mem_nhds_sets (chart_at H c).open_source hx lemma one_of_dist_le (hs : x ∈ (chart_at H c).source) (hd : eudist (ext_chart_at I c x) (ext_chart_at I c c) ≤ f.r) : f x = 1 := by simp only [f.eq_on_source hs, (∘), f.to_times_cont_diff_bump.one_of_mem_closed_ball hd] lemma support_eq_inter_preimage : support f = (chart_at H c).source ∩ (ext_chart_at I c ⁻¹' ball (ext_chart_at I c c) f.R) := by rw [coe_def, support_indicator, (∘), support_comp_eq_preimage, ← ext_chart_at_source I, ← (ext_chart_at I c).symm_image_target_inter_eq', ← (ext_chart_at I c).symm_image_target_inter_eq', f.to_times_cont_diff_bump.support_eq] lemma open_support : is_open (support f) := by { rw support_eq_inter_preimage, exact ext_chart_preimage_open_of_open I c is_open_ball } lemma support_eq_symm_image : support f = (ext_chart_at I c).symm '' (ball (ext_chart_at I c c) f.R ∩ range I) := begin rw [f.support_eq_inter_preimage, ← ext_chart_at_source I, ← (ext_chart_at I c).symm_image_target_inter_eq', inter_comm], congr' 1 with y, exact and.congr_right_iff.2 (λ hy, ⟨λ h, ext_chart_at_target_subset_range _ _ h, λ h, f.ball_subset ⟨hy, h⟩⟩) end lemma support_subset_source : support f ⊆ (chart_at H c).source := by { rw [f.support_eq_inter_preimage, ← ext_chart_at_source I], exact inter_subset_left _ _ } lemma image_eq_inter_preimage_of_subset_support {s : set M} (hs : s ⊆ support f) : ext_chart_at I c '' s = closed_ball (ext_chart_at I c c) f.R ∩ range I ∩ (ext_chart_at I c).symm ⁻¹' s := begin rw [support_eq_inter_preimage, subset_inter_iff, ← ext_chart_at_source I, ← image_subset_iff] at hs, cases hs with hse hsf, apply subset.antisymm, { refine subset_inter (subset_inter (subset.trans hsf ball_subset_closed_ball) _) _, { rintro _ ⟨x, -, rfl⟩, exact mem_range_self _ }, { rw [(ext_chart_at I c).image_eq_target_inter_inv_preimage hse], exact inter_subset_right _ _ } }, { refine subset.trans (inter_subset_inter_left _ f.closed_ball_subset) _, rw [(ext_chart_at I c).image_eq_target_inter_inv_preimage hse] } end lemma mem_Icc : f x ∈ Icc (0 : ℝ) 1 := begin have : f x = 0 ∨ f x = _, from indicator_eq_zero_or_self _ _ _, cases this; rw this, exacts [left_mem_Icc.2 zero_le_one, ⟨f.to_times_cont_diff_bump.nonneg, f.to_times_cont_diff_bump.le_one⟩] end lemma nonneg : 0 ≤ f x := f.mem_Icc.1 lemma le_one : f x ≤ 1 := f.mem_Icc.2 lemma eventually_eq_one_of_dist_lt (hs : x ∈ (chart_at H c).source) (hd : eudist (ext_chart_at I c x) (ext_chart_at I c c) < f.r) : f =ᶠ[𝓝 x] 1 := begin filter_upwards [mem_nhds_sets (ext_chart_preimage_open_of_open I c is_open_ball) ⟨hs, hd⟩], rintro z ⟨hzs, hzd : _ < _⟩, exact f.one_of_dist_le hzs hzd.le end lemma eventually_eq_one : f =ᶠ[𝓝 c] 1 := f.eventually_eq_one_of_dist_lt (mem_chart_source _ _) $ by { rw [euclidean.dist, dist_self], exact f.r_pos } @[simp] lemma eq_one : f c = 1 := f.eventually_eq_one.eq_of_nhds lemma support_mem_nhds : support f ∈ 𝓝 c := f.eventually_eq_one.mono $ λ x hx, by { rw hx, exact one_ne_zero } lemma closure_support_mem_nhds : closure (support f) ∈ 𝓝 c := mem_sets_of_superset f.support_mem_nhds subset_closure lemma c_mem_support : c ∈ support f := mem_of_nhds f.support_mem_nhds lemma nonempty_support : (support f).nonempty := ⟨c, f.c_mem_support⟩ lemma compact_symm_image_closed_ball : is_compact ((ext_chart_at I c).symm '' (closed_ball (ext_chart_at I c c) f.R ∩ range I)) := (compact_ball.inter_right I.closed_range).image_of_continuous_on $ (ext_chart_at_continuous_on_symm _ _).mono f.closed_ball_subset /-- Given a smooth bump function `f : smooth_bump_function I c`, the closed ball of radius `f.R` is known to include the support of `f`. These closed balls (in the model normed space `E`) intersected with `set.range I` form a basis of `𝓝[range I] (ext_chart_at I c c)`. -/ lemma nhds_within_range_basis : (𝓝[range I] (ext_chart_at I c c)).has_basis (λ f : smooth_bump_function I c, true) (λ f, closed_ball (ext_chart_at I c c) f.R ∩ range I) := begin refine ((nhds_within_has_basis euclidean.nhds_basis_closed_ball _).restrict_subset (ext_chart_at_target_mem_nhds_within _ _)).to_has_basis' _ _, { rintro R ⟨hR0, hsub⟩, exact ⟨⟨⟨⟨R / 2, R, half_pos hR0, half_lt_self hR0⟩⟩, hsub⟩, trivial, subset.rfl⟩ }, { exact λ f _, inter_mem_sets (mem_nhds_within_of_mem_nhds $ closed_ball_mem_nhds f.R_pos) self_mem_nhds_within } end lemma closed_image_of_closed {s : set M} (hsc : is_closed s) (hs : s ⊆ support f) : is_closed (ext_chart_at I c '' s) := begin rw f.image_eq_inter_preimage_of_subset_support hs, refine continuous_on.preimage_closed_of_closed ((ext_chart_continuous_on_symm _ _).mono f.closed_ball_subset) _ hsc, exact is_closed_inter is_closed_closed_ball I.closed_range end /-- If `f` is a smooth bump function and `s` closed subset of the support of `f` (i.e., of the open ball of radius `f.R`), then there exists `0 < r < f.R` such that `s` is a subset of the open ball of radius `r`. Formally, `s ⊆ e.source ∩ e ⁻¹' (ball (e c) r)`, where `e = ext_chart_at I c`. -/ lemma exists_r_pos_lt_subset_ball {s : set M} (hsc : is_closed s) (hs : s ⊆ support f) : ∃ r (hr : r ∈ Ioo 0 f.R), s ⊆ (chart_at H c).source ∩ ext_chart_at I c ⁻¹' (ball (ext_chart_at I c c) r) := begin set e := ext_chart_at I c, have : is_closed (e '' s) := f.closed_image_of_closed hsc hs, rw [support_eq_inter_preimage, subset_inter_iff, ← image_subset_iff] at hs, rcases euclidean.exists_pos_lt_subset_ball f.R_pos this hs.2 with ⟨r, hrR, hr⟩, exact ⟨r, hrR, subset_inter hs.1 (image_subset_iff.1 hr)⟩ end /-- Replace `r` with another value in the interval `(0, f.R)`. -/ def update_r (r : ℝ) (hr : r ∈ Ioo 0 f.R) : smooth_bump_function I c := ⟨⟨⟨r, f.R, hr.1, hr.2⟩⟩, f.closed_ball_subset⟩ @[simp] lemma update_r_R {r : ℝ} (hr : r ∈ Ioo 0 f.R) : (f.update_r r hr).R = f.R := rfl @[simp] lemma update_r_r {r : ℝ} (hr : r ∈ Ioo 0 f.R) : (f.update_r r hr).r = r := rfl @[simp] lemma support_update_r {r : ℝ} (hr : r ∈ Ioo 0 f.R) : support (f.update_r r hr) = support f := by simp only [support_eq_inter_preimage, update_r_R] instance : inhabited (smooth_bump_function I c) := classical.inhabited_of_nonempty nhds_within_range_basis.nonempty variables [t2_space M] lemma closed_symm_image_closed_ball : is_closed ((ext_chart_at I c).symm '' (closed_ball (ext_chart_at I c c) f.R ∩ range I)) := f.compact_symm_image_closed_ball.is_closed lemma closure_support_subset_symm_image_closed_ball : closure (support f) ⊆ (ext_chart_at I c).symm '' (closed_ball (ext_chart_at I c c) f.R ∩ range I) := begin rw support_eq_symm_image, exact closure_minimal (image_subset _ $ inter_subset_inter_left _ ball_subset_closed_ball) f.closed_symm_image_closed_ball end lemma closure_support_subset_ext_chart_at_source : closure (support f) ⊆ (ext_chart_at I c).source := calc closure (support f) ⊆ (ext_chart_at I c).symm '' (closed_ball (ext_chart_at I c c) f.R ∩ range I) : f.closure_support_subset_symm_image_closed_ball ... ⊆ (ext_chart_at I c).symm '' (ext_chart_at I c).target : image_subset _ f.closed_ball_subset ... = (ext_chart_at I c).source : (ext_chart_at I c).symm_image_target_eq_source lemma closure_support_subset_chart_at_source : closure (support f) ⊆ (chart_at H c).source := by simpa only [ext_chart_at_source] using f.closure_support_subset_ext_chart_at_source lemma compact_closure_support : is_compact (closure $ support f) := compact_of_is_closed_subset f.compact_symm_image_closed_ball is_closed_closure f.closure_support_subset_symm_image_closed_ball variables (I c) /-- The closures of supports of smooth bump functions centered at `c` form a basis of `𝓝 c`. In other words, each of these closures is a neighborhood of `c` and each neighborhood of `c` includes `closure (support f)` for some `f : smooth_bump_function I c`. -/ lemma nhds_basis_closure_support : (𝓝 c).has_basis (λ f : smooth_bump_function I c, true) (λ f, closure $ support f) := begin have : (𝓝 c).has_basis (λ f : smooth_bump_function I c, true) (λ f, (ext_chart_at I c).symm '' (closed_ball (ext_chart_at I c c) f.R ∩ range I)), { rw [← ext_chart_at_symm_map_nhds_within_range I c], exact nhds_within_range_basis.map _ }, refine this.to_has_basis' (λ f hf, ⟨f, trivial, f.closure_support_subset_symm_image_closed_ball⟩) (λ f _, f.closure_support_mem_nhds), end variable {c} /-- Given `s ∈ 𝓝 c`, the supports of smooth bump functions `f : smooth_bump_function I c` such that `closure (support f) ⊆ s` form a basis of `𝓝 c`. In other words, each of these supports is a neighborhood of `c` and each neighborhood of `c` includes `support f` for some `f : smooth_bump_function I c` such that `closure (support f) ⊆ s`. -/ lemma nhds_basis_support {s : set M} (hs : s ∈ 𝓝 c) : (𝓝 c).has_basis (λ f : smooth_bump_function I c, closure (support f) ⊆ s) (λ f, support f) := ((nhds_basis_closure_support I c).restrict_subset hs).to_has_basis' (λ f hf, ⟨f, hf.2, subset_closure⟩) (λ f hf, f.support_mem_nhds) variables [smooth_manifold_with_corners I M] {I} /-- A smooth bump function is infinitely smooth. -/ protected lemma smooth : smooth I 𝓘(ℝ) f := begin refine times_cont_mdiff_of_support (λ x hx, _), have : x ∈ (chart_at H c).source := f.closure_support_subset_chart_at_source hx, refine times_cont_mdiff_at.congr_of_eventually_eq _ (f.eq_on_source.eventually_eq_of_mem $ mem_nhds_sets (chart_at _ _).open_source this), exact f.to_times_cont_diff_bump.times_cont_diff_at.times_cont_mdiff_at.comp _ (times_cont_mdiff_at_ext_chart_at' this) end protected lemma smooth_at {x} : smooth_at I 𝓘(ℝ) f x := f.smooth.smooth_at /-- If `f : smooth_bump_function I c` is a smooth bump function and `g : M → G` is a function smooth on the source of the chart at `c`, then `f • g` is smooth on the whole manifold. -/ lemma smooth_smul {G} [normed_group G] [normed_space ℝ G] {g : M → G} (hg : smooth_on I 𝓘(ℝ, G) g (chart_at H c).source) : smooth I 𝓘(ℝ, G) (λ x, f x • g x) := begin apply times_cont_mdiff_of_support (λ x hx, _), have : x ∈ (chart_at H c).source, calc x ∈ closure (support (λ x, f x • g x)) : hx ... ⊆ closure (support f) : closure_mono (support_smul_subset_left _ _) ... ⊆ (chart_at _ c).source : f.closure_support_subset_chart_at_source, exact f.smooth_at.smul ((hg _ this).times_cont_mdiff_at $ mem_nhds_sets (chart_at _ _).open_source this) end end smooth_bump_function /-! ### Covering by supports of smooth bump functions In this section we define `smooth_bump_covering I s` to be a collection of `smooth_bump_function`s such that their supports is a locally finite family of sets and for each `x ∈ s` some function `f i` from the collection is equal to `1` in a neighborhood of `x`. A covering of this type is useful to construct a smooth partition of unity and can be used instead of a partition of unity in some proofs. We prove that on a smooth finite dimensional real manifold with `σ`-compact Hausdorff topology, for any `U : M → set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `smooth_bump_covering I s` subordinate to `U`. Then we use this fact to prove a version of the Whitney embedding theorem: any compact real manifold can be embedded into `ℝ^n` for large enough `n`. -/ /-- We say that a collection of `smooth_bump_function`s is a `smooth_bump_covering` of a set `s` if * `(f i).c ∈ s` for all `i`; * the family `λ i, support (f i)` is locally finite; * for each point `x ∈ s` there exists `i` such that `f i =ᶠ[𝓝 x] 1`; in other words, `x` belongs to the interior of `{y | f i y = 1}`; If `M` is a finite dimensional real manifold which is a sigma-compact Hausdorff topological space, then a choice of `smooth_bump_covering` is available as `smooth_bump_covering.choice_set`, see also `smooth_bump_covering.choice` for the case `s = univ` and `smooth_bump_covering.exists_is_subordinate` for a lemma providing a covering subordinate to a given `U : M → set M`. This covering can be used, e.g., to construct a partition of unity and to prove the weak Whitney embedding theorem. -/ structure smooth_bump_covering (s : set M) := (ι : Type uM) (c : ι → M) (to_fun : Π i, smooth_bump_function I (c i)) (c_mem' : ∀ i, c i ∈ s) (locally_finite' : locally_finite (λ i, support (to_fun i))) (eventually_eq_one' : ∀ x ∈ s, ∃ i, to_fun i =ᶠ[𝓝 x] 1) namespace smooth_bump_covering variables {s : set M} {U : M → set M} (fs : smooth_bump_covering I s) {I} instance : has_coe_to_fun (smooth_bump_covering I s) := ⟨_, to_fun⟩ @[simp] lemma coe_mk (ι : Type uM) (c : ι → M) (to_fun : Π i, smooth_bump_function I (c i)) (h₁ h₂ h₃) : ⇑(mk ι c to_fun h₁ h₂ h₃ : smooth_bump_covering I s) = to_fun := rfl /-- We say that `f : smooth_bump_covering I s` is *subordinate* to a map `U : M → set M` if for each index `i`, we have `closure (support (f i)) ⊆ U (f i).c`. This notion is a bit more general than being subordinate to an open covering of `M`, because we make no assumption about the way `U x` depends on `x`. -/ def is_subordinate {s : set M} (f : smooth_bump_covering I s) (U : M → set M) := ∀ i, closure (support $ f i) ⊆ U (f.c i) variable (I) /-- Let `M` be a smooth manifold with corners modelled on a finite dimensional real vector space. Suppose also that `M` is a Hausdorff `σ`-compact topological space. Let `s` be a closed set in `M` and `U : M → set M` be a collection of sets such that `U x ∈ 𝓝 x` for every `x ∈ s`. Then there exists a smooth bump covering of `s` that is subordinate to `U`. -/ lemma exists_is_subordinate [t2_space M] [sigma_compact_space M] (hs : is_closed s) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ f : smooth_bump_covering I s, f.is_subordinate U := begin -- First we deduce some missing instances haveI : locally_compact_space H := I.locally_compact, haveI : locally_compact_space M := charted_space.locally_compact H, haveI : normal_space M := normal_of_paracompact_t2, -- Next we choose a covering by supports of smooth bump functions have hB := λ x hx, smooth_bump_function.nhds_basis_support I (hU x hx), rcases refinement_of_locally_compact_sigma_compact_of_nhds_basis_set hs hB with ⟨ι, c, f, hf, hsub', hfin⟩, choose hcs hfU using hf, /- Then we use the shrinking lemma to get a covering by smaller open -/ rcases exists_subset_Union_closed_subset hs (λ i, (f i).open_support) (λ x hx, hfin.point_finite x) hsub' with ⟨V, hsV, hVc, hVf⟩, choose r hrR hr using λ i, (f i).exists_r_pos_lt_subset_ball (hVc i) (hVf i), refine ⟨⟨ι, c, λ i, (f i).update_r (r i) (hrR i), hcs, _, λ x hx, _⟩, λ i, _⟩, { simpa only [smooth_bump_function.support_update_r] }, { refine (mem_Union.1 $ hsV hx).imp (λ i hi, _), exact ((f i).update_r _ _).eventually_eq_one_of_dist_lt ((f i).support_subset_source $ hVf _ hi) (hr i hi).2 }, { simpa only [coe_mk, smooth_bump_function.support_update_r] using hfU i } end /-- Choice of a covering of a closed set `s` by supports of smooth bump functions. -/ def choice_set [t2_space M] [sigma_compact_space M] (s : set M) (hs : is_closed s) : smooth_bump_covering I s := (exists_is_subordinate I hs (λ x hx, univ_mem_sets)).some instance [t2_space M] [sigma_compact_space M] {s : set M} [is_closed s] : inhabited (smooth_bump_covering I s) := ⟨choice_set I s ‹_›⟩ variable (M) /-- Choice of a covering of a manifold by supports of smooth bump functions. -/ def choice [t2_space M] [sigma_compact_space M] : smooth_bump_covering I (univ : set M) := choice_set I univ is_closed_univ variables {I M} protected lemma locally_finite : locally_finite (λ i, support (fs i)) := fs.locally_finite' protected lemma point_finite (x : M) : {i | fs i x ≠ 0}.finite := fs.locally_finite.point_finite x lemma mem_chart_at_source_of_eq_one {i : fs.ι} {x : M} (h : fs i x = 1) : x ∈ (chart_at H (fs.c i)).source := (fs i).support_subset_source $ by simp [h] lemma mem_ext_chart_at_source_of_eq_one {i : fs.ι} {x : M} (h : fs i x = 1) : x ∈ (ext_chart_at I (fs.c i)).source := by { rw ext_chart_at_source, exact fs.mem_chart_at_source_of_eq_one h } /-- Index of a bump function such that `fs i =ᶠ[𝓝 x] 1`. -/ def ind (x : M) (hx : x ∈ s) : fs.ι := (fs.eventually_eq_one' x hx).some lemma eventually_eq_one (x : M) (hx : x ∈ s) : fs (fs.ind x hx) =ᶠ[𝓝 x] 1 := (fs.eventually_eq_one' x hx).some_spec lemma apply_ind (x : M) (hx : x ∈ s) : fs (fs.ind x hx) x = 1 := (fs.eventually_eq_one x hx).eq_of_nhds lemma mem_support_ind (x : M) (hx : x ∈ s) : x ∈ support (fs $ fs.ind x hx) := by simp [fs.apply_ind x hx] lemma mem_chart_at_ind_source (x : M) (hx : x ∈ s) : x ∈ (chart_at H (fs.c (fs.ind x hx))).source := fs.mem_chart_at_source_of_eq_one (fs.apply_ind x hx) lemma mem_ext_chart_at_ind_source (x : M) (hx : x ∈ s) : x ∈ (ext_chart_at I (fs.c (fs.ind x hx))).source := fs.mem_ext_chart_at_source_of_eq_one (fs.apply_ind x hx) section embedding /-! ### Whitney embedding theorem In this section we prove a version of the Whitney embedding theorem: for any compact real manifold `M`, for sufficiently large `n` there exists a smooth embedding `M → ℝ^n`. -/ instance fintype_ι_of_compact [compact_space M] : fintype fs.ι := fs.locally_finite.fintype_of_compact $ λ i, (fs i).nonempty_support variables [t2_space M] [fintype fs.ι] (f : smooth_bump_covering I (univ : set M)) [fintype f.ι] /-- Smooth embedding of `M` into `(E × ℝ) ^ f.ι`. -/ def embedding_pi_tangent : C^∞⟮I, M; 𝓘(ℝ, fs.ι → (E × ℝ)), fs.ι → (E × ℝ)⟯ := { to_fun := λ x i, (fs i x • ext_chart_at I (fs.c i) x, fs i x), times_cont_mdiff_to_fun := times_cont_mdiff_pi_space.2 $ λ i, ((fs i).smooth_smul times_cont_mdiff_on_ext_chart_at).prod_mk_space ((fs i).smooth) } local attribute [simp] lemma embedding_pi_tangent_coe : ⇑fs.embedding_pi_tangent = λ x i, (fs i x • ext_chart_at I (fs.c i) x, fs i x) := rfl lemma embedding_pi_tangent_inj_on : inj_on fs.embedding_pi_tangent s := begin intros x hx y hy h, simp only [embedding_pi_tangent_coe, funext_iff] at h, obtain ⟨h₁, h₂⟩ := prod.mk.inj_iff.1 (h (fs.ind x hx)), rw [fs.apply_ind x hx] at h₂, rw [← h₂, fs.apply_ind x hx, one_smul, one_smul] at h₁, have := fs.mem_ext_chart_at_source_of_eq_one h₂.symm, exact (ext_chart_at I (fs.c _)).inj_on (fs.mem_ext_chart_at_ind_source x hx) this h₁ end lemma embedding_pi_tangent_injective : injective f.embedding_pi_tangent := injective_iff_inj_on_univ.2 f.embedding_pi_tangent_inj_on lemma comp_embedding_pi_tangent_mfderiv (x : M) (hx : x ∈ s) : ((continuous_linear_map.fst ℝ E ℝ).comp (@continuous_linear_map.proj ℝ _ fs.ι (λ _, E × ℝ) _ _ (λ _, infer_instance) (fs.ind x hx))).comp (mfderiv I 𝓘(ℝ, fs.ι → (E × ℝ)) fs.embedding_pi_tangent x) = mfderiv I I (chart_at H (fs.c (fs.ind x hx))) x := begin set L := ((continuous_linear_map.fst ℝ E ℝ).comp (@continuous_linear_map.proj ℝ _ fs.ι (λ _, E × ℝ) _ _ (λ _, infer_instance) (fs.ind x hx))), have := (L.has_mfderiv_at.comp x (fs.embedding_pi_tangent.mdifferentiable_at.has_mfderiv_at)), convert has_mfderiv_at_unique this _, refine (has_mfderiv_at_ext_chart_at I (fs.mem_chart_at_ind_source x hx)).congr_of_eventually_eq _, refine (fs.eventually_eq_one x hx).mono (λ y hy, _), simp only [embedding_pi_tangent_coe, continuous_linear_map.coe_comp', (∘), continuous_linear_map.coe_fst', continuous_linear_map.proj_apply], rw [hy, pi.one_apply, one_smul] end lemma embedding_pi_tangent_ker_mfderiv (x : M) (hx : x ∈ s) : (mfderiv I 𝓘(ℝ, fs.ι → (E × ℝ)) fs.embedding_pi_tangent x).ker = ⊥ := begin apply bot_unique, rw [← (mdifferentiable_chart I (fs.c (fs.ind x hx))).ker_mfderiv_eq_bot (fs.mem_chart_at_ind_source x hx), ← comp_embedding_pi_tangent_mfderiv], exact linear_map.ker_le_ker_comp _ _ end lemma embedding_pi_tangent_injective_mfderiv (x : M) (hx : x ∈ s) : injective (mfderiv I 𝓘(ℝ, fs.ι → (E × ℝ)) fs.embedding_pi_tangent x) := linear_map.ker_eq_bot.1 (fs.embedding_pi_tangent_ker_mfderiv x hx) end embedding /-- Baby version of the Whitney weak embedding theorem: if `M` admits a finite covering by supports of bump functions, then for some `n` it can be immersed into the `n`-dimensional Euclidean space. -/ lemma exists_immersion_findim [t2_space M] (f : smooth_bump_covering I (univ : set M)) [fintype f.ι] : ∃ (n : ℕ) (e : M → euclidean_space ℝ (fin n)), smooth I (𝓡 n) e ∧ injective e ∧ ∀ x : M, injective (mfderiv I (𝓡 n) e x) := begin set F := euclidean_space ℝ (fin $ findim ℝ (f.ι → (E × ℝ))), letI : finite_dimensional ℝ (E × ℝ) := by apply_instance, set eEF : (f.ι → (E × ℝ)) ≃L[ℝ] F := continuous_linear_equiv.of_findim_eq findim_euclidean_space_fin.symm, refine ⟨_, eEF ∘ f.embedding_pi_tangent, eEF.to_diffeomorph.smooth.comp f.embedding_pi_tangent.smooth, eEF.injective.comp f.embedding_pi_tangent_injective, λ x, _⟩, rw [mfderiv_comp _ eEF.differentiable_at.mdifferentiable_at f.embedding_pi_tangent.mdifferentiable_at, eEF.mfderiv_eq], exact eEF.injective.comp (f.embedding_pi_tangent_injective_mfderiv _ trivial) end end smooth_bump_covering /-- Baby version of the Whitney weak embedding theorem: if `M` admits a finite covering by supports of bump functions, then for some `n` it can be embedded into the `n`-dimensional Euclidean space. -/ lemma exists_embedding_findim_of_compact [t2_space M] [compact_space M] : ∃ (n : ℕ) (e : M → euclidean_space ℝ (fin n)), smooth I (𝓡 n) e ∧ closed_embedding e ∧ ∀ x : M, injective (mfderiv I (𝓡 n) e x) := begin rcases (smooth_bump_covering.choice I M).exists_immersion_findim with ⟨n, e, hsmooth, hinj, hinj_mfderiv⟩, exact ⟨n, e, hsmooth, hsmooth.continuous.closed_embedding hinj, hinj_mfderiv⟩ end
759adc38fca5941dc73bd151ae45a55f0ba6d2da
3446e92e64a5de7ed1f2109cfb024f83cd904c34
/src/game/world4/level4.lean
526cb7185b1734acf175a24fba869dc6d75dabdc
[]
no_license
kckennylau/natural_number_game
019f4a5f419c9681e65234ecd124c564f9a0a246
ad8c0adaa725975be8a9f978c8494a39311029be
refs/heads/master
1,598,784,137,722
1,571,905,156,000
1,571,905,156,000
218,354,686
0
0
null
1,572,373,319,000
1,572,373,318,000
null
UTF-8
Lean
false
false
359
lean
import game.world4.level3 -- hide namespace mynat -- hide /- # World 4 : Power World ## Level 4 of 7: `one_pow` -/ /- Lemma For all naturals $m$, $1 ^ m = 1$. -/ lemma one_pow (m : mynat) : (1 : mynat) ^ m = 1 := begin [less_leaky] induction m with t ht, rw pow_zero, refl, rw pow_succ, rw ht, rw mul_one, refl, end end mynat -- hide
435cf8b12115c35029c9a265425f908a3f06b227
a5e2e6395319779f21675263bc0e486be5bc03bd
/bench/stlc10k.lean
1b2e48f5eb86db6605552f188f31d88a661bf693
[ "MIT" ]
permissive
AndrasKovacs/smalltt
10f0ec55fb3f487e9dd21a740fe1a899e0cdb790
c306f727ba3c92abe6ef75013da5a5dade6b15c8
refs/heads/master
1,689,497,785,394
1,680,893,106,000
1,680,893,106,000
112,098,494
483
26
MIT
1,640,720,815,000
1,511,713,805,000
Lean
UTF-8
Lean
false
false
587,910
lean
def Ty0 : Type 1 := ∀ (Ty0 : Type) (nat top bot : Ty0) (arr prod sum : Ty0 → Ty0 → Ty0) , Ty0 def nat0 : Ty0 := λ _ nat0 _ _ _ _ _ => nat0 def top0 : Ty0 := λ _ _ top0 _ _ _ _ => top0 def bot0 : Ty0 := λ _ _ _ bot0 _ _ _ => bot0 def arr0 : Ty0 → Ty0 → Ty0 := λ A B Ty0 nat0 top0 bot0 arr0 prod sum => arr0 (A Ty0 nat0 top0 bot0 arr0 prod sum) (B Ty0 nat0 top0 bot0 arr0 prod sum) def prod0 : Ty0 → Ty0 → Ty0 := λ A B Ty0 nat0 top0 bot0 arr0 prod0 sum => prod0 (A Ty0 nat0 top0 bot0 arr0 prod0 sum) (B Ty0 nat0 top0 bot0 arr0 prod0 sum) def sum0 : Ty0 → Ty0 → Ty0 := λ A B Ty0 nat0 top0 bot0 arr0 prod0 sum0 => sum0 (A Ty0 nat0 top0 bot0 arr0 prod0 sum0) (B Ty0 nat0 top0 bot0 arr0 prod0 sum0) def Con0 : Type 1 := ∀ (Con0 : Type) (nil : Con0) (snoc : Con0 → Ty0 → Con0) , Con0 def nil0 : Con0 := λ Con0 nil0 snoc => nil0 def snoc0 : Con0 → Ty0 → Con0 := λ Γ A Con0 nil0 snoc0 => snoc0 (Γ Con0 nil0 snoc0) A def Var0 : Con0 → Ty0 → Type 1 := λ Γ A => ∀ (Var0 : Con0 → Ty0 → Type) (vz : ∀{Γ A}, Var0 (snoc0 Γ A) A) (vs : ∀{Γ B A}, Var0 Γ A → Var0 (snoc0 Γ B) A) , Var0 Γ A def vz0 : ∀ {Γ A}, Var0 (snoc0 Γ A) A := λ Var0 vz0 vs => vz0 def vs0 : ∀ {Γ B A}, Var0 Γ A → Var0 (snoc0 Γ B) A := λ x Var0 vz0 vs0 => vs0 (x Var0 vz0 vs0) def Tm0 : Con0 → Ty0 → Type 1 := λ Γ A => ∀ (Tm0 : Con0 → Ty0 → Type) (var : ∀ {Γ A}, Var0 Γ A → Tm0 Γ A) (lam : ∀ {Γ A B}, (Tm0 (snoc0 Γ A) B → Tm0 Γ (arr0 A B))) (app : ∀ {Γ A B} , Tm0 Γ (arr0 A B) → Tm0 Γ A → Tm0 Γ B) (tt : ∀ {Γ} , Tm0 Γ top0) (pair : ∀ {Γ A B} , Tm0 Γ A → Tm0 Γ B → Tm0 Γ (prod0 A B)) (fst : ∀ {Γ A B} , Tm0 Γ (prod0 A B) → Tm0 Γ A) (snd : ∀ {Γ A B} , Tm0 Γ (prod0 A B) → Tm0 Γ B) (left : ∀ {Γ A B} , Tm0 Γ A → Tm0 Γ (sum0 A B)) (right : ∀ {Γ A B} , Tm0 Γ B → Tm0 Γ (sum0 A B)) (case : ∀ {Γ A B C} , Tm0 Γ (sum0 A B) → Tm0 Γ (arr0 A C) → Tm0 Γ (arr0 B C) → Tm0 Γ C) (zero : ∀ {Γ} , Tm0 Γ nat0) (suc : ∀ {Γ} , Tm0 Γ nat0 → Tm0 Γ nat0) (rec : ∀ {Γ A} , Tm0 Γ nat0 → Tm0 Γ (arr0 nat0 (arr0 A A)) → Tm0 Γ A → Tm0 Γ A) , Tm0 Γ A def var0 : ∀ {Γ A}, Var0 Γ A → Tm0 Γ A := λ x Tm0 var0 lam app tt pair fst snd left right case zero suc rec => var0 x def lam0 : ∀ {Γ A B} , Tm0 (snoc0 Γ A) B → Tm0 Γ (arr0 A B) := λ t Tm0 var0 lam0 app tt pair fst snd left right case zero suc rec => lam0 (t Tm0 var0 lam0 app tt pair fst snd left right case zero suc rec) def app0 : ∀ {Γ A B} , Tm0 Γ (arr0 A B) → Tm0 Γ A → Tm0 Γ B := λ t u Tm0 var0 lam0 app0 tt pair fst snd left right case zero suc rec => app0 (t Tm0 var0 lam0 app0 tt pair fst snd left right case zero suc rec) (u Tm0 var0 lam0 app0 tt pair fst snd left right case zero suc rec) def tt0 : ∀ {Γ} , Tm0 Γ top0 := λ Tm0 var0 lam0 app0 tt0 pair fst snd left right case zero suc rec => tt0 def pair0 : ∀ {Γ A B} , Tm0 Γ A → Tm0 Γ B → Tm0 Γ (prod0 A B) := λ t u Tm0 var0 lam0 app0 tt0 pair0 fst snd left right case zero suc rec => pair0 (t Tm0 var0 lam0 app0 tt0 pair0 fst snd left right case zero suc rec) (u Tm0 var0 lam0 app0 tt0 pair0 fst snd left right case zero suc rec) def fst0 : ∀ {Γ A B} , Tm0 Γ (prod0 A B) → Tm0 Γ A := λ t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd left right case zero suc rec => fst0 (t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd left right case zero suc rec) def snd0 : ∀ {Γ A B} , Tm0 Γ (prod0 A B) → Tm0 Γ B := λ t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left right case zero suc rec => snd0 (t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left right case zero suc rec) def left0 : ∀ {Γ A B} , Tm0 Γ A → Tm0 Γ (sum0 A B) := λ t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right case zero suc rec => left0 (t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right case zero suc rec) def right0 : ∀ {Γ A B} , Tm0 Γ B → Tm0 Γ (sum0 A B) := λ t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case zero suc rec => right0 (t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case zero suc rec) def case0 : ∀ {Γ A B C} , Tm0 Γ (sum0 A B) → Tm0 Γ (arr0 A C) → Tm0 Γ (arr0 B C) → Tm0 Γ C := λ t u v Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case0 zero suc rec => case0 (t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case0 zero suc rec) (u Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case0 zero suc rec) (v Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case0 zero suc rec) def zero0 : ∀ {Γ} , Tm0 Γ nat0 := λ Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case0 zero0 suc rec => zero0 def suc0 : ∀ {Γ} , Tm0 Γ nat0 → Tm0 Γ nat0 := λ t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case0 zero0 suc0 rec => suc0 (t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case0 zero0 suc0 rec) def rec0 : ∀ {Γ A} , Tm0 Γ nat0 → Tm0 Γ (arr0 nat0 (arr0 A A)) → Tm0 Γ A → Tm0 Γ A := λ t u v Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case0 zero0 suc0 rec0 => rec0 (t Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case0 zero0 suc0 rec0) (u Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case0 zero0 suc0 rec0) (v Tm0 var0 lam0 app0 tt0 pair0 fst0 snd0 left0 right0 case0 zero0 suc0 rec0) def v00 : ∀ {Γ A}, Tm0 (snoc0 Γ A) A := var0 vz0 def v10 : ∀ {Γ A B}, Tm0 (snoc0 (snoc0 Γ A) B) A := var0 (vs0 vz0) def v20 : ∀ {Γ A B C}, Tm0 (snoc0 (snoc0 (snoc0 Γ A) B) C) A := var0 (vs0 (vs0 vz0)) def v30 : ∀ {Γ A B C D}, Tm0 (snoc0 (snoc0 (snoc0 (snoc0 Γ A) B) C) D) A := var0 (vs0 (vs0 (vs0 vz0))) def tbool0 : Ty0 := sum0 top0 top0 def ttrue0 : ∀ {Γ}, Tm0 Γ tbool0 := left0 tt0 def tfalse0 : ∀ {Γ}, Tm0 Γ tbool0 := right0 tt0 def ifthenelse0 : ∀ {Γ A}, Tm0 Γ (arr0 tbool0 (arr0 A (arr0 A A))) := lam0 (lam0 (lam0 (case0 v20 (lam0 v20) (lam0 v10)))) def times40 : ∀ {Γ A}, Tm0 Γ (arr0 (arr0 A A) (arr0 A A)) := lam0 (lam0 (app0 v10 (app0 v10 (app0 v10 (app0 v10 v00))))) def add0 : ∀ {Γ}, Tm0 Γ (arr0 nat0 (arr0 nat0 nat0)) := lam0 (rec0 v00 (lam0 (lam0 (lam0 (suc0 (app0 v10 v00))))) (lam0 v00)) def mul0 : ∀ {Γ}, Tm0 Γ (arr0 nat0 (arr0 nat0 nat0)) := lam0 (rec0 v00 (lam0 (lam0 (lam0 (app0 (app0 add0 (app0 v10 v00)) v00)))) (lam0 zero0)) def fact0 : ∀ {Γ}, Tm0 Γ (arr0 nat0 nat0) := lam0 (rec0 v00 (lam0 (lam0 (app0 (app0 mul0 (suc0 v10)) v00))) (suc0 zero0)) def Ty1 : Type 1 := ∀ (Ty1 : Type) (nat top bot : Ty1) (arr prod sum : Ty1 → Ty1 → Ty1) , Ty1 def nat1 : Ty1 := λ _ nat1 _ _ _ _ _ => nat1 def top1 : Ty1 := λ _ _ top1 _ _ _ _ => top1 def bot1 : Ty1 := λ _ _ _ bot1 _ _ _ => bot1 def arr1 : Ty1 → Ty1 → Ty1 := λ A B Ty1 nat1 top1 bot1 arr1 prod sum => arr1 (A Ty1 nat1 top1 bot1 arr1 prod sum) (B Ty1 nat1 top1 bot1 arr1 prod sum) def prod1 : Ty1 → Ty1 → Ty1 := λ A B Ty1 nat1 top1 bot1 arr1 prod1 sum => prod1 (A Ty1 nat1 top1 bot1 arr1 prod1 sum) (B Ty1 nat1 top1 bot1 arr1 prod1 sum) def sum1 : Ty1 → Ty1 → Ty1 := λ A B Ty1 nat1 top1 bot1 arr1 prod1 sum1 => sum1 (A Ty1 nat1 top1 bot1 arr1 prod1 sum1) (B Ty1 nat1 top1 bot1 arr1 prod1 sum1) def Con1 : Type 1 := ∀ (Con1 : Type) (nil : Con1) (snoc : Con1 → Ty1 → Con1) , Con1 def nil1 : Con1 := λ Con1 nil1 snoc => nil1 def snoc1 : Con1 → Ty1 → Con1 := λ Γ A Con1 nil1 snoc1 => snoc1 (Γ Con1 nil1 snoc1) A def Var1 : Con1 → Ty1 → Type 1 := λ Γ A => ∀ (Var1 : Con1 → Ty1 → Type) (vz : ∀{Γ A}, Var1 (snoc1 Γ A) A) (vs : ∀{Γ B A}, Var1 Γ A → Var1 (snoc1 Γ B) A) , Var1 Γ A def vz1 : ∀ {Γ A}, Var1 (snoc1 Γ A) A := λ Var1 vz1 vs => vz1 def vs1 : ∀ {Γ B A}, Var1 Γ A → Var1 (snoc1 Γ B) A := λ x Var1 vz1 vs1 => vs1 (x Var1 vz1 vs1) def Tm1 : Con1 → Ty1 → Type 1 := λ Γ A => ∀ (Tm1 : Con1 → Ty1 → Type) (var : ∀ {Γ A}, Var1 Γ A → Tm1 Γ A) (lam : ∀ {Γ A B}, (Tm1 (snoc1 Γ A) B → Tm1 Γ (arr1 A B))) (app : ∀ {Γ A B} , Tm1 Γ (arr1 A B) → Tm1 Γ A → Tm1 Γ B) (tt : ∀ {Γ} , Tm1 Γ top1) (pair : ∀ {Γ A B} , Tm1 Γ A → Tm1 Γ B → Tm1 Γ (prod1 A B)) (fst : ∀ {Γ A B} , Tm1 Γ (prod1 A B) → Tm1 Γ A) (snd : ∀ {Γ A B} , Tm1 Γ (prod1 A B) → Tm1 Γ B) (left : ∀ {Γ A B} , Tm1 Γ A → Tm1 Γ (sum1 A B)) (right : ∀ {Γ A B} , Tm1 Γ B → Tm1 Γ (sum1 A B)) (case : ∀ {Γ A B C} , Tm1 Γ (sum1 A B) → Tm1 Γ (arr1 A C) → Tm1 Γ (arr1 B C) → Tm1 Γ C) (zero : ∀ {Γ} , Tm1 Γ nat1) (suc : ∀ {Γ} , Tm1 Γ nat1 → Tm1 Γ nat1) (rec : ∀ {Γ A} , Tm1 Γ nat1 → Tm1 Γ (arr1 nat1 (arr1 A A)) → Tm1 Γ A → Tm1 Γ A) , Tm1 Γ A def var1 : ∀ {Γ A}, Var1 Γ A → Tm1 Γ A := λ x Tm1 var1 lam app tt pair fst snd left right case zero suc rec => var1 x def lam1 : ∀ {Γ A B} , Tm1 (snoc1 Γ A) B → Tm1 Γ (arr1 A B) := λ t Tm1 var1 lam1 app tt pair fst snd left right case zero suc rec => lam1 (t Tm1 var1 lam1 app tt pair fst snd left right case zero suc rec) def app1 : ∀ {Γ A B} , Tm1 Γ (arr1 A B) → Tm1 Γ A → Tm1 Γ B := λ t u Tm1 var1 lam1 app1 tt pair fst snd left right case zero suc rec => app1 (t Tm1 var1 lam1 app1 tt pair fst snd left right case zero suc rec) (u Tm1 var1 lam1 app1 tt pair fst snd left right case zero suc rec) def tt1 : ∀ {Γ} , Tm1 Γ top1 := λ Tm1 var1 lam1 app1 tt1 pair fst snd left right case zero suc rec => tt1 def pair1 : ∀ {Γ A B} , Tm1 Γ A → Tm1 Γ B → Tm1 Γ (prod1 A B) := λ t u Tm1 var1 lam1 app1 tt1 pair1 fst snd left right case zero suc rec => pair1 (t Tm1 var1 lam1 app1 tt1 pair1 fst snd left right case zero suc rec) (u Tm1 var1 lam1 app1 tt1 pair1 fst snd left right case zero suc rec) def fst1 : ∀ {Γ A B} , Tm1 Γ (prod1 A B) → Tm1 Γ A := λ t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd left right case zero suc rec => fst1 (t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd left right case zero suc rec) def snd1 : ∀ {Γ A B} , Tm1 Γ (prod1 A B) → Tm1 Γ B := λ t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left right case zero suc rec => snd1 (t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left right case zero suc rec) def left1 : ∀ {Γ A B} , Tm1 Γ A → Tm1 Γ (sum1 A B) := λ t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right case zero suc rec => left1 (t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right case zero suc rec) def right1 : ∀ {Γ A B} , Tm1 Γ B → Tm1 Γ (sum1 A B) := λ t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case zero suc rec => right1 (t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case zero suc rec) def case1 : ∀ {Γ A B C} , Tm1 Γ (sum1 A B) → Tm1 Γ (arr1 A C) → Tm1 Γ (arr1 B C) → Tm1 Γ C := λ t u v Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case1 zero suc rec => case1 (t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case1 zero suc rec) (u Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case1 zero suc rec) (v Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case1 zero suc rec) def zero1 : ∀ {Γ} , Tm1 Γ nat1 := λ Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case1 zero1 suc rec => zero1 def suc1 : ∀ {Γ} , Tm1 Γ nat1 → Tm1 Γ nat1 := λ t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case1 zero1 suc1 rec => suc1 (t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case1 zero1 suc1 rec) def rec1 : ∀ {Γ A} , Tm1 Γ nat1 → Tm1 Γ (arr1 nat1 (arr1 A A)) → Tm1 Γ A → Tm1 Γ A := λ t u v Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case1 zero1 suc1 rec1 => rec1 (t Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case1 zero1 suc1 rec1) (u Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case1 zero1 suc1 rec1) (v Tm1 var1 lam1 app1 tt1 pair1 fst1 snd1 left1 right1 case1 zero1 suc1 rec1) def v01 : ∀ {Γ A}, Tm1 (snoc1 Γ A) A := var1 vz1 def v11 : ∀ {Γ A B}, Tm1 (snoc1 (snoc1 Γ A) B) A := var1 (vs1 vz1) def v21 : ∀ {Γ A B C}, Tm1 (snoc1 (snoc1 (snoc1 Γ A) B) C) A := var1 (vs1 (vs1 vz1)) def v31 : ∀ {Γ A B C D}, Tm1 (snoc1 (snoc1 (snoc1 (snoc1 Γ A) B) C) D) A := var1 (vs1 (vs1 (vs1 vz1))) def tbool1 : Ty1 := sum1 top1 top1 def ttrue1 : ∀ {Γ}, Tm1 Γ tbool1 := left1 tt1 def tfalse1 : ∀ {Γ}, Tm1 Γ tbool1 := right1 tt1 def ifthenelse1 : ∀ {Γ A}, Tm1 Γ (arr1 tbool1 (arr1 A (arr1 A A))) := lam1 (lam1 (lam1 (case1 v21 (lam1 v21) (lam1 v11)))) def times41 : ∀ {Γ A}, Tm1 Γ (arr1 (arr1 A A) (arr1 A A)) := lam1 (lam1 (app1 v11 (app1 v11 (app1 v11 (app1 v11 v01))))) def add1 : ∀ {Γ}, Tm1 Γ (arr1 nat1 (arr1 nat1 nat1)) := lam1 (rec1 v01 (lam1 (lam1 (lam1 (suc1 (app1 v11 v01))))) (lam1 v01)) def mul1 : ∀ {Γ}, Tm1 Γ (arr1 nat1 (arr1 nat1 nat1)) := lam1 (rec1 v01 (lam1 (lam1 (lam1 (app1 (app1 add1 (app1 v11 v01)) v01)))) (lam1 zero1)) def fact1 : ∀ {Γ}, Tm1 Γ (arr1 nat1 nat1) := lam1 (rec1 v01 (lam1 (lam1 (app1 (app1 mul1 (suc1 v11)) v01))) (suc1 zero1)) def Ty2 : Type 1 := ∀ (Ty2 : Type) (nat top bot : Ty2) (arr prod sum : Ty2 → Ty2 → Ty2) , Ty2 def nat2 : Ty2 := λ _ nat2 _ _ _ _ _ => nat2 def top2 : Ty2 := λ _ _ top2 _ _ _ _ => top2 def bot2 : Ty2 := λ _ _ _ bot2 _ _ _ => bot2 def arr2 : Ty2 → Ty2 → Ty2 := λ A B Ty2 nat2 top2 bot2 arr2 prod sum => arr2 (A Ty2 nat2 top2 bot2 arr2 prod sum) (B Ty2 nat2 top2 bot2 arr2 prod sum) def prod2 : Ty2 → Ty2 → Ty2 := λ A B Ty2 nat2 top2 bot2 arr2 prod2 sum => prod2 (A Ty2 nat2 top2 bot2 arr2 prod2 sum) (B Ty2 nat2 top2 bot2 arr2 prod2 sum) def sum2 : Ty2 → Ty2 → Ty2 := λ A B Ty2 nat2 top2 bot2 arr2 prod2 sum2 => sum2 (A Ty2 nat2 top2 bot2 arr2 prod2 sum2) (B Ty2 nat2 top2 bot2 arr2 prod2 sum2) def Con2 : Type 1 := ∀ (Con2 : Type) (nil : Con2) (snoc : Con2 → Ty2 → Con2) , Con2 def nil2 : Con2 := λ Con2 nil2 snoc => nil2 def snoc2 : Con2 → Ty2 → Con2 := λ Γ A Con2 nil2 snoc2 => snoc2 (Γ Con2 nil2 snoc2) A def Var2 : Con2 → Ty2 → Type 1 := λ Γ A => ∀ (Var2 : Con2 → Ty2 → Type) (vz : ∀{Γ A}, Var2 (snoc2 Γ A) A) (vs : ∀{Γ B A}, Var2 Γ A → Var2 (snoc2 Γ B) A) , Var2 Γ A def vz2 : ∀ {Γ A}, Var2 (snoc2 Γ A) A := λ Var2 vz2 vs => vz2 def vs2 : ∀ {Γ B A}, Var2 Γ A → Var2 (snoc2 Γ B) A := λ x Var2 vz2 vs2 => vs2 (x Var2 vz2 vs2) def Tm2 : Con2 → Ty2 → Type 1 := λ Γ A => ∀ (Tm2 : Con2 → Ty2 → Type) (var : ∀ {Γ A}, Var2 Γ A → Tm2 Γ A) (lam : ∀ {Γ A B}, (Tm2 (snoc2 Γ A) B → Tm2 Γ (arr2 A B))) (app : ∀ {Γ A B} , Tm2 Γ (arr2 A B) → Tm2 Γ A → Tm2 Γ B) (tt : ∀ {Γ} , Tm2 Γ top2) (pair : ∀ {Γ A B} , Tm2 Γ A → Tm2 Γ B → Tm2 Γ (prod2 A B)) (fst : ∀ {Γ A B} , Tm2 Γ (prod2 A B) → Tm2 Γ A) (snd : ∀ {Γ A B} , Tm2 Γ (prod2 A B) → Tm2 Γ B) (left : ∀ {Γ A B} , Tm2 Γ A → Tm2 Γ (sum2 A B)) (right : ∀ {Γ A B} , Tm2 Γ B → Tm2 Γ (sum2 A B)) (case : ∀ {Γ A B C} , Tm2 Γ (sum2 A B) → Tm2 Γ (arr2 A C) → Tm2 Γ (arr2 B C) → Tm2 Γ C) (zero : ∀ {Γ} , Tm2 Γ nat2) (suc : ∀ {Γ} , Tm2 Γ nat2 → Tm2 Γ nat2) (rec : ∀ {Γ A} , Tm2 Γ nat2 → Tm2 Γ (arr2 nat2 (arr2 A A)) → Tm2 Γ A → Tm2 Γ A) , Tm2 Γ A def var2 : ∀ {Γ A}, Var2 Γ A → Tm2 Γ A := λ x Tm2 var2 lam app tt pair fst snd left right case zero suc rec => var2 x def lam2 : ∀ {Γ A B} , Tm2 (snoc2 Γ A) B → Tm2 Γ (arr2 A B) := λ t Tm2 var2 lam2 app tt pair fst snd left right case zero suc rec => lam2 (t Tm2 var2 lam2 app tt pair fst snd left right case zero suc rec) def app2 : ∀ {Γ A B} , Tm2 Γ (arr2 A B) → Tm2 Γ A → Tm2 Γ B := λ t u Tm2 var2 lam2 app2 tt pair fst snd left right case zero suc rec => app2 (t Tm2 var2 lam2 app2 tt pair fst snd left right case zero suc rec) (u Tm2 var2 lam2 app2 tt pair fst snd left right case zero suc rec) def tt2 : ∀ {Γ} , Tm2 Γ top2 := λ Tm2 var2 lam2 app2 tt2 pair fst snd left right case zero suc rec => tt2 def pair2 : ∀ {Γ A B} , Tm2 Γ A → Tm2 Γ B → Tm2 Γ (prod2 A B) := λ t u Tm2 var2 lam2 app2 tt2 pair2 fst snd left right case zero suc rec => pair2 (t Tm2 var2 lam2 app2 tt2 pair2 fst snd left right case zero suc rec) (u Tm2 var2 lam2 app2 tt2 pair2 fst snd left right case zero suc rec) def fst2 : ∀ {Γ A B} , Tm2 Γ (prod2 A B) → Tm2 Γ A := λ t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd left right case zero suc rec => fst2 (t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd left right case zero suc rec) def snd2 : ∀ {Γ A B} , Tm2 Γ (prod2 A B) → Tm2 Γ B := λ t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left right case zero suc rec => snd2 (t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left right case zero suc rec) def left2 : ∀ {Γ A B} , Tm2 Γ A → Tm2 Γ (sum2 A B) := λ t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right case zero suc rec => left2 (t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right case zero suc rec) def right2 : ∀ {Γ A B} , Tm2 Γ B → Tm2 Γ (sum2 A B) := λ t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case zero suc rec => right2 (t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case zero suc rec) def case2 : ∀ {Γ A B C} , Tm2 Γ (sum2 A B) → Tm2 Γ (arr2 A C) → Tm2 Γ (arr2 B C) → Tm2 Γ C := λ t u v Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case2 zero suc rec => case2 (t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case2 zero suc rec) (u Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case2 zero suc rec) (v Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case2 zero suc rec) def zero2 : ∀ {Γ} , Tm2 Γ nat2 := λ Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case2 zero2 suc rec => zero2 def suc2 : ∀ {Γ} , Tm2 Γ nat2 → Tm2 Γ nat2 := λ t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case2 zero2 suc2 rec => suc2 (t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case2 zero2 suc2 rec) def rec2 : ∀ {Γ A} , Tm2 Γ nat2 → Tm2 Γ (arr2 nat2 (arr2 A A)) → Tm2 Γ A → Tm2 Γ A := λ t u v Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case2 zero2 suc2 rec2 => rec2 (t Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case2 zero2 suc2 rec2) (u Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case2 zero2 suc2 rec2) (v Tm2 var2 lam2 app2 tt2 pair2 fst2 snd2 left2 right2 case2 zero2 suc2 rec2) def v02 : ∀ {Γ A}, Tm2 (snoc2 Γ A) A := var2 vz2 def v12 : ∀ {Γ A B}, Tm2 (snoc2 (snoc2 Γ A) B) A := var2 (vs2 vz2) def v22 : ∀ {Γ A B C}, Tm2 (snoc2 (snoc2 (snoc2 Γ A) B) C) A := var2 (vs2 (vs2 vz2)) def v32 : ∀ {Γ A B C D}, Tm2 (snoc2 (snoc2 (snoc2 (snoc2 Γ A) B) C) D) A := var2 (vs2 (vs2 (vs2 vz2))) def tbool2 : Ty2 := sum2 top2 top2 def ttrue2 : ∀ {Γ}, Tm2 Γ tbool2 := left2 tt2 def tfalse2 : ∀ {Γ}, Tm2 Γ tbool2 := right2 tt2 def ifthenelse2 : ∀ {Γ A}, Tm2 Γ (arr2 tbool2 (arr2 A (arr2 A A))) := lam2 (lam2 (lam2 (case2 v22 (lam2 v22) (lam2 v12)))) def times42 : ∀ {Γ A}, Tm2 Γ (arr2 (arr2 A A) (arr2 A A)) := lam2 (lam2 (app2 v12 (app2 v12 (app2 v12 (app2 v12 v02))))) def add2 : ∀ {Γ}, Tm2 Γ (arr2 nat2 (arr2 nat2 nat2)) := lam2 (rec2 v02 (lam2 (lam2 (lam2 (suc2 (app2 v12 v02))))) (lam2 v02)) def mul2 : ∀ {Γ}, Tm2 Γ (arr2 nat2 (arr2 nat2 nat2)) := lam2 (rec2 v02 (lam2 (lam2 (lam2 (app2 (app2 add2 (app2 v12 v02)) v02)))) (lam2 zero2)) def fact2 : ∀ {Γ}, Tm2 Γ (arr2 nat2 nat2) := lam2 (rec2 v02 (lam2 (lam2 (app2 (app2 mul2 (suc2 v12)) v02))) (suc2 zero2)) def Ty3 : Type 1 := ∀ (Ty3 : Type) (nat top bot : Ty3) (arr prod sum : Ty3 → Ty3 → Ty3) , Ty3 def nat3 : Ty3 := λ _ nat3 _ _ _ _ _ => nat3 def top3 : Ty3 := λ _ _ top3 _ _ _ _ => top3 def bot3 : Ty3 := λ _ _ _ bot3 _ _ _ => bot3 def arr3 : Ty3 → Ty3 → Ty3 := λ A B Ty3 nat3 top3 bot3 arr3 prod sum => arr3 (A Ty3 nat3 top3 bot3 arr3 prod sum) (B Ty3 nat3 top3 bot3 arr3 prod sum) def prod3 : Ty3 → Ty3 → Ty3 := λ A B Ty3 nat3 top3 bot3 arr3 prod3 sum => prod3 (A Ty3 nat3 top3 bot3 arr3 prod3 sum) (B Ty3 nat3 top3 bot3 arr3 prod3 sum) def sum3 : Ty3 → Ty3 → Ty3 := λ A B Ty3 nat3 top3 bot3 arr3 prod3 sum3 => sum3 (A Ty3 nat3 top3 bot3 arr3 prod3 sum3) (B Ty3 nat3 top3 bot3 arr3 prod3 sum3) def Con3 : Type 1 := ∀ (Con3 : Type) (nil : Con3) (snoc : Con3 → Ty3 → Con3) , Con3 def nil3 : Con3 := λ Con3 nil3 snoc => nil3 def snoc3 : Con3 → Ty3 → Con3 := λ Γ A Con3 nil3 snoc3 => snoc3 (Γ Con3 nil3 snoc3) A def Var3 : Con3 → Ty3 → Type 1 := λ Γ A => ∀ (Var3 : Con3 → Ty3 → Type) (vz : ∀{Γ A}, Var3 (snoc3 Γ A) A) (vs : ∀{Γ B A}, Var3 Γ A → Var3 (snoc3 Γ B) A) , Var3 Γ A def vz3 : ∀ {Γ A}, Var3 (snoc3 Γ A) A := λ Var3 vz3 vs => vz3 def vs3 : ∀ {Γ B A}, Var3 Γ A → Var3 (snoc3 Γ B) A := λ x Var3 vz3 vs3 => vs3 (x Var3 vz3 vs3) def Tm3 : Con3 → Ty3 → Type 1 := λ Γ A => ∀ (Tm3 : Con3 → Ty3 → Type) (var : ∀ {Γ A}, Var3 Γ A → Tm3 Γ A) (lam : ∀ {Γ A B}, (Tm3 (snoc3 Γ A) B → Tm3 Γ (arr3 A B))) (app : ∀ {Γ A B} , Tm3 Γ (arr3 A B) → Tm3 Γ A → Tm3 Γ B) (tt : ∀ {Γ} , Tm3 Γ top3) (pair : ∀ {Γ A B} , Tm3 Γ A → Tm3 Γ B → Tm3 Γ (prod3 A B)) (fst : ∀ {Γ A B} , Tm3 Γ (prod3 A B) → Tm3 Γ A) (snd : ∀ {Γ A B} , Tm3 Γ (prod3 A B) → Tm3 Γ B) (left : ∀ {Γ A B} , Tm3 Γ A → Tm3 Γ (sum3 A B)) (right : ∀ {Γ A B} , Tm3 Γ B → Tm3 Γ (sum3 A B)) (case : ∀ {Γ A B C} , Tm3 Γ (sum3 A B) → Tm3 Γ (arr3 A C) → Tm3 Γ (arr3 B C) → Tm3 Γ C) (zero : ∀ {Γ} , Tm3 Γ nat3) (suc : ∀ {Γ} , Tm3 Γ nat3 → Tm3 Γ nat3) (rec : ∀ {Γ A} , Tm3 Γ nat3 → Tm3 Γ (arr3 nat3 (arr3 A A)) → Tm3 Γ A → Tm3 Γ A) , Tm3 Γ A def var3 : ∀ {Γ A}, Var3 Γ A → Tm3 Γ A := λ x Tm3 var3 lam app tt pair fst snd left right case zero suc rec => var3 x def lam3 : ∀ {Γ A B} , Tm3 (snoc3 Γ A) B → Tm3 Γ (arr3 A B) := λ t Tm3 var3 lam3 app tt pair fst snd left right case zero suc rec => lam3 (t Tm3 var3 lam3 app tt pair fst snd left right case zero suc rec) def app3 : ∀ {Γ A B} , Tm3 Γ (arr3 A B) → Tm3 Γ A → Tm3 Γ B := λ t u Tm3 var3 lam3 app3 tt pair fst snd left right case zero suc rec => app3 (t Tm3 var3 lam3 app3 tt pair fst snd left right case zero suc rec) (u Tm3 var3 lam3 app3 tt pair fst snd left right case zero suc rec) def tt3 : ∀ {Γ} , Tm3 Γ top3 := λ Tm3 var3 lam3 app3 tt3 pair fst snd left right case zero suc rec => tt3 def pair3 : ∀ {Γ A B} , Tm3 Γ A → Tm3 Γ B → Tm3 Γ (prod3 A B) := λ t u Tm3 var3 lam3 app3 tt3 pair3 fst snd left right case zero suc rec => pair3 (t Tm3 var3 lam3 app3 tt3 pair3 fst snd left right case zero suc rec) (u Tm3 var3 lam3 app3 tt3 pair3 fst snd left right case zero suc rec) def fst3 : ∀ {Γ A B} , Tm3 Γ (prod3 A B) → Tm3 Γ A := λ t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd left right case zero suc rec => fst3 (t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd left right case zero suc rec) def snd3 : ∀ {Γ A B} , Tm3 Γ (prod3 A B) → Tm3 Γ B := λ t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left right case zero suc rec => snd3 (t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left right case zero suc rec) def left3 : ∀ {Γ A B} , Tm3 Γ A → Tm3 Γ (sum3 A B) := λ t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right case zero suc rec => left3 (t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right case zero suc rec) def right3 : ∀ {Γ A B} , Tm3 Γ B → Tm3 Γ (sum3 A B) := λ t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case zero suc rec => right3 (t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case zero suc rec) def case3 : ∀ {Γ A B C} , Tm3 Γ (sum3 A B) → Tm3 Γ (arr3 A C) → Tm3 Γ (arr3 B C) → Tm3 Γ C := λ t u v Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case3 zero suc rec => case3 (t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case3 zero suc rec) (u Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case3 zero suc rec) (v Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case3 zero suc rec) def zero3 : ∀ {Γ} , Tm3 Γ nat3 := λ Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case3 zero3 suc rec => zero3 def suc3 : ∀ {Γ} , Tm3 Γ nat3 → Tm3 Γ nat3 := λ t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case3 zero3 suc3 rec => suc3 (t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case3 zero3 suc3 rec) def rec3 : ∀ {Γ A} , Tm3 Γ nat3 → Tm3 Γ (arr3 nat3 (arr3 A A)) → Tm3 Γ A → Tm3 Γ A := λ t u v Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case3 zero3 suc3 rec3 => rec3 (t Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case3 zero3 suc3 rec3) (u Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case3 zero3 suc3 rec3) (v Tm3 var3 lam3 app3 tt3 pair3 fst3 snd3 left3 right3 case3 zero3 suc3 rec3) def v03 : ∀ {Γ A}, Tm3 (snoc3 Γ A) A := var3 vz3 def v13 : ∀ {Γ A B}, Tm3 (snoc3 (snoc3 Γ A) B) A := var3 (vs3 vz3) def v23 : ∀ {Γ A B C}, Tm3 (snoc3 (snoc3 (snoc3 Γ A) B) C) A := var3 (vs3 (vs3 vz3)) def v33 : ∀ {Γ A B C D}, Tm3 (snoc3 (snoc3 (snoc3 (snoc3 Γ A) B) C) D) A := var3 (vs3 (vs3 (vs3 vz3))) def tbool3 : Ty3 := sum3 top3 top3 def ttrue3 : ∀ {Γ}, Tm3 Γ tbool3 := left3 tt3 def tfalse3 : ∀ {Γ}, Tm3 Γ tbool3 := right3 tt3 def ifthenelse3 : ∀ {Γ A}, Tm3 Γ (arr3 tbool3 (arr3 A (arr3 A A))) := lam3 (lam3 (lam3 (case3 v23 (lam3 v23) (lam3 v13)))) def times43 : ∀ {Γ A}, Tm3 Γ (arr3 (arr3 A A) (arr3 A A)) := lam3 (lam3 (app3 v13 (app3 v13 (app3 v13 (app3 v13 v03))))) def add3 : ∀ {Γ}, Tm3 Γ (arr3 nat3 (arr3 nat3 nat3)) := lam3 (rec3 v03 (lam3 (lam3 (lam3 (suc3 (app3 v13 v03))))) (lam3 v03)) def mul3 : ∀ {Γ}, Tm3 Γ (arr3 nat3 (arr3 nat3 nat3)) := lam3 (rec3 v03 (lam3 (lam3 (lam3 (app3 (app3 add3 (app3 v13 v03)) v03)))) (lam3 zero3)) def fact3 : ∀ {Γ}, Tm3 Γ (arr3 nat3 nat3) := lam3 (rec3 v03 (lam3 (lam3 (app3 (app3 mul3 (suc3 v13)) v03))) (suc3 zero3)) def Ty4 : Type 1 := ∀ (Ty4 : Type) (nat top bot : Ty4) (arr prod sum : Ty4 → Ty4 → Ty4) , Ty4 def nat4 : Ty4 := λ _ nat4 _ _ _ _ _ => nat4 def top4 : Ty4 := λ _ _ top4 _ _ _ _ => top4 def bot4 : Ty4 := λ _ _ _ bot4 _ _ _ => bot4 def arr4 : Ty4 → Ty4 → Ty4 := λ A B Ty4 nat4 top4 bot4 arr4 prod sum => arr4 (A Ty4 nat4 top4 bot4 arr4 prod sum) (B Ty4 nat4 top4 bot4 arr4 prod sum) def prod4 : Ty4 → Ty4 → Ty4 := λ A B Ty4 nat4 top4 bot4 arr4 prod4 sum => prod4 (A Ty4 nat4 top4 bot4 arr4 prod4 sum) (B Ty4 nat4 top4 bot4 arr4 prod4 sum) def sum4 : Ty4 → Ty4 → Ty4 := λ A B Ty4 nat4 top4 bot4 arr4 prod4 sum4 => sum4 (A Ty4 nat4 top4 bot4 arr4 prod4 sum4) (B Ty4 nat4 top4 bot4 arr4 prod4 sum4) def Con4 : Type 1 := ∀ (Con4 : Type) (nil : Con4) (snoc : Con4 → Ty4 → Con4) , Con4 def nil4 : Con4 := λ Con4 nil4 snoc => nil4 def snoc4 : Con4 → Ty4 → Con4 := λ Γ A Con4 nil4 snoc4 => snoc4 (Γ Con4 nil4 snoc4) A def Var4 : Con4 → Ty4 → Type 1 := λ Γ A => ∀ (Var4 : Con4 → Ty4 → Type) (vz : ∀{Γ A}, Var4 (snoc4 Γ A) A) (vs : ∀{Γ B A}, Var4 Γ A → Var4 (snoc4 Γ B) A) , Var4 Γ A def vz4 : ∀ {Γ A}, Var4 (snoc4 Γ A) A := λ Var4 vz4 vs => vz4 def vs4 : ∀ {Γ B A}, Var4 Γ A → Var4 (snoc4 Γ B) A := λ x Var4 vz4 vs4 => vs4 (x Var4 vz4 vs4) def Tm4 : Con4 → Ty4 → Type 1 := λ Γ A => ∀ (Tm4 : Con4 → Ty4 → Type) (var : ∀ {Γ A}, Var4 Γ A → Tm4 Γ A) (lam : ∀ {Γ A B}, (Tm4 (snoc4 Γ A) B → Tm4 Γ (arr4 A B))) (app : ∀ {Γ A B} , Tm4 Γ (arr4 A B) → Tm4 Γ A → Tm4 Γ B) (tt : ∀ {Γ} , Tm4 Γ top4) (pair : ∀ {Γ A B} , Tm4 Γ A → Tm4 Γ B → Tm4 Γ (prod4 A B)) (fst : ∀ {Γ A B} , Tm4 Γ (prod4 A B) → Tm4 Γ A) (snd : ∀ {Γ A B} , Tm4 Γ (prod4 A B) → Tm4 Γ B) (left : ∀ {Γ A B} , Tm4 Γ A → Tm4 Γ (sum4 A B)) (right : ∀ {Γ A B} , Tm4 Γ B → Tm4 Γ (sum4 A B)) (case : ∀ {Γ A B C} , Tm4 Γ (sum4 A B) → Tm4 Γ (arr4 A C) → Tm4 Γ (arr4 B C) → Tm4 Γ C) (zero : ∀ {Γ} , Tm4 Γ nat4) (suc : ∀ {Γ} , Tm4 Γ nat4 → Tm4 Γ nat4) (rec : ∀ {Γ A} , Tm4 Γ nat4 → Tm4 Γ (arr4 nat4 (arr4 A A)) → Tm4 Γ A → Tm4 Γ A) , Tm4 Γ A def var4 : ∀ {Γ A}, Var4 Γ A → Tm4 Γ A := λ x Tm4 var4 lam app tt pair fst snd left right case zero suc rec => var4 x def lam4 : ∀ {Γ A B} , Tm4 (snoc4 Γ A) B → Tm4 Γ (arr4 A B) := λ t Tm4 var4 lam4 app tt pair fst snd left right case zero suc rec => lam4 (t Tm4 var4 lam4 app tt pair fst snd left right case zero suc rec) def app4 : ∀ {Γ A B} , Tm4 Γ (arr4 A B) → Tm4 Γ A → Tm4 Γ B := λ t u Tm4 var4 lam4 app4 tt pair fst snd left right case zero suc rec => app4 (t Tm4 var4 lam4 app4 tt pair fst snd left right case zero suc rec) (u Tm4 var4 lam4 app4 tt pair fst snd left right case zero suc rec) def tt4 : ∀ {Γ} , Tm4 Γ top4 := λ Tm4 var4 lam4 app4 tt4 pair fst snd left right case zero suc rec => tt4 def pair4 : ∀ {Γ A B} , Tm4 Γ A → Tm4 Γ B → Tm4 Γ (prod4 A B) := λ t u Tm4 var4 lam4 app4 tt4 pair4 fst snd left right case zero suc rec => pair4 (t Tm4 var4 lam4 app4 tt4 pair4 fst snd left right case zero suc rec) (u Tm4 var4 lam4 app4 tt4 pair4 fst snd left right case zero suc rec) def fst4 : ∀ {Γ A B} , Tm4 Γ (prod4 A B) → Tm4 Γ A := λ t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd left right case zero suc rec => fst4 (t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd left right case zero suc rec) def snd4 : ∀ {Γ A B} , Tm4 Γ (prod4 A B) → Tm4 Γ B := λ t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left right case zero suc rec => snd4 (t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left right case zero suc rec) def left4 : ∀ {Γ A B} , Tm4 Γ A → Tm4 Γ (sum4 A B) := λ t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right case zero suc rec => left4 (t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right case zero suc rec) def right4 : ∀ {Γ A B} , Tm4 Γ B → Tm4 Γ (sum4 A B) := λ t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case zero suc rec => right4 (t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case zero suc rec) def case4 : ∀ {Γ A B C} , Tm4 Γ (sum4 A B) → Tm4 Γ (arr4 A C) → Tm4 Γ (arr4 B C) → Tm4 Γ C := λ t u v Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case4 zero suc rec => case4 (t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case4 zero suc rec) (u Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case4 zero suc rec) (v Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case4 zero suc rec) def zero4 : ∀ {Γ} , Tm4 Γ nat4 := λ Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case4 zero4 suc rec => zero4 def suc4 : ∀ {Γ} , Tm4 Γ nat4 → Tm4 Γ nat4 := λ t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case4 zero4 suc4 rec => suc4 (t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case4 zero4 suc4 rec) def rec4 : ∀ {Γ A} , Tm4 Γ nat4 → Tm4 Γ (arr4 nat4 (arr4 A A)) → Tm4 Γ A → Tm4 Γ A := λ t u v Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case4 zero4 suc4 rec4 => rec4 (t Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case4 zero4 suc4 rec4) (u Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case4 zero4 suc4 rec4) (v Tm4 var4 lam4 app4 tt4 pair4 fst4 snd4 left4 right4 case4 zero4 suc4 rec4) def v04 : ∀ {Γ A}, Tm4 (snoc4 Γ A) A := var4 vz4 def v14 : ∀ {Γ A B}, Tm4 (snoc4 (snoc4 Γ A) B) A := var4 (vs4 vz4) def v24 : ∀ {Γ A B C}, Tm4 (snoc4 (snoc4 (snoc4 Γ A) B) C) A := var4 (vs4 (vs4 vz4)) def v34 : ∀ {Γ A B C D}, Tm4 (snoc4 (snoc4 (snoc4 (snoc4 Γ A) B) C) D) A := var4 (vs4 (vs4 (vs4 vz4))) def tbool4 : Ty4 := sum4 top4 top4 def ttrue4 : ∀ {Γ}, Tm4 Γ tbool4 := left4 tt4 def tfalse4 : ∀ {Γ}, Tm4 Γ tbool4 := right4 tt4 def ifthenelse4 : ∀ {Γ A}, Tm4 Γ (arr4 tbool4 (arr4 A (arr4 A A))) := lam4 (lam4 (lam4 (case4 v24 (lam4 v24) (lam4 v14)))) def times44 : ∀ {Γ A}, Tm4 Γ (arr4 (arr4 A A) (arr4 A A)) := lam4 (lam4 (app4 v14 (app4 v14 (app4 v14 (app4 v14 v04))))) def add4 : ∀ {Γ}, Tm4 Γ (arr4 nat4 (arr4 nat4 nat4)) := lam4 (rec4 v04 (lam4 (lam4 (lam4 (suc4 (app4 v14 v04))))) (lam4 v04)) def mul4 : ∀ {Γ}, Tm4 Γ (arr4 nat4 (arr4 nat4 nat4)) := lam4 (rec4 v04 (lam4 (lam4 (lam4 (app4 (app4 add4 (app4 v14 v04)) v04)))) (lam4 zero4)) def fact4 : ∀ {Γ}, Tm4 Γ (arr4 nat4 nat4) := lam4 (rec4 v04 (lam4 (lam4 (app4 (app4 mul4 (suc4 v14)) v04))) (suc4 zero4)) def Ty5 : Type 1 := ∀ (Ty5 : Type) (nat top bot : Ty5) (arr prod sum : Ty5 → Ty5 → Ty5) , Ty5 def nat5 : Ty5 := λ _ nat5 _ _ _ _ _ => nat5 def top5 : Ty5 := λ _ _ top5 _ _ _ _ => top5 def bot5 : Ty5 := λ _ _ _ bot5 _ _ _ => bot5 def arr5 : Ty5 → Ty5 → Ty5 := λ A B Ty5 nat5 top5 bot5 arr5 prod sum => arr5 (A Ty5 nat5 top5 bot5 arr5 prod sum) (B Ty5 nat5 top5 bot5 arr5 prod sum) def prod5 : Ty5 → Ty5 → Ty5 := λ A B Ty5 nat5 top5 bot5 arr5 prod5 sum => prod5 (A Ty5 nat5 top5 bot5 arr5 prod5 sum) (B Ty5 nat5 top5 bot5 arr5 prod5 sum) def sum5 : Ty5 → Ty5 → Ty5 := λ A B Ty5 nat5 top5 bot5 arr5 prod5 sum5 => sum5 (A Ty5 nat5 top5 bot5 arr5 prod5 sum5) (B Ty5 nat5 top5 bot5 arr5 prod5 sum5) def Con5 : Type 1 := ∀ (Con5 : Type) (nil : Con5) (snoc : Con5 → Ty5 → Con5) , Con5 def nil5 : Con5 := λ Con5 nil5 snoc => nil5 def snoc5 : Con5 → Ty5 → Con5 := λ Γ A Con5 nil5 snoc5 => snoc5 (Γ Con5 nil5 snoc5) A def Var5 : Con5 → Ty5 → Type 1 := λ Γ A => ∀ (Var5 : Con5 → Ty5 → Type) (vz : ∀{Γ A}, Var5 (snoc5 Γ A) A) (vs : ∀{Γ B A}, Var5 Γ A → Var5 (snoc5 Γ B) A) , Var5 Γ A def vz5 : ∀ {Γ A}, Var5 (snoc5 Γ A) A := λ Var5 vz5 vs => vz5 def vs5 : ∀ {Γ B A}, Var5 Γ A → Var5 (snoc5 Γ B) A := λ x Var5 vz5 vs5 => vs5 (x Var5 vz5 vs5) def Tm5 : Con5 → Ty5 → Type 1 := λ Γ A => ∀ (Tm5 : Con5 → Ty5 → Type) (var : ∀ {Γ A}, Var5 Γ A → Tm5 Γ A) (lam : ∀ {Γ A B}, (Tm5 (snoc5 Γ A) B → Tm5 Γ (arr5 A B))) (app : ∀ {Γ A B} , Tm5 Γ (arr5 A B) → Tm5 Γ A → Tm5 Γ B) (tt : ∀ {Γ} , Tm5 Γ top5) (pair : ∀ {Γ A B} , Tm5 Γ A → Tm5 Γ B → Tm5 Γ (prod5 A B)) (fst : ∀ {Γ A B} , Tm5 Γ (prod5 A B) → Tm5 Γ A) (snd : ∀ {Γ A B} , Tm5 Γ (prod5 A B) → Tm5 Γ B) (left : ∀ {Γ A B} , Tm5 Γ A → Tm5 Γ (sum5 A B)) (right : ∀ {Γ A B} , Tm5 Γ B → Tm5 Γ (sum5 A B)) (case : ∀ {Γ A B C} , Tm5 Γ (sum5 A B) → Tm5 Γ (arr5 A C) → Tm5 Γ (arr5 B C) → Tm5 Γ C) (zero : ∀ {Γ} , Tm5 Γ nat5) (suc : ∀ {Γ} , Tm5 Γ nat5 → Tm5 Γ nat5) (rec : ∀ {Γ A} , Tm5 Γ nat5 → Tm5 Γ (arr5 nat5 (arr5 A A)) → Tm5 Γ A → Tm5 Γ A) , Tm5 Γ A def var5 : ∀ {Γ A}, Var5 Γ A → Tm5 Γ A := λ x Tm5 var5 lam app tt pair fst snd left right case zero suc rec => var5 x def lam5 : ∀ {Γ A B} , Tm5 (snoc5 Γ A) B → Tm5 Γ (arr5 A B) := λ t Tm5 var5 lam5 app tt pair fst snd left right case zero suc rec => lam5 (t Tm5 var5 lam5 app tt pair fst snd left right case zero suc rec) def app5 : ∀ {Γ A B} , Tm5 Γ (arr5 A B) → Tm5 Γ A → Tm5 Γ B := λ t u Tm5 var5 lam5 app5 tt pair fst snd left right case zero suc rec => app5 (t Tm5 var5 lam5 app5 tt pair fst snd left right case zero suc rec) (u Tm5 var5 lam5 app5 tt pair fst snd left right case zero suc rec) def tt5 : ∀ {Γ} , Tm5 Γ top5 := λ Tm5 var5 lam5 app5 tt5 pair fst snd left right case zero suc rec => tt5 def pair5 : ∀ {Γ A B} , Tm5 Γ A → Tm5 Γ B → Tm5 Γ (prod5 A B) := λ t u Tm5 var5 lam5 app5 tt5 pair5 fst snd left right case zero suc rec => pair5 (t Tm5 var5 lam5 app5 tt5 pair5 fst snd left right case zero suc rec) (u Tm5 var5 lam5 app5 tt5 pair5 fst snd left right case zero suc rec) def fst5 : ∀ {Γ A B} , Tm5 Γ (prod5 A B) → Tm5 Γ A := λ t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd left right case zero suc rec => fst5 (t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd left right case zero suc rec) def snd5 : ∀ {Γ A B} , Tm5 Γ (prod5 A B) → Tm5 Γ B := λ t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left right case zero suc rec => snd5 (t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left right case zero suc rec) def left5 : ∀ {Γ A B} , Tm5 Γ A → Tm5 Γ (sum5 A B) := λ t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right case zero suc rec => left5 (t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right case zero suc rec) def right5 : ∀ {Γ A B} , Tm5 Γ B → Tm5 Γ (sum5 A B) := λ t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case zero suc rec => right5 (t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case zero suc rec) def case5 : ∀ {Γ A B C} , Tm5 Γ (sum5 A B) → Tm5 Γ (arr5 A C) → Tm5 Γ (arr5 B C) → Tm5 Γ C := λ t u v Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case5 zero suc rec => case5 (t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case5 zero suc rec) (u Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case5 zero suc rec) (v Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case5 zero suc rec) def zero5 : ∀ {Γ} , Tm5 Γ nat5 := λ Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case5 zero5 suc rec => zero5 def suc5 : ∀ {Γ} , Tm5 Γ nat5 → Tm5 Γ nat5 := λ t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case5 zero5 suc5 rec => suc5 (t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case5 zero5 suc5 rec) def rec5 : ∀ {Γ A} , Tm5 Γ nat5 → Tm5 Γ (arr5 nat5 (arr5 A A)) → Tm5 Γ A → Tm5 Γ A := λ t u v Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case5 zero5 suc5 rec5 => rec5 (t Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case5 zero5 suc5 rec5) (u Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case5 zero5 suc5 rec5) (v Tm5 var5 lam5 app5 tt5 pair5 fst5 snd5 left5 right5 case5 zero5 suc5 rec5) def v05 : ∀ {Γ A}, Tm5 (snoc5 Γ A) A := var5 vz5 def v15 : ∀ {Γ A B}, Tm5 (snoc5 (snoc5 Γ A) B) A := var5 (vs5 vz5) def v25 : ∀ {Γ A B C}, Tm5 (snoc5 (snoc5 (snoc5 Γ A) B) C) A := var5 (vs5 (vs5 vz5)) def v35 : ∀ {Γ A B C D}, Tm5 (snoc5 (snoc5 (snoc5 (snoc5 Γ A) B) C) D) A := var5 (vs5 (vs5 (vs5 vz5))) def tbool5 : Ty5 := sum5 top5 top5 def ttrue5 : ∀ {Γ}, Tm5 Γ tbool5 := left5 tt5 def tfalse5 : ∀ {Γ}, Tm5 Γ tbool5 := right5 tt5 def ifthenelse5 : ∀ {Γ A}, Tm5 Γ (arr5 tbool5 (arr5 A (arr5 A A))) := lam5 (lam5 (lam5 (case5 v25 (lam5 v25) (lam5 v15)))) def times45 : ∀ {Γ A}, Tm5 Γ (arr5 (arr5 A A) (arr5 A A)) := lam5 (lam5 (app5 v15 (app5 v15 (app5 v15 (app5 v15 v05))))) def add5 : ∀ {Γ}, Tm5 Γ (arr5 nat5 (arr5 nat5 nat5)) := lam5 (rec5 v05 (lam5 (lam5 (lam5 (suc5 (app5 v15 v05))))) (lam5 v05)) def mul5 : ∀ {Γ}, Tm5 Γ (arr5 nat5 (arr5 nat5 nat5)) := lam5 (rec5 v05 (lam5 (lam5 (lam5 (app5 (app5 add5 (app5 v15 v05)) v05)))) (lam5 zero5)) def fact5 : ∀ {Γ}, Tm5 Γ (arr5 nat5 nat5) := lam5 (rec5 v05 (lam5 (lam5 (app5 (app5 mul5 (suc5 v15)) v05))) (suc5 zero5)) def Ty6 : Type 1 := ∀ (Ty6 : Type) (nat top bot : Ty6) (arr prod sum : Ty6 → Ty6 → Ty6) , Ty6 def nat6 : Ty6 := λ _ nat6 _ _ _ _ _ => nat6 def top6 : Ty6 := λ _ _ top6 _ _ _ _ => top6 def bot6 : Ty6 := λ _ _ _ bot6 _ _ _ => bot6 def arr6 : Ty6 → Ty6 → Ty6 := λ A B Ty6 nat6 top6 bot6 arr6 prod sum => arr6 (A Ty6 nat6 top6 bot6 arr6 prod sum) (B Ty6 nat6 top6 bot6 arr6 prod sum) def prod6 : Ty6 → Ty6 → Ty6 := λ A B Ty6 nat6 top6 bot6 arr6 prod6 sum => prod6 (A Ty6 nat6 top6 bot6 arr6 prod6 sum) (B Ty6 nat6 top6 bot6 arr6 prod6 sum) def sum6 : Ty6 → Ty6 → Ty6 := λ A B Ty6 nat6 top6 bot6 arr6 prod6 sum6 => sum6 (A Ty6 nat6 top6 bot6 arr6 prod6 sum6) (B Ty6 nat6 top6 bot6 arr6 prod6 sum6) def Con6 : Type 1 := ∀ (Con6 : Type) (nil : Con6) (snoc : Con6 → Ty6 → Con6) , Con6 def nil6 : Con6 := λ Con6 nil6 snoc => nil6 def snoc6 : Con6 → Ty6 → Con6 := λ Γ A Con6 nil6 snoc6 => snoc6 (Γ Con6 nil6 snoc6) A def Var6 : Con6 → Ty6 → Type 1 := λ Γ A => ∀ (Var6 : Con6 → Ty6 → Type) (vz : ∀{Γ A}, Var6 (snoc6 Γ A) A) (vs : ∀{Γ B A}, Var6 Γ A → Var6 (snoc6 Γ B) A) , Var6 Γ A def vz6 : ∀ {Γ A}, Var6 (snoc6 Γ A) A := λ Var6 vz6 vs => vz6 def vs6 : ∀ {Γ B A}, Var6 Γ A → Var6 (snoc6 Γ B) A := λ x Var6 vz6 vs6 => vs6 (x Var6 vz6 vs6) def Tm6 : Con6 → Ty6 → Type 1 := λ Γ A => ∀ (Tm6 : Con6 → Ty6 → Type) (var : ∀ {Γ A}, Var6 Γ A → Tm6 Γ A) (lam : ∀ {Γ A B}, (Tm6 (snoc6 Γ A) B → Tm6 Γ (arr6 A B))) (app : ∀ {Γ A B} , Tm6 Γ (arr6 A B) → Tm6 Γ A → Tm6 Γ B) (tt : ∀ {Γ} , Tm6 Γ top6) (pair : ∀ {Γ A B} , Tm6 Γ A → Tm6 Γ B → Tm6 Γ (prod6 A B)) (fst : ∀ {Γ A B} , Tm6 Γ (prod6 A B) → Tm6 Γ A) (snd : ∀ {Γ A B} , Tm6 Γ (prod6 A B) → Tm6 Γ B) (left : ∀ {Γ A B} , Tm6 Γ A → Tm6 Γ (sum6 A B)) (right : ∀ {Γ A B} , Tm6 Γ B → Tm6 Γ (sum6 A B)) (case : ∀ {Γ A B C} , Tm6 Γ (sum6 A B) → Tm6 Γ (arr6 A C) → Tm6 Γ (arr6 B C) → Tm6 Γ C) (zero : ∀ {Γ} , Tm6 Γ nat6) (suc : ∀ {Γ} , Tm6 Γ nat6 → Tm6 Γ nat6) (rec : ∀ {Γ A} , Tm6 Γ nat6 → Tm6 Γ (arr6 nat6 (arr6 A A)) → Tm6 Γ A → Tm6 Γ A) , Tm6 Γ A def var6 : ∀ {Γ A}, Var6 Γ A → Tm6 Γ A := λ x Tm6 var6 lam app tt pair fst snd left right case zero suc rec => var6 x def lam6 : ∀ {Γ A B} , Tm6 (snoc6 Γ A) B → Tm6 Γ (arr6 A B) := λ t Tm6 var6 lam6 app tt pair fst snd left right case zero suc rec => lam6 (t Tm6 var6 lam6 app tt pair fst snd left right case zero suc rec) def app6 : ∀ {Γ A B} , Tm6 Γ (arr6 A B) → Tm6 Γ A → Tm6 Γ B := λ t u Tm6 var6 lam6 app6 tt pair fst snd left right case zero suc rec => app6 (t Tm6 var6 lam6 app6 tt pair fst snd left right case zero suc rec) (u Tm6 var6 lam6 app6 tt pair fst snd left right case zero suc rec) def tt6 : ∀ {Γ} , Tm6 Γ top6 := λ Tm6 var6 lam6 app6 tt6 pair fst snd left right case zero suc rec => tt6 def pair6 : ∀ {Γ A B} , Tm6 Γ A → Tm6 Γ B → Tm6 Γ (prod6 A B) := λ t u Tm6 var6 lam6 app6 tt6 pair6 fst snd left right case zero suc rec => pair6 (t Tm6 var6 lam6 app6 tt6 pair6 fst snd left right case zero suc rec) (u Tm6 var6 lam6 app6 tt6 pair6 fst snd left right case zero suc rec) def fst6 : ∀ {Γ A B} , Tm6 Γ (prod6 A B) → Tm6 Γ A := λ t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd left right case zero suc rec => fst6 (t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd left right case zero suc rec) def snd6 : ∀ {Γ A B} , Tm6 Γ (prod6 A B) → Tm6 Γ B := λ t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left right case zero suc rec => snd6 (t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left right case zero suc rec) def left6 : ∀ {Γ A B} , Tm6 Γ A → Tm6 Γ (sum6 A B) := λ t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right case zero suc rec => left6 (t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right case zero suc rec) def right6 : ∀ {Γ A B} , Tm6 Γ B → Tm6 Γ (sum6 A B) := λ t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case zero suc rec => right6 (t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case zero suc rec) def case6 : ∀ {Γ A B C} , Tm6 Γ (sum6 A B) → Tm6 Γ (arr6 A C) → Tm6 Γ (arr6 B C) → Tm6 Γ C := λ t u v Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case6 zero suc rec => case6 (t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case6 zero suc rec) (u Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case6 zero suc rec) (v Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case6 zero suc rec) def zero6 : ∀ {Γ} , Tm6 Γ nat6 := λ Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case6 zero6 suc rec => zero6 def suc6 : ∀ {Γ} , Tm6 Γ nat6 → Tm6 Γ nat6 := λ t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case6 zero6 suc6 rec => suc6 (t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case6 zero6 suc6 rec) def rec6 : ∀ {Γ A} , Tm6 Γ nat6 → Tm6 Γ (arr6 nat6 (arr6 A A)) → Tm6 Γ A → Tm6 Γ A := λ t u v Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case6 zero6 suc6 rec6 => rec6 (t Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case6 zero6 suc6 rec6) (u Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case6 zero6 suc6 rec6) (v Tm6 var6 lam6 app6 tt6 pair6 fst6 snd6 left6 right6 case6 zero6 suc6 rec6) def v06 : ∀ {Γ A}, Tm6 (snoc6 Γ A) A := var6 vz6 def v16 : ∀ {Γ A B}, Tm6 (snoc6 (snoc6 Γ A) B) A := var6 (vs6 vz6) def v26 : ∀ {Γ A B C}, Tm6 (snoc6 (snoc6 (snoc6 Γ A) B) C) A := var6 (vs6 (vs6 vz6)) def v36 : ∀ {Γ A B C D}, Tm6 (snoc6 (snoc6 (snoc6 (snoc6 Γ A) B) C) D) A := var6 (vs6 (vs6 (vs6 vz6))) def tbool6 : Ty6 := sum6 top6 top6 def ttrue6 : ∀ {Γ}, Tm6 Γ tbool6 := left6 tt6 def tfalse6 : ∀ {Γ}, Tm6 Γ tbool6 := right6 tt6 def ifthenelse6 : ∀ {Γ A}, Tm6 Γ (arr6 tbool6 (arr6 A (arr6 A A))) := lam6 (lam6 (lam6 (case6 v26 (lam6 v26) (lam6 v16)))) def times46 : ∀ {Γ A}, Tm6 Γ (arr6 (arr6 A A) (arr6 A A)) := lam6 (lam6 (app6 v16 (app6 v16 (app6 v16 (app6 v16 v06))))) def add6 : ∀ {Γ}, Tm6 Γ (arr6 nat6 (arr6 nat6 nat6)) := lam6 (rec6 v06 (lam6 (lam6 (lam6 (suc6 (app6 v16 v06))))) (lam6 v06)) def mul6 : ∀ {Γ}, Tm6 Γ (arr6 nat6 (arr6 nat6 nat6)) := lam6 (rec6 v06 (lam6 (lam6 (lam6 (app6 (app6 add6 (app6 v16 v06)) v06)))) (lam6 zero6)) def fact6 : ∀ {Γ}, Tm6 Γ (arr6 nat6 nat6) := lam6 (rec6 v06 (lam6 (lam6 (app6 (app6 mul6 (suc6 v16)) v06))) (suc6 zero6)) def Ty7 : Type 1 := ∀ (Ty7 : Type) (nat top bot : Ty7) (arr prod sum : Ty7 → Ty7 → Ty7) , Ty7 def nat7 : Ty7 := λ _ nat7 _ _ _ _ _ => nat7 def top7 : Ty7 := λ _ _ top7 _ _ _ _ => top7 def bot7 : Ty7 := λ _ _ _ bot7 _ _ _ => bot7 def arr7 : Ty7 → Ty7 → Ty7 := λ A B Ty7 nat7 top7 bot7 arr7 prod sum => arr7 (A Ty7 nat7 top7 bot7 arr7 prod sum) (B Ty7 nat7 top7 bot7 arr7 prod sum) def prod7 : Ty7 → Ty7 → Ty7 := λ A B Ty7 nat7 top7 bot7 arr7 prod7 sum => prod7 (A Ty7 nat7 top7 bot7 arr7 prod7 sum) (B Ty7 nat7 top7 bot7 arr7 prod7 sum) def sum7 : Ty7 → Ty7 → Ty7 := λ A B Ty7 nat7 top7 bot7 arr7 prod7 sum7 => sum7 (A Ty7 nat7 top7 bot7 arr7 prod7 sum7) (B Ty7 nat7 top7 bot7 arr7 prod7 sum7) def Con7 : Type 1 := ∀ (Con7 : Type) (nil : Con7) (snoc : Con7 → Ty7 → Con7) , Con7 def nil7 : Con7 := λ Con7 nil7 snoc => nil7 def snoc7 : Con7 → Ty7 → Con7 := λ Γ A Con7 nil7 snoc7 => snoc7 (Γ Con7 nil7 snoc7) A def Var7 : Con7 → Ty7 → Type 1 := λ Γ A => ∀ (Var7 : Con7 → Ty7 → Type) (vz : ∀{Γ A}, Var7 (snoc7 Γ A) A) (vs : ∀{Γ B A}, Var7 Γ A → Var7 (snoc7 Γ B) A) , Var7 Γ A def vz7 : ∀ {Γ A}, Var7 (snoc7 Γ A) A := λ Var7 vz7 vs => vz7 def vs7 : ∀ {Γ B A}, Var7 Γ A → Var7 (snoc7 Γ B) A := λ x Var7 vz7 vs7 => vs7 (x Var7 vz7 vs7) def Tm7 : Con7 → Ty7 → Type 1 := λ Γ A => ∀ (Tm7 : Con7 → Ty7 → Type) (var : ∀ {Γ A}, Var7 Γ A → Tm7 Γ A) (lam : ∀ {Γ A B}, (Tm7 (snoc7 Γ A) B → Tm7 Γ (arr7 A B))) (app : ∀ {Γ A B} , Tm7 Γ (arr7 A B) → Tm7 Γ A → Tm7 Γ B) (tt : ∀ {Γ} , Tm7 Γ top7) (pair : ∀ {Γ A B} , Tm7 Γ A → Tm7 Γ B → Tm7 Γ (prod7 A B)) (fst : ∀ {Γ A B} , Tm7 Γ (prod7 A B) → Tm7 Γ A) (snd : ∀ {Γ A B} , Tm7 Γ (prod7 A B) → Tm7 Γ B) (left : ∀ {Γ A B} , Tm7 Γ A → Tm7 Γ (sum7 A B)) (right : ∀ {Γ A B} , Tm7 Γ B → Tm7 Γ (sum7 A B)) (case : ∀ {Γ A B C} , Tm7 Γ (sum7 A B) → Tm7 Γ (arr7 A C) → Tm7 Γ (arr7 B C) → Tm7 Γ C) (zero : ∀ {Γ} , Tm7 Γ nat7) (suc : ∀ {Γ} , Tm7 Γ nat7 → Tm7 Γ nat7) (rec : ∀ {Γ A} , Tm7 Γ nat7 → Tm7 Γ (arr7 nat7 (arr7 A A)) → Tm7 Γ A → Tm7 Γ A) , Tm7 Γ A def var7 : ∀ {Γ A}, Var7 Γ A → Tm7 Γ A := λ x Tm7 var7 lam app tt pair fst snd left right case zero suc rec => var7 x def lam7 : ∀ {Γ A B} , Tm7 (snoc7 Γ A) B → Tm7 Γ (arr7 A B) := λ t Tm7 var7 lam7 app tt pair fst snd left right case zero suc rec => lam7 (t Tm7 var7 lam7 app tt pair fst snd left right case zero suc rec) def app7 : ∀ {Γ A B} , Tm7 Γ (arr7 A B) → Tm7 Γ A → Tm7 Γ B := λ t u Tm7 var7 lam7 app7 tt pair fst snd left right case zero suc rec => app7 (t Tm7 var7 lam7 app7 tt pair fst snd left right case zero suc rec) (u Tm7 var7 lam7 app7 tt pair fst snd left right case zero suc rec) def tt7 : ∀ {Γ} , Tm7 Γ top7 := λ Tm7 var7 lam7 app7 tt7 pair fst snd left right case zero suc rec => tt7 def pair7 : ∀ {Γ A B} , Tm7 Γ A → Tm7 Γ B → Tm7 Γ (prod7 A B) := λ t u Tm7 var7 lam7 app7 tt7 pair7 fst snd left right case zero suc rec => pair7 (t Tm7 var7 lam7 app7 tt7 pair7 fst snd left right case zero suc rec) (u Tm7 var7 lam7 app7 tt7 pair7 fst snd left right case zero suc rec) def fst7 : ∀ {Γ A B} , Tm7 Γ (prod7 A B) → Tm7 Γ A := λ t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd left right case zero suc rec => fst7 (t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd left right case zero suc rec) def snd7 : ∀ {Γ A B} , Tm7 Γ (prod7 A B) → Tm7 Γ B := λ t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left right case zero suc rec => snd7 (t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left right case zero suc rec) def left7 : ∀ {Γ A B} , Tm7 Γ A → Tm7 Γ (sum7 A B) := λ t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right case zero suc rec => left7 (t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right case zero suc rec) def right7 : ∀ {Γ A B} , Tm7 Γ B → Tm7 Γ (sum7 A B) := λ t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case zero suc rec => right7 (t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case zero suc rec) def case7 : ∀ {Γ A B C} , Tm7 Γ (sum7 A B) → Tm7 Γ (arr7 A C) → Tm7 Γ (arr7 B C) → Tm7 Γ C := λ t u v Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case7 zero suc rec => case7 (t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case7 zero suc rec) (u Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case7 zero suc rec) (v Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case7 zero suc rec) def zero7 : ∀ {Γ} , Tm7 Γ nat7 := λ Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case7 zero7 suc rec => zero7 def suc7 : ∀ {Γ} , Tm7 Γ nat7 → Tm7 Γ nat7 := λ t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case7 zero7 suc7 rec => suc7 (t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case7 zero7 suc7 rec) def rec7 : ∀ {Γ A} , Tm7 Γ nat7 → Tm7 Γ (arr7 nat7 (arr7 A A)) → Tm7 Γ A → Tm7 Γ A := λ t u v Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case7 zero7 suc7 rec7 => rec7 (t Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case7 zero7 suc7 rec7) (u Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case7 zero7 suc7 rec7) (v Tm7 var7 lam7 app7 tt7 pair7 fst7 snd7 left7 right7 case7 zero7 suc7 rec7) def v07 : ∀ {Γ A}, Tm7 (snoc7 Γ A) A := var7 vz7 def v17 : ∀ {Γ A B}, Tm7 (snoc7 (snoc7 Γ A) B) A := var7 (vs7 vz7) def v27 : ∀ {Γ A B C}, Tm7 (snoc7 (snoc7 (snoc7 Γ A) B) C) A := var7 (vs7 (vs7 vz7)) def v37 : ∀ {Γ A B C D}, Tm7 (snoc7 (snoc7 (snoc7 (snoc7 Γ A) B) C) D) A := var7 (vs7 (vs7 (vs7 vz7))) def tbool7 : Ty7 := sum7 top7 top7 def ttrue7 : ∀ {Γ}, Tm7 Γ tbool7 := left7 tt7 def tfalse7 : ∀ {Γ}, Tm7 Γ tbool7 := right7 tt7 def ifthenelse7 : ∀ {Γ A}, Tm7 Γ (arr7 tbool7 (arr7 A (arr7 A A))) := lam7 (lam7 (lam7 (case7 v27 (lam7 v27) (lam7 v17)))) def times47 : ∀ {Γ A}, Tm7 Γ (arr7 (arr7 A A) (arr7 A A)) := lam7 (lam7 (app7 v17 (app7 v17 (app7 v17 (app7 v17 v07))))) def add7 : ∀ {Γ}, Tm7 Γ (arr7 nat7 (arr7 nat7 nat7)) := lam7 (rec7 v07 (lam7 (lam7 (lam7 (suc7 (app7 v17 v07))))) (lam7 v07)) def mul7 : ∀ {Γ}, Tm7 Γ (arr7 nat7 (arr7 nat7 nat7)) := lam7 (rec7 v07 (lam7 (lam7 (lam7 (app7 (app7 add7 (app7 v17 v07)) v07)))) (lam7 zero7)) def fact7 : ∀ {Γ}, Tm7 Γ (arr7 nat7 nat7) := lam7 (rec7 v07 (lam7 (lam7 (app7 (app7 mul7 (suc7 v17)) v07))) (suc7 zero7)) def Ty8 : Type 1 := ∀ (Ty8 : Type) (nat top bot : Ty8) (arr prod sum : Ty8 → Ty8 → Ty8) , Ty8 def nat8 : Ty8 := λ _ nat8 _ _ _ _ _ => nat8 def top8 : Ty8 := λ _ _ top8 _ _ _ _ => top8 def bot8 : Ty8 := λ _ _ _ bot8 _ _ _ => bot8 def arr8 : Ty8 → Ty8 → Ty8 := λ A B Ty8 nat8 top8 bot8 arr8 prod sum => arr8 (A Ty8 nat8 top8 bot8 arr8 prod sum) (B Ty8 nat8 top8 bot8 arr8 prod sum) def prod8 : Ty8 → Ty8 → Ty8 := λ A B Ty8 nat8 top8 bot8 arr8 prod8 sum => prod8 (A Ty8 nat8 top8 bot8 arr8 prod8 sum) (B Ty8 nat8 top8 bot8 arr8 prod8 sum) def sum8 : Ty8 → Ty8 → Ty8 := λ A B Ty8 nat8 top8 bot8 arr8 prod8 sum8 => sum8 (A Ty8 nat8 top8 bot8 arr8 prod8 sum8) (B Ty8 nat8 top8 bot8 arr8 prod8 sum8) def Con8 : Type 1 := ∀ (Con8 : Type) (nil : Con8) (snoc : Con8 → Ty8 → Con8) , Con8 def nil8 : Con8 := λ Con8 nil8 snoc => nil8 def snoc8 : Con8 → Ty8 → Con8 := λ Γ A Con8 nil8 snoc8 => snoc8 (Γ Con8 nil8 snoc8) A def Var8 : Con8 → Ty8 → Type 1 := λ Γ A => ∀ (Var8 : Con8 → Ty8 → Type) (vz : ∀{Γ A}, Var8 (snoc8 Γ A) A) (vs : ∀{Γ B A}, Var8 Γ A → Var8 (snoc8 Γ B) A) , Var8 Γ A def vz8 : ∀ {Γ A}, Var8 (snoc8 Γ A) A := λ Var8 vz8 vs => vz8 def vs8 : ∀ {Γ B A}, Var8 Γ A → Var8 (snoc8 Γ B) A := λ x Var8 vz8 vs8 => vs8 (x Var8 vz8 vs8) def Tm8 : Con8 → Ty8 → Type 1 := λ Γ A => ∀ (Tm8 : Con8 → Ty8 → Type) (var : ∀ {Γ A}, Var8 Γ A → Tm8 Γ A) (lam : ∀ {Γ A B}, (Tm8 (snoc8 Γ A) B → Tm8 Γ (arr8 A B))) (app : ∀ {Γ A B} , Tm8 Γ (arr8 A B) → Tm8 Γ A → Tm8 Γ B) (tt : ∀ {Γ} , Tm8 Γ top8) (pair : ∀ {Γ A B} , Tm8 Γ A → Tm8 Γ B → Tm8 Γ (prod8 A B)) (fst : ∀ {Γ A B} , Tm8 Γ (prod8 A B) → Tm8 Γ A) (snd : ∀ {Γ A B} , Tm8 Γ (prod8 A B) → Tm8 Γ B) (left : ∀ {Γ A B} , Tm8 Γ A → Tm8 Γ (sum8 A B)) (right : ∀ {Γ A B} , Tm8 Γ B → Tm8 Γ (sum8 A B)) (case : ∀ {Γ A B C} , Tm8 Γ (sum8 A B) → Tm8 Γ (arr8 A C) → Tm8 Γ (arr8 B C) → Tm8 Γ C) (zero : ∀ {Γ} , Tm8 Γ nat8) (suc : ∀ {Γ} , Tm8 Γ nat8 → Tm8 Γ nat8) (rec : ∀ {Γ A} , Tm8 Γ nat8 → Tm8 Γ (arr8 nat8 (arr8 A A)) → Tm8 Γ A → Tm8 Γ A) , Tm8 Γ A def var8 : ∀ {Γ A}, Var8 Γ A → Tm8 Γ A := λ x Tm8 var8 lam app tt pair fst snd left right case zero suc rec => var8 x def lam8 : ∀ {Γ A B} , Tm8 (snoc8 Γ A) B → Tm8 Γ (arr8 A B) := λ t Tm8 var8 lam8 app tt pair fst snd left right case zero suc rec => lam8 (t Tm8 var8 lam8 app tt pair fst snd left right case zero suc rec) def app8 : ∀ {Γ A B} , Tm8 Γ (arr8 A B) → Tm8 Γ A → Tm8 Γ B := λ t u Tm8 var8 lam8 app8 tt pair fst snd left right case zero suc rec => app8 (t Tm8 var8 lam8 app8 tt pair fst snd left right case zero suc rec) (u Tm8 var8 lam8 app8 tt pair fst snd left right case zero suc rec) def tt8 : ∀ {Γ} , Tm8 Γ top8 := λ Tm8 var8 lam8 app8 tt8 pair fst snd left right case zero suc rec => tt8 def pair8 : ∀ {Γ A B} , Tm8 Γ A → Tm8 Γ B → Tm8 Γ (prod8 A B) := λ t u Tm8 var8 lam8 app8 tt8 pair8 fst snd left right case zero suc rec => pair8 (t Tm8 var8 lam8 app8 tt8 pair8 fst snd left right case zero suc rec) (u Tm8 var8 lam8 app8 tt8 pair8 fst snd left right case zero suc rec) def fst8 : ∀ {Γ A B} , Tm8 Γ (prod8 A B) → Tm8 Γ A := λ t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd left right case zero suc rec => fst8 (t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd left right case zero suc rec) def snd8 : ∀ {Γ A B} , Tm8 Γ (prod8 A B) → Tm8 Γ B := λ t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left right case zero suc rec => snd8 (t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left right case zero suc rec) def left8 : ∀ {Γ A B} , Tm8 Γ A → Tm8 Γ (sum8 A B) := λ t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right case zero suc rec => left8 (t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right case zero suc rec) def right8 : ∀ {Γ A B} , Tm8 Γ B → Tm8 Γ (sum8 A B) := λ t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case zero suc rec => right8 (t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case zero suc rec) def case8 : ∀ {Γ A B C} , Tm8 Γ (sum8 A B) → Tm8 Γ (arr8 A C) → Tm8 Γ (arr8 B C) → Tm8 Γ C := λ t u v Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case8 zero suc rec => case8 (t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case8 zero suc rec) (u Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case8 zero suc rec) (v Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case8 zero suc rec) def zero8 : ∀ {Γ} , Tm8 Γ nat8 := λ Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case8 zero8 suc rec => zero8 def suc8 : ∀ {Γ} , Tm8 Γ nat8 → Tm8 Γ nat8 := λ t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case8 zero8 suc8 rec => suc8 (t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case8 zero8 suc8 rec) def rec8 : ∀ {Γ A} , Tm8 Γ nat8 → Tm8 Γ (arr8 nat8 (arr8 A A)) → Tm8 Γ A → Tm8 Γ A := λ t u v Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case8 zero8 suc8 rec8 => rec8 (t Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case8 zero8 suc8 rec8) (u Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case8 zero8 suc8 rec8) (v Tm8 var8 lam8 app8 tt8 pair8 fst8 snd8 left8 right8 case8 zero8 suc8 rec8) def v08 : ∀ {Γ A}, Tm8 (snoc8 Γ A) A := var8 vz8 def v18 : ∀ {Γ A B}, Tm8 (snoc8 (snoc8 Γ A) B) A := var8 (vs8 vz8) def v28 : ∀ {Γ A B C}, Tm8 (snoc8 (snoc8 (snoc8 Γ A) B) C) A := var8 (vs8 (vs8 vz8)) def v38 : ∀ {Γ A B C D}, Tm8 (snoc8 (snoc8 (snoc8 (snoc8 Γ A) B) C) D) A := var8 (vs8 (vs8 (vs8 vz8))) def tbool8 : Ty8 := sum8 top8 top8 def ttrue8 : ∀ {Γ}, Tm8 Γ tbool8 := left8 tt8 def tfalse8 : ∀ {Γ}, Tm8 Γ tbool8 := right8 tt8 def ifthenelse8 : ∀ {Γ A}, Tm8 Γ (arr8 tbool8 (arr8 A (arr8 A A))) := lam8 (lam8 (lam8 (case8 v28 (lam8 v28) (lam8 v18)))) def times48 : ∀ {Γ A}, Tm8 Γ (arr8 (arr8 A A) (arr8 A A)) := lam8 (lam8 (app8 v18 (app8 v18 (app8 v18 (app8 v18 v08))))) def add8 : ∀ {Γ}, Tm8 Γ (arr8 nat8 (arr8 nat8 nat8)) := lam8 (rec8 v08 (lam8 (lam8 (lam8 (suc8 (app8 v18 v08))))) (lam8 v08)) def mul8 : ∀ {Γ}, Tm8 Γ (arr8 nat8 (arr8 nat8 nat8)) := lam8 (rec8 v08 (lam8 (lam8 (lam8 (app8 (app8 add8 (app8 v18 v08)) v08)))) (lam8 zero8)) def fact8 : ∀ {Γ}, Tm8 Γ (arr8 nat8 nat8) := lam8 (rec8 v08 (lam8 (lam8 (app8 (app8 mul8 (suc8 v18)) v08))) (suc8 zero8)) def Ty9 : Type 1 := ∀ (Ty9 : Type) (nat top bot : Ty9) (arr prod sum : Ty9 → Ty9 → Ty9) , Ty9 def nat9 : Ty9 := λ _ nat9 _ _ _ _ _ => nat9 def top9 : Ty9 := λ _ _ top9 _ _ _ _ => top9 def bot9 : Ty9 := λ _ _ _ bot9 _ _ _ => bot9 def arr9 : Ty9 → Ty9 → Ty9 := λ A B Ty9 nat9 top9 bot9 arr9 prod sum => arr9 (A Ty9 nat9 top9 bot9 arr9 prod sum) (B Ty9 nat9 top9 bot9 arr9 prod sum) def prod9 : Ty9 → Ty9 → Ty9 := λ A B Ty9 nat9 top9 bot9 arr9 prod9 sum => prod9 (A Ty9 nat9 top9 bot9 arr9 prod9 sum) (B Ty9 nat9 top9 bot9 arr9 prod9 sum) def sum9 : Ty9 → Ty9 → Ty9 := λ A B Ty9 nat9 top9 bot9 arr9 prod9 sum9 => sum9 (A Ty9 nat9 top9 bot9 arr9 prod9 sum9) (B Ty9 nat9 top9 bot9 arr9 prod9 sum9) def Con9 : Type 1 := ∀ (Con9 : Type) (nil : Con9) (snoc : Con9 → Ty9 → Con9) , Con9 def nil9 : Con9 := λ Con9 nil9 snoc => nil9 def snoc9 : Con9 → Ty9 → Con9 := λ Γ A Con9 nil9 snoc9 => snoc9 (Γ Con9 nil9 snoc9) A def Var9 : Con9 → Ty9 → Type 1 := λ Γ A => ∀ (Var9 : Con9 → Ty9 → Type) (vz : ∀{Γ A}, Var9 (snoc9 Γ A) A) (vs : ∀{Γ B A}, Var9 Γ A → Var9 (snoc9 Γ B) A) , Var9 Γ A def vz9 : ∀ {Γ A}, Var9 (snoc9 Γ A) A := λ Var9 vz9 vs => vz9 def vs9 : ∀ {Γ B A}, Var9 Γ A → Var9 (snoc9 Γ B) A := λ x Var9 vz9 vs9 => vs9 (x Var9 vz9 vs9) def Tm9 : Con9 → Ty9 → Type 1 := λ Γ A => ∀ (Tm9 : Con9 → Ty9 → Type) (var : ∀ {Γ A}, Var9 Γ A → Tm9 Γ A) (lam : ∀ {Γ A B}, (Tm9 (snoc9 Γ A) B → Tm9 Γ (arr9 A B))) (app : ∀ {Γ A B} , Tm9 Γ (arr9 A B) → Tm9 Γ A → Tm9 Γ B) (tt : ∀ {Γ} , Tm9 Γ top9) (pair : ∀ {Γ A B} , Tm9 Γ A → Tm9 Γ B → Tm9 Γ (prod9 A B)) (fst : ∀ {Γ A B} , Tm9 Γ (prod9 A B) → Tm9 Γ A) (snd : ∀ {Γ A B} , Tm9 Γ (prod9 A B) → Tm9 Γ B) (left : ∀ {Γ A B} , Tm9 Γ A → Tm9 Γ (sum9 A B)) (right : ∀ {Γ A B} , Tm9 Γ B → Tm9 Γ (sum9 A B)) (case : ∀ {Γ A B C} , Tm9 Γ (sum9 A B) → Tm9 Γ (arr9 A C) → Tm9 Γ (arr9 B C) → Tm9 Γ C) (zero : ∀ {Γ} , Tm9 Γ nat9) (suc : ∀ {Γ} , Tm9 Γ nat9 → Tm9 Γ nat9) (rec : ∀ {Γ A} , Tm9 Γ nat9 → Tm9 Γ (arr9 nat9 (arr9 A A)) → Tm9 Γ A → Tm9 Γ A) , Tm9 Γ A def var9 : ∀ {Γ A}, Var9 Γ A → Tm9 Γ A := λ x Tm9 var9 lam app tt pair fst snd left right case zero suc rec => var9 x def lam9 : ∀ {Γ A B} , Tm9 (snoc9 Γ A) B → Tm9 Γ (arr9 A B) := λ t Tm9 var9 lam9 app tt pair fst snd left right case zero suc rec => lam9 (t Tm9 var9 lam9 app tt pair fst snd left right case zero suc rec) def app9 : ∀ {Γ A B} , Tm9 Γ (arr9 A B) → Tm9 Γ A → Tm9 Γ B := λ t u Tm9 var9 lam9 app9 tt pair fst snd left right case zero suc rec => app9 (t Tm9 var9 lam9 app9 tt pair fst snd left right case zero suc rec) (u Tm9 var9 lam9 app9 tt pair fst snd left right case zero suc rec) def tt9 : ∀ {Γ} , Tm9 Γ top9 := λ Tm9 var9 lam9 app9 tt9 pair fst snd left right case zero suc rec => tt9 def pair9 : ∀ {Γ A B} , Tm9 Γ A → Tm9 Γ B → Tm9 Γ (prod9 A B) := λ t u Tm9 var9 lam9 app9 tt9 pair9 fst snd left right case zero suc rec => pair9 (t Tm9 var9 lam9 app9 tt9 pair9 fst snd left right case zero suc rec) (u Tm9 var9 lam9 app9 tt9 pair9 fst snd left right case zero suc rec) def fst9 : ∀ {Γ A B} , Tm9 Γ (prod9 A B) → Tm9 Γ A := λ t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd left right case zero suc rec => fst9 (t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd left right case zero suc rec) def snd9 : ∀ {Γ A B} , Tm9 Γ (prod9 A B) → Tm9 Γ B := λ t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left right case zero suc rec => snd9 (t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left right case zero suc rec) def left9 : ∀ {Γ A B} , Tm9 Γ A → Tm9 Γ (sum9 A B) := λ t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right case zero suc rec => left9 (t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right case zero suc rec) def right9 : ∀ {Γ A B} , Tm9 Γ B → Tm9 Γ (sum9 A B) := λ t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case zero suc rec => right9 (t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case zero suc rec) def case9 : ∀ {Γ A B C} , Tm9 Γ (sum9 A B) → Tm9 Γ (arr9 A C) → Tm9 Γ (arr9 B C) → Tm9 Γ C := λ t u v Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case9 zero suc rec => case9 (t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case9 zero suc rec) (u Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case9 zero suc rec) (v Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case9 zero suc rec) def zero9 : ∀ {Γ} , Tm9 Γ nat9 := λ Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case9 zero9 suc rec => zero9 def suc9 : ∀ {Γ} , Tm9 Γ nat9 → Tm9 Γ nat9 := λ t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case9 zero9 suc9 rec => suc9 (t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case9 zero9 suc9 rec) def rec9 : ∀ {Γ A} , Tm9 Γ nat9 → Tm9 Γ (arr9 nat9 (arr9 A A)) → Tm9 Γ A → Tm9 Γ A := λ t u v Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case9 zero9 suc9 rec9 => rec9 (t Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case9 zero9 suc9 rec9) (u Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case9 zero9 suc9 rec9) (v Tm9 var9 lam9 app9 tt9 pair9 fst9 snd9 left9 right9 case9 zero9 suc9 rec9) def v09 : ∀ {Γ A}, Tm9 (snoc9 Γ A) A := var9 vz9 def v19 : ∀ {Γ A B}, Tm9 (snoc9 (snoc9 Γ A) B) A := var9 (vs9 vz9) def v29 : ∀ {Γ A B C}, Tm9 (snoc9 (snoc9 (snoc9 Γ A) B) C) A := var9 (vs9 (vs9 vz9)) def v39 : ∀ {Γ A B C D}, Tm9 (snoc9 (snoc9 (snoc9 (snoc9 Γ A) B) C) D) A := var9 (vs9 (vs9 (vs9 vz9))) def tbool9 : Ty9 := sum9 top9 top9 def ttrue9 : ∀ {Γ}, Tm9 Γ tbool9 := left9 tt9 def tfalse9 : ∀ {Γ}, Tm9 Γ tbool9 := right9 tt9 def ifthenelse9 : ∀ {Γ A}, Tm9 Γ (arr9 tbool9 (arr9 A (arr9 A A))) := lam9 (lam9 (lam9 (case9 v29 (lam9 v29) (lam9 v19)))) def times49 : ∀ {Γ A}, Tm9 Γ (arr9 (arr9 A A) (arr9 A A)) := lam9 (lam9 (app9 v19 (app9 v19 (app9 v19 (app9 v19 v09))))) def add9 : ∀ {Γ}, Tm9 Γ (arr9 nat9 (arr9 nat9 nat9)) := lam9 (rec9 v09 (lam9 (lam9 (lam9 (suc9 (app9 v19 v09))))) (lam9 v09)) def mul9 : ∀ {Γ}, Tm9 Γ (arr9 nat9 (arr9 nat9 nat9)) := lam9 (rec9 v09 (lam9 (lam9 (lam9 (app9 (app9 add9 (app9 v19 v09)) v09)))) (lam9 zero9)) def fact9 : ∀ {Γ}, Tm9 Γ (arr9 nat9 nat9) := lam9 (rec9 v09 (lam9 (lam9 (app9 (app9 mul9 (suc9 v19)) v09))) (suc9 zero9)) def Ty10 : Type 1 := ∀ (Ty10 : Type) (nat top bot : Ty10) (arr prod sum : Ty10 → Ty10 → Ty10) , Ty10 def nat10 : Ty10 := λ _ nat10 _ _ _ _ _ => nat10 def top10 : Ty10 := λ _ _ top10 _ _ _ _ => top10 def bot10 : Ty10 := λ _ _ _ bot10 _ _ _ => bot10 def arr10 : Ty10 → Ty10 → Ty10 := λ A B Ty10 nat10 top10 bot10 arr10 prod sum => arr10 (A Ty10 nat10 top10 bot10 arr10 prod sum) (B Ty10 nat10 top10 bot10 arr10 prod sum) def prod10 : Ty10 → Ty10 → Ty10 := λ A B Ty10 nat10 top10 bot10 arr10 prod10 sum => prod10 (A Ty10 nat10 top10 bot10 arr10 prod10 sum) (B Ty10 nat10 top10 bot10 arr10 prod10 sum) def sum10 : Ty10 → Ty10 → Ty10 := λ A B Ty10 nat10 top10 bot10 arr10 prod10 sum10 => sum10 (A Ty10 nat10 top10 bot10 arr10 prod10 sum10) (B Ty10 nat10 top10 bot10 arr10 prod10 sum10) def Con10 : Type 1 := ∀ (Con10 : Type) (nil : Con10) (snoc : Con10 → Ty10 → Con10) , Con10 def nil10 : Con10 := λ Con10 nil10 snoc => nil10 def snoc10 : Con10 → Ty10 → Con10 := λ Γ A Con10 nil10 snoc10 => snoc10 (Γ Con10 nil10 snoc10) A def Var10 : Con10 → Ty10 → Type 1 := λ Γ A => ∀ (Var10 : Con10 → Ty10 → Type) (vz : ∀{Γ A}, Var10 (snoc10 Γ A) A) (vs : ∀{Γ B A}, Var10 Γ A → Var10 (snoc10 Γ B) A) , Var10 Γ A def vz10 : ∀ {Γ A}, Var10 (snoc10 Γ A) A := λ Var10 vz10 vs => vz10 def vs10 : ∀ {Γ B A}, Var10 Γ A → Var10 (snoc10 Γ B) A := λ x Var10 vz10 vs10 => vs10 (x Var10 vz10 vs10) def Tm10 : Con10 → Ty10 → Type 1 := λ Γ A => ∀ (Tm10 : Con10 → Ty10 → Type) (var : ∀ {Γ A}, Var10 Γ A → Tm10 Γ A) (lam : ∀ {Γ A B}, (Tm10 (snoc10 Γ A) B → Tm10 Γ (arr10 A B))) (app : ∀ {Γ A B} , Tm10 Γ (arr10 A B) → Tm10 Γ A → Tm10 Γ B) (tt : ∀ {Γ} , Tm10 Γ top10) (pair : ∀ {Γ A B} , Tm10 Γ A → Tm10 Γ B → Tm10 Γ (prod10 A B)) (fst : ∀ {Γ A B} , Tm10 Γ (prod10 A B) → Tm10 Γ A) (snd : ∀ {Γ A B} , Tm10 Γ (prod10 A B) → Tm10 Γ B) (left : ∀ {Γ A B} , Tm10 Γ A → Tm10 Γ (sum10 A B)) (right : ∀ {Γ A B} , Tm10 Γ B → Tm10 Γ (sum10 A B)) (case : ∀ {Γ A B C} , Tm10 Γ (sum10 A B) → Tm10 Γ (arr10 A C) → Tm10 Γ (arr10 B C) → Tm10 Γ C) (zero : ∀ {Γ} , Tm10 Γ nat10) (suc : ∀ {Γ} , Tm10 Γ nat10 → Tm10 Γ nat10) (rec : ∀ {Γ A} , Tm10 Γ nat10 → Tm10 Γ (arr10 nat10 (arr10 A A)) → Tm10 Γ A → Tm10 Γ A) , Tm10 Γ A def var10 : ∀ {Γ A}, Var10 Γ A → Tm10 Γ A := λ x Tm10 var10 lam app tt pair fst snd left right case zero suc rec => var10 x def lam10 : ∀ {Γ A B} , Tm10 (snoc10 Γ A) B → Tm10 Γ (arr10 A B) := λ t Tm10 var10 lam10 app tt pair fst snd left right case zero suc rec => lam10 (t Tm10 var10 lam10 app tt pair fst snd left right case zero suc rec) def app10 : ∀ {Γ A B} , Tm10 Γ (arr10 A B) → Tm10 Γ A → Tm10 Γ B := λ t u Tm10 var10 lam10 app10 tt pair fst snd left right case zero suc rec => app10 (t Tm10 var10 lam10 app10 tt pair fst snd left right case zero suc rec) (u Tm10 var10 lam10 app10 tt pair fst snd left right case zero suc rec) def tt10 : ∀ {Γ} , Tm10 Γ top10 := λ Tm10 var10 lam10 app10 tt10 pair fst snd left right case zero suc rec => tt10 def pair10 : ∀ {Γ A B} , Tm10 Γ A → Tm10 Γ B → Tm10 Γ (prod10 A B) := λ t u Tm10 var10 lam10 app10 tt10 pair10 fst snd left right case zero suc rec => pair10 (t Tm10 var10 lam10 app10 tt10 pair10 fst snd left right case zero suc rec) (u Tm10 var10 lam10 app10 tt10 pair10 fst snd left right case zero suc rec) def fst10 : ∀ {Γ A B} , Tm10 Γ (prod10 A B) → Tm10 Γ A := λ t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd left right case zero suc rec => fst10 (t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd left right case zero suc rec) def snd10 : ∀ {Γ A B} , Tm10 Γ (prod10 A B) → Tm10 Γ B := λ t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left right case zero suc rec => snd10 (t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left right case zero suc rec) def left10 : ∀ {Γ A B} , Tm10 Γ A → Tm10 Γ (sum10 A B) := λ t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right case zero suc rec => left10 (t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right case zero suc rec) def right10 : ∀ {Γ A B} , Tm10 Γ B → Tm10 Γ (sum10 A B) := λ t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case zero suc rec => right10 (t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case zero suc rec) def case10 : ∀ {Γ A B C} , Tm10 Γ (sum10 A B) → Tm10 Γ (arr10 A C) → Tm10 Γ (arr10 B C) → Tm10 Γ C := λ t u v Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case10 zero suc rec => case10 (t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case10 zero suc rec) (u Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case10 zero suc rec) (v Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case10 zero suc rec) def zero10 : ∀ {Γ} , Tm10 Γ nat10 := λ Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case10 zero10 suc rec => zero10 def suc10 : ∀ {Γ} , Tm10 Γ nat10 → Tm10 Γ nat10 := λ t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case10 zero10 suc10 rec => suc10 (t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case10 zero10 suc10 rec) def rec10 : ∀ {Γ A} , Tm10 Γ nat10 → Tm10 Γ (arr10 nat10 (arr10 A A)) → Tm10 Γ A → Tm10 Γ A := λ t u v Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case10 zero10 suc10 rec10 => rec10 (t Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case10 zero10 suc10 rec10) (u Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case10 zero10 suc10 rec10) (v Tm10 var10 lam10 app10 tt10 pair10 fst10 snd10 left10 right10 case10 zero10 suc10 rec10) def v010 : ∀ {Γ A}, Tm10 (snoc10 Γ A) A := var10 vz10 def v110 : ∀ {Γ A B}, Tm10 (snoc10 (snoc10 Γ A) B) A := var10 (vs10 vz10) def v210 : ∀ {Γ A B C}, Tm10 (snoc10 (snoc10 (snoc10 Γ A) B) C) A := var10 (vs10 (vs10 vz10)) def v310 : ∀ {Γ A B C D}, Tm10 (snoc10 (snoc10 (snoc10 (snoc10 Γ A) B) C) D) A := var10 (vs10 (vs10 (vs10 vz10))) def tbool10 : Ty10 := sum10 top10 top10 def ttrue10 : ∀ {Γ}, Tm10 Γ tbool10 := left10 tt10 def tfalse10 : ∀ {Γ}, Tm10 Γ tbool10 := right10 tt10 def ifthenelse10 : ∀ {Γ A}, Tm10 Γ (arr10 tbool10 (arr10 A (arr10 A A))) := lam10 (lam10 (lam10 (case10 v210 (lam10 v210) (lam10 v110)))) def times410 : ∀ {Γ A}, Tm10 Γ (arr10 (arr10 A A) (arr10 A A)) := lam10 (lam10 (app10 v110 (app10 v110 (app10 v110 (app10 v110 v010))))) def add10 : ∀ {Γ}, Tm10 Γ (arr10 nat10 (arr10 nat10 nat10)) := lam10 (rec10 v010 (lam10 (lam10 (lam10 (suc10 (app10 v110 v010))))) (lam10 v010)) def mul10 : ∀ {Γ}, Tm10 Γ (arr10 nat10 (arr10 nat10 nat10)) := lam10 (rec10 v010 (lam10 (lam10 (lam10 (app10 (app10 add10 (app10 v110 v010)) v010)))) (lam10 zero10)) def fact10 : ∀ {Γ}, Tm10 Γ (arr10 nat10 nat10) := lam10 (rec10 v010 (lam10 (lam10 (app10 (app10 mul10 (suc10 v110)) v010))) (suc10 zero10)) def Ty11 : Type 1 := ∀ (Ty11 : Type) (nat top bot : Ty11) (arr prod sum : Ty11 → Ty11 → Ty11) , Ty11 def nat11 : Ty11 := λ _ nat11 _ _ _ _ _ => nat11 def top11 : Ty11 := λ _ _ top11 _ _ _ _ => top11 def bot11 : Ty11 := λ _ _ _ bot11 _ _ _ => bot11 def arr11 : Ty11 → Ty11 → Ty11 := λ A B Ty11 nat11 top11 bot11 arr11 prod sum => arr11 (A Ty11 nat11 top11 bot11 arr11 prod sum) (B Ty11 nat11 top11 bot11 arr11 prod sum) def prod11 : Ty11 → Ty11 → Ty11 := λ A B Ty11 nat11 top11 bot11 arr11 prod11 sum => prod11 (A Ty11 nat11 top11 bot11 arr11 prod11 sum) (B Ty11 nat11 top11 bot11 arr11 prod11 sum) def sum11 : Ty11 → Ty11 → Ty11 := λ A B Ty11 nat11 top11 bot11 arr11 prod11 sum11 => sum11 (A Ty11 nat11 top11 bot11 arr11 prod11 sum11) (B Ty11 nat11 top11 bot11 arr11 prod11 sum11) def Con11 : Type 1 := ∀ (Con11 : Type) (nil : Con11) (snoc : Con11 → Ty11 → Con11) , Con11 def nil11 : Con11 := λ Con11 nil11 snoc => nil11 def snoc11 : Con11 → Ty11 → Con11 := λ Γ A Con11 nil11 snoc11 => snoc11 (Γ Con11 nil11 snoc11) A def Var11 : Con11 → Ty11 → Type 1 := λ Γ A => ∀ (Var11 : Con11 → Ty11 → Type) (vz : ∀{Γ A}, Var11 (snoc11 Γ A) A) (vs : ∀{Γ B A}, Var11 Γ A → Var11 (snoc11 Γ B) A) , Var11 Γ A def vz11 : ∀ {Γ A}, Var11 (snoc11 Γ A) A := λ Var11 vz11 vs => vz11 def vs11 : ∀ {Γ B A}, Var11 Γ A → Var11 (snoc11 Γ B) A := λ x Var11 vz11 vs11 => vs11 (x Var11 vz11 vs11) def Tm11 : Con11 → Ty11 → Type 1 := λ Γ A => ∀ (Tm11 : Con11 → Ty11 → Type) (var : ∀ {Γ A}, Var11 Γ A → Tm11 Γ A) (lam : ∀ {Γ A B}, (Tm11 (snoc11 Γ A) B → Tm11 Γ (arr11 A B))) (app : ∀ {Γ A B} , Tm11 Γ (arr11 A B) → Tm11 Γ A → Tm11 Γ B) (tt : ∀ {Γ} , Tm11 Γ top11) (pair : ∀ {Γ A B} , Tm11 Γ A → Tm11 Γ B → Tm11 Γ (prod11 A B)) (fst : ∀ {Γ A B} , Tm11 Γ (prod11 A B) → Tm11 Γ A) (snd : ∀ {Γ A B} , Tm11 Γ (prod11 A B) → Tm11 Γ B) (left : ∀ {Γ A B} , Tm11 Γ A → Tm11 Γ (sum11 A B)) (right : ∀ {Γ A B} , Tm11 Γ B → Tm11 Γ (sum11 A B)) (case : ∀ {Γ A B C} , Tm11 Γ (sum11 A B) → Tm11 Γ (arr11 A C) → Tm11 Γ (arr11 B C) → Tm11 Γ C) (zero : ∀ {Γ} , Tm11 Γ nat11) (suc : ∀ {Γ} , Tm11 Γ nat11 → Tm11 Γ nat11) (rec : ∀ {Γ A} , Tm11 Γ nat11 → Tm11 Γ (arr11 nat11 (arr11 A A)) → Tm11 Γ A → Tm11 Γ A) , Tm11 Γ A def var11 : ∀ {Γ A}, Var11 Γ A → Tm11 Γ A := λ x Tm11 var11 lam app tt pair fst snd left right case zero suc rec => var11 x def lam11 : ∀ {Γ A B} , Tm11 (snoc11 Γ A) B → Tm11 Γ (arr11 A B) := λ t Tm11 var11 lam11 app tt pair fst snd left right case zero suc rec => lam11 (t Tm11 var11 lam11 app tt pair fst snd left right case zero suc rec) def app11 : ∀ {Γ A B} , Tm11 Γ (arr11 A B) → Tm11 Γ A → Tm11 Γ B := λ t u Tm11 var11 lam11 app11 tt pair fst snd left right case zero suc rec => app11 (t Tm11 var11 lam11 app11 tt pair fst snd left right case zero suc rec) (u Tm11 var11 lam11 app11 tt pair fst snd left right case zero suc rec) def tt11 : ∀ {Γ} , Tm11 Γ top11 := λ Tm11 var11 lam11 app11 tt11 pair fst snd left right case zero suc rec => tt11 def pair11 : ∀ {Γ A B} , Tm11 Γ A → Tm11 Γ B → Tm11 Γ (prod11 A B) := λ t u Tm11 var11 lam11 app11 tt11 pair11 fst snd left right case zero suc rec => pair11 (t Tm11 var11 lam11 app11 tt11 pair11 fst snd left right case zero suc rec) (u Tm11 var11 lam11 app11 tt11 pair11 fst snd left right case zero suc rec) def fst11 : ∀ {Γ A B} , Tm11 Γ (prod11 A B) → Tm11 Γ A := λ t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd left right case zero suc rec => fst11 (t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd left right case zero suc rec) def snd11 : ∀ {Γ A B} , Tm11 Γ (prod11 A B) → Tm11 Γ B := λ t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left right case zero suc rec => snd11 (t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left right case zero suc rec) def left11 : ∀ {Γ A B} , Tm11 Γ A → Tm11 Γ (sum11 A B) := λ t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right case zero suc rec => left11 (t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right case zero suc rec) def right11 : ∀ {Γ A B} , Tm11 Γ B → Tm11 Γ (sum11 A B) := λ t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case zero suc rec => right11 (t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case zero suc rec) def case11 : ∀ {Γ A B C} , Tm11 Γ (sum11 A B) → Tm11 Γ (arr11 A C) → Tm11 Γ (arr11 B C) → Tm11 Γ C := λ t u v Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case11 zero suc rec => case11 (t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case11 zero suc rec) (u Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case11 zero suc rec) (v Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case11 zero suc rec) def zero11 : ∀ {Γ} , Tm11 Γ nat11 := λ Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case11 zero11 suc rec => zero11 def suc11 : ∀ {Γ} , Tm11 Γ nat11 → Tm11 Γ nat11 := λ t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case11 zero11 suc11 rec => suc11 (t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case11 zero11 suc11 rec) def rec11 : ∀ {Γ A} , Tm11 Γ nat11 → Tm11 Γ (arr11 nat11 (arr11 A A)) → Tm11 Γ A → Tm11 Γ A := λ t u v Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case11 zero11 suc11 rec11 => rec11 (t Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case11 zero11 suc11 rec11) (u Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case11 zero11 suc11 rec11) (v Tm11 var11 lam11 app11 tt11 pair11 fst11 snd11 left11 right11 case11 zero11 suc11 rec11) def v011 : ∀ {Γ A}, Tm11 (snoc11 Γ A) A := var11 vz11 def v111 : ∀ {Γ A B}, Tm11 (snoc11 (snoc11 Γ A) B) A := var11 (vs11 vz11) def v211 : ∀ {Γ A B C}, Tm11 (snoc11 (snoc11 (snoc11 Γ A) B) C) A := var11 (vs11 (vs11 vz11)) def v311 : ∀ {Γ A B C D}, Tm11 (snoc11 (snoc11 (snoc11 (snoc11 Γ A) B) C) D) A := var11 (vs11 (vs11 (vs11 vz11))) def tbool11 : Ty11 := sum11 top11 top11 def ttrue11 : ∀ {Γ}, Tm11 Γ tbool11 := left11 tt11 def tfalse11 : ∀ {Γ}, Tm11 Γ tbool11 := right11 tt11 def ifthenelse11 : ∀ {Γ A}, Tm11 Γ (arr11 tbool11 (arr11 A (arr11 A A))) := lam11 (lam11 (lam11 (case11 v211 (lam11 v211) (lam11 v111)))) def times411 : ∀ {Γ A}, Tm11 Γ (arr11 (arr11 A A) (arr11 A A)) := lam11 (lam11 (app11 v111 (app11 v111 (app11 v111 (app11 v111 v011))))) def add11 : ∀ {Γ}, Tm11 Γ (arr11 nat11 (arr11 nat11 nat11)) := lam11 (rec11 v011 (lam11 (lam11 (lam11 (suc11 (app11 v111 v011))))) (lam11 v011)) def mul11 : ∀ {Γ}, Tm11 Γ (arr11 nat11 (arr11 nat11 nat11)) := lam11 (rec11 v011 (lam11 (lam11 (lam11 (app11 (app11 add11 (app11 v111 v011)) v011)))) (lam11 zero11)) def fact11 : ∀ {Γ}, Tm11 Γ (arr11 nat11 nat11) := lam11 (rec11 v011 (lam11 (lam11 (app11 (app11 mul11 (suc11 v111)) v011))) (suc11 zero11)) def Ty12 : Type 1 := ∀ (Ty12 : Type) (nat top bot : Ty12) (arr prod sum : Ty12 → Ty12 → Ty12) , Ty12 def nat12 : Ty12 := λ _ nat12 _ _ _ _ _ => nat12 def top12 : Ty12 := λ _ _ top12 _ _ _ _ => top12 def bot12 : Ty12 := λ _ _ _ bot12 _ _ _ => bot12 def arr12 : Ty12 → Ty12 → Ty12 := λ A B Ty12 nat12 top12 bot12 arr12 prod sum => arr12 (A Ty12 nat12 top12 bot12 arr12 prod sum) (B Ty12 nat12 top12 bot12 arr12 prod sum) def prod12 : Ty12 → Ty12 → Ty12 := λ A B Ty12 nat12 top12 bot12 arr12 prod12 sum => prod12 (A Ty12 nat12 top12 bot12 arr12 prod12 sum) (B Ty12 nat12 top12 bot12 arr12 prod12 sum) def sum12 : Ty12 → Ty12 → Ty12 := λ A B Ty12 nat12 top12 bot12 arr12 prod12 sum12 => sum12 (A Ty12 nat12 top12 bot12 arr12 prod12 sum12) (B Ty12 nat12 top12 bot12 arr12 prod12 sum12) def Con12 : Type 1 := ∀ (Con12 : Type) (nil : Con12) (snoc : Con12 → Ty12 → Con12) , Con12 def nil12 : Con12 := λ Con12 nil12 snoc => nil12 def snoc12 : Con12 → Ty12 → Con12 := λ Γ A Con12 nil12 snoc12 => snoc12 (Γ Con12 nil12 snoc12) A def Var12 : Con12 → Ty12 → Type 1 := λ Γ A => ∀ (Var12 : Con12 → Ty12 → Type) (vz : ∀{Γ A}, Var12 (snoc12 Γ A) A) (vs : ∀{Γ B A}, Var12 Γ A → Var12 (snoc12 Γ B) A) , Var12 Γ A def vz12 : ∀ {Γ A}, Var12 (snoc12 Γ A) A := λ Var12 vz12 vs => vz12 def vs12 : ∀ {Γ B A}, Var12 Γ A → Var12 (snoc12 Γ B) A := λ x Var12 vz12 vs12 => vs12 (x Var12 vz12 vs12) def Tm12 : Con12 → Ty12 → Type 1 := λ Γ A => ∀ (Tm12 : Con12 → Ty12 → Type) (var : ∀ {Γ A}, Var12 Γ A → Tm12 Γ A) (lam : ∀ {Γ A B}, (Tm12 (snoc12 Γ A) B → Tm12 Γ (arr12 A B))) (app : ∀ {Γ A B} , Tm12 Γ (arr12 A B) → Tm12 Γ A → Tm12 Γ B) (tt : ∀ {Γ} , Tm12 Γ top12) (pair : ∀ {Γ A B} , Tm12 Γ A → Tm12 Γ B → Tm12 Γ (prod12 A B)) (fst : ∀ {Γ A B} , Tm12 Γ (prod12 A B) → Tm12 Γ A) (snd : ∀ {Γ A B} , Tm12 Γ (prod12 A B) → Tm12 Γ B) (left : ∀ {Γ A B} , Tm12 Γ A → Tm12 Γ (sum12 A B)) (right : ∀ {Γ A B} , Tm12 Γ B → Tm12 Γ (sum12 A B)) (case : ∀ {Γ A B C} , Tm12 Γ (sum12 A B) → Tm12 Γ (arr12 A C) → Tm12 Γ (arr12 B C) → Tm12 Γ C) (zero : ∀ {Γ} , Tm12 Γ nat12) (suc : ∀ {Γ} , Tm12 Γ nat12 → Tm12 Γ nat12) (rec : ∀ {Γ A} , Tm12 Γ nat12 → Tm12 Γ (arr12 nat12 (arr12 A A)) → Tm12 Γ A → Tm12 Γ A) , Tm12 Γ A def var12 : ∀ {Γ A}, Var12 Γ A → Tm12 Γ A := λ x Tm12 var12 lam app tt pair fst snd left right case zero suc rec => var12 x def lam12 : ∀ {Γ A B} , Tm12 (snoc12 Γ A) B → Tm12 Γ (arr12 A B) := λ t Tm12 var12 lam12 app tt pair fst snd left right case zero suc rec => lam12 (t Tm12 var12 lam12 app tt pair fst snd left right case zero suc rec) def app12 : ∀ {Γ A B} , Tm12 Γ (arr12 A B) → Tm12 Γ A → Tm12 Γ B := λ t u Tm12 var12 lam12 app12 tt pair fst snd left right case zero suc rec => app12 (t Tm12 var12 lam12 app12 tt pair fst snd left right case zero suc rec) (u Tm12 var12 lam12 app12 tt pair fst snd left right case zero suc rec) def tt12 : ∀ {Γ} , Tm12 Γ top12 := λ Tm12 var12 lam12 app12 tt12 pair fst snd left right case zero suc rec => tt12 def pair12 : ∀ {Γ A B} , Tm12 Γ A → Tm12 Γ B → Tm12 Γ (prod12 A B) := λ t u Tm12 var12 lam12 app12 tt12 pair12 fst snd left right case zero suc rec => pair12 (t Tm12 var12 lam12 app12 tt12 pair12 fst snd left right case zero suc rec) (u Tm12 var12 lam12 app12 tt12 pair12 fst snd left right case zero suc rec) def fst12 : ∀ {Γ A B} , Tm12 Γ (prod12 A B) → Tm12 Γ A := λ t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd left right case zero suc rec => fst12 (t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd left right case zero suc rec) def snd12 : ∀ {Γ A B} , Tm12 Γ (prod12 A B) → Tm12 Γ B := λ t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left right case zero suc rec => snd12 (t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left right case zero suc rec) def left12 : ∀ {Γ A B} , Tm12 Γ A → Tm12 Γ (sum12 A B) := λ t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right case zero suc rec => left12 (t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right case zero suc rec) def right12 : ∀ {Γ A B} , Tm12 Γ B → Tm12 Γ (sum12 A B) := λ t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case zero suc rec => right12 (t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case zero suc rec) def case12 : ∀ {Γ A B C} , Tm12 Γ (sum12 A B) → Tm12 Γ (arr12 A C) → Tm12 Γ (arr12 B C) → Tm12 Γ C := λ t u v Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case12 zero suc rec => case12 (t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case12 zero suc rec) (u Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case12 zero suc rec) (v Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case12 zero suc rec) def zero12 : ∀ {Γ} , Tm12 Γ nat12 := λ Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case12 zero12 suc rec => zero12 def suc12 : ∀ {Γ} , Tm12 Γ nat12 → Tm12 Γ nat12 := λ t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case12 zero12 suc12 rec => suc12 (t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case12 zero12 suc12 rec) def rec12 : ∀ {Γ A} , Tm12 Γ nat12 → Tm12 Γ (arr12 nat12 (arr12 A A)) → Tm12 Γ A → Tm12 Γ A := λ t u v Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case12 zero12 suc12 rec12 => rec12 (t Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case12 zero12 suc12 rec12) (u Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case12 zero12 suc12 rec12) (v Tm12 var12 lam12 app12 tt12 pair12 fst12 snd12 left12 right12 case12 zero12 suc12 rec12) def v012 : ∀ {Γ A}, Tm12 (snoc12 Γ A) A := var12 vz12 def v112 : ∀ {Γ A B}, Tm12 (snoc12 (snoc12 Γ A) B) A := var12 (vs12 vz12) def v212 : ∀ {Γ A B C}, Tm12 (snoc12 (snoc12 (snoc12 Γ A) B) C) A := var12 (vs12 (vs12 vz12)) def v312 : ∀ {Γ A B C D}, Tm12 (snoc12 (snoc12 (snoc12 (snoc12 Γ A) B) C) D) A := var12 (vs12 (vs12 (vs12 vz12))) def tbool12 : Ty12 := sum12 top12 top12 def ttrue12 : ∀ {Γ}, Tm12 Γ tbool12 := left12 tt12 def tfalse12 : ∀ {Γ}, Tm12 Γ tbool12 := right12 tt12 def ifthenelse12 : ∀ {Γ A}, Tm12 Γ (arr12 tbool12 (arr12 A (arr12 A A))) := lam12 (lam12 (lam12 (case12 v212 (lam12 v212) (lam12 v112)))) def times412 : ∀ {Γ A}, Tm12 Γ (arr12 (arr12 A A) (arr12 A A)) := lam12 (lam12 (app12 v112 (app12 v112 (app12 v112 (app12 v112 v012))))) def add12 : ∀ {Γ}, Tm12 Γ (arr12 nat12 (arr12 nat12 nat12)) := lam12 (rec12 v012 (lam12 (lam12 (lam12 (suc12 (app12 v112 v012))))) (lam12 v012)) def mul12 : ∀ {Γ}, Tm12 Γ (arr12 nat12 (arr12 nat12 nat12)) := lam12 (rec12 v012 (lam12 (lam12 (lam12 (app12 (app12 add12 (app12 v112 v012)) v012)))) (lam12 zero12)) def fact12 : ∀ {Γ}, Tm12 Γ (arr12 nat12 nat12) := lam12 (rec12 v012 (lam12 (lam12 (app12 (app12 mul12 (suc12 v112)) v012))) (suc12 zero12)) def Ty13 : Type 1 := ∀ (Ty13 : Type) (nat top bot : Ty13) (arr prod sum : Ty13 → Ty13 → Ty13) , Ty13 def nat13 : Ty13 := λ _ nat13 _ _ _ _ _ => nat13 def top13 : Ty13 := λ _ _ top13 _ _ _ _ => top13 def bot13 : Ty13 := λ _ _ _ bot13 _ _ _ => bot13 def arr13 : Ty13 → Ty13 → Ty13 := λ A B Ty13 nat13 top13 bot13 arr13 prod sum => arr13 (A Ty13 nat13 top13 bot13 arr13 prod sum) (B Ty13 nat13 top13 bot13 arr13 prod sum) def prod13 : Ty13 → Ty13 → Ty13 := λ A B Ty13 nat13 top13 bot13 arr13 prod13 sum => prod13 (A Ty13 nat13 top13 bot13 arr13 prod13 sum) (B Ty13 nat13 top13 bot13 arr13 prod13 sum) def sum13 : Ty13 → Ty13 → Ty13 := λ A B Ty13 nat13 top13 bot13 arr13 prod13 sum13 => sum13 (A Ty13 nat13 top13 bot13 arr13 prod13 sum13) (B Ty13 nat13 top13 bot13 arr13 prod13 sum13) def Con13 : Type 1 := ∀ (Con13 : Type) (nil : Con13) (snoc : Con13 → Ty13 → Con13) , Con13 def nil13 : Con13 := λ Con13 nil13 snoc => nil13 def snoc13 : Con13 → Ty13 → Con13 := λ Γ A Con13 nil13 snoc13 => snoc13 (Γ Con13 nil13 snoc13) A def Var13 : Con13 → Ty13 → Type 1 := λ Γ A => ∀ (Var13 : Con13 → Ty13 → Type) (vz : ∀{Γ A}, Var13 (snoc13 Γ A) A) (vs : ∀{Γ B A}, Var13 Γ A → Var13 (snoc13 Γ B) A) , Var13 Γ A def vz13 : ∀ {Γ A}, Var13 (snoc13 Γ A) A := λ Var13 vz13 vs => vz13 def vs13 : ∀ {Γ B A}, Var13 Γ A → Var13 (snoc13 Γ B) A := λ x Var13 vz13 vs13 => vs13 (x Var13 vz13 vs13) def Tm13 : Con13 → Ty13 → Type 1 := λ Γ A => ∀ (Tm13 : Con13 → Ty13 → Type) (var : ∀ {Γ A}, Var13 Γ A → Tm13 Γ A) (lam : ∀ {Γ A B}, (Tm13 (snoc13 Γ A) B → Tm13 Γ (arr13 A B))) (app : ∀ {Γ A B} , Tm13 Γ (arr13 A B) → Tm13 Γ A → Tm13 Γ B) (tt : ∀ {Γ} , Tm13 Γ top13) (pair : ∀ {Γ A B} , Tm13 Γ A → Tm13 Γ B → Tm13 Γ (prod13 A B)) (fst : ∀ {Γ A B} , Tm13 Γ (prod13 A B) → Tm13 Γ A) (snd : ∀ {Γ A B} , Tm13 Γ (prod13 A B) → Tm13 Γ B) (left : ∀ {Γ A B} , Tm13 Γ A → Tm13 Γ (sum13 A B)) (right : ∀ {Γ A B} , Tm13 Γ B → Tm13 Γ (sum13 A B)) (case : ∀ {Γ A B C} , Tm13 Γ (sum13 A B) → Tm13 Γ (arr13 A C) → Tm13 Γ (arr13 B C) → Tm13 Γ C) (zero : ∀ {Γ} , Tm13 Γ nat13) (suc : ∀ {Γ} , Tm13 Γ nat13 → Tm13 Γ nat13) (rec : ∀ {Γ A} , Tm13 Γ nat13 → Tm13 Γ (arr13 nat13 (arr13 A A)) → Tm13 Γ A → Tm13 Γ A) , Tm13 Γ A def var13 : ∀ {Γ A}, Var13 Γ A → Tm13 Γ A := λ x Tm13 var13 lam app tt pair fst snd left right case zero suc rec => var13 x def lam13 : ∀ {Γ A B} , Tm13 (snoc13 Γ A) B → Tm13 Γ (arr13 A B) := λ t Tm13 var13 lam13 app tt pair fst snd left right case zero suc rec => lam13 (t Tm13 var13 lam13 app tt pair fst snd left right case zero suc rec) def app13 : ∀ {Γ A B} , Tm13 Γ (arr13 A B) → Tm13 Γ A → Tm13 Γ B := λ t u Tm13 var13 lam13 app13 tt pair fst snd left right case zero suc rec => app13 (t Tm13 var13 lam13 app13 tt pair fst snd left right case zero suc rec) (u Tm13 var13 lam13 app13 tt pair fst snd left right case zero suc rec) def tt13 : ∀ {Γ} , Tm13 Γ top13 := λ Tm13 var13 lam13 app13 tt13 pair fst snd left right case zero suc rec => tt13 def pair13 : ∀ {Γ A B} , Tm13 Γ A → Tm13 Γ B → Tm13 Γ (prod13 A B) := λ t u Tm13 var13 lam13 app13 tt13 pair13 fst snd left right case zero suc rec => pair13 (t Tm13 var13 lam13 app13 tt13 pair13 fst snd left right case zero suc rec) (u Tm13 var13 lam13 app13 tt13 pair13 fst snd left right case zero suc rec) def fst13 : ∀ {Γ A B} , Tm13 Γ (prod13 A B) → Tm13 Γ A := λ t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd left right case zero suc rec => fst13 (t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd left right case zero suc rec) def snd13 : ∀ {Γ A B} , Tm13 Γ (prod13 A B) → Tm13 Γ B := λ t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left right case zero suc rec => snd13 (t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left right case zero suc rec) def left13 : ∀ {Γ A B} , Tm13 Γ A → Tm13 Γ (sum13 A B) := λ t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right case zero suc rec => left13 (t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right case zero suc rec) def right13 : ∀ {Γ A B} , Tm13 Γ B → Tm13 Γ (sum13 A B) := λ t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case zero suc rec => right13 (t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case zero suc rec) def case13 : ∀ {Γ A B C} , Tm13 Γ (sum13 A B) → Tm13 Γ (arr13 A C) → Tm13 Γ (arr13 B C) → Tm13 Γ C := λ t u v Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case13 zero suc rec => case13 (t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case13 zero suc rec) (u Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case13 zero suc rec) (v Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case13 zero suc rec) def zero13 : ∀ {Γ} , Tm13 Γ nat13 := λ Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case13 zero13 suc rec => zero13 def suc13 : ∀ {Γ} , Tm13 Γ nat13 → Tm13 Γ nat13 := λ t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case13 zero13 suc13 rec => suc13 (t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case13 zero13 suc13 rec) def rec13 : ∀ {Γ A} , Tm13 Γ nat13 → Tm13 Γ (arr13 nat13 (arr13 A A)) → Tm13 Γ A → Tm13 Γ A := λ t u v Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case13 zero13 suc13 rec13 => rec13 (t Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case13 zero13 suc13 rec13) (u Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case13 zero13 suc13 rec13) (v Tm13 var13 lam13 app13 tt13 pair13 fst13 snd13 left13 right13 case13 zero13 suc13 rec13) def v013 : ∀ {Γ A}, Tm13 (snoc13 Γ A) A := var13 vz13 def v113 : ∀ {Γ A B}, Tm13 (snoc13 (snoc13 Γ A) B) A := var13 (vs13 vz13) def v213 : ∀ {Γ A B C}, Tm13 (snoc13 (snoc13 (snoc13 Γ A) B) C) A := var13 (vs13 (vs13 vz13)) def v313 : ∀ {Γ A B C D}, Tm13 (snoc13 (snoc13 (snoc13 (snoc13 Γ A) B) C) D) A := var13 (vs13 (vs13 (vs13 vz13))) def tbool13 : Ty13 := sum13 top13 top13 def ttrue13 : ∀ {Γ}, Tm13 Γ tbool13 := left13 tt13 def tfalse13 : ∀ {Γ}, Tm13 Γ tbool13 := right13 tt13 def ifthenelse13 : ∀ {Γ A}, Tm13 Γ (arr13 tbool13 (arr13 A (arr13 A A))) := lam13 (lam13 (lam13 (case13 v213 (lam13 v213) (lam13 v113)))) def times413 : ∀ {Γ A}, Tm13 Γ (arr13 (arr13 A A) (arr13 A A)) := lam13 (lam13 (app13 v113 (app13 v113 (app13 v113 (app13 v113 v013))))) def add13 : ∀ {Γ}, Tm13 Γ (arr13 nat13 (arr13 nat13 nat13)) := lam13 (rec13 v013 (lam13 (lam13 (lam13 (suc13 (app13 v113 v013))))) (lam13 v013)) def mul13 : ∀ {Γ}, Tm13 Γ (arr13 nat13 (arr13 nat13 nat13)) := lam13 (rec13 v013 (lam13 (lam13 (lam13 (app13 (app13 add13 (app13 v113 v013)) v013)))) (lam13 zero13)) def fact13 : ∀ {Γ}, Tm13 Γ (arr13 nat13 nat13) := lam13 (rec13 v013 (lam13 (lam13 (app13 (app13 mul13 (suc13 v113)) v013))) (suc13 zero13)) def Ty14 : Type 1 := ∀ (Ty14 : Type) (nat top bot : Ty14) (arr prod sum : Ty14 → Ty14 → Ty14) , Ty14 def nat14 : Ty14 := λ _ nat14 _ _ _ _ _ => nat14 def top14 : Ty14 := λ _ _ top14 _ _ _ _ => top14 def bot14 : Ty14 := λ _ _ _ bot14 _ _ _ => bot14 def arr14 : Ty14 → Ty14 → Ty14 := λ A B Ty14 nat14 top14 bot14 arr14 prod sum => arr14 (A Ty14 nat14 top14 bot14 arr14 prod sum) (B Ty14 nat14 top14 bot14 arr14 prod sum) def prod14 : Ty14 → Ty14 → Ty14 := λ A B Ty14 nat14 top14 bot14 arr14 prod14 sum => prod14 (A Ty14 nat14 top14 bot14 arr14 prod14 sum) (B Ty14 nat14 top14 bot14 arr14 prod14 sum) def sum14 : Ty14 → Ty14 → Ty14 := λ A B Ty14 nat14 top14 bot14 arr14 prod14 sum14 => sum14 (A Ty14 nat14 top14 bot14 arr14 prod14 sum14) (B Ty14 nat14 top14 bot14 arr14 prod14 sum14) def Con14 : Type 1 := ∀ (Con14 : Type) (nil : Con14) (snoc : Con14 → Ty14 → Con14) , Con14 def nil14 : Con14 := λ Con14 nil14 snoc => nil14 def snoc14 : Con14 → Ty14 → Con14 := λ Γ A Con14 nil14 snoc14 => snoc14 (Γ Con14 nil14 snoc14) A def Var14 : Con14 → Ty14 → Type 1 := λ Γ A => ∀ (Var14 : Con14 → Ty14 → Type) (vz : ∀{Γ A}, Var14 (snoc14 Γ A) A) (vs : ∀{Γ B A}, Var14 Γ A → Var14 (snoc14 Γ B) A) , Var14 Γ A def vz14 : ∀ {Γ A}, Var14 (snoc14 Γ A) A := λ Var14 vz14 vs => vz14 def vs14 : ∀ {Γ B A}, Var14 Γ A → Var14 (snoc14 Γ B) A := λ x Var14 vz14 vs14 => vs14 (x Var14 vz14 vs14) def Tm14 : Con14 → Ty14 → Type 1 := λ Γ A => ∀ (Tm14 : Con14 → Ty14 → Type) (var : ∀ {Γ A}, Var14 Γ A → Tm14 Γ A) (lam : ∀ {Γ A B}, (Tm14 (snoc14 Γ A) B → Tm14 Γ (arr14 A B))) (app : ∀ {Γ A B} , Tm14 Γ (arr14 A B) → Tm14 Γ A → Tm14 Γ B) (tt : ∀ {Γ} , Tm14 Γ top14) (pair : ∀ {Γ A B} , Tm14 Γ A → Tm14 Γ B → Tm14 Γ (prod14 A B)) (fst : ∀ {Γ A B} , Tm14 Γ (prod14 A B) → Tm14 Γ A) (snd : ∀ {Γ A B} , Tm14 Γ (prod14 A B) → Tm14 Γ B) (left : ∀ {Γ A B} , Tm14 Γ A → Tm14 Γ (sum14 A B)) (right : ∀ {Γ A B} , Tm14 Γ B → Tm14 Γ (sum14 A B)) (case : ∀ {Γ A B C} , Tm14 Γ (sum14 A B) → Tm14 Γ (arr14 A C) → Tm14 Γ (arr14 B C) → Tm14 Γ C) (zero : ∀ {Γ} , Tm14 Γ nat14) (suc : ∀ {Γ} , Tm14 Γ nat14 → Tm14 Γ nat14) (rec : ∀ {Γ A} , Tm14 Γ nat14 → Tm14 Γ (arr14 nat14 (arr14 A A)) → Tm14 Γ A → Tm14 Γ A) , Tm14 Γ A def var14 : ∀ {Γ A}, Var14 Γ A → Tm14 Γ A := λ x Tm14 var14 lam app tt pair fst snd left right case zero suc rec => var14 x def lam14 : ∀ {Γ A B} , Tm14 (snoc14 Γ A) B → Tm14 Γ (arr14 A B) := λ t Tm14 var14 lam14 app tt pair fst snd left right case zero suc rec => lam14 (t Tm14 var14 lam14 app tt pair fst snd left right case zero suc rec) def app14 : ∀ {Γ A B} , Tm14 Γ (arr14 A B) → Tm14 Γ A → Tm14 Γ B := λ t u Tm14 var14 lam14 app14 tt pair fst snd left right case zero suc rec => app14 (t Tm14 var14 lam14 app14 tt pair fst snd left right case zero suc rec) (u Tm14 var14 lam14 app14 tt pair fst snd left right case zero suc rec) def tt14 : ∀ {Γ} , Tm14 Γ top14 := λ Tm14 var14 lam14 app14 tt14 pair fst snd left right case zero suc rec => tt14 def pair14 : ∀ {Γ A B} , Tm14 Γ A → Tm14 Γ B → Tm14 Γ (prod14 A B) := λ t u Tm14 var14 lam14 app14 tt14 pair14 fst snd left right case zero suc rec => pair14 (t Tm14 var14 lam14 app14 tt14 pair14 fst snd left right case zero suc rec) (u Tm14 var14 lam14 app14 tt14 pair14 fst snd left right case zero suc rec) def fst14 : ∀ {Γ A B} , Tm14 Γ (prod14 A B) → Tm14 Γ A := λ t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd left right case zero suc rec => fst14 (t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd left right case zero suc rec) def snd14 : ∀ {Γ A B} , Tm14 Γ (prod14 A B) → Tm14 Γ B := λ t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left right case zero suc rec => snd14 (t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left right case zero suc rec) def left14 : ∀ {Γ A B} , Tm14 Γ A → Tm14 Γ (sum14 A B) := λ t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right case zero suc rec => left14 (t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right case zero suc rec) def right14 : ∀ {Γ A B} , Tm14 Γ B → Tm14 Γ (sum14 A B) := λ t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case zero suc rec => right14 (t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case zero suc rec) def case14 : ∀ {Γ A B C} , Tm14 Γ (sum14 A B) → Tm14 Γ (arr14 A C) → Tm14 Γ (arr14 B C) → Tm14 Γ C := λ t u v Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case14 zero suc rec => case14 (t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case14 zero suc rec) (u Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case14 zero suc rec) (v Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case14 zero suc rec) def zero14 : ∀ {Γ} , Tm14 Γ nat14 := λ Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case14 zero14 suc rec => zero14 def suc14 : ∀ {Γ} , Tm14 Γ nat14 → Tm14 Γ nat14 := λ t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case14 zero14 suc14 rec => suc14 (t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case14 zero14 suc14 rec) def rec14 : ∀ {Γ A} , Tm14 Γ nat14 → Tm14 Γ (arr14 nat14 (arr14 A A)) → Tm14 Γ A → Tm14 Γ A := λ t u v Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case14 zero14 suc14 rec14 => rec14 (t Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case14 zero14 suc14 rec14) (u Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case14 zero14 suc14 rec14) (v Tm14 var14 lam14 app14 tt14 pair14 fst14 snd14 left14 right14 case14 zero14 suc14 rec14) def v014 : ∀ {Γ A}, Tm14 (snoc14 Γ A) A := var14 vz14 def v114 : ∀ {Γ A B}, Tm14 (snoc14 (snoc14 Γ A) B) A := var14 (vs14 vz14) def v214 : ∀ {Γ A B C}, Tm14 (snoc14 (snoc14 (snoc14 Γ A) B) C) A := var14 (vs14 (vs14 vz14)) def v314 : ∀ {Γ A B C D}, Tm14 (snoc14 (snoc14 (snoc14 (snoc14 Γ A) B) C) D) A := var14 (vs14 (vs14 (vs14 vz14))) def tbool14 : Ty14 := sum14 top14 top14 def ttrue14 : ∀ {Γ}, Tm14 Γ tbool14 := left14 tt14 def tfalse14 : ∀ {Γ}, Tm14 Γ tbool14 := right14 tt14 def ifthenelse14 : ∀ {Γ A}, Tm14 Γ (arr14 tbool14 (arr14 A (arr14 A A))) := lam14 (lam14 (lam14 (case14 v214 (lam14 v214) (lam14 v114)))) def times414 : ∀ {Γ A}, Tm14 Γ (arr14 (arr14 A A) (arr14 A A)) := lam14 (lam14 (app14 v114 (app14 v114 (app14 v114 (app14 v114 v014))))) def add14 : ∀ {Γ}, Tm14 Γ (arr14 nat14 (arr14 nat14 nat14)) := lam14 (rec14 v014 (lam14 (lam14 (lam14 (suc14 (app14 v114 v014))))) (lam14 v014)) def mul14 : ∀ {Γ}, Tm14 Γ (arr14 nat14 (arr14 nat14 nat14)) := lam14 (rec14 v014 (lam14 (lam14 (lam14 (app14 (app14 add14 (app14 v114 v014)) v014)))) (lam14 zero14)) def fact14 : ∀ {Γ}, Tm14 Γ (arr14 nat14 nat14) := lam14 (rec14 v014 (lam14 (lam14 (app14 (app14 mul14 (suc14 v114)) v014))) (suc14 zero14)) def Ty15 : Type 1 := ∀ (Ty15 : Type) (nat top bot : Ty15) (arr prod sum : Ty15 → Ty15 → Ty15) , Ty15 def nat15 : Ty15 := λ _ nat15 _ _ _ _ _ => nat15 def top15 : Ty15 := λ _ _ top15 _ _ _ _ => top15 def bot15 : Ty15 := λ _ _ _ bot15 _ _ _ => bot15 def arr15 : Ty15 → Ty15 → Ty15 := λ A B Ty15 nat15 top15 bot15 arr15 prod sum => arr15 (A Ty15 nat15 top15 bot15 arr15 prod sum) (B Ty15 nat15 top15 bot15 arr15 prod sum) def prod15 : Ty15 → Ty15 → Ty15 := λ A B Ty15 nat15 top15 bot15 arr15 prod15 sum => prod15 (A Ty15 nat15 top15 bot15 arr15 prod15 sum) (B Ty15 nat15 top15 bot15 arr15 prod15 sum) def sum15 : Ty15 → Ty15 → Ty15 := λ A B Ty15 nat15 top15 bot15 arr15 prod15 sum15 => sum15 (A Ty15 nat15 top15 bot15 arr15 prod15 sum15) (B Ty15 nat15 top15 bot15 arr15 prod15 sum15) def Con15 : Type 1 := ∀ (Con15 : Type) (nil : Con15) (snoc : Con15 → Ty15 → Con15) , Con15 def nil15 : Con15 := λ Con15 nil15 snoc => nil15 def snoc15 : Con15 → Ty15 → Con15 := λ Γ A Con15 nil15 snoc15 => snoc15 (Γ Con15 nil15 snoc15) A def Var15 : Con15 → Ty15 → Type 1 := λ Γ A => ∀ (Var15 : Con15 → Ty15 → Type) (vz : ∀{Γ A}, Var15 (snoc15 Γ A) A) (vs : ∀{Γ B A}, Var15 Γ A → Var15 (snoc15 Γ B) A) , Var15 Γ A def vz15 : ∀ {Γ A}, Var15 (snoc15 Γ A) A := λ Var15 vz15 vs => vz15 def vs15 : ∀ {Γ B A}, Var15 Γ A → Var15 (snoc15 Γ B) A := λ x Var15 vz15 vs15 => vs15 (x Var15 vz15 vs15) def Tm15 : Con15 → Ty15 → Type 1 := λ Γ A => ∀ (Tm15 : Con15 → Ty15 → Type) (var : ∀ {Γ A}, Var15 Γ A → Tm15 Γ A) (lam : ∀ {Γ A B}, (Tm15 (snoc15 Γ A) B → Tm15 Γ (arr15 A B))) (app : ∀ {Γ A B} , Tm15 Γ (arr15 A B) → Tm15 Γ A → Tm15 Γ B) (tt : ∀ {Γ} , Tm15 Γ top15) (pair : ∀ {Γ A B} , Tm15 Γ A → Tm15 Γ B → Tm15 Γ (prod15 A B)) (fst : ∀ {Γ A B} , Tm15 Γ (prod15 A B) → Tm15 Γ A) (snd : ∀ {Γ A B} , Tm15 Γ (prod15 A B) → Tm15 Γ B) (left : ∀ {Γ A B} , Tm15 Γ A → Tm15 Γ (sum15 A B)) (right : ∀ {Γ A B} , Tm15 Γ B → Tm15 Γ (sum15 A B)) (case : ∀ {Γ A B C} , Tm15 Γ (sum15 A B) → Tm15 Γ (arr15 A C) → Tm15 Γ (arr15 B C) → Tm15 Γ C) (zero : ∀ {Γ} , Tm15 Γ nat15) (suc : ∀ {Γ} , Tm15 Γ nat15 → Tm15 Γ nat15) (rec : ∀ {Γ A} , Tm15 Γ nat15 → Tm15 Γ (arr15 nat15 (arr15 A A)) → Tm15 Γ A → Tm15 Γ A) , Tm15 Γ A def var15 : ∀ {Γ A}, Var15 Γ A → Tm15 Γ A := λ x Tm15 var15 lam app tt pair fst snd left right case zero suc rec => var15 x def lam15 : ∀ {Γ A B} , Tm15 (snoc15 Γ A) B → Tm15 Γ (arr15 A B) := λ t Tm15 var15 lam15 app tt pair fst snd left right case zero suc rec => lam15 (t Tm15 var15 lam15 app tt pair fst snd left right case zero suc rec) def app15 : ∀ {Γ A B} , Tm15 Γ (arr15 A B) → Tm15 Γ A → Tm15 Γ B := λ t u Tm15 var15 lam15 app15 tt pair fst snd left right case zero suc rec => app15 (t Tm15 var15 lam15 app15 tt pair fst snd left right case zero suc rec) (u Tm15 var15 lam15 app15 tt pair fst snd left right case zero suc rec) def tt15 : ∀ {Γ} , Tm15 Γ top15 := λ Tm15 var15 lam15 app15 tt15 pair fst snd left right case zero suc rec => tt15 def pair15 : ∀ {Γ A B} , Tm15 Γ A → Tm15 Γ B → Tm15 Γ (prod15 A B) := λ t u Tm15 var15 lam15 app15 tt15 pair15 fst snd left right case zero suc rec => pair15 (t Tm15 var15 lam15 app15 tt15 pair15 fst snd left right case zero suc rec) (u Tm15 var15 lam15 app15 tt15 pair15 fst snd left right case zero suc rec) def fst15 : ∀ {Γ A B} , Tm15 Γ (prod15 A B) → Tm15 Γ A := λ t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd left right case zero suc rec => fst15 (t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd left right case zero suc rec) def snd15 : ∀ {Γ A B} , Tm15 Γ (prod15 A B) → Tm15 Γ B := λ t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left right case zero suc rec => snd15 (t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left right case zero suc rec) def left15 : ∀ {Γ A B} , Tm15 Γ A → Tm15 Γ (sum15 A B) := λ t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right case zero suc rec => left15 (t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right case zero suc rec) def right15 : ∀ {Γ A B} , Tm15 Γ B → Tm15 Γ (sum15 A B) := λ t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case zero suc rec => right15 (t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case zero suc rec) def case15 : ∀ {Γ A B C} , Tm15 Γ (sum15 A B) → Tm15 Γ (arr15 A C) → Tm15 Γ (arr15 B C) → Tm15 Γ C := λ t u v Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case15 zero suc rec => case15 (t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case15 zero suc rec) (u Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case15 zero suc rec) (v Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case15 zero suc rec) def zero15 : ∀ {Γ} , Tm15 Γ nat15 := λ Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case15 zero15 suc rec => zero15 def suc15 : ∀ {Γ} , Tm15 Γ nat15 → Tm15 Γ nat15 := λ t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case15 zero15 suc15 rec => suc15 (t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case15 zero15 suc15 rec) def rec15 : ∀ {Γ A} , Tm15 Γ nat15 → Tm15 Γ (arr15 nat15 (arr15 A A)) → Tm15 Γ A → Tm15 Γ A := λ t u v Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case15 zero15 suc15 rec15 => rec15 (t Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case15 zero15 suc15 rec15) (u Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case15 zero15 suc15 rec15) (v Tm15 var15 lam15 app15 tt15 pair15 fst15 snd15 left15 right15 case15 zero15 suc15 rec15) def v015 : ∀ {Γ A}, Tm15 (snoc15 Γ A) A := var15 vz15 def v115 : ∀ {Γ A B}, Tm15 (snoc15 (snoc15 Γ A) B) A := var15 (vs15 vz15) def v215 : ∀ {Γ A B C}, Tm15 (snoc15 (snoc15 (snoc15 Γ A) B) C) A := var15 (vs15 (vs15 vz15)) def v315 : ∀ {Γ A B C D}, Tm15 (snoc15 (snoc15 (snoc15 (snoc15 Γ A) B) C) D) A := var15 (vs15 (vs15 (vs15 vz15))) def tbool15 : Ty15 := sum15 top15 top15 def ttrue15 : ∀ {Γ}, Tm15 Γ tbool15 := left15 tt15 def tfalse15 : ∀ {Γ}, Tm15 Γ tbool15 := right15 tt15 def ifthenelse15 : ∀ {Γ A}, Tm15 Γ (arr15 tbool15 (arr15 A (arr15 A A))) := lam15 (lam15 (lam15 (case15 v215 (lam15 v215) (lam15 v115)))) def times415 : ∀ {Γ A}, Tm15 Γ (arr15 (arr15 A A) (arr15 A A)) := lam15 (lam15 (app15 v115 (app15 v115 (app15 v115 (app15 v115 v015))))) def add15 : ∀ {Γ}, Tm15 Γ (arr15 nat15 (arr15 nat15 nat15)) := lam15 (rec15 v015 (lam15 (lam15 (lam15 (suc15 (app15 v115 v015))))) (lam15 v015)) def mul15 : ∀ {Γ}, Tm15 Γ (arr15 nat15 (arr15 nat15 nat15)) := lam15 (rec15 v015 (lam15 (lam15 (lam15 (app15 (app15 add15 (app15 v115 v015)) v015)))) (lam15 zero15)) def fact15 : ∀ {Γ}, Tm15 Γ (arr15 nat15 nat15) := lam15 (rec15 v015 (lam15 (lam15 (app15 (app15 mul15 (suc15 v115)) v015))) (suc15 zero15)) def Ty16 : Type 1 := ∀ (Ty16 : Type) (nat top bot : Ty16) (arr prod sum : Ty16 → Ty16 → Ty16) , Ty16 def nat16 : Ty16 := λ _ nat16 _ _ _ _ _ => nat16 def top16 : Ty16 := λ _ _ top16 _ _ _ _ => top16 def bot16 : Ty16 := λ _ _ _ bot16 _ _ _ => bot16 def arr16 : Ty16 → Ty16 → Ty16 := λ A B Ty16 nat16 top16 bot16 arr16 prod sum => arr16 (A Ty16 nat16 top16 bot16 arr16 prod sum) (B Ty16 nat16 top16 bot16 arr16 prod sum) def prod16 : Ty16 → Ty16 → Ty16 := λ A B Ty16 nat16 top16 bot16 arr16 prod16 sum => prod16 (A Ty16 nat16 top16 bot16 arr16 prod16 sum) (B Ty16 nat16 top16 bot16 arr16 prod16 sum) def sum16 : Ty16 → Ty16 → Ty16 := λ A B Ty16 nat16 top16 bot16 arr16 prod16 sum16 => sum16 (A Ty16 nat16 top16 bot16 arr16 prod16 sum16) (B Ty16 nat16 top16 bot16 arr16 prod16 sum16) def Con16 : Type 1 := ∀ (Con16 : Type) (nil : Con16) (snoc : Con16 → Ty16 → Con16) , Con16 def nil16 : Con16 := λ Con16 nil16 snoc => nil16 def snoc16 : Con16 → Ty16 → Con16 := λ Γ A Con16 nil16 snoc16 => snoc16 (Γ Con16 nil16 snoc16) A def Var16 : Con16 → Ty16 → Type 1 := λ Γ A => ∀ (Var16 : Con16 → Ty16 → Type) (vz : ∀{Γ A}, Var16 (snoc16 Γ A) A) (vs : ∀{Γ B A}, Var16 Γ A → Var16 (snoc16 Γ B) A) , Var16 Γ A def vz16 : ∀ {Γ A}, Var16 (snoc16 Γ A) A := λ Var16 vz16 vs => vz16 def vs16 : ∀ {Γ B A}, Var16 Γ A → Var16 (snoc16 Γ B) A := λ x Var16 vz16 vs16 => vs16 (x Var16 vz16 vs16) def Tm16 : Con16 → Ty16 → Type 1 := λ Γ A => ∀ (Tm16 : Con16 → Ty16 → Type) (var : ∀ {Γ A}, Var16 Γ A → Tm16 Γ A) (lam : ∀ {Γ A B}, (Tm16 (snoc16 Γ A) B → Tm16 Γ (arr16 A B))) (app : ∀ {Γ A B} , Tm16 Γ (arr16 A B) → Tm16 Γ A → Tm16 Γ B) (tt : ∀ {Γ} , Tm16 Γ top16) (pair : ∀ {Γ A B} , Tm16 Γ A → Tm16 Γ B → Tm16 Γ (prod16 A B)) (fst : ∀ {Γ A B} , Tm16 Γ (prod16 A B) → Tm16 Γ A) (snd : ∀ {Γ A B} , Tm16 Γ (prod16 A B) → Tm16 Γ B) (left : ∀ {Γ A B} , Tm16 Γ A → Tm16 Γ (sum16 A B)) (right : ∀ {Γ A B} , Tm16 Γ B → Tm16 Γ (sum16 A B)) (case : ∀ {Γ A B C} , Tm16 Γ (sum16 A B) → Tm16 Γ (arr16 A C) → Tm16 Γ (arr16 B C) → Tm16 Γ C) (zero : ∀ {Γ} , Tm16 Γ nat16) (suc : ∀ {Γ} , Tm16 Γ nat16 → Tm16 Γ nat16) (rec : ∀ {Γ A} , Tm16 Γ nat16 → Tm16 Γ (arr16 nat16 (arr16 A A)) → Tm16 Γ A → Tm16 Γ A) , Tm16 Γ A def var16 : ∀ {Γ A}, Var16 Γ A → Tm16 Γ A := λ x Tm16 var16 lam app tt pair fst snd left right case zero suc rec => var16 x def lam16 : ∀ {Γ A B} , Tm16 (snoc16 Γ A) B → Tm16 Γ (arr16 A B) := λ t Tm16 var16 lam16 app tt pair fst snd left right case zero suc rec => lam16 (t Tm16 var16 lam16 app tt pair fst snd left right case zero suc rec) def app16 : ∀ {Γ A B} , Tm16 Γ (arr16 A B) → Tm16 Γ A → Tm16 Γ B := λ t u Tm16 var16 lam16 app16 tt pair fst snd left right case zero suc rec => app16 (t Tm16 var16 lam16 app16 tt pair fst snd left right case zero suc rec) (u Tm16 var16 lam16 app16 tt pair fst snd left right case zero suc rec) def tt16 : ∀ {Γ} , Tm16 Γ top16 := λ Tm16 var16 lam16 app16 tt16 pair fst snd left right case zero suc rec => tt16 def pair16 : ∀ {Γ A B} , Tm16 Γ A → Tm16 Γ B → Tm16 Γ (prod16 A B) := λ t u Tm16 var16 lam16 app16 tt16 pair16 fst snd left right case zero suc rec => pair16 (t Tm16 var16 lam16 app16 tt16 pair16 fst snd left right case zero suc rec) (u Tm16 var16 lam16 app16 tt16 pair16 fst snd left right case zero suc rec) def fst16 : ∀ {Γ A B} , Tm16 Γ (prod16 A B) → Tm16 Γ A := λ t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd left right case zero suc rec => fst16 (t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd left right case zero suc rec) def snd16 : ∀ {Γ A B} , Tm16 Γ (prod16 A B) → Tm16 Γ B := λ t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left right case zero suc rec => snd16 (t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left right case zero suc rec) def left16 : ∀ {Γ A B} , Tm16 Γ A → Tm16 Γ (sum16 A B) := λ t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right case zero suc rec => left16 (t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right case zero suc rec) def right16 : ∀ {Γ A B} , Tm16 Γ B → Tm16 Γ (sum16 A B) := λ t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case zero suc rec => right16 (t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case zero suc rec) def case16 : ∀ {Γ A B C} , Tm16 Γ (sum16 A B) → Tm16 Γ (arr16 A C) → Tm16 Γ (arr16 B C) → Tm16 Γ C := λ t u v Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case16 zero suc rec => case16 (t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case16 zero suc rec) (u Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case16 zero suc rec) (v Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case16 zero suc rec) def zero16 : ∀ {Γ} , Tm16 Γ nat16 := λ Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case16 zero16 suc rec => zero16 def suc16 : ∀ {Γ} , Tm16 Γ nat16 → Tm16 Γ nat16 := λ t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case16 zero16 suc16 rec => suc16 (t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case16 zero16 suc16 rec) def rec16 : ∀ {Γ A} , Tm16 Γ nat16 → Tm16 Γ (arr16 nat16 (arr16 A A)) → Tm16 Γ A → Tm16 Γ A := λ t u v Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case16 zero16 suc16 rec16 => rec16 (t Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case16 zero16 suc16 rec16) (u Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case16 zero16 suc16 rec16) (v Tm16 var16 lam16 app16 tt16 pair16 fst16 snd16 left16 right16 case16 zero16 suc16 rec16) def v016 : ∀ {Γ A}, Tm16 (snoc16 Γ A) A := var16 vz16 def v116 : ∀ {Γ A B}, Tm16 (snoc16 (snoc16 Γ A) B) A := var16 (vs16 vz16) def v216 : ∀ {Γ A B C}, Tm16 (snoc16 (snoc16 (snoc16 Γ A) B) C) A := var16 (vs16 (vs16 vz16)) def v316 : ∀ {Γ A B C D}, Tm16 (snoc16 (snoc16 (snoc16 (snoc16 Γ A) B) C) D) A := var16 (vs16 (vs16 (vs16 vz16))) def tbool16 : Ty16 := sum16 top16 top16 def ttrue16 : ∀ {Γ}, Tm16 Γ tbool16 := left16 tt16 def tfalse16 : ∀ {Γ}, Tm16 Γ tbool16 := right16 tt16 def ifthenelse16 : ∀ {Γ A}, Tm16 Γ (arr16 tbool16 (arr16 A (arr16 A A))) := lam16 (lam16 (lam16 (case16 v216 (lam16 v216) (lam16 v116)))) def times416 : ∀ {Γ A}, Tm16 Γ (arr16 (arr16 A A) (arr16 A A)) := lam16 (lam16 (app16 v116 (app16 v116 (app16 v116 (app16 v116 v016))))) def add16 : ∀ {Γ}, Tm16 Γ (arr16 nat16 (arr16 nat16 nat16)) := lam16 (rec16 v016 (lam16 (lam16 (lam16 (suc16 (app16 v116 v016))))) (lam16 v016)) def mul16 : ∀ {Γ}, Tm16 Γ (arr16 nat16 (arr16 nat16 nat16)) := lam16 (rec16 v016 (lam16 (lam16 (lam16 (app16 (app16 add16 (app16 v116 v016)) v016)))) (lam16 zero16)) def fact16 : ∀ {Γ}, Tm16 Γ (arr16 nat16 nat16) := lam16 (rec16 v016 (lam16 (lam16 (app16 (app16 mul16 (suc16 v116)) v016))) (suc16 zero16)) def Ty17 : Type 1 := ∀ (Ty17 : Type) (nat top bot : Ty17) (arr prod sum : Ty17 → Ty17 → Ty17) , Ty17 def nat17 : Ty17 := λ _ nat17 _ _ _ _ _ => nat17 def top17 : Ty17 := λ _ _ top17 _ _ _ _ => top17 def bot17 : Ty17 := λ _ _ _ bot17 _ _ _ => bot17 def arr17 : Ty17 → Ty17 → Ty17 := λ A B Ty17 nat17 top17 bot17 arr17 prod sum => arr17 (A Ty17 nat17 top17 bot17 arr17 prod sum) (B Ty17 nat17 top17 bot17 arr17 prod sum) def prod17 : Ty17 → Ty17 → Ty17 := λ A B Ty17 nat17 top17 bot17 arr17 prod17 sum => prod17 (A Ty17 nat17 top17 bot17 arr17 prod17 sum) (B Ty17 nat17 top17 bot17 arr17 prod17 sum) def sum17 : Ty17 → Ty17 → Ty17 := λ A B Ty17 nat17 top17 bot17 arr17 prod17 sum17 => sum17 (A Ty17 nat17 top17 bot17 arr17 prod17 sum17) (B Ty17 nat17 top17 bot17 arr17 prod17 sum17) def Con17 : Type 1 := ∀ (Con17 : Type) (nil : Con17) (snoc : Con17 → Ty17 → Con17) , Con17 def nil17 : Con17 := λ Con17 nil17 snoc => nil17 def snoc17 : Con17 → Ty17 → Con17 := λ Γ A Con17 nil17 snoc17 => snoc17 (Γ Con17 nil17 snoc17) A def Var17 : Con17 → Ty17 → Type 1 := λ Γ A => ∀ (Var17 : Con17 → Ty17 → Type) (vz : ∀{Γ A}, Var17 (snoc17 Γ A) A) (vs : ∀{Γ B A}, Var17 Γ A → Var17 (snoc17 Γ B) A) , Var17 Γ A def vz17 : ∀ {Γ A}, Var17 (snoc17 Γ A) A := λ Var17 vz17 vs => vz17 def vs17 : ∀ {Γ B A}, Var17 Γ A → Var17 (snoc17 Γ B) A := λ x Var17 vz17 vs17 => vs17 (x Var17 vz17 vs17) def Tm17 : Con17 → Ty17 → Type 1 := λ Γ A => ∀ (Tm17 : Con17 → Ty17 → Type) (var : ∀ {Γ A}, Var17 Γ A → Tm17 Γ A) (lam : ∀ {Γ A B}, (Tm17 (snoc17 Γ A) B → Tm17 Γ (arr17 A B))) (app : ∀ {Γ A B} , Tm17 Γ (arr17 A B) → Tm17 Γ A → Tm17 Γ B) (tt : ∀ {Γ} , Tm17 Γ top17) (pair : ∀ {Γ A B} , Tm17 Γ A → Tm17 Γ B → Tm17 Γ (prod17 A B)) (fst : ∀ {Γ A B} , Tm17 Γ (prod17 A B) → Tm17 Γ A) (snd : ∀ {Γ A B} , Tm17 Γ (prod17 A B) → Tm17 Γ B) (left : ∀ {Γ A B} , Tm17 Γ A → Tm17 Γ (sum17 A B)) (right : ∀ {Γ A B} , Tm17 Γ B → Tm17 Γ (sum17 A B)) (case : ∀ {Γ A B C} , Tm17 Γ (sum17 A B) → Tm17 Γ (arr17 A C) → Tm17 Γ (arr17 B C) → Tm17 Γ C) (zero : ∀ {Γ} , Tm17 Γ nat17) (suc : ∀ {Γ} , Tm17 Γ nat17 → Tm17 Γ nat17) (rec : ∀ {Γ A} , Tm17 Γ nat17 → Tm17 Γ (arr17 nat17 (arr17 A A)) → Tm17 Γ A → Tm17 Γ A) , Tm17 Γ A def var17 : ∀ {Γ A}, Var17 Γ A → Tm17 Γ A := λ x Tm17 var17 lam app tt pair fst snd left right case zero suc rec => var17 x def lam17 : ∀ {Γ A B} , Tm17 (snoc17 Γ A) B → Tm17 Γ (arr17 A B) := λ t Tm17 var17 lam17 app tt pair fst snd left right case zero suc rec => lam17 (t Tm17 var17 lam17 app tt pair fst snd left right case zero suc rec) def app17 : ∀ {Γ A B} , Tm17 Γ (arr17 A B) → Tm17 Γ A → Tm17 Γ B := λ t u Tm17 var17 lam17 app17 tt pair fst snd left right case zero suc rec => app17 (t Tm17 var17 lam17 app17 tt pair fst snd left right case zero suc rec) (u Tm17 var17 lam17 app17 tt pair fst snd left right case zero suc rec) def tt17 : ∀ {Γ} , Tm17 Γ top17 := λ Tm17 var17 lam17 app17 tt17 pair fst snd left right case zero suc rec => tt17 def pair17 : ∀ {Γ A B} , Tm17 Γ A → Tm17 Γ B → Tm17 Γ (prod17 A B) := λ t u Tm17 var17 lam17 app17 tt17 pair17 fst snd left right case zero suc rec => pair17 (t Tm17 var17 lam17 app17 tt17 pair17 fst snd left right case zero suc rec) (u Tm17 var17 lam17 app17 tt17 pair17 fst snd left right case zero suc rec) def fst17 : ∀ {Γ A B} , Tm17 Γ (prod17 A B) → Tm17 Γ A := λ t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd left right case zero suc rec => fst17 (t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd left right case zero suc rec) def snd17 : ∀ {Γ A B} , Tm17 Γ (prod17 A B) → Tm17 Γ B := λ t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left right case zero suc rec => snd17 (t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left right case zero suc rec) def left17 : ∀ {Γ A B} , Tm17 Γ A → Tm17 Γ (sum17 A B) := λ t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right case zero suc rec => left17 (t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right case zero suc rec) def right17 : ∀ {Γ A B} , Tm17 Γ B → Tm17 Γ (sum17 A B) := λ t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case zero suc rec => right17 (t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case zero suc rec) def case17 : ∀ {Γ A B C} , Tm17 Γ (sum17 A B) → Tm17 Γ (arr17 A C) → Tm17 Γ (arr17 B C) → Tm17 Γ C := λ t u v Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case17 zero suc rec => case17 (t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case17 zero suc rec) (u Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case17 zero suc rec) (v Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case17 zero suc rec) def zero17 : ∀ {Γ} , Tm17 Γ nat17 := λ Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case17 zero17 suc rec => zero17 def suc17 : ∀ {Γ} , Tm17 Γ nat17 → Tm17 Γ nat17 := λ t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case17 zero17 suc17 rec => suc17 (t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case17 zero17 suc17 rec) def rec17 : ∀ {Γ A} , Tm17 Γ nat17 → Tm17 Γ (arr17 nat17 (arr17 A A)) → Tm17 Γ A → Tm17 Γ A := λ t u v Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case17 zero17 suc17 rec17 => rec17 (t Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case17 zero17 suc17 rec17) (u Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case17 zero17 suc17 rec17) (v Tm17 var17 lam17 app17 tt17 pair17 fst17 snd17 left17 right17 case17 zero17 suc17 rec17) def v017 : ∀ {Γ A}, Tm17 (snoc17 Γ A) A := var17 vz17 def v117 : ∀ {Γ A B}, Tm17 (snoc17 (snoc17 Γ A) B) A := var17 (vs17 vz17) def v217 : ∀ {Γ A B C}, Tm17 (snoc17 (snoc17 (snoc17 Γ A) B) C) A := var17 (vs17 (vs17 vz17)) def v317 : ∀ {Γ A B C D}, Tm17 (snoc17 (snoc17 (snoc17 (snoc17 Γ A) B) C) D) A := var17 (vs17 (vs17 (vs17 vz17))) def tbool17 : Ty17 := sum17 top17 top17 def ttrue17 : ∀ {Γ}, Tm17 Γ tbool17 := left17 tt17 def tfalse17 : ∀ {Γ}, Tm17 Γ tbool17 := right17 tt17 def ifthenelse17 : ∀ {Γ A}, Tm17 Γ (arr17 tbool17 (arr17 A (arr17 A A))) := lam17 (lam17 (lam17 (case17 v217 (lam17 v217) (lam17 v117)))) def times417 : ∀ {Γ A}, Tm17 Γ (arr17 (arr17 A A) (arr17 A A)) := lam17 (lam17 (app17 v117 (app17 v117 (app17 v117 (app17 v117 v017))))) def add17 : ∀ {Γ}, Tm17 Γ (arr17 nat17 (arr17 nat17 nat17)) := lam17 (rec17 v017 (lam17 (lam17 (lam17 (suc17 (app17 v117 v017))))) (lam17 v017)) def mul17 : ∀ {Γ}, Tm17 Γ (arr17 nat17 (arr17 nat17 nat17)) := lam17 (rec17 v017 (lam17 (lam17 (lam17 (app17 (app17 add17 (app17 v117 v017)) v017)))) (lam17 zero17)) def fact17 : ∀ {Γ}, Tm17 Γ (arr17 nat17 nat17) := lam17 (rec17 v017 (lam17 (lam17 (app17 (app17 mul17 (suc17 v117)) v017))) (suc17 zero17)) def Ty18 : Type 1 := ∀ (Ty18 : Type) (nat top bot : Ty18) (arr prod sum : Ty18 → Ty18 → Ty18) , Ty18 def nat18 : Ty18 := λ _ nat18 _ _ _ _ _ => nat18 def top18 : Ty18 := λ _ _ top18 _ _ _ _ => top18 def bot18 : Ty18 := λ _ _ _ bot18 _ _ _ => bot18 def arr18 : Ty18 → Ty18 → Ty18 := λ A B Ty18 nat18 top18 bot18 arr18 prod sum => arr18 (A Ty18 nat18 top18 bot18 arr18 prod sum) (B Ty18 nat18 top18 bot18 arr18 prod sum) def prod18 : Ty18 → Ty18 → Ty18 := λ A B Ty18 nat18 top18 bot18 arr18 prod18 sum => prod18 (A Ty18 nat18 top18 bot18 arr18 prod18 sum) (B Ty18 nat18 top18 bot18 arr18 prod18 sum) def sum18 : Ty18 → Ty18 → Ty18 := λ A B Ty18 nat18 top18 bot18 arr18 prod18 sum18 => sum18 (A Ty18 nat18 top18 bot18 arr18 prod18 sum18) (B Ty18 nat18 top18 bot18 arr18 prod18 sum18) def Con18 : Type 1 := ∀ (Con18 : Type) (nil : Con18) (snoc : Con18 → Ty18 → Con18) , Con18 def nil18 : Con18 := λ Con18 nil18 snoc => nil18 def snoc18 : Con18 → Ty18 → Con18 := λ Γ A Con18 nil18 snoc18 => snoc18 (Γ Con18 nil18 snoc18) A def Var18 : Con18 → Ty18 → Type 1 := λ Γ A => ∀ (Var18 : Con18 → Ty18 → Type) (vz : ∀{Γ A}, Var18 (snoc18 Γ A) A) (vs : ∀{Γ B A}, Var18 Γ A → Var18 (snoc18 Γ B) A) , Var18 Γ A def vz18 : ∀ {Γ A}, Var18 (snoc18 Γ A) A := λ Var18 vz18 vs => vz18 def vs18 : ∀ {Γ B A}, Var18 Γ A → Var18 (snoc18 Γ B) A := λ x Var18 vz18 vs18 => vs18 (x Var18 vz18 vs18) def Tm18 : Con18 → Ty18 → Type 1 := λ Γ A => ∀ (Tm18 : Con18 → Ty18 → Type) (var : ∀ {Γ A}, Var18 Γ A → Tm18 Γ A) (lam : ∀ {Γ A B}, (Tm18 (snoc18 Γ A) B → Tm18 Γ (arr18 A B))) (app : ∀ {Γ A B} , Tm18 Γ (arr18 A B) → Tm18 Γ A → Tm18 Γ B) (tt : ∀ {Γ} , Tm18 Γ top18) (pair : ∀ {Γ A B} , Tm18 Γ A → Tm18 Γ B → Tm18 Γ (prod18 A B)) (fst : ∀ {Γ A B} , Tm18 Γ (prod18 A B) → Tm18 Γ A) (snd : ∀ {Γ A B} , Tm18 Γ (prod18 A B) → Tm18 Γ B) (left : ∀ {Γ A B} , Tm18 Γ A → Tm18 Γ (sum18 A B)) (right : ∀ {Γ A B} , Tm18 Γ B → Tm18 Γ (sum18 A B)) (case : ∀ {Γ A B C} , Tm18 Γ (sum18 A B) → Tm18 Γ (arr18 A C) → Tm18 Γ (arr18 B C) → Tm18 Γ C) (zero : ∀ {Γ} , Tm18 Γ nat18) (suc : ∀ {Γ} , Tm18 Γ nat18 → Tm18 Γ nat18) (rec : ∀ {Γ A} , Tm18 Γ nat18 → Tm18 Γ (arr18 nat18 (arr18 A A)) → Tm18 Γ A → Tm18 Γ A) , Tm18 Γ A def var18 : ∀ {Γ A}, Var18 Γ A → Tm18 Γ A := λ x Tm18 var18 lam app tt pair fst snd left right case zero suc rec => var18 x def lam18 : ∀ {Γ A B} , Tm18 (snoc18 Γ A) B → Tm18 Γ (arr18 A B) := λ t Tm18 var18 lam18 app tt pair fst snd left right case zero suc rec => lam18 (t Tm18 var18 lam18 app tt pair fst snd left right case zero suc rec) def app18 : ∀ {Γ A B} , Tm18 Γ (arr18 A B) → Tm18 Γ A → Tm18 Γ B := λ t u Tm18 var18 lam18 app18 tt pair fst snd left right case zero suc rec => app18 (t Tm18 var18 lam18 app18 tt pair fst snd left right case zero suc rec) (u Tm18 var18 lam18 app18 tt pair fst snd left right case zero suc rec) def tt18 : ∀ {Γ} , Tm18 Γ top18 := λ Tm18 var18 lam18 app18 tt18 pair fst snd left right case zero suc rec => tt18 def pair18 : ∀ {Γ A B} , Tm18 Γ A → Tm18 Γ B → Tm18 Γ (prod18 A B) := λ t u Tm18 var18 lam18 app18 tt18 pair18 fst snd left right case zero suc rec => pair18 (t Tm18 var18 lam18 app18 tt18 pair18 fst snd left right case zero suc rec) (u Tm18 var18 lam18 app18 tt18 pair18 fst snd left right case zero suc rec) def fst18 : ∀ {Γ A B} , Tm18 Γ (prod18 A B) → Tm18 Γ A := λ t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd left right case zero suc rec => fst18 (t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd left right case zero suc rec) def snd18 : ∀ {Γ A B} , Tm18 Γ (prod18 A B) → Tm18 Γ B := λ t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left right case zero suc rec => snd18 (t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left right case zero suc rec) def left18 : ∀ {Γ A B} , Tm18 Γ A → Tm18 Γ (sum18 A B) := λ t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right case zero suc rec => left18 (t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right case zero suc rec) def right18 : ∀ {Γ A B} , Tm18 Γ B → Tm18 Γ (sum18 A B) := λ t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case zero suc rec => right18 (t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case zero suc rec) def case18 : ∀ {Γ A B C} , Tm18 Γ (sum18 A B) → Tm18 Γ (arr18 A C) → Tm18 Γ (arr18 B C) → Tm18 Γ C := λ t u v Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case18 zero suc rec => case18 (t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case18 zero suc rec) (u Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case18 zero suc rec) (v Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case18 zero suc rec) def zero18 : ∀ {Γ} , Tm18 Γ nat18 := λ Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case18 zero18 suc rec => zero18 def suc18 : ∀ {Γ} , Tm18 Γ nat18 → Tm18 Γ nat18 := λ t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case18 zero18 suc18 rec => suc18 (t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case18 zero18 suc18 rec) def rec18 : ∀ {Γ A} , Tm18 Γ nat18 → Tm18 Γ (arr18 nat18 (arr18 A A)) → Tm18 Γ A → Tm18 Γ A := λ t u v Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case18 zero18 suc18 rec18 => rec18 (t Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case18 zero18 suc18 rec18) (u Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case18 zero18 suc18 rec18) (v Tm18 var18 lam18 app18 tt18 pair18 fst18 snd18 left18 right18 case18 zero18 suc18 rec18) def v018 : ∀ {Γ A}, Tm18 (snoc18 Γ A) A := var18 vz18 def v118 : ∀ {Γ A B}, Tm18 (snoc18 (snoc18 Γ A) B) A := var18 (vs18 vz18) def v218 : ∀ {Γ A B C}, Tm18 (snoc18 (snoc18 (snoc18 Γ A) B) C) A := var18 (vs18 (vs18 vz18)) def v318 : ∀ {Γ A B C D}, Tm18 (snoc18 (snoc18 (snoc18 (snoc18 Γ A) B) C) D) A := var18 (vs18 (vs18 (vs18 vz18))) def tbool18 : Ty18 := sum18 top18 top18 def ttrue18 : ∀ {Γ}, Tm18 Γ tbool18 := left18 tt18 def tfalse18 : ∀ {Γ}, Tm18 Γ tbool18 := right18 tt18 def ifthenelse18 : ∀ {Γ A}, Tm18 Γ (arr18 tbool18 (arr18 A (arr18 A A))) := lam18 (lam18 (lam18 (case18 v218 (lam18 v218) (lam18 v118)))) def times418 : ∀ {Γ A}, Tm18 Γ (arr18 (arr18 A A) (arr18 A A)) := lam18 (lam18 (app18 v118 (app18 v118 (app18 v118 (app18 v118 v018))))) def add18 : ∀ {Γ}, Tm18 Γ (arr18 nat18 (arr18 nat18 nat18)) := lam18 (rec18 v018 (lam18 (lam18 (lam18 (suc18 (app18 v118 v018))))) (lam18 v018)) def mul18 : ∀ {Γ}, Tm18 Γ (arr18 nat18 (arr18 nat18 nat18)) := lam18 (rec18 v018 (lam18 (lam18 (lam18 (app18 (app18 add18 (app18 v118 v018)) v018)))) (lam18 zero18)) def fact18 : ∀ {Γ}, Tm18 Γ (arr18 nat18 nat18) := lam18 (rec18 v018 (lam18 (lam18 (app18 (app18 mul18 (suc18 v118)) v018))) (suc18 zero18)) def Ty19 : Type 1 := ∀ (Ty19 : Type) (nat top bot : Ty19) (arr prod sum : Ty19 → Ty19 → Ty19) , Ty19 def nat19 : Ty19 := λ _ nat19 _ _ _ _ _ => nat19 def top19 : Ty19 := λ _ _ top19 _ _ _ _ => top19 def bot19 : Ty19 := λ _ _ _ bot19 _ _ _ => bot19 def arr19 : Ty19 → Ty19 → Ty19 := λ A B Ty19 nat19 top19 bot19 arr19 prod sum => arr19 (A Ty19 nat19 top19 bot19 arr19 prod sum) (B Ty19 nat19 top19 bot19 arr19 prod sum) def prod19 : Ty19 → Ty19 → Ty19 := λ A B Ty19 nat19 top19 bot19 arr19 prod19 sum => prod19 (A Ty19 nat19 top19 bot19 arr19 prod19 sum) (B Ty19 nat19 top19 bot19 arr19 prod19 sum) def sum19 : Ty19 → Ty19 → Ty19 := λ A B Ty19 nat19 top19 bot19 arr19 prod19 sum19 => sum19 (A Ty19 nat19 top19 bot19 arr19 prod19 sum19) (B Ty19 nat19 top19 bot19 arr19 prod19 sum19) def Con19 : Type 1 := ∀ (Con19 : Type) (nil : Con19) (snoc : Con19 → Ty19 → Con19) , Con19 def nil19 : Con19 := λ Con19 nil19 snoc => nil19 def snoc19 : Con19 → Ty19 → Con19 := λ Γ A Con19 nil19 snoc19 => snoc19 (Γ Con19 nil19 snoc19) A def Var19 : Con19 → Ty19 → Type 1 := λ Γ A => ∀ (Var19 : Con19 → Ty19 → Type) (vz : ∀{Γ A}, Var19 (snoc19 Γ A) A) (vs : ∀{Γ B A}, Var19 Γ A → Var19 (snoc19 Γ B) A) , Var19 Γ A def vz19 : ∀ {Γ A}, Var19 (snoc19 Γ A) A := λ Var19 vz19 vs => vz19 def vs19 : ∀ {Γ B A}, Var19 Γ A → Var19 (snoc19 Γ B) A := λ x Var19 vz19 vs19 => vs19 (x Var19 vz19 vs19) def Tm19 : Con19 → Ty19 → Type 1 := λ Γ A => ∀ (Tm19 : Con19 → Ty19 → Type) (var : ∀ {Γ A}, Var19 Γ A → Tm19 Γ A) (lam : ∀ {Γ A B}, (Tm19 (snoc19 Γ A) B → Tm19 Γ (arr19 A B))) (app : ∀ {Γ A B} , Tm19 Γ (arr19 A B) → Tm19 Γ A → Tm19 Γ B) (tt : ∀ {Γ} , Tm19 Γ top19) (pair : ∀ {Γ A B} , Tm19 Γ A → Tm19 Γ B → Tm19 Γ (prod19 A B)) (fst : ∀ {Γ A B} , Tm19 Γ (prod19 A B) → Tm19 Γ A) (snd : ∀ {Γ A B} , Tm19 Γ (prod19 A B) → Tm19 Γ B) (left : ∀ {Γ A B} , Tm19 Γ A → Tm19 Γ (sum19 A B)) (right : ∀ {Γ A B} , Tm19 Γ B → Tm19 Γ (sum19 A B)) (case : ∀ {Γ A B C} , Tm19 Γ (sum19 A B) → Tm19 Γ (arr19 A C) → Tm19 Γ (arr19 B C) → Tm19 Γ C) (zero : ∀ {Γ} , Tm19 Γ nat19) (suc : ∀ {Γ} , Tm19 Γ nat19 → Tm19 Γ nat19) (rec : ∀ {Γ A} , Tm19 Γ nat19 → Tm19 Γ (arr19 nat19 (arr19 A A)) → Tm19 Γ A → Tm19 Γ A) , Tm19 Γ A def var19 : ∀ {Γ A}, Var19 Γ A → Tm19 Γ A := λ x Tm19 var19 lam app tt pair fst snd left right case zero suc rec => var19 x def lam19 : ∀ {Γ A B} , Tm19 (snoc19 Γ A) B → Tm19 Γ (arr19 A B) := λ t Tm19 var19 lam19 app tt pair fst snd left right case zero suc rec => lam19 (t Tm19 var19 lam19 app tt pair fst snd left right case zero suc rec) def app19 : ∀ {Γ A B} , Tm19 Γ (arr19 A B) → Tm19 Γ A → Tm19 Γ B := λ t u Tm19 var19 lam19 app19 tt pair fst snd left right case zero suc rec => app19 (t Tm19 var19 lam19 app19 tt pair fst snd left right case zero suc rec) (u Tm19 var19 lam19 app19 tt pair fst snd left right case zero suc rec) def tt19 : ∀ {Γ} , Tm19 Γ top19 := λ Tm19 var19 lam19 app19 tt19 pair fst snd left right case zero suc rec => tt19 def pair19 : ∀ {Γ A B} , Tm19 Γ A → Tm19 Γ B → Tm19 Γ (prod19 A B) := λ t u Tm19 var19 lam19 app19 tt19 pair19 fst snd left right case zero suc rec => pair19 (t Tm19 var19 lam19 app19 tt19 pair19 fst snd left right case zero suc rec) (u Tm19 var19 lam19 app19 tt19 pair19 fst snd left right case zero suc rec) def fst19 : ∀ {Γ A B} , Tm19 Γ (prod19 A B) → Tm19 Γ A := λ t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd left right case zero suc rec => fst19 (t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd left right case zero suc rec) def snd19 : ∀ {Γ A B} , Tm19 Γ (prod19 A B) → Tm19 Γ B := λ t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left right case zero suc rec => snd19 (t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left right case zero suc rec) def left19 : ∀ {Γ A B} , Tm19 Γ A → Tm19 Γ (sum19 A B) := λ t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right case zero suc rec => left19 (t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right case zero suc rec) def right19 : ∀ {Γ A B} , Tm19 Γ B → Tm19 Γ (sum19 A B) := λ t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case zero suc rec => right19 (t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case zero suc rec) def case19 : ∀ {Γ A B C} , Tm19 Γ (sum19 A B) → Tm19 Γ (arr19 A C) → Tm19 Γ (arr19 B C) → Tm19 Γ C := λ t u v Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case19 zero suc rec => case19 (t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case19 zero suc rec) (u Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case19 zero suc rec) (v Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case19 zero suc rec) def zero19 : ∀ {Γ} , Tm19 Γ nat19 := λ Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case19 zero19 suc rec => zero19 def suc19 : ∀ {Γ} , Tm19 Γ nat19 → Tm19 Γ nat19 := λ t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case19 zero19 suc19 rec => suc19 (t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case19 zero19 suc19 rec) def rec19 : ∀ {Γ A} , Tm19 Γ nat19 → Tm19 Γ (arr19 nat19 (arr19 A A)) → Tm19 Γ A → Tm19 Γ A := λ t u v Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case19 zero19 suc19 rec19 => rec19 (t Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case19 zero19 suc19 rec19) (u Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case19 zero19 suc19 rec19) (v Tm19 var19 lam19 app19 tt19 pair19 fst19 snd19 left19 right19 case19 zero19 suc19 rec19) def v019 : ∀ {Γ A}, Tm19 (snoc19 Γ A) A := var19 vz19 def v119 : ∀ {Γ A B}, Tm19 (snoc19 (snoc19 Γ A) B) A := var19 (vs19 vz19) def v219 : ∀ {Γ A B C}, Tm19 (snoc19 (snoc19 (snoc19 Γ A) B) C) A := var19 (vs19 (vs19 vz19)) def v319 : ∀ {Γ A B C D}, Tm19 (snoc19 (snoc19 (snoc19 (snoc19 Γ A) B) C) D) A := var19 (vs19 (vs19 (vs19 vz19))) def tbool19 : Ty19 := sum19 top19 top19 def ttrue19 : ∀ {Γ}, Tm19 Γ tbool19 := left19 tt19 def tfalse19 : ∀ {Γ}, Tm19 Γ tbool19 := right19 tt19 def ifthenelse19 : ∀ {Γ A}, Tm19 Γ (arr19 tbool19 (arr19 A (arr19 A A))) := lam19 (lam19 (lam19 (case19 v219 (lam19 v219) (lam19 v119)))) def times419 : ∀ {Γ A}, Tm19 Γ (arr19 (arr19 A A) (arr19 A A)) := lam19 (lam19 (app19 v119 (app19 v119 (app19 v119 (app19 v119 v019))))) def add19 : ∀ {Γ}, Tm19 Γ (arr19 nat19 (arr19 nat19 nat19)) := lam19 (rec19 v019 (lam19 (lam19 (lam19 (suc19 (app19 v119 v019))))) (lam19 v019)) def mul19 : ∀ {Γ}, Tm19 Γ (arr19 nat19 (arr19 nat19 nat19)) := lam19 (rec19 v019 (lam19 (lam19 (lam19 (app19 (app19 add19 (app19 v119 v019)) v019)))) (lam19 zero19)) def fact19 : ∀ {Γ}, Tm19 Γ (arr19 nat19 nat19) := lam19 (rec19 v019 (lam19 (lam19 (app19 (app19 mul19 (suc19 v119)) v019))) (suc19 zero19)) def Ty20 : Type 1 := ∀ (Ty20 : Type) (nat top bot : Ty20) (arr prod sum : Ty20 → Ty20 → Ty20) , Ty20 def nat20 : Ty20 := λ _ nat20 _ _ _ _ _ => nat20 def top20 : Ty20 := λ _ _ top20 _ _ _ _ => top20 def bot20 : Ty20 := λ _ _ _ bot20 _ _ _ => bot20 def arr20 : Ty20 → Ty20 → Ty20 := λ A B Ty20 nat20 top20 bot20 arr20 prod sum => arr20 (A Ty20 nat20 top20 bot20 arr20 prod sum) (B Ty20 nat20 top20 bot20 arr20 prod sum) def prod20 : Ty20 → Ty20 → Ty20 := λ A B Ty20 nat20 top20 bot20 arr20 prod20 sum => prod20 (A Ty20 nat20 top20 bot20 arr20 prod20 sum) (B Ty20 nat20 top20 bot20 arr20 prod20 sum) def sum20 : Ty20 → Ty20 → Ty20 := λ A B Ty20 nat20 top20 bot20 arr20 prod20 sum20 => sum20 (A Ty20 nat20 top20 bot20 arr20 prod20 sum20) (B Ty20 nat20 top20 bot20 arr20 prod20 sum20) def Con20 : Type 1 := ∀ (Con20 : Type) (nil : Con20) (snoc : Con20 → Ty20 → Con20) , Con20 def nil20 : Con20 := λ Con20 nil20 snoc => nil20 def snoc20 : Con20 → Ty20 → Con20 := λ Γ A Con20 nil20 snoc20 => snoc20 (Γ Con20 nil20 snoc20) A def Var20 : Con20 → Ty20 → Type 1 := λ Γ A => ∀ (Var20 : Con20 → Ty20 → Type) (vz : ∀{Γ A}, Var20 (snoc20 Γ A) A) (vs : ∀{Γ B A}, Var20 Γ A → Var20 (snoc20 Γ B) A) , Var20 Γ A def vz20 : ∀ {Γ A}, Var20 (snoc20 Γ A) A := λ Var20 vz20 vs => vz20 def vs20 : ∀ {Γ B A}, Var20 Γ A → Var20 (snoc20 Γ B) A := λ x Var20 vz20 vs20 => vs20 (x Var20 vz20 vs20) def Tm20 : Con20 → Ty20 → Type 1 := λ Γ A => ∀ (Tm20 : Con20 → Ty20 → Type) (var : ∀ {Γ A}, Var20 Γ A → Tm20 Γ A) (lam : ∀ {Γ A B}, (Tm20 (snoc20 Γ A) B → Tm20 Γ (arr20 A B))) (app : ∀ {Γ A B} , Tm20 Γ (arr20 A B) → Tm20 Γ A → Tm20 Γ B) (tt : ∀ {Γ} , Tm20 Γ top20) (pair : ∀ {Γ A B} , Tm20 Γ A → Tm20 Γ B → Tm20 Γ (prod20 A B)) (fst : ∀ {Γ A B} , Tm20 Γ (prod20 A B) → Tm20 Γ A) (snd : ∀ {Γ A B} , Tm20 Γ (prod20 A B) → Tm20 Γ B) (left : ∀ {Γ A B} , Tm20 Γ A → Tm20 Γ (sum20 A B)) (right : ∀ {Γ A B} , Tm20 Γ B → Tm20 Γ (sum20 A B)) (case : ∀ {Γ A B C} , Tm20 Γ (sum20 A B) → Tm20 Γ (arr20 A C) → Tm20 Γ (arr20 B C) → Tm20 Γ C) (zero : ∀ {Γ} , Tm20 Γ nat20) (suc : ∀ {Γ} , Tm20 Γ nat20 → Tm20 Γ nat20) (rec : ∀ {Γ A} , Tm20 Γ nat20 → Tm20 Γ (arr20 nat20 (arr20 A A)) → Tm20 Γ A → Tm20 Γ A) , Tm20 Γ A def var20 : ∀ {Γ A}, Var20 Γ A → Tm20 Γ A := λ x Tm20 var20 lam app tt pair fst snd left right case zero suc rec => var20 x def lam20 : ∀ {Γ A B} , Tm20 (snoc20 Γ A) B → Tm20 Γ (arr20 A B) := λ t Tm20 var20 lam20 app tt pair fst snd left right case zero suc rec => lam20 (t Tm20 var20 lam20 app tt pair fst snd left right case zero suc rec) def app20 : ∀ {Γ A B} , Tm20 Γ (arr20 A B) → Tm20 Γ A → Tm20 Γ B := λ t u Tm20 var20 lam20 app20 tt pair fst snd left right case zero suc rec => app20 (t Tm20 var20 lam20 app20 tt pair fst snd left right case zero suc rec) (u Tm20 var20 lam20 app20 tt pair fst snd left right case zero suc rec) def tt20 : ∀ {Γ} , Tm20 Γ top20 := λ Tm20 var20 lam20 app20 tt20 pair fst snd left right case zero suc rec => tt20 def pair20 : ∀ {Γ A B} , Tm20 Γ A → Tm20 Γ B → Tm20 Γ (prod20 A B) := λ t u Tm20 var20 lam20 app20 tt20 pair20 fst snd left right case zero suc rec => pair20 (t Tm20 var20 lam20 app20 tt20 pair20 fst snd left right case zero suc rec) (u Tm20 var20 lam20 app20 tt20 pair20 fst snd left right case zero suc rec) def fst20 : ∀ {Γ A B} , Tm20 Γ (prod20 A B) → Tm20 Γ A := λ t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd left right case zero suc rec => fst20 (t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd left right case zero suc rec) def snd20 : ∀ {Γ A B} , Tm20 Γ (prod20 A B) → Tm20 Γ B := λ t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left right case zero suc rec => snd20 (t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left right case zero suc rec) def left20 : ∀ {Γ A B} , Tm20 Γ A → Tm20 Γ (sum20 A B) := λ t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right case zero suc rec => left20 (t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right case zero suc rec) def right20 : ∀ {Γ A B} , Tm20 Γ B → Tm20 Γ (sum20 A B) := λ t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case zero suc rec => right20 (t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case zero suc rec) def case20 : ∀ {Γ A B C} , Tm20 Γ (sum20 A B) → Tm20 Γ (arr20 A C) → Tm20 Γ (arr20 B C) → Tm20 Γ C := λ t u v Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case20 zero suc rec => case20 (t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case20 zero suc rec) (u Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case20 zero suc rec) (v Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case20 zero suc rec) def zero20 : ∀ {Γ} , Tm20 Γ nat20 := λ Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case20 zero20 suc rec => zero20 def suc20 : ∀ {Γ} , Tm20 Γ nat20 → Tm20 Γ nat20 := λ t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case20 zero20 suc20 rec => suc20 (t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case20 zero20 suc20 rec) def rec20 : ∀ {Γ A} , Tm20 Γ nat20 → Tm20 Γ (arr20 nat20 (arr20 A A)) → Tm20 Γ A → Tm20 Γ A := λ t u v Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case20 zero20 suc20 rec20 => rec20 (t Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case20 zero20 suc20 rec20) (u Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case20 zero20 suc20 rec20) (v Tm20 var20 lam20 app20 tt20 pair20 fst20 snd20 left20 right20 case20 zero20 suc20 rec20) def v020 : ∀ {Γ A}, Tm20 (snoc20 Γ A) A := var20 vz20 def v120 : ∀ {Γ A B}, Tm20 (snoc20 (snoc20 Γ A) B) A := var20 (vs20 vz20) def v220 : ∀ {Γ A B C}, Tm20 (snoc20 (snoc20 (snoc20 Γ A) B) C) A := var20 (vs20 (vs20 vz20)) def v320 : ∀ {Γ A B C D}, Tm20 (snoc20 (snoc20 (snoc20 (snoc20 Γ A) B) C) D) A := var20 (vs20 (vs20 (vs20 vz20))) def tbool20 : Ty20 := sum20 top20 top20 def ttrue20 : ∀ {Γ}, Tm20 Γ tbool20 := left20 tt20 def tfalse20 : ∀ {Γ}, Tm20 Γ tbool20 := right20 tt20 def ifthenelse20 : ∀ {Γ A}, Tm20 Γ (arr20 tbool20 (arr20 A (arr20 A A))) := lam20 (lam20 (lam20 (case20 v220 (lam20 v220) (lam20 v120)))) def times420 : ∀ {Γ A}, Tm20 Γ (arr20 (arr20 A A) (arr20 A A)) := lam20 (lam20 (app20 v120 (app20 v120 (app20 v120 (app20 v120 v020))))) def add20 : ∀ {Γ}, Tm20 Γ (arr20 nat20 (arr20 nat20 nat20)) := lam20 (rec20 v020 (lam20 (lam20 (lam20 (suc20 (app20 v120 v020))))) (lam20 v020)) def mul20 : ∀ {Γ}, Tm20 Γ (arr20 nat20 (arr20 nat20 nat20)) := lam20 (rec20 v020 (lam20 (lam20 (lam20 (app20 (app20 add20 (app20 v120 v020)) v020)))) (lam20 zero20)) def fact20 : ∀ {Γ}, Tm20 Γ (arr20 nat20 nat20) := lam20 (rec20 v020 (lam20 (lam20 (app20 (app20 mul20 (suc20 v120)) v020))) (suc20 zero20)) def Ty21 : Type 1 := ∀ (Ty21 : Type) (nat top bot : Ty21) (arr prod sum : Ty21 → Ty21 → Ty21) , Ty21 def nat21 : Ty21 := λ _ nat21 _ _ _ _ _ => nat21 def top21 : Ty21 := λ _ _ top21 _ _ _ _ => top21 def bot21 : Ty21 := λ _ _ _ bot21 _ _ _ => bot21 def arr21 : Ty21 → Ty21 → Ty21 := λ A B Ty21 nat21 top21 bot21 arr21 prod sum => arr21 (A Ty21 nat21 top21 bot21 arr21 prod sum) (B Ty21 nat21 top21 bot21 arr21 prod sum) def prod21 : Ty21 → Ty21 → Ty21 := λ A B Ty21 nat21 top21 bot21 arr21 prod21 sum => prod21 (A Ty21 nat21 top21 bot21 arr21 prod21 sum) (B Ty21 nat21 top21 bot21 arr21 prod21 sum) def sum21 : Ty21 → Ty21 → Ty21 := λ A B Ty21 nat21 top21 bot21 arr21 prod21 sum21 => sum21 (A Ty21 nat21 top21 bot21 arr21 prod21 sum21) (B Ty21 nat21 top21 bot21 arr21 prod21 sum21) def Con21 : Type 1 := ∀ (Con21 : Type) (nil : Con21) (snoc : Con21 → Ty21 → Con21) , Con21 def nil21 : Con21 := λ Con21 nil21 snoc => nil21 def snoc21 : Con21 → Ty21 → Con21 := λ Γ A Con21 nil21 snoc21 => snoc21 (Γ Con21 nil21 snoc21) A def Var21 : Con21 → Ty21 → Type 1 := λ Γ A => ∀ (Var21 : Con21 → Ty21 → Type) (vz : ∀{Γ A}, Var21 (snoc21 Γ A) A) (vs : ∀{Γ B A}, Var21 Γ A → Var21 (snoc21 Γ B) A) , Var21 Γ A def vz21 : ∀ {Γ A}, Var21 (snoc21 Γ A) A := λ Var21 vz21 vs => vz21 def vs21 : ∀ {Γ B A}, Var21 Γ A → Var21 (snoc21 Γ B) A := λ x Var21 vz21 vs21 => vs21 (x Var21 vz21 vs21) def Tm21 : Con21 → Ty21 → Type 1 := λ Γ A => ∀ (Tm21 : Con21 → Ty21 → Type) (var : ∀ {Γ A}, Var21 Γ A → Tm21 Γ A) (lam : ∀ {Γ A B}, (Tm21 (snoc21 Γ A) B → Tm21 Γ (arr21 A B))) (app : ∀ {Γ A B} , Tm21 Γ (arr21 A B) → Tm21 Γ A → Tm21 Γ B) (tt : ∀ {Γ} , Tm21 Γ top21) (pair : ∀ {Γ A B} , Tm21 Γ A → Tm21 Γ B → Tm21 Γ (prod21 A B)) (fst : ∀ {Γ A B} , Tm21 Γ (prod21 A B) → Tm21 Γ A) (snd : ∀ {Γ A B} , Tm21 Γ (prod21 A B) → Tm21 Γ B) (left : ∀ {Γ A B} , Tm21 Γ A → Tm21 Γ (sum21 A B)) (right : ∀ {Γ A B} , Tm21 Γ B → Tm21 Γ (sum21 A B)) (case : ∀ {Γ A B C} , Tm21 Γ (sum21 A B) → Tm21 Γ (arr21 A C) → Tm21 Γ (arr21 B C) → Tm21 Γ C) (zero : ∀ {Γ} , Tm21 Γ nat21) (suc : ∀ {Γ} , Tm21 Γ nat21 → Tm21 Γ nat21) (rec : ∀ {Γ A} , Tm21 Γ nat21 → Tm21 Γ (arr21 nat21 (arr21 A A)) → Tm21 Γ A → Tm21 Γ A) , Tm21 Γ A def var21 : ∀ {Γ A}, Var21 Γ A → Tm21 Γ A := λ x Tm21 var21 lam app tt pair fst snd left right case zero suc rec => var21 x def lam21 : ∀ {Γ A B} , Tm21 (snoc21 Γ A) B → Tm21 Γ (arr21 A B) := λ t Tm21 var21 lam21 app tt pair fst snd left right case zero suc rec => lam21 (t Tm21 var21 lam21 app tt pair fst snd left right case zero suc rec) def app21 : ∀ {Γ A B} , Tm21 Γ (arr21 A B) → Tm21 Γ A → Tm21 Γ B := λ t u Tm21 var21 lam21 app21 tt pair fst snd left right case zero suc rec => app21 (t Tm21 var21 lam21 app21 tt pair fst snd left right case zero suc rec) (u Tm21 var21 lam21 app21 tt pair fst snd left right case zero suc rec) def tt21 : ∀ {Γ} , Tm21 Γ top21 := λ Tm21 var21 lam21 app21 tt21 pair fst snd left right case zero suc rec => tt21 def pair21 : ∀ {Γ A B} , Tm21 Γ A → Tm21 Γ B → Tm21 Γ (prod21 A B) := λ t u Tm21 var21 lam21 app21 tt21 pair21 fst snd left right case zero suc rec => pair21 (t Tm21 var21 lam21 app21 tt21 pair21 fst snd left right case zero suc rec) (u Tm21 var21 lam21 app21 tt21 pair21 fst snd left right case zero suc rec) def fst21 : ∀ {Γ A B} , Tm21 Γ (prod21 A B) → Tm21 Γ A := λ t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd left right case zero suc rec => fst21 (t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd left right case zero suc rec) def snd21 : ∀ {Γ A B} , Tm21 Γ (prod21 A B) → Tm21 Γ B := λ t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left right case zero suc rec => snd21 (t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left right case zero suc rec) def left21 : ∀ {Γ A B} , Tm21 Γ A → Tm21 Γ (sum21 A B) := λ t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right case zero suc rec => left21 (t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right case zero suc rec) def right21 : ∀ {Γ A B} , Tm21 Γ B → Tm21 Γ (sum21 A B) := λ t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case zero suc rec => right21 (t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case zero suc rec) def case21 : ∀ {Γ A B C} , Tm21 Γ (sum21 A B) → Tm21 Γ (arr21 A C) → Tm21 Γ (arr21 B C) → Tm21 Γ C := λ t u v Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case21 zero suc rec => case21 (t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case21 zero suc rec) (u Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case21 zero suc rec) (v Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case21 zero suc rec) def zero21 : ∀ {Γ} , Tm21 Γ nat21 := λ Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case21 zero21 suc rec => zero21 def suc21 : ∀ {Γ} , Tm21 Γ nat21 → Tm21 Γ nat21 := λ t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case21 zero21 suc21 rec => suc21 (t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case21 zero21 suc21 rec) def rec21 : ∀ {Γ A} , Tm21 Γ nat21 → Tm21 Γ (arr21 nat21 (arr21 A A)) → Tm21 Γ A → Tm21 Γ A := λ t u v Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case21 zero21 suc21 rec21 => rec21 (t Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case21 zero21 suc21 rec21) (u Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case21 zero21 suc21 rec21) (v Tm21 var21 lam21 app21 tt21 pair21 fst21 snd21 left21 right21 case21 zero21 suc21 rec21) def v021 : ∀ {Γ A}, Tm21 (snoc21 Γ A) A := var21 vz21 def v121 : ∀ {Γ A B}, Tm21 (snoc21 (snoc21 Γ A) B) A := var21 (vs21 vz21) def v221 : ∀ {Γ A B C}, Tm21 (snoc21 (snoc21 (snoc21 Γ A) B) C) A := var21 (vs21 (vs21 vz21)) def v321 : ∀ {Γ A B C D}, Tm21 (snoc21 (snoc21 (snoc21 (snoc21 Γ A) B) C) D) A := var21 (vs21 (vs21 (vs21 vz21))) def tbool21 : Ty21 := sum21 top21 top21 def ttrue21 : ∀ {Γ}, Tm21 Γ tbool21 := left21 tt21 def tfalse21 : ∀ {Γ}, Tm21 Γ tbool21 := right21 tt21 def ifthenelse21 : ∀ {Γ A}, Tm21 Γ (arr21 tbool21 (arr21 A (arr21 A A))) := lam21 (lam21 (lam21 (case21 v221 (lam21 v221) (lam21 v121)))) def times421 : ∀ {Γ A}, Tm21 Γ (arr21 (arr21 A A) (arr21 A A)) := lam21 (lam21 (app21 v121 (app21 v121 (app21 v121 (app21 v121 v021))))) def add21 : ∀ {Γ}, Tm21 Γ (arr21 nat21 (arr21 nat21 nat21)) := lam21 (rec21 v021 (lam21 (lam21 (lam21 (suc21 (app21 v121 v021))))) (lam21 v021)) def mul21 : ∀ {Γ}, Tm21 Γ (arr21 nat21 (arr21 nat21 nat21)) := lam21 (rec21 v021 (lam21 (lam21 (lam21 (app21 (app21 add21 (app21 v121 v021)) v021)))) (lam21 zero21)) def fact21 : ∀ {Γ}, Tm21 Γ (arr21 nat21 nat21) := lam21 (rec21 v021 (lam21 (lam21 (app21 (app21 mul21 (suc21 v121)) v021))) (suc21 zero21)) def Ty22 : Type 1 := ∀ (Ty22 : Type) (nat top bot : Ty22) (arr prod sum : Ty22 → Ty22 → Ty22) , Ty22 def nat22 : Ty22 := λ _ nat22 _ _ _ _ _ => nat22 def top22 : Ty22 := λ _ _ top22 _ _ _ _ => top22 def bot22 : Ty22 := λ _ _ _ bot22 _ _ _ => bot22 def arr22 : Ty22 → Ty22 → Ty22 := λ A B Ty22 nat22 top22 bot22 arr22 prod sum => arr22 (A Ty22 nat22 top22 bot22 arr22 prod sum) (B Ty22 nat22 top22 bot22 arr22 prod sum) def prod22 : Ty22 → Ty22 → Ty22 := λ A B Ty22 nat22 top22 bot22 arr22 prod22 sum => prod22 (A Ty22 nat22 top22 bot22 arr22 prod22 sum) (B Ty22 nat22 top22 bot22 arr22 prod22 sum) def sum22 : Ty22 → Ty22 → Ty22 := λ A B Ty22 nat22 top22 bot22 arr22 prod22 sum22 => sum22 (A Ty22 nat22 top22 bot22 arr22 prod22 sum22) (B Ty22 nat22 top22 bot22 arr22 prod22 sum22) def Con22 : Type 1 := ∀ (Con22 : Type) (nil : Con22) (snoc : Con22 → Ty22 → Con22) , Con22 def nil22 : Con22 := λ Con22 nil22 snoc => nil22 def snoc22 : Con22 → Ty22 → Con22 := λ Γ A Con22 nil22 snoc22 => snoc22 (Γ Con22 nil22 snoc22) A def Var22 : Con22 → Ty22 → Type 1 := λ Γ A => ∀ (Var22 : Con22 → Ty22 → Type) (vz : ∀{Γ A}, Var22 (snoc22 Γ A) A) (vs : ∀{Γ B A}, Var22 Γ A → Var22 (snoc22 Γ B) A) , Var22 Γ A def vz22 : ∀ {Γ A}, Var22 (snoc22 Γ A) A := λ Var22 vz22 vs => vz22 def vs22 : ∀ {Γ B A}, Var22 Γ A → Var22 (snoc22 Γ B) A := λ x Var22 vz22 vs22 => vs22 (x Var22 vz22 vs22) def Tm22 : Con22 → Ty22 → Type 1 := λ Γ A => ∀ (Tm22 : Con22 → Ty22 → Type) (var : ∀ {Γ A}, Var22 Γ A → Tm22 Γ A) (lam : ∀ {Γ A B}, (Tm22 (snoc22 Γ A) B → Tm22 Γ (arr22 A B))) (app : ∀ {Γ A B} , Tm22 Γ (arr22 A B) → Tm22 Γ A → Tm22 Γ B) (tt : ∀ {Γ} , Tm22 Γ top22) (pair : ∀ {Γ A B} , Tm22 Γ A → Tm22 Γ B → Tm22 Γ (prod22 A B)) (fst : ∀ {Γ A B} , Tm22 Γ (prod22 A B) → Tm22 Γ A) (snd : ∀ {Γ A B} , Tm22 Γ (prod22 A B) → Tm22 Γ B) (left : ∀ {Γ A B} , Tm22 Γ A → Tm22 Γ (sum22 A B)) (right : ∀ {Γ A B} , Tm22 Γ B → Tm22 Γ (sum22 A B)) (case : ∀ {Γ A B C} , Tm22 Γ (sum22 A B) → Tm22 Γ (arr22 A C) → Tm22 Γ (arr22 B C) → Tm22 Γ C) (zero : ∀ {Γ} , Tm22 Γ nat22) (suc : ∀ {Γ} , Tm22 Γ nat22 → Tm22 Γ nat22) (rec : ∀ {Γ A} , Tm22 Γ nat22 → Tm22 Γ (arr22 nat22 (arr22 A A)) → Tm22 Γ A → Tm22 Γ A) , Tm22 Γ A def var22 : ∀ {Γ A}, Var22 Γ A → Tm22 Γ A := λ x Tm22 var22 lam app tt pair fst snd left right case zero suc rec => var22 x def lam22 : ∀ {Γ A B} , Tm22 (snoc22 Γ A) B → Tm22 Γ (arr22 A B) := λ t Tm22 var22 lam22 app tt pair fst snd left right case zero suc rec => lam22 (t Tm22 var22 lam22 app tt pair fst snd left right case zero suc rec) def app22 : ∀ {Γ A B} , Tm22 Γ (arr22 A B) → Tm22 Γ A → Tm22 Γ B := λ t u Tm22 var22 lam22 app22 tt pair fst snd left right case zero suc rec => app22 (t Tm22 var22 lam22 app22 tt pair fst snd left right case zero suc rec) (u Tm22 var22 lam22 app22 tt pair fst snd left right case zero suc rec) def tt22 : ∀ {Γ} , Tm22 Γ top22 := λ Tm22 var22 lam22 app22 tt22 pair fst snd left right case zero suc rec => tt22 def pair22 : ∀ {Γ A B} , Tm22 Γ A → Tm22 Γ B → Tm22 Γ (prod22 A B) := λ t u Tm22 var22 lam22 app22 tt22 pair22 fst snd left right case zero suc rec => pair22 (t Tm22 var22 lam22 app22 tt22 pair22 fst snd left right case zero suc rec) (u Tm22 var22 lam22 app22 tt22 pair22 fst snd left right case zero suc rec) def fst22 : ∀ {Γ A B} , Tm22 Γ (prod22 A B) → Tm22 Γ A := λ t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd left right case zero suc rec => fst22 (t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd left right case zero suc rec) def snd22 : ∀ {Γ A B} , Tm22 Γ (prod22 A B) → Tm22 Γ B := λ t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left right case zero suc rec => snd22 (t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left right case zero suc rec) def left22 : ∀ {Γ A B} , Tm22 Γ A → Tm22 Γ (sum22 A B) := λ t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right case zero suc rec => left22 (t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right case zero suc rec) def right22 : ∀ {Γ A B} , Tm22 Γ B → Tm22 Γ (sum22 A B) := λ t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case zero suc rec => right22 (t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case zero suc rec) def case22 : ∀ {Γ A B C} , Tm22 Γ (sum22 A B) → Tm22 Γ (arr22 A C) → Tm22 Γ (arr22 B C) → Tm22 Γ C := λ t u v Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case22 zero suc rec => case22 (t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case22 zero suc rec) (u Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case22 zero suc rec) (v Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case22 zero suc rec) def zero22 : ∀ {Γ} , Tm22 Γ nat22 := λ Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case22 zero22 suc rec => zero22 def suc22 : ∀ {Γ} , Tm22 Γ nat22 → Tm22 Γ nat22 := λ t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case22 zero22 suc22 rec => suc22 (t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case22 zero22 suc22 rec) def rec22 : ∀ {Γ A} , Tm22 Γ nat22 → Tm22 Γ (arr22 nat22 (arr22 A A)) → Tm22 Γ A → Tm22 Γ A := λ t u v Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case22 zero22 suc22 rec22 => rec22 (t Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case22 zero22 suc22 rec22) (u Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case22 zero22 suc22 rec22) (v Tm22 var22 lam22 app22 tt22 pair22 fst22 snd22 left22 right22 case22 zero22 suc22 rec22) def v022 : ∀ {Γ A}, Tm22 (snoc22 Γ A) A := var22 vz22 def v122 : ∀ {Γ A B}, Tm22 (snoc22 (snoc22 Γ A) B) A := var22 (vs22 vz22) def v222 : ∀ {Γ A B C}, Tm22 (snoc22 (snoc22 (snoc22 Γ A) B) C) A := var22 (vs22 (vs22 vz22)) def v322 : ∀ {Γ A B C D}, Tm22 (snoc22 (snoc22 (snoc22 (snoc22 Γ A) B) C) D) A := var22 (vs22 (vs22 (vs22 vz22))) def tbool22 : Ty22 := sum22 top22 top22 def ttrue22 : ∀ {Γ}, Tm22 Γ tbool22 := left22 tt22 def tfalse22 : ∀ {Γ}, Tm22 Γ tbool22 := right22 tt22 def ifthenelse22 : ∀ {Γ A}, Tm22 Γ (arr22 tbool22 (arr22 A (arr22 A A))) := lam22 (lam22 (lam22 (case22 v222 (lam22 v222) (lam22 v122)))) def times422 : ∀ {Γ A}, Tm22 Γ (arr22 (arr22 A A) (arr22 A A)) := lam22 (lam22 (app22 v122 (app22 v122 (app22 v122 (app22 v122 v022))))) def add22 : ∀ {Γ}, Tm22 Γ (arr22 nat22 (arr22 nat22 nat22)) := lam22 (rec22 v022 (lam22 (lam22 (lam22 (suc22 (app22 v122 v022))))) (lam22 v022)) def mul22 : ∀ {Γ}, Tm22 Γ (arr22 nat22 (arr22 nat22 nat22)) := lam22 (rec22 v022 (lam22 (lam22 (lam22 (app22 (app22 add22 (app22 v122 v022)) v022)))) (lam22 zero22)) def fact22 : ∀ {Γ}, Tm22 Γ (arr22 nat22 nat22) := lam22 (rec22 v022 (lam22 (lam22 (app22 (app22 mul22 (suc22 v122)) v022))) (suc22 zero22)) def Ty23 : Type 1 := ∀ (Ty23 : Type) (nat top bot : Ty23) (arr prod sum : Ty23 → Ty23 → Ty23) , Ty23 def nat23 : Ty23 := λ _ nat23 _ _ _ _ _ => nat23 def top23 : Ty23 := λ _ _ top23 _ _ _ _ => top23 def bot23 : Ty23 := λ _ _ _ bot23 _ _ _ => bot23 def arr23 : Ty23 → Ty23 → Ty23 := λ A B Ty23 nat23 top23 bot23 arr23 prod sum => arr23 (A Ty23 nat23 top23 bot23 arr23 prod sum) (B Ty23 nat23 top23 bot23 arr23 prod sum) def prod23 : Ty23 → Ty23 → Ty23 := λ A B Ty23 nat23 top23 bot23 arr23 prod23 sum => prod23 (A Ty23 nat23 top23 bot23 arr23 prod23 sum) (B Ty23 nat23 top23 bot23 arr23 prod23 sum) def sum23 : Ty23 → Ty23 → Ty23 := λ A B Ty23 nat23 top23 bot23 arr23 prod23 sum23 => sum23 (A Ty23 nat23 top23 bot23 arr23 prod23 sum23) (B Ty23 nat23 top23 bot23 arr23 prod23 sum23) def Con23 : Type 1 := ∀ (Con23 : Type) (nil : Con23) (snoc : Con23 → Ty23 → Con23) , Con23 def nil23 : Con23 := λ Con23 nil23 snoc => nil23 def snoc23 : Con23 → Ty23 → Con23 := λ Γ A Con23 nil23 snoc23 => snoc23 (Γ Con23 nil23 snoc23) A def Var23 : Con23 → Ty23 → Type 1 := λ Γ A => ∀ (Var23 : Con23 → Ty23 → Type) (vz : ∀{Γ A}, Var23 (snoc23 Γ A) A) (vs : ∀{Γ B A}, Var23 Γ A → Var23 (snoc23 Γ B) A) , Var23 Γ A def vz23 : ∀ {Γ A}, Var23 (snoc23 Γ A) A := λ Var23 vz23 vs => vz23 def vs23 : ∀ {Γ B A}, Var23 Γ A → Var23 (snoc23 Γ B) A := λ x Var23 vz23 vs23 => vs23 (x Var23 vz23 vs23) def Tm23 : Con23 → Ty23 → Type 1 := λ Γ A => ∀ (Tm23 : Con23 → Ty23 → Type) (var : ∀ {Γ A}, Var23 Γ A → Tm23 Γ A) (lam : ∀ {Γ A B}, (Tm23 (snoc23 Γ A) B → Tm23 Γ (arr23 A B))) (app : ∀ {Γ A B} , Tm23 Γ (arr23 A B) → Tm23 Γ A → Tm23 Γ B) (tt : ∀ {Γ} , Tm23 Γ top23) (pair : ∀ {Γ A B} , Tm23 Γ A → Tm23 Γ B → Tm23 Γ (prod23 A B)) (fst : ∀ {Γ A B} , Tm23 Γ (prod23 A B) → Tm23 Γ A) (snd : ∀ {Γ A B} , Tm23 Γ (prod23 A B) → Tm23 Γ B) (left : ∀ {Γ A B} , Tm23 Γ A → Tm23 Γ (sum23 A B)) (right : ∀ {Γ A B} , Tm23 Γ B → Tm23 Γ (sum23 A B)) (case : ∀ {Γ A B C} , Tm23 Γ (sum23 A B) → Tm23 Γ (arr23 A C) → Tm23 Γ (arr23 B C) → Tm23 Γ C) (zero : ∀ {Γ} , Tm23 Γ nat23) (suc : ∀ {Γ} , Tm23 Γ nat23 → Tm23 Γ nat23) (rec : ∀ {Γ A} , Tm23 Γ nat23 → Tm23 Γ (arr23 nat23 (arr23 A A)) → Tm23 Γ A → Tm23 Γ A) , Tm23 Γ A def var23 : ∀ {Γ A}, Var23 Γ A → Tm23 Γ A := λ x Tm23 var23 lam app tt pair fst snd left right case zero suc rec => var23 x def lam23 : ∀ {Γ A B} , Tm23 (snoc23 Γ A) B → Tm23 Γ (arr23 A B) := λ t Tm23 var23 lam23 app tt pair fst snd left right case zero suc rec => lam23 (t Tm23 var23 lam23 app tt pair fst snd left right case zero suc rec) def app23 : ∀ {Γ A B} , Tm23 Γ (arr23 A B) → Tm23 Γ A → Tm23 Γ B := λ t u Tm23 var23 lam23 app23 tt pair fst snd left right case zero suc rec => app23 (t Tm23 var23 lam23 app23 tt pair fst snd left right case zero suc rec) (u Tm23 var23 lam23 app23 tt pair fst snd left right case zero suc rec) def tt23 : ∀ {Γ} , Tm23 Γ top23 := λ Tm23 var23 lam23 app23 tt23 pair fst snd left right case zero suc rec => tt23 def pair23 : ∀ {Γ A B} , Tm23 Γ A → Tm23 Γ B → Tm23 Γ (prod23 A B) := λ t u Tm23 var23 lam23 app23 tt23 pair23 fst snd left right case zero suc rec => pair23 (t Tm23 var23 lam23 app23 tt23 pair23 fst snd left right case zero suc rec) (u Tm23 var23 lam23 app23 tt23 pair23 fst snd left right case zero suc rec) def fst23 : ∀ {Γ A B} , Tm23 Γ (prod23 A B) → Tm23 Γ A := λ t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd left right case zero suc rec => fst23 (t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd left right case zero suc rec) def snd23 : ∀ {Γ A B} , Tm23 Γ (prod23 A B) → Tm23 Γ B := λ t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left right case zero suc rec => snd23 (t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left right case zero suc rec) def left23 : ∀ {Γ A B} , Tm23 Γ A → Tm23 Γ (sum23 A B) := λ t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right case zero suc rec => left23 (t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right case zero suc rec) def right23 : ∀ {Γ A B} , Tm23 Γ B → Tm23 Γ (sum23 A B) := λ t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case zero suc rec => right23 (t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case zero suc rec) def case23 : ∀ {Γ A B C} , Tm23 Γ (sum23 A B) → Tm23 Γ (arr23 A C) → Tm23 Γ (arr23 B C) → Tm23 Γ C := λ t u v Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case23 zero suc rec => case23 (t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case23 zero suc rec) (u Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case23 zero suc rec) (v Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case23 zero suc rec) def zero23 : ∀ {Γ} , Tm23 Γ nat23 := λ Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case23 zero23 suc rec => zero23 def suc23 : ∀ {Γ} , Tm23 Γ nat23 → Tm23 Γ nat23 := λ t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case23 zero23 suc23 rec => suc23 (t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case23 zero23 suc23 rec) def rec23 : ∀ {Γ A} , Tm23 Γ nat23 → Tm23 Γ (arr23 nat23 (arr23 A A)) → Tm23 Γ A → Tm23 Γ A := λ t u v Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case23 zero23 suc23 rec23 => rec23 (t Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case23 zero23 suc23 rec23) (u Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case23 zero23 suc23 rec23) (v Tm23 var23 lam23 app23 tt23 pair23 fst23 snd23 left23 right23 case23 zero23 suc23 rec23) def v023 : ∀ {Γ A}, Tm23 (snoc23 Γ A) A := var23 vz23 def v123 : ∀ {Γ A B}, Tm23 (snoc23 (snoc23 Γ A) B) A := var23 (vs23 vz23) def v223 : ∀ {Γ A B C}, Tm23 (snoc23 (snoc23 (snoc23 Γ A) B) C) A := var23 (vs23 (vs23 vz23)) def v323 : ∀ {Γ A B C D}, Tm23 (snoc23 (snoc23 (snoc23 (snoc23 Γ A) B) C) D) A := var23 (vs23 (vs23 (vs23 vz23))) def tbool23 : Ty23 := sum23 top23 top23 def ttrue23 : ∀ {Γ}, Tm23 Γ tbool23 := left23 tt23 def tfalse23 : ∀ {Γ}, Tm23 Γ tbool23 := right23 tt23 def ifthenelse23 : ∀ {Γ A}, Tm23 Γ (arr23 tbool23 (arr23 A (arr23 A A))) := lam23 (lam23 (lam23 (case23 v223 (lam23 v223) (lam23 v123)))) def times423 : ∀ {Γ A}, Tm23 Γ (arr23 (arr23 A A) (arr23 A A)) := lam23 (lam23 (app23 v123 (app23 v123 (app23 v123 (app23 v123 v023))))) def add23 : ∀ {Γ}, Tm23 Γ (arr23 nat23 (arr23 nat23 nat23)) := lam23 (rec23 v023 (lam23 (lam23 (lam23 (suc23 (app23 v123 v023))))) (lam23 v023)) def mul23 : ∀ {Γ}, Tm23 Γ (arr23 nat23 (arr23 nat23 nat23)) := lam23 (rec23 v023 (lam23 (lam23 (lam23 (app23 (app23 add23 (app23 v123 v023)) v023)))) (lam23 zero23)) def fact23 : ∀ {Γ}, Tm23 Γ (arr23 nat23 nat23) := lam23 (rec23 v023 (lam23 (lam23 (app23 (app23 mul23 (suc23 v123)) v023))) (suc23 zero23)) def Ty24 : Type 1 := ∀ (Ty24 : Type) (nat top bot : Ty24) (arr prod sum : Ty24 → Ty24 → Ty24) , Ty24 def nat24 : Ty24 := λ _ nat24 _ _ _ _ _ => nat24 def top24 : Ty24 := λ _ _ top24 _ _ _ _ => top24 def bot24 : Ty24 := λ _ _ _ bot24 _ _ _ => bot24 def arr24 : Ty24 → Ty24 → Ty24 := λ A B Ty24 nat24 top24 bot24 arr24 prod sum => arr24 (A Ty24 nat24 top24 bot24 arr24 prod sum) (B Ty24 nat24 top24 bot24 arr24 prod sum) def prod24 : Ty24 → Ty24 → Ty24 := λ A B Ty24 nat24 top24 bot24 arr24 prod24 sum => prod24 (A Ty24 nat24 top24 bot24 arr24 prod24 sum) (B Ty24 nat24 top24 bot24 arr24 prod24 sum) def sum24 : Ty24 → Ty24 → Ty24 := λ A B Ty24 nat24 top24 bot24 arr24 prod24 sum24 => sum24 (A Ty24 nat24 top24 bot24 arr24 prod24 sum24) (B Ty24 nat24 top24 bot24 arr24 prod24 sum24) def Con24 : Type 1 := ∀ (Con24 : Type) (nil : Con24) (snoc : Con24 → Ty24 → Con24) , Con24 def nil24 : Con24 := λ Con24 nil24 snoc => nil24 def snoc24 : Con24 → Ty24 → Con24 := λ Γ A Con24 nil24 snoc24 => snoc24 (Γ Con24 nil24 snoc24) A def Var24 : Con24 → Ty24 → Type 1 := λ Γ A => ∀ (Var24 : Con24 → Ty24 → Type) (vz : ∀{Γ A}, Var24 (snoc24 Γ A) A) (vs : ∀{Γ B A}, Var24 Γ A → Var24 (snoc24 Γ B) A) , Var24 Γ A def vz24 : ∀ {Γ A}, Var24 (snoc24 Γ A) A := λ Var24 vz24 vs => vz24 def vs24 : ∀ {Γ B A}, Var24 Γ A → Var24 (snoc24 Γ B) A := λ x Var24 vz24 vs24 => vs24 (x Var24 vz24 vs24) def Tm24 : Con24 → Ty24 → Type 1 := λ Γ A => ∀ (Tm24 : Con24 → Ty24 → Type) (var : ∀ {Γ A}, Var24 Γ A → Tm24 Γ A) (lam : ∀ {Γ A B}, (Tm24 (snoc24 Γ A) B → Tm24 Γ (arr24 A B))) (app : ∀ {Γ A B} , Tm24 Γ (arr24 A B) → Tm24 Γ A → Tm24 Γ B) (tt : ∀ {Γ} , Tm24 Γ top24) (pair : ∀ {Γ A B} , Tm24 Γ A → Tm24 Γ B → Tm24 Γ (prod24 A B)) (fst : ∀ {Γ A B} , Tm24 Γ (prod24 A B) → Tm24 Γ A) (snd : ∀ {Γ A B} , Tm24 Γ (prod24 A B) → Tm24 Γ B) (left : ∀ {Γ A B} , Tm24 Γ A → Tm24 Γ (sum24 A B)) (right : ∀ {Γ A B} , Tm24 Γ B → Tm24 Γ (sum24 A B)) (case : ∀ {Γ A B C} , Tm24 Γ (sum24 A B) → Tm24 Γ (arr24 A C) → Tm24 Γ (arr24 B C) → Tm24 Γ C) (zero : ∀ {Γ} , Tm24 Γ nat24) (suc : ∀ {Γ} , Tm24 Γ nat24 → Tm24 Γ nat24) (rec : ∀ {Γ A} , Tm24 Γ nat24 → Tm24 Γ (arr24 nat24 (arr24 A A)) → Tm24 Γ A → Tm24 Γ A) , Tm24 Γ A def var24 : ∀ {Γ A}, Var24 Γ A → Tm24 Γ A := λ x Tm24 var24 lam app tt pair fst snd left right case zero suc rec => var24 x def lam24 : ∀ {Γ A B} , Tm24 (snoc24 Γ A) B → Tm24 Γ (arr24 A B) := λ t Tm24 var24 lam24 app tt pair fst snd left right case zero suc rec => lam24 (t Tm24 var24 lam24 app tt pair fst snd left right case zero suc rec) def app24 : ∀ {Γ A B} , Tm24 Γ (arr24 A B) → Tm24 Γ A → Tm24 Γ B := λ t u Tm24 var24 lam24 app24 tt pair fst snd left right case zero suc rec => app24 (t Tm24 var24 lam24 app24 tt pair fst snd left right case zero suc rec) (u Tm24 var24 lam24 app24 tt pair fst snd left right case zero suc rec) def tt24 : ∀ {Γ} , Tm24 Γ top24 := λ Tm24 var24 lam24 app24 tt24 pair fst snd left right case zero suc rec => tt24 def pair24 : ∀ {Γ A B} , Tm24 Γ A → Tm24 Γ B → Tm24 Γ (prod24 A B) := λ t u Tm24 var24 lam24 app24 tt24 pair24 fst snd left right case zero suc rec => pair24 (t Tm24 var24 lam24 app24 tt24 pair24 fst snd left right case zero suc rec) (u Tm24 var24 lam24 app24 tt24 pair24 fst snd left right case zero suc rec) def fst24 : ∀ {Γ A B} , Tm24 Γ (prod24 A B) → Tm24 Γ A := λ t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd left right case zero suc rec => fst24 (t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd left right case zero suc rec) def snd24 : ∀ {Γ A B} , Tm24 Γ (prod24 A B) → Tm24 Γ B := λ t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left right case zero suc rec => snd24 (t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left right case zero suc rec) def left24 : ∀ {Γ A B} , Tm24 Γ A → Tm24 Γ (sum24 A B) := λ t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right case zero suc rec => left24 (t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right case zero suc rec) def right24 : ∀ {Γ A B} , Tm24 Γ B → Tm24 Γ (sum24 A B) := λ t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case zero suc rec => right24 (t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case zero suc rec) def case24 : ∀ {Γ A B C} , Tm24 Γ (sum24 A B) → Tm24 Γ (arr24 A C) → Tm24 Γ (arr24 B C) → Tm24 Γ C := λ t u v Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case24 zero suc rec => case24 (t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case24 zero suc rec) (u Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case24 zero suc rec) (v Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case24 zero suc rec) def zero24 : ∀ {Γ} , Tm24 Γ nat24 := λ Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case24 zero24 suc rec => zero24 def suc24 : ∀ {Γ} , Tm24 Γ nat24 → Tm24 Γ nat24 := λ t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case24 zero24 suc24 rec => suc24 (t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case24 zero24 suc24 rec) def rec24 : ∀ {Γ A} , Tm24 Γ nat24 → Tm24 Γ (arr24 nat24 (arr24 A A)) → Tm24 Γ A → Tm24 Γ A := λ t u v Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case24 zero24 suc24 rec24 => rec24 (t Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case24 zero24 suc24 rec24) (u Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case24 zero24 suc24 rec24) (v Tm24 var24 lam24 app24 tt24 pair24 fst24 snd24 left24 right24 case24 zero24 suc24 rec24) def v024 : ∀ {Γ A}, Tm24 (snoc24 Γ A) A := var24 vz24 def v124 : ∀ {Γ A B}, Tm24 (snoc24 (snoc24 Γ A) B) A := var24 (vs24 vz24) def v224 : ∀ {Γ A B C}, Tm24 (snoc24 (snoc24 (snoc24 Γ A) B) C) A := var24 (vs24 (vs24 vz24)) def v324 : ∀ {Γ A B C D}, Tm24 (snoc24 (snoc24 (snoc24 (snoc24 Γ A) B) C) D) A := var24 (vs24 (vs24 (vs24 vz24))) def tbool24 : Ty24 := sum24 top24 top24 def ttrue24 : ∀ {Γ}, Tm24 Γ tbool24 := left24 tt24 def tfalse24 : ∀ {Γ}, Tm24 Γ tbool24 := right24 tt24 def ifthenelse24 : ∀ {Γ A}, Tm24 Γ (arr24 tbool24 (arr24 A (arr24 A A))) := lam24 (lam24 (lam24 (case24 v224 (lam24 v224) (lam24 v124)))) def times424 : ∀ {Γ A}, Tm24 Γ (arr24 (arr24 A A) (arr24 A A)) := lam24 (lam24 (app24 v124 (app24 v124 (app24 v124 (app24 v124 v024))))) def add24 : ∀ {Γ}, Tm24 Γ (arr24 nat24 (arr24 nat24 nat24)) := lam24 (rec24 v024 (lam24 (lam24 (lam24 (suc24 (app24 v124 v024))))) (lam24 v024)) def mul24 : ∀ {Γ}, Tm24 Γ (arr24 nat24 (arr24 nat24 nat24)) := lam24 (rec24 v024 (lam24 (lam24 (lam24 (app24 (app24 add24 (app24 v124 v024)) v024)))) (lam24 zero24)) def fact24 : ∀ {Γ}, Tm24 Γ (arr24 nat24 nat24) := lam24 (rec24 v024 (lam24 (lam24 (app24 (app24 mul24 (suc24 v124)) v024))) (suc24 zero24)) def Ty25 : Type 1 := ∀ (Ty25 : Type) (nat top bot : Ty25) (arr prod sum : Ty25 → Ty25 → Ty25) , Ty25 def nat25 : Ty25 := λ _ nat25 _ _ _ _ _ => nat25 def top25 : Ty25 := λ _ _ top25 _ _ _ _ => top25 def bot25 : Ty25 := λ _ _ _ bot25 _ _ _ => bot25 def arr25 : Ty25 → Ty25 → Ty25 := λ A B Ty25 nat25 top25 bot25 arr25 prod sum => arr25 (A Ty25 nat25 top25 bot25 arr25 prod sum) (B Ty25 nat25 top25 bot25 arr25 prod sum) def prod25 : Ty25 → Ty25 → Ty25 := λ A B Ty25 nat25 top25 bot25 arr25 prod25 sum => prod25 (A Ty25 nat25 top25 bot25 arr25 prod25 sum) (B Ty25 nat25 top25 bot25 arr25 prod25 sum) def sum25 : Ty25 → Ty25 → Ty25 := λ A B Ty25 nat25 top25 bot25 arr25 prod25 sum25 => sum25 (A Ty25 nat25 top25 bot25 arr25 prod25 sum25) (B Ty25 nat25 top25 bot25 arr25 prod25 sum25) def Con25 : Type 1 := ∀ (Con25 : Type) (nil : Con25) (snoc : Con25 → Ty25 → Con25) , Con25 def nil25 : Con25 := λ Con25 nil25 snoc => nil25 def snoc25 : Con25 → Ty25 → Con25 := λ Γ A Con25 nil25 snoc25 => snoc25 (Γ Con25 nil25 snoc25) A def Var25 : Con25 → Ty25 → Type 1 := λ Γ A => ∀ (Var25 : Con25 → Ty25 → Type) (vz : ∀{Γ A}, Var25 (snoc25 Γ A) A) (vs : ∀{Γ B A}, Var25 Γ A → Var25 (snoc25 Γ B) A) , Var25 Γ A def vz25 : ∀ {Γ A}, Var25 (snoc25 Γ A) A := λ Var25 vz25 vs => vz25 def vs25 : ∀ {Γ B A}, Var25 Γ A → Var25 (snoc25 Γ B) A := λ x Var25 vz25 vs25 => vs25 (x Var25 vz25 vs25) def Tm25 : Con25 → Ty25 → Type 1 := λ Γ A => ∀ (Tm25 : Con25 → Ty25 → Type) (var : ∀ {Γ A}, Var25 Γ A → Tm25 Γ A) (lam : ∀ {Γ A B}, (Tm25 (snoc25 Γ A) B → Tm25 Γ (arr25 A B))) (app : ∀ {Γ A B} , Tm25 Γ (arr25 A B) → Tm25 Γ A → Tm25 Γ B) (tt : ∀ {Γ} , Tm25 Γ top25) (pair : ∀ {Γ A B} , Tm25 Γ A → Tm25 Γ B → Tm25 Γ (prod25 A B)) (fst : ∀ {Γ A B} , Tm25 Γ (prod25 A B) → Tm25 Γ A) (snd : ∀ {Γ A B} , Tm25 Γ (prod25 A B) → Tm25 Γ B) (left : ∀ {Γ A B} , Tm25 Γ A → Tm25 Γ (sum25 A B)) (right : ∀ {Γ A B} , Tm25 Γ B → Tm25 Γ (sum25 A B)) (case : ∀ {Γ A B C} , Tm25 Γ (sum25 A B) → Tm25 Γ (arr25 A C) → Tm25 Γ (arr25 B C) → Tm25 Γ C) (zero : ∀ {Γ} , Tm25 Γ nat25) (suc : ∀ {Γ} , Tm25 Γ nat25 → Tm25 Γ nat25) (rec : ∀ {Γ A} , Tm25 Γ nat25 → Tm25 Γ (arr25 nat25 (arr25 A A)) → Tm25 Γ A → Tm25 Γ A) , Tm25 Γ A def var25 : ∀ {Γ A}, Var25 Γ A → Tm25 Γ A := λ x Tm25 var25 lam app tt pair fst snd left right case zero suc rec => var25 x def lam25 : ∀ {Γ A B} , Tm25 (snoc25 Γ A) B → Tm25 Γ (arr25 A B) := λ t Tm25 var25 lam25 app tt pair fst snd left right case zero suc rec => lam25 (t Tm25 var25 lam25 app tt pair fst snd left right case zero suc rec) def app25 : ∀ {Γ A B} , Tm25 Γ (arr25 A B) → Tm25 Γ A → Tm25 Γ B := λ t u Tm25 var25 lam25 app25 tt pair fst snd left right case zero suc rec => app25 (t Tm25 var25 lam25 app25 tt pair fst snd left right case zero suc rec) (u Tm25 var25 lam25 app25 tt pair fst snd left right case zero suc rec) def tt25 : ∀ {Γ} , Tm25 Γ top25 := λ Tm25 var25 lam25 app25 tt25 pair fst snd left right case zero suc rec => tt25 def pair25 : ∀ {Γ A B} , Tm25 Γ A → Tm25 Γ B → Tm25 Γ (prod25 A B) := λ t u Tm25 var25 lam25 app25 tt25 pair25 fst snd left right case zero suc rec => pair25 (t Tm25 var25 lam25 app25 tt25 pair25 fst snd left right case zero suc rec) (u Tm25 var25 lam25 app25 tt25 pair25 fst snd left right case zero suc rec) def fst25 : ∀ {Γ A B} , Tm25 Γ (prod25 A B) → Tm25 Γ A := λ t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd left right case zero suc rec => fst25 (t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd left right case zero suc rec) def snd25 : ∀ {Γ A B} , Tm25 Γ (prod25 A B) → Tm25 Γ B := λ t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left right case zero suc rec => snd25 (t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left right case zero suc rec) def left25 : ∀ {Γ A B} , Tm25 Γ A → Tm25 Γ (sum25 A B) := λ t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right case zero suc rec => left25 (t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right case zero suc rec) def right25 : ∀ {Γ A B} , Tm25 Γ B → Tm25 Γ (sum25 A B) := λ t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case zero suc rec => right25 (t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case zero suc rec) def case25 : ∀ {Γ A B C} , Tm25 Γ (sum25 A B) → Tm25 Γ (arr25 A C) → Tm25 Γ (arr25 B C) → Tm25 Γ C := λ t u v Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case25 zero suc rec => case25 (t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case25 zero suc rec) (u Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case25 zero suc rec) (v Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case25 zero suc rec) def zero25 : ∀ {Γ} , Tm25 Γ nat25 := λ Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case25 zero25 suc rec => zero25 def suc25 : ∀ {Γ} , Tm25 Γ nat25 → Tm25 Γ nat25 := λ t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case25 zero25 suc25 rec => suc25 (t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case25 zero25 suc25 rec) def rec25 : ∀ {Γ A} , Tm25 Γ nat25 → Tm25 Γ (arr25 nat25 (arr25 A A)) → Tm25 Γ A → Tm25 Γ A := λ t u v Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case25 zero25 suc25 rec25 => rec25 (t Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case25 zero25 suc25 rec25) (u Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case25 zero25 suc25 rec25) (v Tm25 var25 lam25 app25 tt25 pair25 fst25 snd25 left25 right25 case25 zero25 suc25 rec25) def v025 : ∀ {Γ A}, Tm25 (snoc25 Γ A) A := var25 vz25 def v125 : ∀ {Γ A B}, Tm25 (snoc25 (snoc25 Γ A) B) A := var25 (vs25 vz25) def v225 : ∀ {Γ A B C}, Tm25 (snoc25 (snoc25 (snoc25 Γ A) B) C) A := var25 (vs25 (vs25 vz25)) def v325 : ∀ {Γ A B C D}, Tm25 (snoc25 (snoc25 (snoc25 (snoc25 Γ A) B) C) D) A := var25 (vs25 (vs25 (vs25 vz25))) def tbool25 : Ty25 := sum25 top25 top25 def ttrue25 : ∀ {Γ}, Tm25 Γ tbool25 := left25 tt25 def tfalse25 : ∀ {Γ}, Tm25 Γ tbool25 := right25 tt25 def ifthenelse25 : ∀ {Γ A}, Tm25 Γ (arr25 tbool25 (arr25 A (arr25 A A))) := lam25 (lam25 (lam25 (case25 v225 (lam25 v225) (lam25 v125)))) def times425 : ∀ {Γ A}, Tm25 Γ (arr25 (arr25 A A) (arr25 A A)) := lam25 (lam25 (app25 v125 (app25 v125 (app25 v125 (app25 v125 v025))))) def add25 : ∀ {Γ}, Tm25 Γ (arr25 nat25 (arr25 nat25 nat25)) := lam25 (rec25 v025 (lam25 (lam25 (lam25 (suc25 (app25 v125 v025))))) (lam25 v025)) def mul25 : ∀ {Γ}, Tm25 Γ (arr25 nat25 (arr25 nat25 nat25)) := lam25 (rec25 v025 (lam25 (lam25 (lam25 (app25 (app25 add25 (app25 v125 v025)) v025)))) (lam25 zero25)) def fact25 : ∀ {Γ}, Tm25 Γ (arr25 nat25 nat25) := lam25 (rec25 v025 (lam25 (lam25 (app25 (app25 mul25 (suc25 v125)) v025))) (suc25 zero25)) def Ty26 : Type 1 := ∀ (Ty26 : Type) (nat top bot : Ty26) (arr prod sum : Ty26 → Ty26 → Ty26) , Ty26 def nat26 : Ty26 := λ _ nat26 _ _ _ _ _ => nat26 def top26 : Ty26 := λ _ _ top26 _ _ _ _ => top26 def bot26 : Ty26 := λ _ _ _ bot26 _ _ _ => bot26 def arr26 : Ty26 → Ty26 → Ty26 := λ A B Ty26 nat26 top26 bot26 arr26 prod sum => arr26 (A Ty26 nat26 top26 bot26 arr26 prod sum) (B Ty26 nat26 top26 bot26 arr26 prod sum) def prod26 : Ty26 → Ty26 → Ty26 := λ A B Ty26 nat26 top26 bot26 arr26 prod26 sum => prod26 (A Ty26 nat26 top26 bot26 arr26 prod26 sum) (B Ty26 nat26 top26 bot26 arr26 prod26 sum) def sum26 : Ty26 → Ty26 → Ty26 := λ A B Ty26 nat26 top26 bot26 arr26 prod26 sum26 => sum26 (A Ty26 nat26 top26 bot26 arr26 prod26 sum26) (B Ty26 nat26 top26 bot26 arr26 prod26 sum26) def Con26 : Type 1 := ∀ (Con26 : Type) (nil : Con26) (snoc : Con26 → Ty26 → Con26) , Con26 def nil26 : Con26 := λ Con26 nil26 snoc => nil26 def snoc26 : Con26 → Ty26 → Con26 := λ Γ A Con26 nil26 snoc26 => snoc26 (Γ Con26 nil26 snoc26) A def Var26 : Con26 → Ty26 → Type 1 := λ Γ A => ∀ (Var26 : Con26 → Ty26 → Type) (vz : ∀{Γ A}, Var26 (snoc26 Γ A) A) (vs : ∀{Γ B A}, Var26 Γ A → Var26 (snoc26 Γ B) A) , Var26 Γ A def vz26 : ∀ {Γ A}, Var26 (snoc26 Γ A) A := λ Var26 vz26 vs => vz26 def vs26 : ∀ {Γ B A}, Var26 Γ A → Var26 (snoc26 Γ B) A := λ x Var26 vz26 vs26 => vs26 (x Var26 vz26 vs26) def Tm26 : Con26 → Ty26 → Type 1 := λ Γ A => ∀ (Tm26 : Con26 → Ty26 → Type) (var : ∀ {Γ A}, Var26 Γ A → Tm26 Γ A) (lam : ∀ {Γ A B}, (Tm26 (snoc26 Γ A) B → Tm26 Γ (arr26 A B))) (app : ∀ {Γ A B} , Tm26 Γ (arr26 A B) → Tm26 Γ A → Tm26 Γ B) (tt : ∀ {Γ} , Tm26 Γ top26) (pair : ∀ {Γ A B} , Tm26 Γ A → Tm26 Γ B → Tm26 Γ (prod26 A B)) (fst : ∀ {Γ A B} , Tm26 Γ (prod26 A B) → Tm26 Γ A) (snd : ∀ {Γ A B} , Tm26 Γ (prod26 A B) → Tm26 Γ B) (left : ∀ {Γ A B} , Tm26 Γ A → Tm26 Γ (sum26 A B)) (right : ∀ {Γ A B} , Tm26 Γ B → Tm26 Γ (sum26 A B)) (case : ∀ {Γ A B C} , Tm26 Γ (sum26 A B) → Tm26 Γ (arr26 A C) → Tm26 Γ (arr26 B C) → Tm26 Γ C) (zero : ∀ {Γ} , Tm26 Γ nat26) (suc : ∀ {Γ} , Tm26 Γ nat26 → Tm26 Γ nat26) (rec : ∀ {Γ A} , Tm26 Γ nat26 → Tm26 Γ (arr26 nat26 (arr26 A A)) → Tm26 Γ A → Tm26 Γ A) , Tm26 Γ A def var26 : ∀ {Γ A}, Var26 Γ A → Tm26 Γ A := λ x Tm26 var26 lam app tt pair fst snd left right case zero suc rec => var26 x def lam26 : ∀ {Γ A B} , Tm26 (snoc26 Γ A) B → Tm26 Γ (arr26 A B) := λ t Tm26 var26 lam26 app tt pair fst snd left right case zero suc rec => lam26 (t Tm26 var26 lam26 app tt pair fst snd left right case zero suc rec) def app26 : ∀ {Γ A B} , Tm26 Γ (arr26 A B) → Tm26 Γ A → Tm26 Γ B := λ t u Tm26 var26 lam26 app26 tt pair fst snd left right case zero suc rec => app26 (t Tm26 var26 lam26 app26 tt pair fst snd left right case zero suc rec) (u Tm26 var26 lam26 app26 tt pair fst snd left right case zero suc rec) def tt26 : ∀ {Γ} , Tm26 Γ top26 := λ Tm26 var26 lam26 app26 tt26 pair fst snd left right case zero suc rec => tt26 def pair26 : ∀ {Γ A B} , Tm26 Γ A → Tm26 Γ B → Tm26 Γ (prod26 A B) := λ t u Tm26 var26 lam26 app26 tt26 pair26 fst snd left right case zero suc rec => pair26 (t Tm26 var26 lam26 app26 tt26 pair26 fst snd left right case zero suc rec) (u Tm26 var26 lam26 app26 tt26 pair26 fst snd left right case zero suc rec) def fst26 : ∀ {Γ A B} , Tm26 Γ (prod26 A B) → Tm26 Γ A := λ t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd left right case zero suc rec => fst26 (t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd left right case zero suc rec) def snd26 : ∀ {Γ A B} , Tm26 Γ (prod26 A B) → Tm26 Γ B := λ t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left right case zero suc rec => snd26 (t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left right case zero suc rec) def left26 : ∀ {Γ A B} , Tm26 Γ A → Tm26 Γ (sum26 A B) := λ t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right case zero suc rec => left26 (t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right case zero suc rec) def right26 : ∀ {Γ A B} , Tm26 Γ B → Tm26 Γ (sum26 A B) := λ t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case zero suc rec => right26 (t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case zero suc rec) def case26 : ∀ {Γ A B C} , Tm26 Γ (sum26 A B) → Tm26 Γ (arr26 A C) → Tm26 Γ (arr26 B C) → Tm26 Γ C := λ t u v Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case26 zero suc rec => case26 (t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case26 zero suc rec) (u Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case26 zero suc rec) (v Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case26 zero suc rec) def zero26 : ∀ {Γ} , Tm26 Γ nat26 := λ Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case26 zero26 suc rec => zero26 def suc26 : ∀ {Γ} , Tm26 Γ nat26 → Tm26 Γ nat26 := λ t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case26 zero26 suc26 rec => suc26 (t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case26 zero26 suc26 rec) def rec26 : ∀ {Γ A} , Tm26 Γ nat26 → Tm26 Γ (arr26 nat26 (arr26 A A)) → Tm26 Γ A → Tm26 Γ A := λ t u v Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case26 zero26 suc26 rec26 => rec26 (t Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case26 zero26 suc26 rec26) (u Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case26 zero26 suc26 rec26) (v Tm26 var26 lam26 app26 tt26 pair26 fst26 snd26 left26 right26 case26 zero26 suc26 rec26) def v026 : ∀ {Γ A}, Tm26 (snoc26 Γ A) A := var26 vz26 def v126 : ∀ {Γ A B}, Tm26 (snoc26 (snoc26 Γ A) B) A := var26 (vs26 vz26) def v226 : ∀ {Γ A B C}, Tm26 (snoc26 (snoc26 (snoc26 Γ A) B) C) A := var26 (vs26 (vs26 vz26)) def v326 : ∀ {Γ A B C D}, Tm26 (snoc26 (snoc26 (snoc26 (snoc26 Γ A) B) C) D) A := var26 (vs26 (vs26 (vs26 vz26))) def tbool26 : Ty26 := sum26 top26 top26 def ttrue26 : ∀ {Γ}, Tm26 Γ tbool26 := left26 tt26 def tfalse26 : ∀ {Γ}, Tm26 Γ tbool26 := right26 tt26 def ifthenelse26 : ∀ {Γ A}, Tm26 Γ (arr26 tbool26 (arr26 A (arr26 A A))) := lam26 (lam26 (lam26 (case26 v226 (lam26 v226) (lam26 v126)))) def times426 : ∀ {Γ A}, Tm26 Γ (arr26 (arr26 A A) (arr26 A A)) := lam26 (lam26 (app26 v126 (app26 v126 (app26 v126 (app26 v126 v026))))) def add26 : ∀ {Γ}, Tm26 Γ (arr26 nat26 (arr26 nat26 nat26)) := lam26 (rec26 v026 (lam26 (lam26 (lam26 (suc26 (app26 v126 v026))))) (lam26 v026)) def mul26 : ∀ {Γ}, Tm26 Γ (arr26 nat26 (arr26 nat26 nat26)) := lam26 (rec26 v026 (lam26 (lam26 (lam26 (app26 (app26 add26 (app26 v126 v026)) v026)))) (lam26 zero26)) def fact26 : ∀ {Γ}, Tm26 Γ (arr26 nat26 nat26) := lam26 (rec26 v026 (lam26 (lam26 (app26 (app26 mul26 (suc26 v126)) v026))) (suc26 zero26)) def Ty27 : Type 1 := ∀ (Ty27 : Type) (nat top bot : Ty27) (arr prod sum : Ty27 → Ty27 → Ty27) , Ty27 def nat27 : Ty27 := λ _ nat27 _ _ _ _ _ => nat27 def top27 : Ty27 := λ _ _ top27 _ _ _ _ => top27 def bot27 : Ty27 := λ _ _ _ bot27 _ _ _ => bot27 def arr27 : Ty27 → Ty27 → Ty27 := λ A B Ty27 nat27 top27 bot27 arr27 prod sum => arr27 (A Ty27 nat27 top27 bot27 arr27 prod sum) (B Ty27 nat27 top27 bot27 arr27 prod sum) def prod27 : Ty27 → Ty27 → Ty27 := λ A B Ty27 nat27 top27 bot27 arr27 prod27 sum => prod27 (A Ty27 nat27 top27 bot27 arr27 prod27 sum) (B Ty27 nat27 top27 bot27 arr27 prod27 sum) def sum27 : Ty27 → Ty27 → Ty27 := λ A B Ty27 nat27 top27 bot27 arr27 prod27 sum27 => sum27 (A Ty27 nat27 top27 bot27 arr27 prod27 sum27) (B Ty27 nat27 top27 bot27 arr27 prod27 sum27) def Con27 : Type 1 := ∀ (Con27 : Type) (nil : Con27) (snoc : Con27 → Ty27 → Con27) , Con27 def nil27 : Con27 := λ Con27 nil27 snoc => nil27 def snoc27 : Con27 → Ty27 → Con27 := λ Γ A Con27 nil27 snoc27 => snoc27 (Γ Con27 nil27 snoc27) A def Var27 : Con27 → Ty27 → Type 1 := λ Γ A => ∀ (Var27 : Con27 → Ty27 → Type) (vz : ∀{Γ A}, Var27 (snoc27 Γ A) A) (vs : ∀{Γ B A}, Var27 Γ A → Var27 (snoc27 Γ B) A) , Var27 Γ A def vz27 : ∀ {Γ A}, Var27 (snoc27 Γ A) A := λ Var27 vz27 vs => vz27 def vs27 : ∀ {Γ B A}, Var27 Γ A → Var27 (snoc27 Γ B) A := λ x Var27 vz27 vs27 => vs27 (x Var27 vz27 vs27) def Tm27 : Con27 → Ty27 → Type 1 := λ Γ A => ∀ (Tm27 : Con27 → Ty27 → Type) (var : ∀ {Γ A}, Var27 Γ A → Tm27 Γ A) (lam : ∀ {Γ A B}, (Tm27 (snoc27 Γ A) B → Tm27 Γ (arr27 A B))) (app : ∀ {Γ A B} , Tm27 Γ (arr27 A B) → Tm27 Γ A → Tm27 Γ B) (tt : ∀ {Γ} , Tm27 Γ top27) (pair : ∀ {Γ A B} , Tm27 Γ A → Tm27 Γ B → Tm27 Γ (prod27 A B)) (fst : ∀ {Γ A B} , Tm27 Γ (prod27 A B) → Tm27 Γ A) (snd : ∀ {Γ A B} , Tm27 Γ (prod27 A B) → Tm27 Γ B) (left : ∀ {Γ A B} , Tm27 Γ A → Tm27 Γ (sum27 A B)) (right : ∀ {Γ A B} , Tm27 Γ B → Tm27 Γ (sum27 A B)) (case : ∀ {Γ A B C} , Tm27 Γ (sum27 A B) → Tm27 Γ (arr27 A C) → Tm27 Γ (arr27 B C) → Tm27 Γ C) (zero : ∀ {Γ} , Tm27 Γ nat27) (suc : ∀ {Γ} , Tm27 Γ nat27 → Tm27 Γ nat27) (rec : ∀ {Γ A} , Tm27 Γ nat27 → Tm27 Γ (arr27 nat27 (arr27 A A)) → Tm27 Γ A → Tm27 Γ A) , Tm27 Γ A def var27 : ∀ {Γ A}, Var27 Γ A → Tm27 Γ A := λ x Tm27 var27 lam app tt pair fst snd left right case zero suc rec => var27 x def lam27 : ∀ {Γ A B} , Tm27 (snoc27 Γ A) B → Tm27 Γ (arr27 A B) := λ t Tm27 var27 lam27 app tt pair fst snd left right case zero suc rec => lam27 (t Tm27 var27 lam27 app tt pair fst snd left right case zero suc rec) def app27 : ∀ {Γ A B} , Tm27 Γ (arr27 A B) → Tm27 Γ A → Tm27 Γ B := λ t u Tm27 var27 lam27 app27 tt pair fst snd left right case zero suc rec => app27 (t Tm27 var27 lam27 app27 tt pair fst snd left right case zero suc rec) (u Tm27 var27 lam27 app27 tt pair fst snd left right case zero suc rec) def tt27 : ∀ {Γ} , Tm27 Γ top27 := λ Tm27 var27 lam27 app27 tt27 pair fst snd left right case zero suc rec => tt27 def pair27 : ∀ {Γ A B} , Tm27 Γ A → Tm27 Γ B → Tm27 Γ (prod27 A B) := λ t u Tm27 var27 lam27 app27 tt27 pair27 fst snd left right case zero suc rec => pair27 (t Tm27 var27 lam27 app27 tt27 pair27 fst snd left right case zero suc rec) (u Tm27 var27 lam27 app27 tt27 pair27 fst snd left right case zero suc rec) def fst27 : ∀ {Γ A B} , Tm27 Γ (prod27 A B) → Tm27 Γ A := λ t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd left right case zero suc rec => fst27 (t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd left right case zero suc rec) def snd27 : ∀ {Γ A B} , Tm27 Γ (prod27 A B) → Tm27 Γ B := λ t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left right case zero suc rec => snd27 (t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left right case zero suc rec) def left27 : ∀ {Γ A B} , Tm27 Γ A → Tm27 Γ (sum27 A B) := λ t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right case zero suc rec => left27 (t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right case zero suc rec) def right27 : ∀ {Γ A B} , Tm27 Γ B → Tm27 Γ (sum27 A B) := λ t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case zero suc rec => right27 (t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case zero suc rec) def case27 : ∀ {Γ A B C} , Tm27 Γ (sum27 A B) → Tm27 Γ (arr27 A C) → Tm27 Γ (arr27 B C) → Tm27 Γ C := λ t u v Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case27 zero suc rec => case27 (t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case27 zero suc rec) (u Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case27 zero suc rec) (v Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case27 zero suc rec) def zero27 : ∀ {Γ} , Tm27 Γ nat27 := λ Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case27 zero27 suc rec => zero27 def suc27 : ∀ {Γ} , Tm27 Γ nat27 → Tm27 Γ nat27 := λ t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case27 zero27 suc27 rec => suc27 (t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case27 zero27 suc27 rec) def rec27 : ∀ {Γ A} , Tm27 Γ nat27 → Tm27 Γ (arr27 nat27 (arr27 A A)) → Tm27 Γ A → Tm27 Γ A := λ t u v Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case27 zero27 suc27 rec27 => rec27 (t Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case27 zero27 suc27 rec27) (u Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case27 zero27 suc27 rec27) (v Tm27 var27 lam27 app27 tt27 pair27 fst27 snd27 left27 right27 case27 zero27 suc27 rec27) def v027 : ∀ {Γ A}, Tm27 (snoc27 Γ A) A := var27 vz27 def v127 : ∀ {Γ A B}, Tm27 (snoc27 (snoc27 Γ A) B) A := var27 (vs27 vz27) def v227 : ∀ {Γ A B C}, Tm27 (snoc27 (snoc27 (snoc27 Γ A) B) C) A := var27 (vs27 (vs27 vz27)) def v327 : ∀ {Γ A B C D}, Tm27 (snoc27 (snoc27 (snoc27 (snoc27 Γ A) B) C) D) A := var27 (vs27 (vs27 (vs27 vz27))) def tbool27 : Ty27 := sum27 top27 top27 def ttrue27 : ∀ {Γ}, Tm27 Γ tbool27 := left27 tt27 def tfalse27 : ∀ {Γ}, Tm27 Γ tbool27 := right27 tt27 def ifthenelse27 : ∀ {Γ A}, Tm27 Γ (arr27 tbool27 (arr27 A (arr27 A A))) := lam27 (lam27 (lam27 (case27 v227 (lam27 v227) (lam27 v127)))) def times427 : ∀ {Γ A}, Tm27 Γ (arr27 (arr27 A A) (arr27 A A)) := lam27 (lam27 (app27 v127 (app27 v127 (app27 v127 (app27 v127 v027))))) def add27 : ∀ {Γ}, Tm27 Γ (arr27 nat27 (arr27 nat27 nat27)) := lam27 (rec27 v027 (lam27 (lam27 (lam27 (suc27 (app27 v127 v027))))) (lam27 v027)) def mul27 : ∀ {Γ}, Tm27 Γ (arr27 nat27 (arr27 nat27 nat27)) := lam27 (rec27 v027 (lam27 (lam27 (lam27 (app27 (app27 add27 (app27 v127 v027)) v027)))) (lam27 zero27)) def fact27 : ∀ {Γ}, Tm27 Γ (arr27 nat27 nat27) := lam27 (rec27 v027 (lam27 (lam27 (app27 (app27 mul27 (suc27 v127)) v027))) (suc27 zero27)) def Ty28 : Type 1 := ∀ (Ty28 : Type) (nat top bot : Ty28) (arr prod sum : Ty28 → Ty28 → Ty28) , Ty28 def nat28 : Ty28 := λ _ nat28 _ _ _ _ _ => nat28 def top28 : Ty28 := λ _ _ top28 _ _ _ _ => top28 def bot28 : Ty28 := λ _ _ _ bot28 _ _ _ => bot28 def arr28 : Ty28 → Ty28 → Ty28 := λ A B Ty28 nat28 top28 bot28 arr28 prod sum => arr28 (A Ty28 nat28 top28 bot28 arr28 prod sum) (B Ty28 nat28 top28 bot28 arr28 prod sum) def prod28 : Ty28 → Ty28 → Ty28 := λ A B Ty28 nat28 top28 bot28 arr28 prod28 sum => prod28 (A Ty28 nat28 top28 bot28 arr28 prod28 sum) (B Ty28 nat28 top28 bot28 arr28 prod28 sum) def sum28 : Ty28 → Ty28 → Ty28 := λ A B Ty28 nat28 top28 bot28 arr28 prod28 sum28 => sum28 (A Ty28 nat28 top28 bot28 arr28 prod28 sum28) (B Ty28 nat28 top28 bot28 arr28 prod28 sum28) def Con28 : Type 1 := ∀ (Con28 : Type) (nil : Con28) (snoc : Con28 → Ty28 → Con28) , Con28 def nil28 : Con28 := λ Con28 nil28 snoc => nil28 def snoc28 : Con28 → Ty28 → Con28 := λ Γ A Con28 nil28 snoc28 => snoc28 (Γ Con28 nil28 snoc28) A def Var28 : Con28 → Ty28 → Type 1 := λ Γ A => ∀ (Var28 : Con28 → Ty28 → Type) (vz : ∀{Γ A}, Var28 (snoc28 Γ A) A) (vs : ∀{Γ B A}, Var28 Γ A → Var28 (snoc28 Γ B) A) , Var28 Γ A def vz28 : ∀ {Γ A}, Var28 (snoc28 Γ A) A := λ Var28 vz28 vs => vz28 def vs28 : ∀ {Γ B A}, Var28 Γ A → Var28 (snoc28 Γ B) A := λ x Var28 vz28 vs28 => vs28 (x Var28 vz28 vs28) def Tm28 : Con28 → Ty28 → Type 1 := λ Γ A => ∀ (Tm28 : Con28 → Ty28 → Type) (var : ∀ {Γ A}, Var28 Γ A → Tm28 Γ A) (lam : ∀ {Γ A B}, (Tm28 (snoc28 Γ A) B → Tm28 Γ (arr28 A B))) (app : ∀ {Γ A B} , Tm28 Γ (arr28 A B) → Tm28 Γ A → Tm28 Γ B) (tt : ∀ {Γ} , Tm28 Γ top28) (pair : ∀ {Γ A B} , Tm28 Γ A → Tm28 Γ B → Tm28 Γ (prod28 A B)) (fst : ∀ {Γ A B} , Tm28 Γ (prod28 A B) → Tm28 Γ A) (snd : ∀ {Γ A B} , Tm28 Γ (prod28 A B) → Tm28 Γ B) (left : ∀ {Γ A B} , Tm28 Γ A → Tm28 Γ (sum28 A B)) (right : ∀ {Γ A B} , Tm28 Γ B → Tm28 Γ (sum28 A B)) (case : ∀ {Γ A B C} , Tm28 Γ (sum28 A B) → Tm28 Γ (arr28 A C) → Tm28 Γ (arr28 B C) → Tm28 Γ C) (zero : ∀ {Γ} , Tm28 Γ nat28) (suc : ∀ {Γ} , Tm28 Γ nat28 → Tm28 Γ nat28) (rec : ∀ {Γ A} , Tm28 Γ nat28 → Tm28 Γ (arr28 nat28 (arr28 A A)) → Tm28 Γ A → Tm28 Γ A) , Tm28 Γ A def var28 : ∀ {Γ A}, Var28 Γ A → Tm28 Γ A := λ x Tm28 var28 lam app tt pair fst snd left right case zero suc rec => var28 x def lam28 : ∀ {Γ A B} , Tm28 (snoc28 Γ A) B → Tm28 Γ (arr28 A B) := λ t Tm28 var28 lam28 app tt pair fst snd left right case zero suc rec => lam28 (t Tm28 var28 lam28 app tt pair fst snd left right case zero suc rec) def app28 : ∀ {Γ A B} , Tm28 Γ (arr28 A B) → Tm28 Γ A → Tm28 Γ B := λ t u Tm28 var28 lam28 app28 tt pair fst snd left right case zero suc rec => app28 (t Tm28 var28 lam28 app28 tt pair fst snd left right case zero suc rec) (u Tm28 var28 lam28 app28 tt pair fst snd left right case zero suc rec) def tt28 : ∀ {Γ} , Tm28 Γ top28 := λ Tm28 var28 lam28 app28 tt28 pair fst snd left right case zero suc rec => tt28 def pair28 : ∀ {Γ A B} , Tm28 Γ A → Tm28 Γ B → Tm28 Γ (prod28 A B) := λ t u Tm28 var28 lam28 app28 tt28 pair28 fst snd left right case zero suc rec => pair28 (t Tm28 var28 lam28 app28 tt28 pair28 fst snd left right case zero suc rec) (u Tm28 var28 lam28 app28 tt28 pair28 fst snd left right case zero suc rec) def fst28 : ∀ {Γ A B} , Tm28 Γ (prod28 A B) → Tm28 Γ A := λ t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd left right case zero suc rec => fst28 (t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd left right case zero suc rec) def snd28 : ∀ {Γ A B} , Tm28 Γ (prod28 A B) → Tm28 Γ B := λ t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left right case zero suc rec => snd28 (t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left right case zero suc rec) def left28 : ∀ {Γ A B} , Tm28 Γ A → Tm28 Γ (sum28 A B) := λ t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right case zero suc rec => left28 (t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right case zero suc rec) def right28 : ∀ {Γ A B} , Tm28 Γ B → Tm28 Γ (sum28 A B) := λ t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case zero suc rec => right28 (t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case zero suc rec) def case28 : ∀ {Γ A B C} , Tm28 Γ (sum28 A B) → Tm28 Γ (arr28 A C) → Tm28 Γ (arr28 B C) → Tm28 Γ C := λ t u v Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case28 zero suc rec => case28 (t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case28 zero suc rec) (u Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case28 zero suc rec) (v Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case28 zero suc rec) def zero28 : ∀ {Γ} , Tm28 Γ nat28 := λ Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case28 zero28 suc rec => zero28 def suc28 : ∀ {Γ} , Tm28 Γ nat28 → Tm28 Γ nat28 := λ t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case28 zero28 suc28 rec => suc28 (t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case28 zero28 suc28 rec) def rec28 : ∀ {Γ A} , Tm28 Γ nat28 → Tm28 Γ (arr28 nat28 (arr28 A A)) → Tm28 Γ A → Tm28 Γ A := λ t u v Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case28 zero28 suc28 rec28 => rec28 (t Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case28 zero28 suc28 rec28) (u Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case28 zero28 suc28 rec28) (v Tm28 var28 lam28 app28 tt28 pair28 fst28 snd28 left28 right28 case28 zero28 suc28 rec28) def v028 : ∀ {Γ A}, Tm28 (snoc28 Γ A) A := var28 vz28 def v128 : ∀ {Γ A B}, Tm28 (snoc28 (snoc28 Γ A) B) A := var28 (vs28 vz28) def v228 : ∀ {Γ A B C}, Tm28 (snoc28 (snoc28 (snoc28 Γ A) B) C) A := var28 (vs28 (vs28 vz28)) def v328 : ∀ {Γ A B C D}, Tm28 (snoc28 (snoc28 (snoc28 (snoc28 Γ A) B) C) D) A := var28 (vs28 (vs28 (vs28 vz28))) def tbool28 : Ty28 := sum28 top28 top28 def ttrue28 : ∀ {Γ}, Tm28 Γ tbool28 := left28 tt28 def tfalse28 : ∀ {Γ}, Tm28 Γ tbool28 := right28 tt28 def ifthenelse28 : ∀ {Γ A}, Tm28 Γ (arr28 tbool28 (arr28 A (arr28 A A))) := lam28 (lam28 (lam28 (case28 v228 (lam28 v228) (lam28 v128)))) def times428 : ∀ {Γ A}, Tm28 Γ (arr28 (arr28 A A) (arr28 A A)) := lam28 (lam28 (app28 v128 (app28 v128 (app28 v128 (app28 v128 v028))))) def add28 : ∀ {Γ}, Tm28 Γ (arr28 nat28 (arr28 nat28 nat28)) := lam28 (rec28 v028 (lam28 (lam28 (lam28 (suc28 (app28 v128 v028))))) (lam28 v028)) def mul28 : ∀ {Γ}, Tm28 Γ (arr28 nat28 (arr28 nat28 nat28)) := lam28 (rec28 v028 (lam28 (lam28 (lam28 (app28 (app28 add28 (app28 v128 v028)) v028)))) (lam28 zero28)) def fact28 : ∀ {Γ}, Tm28 Γ (arr28 nat28 nat28) := lam28 (rec28 v028 (lam28 (lam28 (app28 (app28 mul28 (suc28 v128)) v028))) (suc28 zero28)) def Ty29 : Type 1 := ∀ (Ty29 : Type) (nat top bot : Ty29) (arr prod sum : Ty29 → Ty29 → Ty29) , Ty29 def nat29 : Ty29 := λ _ nat29 _ _ _ _ _ => nat29 def top29 : Ty29 := λ _ _ top29 _ _ _ _ => top29 def bot29 : Ty29 := λ _ _ _ bot29 _ _ _ => bot29 def arr29 : Ty29 → Ty29 → Ty29 := λ A B Ty29 nat29 top29 bot29 arr29 prod sum => arr29 (A Ty29 nat29 top29 bot29 arr29 prod sum) (B Ty29 nat29 top29 bot29 arr29 prod sum) def prod29 : Ty29 → Ty29 → Ty29 := λ A B Ty29 nat29 top29 bot29 arr29 prod29 sum => prod29 (A Ty29 nat29 top29 bot29 arr29 prod29 sum) (B Ty29 nat29 top29 bot29 arr29 prod29 sum) def sum29 : Ty29 → Ty29 → Ty29 := λ A B Ty29 nat29 top29 bot29 arr29 prod29 sum29 => sum29 (A Ty29 nat29 top29 bot29 arr29 prod29 sum29) (B Ty29 nat29 top29 bot29 arr29 prod29 sum29) def Con29 : Type 1 := ∀ (Con29 : Type) (nil : Con29) (snoc : Con29 → Ty29 → Con29) , Con29 def nil29 : Con29 := λ Con29 nil29 snoc => nil29 def snoc29 : Con29 → Ty29 → Con29 := λ Γ A Con29 nil29 snoc29 => snoc29 (Γ Con29 nil29 snoc29) A def Var29 : Con29 → Ty29 → Type 1 := λ Γ A => ∀ (Var29 : Con29 → Ty29 → Type) (vz : ∀{Γ A}, Var29 (snoc29 Γ A) A) (vs : ∀{Γ B A}, Var29 Γ A → Var29 (snoc29 Γ B) A) , Var29 Γ A def vz29 : ∀ {Γ A}, Var29 (snoc29 Γ A) A := λ Var29 vz29 vs => vz29 def vs29 : ∀ {Γ B A}, Var29 Γ A → Var29 (snoc29 Γ B) A := λ x Var29 vz29 vs29 => vs29 (x Var29 vz29 vs29) def Tm29 : Con29 → Ty29 → Type 1 := λ Γ A => ∀ (Tm29 : Con29 → Ty29 → Type) (var : ∀ {Γ A}, Var29 Γ A → Tm29 Γ A) (lam : ∀ {Γ A B}, (Tm29 (snoc29 Γ A) B → Tm29 Γ (arr29 A B))) (app : ∀ {Γ A B} , Tm29 Γ (arr29 A B) → Tm29 Γ A → Tm29 Γ B) (tt : ∀ {Γ} , Tm29 Γ top29) (pair : ∀ {Γ A B} , Tm29 Γ A → Tm29 Γ B → Tm29 Γ (prod29 A B)) (fst : ∀ {Γ A B} , Tm29 Γ (prod29 A B) → Tm29 Γ A) (snd : ∀ {Γ A B} , Tm29 Γ (prod29 A B) → Tm29 Γ B) (left : ∀ {Γ A B} , Tm29 Γ A → Tm29 Γ (sum29 A B)) (right : ∀ {Γ A B} , Tm29 Γ B → Tm29 Γ (sum29 A B)) (case : ∀ {Γ A B C} , Tm29 Γ (sum29 A B) → Tm29 Γ (arr29 A C) → Tm29 Γ (arr29 B C) → Tm29 Γ C) (zero : ∀ {Γ} , Tm29 Γ nat29) (suc : ∀ {Γ} , Tm29 Γ nat29 → Tm29 Γ nat29) (rec : ∀ {Γ A} , Tm29 Γ nat29 → Tm29 Γ (arr29 nat29 (arr29 A A)) → Tm29 Γ A → Tm29 Γ A) , Tm29 Γ A def var29 : ∀ {Γ A}, Var29 Γ A → Tm29 Γ A := λ x Tm29 var29 lam app tt pair fst snd left right case zero suc rec => var29 x def lam29 : ∀ {Γ A B} , Tm29 (snoc29 Γ A) B → Tm29 Γ (arr29 A B) := λ t Tm29 var29 lam29 app tt pair fst snd left right case zero suc rec => lam29 (t Tm29 var29 lam29 app tt pair fst snd left right case zero suc rec) def app29 : ∀ {Γ A B} , Tm29 Γ (arr29 A B) → Tm29 Γ A → Tm29 Γ B := λ t u Tm29 var29 lam29 app29 tt pair fst snd left right case zero suc rec => app29 (t Tm29 var29 lam29 app29 tt pair fst snd left right case zero suc rec) (u Tm29 var29 lam29 app29 tt pair fst snd left right case zero suc rec) def tt29 : ∀ {Γ} , Tm29 Γ top29 := λ Tm29 var29 lam29 app29 tt29 pair fst snd left right case zero suc rec => tt29 def pair29 : ∀ {Γ A B} , Tm29 Γ A → Tm29 Γ B → Tm29 Γ (prod29 A B) := λ t u Tm29 var29 lam29 app29 tt29 pair29 fst snd left right case zero suc rec => pair29 (t Tm29 var29 lam29 app29 tt29 pair29 fst snd left right case zero suc rec) (u Tm29 var29 lam29 app29 tt29 pair29 fst snd left right case zero suc rec) def fst29 : ∀ {Γ A B} , Tm29 Γ (prod29 A B) → Tm29 Γ A := λ t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd left right case zero suc rec => fst29 (t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd left right case zero suc rec) def snd29 : ∀ {Γ A B} , Tm29 Γ (prod29 A B) → Tm29 Γ B := λ t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left right case zero suc rec => snd29 (t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left right case zero suc rec) def left29 : ∀ {Γ A B} , Tm29 Γ A → Tm29 Γ (sum29 A B) := λ t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right case zero suc rec => left29 (t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right case zero suc rec) def right29 : ∀ {Γ A B} , Tm29 Γ B → Tm29 Γ (sum29 A B) := λ t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case zero suc rec => right29 (t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case zero suc rec) def case29 : ∀ {Γ A B C} , Tm29 Γ (sum29 A B) → Tm29 Γ (arr29 A C) → Tm29 Γ (arr29 B C) → Tm29 Γ C := λ t u v Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case29 zero suc rec => case29 (t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case29 zero suc rec) (u Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case29 zero suc rec) (v Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case29 zero suc rec) def zero29 : ∀ {Γ} , Tm29 Γ nat29 := λ Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case29 zero29 suc rec => zero29 def suc29 : ∀ {Γ} , Tm29 Γ nat29 → Tm29 Γ nat29 := λ t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case29 zero29 suc29 rec => suc29 (t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case29 zero29 suc29 rec) def rec29 : ∀ {Γ A} , Tm29 Γ nat29 → Tm29 Γ (arr29 nat29 (arr29 A A)) → Tm29 Γ A → Tm29 Γ A := λ t u v Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case29 zero29 suc29 rec29 => rec29 (t Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case29 zero29 suc29 rec29) (u Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case29 zero29 suc29 rec29) (v Tm29 var29 lam29 app29 tt29 pair29 fst29 snd29 left29 right29 case29 zero29 suc29 rec29) def v029 : ∀ {Γ A}, Tm29 (snoc29 Γ A) A := var29 vz29 def v129 : ∀ {Γ A B}, Tm29 (snoc29 (snoc29 Γ A) B) A := var29 (vs29 vz29) def v229 : ∀ {Γ A B C}, Tm29 (snoc29 (snoc29 (snoc29 Γ A) B) C) A := var29 (vs29 (vs29 vz29)) def v329 : ∀ {Γ A B C D}, Tm29 (snoc29 (snoc29 (snoc29 (snoc29 Γ A) B) C) D) A := var29 (vs29 (vs29 (vs29 vz29))) def tbool29 : Ty29 := sum29 top29 top29 def ttrue29 : ∀ {Γ}, Tm29 Γ tbool29 := left29 tt29 def tfalse29 : ∀ {Γ}, Tm29 Γ tbool29 := right29 tt29 def ifthenelse29 : ∀ {Γ A}, Tm29 Γ (arr29 tbool29 (arr29 A (arr29 A A))) := lam29 (lam29 (lam29 (case29 v229 (lam29 v229) (lam29 v129)))) def times429 : ∀ {Γ A}, Tm29 Γ (arr29 (arr29 A A) (arr29 A A)) := lam29 (lam29 (app29 v129 (app29 v129 (app29 v129 (app29 v129 v029))))) def add29 : ∀ {Γ}, Tm29 Γ (arr29 nat29 (arr29 nat29 nat29)) := lam29 (rec29 v029 (lam29 (lam29 (lam29 (suc29 (app29 v129 v029))))) (lam29 v029)) def mul29 : ∀ {Γ}, Tm29 Γ (arr29 nat29 (arr29 nat29 nat29)) := lam29 (rec29 v029 (lam29 (lam29 (lam29 (app29 (app29 add29 (app29 v129 v029)) v029)))) (lam29 zero29)) def fact29 : ∀ {Γ}, Tm29 Γ (arr29 nat29 nat29) := lam29 (rec29 v029 (lam29 (lam29 (app29 (app29 mul29 (suc29 v129)) v029))) (suc29 zero29)) def Ty30 : Type 1 := ∀ (Ty30 : Type) (nat top bot : Ty30) (arr prod sum : Ty30 → Ty30 → Ty30) , Ty30 def nat30 : Ty30 := λ _ nat30 _ _ _ _ _ => nat30 def top30 : Ty30 := λ _ _ top30 _ _ _ _ => top30 def bot30 : Ty30 := λ _ _ _ bot30 _ _ _ => bot30 def arr30 : Ty30 → Ty30 → Ty30 := λ A B Ty30 nat30 top30 bot30 arr30 prod sum => arr30 (A Ty30 nat30 top30 bot30 arr30 prod sum) (B Ty30 nat30 top30 bot30 arr30 prod sum) def prod30 : Ty30 → Ty30 → Ty30 := λ A B Ty30 nat30 top30 bot30 arr30 prod30 sum => prod30 (A Ty30 nat30 top30 bot30 arr30 prod30 sum) (B Ty30 nat30 top30 bot30 arr30 prod30 sum) def sum30 : Ty30 → Ty30 → Ty30 := λ A B Ty30 nat30 top30 bot30 arr30 prod30 sum30 => sum30 (A Ty30 nat30 top30 bot30 arr30 prod30 sum30) (B Ty30 nat30 top30 bot30 arr30 prod30 sum30) def Con30 : Type 1 := ∀ (Con30 : Type) (nil : Con30) (snoc : Con30 → Ty30 → Con30) , Con30 def nil30 : Con30 := λ Con30 nil30 snoc => nil30 def snoc30 : Con30 → Ty30 → Con30 := λ Γ A Con30 nil30 snoc30 => snoc30 (Γ Con30 nil30 snoc30) A def Var30 : Con30 → Ty30 → Type 1 := λ Γ A => ∀ (Var30 : Con30 → Ty30 → Type) (vz : ∀{Γ A}, Var30 (snoc30 Γ A) A) (vs : ∀{Γ B A}, Var30 Γ A → Var30 (snoc30 Γ B) A) , Var30 Γ A def vz30 : ∀ {Γ A}, Var30 (snoc30 Γ A) A := λ Var30 vz30 vs => vz30 def vs30 : ∀ {Γ B A}, Var30 Γ A → Var30 (snoc30 Γ B) A := λ x Var30 vz30 vs30 => vs30 (x Var30 vz30 vs30) def Tm30 : Con30 → Ty30 → Type 1 := λ Γ A => ∀ (Tm30 : Con30 → Ty30 → Type) (var : ∀ {Γ A}, Var30 Γ A → Tm30 Γ A) (lam : ∀ {Γ A B}, (Tm30 (snoc30 Γ A) B → Tm30 Γ (arr30 A B))) (app : ∀ {Γ A B} , Tm30 Γ (arr30 A B) → Tm30 Γ A → Tm30 Γ B) (tt : ∀ {Γ} , Tm30 Γ top30) (pair : ∀ {Γ A B} , Tm30 Γ A → Tm30 Γ B → Tm30 Γ (prod30 A B)) (fst : ∀ {Γ A B} , Tm30 Γ (prod30 A B) → Tm30 Γ A) (snd : ∀ {Γ A B} , Tm30 Γ (prod30 A B) → Tm30 Γ B) (left : ∀ {Γ A B} , Tm30 Γ A → Tm30 Γ (sum30 A B)) (right : ∀ {Γ A B} , Tm30 Γ B → Tm30 Γ (sum30 A B)) (case : ∀ {Γ A B C} , Tm30 Γ (sum30 A B) → Tm30 Γ (arr30 A C) → Tm30 Γ (arr30 B C) → Tm30 Γ C) (zero : ∀ {Γ} , Tm30 Γ nat30) (suc : ∀ {Γ} , Tm30 Γ nat30 → Tm30 Γ nat30) (rec : ∀ {Γ A} , Tm30 Γ nat30 → Tm30 Γ (arr30 nat30 (arr30 A A)) → Tm30 Γ A → Tm30 Γ A) , Tm30 Γ A def var30 : ∀ {Γ A}, Var30 Γ A → Tm30 Γ A := λ x Tm30 var30 lam app tt pair fst snd left right case zero suc rec => var30 x def lam30 : ∀ {Γ A B} , Tm30 (snoc30 Γ A) B → Tm30 Γ (arr30 A B) := λ t Tm30 var30 lam30 app tt pair fst snd left right case zero suc rec => lam30 (t Tm30 var30 lam30 app tt pair fst snd left right case zero suc rec) def app30 : ∀ {Γ A B} , Tm30 Γ (arr30 A B) → Tm30 Γ A → Tm30 Γ B := λ t u Tm30 var30 lam30 app30 tt pair fst snd left right case zero suc rec => app30 (t Tm30 var30 lam30 app30 tt pair fst snd left right case zero suc rec) (u Tm30 var30 lam30 app30 tt pair fst snd left right case zero suc rec) def tt30 : ∀ {Γ} , Tm30 Γ top30 := λ Tm30 var30 lam30 app30 tt30 pair fst snd left right case zero suc rec => tt30 def pair30 : ∀ {Γ A B} , Tm30 Γ A → Tm30 Γ B → Tm30 Γ (prod30 A B) := λ t u Tm30 var30 lam30 app30 tt30 pair30 fst snd left right case zero suc rec => pair30 (t Tm30 var30 lam30 app30 tt30 pair30 fst snd left right case zero suc rec) (u Tm30 var30 lam30 app30 tt30 pair30 fst snd left right case zero suc rec) def fst30 : ∀ {Γ A B} , Tm30 Γ (prod30 A B) → Tm30 Γ A := λ t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd left right case zero suc rec => fst30 (t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd left right case zero suc rec) def snd30 : ∀ {Γ A B} , Tm30 Γ (prod30 A B) → Tm30 Γ B := λ t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left right case zero suc rec => snd30 (t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left right case zero suc rec) def left30 : ∀ {Γ A B} , Tm30 Γ A → Tm30 Γ (sum30 A B) := λ t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right case zero suc rec => left30 (t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right case zero suc rec) def right30 : ∀ {Γ A B} , Tm30 Γ B → Tm30 Γ (sum30 A B) := λ t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case zero suc rec => right30 (t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case zero suc rec) def case30 : ∀ {Γ A B C} , Tm30 Γ (sum30 A B) → Tm30 Γ (arr30 A C) → Tm30 Γ (arr30 B C) → Tm30 Γ C := λ t u v Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case30 zero suc rec => case30 (t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case30 zero suc rec) (u Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case30 zero suc rec) (v Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case30 zero suc rec) def zero30 : ∀ {Γ} , Tm30 Γ nat30 := λ Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case30 zero30 suc rec => zero30 def suc30 : ∀ {Γ} , Tm30 Γ nat30 → Tm30 Γ nat30 := λ t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case30 zero30 suc30 rec => suc30 (t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case30 zero30 suc30 rec) def rec30 : ∀ {Γ A} , Tm30 Γ nat30 → Tm30 Γ (arr30 nat30 (arr30 A A)) → Tm30 Γ A → Tm30 Γ A := λ t u v Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case30 zero30 suc30 rec30 => rec30 (t Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case30 zero30 suc30 rec30) (u Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case30 zero30 suc30 rec30) (v Tm30 var30 lam30 app30 tt30 pair30 fst30 snd30 left30 right30 case30 zero30 suc30 rec30) def v030 : ∀ {Γ A}, Tm30 (snoc30 Γ A) A := var30 vz30 def v130 : ∀ {Γ A B}, Tm30 (snoc30 (snoc30 Γ A) B) A := var30 (vs30 vz30) def v230 : ∀ {Γ A B C}, Tm30 (snoc30 (snoc30 (snoc30 Γ A) B) C) A := var30 (vs30 (vs30 vz30)) def v330 : ∀ {Γ A B C D}, Tm30 (snoc30 (snoc30 (snoc30 (snoc30 Γ A) B) C) D) A := var30 (vs30 (vs30 (vs30 vz30))) def tbool30 : Ty30 := sum30 top30 top30 def ttrue30 : ∀ {Γ}, Tm30 Γ tbool30 := left30 tt30 def tfalse30 : ∀ {Γ}, Tm30 Γ tbool30 := right30 tt30 def ifthenelse30 : ∀ {Γ A}, Tm30 Γ (arr30 tbool30 (arr30 A (arr30 A A))) := lam30 (lam30 (lam30 (case30 v230 (lam30 v230) (lam30 v130)))) def times430 : ∀ {Γ A}, Tm30 Γ (arr30 (arr30 A A) (arr30 A A)) := lam30 (lam30 (app30 v130 (app30 v130 (app30 v130 (app30 v130 v030))))) def add30 : ∀ {Γ}, Tm30 Γ (arr30 nat30 (arr30 nat30 nat30)) := lam30 (rec30 v030 (lam30 (lam30 (lam30 (suc30 (app30 v130 v030))))) (lam30 v030)) def mul30 : ∀ {Γ}, Tm30 Γ (arr30 nat30 (arr30 nat30 nat30)) := lam30 (rec30 v030 (lam30 (lam30 (lam30 (app30 (app30 add30 (app30 v130 v030)) v030)))) (lam30 zero30)) def fact30 : ∀ {Γ}, Tm30 Γ (arr30 nat30 nat30) := lam30 (rec30 v030 (lam30 (lam30 (app30 (app30 mul30 (suc30 v130)) v030))) (suc30 zero30)) def Ty31 : Type 1 := ∀ (Ty31 : Type) (nat top bot : Ty31) (arr prod sum : Ty31 → Ty31 → Ty31) , Ty31 def nat31 : Ty31 := λ _ nat31 _ _ _ _ _ => nat31 def top31 : Ty31 := λ _ _ top31 _ _ _ _ => top31 def bot31 : Ty31 := λ _ _ _ bot31 _ _ _ => bot31 def arr31 : Ty31 → Ty31 → Ty31 := λ A B Ty31 nat31 top31 bot31 arr31 prod sum => arr31 (A Ty31 nat31 top31 bot31 arr31 prod sum) (B Ty31 nat31 top31 bot31 arr31 prod sum) def prod31 : Ty31 → Ty31 → Ty31 := λ A B Ty31 nat31 top31 bot31 arr31 prod31 sum => prod31 (A Ty31 nat31 top31 bot31 arr31 prod31 sum) (B Ty31 nat31 top31 bot31 arr31 prod31 sum) def sum31 : Ty31 → Ty31 → Ty31 := λ A B Ty31 nat31 top31 bot31 arr31 prod31 sum31 => sum31 (A Ty31 nat31 top31 bot31 arr31 prod31 sum31) (B Ty31 nat31 top31 bot31 arr31 prod31 sum31) def Con31 : Type 1 := ∀ (Con31 : Type) (nil : Con31) (snoc : Con31 → Ty31 → Con31) , Con31 def nil31 : Con31 := λ Con31 nil31 snoc => nil31 def snoc31 : Con31 → Ty31 → Con31 := λ Γ A Con31 nil31 snoc31 => snoc31 (Γ Con31 nil31 snoc31) A def Var31 : Con31 → Ty31 → Type 1 := λ Γ A => ∀ (Var31 : Con31 → Ty31 → Type) (vz : ∀{Γ A}, Var31 (snoc31 Γ A) A) (vs : ∀{Γ B A}, Var31 Γ A → Var31 (snoc31 Γ B) A) , Var31 Γ A def vz31 : ∀ {Γ A}, Var31 (snoc31 Γ A) A := λ Var31 vz31 vs => vz31 def vs31 : ∀ {Γ B A}, Var31 Γ A → Var31 (snoc31 Γ B) A := λ x Var31 vz31 vs31 => vs31 (x Var31 vz31 vs31) def Tm31 : Con31 → Ty31 → Type 1 := λ Γ A => ∀ (Tm31 : Con31 → Ty31 → Type) (var : ∀ {Γ A}, Var31 Γ A → Tm31 Γ A) (lam : ∀ {Γ A B}, (Tm31 (snoc31 Γ A) B → Tm31 Γ (arr31 A B))) (app : ∀ {Γ A B} , Tm31 Γ (arr31 A B) → Tm31 Γ A → Tm31 Γ B) (tt : ∀ {Γ} , Tm31 Γ top31) (pair : ∀ {Γ A B} , Tm31 Γ A → Tm31 Γ B → Tm31 Γ (prod31 A B)) (fst : ∀ {Γ A B} , Tm31 Γ (prod31 A B) → Tm31 Γ A) (snd : ∀ {Γ A B} , Tm31 Γ (prod31 A B) → Tm31 Γ B) (left : ∀ {Γ A B} , Tm31 Γ A → Tm31 Γ (sum31 A B)) (right : ∀ {Γ A B} , Tm31 Γ B → Tm31 Γ (sum31 A B)) (case : ∀ {Γ A B C} , Tm31 Γ (sum31 A B) → Tm31 Γ (arr31 A C) → Tm31 Γ (arr31 B C) → Tm31 Γ C) (zero : ∀ {Γ} , Tm31 Γ nat31) (suc : ∀ {Γ} , Tm31 Γ nat31 → Tm31 Γ nat31) (rec : ∀ {Γ A} , Tm31 Γ nat31 → Tm31 Γ (arr31 nat31 (arr31 A A)) → Tm31 Γ A → Tm31 Γ A) , Tm31 Γ A def var31 : ∀ {Γ A}, Var31 Γ A → Tm31 Γ A := λ x Tm31 var31 lam app tt pair fst snd left right case zero suc rec => var31 x def lam31 : ∀ {Γ A B} , Tm31 (snoc31 Γ A) B → Tm31 Γ (arr31 A B) := λ t Tm31 var31 lam31 app tt pair fst snd left right case zero suc rec => lam31 (t Tm31 var31 lam31 app tt pair fst snd left right case zero suc rec) def app31 : ∀ {Γ A B} , Tm31 Γ (arr31 A B) → Tm31 Γ A → Tm31 Γ B := λ t u Tm31 var31 lam31 app31 tt pair fst snd left right case zero suc rec => app31 (t Tm31 var31 lam31 app31 tt pair fst snd left right case zero suc rec) (u Tm31 var31 lam31 app31 tt pair fst snd left right case zero suc rec) def tt31 : ∀ {Γ} , Tm31 Γ top31 := λ Tm31 var31 lam31 app31 tt31 pair fst snd left right case zero suc rec => tt31 def pair31 : ∀ {Γ A B} , Tm31 Γ A → Tm31 Γ B → Tm31 Γ (prod31 A B) := λ t u Tm31 var31 lam31 app31 tt31 pair31 fst snd left right case zero suc rec => pair31 (t Tm31 var31 lam31 app31 tt31 pair31 fst snd left right case zero suc rec) (u Tm31 var31 lam31 app31 tt31 pair31 fst snd left right case zero suc rec) def fst31 : ∀ {Γ A B} , Tm31 Γ (prod31 A B) → Tm31 Γ A := λ t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd left right case zero suc rec => fst31 (t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd left right case zero suc rec) def snd31 : ∀ {Γ A B} , Tm31 Γ (prod31 A B) → Tm31 Γ B := λ t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left right case zero suc rec => snd31 (t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left right case zero suc rec) def left31 : ∀ {Γ A B} , Tm31 Γ A → Tm31 Γ (sum31 A B) := λ t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right case zero suc rec => left31 (t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right case zero suc rec) def right31 : ∀ {Γ A B} , Tm31 Γ B → Tm31 Γ (sum31 A B) := λ t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case zero suc rec => right31 (t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case zero suc rec) def case31 : ∀ {Γ A B C} , Tm31 Γ (sum31 A B) → Tm31 Γ (arr31 A C) → Tm31 Γ (arr31 B C) → Tm31 Γ C := λ t u v Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case31 zero suc rec => case31 (t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case31 zero suc rec) (u Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case31 zero suc rec) (v Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case31 zero suc rec) def zero31 : ∀ {Γ} , Tm31 Γ nat31 := λ Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case31 zero31 suc rec => zero31 def suc31 : ∀ {Γ} , Tm31 Γ nat31 → Tm31 Γ nat31 := λ t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case31 zero31 suc31 rec => suc31 (t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case31 zero31 suc31 rec) def rec31 : ∀ {Γ A} , Tm31 Γ nat31 → Tm31 Γ (arr31 nat31 (arr31 A A)) → Tm31 Γ A → Tm31 Γ A := λ t u v Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case31 zero31 suc31 rec31 => rec31 (t Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case31 zero31 suc31 rec31) (u Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case31 zero31 suc31 rec31) (v Tm31 var31 lam31 app31 tt31 pair31 fst31 snd31 left31 right31 case31 zero31 suc31 rec31) def v031 : ∀ {Γ A}, Tm31 (snoc31 Γ A) A := var31 vz31 def v131 : ∀ {Γ A B}, Tm31 (snoc31 (snoc31 Γ A) B) A := var31 (vs31 vz31) def v231 : ∀ {Γ A B C}, Tm31 (snoc31 (snoc31 (snoc31 Γ A) B) C) A := var31 (vs31 (vs31 vz31)) def v331 : ∀ {Γ A B C D}, Tm31 (snoc31 (snoc31 (snoc31 (snoc31 Γ A) B) C) D) A := var31 (vs31 (vs31 (vs31 vz31))) def tbool31 : Ty31 := sum31 top31 top31 def ttrue31 : ∀ {Γ}, Tm31 Γ tbool31 := left31 tt31 def tfalse31 : ∀ {Γ}, Tm31 Γ tbool31 := right31 tt31 def ifthenelse31 : ∀ {Γ A}, Tm31 Γ (arr31 tbool31 (arr31 A (arr31 A A))) := lam31 (lam31 (lam31 (case31 v231 (lam31 v231) (lam31 v131)))) def times431 : ∀ {Γ A}, Tm31 Γ (arr31 (arr31 A A) (arr31 A A)) := lam31 (lam31 (app31 v131 (app31 v131 (app31 v131 (app31 v131 v031))))) def add31 : ∀ {Γ}, Tm31 Γ (arr31 nat31 (arr31 nat31 nat31)) := lam31 (rec31 v031 (lam31 (lam31 (lam31 (suc31 (app31 v131 v031))))) (lam31 v031)) def mul31 : ∀ {Γ}, Tm31 Γ (arr31 nat31 (arr31 nat31 nat31)) := lam31 (rec31 v031 (lam31 (lam31 (lam31 (app31 (app31 add31 (app31 v131 v031)) v031)))) (lam31 zero31)) def fact31 : ∀ {Γ}, Tm31 Γ (arr31 nat31 nat31) := lam31 (rec31 v031 (lam31 (lam31 (app31 (app31 mul31 (suc31 v131)) v031))) (suc31 zero31)) def Ty32 : Type 1 := ∀ (Ty32 : Type) (nat top bot : Ty32) (arr prod sum : Ty32 → Ty32 → Ty32) , Ty32 def nat32 : Ty32 := λ _ nat32 _ _ _ _ _ => nat32 def top32 : Ty32 := λ _ _ top32 _ _ _ _ => top32 def bot32 : Ty32 := λ _ _ _ bot32 _ _ _ => bot32 def arr32 : Ty32 → Ty32 → Ty32 := λ A B Ty32 nat32 top32 bot32 arr32 prod sum => arr32 (A Ty32 nat32 top32 bot32 arr32 prod sum) (B Ty32 nat32 top32 bot32 arr32 prod sum) def prod32 : Ty32 → Ty32 → Ty32 := λ A B Ty32 nat32 top32 bot32 arr32 prod32 sum => prod32 (A Ty32 nat32 top32 bot32 arr32 prod32 sum) (B Ty32 nat32 top32 bot32 arr32 prod32 sum) def sum32 : Ty32 → Ty32 → Ty32 := λ A B Ty32 nat32 top32 bot32 arr32 prod32 sum32 => sum32 (A Ty32 nat32 top32 bot32 arr32 prod32 sum32) (B Ty32 nat32 top32 bot32 arr32 prod32 sum32) def Con32 : Type 1 := ∀ (Con32 : Type) (nil : Con32) (snoc : Con32 → Ty32 → Con32) , Con32 def nil32 : Con32 := λ Con32 nil32 snoc => nil32 def snoc32 : Con32 → Ty32 → Con32 := λ Γ A Con32 nil32 snoc32 => snoc32 (Γ Con32 nil32 snoc32) A def Var32 : Con32 → Ty32 → Type 1 := λ Γ A => ∀ (Var32 : Con32 → Ty32 → Type) (vz : ∀{Γ A}, Var32 (snoc32 Γ A) A) (vs : ∀{Γ B A}, Var32 Γ A → Var32 (snoc32 Γ B) A) , Var32 Γ A def vz32 : ∀ {Γ A}, Var32 (snoc32 Γ A) A := λ Var32 vz32 vs => vz32 def vs32 : ∀ {Γ B A}, Var32 Γ A → Var32 (snoc32 Γ B) A := λ x Var32 vz32 vs32 => vs32 (x Var32 vz32 vs32) def Tm32 : Con32 → Ty32 → Type 1 := λ Γ A => ∀ (Tm32 : Con32 → Ty32 → Type) (var : ∀ {Γ A}, Var32 Γ A → Tm32 Γ A) (lam : ∀ {Γ A B}, (Tm32 (snoc32 Γ A) B → Tm32 Γ (arr32 A B))) (app : ∀ {Γ A B} , Tm32 Γ (arr32 A B) → Tm32 Γ A → Tm32 Γ B) (tt : ∀ {Γ} , Tm32 Γ top32) (pair : ∀ {Γ A B} , Tm32 Γ A → Tm32 Γ B → Tm32 Γ (prod32 A B)) (fst : ∀ {Γ A B} , Tm32 Γ (prod32 A B) → Tm32 Γ A) (snd : ∀ {Γ A B} , Tm32 Γ (prod32 A B) → Tm32 Γ B) (left : ∀ {Γ A B} , Tm32 Γ A → Tm32 Γ (sum32 A B)) (right : ∀ {Γ A B} , Tm32 Γ B → Tm32 Γ (sum32 A B)) (case : ∀ {Γ A B C} , Tm32 Γ (sum32 A B) → Tm32 Γ (arr32 A C) → Tm32 Γ (arr32 B C) → Tm32 Γ C) (zero : ∀ {Γ} , Tm32 Γ nat32) (suc : ∀ {Γ} , Tm32 Γ nat32 → Tm32 Γ nat32) (rec : ∀ {Γ A} , Tm32 Γ nat32 → Tm32 Γ (arr32 nat32 (arr32 A A)) → Tm32 Γ A → Tm32 Γ A) , Tm32 Γ A def var32 : ∀ {Γ A}, Var32 Γ A → Tm32 Γ A := λ x Tm32 var32 lam app tt pair fst snd left right case zero suc rec => var32 x def lam32 : ∀ {Γ A B} , Tm32 (snoc32 Γ A) B → Tm32 Γ (arr32 A B) := λ t Tm32 var32 lam32 app tt pair fst snd left right case zero suc rec => lam32 (t Tm32 var32 lam32 app tt pair fst snd left right case zero suc rec) def app32 : ∀ {Γ A B} , Tm32 Γ (arr32 A B) → Tm32 Γ A → Tm32 Γ B := λ t u Tm32 var32 lam32 app32 tt pair fst snd left right case zero suc rec => app32 (t Tm32 var32 lam32 app32 tt pair fst snd left right case zero suc rec) (u Tm32 var32 lam32 app32 tt pair fst snd left right case zero suc rec) def tt32 : ∀ {Γ} , Tm32 Γ top32 := λ Tm32 var32 lam32 app32 tt32 pair fst snd left right case zero suc rec => tt32 def pair32 : ∀ {Γ A B} , Tm32 Γ A → Tm32 Γ B → Tm32 Γ (prod32 A B) := λ t u Tm32 var32 lam32 app32 tt32 pair32 fst snd left right case zero suc rec => pair32 (t Tm32 var32 lam32 app32 tt32 pair32 fst snd left right case zero suc rec) (u Tm32 var32 lam32 app32 tt32 pair32 fst snd left right case zero suc rec) def fst32 : ∀ {Γ A B} , Tm32 Γ (prod32 A B) → Tm32 Γ A := λ t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd left right case zero suc rec => fst32 (t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd left right case zero suc rec) def snd32 : ∀ {Γ A B} , Tm32 Γ (prod32 A B) → Tm32 Γ B := λ t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left right case zero suc rec => snd32 (t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left right case zero suc rec) def left32 : ∀ {Γ A B} , Tm32 Γ A → Tm32 Γ (sum32 A B) := λ t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right case zero suc rec => left32 (t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right case zero suc rec) def right32 : ∀ {Γ A B} , Tm32 Γ B → Tm32 Γ (sum32 A B) := λ t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case zero suc rec => right32 (t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case zero suc rec) def case32 : ∀ {Γ A B C} , Tm32 Γ (sum32 A B) → Tm32 Γ (arr32 A C) → Tm32 Γ (arr32 B C) → Tm32 Γ C := λ t u v Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case32 zero suc rec => case32 (t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case32 zero suc rec) (u Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case32 zero suc rec) (v Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case32 zero suc rec) def zero32 : ∀ {Γ} , Tm32 Γ nat32 := λ Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case32 zero32 suc rec => zero32 def suc32 : ∀ {Γ} , Tm32 Γ nat32 → Tm32 Γ nat32 := λ t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case32 zero32 suc32 rec => suc32 (t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case32 zero32 suc32 rec) def rec32 : ∀ {Γ A} , Tm32 Γ nat32 → Tm32 Γ (arr32 nat32 (arr32 A A)) → Tm32 Γ A → Tm32 Γ A := λ t u v Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case32 zero32 suc32 rec32 => rec32 (t Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case32 zero32 suc32 rec32) (u Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case32 zero32 suc32 rec32) (v Tm32 var32 lam32 app32 tt32 pair32 fst32 snd32 left32 right32 case32 zero32 suc32 rec32) def v032 : ∀ {Γ A}, Tm32 (snoc32 Γ A) A := var32 vz32 def v132 : ∀ {Γ A B}, Tm32 (snoc32 (snoc32 Γ A) B) A := var32 (vs32 vz32) def v232 : ∀ {Γ A B C}, Tm32 (snoc32 (snoc32 (snoc32 Γ A) B) C) A := var32 (vs32 (vs32 vz32)) def v332 : ∀ {Γ A B C D}, Tm32 (snoc32 (snoc32 (snoc32 (snoc32 Γ A) B) C) D) A := var32 (vs32 (vs32 (vs32 vz32))) def tbool32 : Ty32 := sum32 top32 top32 def ttrue32 : ∀ {Γ}, Tm32 Γ tbool32 := left32 tt32 def tfalse32 : ∀ {Γ}, Tm32 Γ tbool32 := right32 tt32 def ifthenelse32 : ∀ {Γ A}, Tm32 Γ (arr32 tbool32 (arr32 A (arr32 A A))) := lam32 (lam32 (lam32 (case32 v232 (lam32 v232) (lam32 v132)))) def times432 : ∀ {Γ A}, Tm32 Γ (arr32 (arr32 A A) (arr32 A A)) := lam32 (lam32 (app32 v132 (app32 v132 (app32 v132 (app32 v132 v032))))) def add32 : ∀ {Γ}, Tm32 Γ (arr32 nat32 (arr32 nat32 nat32)) := lam32 (rec32 v032 (lam32 (lam32 (lam32 (suc32 (app32 v132 v032))))) (lam32 v032)) def mul32 : ∀ {Γ}, Tm32 Γ (arr32 nat32 (arr32 nat32 nat32)) := lam32 (rec32 v032 (lam32 (lam32 (lam32 (app32 (app32 add32 (app32 v132 v032)) v032)))) (lam32 zero32)) def fact32 : ∀ {Γ}, Tm32 Γ (arr32 nat32 nat32) := lam32 (rec32 v032 (lam32 (lam32 (app32 (app32 mul32 (suc32 v132)) v032))) (suc32 zero32)) def Ty33 : Type 1 := ∀ (Ty33 : Type) (nat top bot : Ty33) (arr prod sum : Ty33 → Ty33 → Ty33) , Ty33 def nat33 : Ty33 := λ _ nat33 _ _ _ _ _ => nat33 def top33 : Ty33 := λ _ _ top33 _ _ _ _ => top33 def bot33 : Ty33 := λ _ _ _ bot33 _ _ _ => bot33 def arr33 : Ty33 → Ty33 → Ty33 := λ A B Ty33 nat33 top33 bot33 arr33 prod sum => arr33 (A Ty33 nat33 top33 bot33 arr33 prod sum) (B Ty33 nat33 top33 bot33 arr33 prod sum) def prod33 : Ty33 → Ty33 → Ty33 := λ A B Ty33 nat33 top33 bot33 arr33 prod33 sum => prod33 (A Ty33 nat33 top33 bot33 arr33 prod33 sum) (B Ty33 nat33 top33 bot33 arr33 prod33 sum) def sum33 : Ty33 → Ty33 → Ty33 := λ A B Ty33 nat33 top33 bot33 arr33 prod33 sum33 => sum33 (A Ty33 nat33 top33 bot33 arr33 prod33 sum33) (B Ty33 nat33 top33 bot33 arr33 prod33 sum33) def Con33 : Type 1 := ∀ (Con33 : Type) (nil : Con33) (snoc : Con33 → Ty33 → Con33) , Con33 def nil33 : Con33 := λ Con33 nil33 snoc => nil33 def snoc33 : Con33 → Ty33 → Con33 := λ Γ A Con33 nil33 snoc33 => snoc33 (Γ Con33 nil33 snoc33) A def Var33 : Con33 → Ty33 → Type 1 := λ Γ A => ∀ (Var33 : Con33 → Ty33 → Type) (vz : ∀{Γ A}, Var33 (snoc33 Γ A) A) (vs : ∀{Γ B A}, Var33 Γ A → Var33 (snoc33 Γ B) A) , Var33 Γ A def vz33 : ∀ {Γ A}, Var33 (snoc33 Γ A) A := λ Var33 vz33 vs => vz33 def vs33 : ∀ {Γ B A}, Var33 Γ A → Var33 (snoc33 Γ B) A := λ x Var33 vz33 vs33 => vs33 (x Var33 vz33 vs33) def Tm33 : Con33 → Ty33 → Type 1 := λ Γ A => ∀ (Tm33 : Con33 → Ty33 → Type) (var : ∀ {Γ A}, Var33 Γ A → Tm33 Γ A) (lam : ∀ {Γ A B}, (Tm33 (snoc33 Γ A) B → Tm33 Γ (arr33 A B))) (app : ∀ {Γ A B} , Tm33 Γ (arr33 A B) → Tm33 Γ A → Tm33 Γ B) (tt : ∀ {Γ} , Tm33 Γ top33) (pair : ∀ {Γ A B} , Tm33 Γ A → Tm33 Γ B → Tm33 Γ (prod33 A B)) (fst : ∀ {Γ A B} , Tm33 Γ (prod33 A B) → Tm33 Γ A) (snd : ∀ {Γ A B} , Tm33 Γ (prod33 A B) → Tm33 Γ B) (left : ∀ {Γ A B} , Tm33 Γ A → Tm33 Γ (sum33 A B)) (right : ∀ {Γ A B} , Tm33 Γ B → Tm33 Γ (sum33 A B)) (case : ∀ {Γ A B C} , Tm33 Γ (sum33 A B) → Tm33 Γ (arr33 A C) → Tm33 Γ (arr33 B C) → Tm33 Γ C) (zero : ∀ {Γ} , Tm33 Γ nat33) (suc : ∀ {Γ} , Tm33 Γ nat33 → Tm33 Γ nat33) (rec : ∀ {Γ A} , Tm33 Γ nat33 → Tm33 Γ (arr33 nat33 (arr33 A A)) → Tm33 Γ A → Tm33 Γ A) , Tm33 Γ A def var33 : ∀ {Γ A}, Var33 Γ A → Tm33 Γ A := λ x Tm33 var33 lam app tt pair fst snd left right case zero suc rec => var33 x def lam33 : ∀ {Γ A B} , Tm33 (snoc33 Γ A) B → Tm33 Γ (arr33 A B) := λ t Tm33 var33 lam33 app tt pair fst snd left right case zero suc rec => lam33 (t Tm33 var33 lam33 app tt pair fst snd left right case zero suc rec) def app33 : ∀ {Γ A B} , Tm33 Γ (arr33 A B) → Tm33 Γ A → Tm33 Γ B := λ t u Tm33 var33 lam33 app33 tt pair fst snd left right case zero suc rec => app33 (t Tm33 var33 lam33 app33 tt pair fst snd left right case zero suc rec) (u Tm33 var33 lam33 app33 tt pair fst snd left right case zero suc rec) def tt33 : ∀ {Γ} , Tm33 Γ top33 := λ Tm33 var33 lam33 app33 tt33 pair fst snd left right case zero suc rec => tt33 def pair33 : ∀ {Γ A B} , Tm33 Γ A → Tm33 Γ B → Tm33 Γ (prod33 A B) := λ t u Tm33 var33 lam33 app33 tt33 pair33 fst snd left right case zero suc rec => pair33 (t Tm33 var33 lam33 app33 tt33 pair33 fst snd left right case zero suc rec) (u Tm33 var33 lam33 app33 tt33 pair33 fst snd left right case zero suc rec) def fst33 : ∀ {Γ A B} , Tm33 Γ (prod33 A B) → Tm33 Γ A := λ t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd left right case zero suc rec => fst33 (t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd left right case zero suc rec) def snd33 : ∀ {Γ A B} , Tm33 Γ (prod33 A B) → Tm33 Γ B := λ t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left right case zero suc rec => snd33 (t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left right case zero suc rec) def left33 : ∀ {Γ A B} , Tm33 Γ A → Tm33 Γ (sum33 A B) := λ t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right case zero suc rec => left33 (t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right case zero suc rec) def right33 : ∀ {Γ A B} , Tm33 Γ B → Tm33 Γ (sum33 A B) := λ t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case zero suc rec => right33 (t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case zero suc rec) def case33 : ∀ {Γ A B C} , Tm33 Γ (sum33 A B) → Tm33 Γ (arr33 A C) → Tm33 Γ (arr33 B C) → Tm33 Γ C := λ t u v Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case33 zero suc rec => case33 (t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case33 zero suc rec) (u Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case33 zero suc rec) (v Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case33 zero suc rec) def zero33 : ∀ {Γ} , Tm33 Γ nat33 := λ Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case33 zero33 suc rec => zero33 def suc33 : ∀ {Γ} , Tm33 Γ nat33 → Tm33 Γ nat33 := λ t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case33 zero33 suc33 rec => suc33 (t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case33 zero33 suc33 rec) def rec33 : ∀ {Γ A} , Tm33 Γ nat33 → Tm33 Γ (arr33 nat33 (arr33 A A)) → Tm33 Γ A → Tm33 Γ A := λ t u v Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case33 zero33 suc33 rec33 => rec33 (t Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case33 zero33 suc33 rec33) (u Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case33 zero33 suc33 rec33) (v Tm33 var33 lam33 app33 tt33 pair33 fst33 snd33 left33 right33 case33 zero33 suc33 rec33) def v033 : ∀ {Γ A}, Tm33 (snoc33 Γ A) A := var33 vz33 def v133 : ∀ {Γ A B}, Tm33 (snoc33 (snoc33 Γ A) B) A := var33 (vs33 vz33) def v233 : ∀ {Γ A B C}, Tm33 (snoc33 (snoc33 (snoc33 Γ A) B) C) A := var33 (vs33 (vs33 vz33)) def v333 : ∀ {Γ A B C D}, Tm33 (snoc33 (snoc33 (snoc33 (snoc33 Γ A) B) C) D) A := var33 (vs33 (vs33 (vs33 vz33))) def tbool33 : Ty33 := sum33 top33 top33 def ttrue33 : ∀ {Γ}, Tm33 Γ tbool33 := left33 tt33 def tfalse33 : ∀ {Γ}, Tm33 Γ tbool33 := right33 tt33 def ifthenelse33 : ∀ {Γ A}, Tm33 Γ (arr33 tbool33 (arr33 A (arr33 A A))) := lam33 (lam33 (lam33 (case33 v233 (lam33 v233) (lam33 v133)))) def times433 : ∀ {Γ A}, Tm33 Γ (arr33 (arr33 A A) (arr33 A A)) := lam33 (lam33 (app33 v133 (app33 v133 (app33 v133 (app33 v133 v033))))) def add33 : ∀ {Γ}, Tm33 Γ (arr33 nat33 (arr33 nat33 nat33)) := lam33 (rec33 v033 (lam33 (lam33 (lam33 (suc33 (app33 v133 v033))))) (lam33 v033)) def mul33 : ∀ {Γ}, Tm33 Γ (arr33 nat33 (arr33 nat33 nat33)) := lam33 (rec33 v033 (lam33 (lam33 (lam33 (app33 (app33 add33 (app33 v133 v033)) v033)))) (lam33 zero33)) def fact33 : ∀ {Γ}, Tm33 Γ (arr33 nat33 nat33) := lam33 (rec33 v033 (lam33 (lam33 (app33 (app33 mul33 (suc33 v133)) v033))) (suc33 zero33)) def Ty34 : Type 1 := ∀ (Ty34 : Type) (nat top bot : Ty34) (arr prod sum : Ty34 → Ty34 → Ty34) , Ty34 def nat34 : Ty34 := λ _ nat34 _ _ _ _ _ => nat34 def top34 : Ty34 := λ _ _ top34 _ _ _ _ => top34 def bot34 : Ty34 := λ _ _ _ bot34 _ _ _ => bot34 def arr34 : Ty34 → Ty34 → Ty34 := λ A B Ty34 nat34 top34 bot34 arr34 prod sum => arr34 (A Ty34 nat34 top34 bot34 arr34 prod sum) (B Ty34 nat34 top34 bot34 arr34 prod sum) def prod34 : Ty34 → Ty34 → Ty34 := λ A B Ty34 nat34 top34 bot34 arr34 prod34 sum => prod34 (A Ty34 nat34 top34 bot34 arr34 prod34 sum) (B Ty34 nat34 top34 bot34 arr34 prod34 sum) def sum34 : Ty34 → Ty34 → Ty34 := λ A B Ty34 nat34 top34 bot34 arr34 prod34 sum34 => sum34 (A Ty34 nat34 top34 bot34 arr34 prod34 sum34) (B Ty34 nat34 top34 bot34 arr34 prod34 sum34) def Con34 : Type 1 := ∀ (Con34 : Type) (nil : Con34) (snoc : Con34 → Ty34 → Con34) , Con34 def nil34 : Con34 := λ Con34 nil34 snoc => nil34 def snoc34 : Con34 → Ty34 → Con34 := λ Γ A Con34 nil34 snoc34 => snoc34 (Γ Con34 nil34 snoc34) A def Var34 : Con34 → Ty34 → Type 1 := λ Γ A => ∀ (Var34 : Con34 → Ty34 → Type) (vz : ∀{Γ A}, Var34 (snoc34 Γ A) A) (vs : ∀{Γ B A}, Var34 Γ A → Var34 (snoc34 Γ B) A) , Var34 Γ A def vz34 : ∀ {Γ A}, Var34 (snoc34 Γ A) A := λ Var34 vz34 vs => vz34 def vs34 : ∀ {Γ B A}, Var34 Γ A → Var34 (snoc34 Γ B) A := λ x Var34 vz34 vs34 => vs34 (x Var34 vz34 vs34) def Tm34 : Con34 → Ty34 → Type 1 := λ Γ A => ∀ (Tm34 : Con34 → Ty34 → Type) (var : ∀ {Γ A}, Var34 Γ A → Tm34 Γ A) (lam : ∀ {Γ A B}, (Tm34 (snoc34 Γ A) B → Tm34 Γ (arr34 A B))) (app : ∀ {Γ A B} , Tm34 Γ (arr34 A B) → Tm34 Γ A → Tm34 Γ B) (tt : ∀ {Γ} , Tm34 Γ top34) (pair : ∀ {Γ A B} , Tm34 Γ A → Tm34 Γ B → Tm34 Γ (prod34 A B)) (fst : ∀ {Γ A B} , Tm34 Γ (prod34 A B) → Tm34 Γ A) (snd : ∀ {Γ A B} , Tm34 Γ (prod34 A B) → Tm34 Γ B) (left : ∀ {Γ A B} , Tm34 Γ A → Tm34 Γ (sum34 A B)) (right : ∀ {Γ A B} , Tm34 Γ B → Tm34 Γ (sum34 A B)) (case : ∀ {Γ A B C} , Tm34 Γ (sum34 A B) → Tm34 Γ (arr34 A C) → Tm34 Γ (arr34 B C) → Tm34 Γ C) (zero : ∀ {Γ} , Tm34 Γ nat34) (suc : ∀ {Γ} , Tm34 Γ nat34 → Tm34 Γ nat34) (rec : ∀ {Γ A} , Tm34 Γ nat34 → Tm34 Γ (arr34 nat34 (arr34 A A)) → Tm34 Γ A → Tm34 Γ A) , Tm34 Γ A def var34 : ∀ {Γ A}, Var34 Γ A → Tm34 Γ A := λ x Tm34 var34 lam app tt pair fst snd left right case zero suc rec => var34 x def lam34 : ∀ {Γ A B} , Tm34 (snoc34 Γ A) B → Tm34 Γ (arr34 A B) := λ t Tm34 var34 lam34 app tt pair fst snd left right case zero suc rec => lam34 (t Tm34 var34 lam34 app tt pair fst snd left right case zero suc rec) def app34 : ∀ {Γ A B} , Tm34 Γ (arr34 A B) → Tm34 Γ A → Tm34 Γ B := λ t u Tm34 var34 lam34 app34 tt pair fst snd left right case zero suc rec => app34 (t Tm34 var34 lam34 app34 tt pair fst snd left right case zero suc rec) (u Tm34 var34 lam34 app34 tt pair fst snd left right case zero suc rec) def tt34 : ∀ {Γ} , Tm34 Γ top34 := λ Tm34 var34 lam34 app34 tt34 pair fst snd left right case zero suc rec => tt34 def pair34 : ∀ {Γ A B} , Tm34 Γ A → Tm34 Γ B → Tm34 Γ (prod34 A B) := λ t u Tm34 var34 lam34 app34 tt34 pair34 fst snd left right case zero suc rec => pair34 (t Tm34 var34 lam34 app34 tt34 pair34 fst snd left right case zero suc rec) (u Tm34 var34 lam34 app34 tt34 pair34 fst snd left right case zero suc rec) def fst34 : ∀ {Γ A B} , Tm34 Γ (prod34 A B) → Tm34 Γ A := λ t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd left right case zero suc rec => fst34 (t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd left right case zero suc rec) def snd34 : ∀ {Γ A B} , Tm34 Γ (prod34 A B) → Tm34 Γ B := λ t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left right case zero suc rec => snd34 (t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left right case zero suc rec) def left34 : ∀ {Γ A B} , Tm34 Γ A → Tm34 Γ (sum34 A B) := λ t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right case zero suc rec => left34 (t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right case zero suc rec) def right34 : ∀ {Γ A B} , Tm34 Γ B → Tm34 Γ (sum34 A B) := λ t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case zero suc rec => right34 (t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case zero suc rec) def case34 : ∀ {Γ A B C} , Tm34 Γ (sum34 A B) → Tm34 Γ (arr34 A C) → Tm34 Γ (arr34 B C) → Tm34 Γ C := λ t u v Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case34 zero suc rec => case34 (t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case34 zero suc rec) (u Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case34 zero suc rec) (v Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case34 zero suc rec) def zero34 : ∀ {Γ} , Tm34 Γ nat34 := λ Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case34 zero34 suc rec => zero34 def suc34 : ∀ {Γ} , Tm34 Γ nat34 → Tm34 Γ nat34 := λ t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case34 zero34 suc34 rec => suc34 (t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case34 zero34 suc34 rec) def rec34 : ∀ {Γ A} , Tm34 Γ nat34 → Tm34 Γ (arr34 nat34 (arr34 A A)) → Tm34 Γ A → Tm34 Γ A := λ t u v Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case34 zero34 suc34 rec34 => rec34 (t Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case34 zero34 suc34 rec34) (u Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case34 zero34 suc34 rec34) (v Tm34 var34 lam34 app34 tt34 pair34 fst34 snd34 left34 right34 case34 zero34 suc34 rec34) def v034 : ∀ {Γ A}, Tm34 (snoc34 Γ A) A := var34 vz34 def v134 : ∀ {Γ A B}, Tm34 (snoc34 (snoc34 Γ A) B) A := var34 (vs34 vz34) def v234 : ∀ {Γ A B C}, Tm34 (snoc34 (snoc34 (snoc34 Γ A) B) C) A := var34 (vs34 (vs34 vz34)) def v334 : ∀ {Γ A B C D}, Tm34 (snoc34 (snoc34 (snoc34 (snoc34 Γ A) B) C) D) A := var34 (vs34 (vs34 (vs34 vz34))) def tbool34 : Ty34 := sum34 top34 top34 def ttrue34 : ∀ {Γ}, Tm34 Γ tbool34 := left34 tt34 def tfalse34 : ∀ {Γ}, Tm34 Γ tbool34 := right34 tt34 def ifthenelse34 : ∀ {Γ A}, Tm34 Γ (arr34 tbool34 (arr34 A (arr34 A A))) := lam34 (lam34 (lam34 (case34 v234 (lam34 v234) (lam34 v134)))) def times434 : ∀ {Γ A}, Tm34 Γ (arr34 (arr34 A A) (arr34 A A)) := lam34 (lam34 (app34 v134 (app34 v134 (app34 v134 (app34 v134 v034))))) def add34 : ∀ {Γ}, Tm34 Γ (arr34 nat34 (arr34 nat34 nat34)) := lam34 (rec34 v034 (lam34 (lam34 (lam34 (suc34 (app34 v134 v034))))) (lam34 v034)) def mul34 : ∀ {Γ}, Tm34 Γ (arr34 nat34 (arr34 nat34 nat34)) := lam34 (rec34 v034 (lam34 (lam34 (lam34 (app34 (app34 add34 (app34 v134 v034)) v034)))) (lam34 zero34)) def fact34 : ∀ {Γ}, Tm34 Γ (arr34 nat34 nat34) := lam34 (rec34 v034 (lam34 (lam34 (app34 (app34 mul34 (suc34 v134)) v034))) (suc34 zero34)) def Ty35 : Type 1 := ∀ (Ty35 : Type) (nat top bot : Ty35) (arr prod sum : Ty35 → Ty35 → Ty35) , Ty35 def nat35 : Ty35 := λ _ nat35 _ _ _ _ _ => nat35 def top35 : Ty35 := λ _ _ top35 _ _ _ _ => top35 def bot35 : Ty35 := λ _ _ _ bot35 _ _ _ => bot35 def arr35 : Ty35 → Ty35 → Ty35 := λ A B Ty35 nat35 top35 bot35 arr35 prod sum => arr35 (A Ty35 nat35 top35 bot35 arr35 prod sum) (B Ty35 nat35 top35 bot35 arr35 prod sum) def prod35 : Ty35 → Ty35 → Ty35 := λ A B Ty35 nat35 top35 bot35 arr35 prod35 sum => prod35 (A Ty35 nat35 top35 bot35 arr35 prod35 sum) (B Ty35 nat35 top35 bot35 arr35 prod35 sum) def sum35 : Ty35 → Ty35 → Ty35 := λ A B Ty35 nat35 top35 bot35 arr35 prod35 sum35 => sum35 (A Ty35 nat35 top35 bot35 arr35 prod35 sum35) (B Ty35 nat35 top35 bot35 arr35 prod35 sum35) def Con35 : Type 1 := ∀ (Con35 : Type) (nil : Con35) (snoc : Con35 → Ty35 → Con35) , Con35 def nil35 : Con35 := λ Con35 nil35 snoc => nil35 def snoc35 : Con35 → Ty35 → Con35 := λ Γ A Con35 nil35 snoc35 => snoc35 (Γ Con35 nil35 snoc35) A def Var35 : Con35 → Ty35 → Type 1 := λ Γ A => ∀ (Var35 : Con35 → Ty35 → Type) (vz : ∀{Γ A}, Var35 (snoc35 Γ A) A) (vs : ∀{Γ B A}, Var35 Γ A → Var35 (snoc35 Γ B) A) , Var35 Γ A def vz35 : ∀ {Γ A}, Var35 (snoc35 Γ A) A := λ Var35 vz35 vs => vz35 def vs35 : ∀ {Γ B A}, Var35 Γ A → Var35 (snoc35 Γ B) A := λ x Var35 vz35 vs35 => vs35 (x Var35 vz35 vs35) def Tm35 : Con35 → Ty35 → Type 1 := λ Γ A => ∀ (Tm35 : Con35 → Ty35 → Type) (var : ∀ {Γ A}, Var35 Γ A → Tm35 Γ A) (lam : ∀ {Γ A B}, (Tm35 (snoc35 Γ A) B → Tm35 Γ (arr35 A B))) (app : ∀ {Γ A B} , Tm35 Γ (arr35 A B) → Tm35 Γ A → Tm35 Γ B) (tt : ∀ {Γ} , Tm35 Γ top35) (pair : ∀ {Γ A B} , Tm35 Γ A → Tm35 Γ B → Tm35 Γ (prod35 A B)) (fst : ∀ {Γ A B} , Tm35 Γ (prod35 A B) → Tm35 Γ A) (snd : ∀ {Γ A B} , Tm35 Γ (prod35 A B) → Tm35 Γ B) (left : ∀ {Γ A B} , Tm35 Γ A → Tm35 Γ (sum35 A B)) (right : ∀ {Γ A B} , Tm35 Γ B → Tm35 Γ (sum35 A B)) (case : ∀ {Γ A B C} , Tm35 Γ (sum35 A B) → Tm35 Γ (arr35 A C) → Tm35 Γ (arr35 B C) → Tm35 Γ C) (zero : ∀ {Γ} , Tm35 Γ nat35) (suc : ∀ {Γ} , Tm35 Γ nat35 → Tm35 Γ nat35) (rec : ∀ {Γ A} , Tm35 Γ nat35 → Tm35 Γ (arr35 nat35 (arr35 A A)) → Tm35 Γ A → Tm35 Γ A) , Tm35 Γ A def var35 : ∀ {Γ A}, Var35 Γ A → Tm35 Γ A := λ x Tm35 var35 lam app tt pair fst snd left right case zero suc rec => var35 x def lam35 : ∀ {Γ A B} , Tm35 (snoc35 Γ A) B → Tm35 Γ (arr35 A B) := λ t Tm35 var35 lam35 app tt pair fst snd left right case zero suc rec => lam35 (t Tm35 var35 lam35 app tt pair fst snd left right case zero suc rec) def app35 : ∀ {Γ A B} , Tm35 Γ (arr35 A B) → Tm35 Γ A → Tm35 Γ B := λ t u Tm35 var35 lam35 app35 tt pair fst snd left right case zero suc rec => app35 (t Tm35 var35 lam35 app35 tt pair fst snd left right case zero suc rec) (u Tm35 var35 lam35 app35 tt pair fst snd left right case zero suc rec) def tt35 : ∀ {Γ} , Tm35 Γ top35 := λ Tm35 var35 lam35 app35 tt35 pair fst snd left right case zero suc rec => tt35 def pair35 : ∀ {Γ A B} , Tm35 Γ A → Tm35 Γ B → Tm35 Γ (prod35 A B) := λ t u Tm35 var35 lam35 app35 tt35 pair35 fst snd left right case zero suc rec => pair35 (t Tm35 var35 lam35 app35 tt35 pair35 fst snd left right case zero suc rec) (u Tm35 var35 lam35 app35 tt35 pair35 fst snd left right case zero suc rec) def fst35 : ∀ {Γ A B} , Tm35 Γ (prod35 A B) → Tm35 Γ A := λ t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd left right case zero suc rec => fst35 (t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd left right case zero suc rec) def snd35 : ∀ {Γ A B} , Tm35 Γ (prod35 A B) → Tm35 Γ B := λ t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left right case zero suc rec => snd35 (t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left right case zero suc rec) def left35 : ∀ {Γ A B} , Tm35 Γ A → Tm35 Γ (sum35 A B) := λ t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right case zero suc rec => left35 (t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right case zero suc rec) def right35 : ∀ {Γ A B} , Tm35 Γ B → Tm35 Γ (sum35 A B) := λ t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case zero suc rec => right35 (t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case zero suc rec) def case35 : ∀ {Γ A B C} , Tm35 Γ (sum35 A B) → Tm35 Γ (arr35 A C) → Tm35 Γ (arr35 B C) → Tm35 Γ C := λ t u v Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case35 zero suc rec => case35 (t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case35 zero suc rec) (u Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case35 zero suc rec) (v Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case35 zero suc rec) def zero35 : ∀ {Γ} , Tm35 Γ nat35 := λ Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case35 zero35 suc rec => zero35 def suc35 : ∀ {Γ} , Tm35 Γ nat35 → Tm35 Γ nat35 := λ t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case35 zero35 suc35 rec => suc35 (t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case35 zero35 suc35 rec) def rec35 : ∀ {Γ A} , Tm35 Γ nat35 → Tm35 Γ (arr35 nat35 (arr35 A A)) → Tm35 Γ A → Tm35 Γ A := λ t u v Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case35 zero35 suc35 rec35 => rec35 (t Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case35 zero35 suc35 rec35) (u Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case35 zero35 suc35 rec35) (v Tm35 var35 lam35 app35 tt35 pair35 fst35 snd35 left35 right35 case35 zero35 suc35 rec35) def v035 : ∀ {Γ A}, Tm35 (snoc35 Γ A) A := var35 vz35 def v135 : ∀ {Γ A B}, Tm35 (snoc35 (snoc35 Γ A) B) A := var35 (vs35 vz35) def v235 : ∀ {Γ A B C}, Tm35 (snoc35 (snoc35 (snoc35 Γ A) B) C) A := var35 (vs35 (vs35 vz35)) def v335 : ∀ {Γ A B C D}, Tm35 (snoc35 (snoc35 (snoc35 (snoc35 Γ A) B) C) D) A := var35 (vs35 (vs35 (vs35 vz35))) def tbool35 : Ty35 := sum35 top35 top35 def ttrue35 : ∀ {Γ}, Tm35 Γ tbool35 := left35 tt35 def tfalse35 : ∀ {Γ}, Tm35 Γ tbool35 := right35 tt35 def ifthenelse35 : ∀ {Γ A}, Tm35 Γ (arr35 tbool35 (arr35 A (arr35 A A))) := lam35 (lam35 (lam35 (case35 v235 (lam35 v235) (lam35 v135)))) def times435 : ∀ {Γ A}, Tm35 Γ (arr35 (arr35 A A) (arr35 A A)) := lam35 (lam35 (app35 v135 (app35 v135 (app35 v135 (app35 v135 v035))))) def add35 : ∀ {Γ}, Tm35 Γ (arr35 nat35 (arr35 nat35 nat35)) := lam35 (rec35 v035 (lam35 (lam35 (lam35 (suc35 (app35 v135 v035))))) (lam35 v035)) def mul35 : ∀ {Γ}, Tm35 Γ (arr35 nat35 (arr35 nat35 nat35)) := lam35 (rec35 v035 (lam35 (lam35 (lam35 (app35 (app35 add35 (app35 v135 v035)) v035)))) (lam35 zero35)) def fact35 : ∀ {Γ}, Tm35 Γ (arr35 nat35 nat35) := lam35 (rec35 v035 (lam35 (lam35 (app35 (app35 mul35 (suc35 v135)) v035))) (suc35 zero35)) def Ty36 : Type 1 := ∀ (Ty36 : Type) (nat top bot : Ty36) (arr prod sum : Ty36 → Ty36 → Ty36) , Ty36 def nat36 : Ty36 := λ _ nat36 _ _ _ _ _ => nat36 def top36 : Ty36 := λ _ _ top36 _ _ _ _ => top36 def bot36 : Ty36 := λ _ _ _ bot36 _ _ _ => bot36 def arr36 : Ty36 → Ty36 → Ty36 := λ A B Ty36 nat36 top36 bot36 arr36 prod sum => arr36 (A Ty36 nat36 top36 bot36 arr36 prod sum) (B Ty36 nat36 top36 bot36 arr36 prod sum) def prod36 : Ty36 → Ty36 → Ty36 := λ A B Ty36 nat36 top36 bot36 arr36 prod36 sum => prod36 (A Ty36 nat36 top36 bot36 arr36 prod36 sum) (B Ty36 nat36 top36 bot36 arr36 prod36 sum) def sum36 : Ty36 → Ty36 → Ty36 := λ A B Ty36 nat36 top36 bot36 arr36 prod36 sum36 => sum36 (A Ty36 nat36 top36 bot36 arr36 prod36 sum36) (B Ty36 nat36 top36 bot36 arr36 prod36 sum36) def Con36 : Type 1 := ∀ (Con36 : Type) (nil : Con36) (snoc : Con36 → Ty36 → Con36) , Con36 def nil36 : Con36 := λ Con36 nil36 snoc => nil36 def snoc36 : Con36 → Ty36 → Con36 := λ Γ A Con36 nil36 snoc36 => snoc36 (Γ Con36 nil36 snoc36) A def Var36 : Con36 → Ty36 → Type 1 := λ Γ A => ∀ (Var36 : Con36 → Ty36 → Type) (vz : ∀{Γ A}, Var36 (snoc36 Γ A) A) (vs : ∀{Γ B A}, Var36 Γ A → Var36 (snoc36 Γ B) A) , Var36 Γ A def vz36 : ∀ {Γ A}, Var36 (snoc36 Γ A) A := λ Var36 vz36 vs => vz36 def vs36 : ∀ {Γ B A}, Var36 Γ A → Var36 (snoc36 Γ B) A := λ x Var36 vz36 vs36 => vs36 (x Var36 vz36 vs36) def Tm36 : Con36 → Ty36 → Type 1 := λ Γ A => ∀ (Tm36 : Con36 → Ty36 → Type) (var : ∀ {Γ A}, Var36 Γ A → Tm36 Γ A) (lam : ∀ {Γ A B}, (Tm36 (snoc36 Γ A) B → Tm36 Γ (arr36 A B))) (app : ∀ {Γ A B} , Tm36 Γ (arr36 A B) → Tm36 Γ A → Tm36 Γ B) (tt : ∀ {Γ} , Tm36 Γ top36) (pair : ∀ {Γ A B} , Tm36 Γ A → Tm36 Γ B → Tm36 Γ (prod36 A B)) (fst : ∀ {Γ A B} , Tm36 Γ (prod36 A B) → Tm36 Γ A) (snd : ∀ {Γ A B} , Tm36 Γ (prod36 A B) → Tm36 Γ B) (left : ∀ {Γ A B} , Tm36 Γ A → Tm36 Γ (sum36 A B)) (right : ∀ {Γ A B} , Tm36 Γ B → Tm36 Γ (sum36 A B)) (case : ∀ {Γ A B C} , Tm36 Γ (sum36 A B) → Tm36 Γ (arr36 A C) → Tm36 Γ (arr36 B C) → Tm36 Γ C) (zero : ∀ {Γ} , Tm36 Γ nat36) (suc : ∀ {Γ} , Tm36 Γ nat36 → Tm36 Γ nat36) (rec : ∀ {Γ A} , Tm36 Γ nat36 → Tm36 Γ (arr36 nat36 (arr36 A A)) → Tm36 Γ A → Tm36 Γ A) , Tm36 Γ A def var36 : ∀ {Γ A}, Var36 Γ A → Tm36 Γ A := λ x Tm36 var36 lam app tt pair fst snd left right case zero suc rec => var36 x def lam36 : ∀ {Γ A B} , Tm36 (snoc36 Γ A) B → Tm36 Γ (arr36 A B) := λ t Tm36 var36 lam36 app tt pair fst snd left right case zero suc rec => lam36 (t Tm36 var36 lam36 app tt pair fst snd left right case zero suc rec) def app36 : ∀ {Γ A B} , Tm36 Γ (arr36 A B) → Tm36 Γ A → Tm36 Γ B := λ t u Tm36 var36 lam36 app36 tt pair fst snd left right case zero suc rec => app36 (t Tm36 var36 lam36 app36 tt pair fst snd left right case zero suc rec) (u Tm36 var36 lam36 app36 tt pair fst snd left right case zero suc rec) def tt36 : ∀ {Γ} , Tm36 Γ top36 := λ Tm36 var36 lam36 app36 tt36 pair fst snd left right case zero suc rec => tt36 def pair36 : ∀ {Γ A B} , Tm36 Γ A → Tm36 Γ B → Tm36 Γ (prod36 A B) := λ t u Tm36 var36 lam36 app36 tt36 pair36 fst snd left right case zero suc rec => pair36 (t Tm36 var36 lam36 app36 tt36 pair36 fst snd left right case zero suc rec) (u Tm36 var36 lam36 app36 tt36 pair36 fst snd left right case zero suc rec) def fst36 : ∀ {Γ A B} , Tm36 Γ (prod36 A B) → Tm36 Γ A := λ t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd left right case zero suc rec => fst36 (t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd left right case zero suc rec) def snd36 : ∀ {Γ A B} , Tm36 Γ (prod36 A B) → Tm36 Γ B := λ t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left right case zero suc rec => snd36 (t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left right case zero suc rec) def left36 : ∀ {Γ A B} , Tm36 Γ A → Tm36 Γ (sum36 A B) := λ t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right case zero suc rec => left36 (t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right case zero suc rec) def right36 : ∀ {Γ A B} , Tm36 Γ B → Tm36 Γ (sum36 A B) := λ t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case zero suc rec => right36 (t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case zero suc rec) def case36 : ∀ {Γ A B C} , Tm36 Γ (sum36 A B) → Tm36 Γ (arr36 A C) → Tm36 Γ (arr36 B C) → Tm36 Γ C := λ t u v Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case36 zero suc rec => case36 (t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case36 zero suc rec) (u Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case36 zero suc rec) (v Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case36 zero suc rec) def zero36 : ∀ {Γ} , Tm36 Γ nat36 := λ Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case36 zero36 suc rec => zero36 def suc36 : ∀ {Γ} , Tm36 Γ nat36 → Tm36 Γ nat36 := λ t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case36 zero36 suc36 rec => suc36 (t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case36 zero36 suc36 rec) def rec36 : ∀ {Γ A} , Tm36 Γ nat36 → Tm36 Γ (arr36 nat36 (arr36 A A)) → Tm36 Γ A → Tm36 Γ A := λ t u v Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case36 zero36 suc36 rec36 => rec36 (t Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case36 zero36 suc36 rec36) (u Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case36 zero36 suc36 rec36) (v Tm36 var36 lam36 app36 tt36 pair36 fst36 snd36 left36 right36 case36 zero36 suc36 rec36) def v036 : ∀ {Γ A}, Tm36 (snoc36 Γ A) A := var36 vz36 def v136 : ∀ {Γ A B}, Tm36 (snoc36 (snoc36 Γ A) B) A := var36 (vs36 vz36) def v236 : ∀ {Γ A B C}, Tm36 (snoc36 (snoc36 (snoc36 Γ A) B) C) A := var36 (vs36 (vs36 vz36)) def v336 : ∀ {Γ A B C D}, Tm36 (snoc36 (snoc36 (snoc36 (snoc36 Γ A) B) C) D) A := var36 (vs36 (vs36 (vs36 vz36))) def tbool36 : Ty36 := sum36 top36 top36 def ttrue36 : ∀ {Γ}, Tm36 Γ tbool36 := left36 tt36 def tfalse36 : ∀ {Γ}, Tm36 Γ tbool36 := right36 tt36 def ifthenelse36 : ∀ {Γ A}, Tm36 Γ (arr36 tbool36 (arr36 A (arr36 A A))) := lam36 (lam36 (lam36 (case36 v236 (lam36 v236) (lam36 v136)))) def times436 : ∀ {Γ A}, Tm36 Γ (arr36 (arr36 A A) (arr36 A A)) := lam36 (lam36 (app36 v136 (app36 v136 (app36 v136 (app36 v136 v036))))) def add36 : ∀ {Γ}, Tm36 Γ (arr36 nat36 (arr36 nat36 nat36)) := lam36 (rec36 v036 (lam36 (lam36 (lam36 (suc36 (app36 v136 v036))))) (lam36 v036)) def mul36 : ∀ {Γ}, Tm36 Γ (arr36 nat36 (arr36 nat36 nat36)) := lam36 (rec36 v036 (lam36 (lam36 (lam36 (app36 (app36 add36 (app36 v136 v036)) v036)))) (lam36 zero36)) def fact36 : ∀ {Γ}, Tm36 Γ (arr36 nat36 nat36) := lam36 (rec36 v036 (lam36 (lam36 (app36 (app36 mul36 (suc36 v136)) v036))) (suc36 zero36)) def Ty37 : Type 1 := ∀ (Ty37 : Type) (nat top bot : Ty37) (arr prod sum : Ty37 → Ty37 → Ty37) , Ty37 def nat37 : Ty37 := λ _ nat37 _ _ _ _ _ => nat37 def top37 : Ty37 := λ _ _ top37 _ _ _ _ => top37 def bot37 : Ty37 := λ _ _ _ bot37 _ _ _ => bot37 def arr37 : Ty37 → Ty37 → Ty37 := λ A B Ty37 nat37 top37 bot37 arr37 prod sum => arr37 (A Ty37 nat37 top37 bot37 arr37 prod sum) (B Ty37 nat37 top37 bot37 arr37 prod sum) def prod37 : Ty37 → Ty37 → Ty37 := λ A B Ty37 nat37 top37 bot37 arr37 prod37 sum => prod37 (A Ty37 nat37 top37 bot37 arr37 prod37 sum) (B Ty37 nat37 top37 bot37 arr37 prod37 sum) def sum37 : Ty37 → Ty37 → Ty37 := λ A B Ty37 nat37 top37 bot37 arr37 prod37 sum37 => sum37 (A Ty37 nat37 top37 bot37 arr37 prod37 sum37) (B Ty37 nat37 top37 bot37 arr37 prod37 sum37) def Con37 : Type 1 := ∀ (Con37 : Type) (nil : Con37) (snoc : Con37 → Ty37 → Con37) , Con37 def nil37 : Con37 := λ Con37 nil37 snoc => nil37 def snoc37 : Con37 → Ty37 → Con37 := λ Γ A Con37 nil37 snoc37 => snoc37 (Γ Con37 nil37 snoc37) A def Var37 : Con37 → Ty37 → Type 1 := λ Γ A => ∀ (Var37 : Con37 → Ty37 → Type) (vz : ∀{Γ A}, Var37 (snoc37 Γ A) A) (vs : ∀{Γ B A}, Var37 Γ A → Var37 (snoc37 Γ B) A) , Var37 Γ A def vz37 : ∀ {Γ A}, Var37 (snoc37 Γ A) A := λ Var37 vz37 vs => vz37 def vs37 : ∀ {Γ B A}, Var37 Γ A → Var37 (snoc37 Γ B) A := λ x Var37 vz37 vs37 => vs37 (x Var37 vz37 vs37) def Tm37 : Con37 → Ty37 → Type 1 := λ Γ A => ∀ (Tm37 : Con37 → Ty37 → Type) (var : ∀ {Γ A}, Var37 Γ A → Tm37 Γ A) (lam : ∀ {Γ A B}, (Tm37 (snoc37 Γ A) B → Tm37 Γ (arr37 A B))) (app : ∀ {Γ A B} , Tm37 Γ (arr37 A B) → Tm37 Γ A → Tm37 Γ B) (tt : ∀ {Γ} , Tm37 Γ top37) (pair : ∀ {Γ A B} , Tm37 Γ A → Tm37 Γ B → Tm37 Γ (prod37 A B)) (fst : ∀ {Γ A B} , Tm37 Γ (prod37 A B) → Tm37 Γ A) (snd : ∀ {Γ A B} , Tm37 Γ (prod37 A B) → Tm37 Γ B) (left : ∀ {Γ A B} , Tm37 Γ A → Tm37 Γ (sum37 A B)) (right : ∀ {Γ A B} , Tm37 Γ B → Tm37 Γ (sum37 A B)) (case : ∀ {Γ A B C} , Tm37 Γ (sum37 A B) → Tm37 Γ (arr37 A C) → Tm37 Γ (arr37 B C) → Tm37 Γ C) (zero : ∀ {Γ} , Tm37 Γ nat37) (suc : ∀ {Γ} , Tm37 Γ nat37 → Tm37 Γ nat37) (rec : ∀ {Γ A} , Tm37 Γ nat37 → Tm37 Γ (arr37 nat37 (arr37 A A)) → Tm37 Γ A → Tm37 Γ A) , Tm37 Γ A def var37 : ∀ {Γ A}, Var37 Γ A → Tm37 Γ A := λ x Tm37 var37 lam app tt pair fst snd left right case zero suc rec => var37 x def lam37 : ∀ {Γ A B} , Tm37 (snoc37 Γ A) B → Tm37 Γ (arr37 A B) := λ t Tm37 var37 lam37 app tt pair fst snd left right case zero suc rec => lam37 (t Tm37 var37 lam37 app tt pair fst snd left right case zero suc rec) def app37 : ∀ {Γ A B} , Tm37 Γ (arr37 A B) → Tm37 Γ A → Tm37 Γ B := λ t u Tm37 var37 lam37 app37 tt pair fst snd left right case zero suc rec => app37 (t Tm37 var37 lam37 app37 tt pair fst snd left right case zero suc rec) (u Tm37 var37 lam37 app37 tt pair fst snd left right case zero suc rec) def tt37 : ∀ {Γ} , Tm37 Γ top37 := λ Tm37 var37 lam37 app37 tt37 pair fst snd left right case zero suc rec => tt37 def pair37 : ∀ {Γ A B} , Tm37 Γ A → Tm37 Γ B → Tm37 Γ (prod37 A B) := λ t u Tm37 var37 lam37 app37 tt37 pair37 fst snd left right case zero suc rec => pair37 (t Tm37 var37 lam37 app37 tt37 pair37 fst snd left right case zero suc rec) (u Tm37 var37 lam37 app37 tt37 pair37 fst snd left right case zero suc rec) def fst37 : ∀ {Γ A B} , Tm37 Γ (prod37 A B) → Tm37 Γ A := λ t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd left right case zero suc rec => fst37 (t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd left right case zero suc rec) def snd37 : ∀ {Γ A B} , Tm37 Γ (prod37 A B) → Tm37 Γ B := λ t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left right case zero suc rec => snd37 (t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left right case zero suc rec) def left37 : ∀ {Γ A B} , Tm37 Γ A → Tm37 Γ (sum37 A B) := λ t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right case zero suc rec => left37 (t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right case zero suc rec) def right37 : ∀ {Γ A B} , Tm37 Γ B → Tm37 Γ (sum37 A B) := λ t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case zero suc rec => right37 (t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case zero suc rec) def case37 : ∀ {Γ A B C} , Tm37 Γ (sum37 A B) → Tm37 Γ (arr37 A C) → Tm37 Γ (arr37 B C) → Tm37 Γ C := λ t u v Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case37 zero suc rec => case37 (t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case37 zero suc rec) (u Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case37 zero suc rec) (v Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case37 zero suc rec) def zero37 : ∀ {Γ} , Tm37 Γ nat37 := λ Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case37 zero37 suc rec => zero37 def suc37 : ∀ {Γ} , Tm37 Γ nat37 → Tm37 Γ nat37 := λ t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case37 zero37 suc37 rec => suc37 (t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case37 zero37 suc37 rec) def rec37 : ∀ {Γ A} , Tm37 Γ nat37 → Tm37 Γ (arr37 nat37 (arr37 A A)) → Tm37 Γ A → Tm37 Γ A := λ t u v Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case37 zero37 suc37 rec37 => rec37 (t Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case37 zero37 suc37 rec37) (u Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case37 zero37 suc37 rec37) (v Tm37 var37 lam37 app37 tt37 pair37 fst37 snd37 left37 right37 case37 zero37 suc37 rec37) def v037 : ∀ {Γ A}, Tm37 (snoc37 Γ A) A := var37 vz37 def v137 : ∀ {Γ A B}, Tm37 (snoc37 (snoc37 Γ A) B) A := var37 (vs37 vz37) def v237 : ∀ {Γ A B C}, Tm37 (snoc37 (snoc37 (snoc37 Γ A) B) C) A := var37 (vs37 (vs37 vz37)) def v337 : ∀ {Γ A B C D}, Tm37 (snoc37 (snoc37 (snoc37 (snoc37 Γ A) B) C) D) A := var37 (vs37 (vs37 (vs37 vz37))) def tbool37 : Ty37 := sum37 top37 top37 def ttrue37 : ∀ {Γ}, Tm37 Γ tbool37 := left37 tt37 def tfalse37 : ∀ {Γ}, Tm37 Γ tbool37 := right37 tt37 def ifthenelse37 : ∀ {Γ A}, Tm37 Γ (arr37 tbool37 (arr37 A (arr37 A A))) := lam37 (lam37 (lam37 (case37 v237 (lam37 v237) (lam37 v137)))) def times437 : ∀ {Γ A}, Tm37 Γ (arr37 (arr37 A A) (arr37 A A)) := lam37 (lam37 (app37 v137 (app37 v137 (app37 v137 (app37 v137 v037))))) def add37 : ∀ {Γ}, Tm37 Γ (arr37 nat37 (arr37 nat37 nat37)) := lam37 (rec37 v037 (lam37 (lam37 (lam37 (suc37 (app37 v137 v037))))) (lam37 v037)) def mul37 : ∀ {Γ}, Tm37 Γ (arr37 nat37 (arr37 nat37 nat37)) := lam37 (rec37 v037 (lam37 (lam37 (lam37 (app37 (app37 add37 (app37 v137 v037)) v037)))) (lam37 zero37)) def fact37 : ∀ {Γ}, Tm37 Γ (arr37 nat37 nat37) := lam37 (rec37 v037 (lam37 (lam37 (app37 (app37 mul37 (suc37 v137)) v037))) (suc37 zero37)) def Ty38 : Type 1 := ∀ (Ty38 : Type) (nat top bot : Ty38) (arr prod sum : Ty38 → Ty38 → Ty38) , Ty38 def nat38 : Ty38 := λ _ nat38 _ _ _ _ _ => nat38 def top38 : Ty38 := λ _ _ top38 _ _ _ _ => top38 def bot38 : Ty38 := λ _ _ _ bot38 _ _ _ => bot38 def arr38 : Ty38 → Ty38 → Ty38 := λ A B Ty38 nat38 top38 bot38 arr38 prod sum => arr38 (A Ty38 nat38 top38 bot38 arr38 prod sum) (B Ty38 nat38 top38 bot38 arr38 prod sum) def prod38 : Ty38 → Ty38 → Ty38 := λ A B Ty38 nat38 top38 bot38 arr38 prod38 sum => prod38 (A Ty38 nat38 top38 bot38 arr38 prod38 sum) (B Ty38 nat38 top38 bot38 arr38 prod38 sum) def sum38 : Ty38 → Ty38 → Ty38 := λ A B Ty38 nat38 top38 bot38 arr38 prod38 sum38 => sum38 (A Ty38 nat38 top38 bot38 arr38 prod38 sum38) (B Ty38 nat38 top38 bot38 arr38 prod38 sum38) def Con38 : Type 1 := ∀ (Con38 : Type) (nil : Con38) (snoc : Con38 → Ty38 → Con38) , Con38 def nil38 : Con38 := λ Con38 nil38 snoc => nil38 def snoc38 : Con38 → Ty38 → Con38 := λ Γ A Con38 nil38 snoc38 => snoc38 (Γ Con38 nil38 snoc38) A def Var38 : Con38 → Ty38 → Type 1 := λ Γ A => ∀ (Var38 : Con38 → Ty38 → Type) (vz : ∀{Γ A}, Var38 (snoc38 Γ A) A) (vs : ∀{Γ B A}, Var38 Γ A → Var38 (snoc38 Γ B) A) , Var38 Γ A def vz38 : ∀ {Γ A}, Var38 (snoc38 Γ A) A := λ Var38 vz38 vs => vz38 def vs38 : ∀ {Γ B A}, Var38 Γ A → Var38 (snoc38 Γ B) A := λ x Var38 vz38 vs38 => vs38 (x Var38 vz38 vs38) def Tm38 : Con38 → Ty38 → Type 1 := λ Γ A => ∀ (Tm38 : Con38 → Ty38 → Type) (var : ∀ {Γ A}, Var38 Γ A → Tm38 Γ A) (lam : ∀ {Γ A B}, (Tm38 (snoc38 Γ A) B → Tm38 Γ (arr38 A B))) (app : ∀ {Γ A B} , Tm38 Γ (arr38 A B) → Tm38 Γ A → Tm38 Γ B) (tt : ∀ {Γ} , Tm38 Γ top38) (pair : ∀ {Γ A B} , Tm38 Γ A → Tm38 Γ B → Tm38 Γ (prod38 A B)) (fst : ∀ {Γ A B} , Tm38 Γ (prod38 A B) → Tm38 Γ A) (snd : ∀ {Γ A B} , Tm38 Γ (prod38 A B) → Tm38 Γ B) (left : ∀ {Γ A B} , Tm38 Γ A → Tm38 Γ (sum38 A B)) (right : ∀ {Γ A B} , Tm38 Γ B → Tm38 Γ (sum38 A B)) (case : ∀ {Γ A B C} , Tm38 Γ (sum38 A B) → Tm38 Γ (arr38 A C) → Tm38 Γ (arr38 B C) → Tm38 Γ C) (zero : ∀ {Γ} , Tm38 Γ nat38) (suc : ∀ {Γ} , Tm38 Γ nat38 → Tm38 Γ nat38) (rec : ∀ {Γ A} , Tm38 Γ nat38 → Tm38 Γ (arr38 nat38 (arr38 A A)) → Tm38 Γ A → Tm38 Γ A) , Tm38 Γ A def var38 : ∀ {Γ A}, Var38 Γ A → Tm38 Γ A := λ x Tm38 var38 lam app tt pair fst snd left right case zero suc rec => var38 x def lam38 : ∀ {Γ A B} , Tm38 (snoc38 Γ A) B → Tm38 Γ (arr38 A B) := λ t Tm38 var38 lam38 app tt pair fst snd left right case zero suc rec => lam38 (t Tm38 var38 lam38 app tt pair fst snd left right case zero suc rec) def app38 : ∀ {Γ A B} , Tm38 Γ (arr38 A B) → Tm38 Γ A → Tm38 Γ B := λ t u Tm38 var38 lam38 app38 tt pair fst snd left right case zero suc rec => app38 (t Tm38 var38 lam38 app38 tt pair fst snd left right case zero suc rec) (u Tm38 var38 lam38 app38 tt pair fst snd left right case zero suc rec) def tt38 : ∀ {Γ} , Tm38 Γ top38 := λ Tm38 var38 lam38 app38 tt38 pair fst snd left right case zero suc rec => tt38 def pair38 : ∀ {Γ A B} , Tm38 Γ A → Tm38 Γ B → Tm38 Γ (prod38 A B) := λ t u Tm38 var38 lam38 app38 tt38 pair38 fst snd left right case zero suc rec => pair38 (t Tm38 var38 lam38 app38 tt38 pair38 fst snd left right case zero suc rec) (u Tm38 var38 lam38 app38 tt38 pair38 fst snd left right case zero suc rec) def fst38 : ∀ {Γ A B} , Tm38 Γ (prod38 A B) → Tm38 Γ A := λ t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd left right case zero suc rec => fst38 (t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd left right case zero suc rec) def snd38 : ∀ {Γ A B} , Tm38 Γ (prod38 A B) → Tm38 Γ B := λ t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left right case zero suc rec => snd38 (t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left right case zero suc rec) def left38 : ∀ {Γ A B} , Tm38 Γ A → Tm38 Γ (sum38 A B) := λ t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right case zero suc rec => left38 (t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right case zero suc rec) def right38 : ∀ {Γ A B} , Tm38 Γ B → Tm38 Γ (sum38 A B) := λ t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case zero suc rec => right38 (t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case zero suc rec) def case38 : ∀ {Γ A B C} , Tm38 Γ (sum38 A B) → Tm38 Γ (arr38 A C) → Tm38 Γ (arr38 B C) → Tm38 Γ C := λ t u v Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case38 zero suc rec => case38 (t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case38 zero suc rec) (u Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case38 zero suc rec) (v Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case38 zero suc rec) def zero38 : ∀ {Γ} , Tm38 Γ nat38 := λ Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case38 zero38 suc rec => zero38 def suc38 : ∀ {Γ} , Tm38 Γ nat38 → Tm38 Γ nat38 := λ t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case38 zero38 suc38 rec => suc38 (t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case38 zero38 suc38 rec) def rec38 : ∀ {Γ A} , Tm38 Γ nat38 → Tm38 Γ (arr38 nat38 (arr38 A A)) → Tm38 Γ A → Tm38 Γ A := λ t u v Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case38 zero38 suc38 rec38 => rec38 (t Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case38 zero38 suc38 rec38) (u Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case38 zero38 suc38 rec38) (v Tm38 var38 lam38 app38 tt38 pair38 fst38 snd38 left38 right38 case38 zero38 suc38 rec38) def v038 : ∀ {Γ A}, Tm38 (snoc38 Γ A) A := var38 vz38 def v138 : ∀ {Γ A B}, Tm38 (snoc38 (snoc38 Γ A) B) A := var38 (vs38 vz38) def v238 : ∀ {Γ A B C}, Tm38 (snoc38 (snoc38 (snoc38 Γ A) B) C) A := var38 (vs38 (vs38 vz38)) def v338 : ∀ {Γ A B C D}, Tm38 (snoc38 (snoc38 (snoc38 (snoc38 Γ A) B) C) D) A := var38 (vs38 (vs38 (vs38 vz38))) def tbool38 : Ty38 := sum38 top38 top38 def ttrue38 : ∀ {Γ}, Tm38 Γ tbool38 := left38 tt38 def tfalse38 : ∀ {Γ}, Tm38 Γ tbool38 := right38 tt38 def ifthenelse38 : ∀ {Γ A}, Tm38 Γ (arr38 tbool38 (arr38 A (arr38 A A))) := lam38 (lam38 (lam38 (case38 v238 (lam38 v238) (lam38 v138)))) def times438 : ∀ {Γ A}, Tm38 Γ (arr38 (arr38 A A) (arr38 A A)) := lam38 (lam38 (app38 v138 (app38 v138 (app38 v138 (app38 v138 v038))))) def add38 : ∀ {Γ}, Tm38 Γ (arr38 nat38 (arr38 nat38 nat38)) := lam38 (rec38 v038 (lam38 (lam38 (lam38 (suc38 (app38 v138 v038))))) (lam38 v038)) def mul38 : ∀ {Γ}, Tm38 Γ (arr38 nat38 (arr38 nat38 nat38)) := lam38 (rec38 v038 (lam38 (lam38 (lam38 (app38 (app38 add38 (app38 v138 v038)) v038)))) (lam38 zero38)) def fact38 : ∀ {Γ}, Tm38 Γ (arr38 nat38 nat38) := lam38 (rec38 v038 (lam38 (lam38 (app38 (app38 mul38 (suc38 v138)) v038))) (suc38 zero38)) def Ty39 : Type 1 := ∀ (Ty39 : Type) (nat top bot : Ty39) (arr prod sum : Ty39 → Ty39 → Ty39) , Ty39 def nat39 : Ty39 := λ _ nat39 _ _ _ _ _ => nat39 def top39 : Ty39 := λ _ _ top39 _ _ _ _ => top39 def bot39 : Ty39 := λ _ _ _ bot39 _ _ _ => bot39 def arr39 : Ty39 → Ty39 → Ty39 := λ A B Ty39 nat39 top39 bot39 arr39 prod sum => arr39 (A Ty39 nat39 top39 bot39 arr39 prod sum) (B Ty39 nat39 top39 bot39 arr39 prod sum) def prod39 : Ty39 → Ty39 → Ty39 := λ A B Ty39 nat39 top39 bot39 arr39 prod39 sum => prod39 (A Ty39 nat39 top39 bot39 arr39 prod39 sum) (B Ty39 nat39 top39 bot39 arr39 prod39 sum) def sum39 : Ty39 → Ty39 → Ty39 := λ A B Ty39 nat39 top39 bot39 arr39 prod39 sum39 => sum39 (A Ty39 nat39 top39 bot39 arr39 prod39 sum39) (B Ty39 nat39 top39 bot39 arr39 prod39 sum39) def Con39 : Type 1 := ∀ (Con39 : Type) (nil : Con39) (snoc : Con39 → Ty39 → Con39) , Con39 def nil39 : Con39 := λ Con39 nil39 snoc => nil39 def snoc39 : Con39 → Ty39 → Con39 := λ Γ A Con39 nil39 snoc39 => snoc39 (Γ Con39 nil39 snoc39) A def Var39 : Con39 → Ty39 → Type 1 := λ Γ A => ∀ (Var39 : Con39 → Ty39 → Type) (vz : ∀{Γ A}, Var39 (snoc39 Γ A) A) (vs : ∀{Γ B A}, Var39 Γ A → Var39 (snoc39 Γ B) A) , Var39 Γ A def vz39 : ∀ {Γ A}, Var39 (snoc39 Γ A) A := λ Var39 vz39 vs => vz39 def vs39 : ∀ {Γ B A}, Var39 Γ A → Var39 (snoc39 Γ B) A := λ x Var39 vz39 vs39 => vs39 (x Var39 vz39 vs39) def Tm39 : Con39 → Ty39 → Type 1 := λ Γ A => ∀ (Tm39 : Con39 → Ty39 → Type) (var : ∀ {Γ A}, Var39 Γ A → Tm39 Γ A) (lam : ∀ {Γ A B}, (Tm39 (snoc39 Γ A) B → Tm39 Γ (arr39 A B))) (app : ∀ {Γ A B} , Tm39 Γ (arr39 A B) → Tm39 Γ A → Tm39 Γ B) (tt : ∀ {Γ} , Tm39 Γ top39) (pair : ∀ {Γ A B} , Tm39 Γ A → Tm39 Γ B → Tm39 Γ (prod39 A B)) (fst : ∀ {Γ A B} , Tm39 Γ (prod39 A B) → Tm39 Γ A) (snd : ∀ {Γ A B} , Tm39 Γ (prod39 A B) → Tm39 Γ B) (left : ∀ {Γ A B} , Tm39 Γ A → Tm39 Γ (sum39 A B)) (right : ∀ {Γ A B} , Tm39 Γ B → Tm39 Γ (sum39 A B)) (case : ∀ {Γ A B C} , Tm39 Γ (sum39 A B) → Tm39 Γ (arr39 A C) → Tm39 Γ (arr39 B C) → Tm39 Γ C) (zero : ∀ {Γ} , Tm39 Γ nat39) (suc : ∀ {Γ} , Tm39 Γ nat39 → Tm39 Γ nat39) (rec : ∀ {Γ A} , Tm39 Γ nat39 → Tm39 Γ (arr39 nat39 (arr39 A A)) → Tm39 Γ A → Tm39 Γ A) , Tm39 Γ A def var39 : ∀ {Γ A}, Var39 Γ A → Tm39 Γ A := λ x Tm39 var39 lam app tt pair fst snd left right case zero suc rec => var39 x def lam39 : ∀ {Γ A B} , Tm39 (snoc39 Γ A) B → Tm39 Γ (arr39 A B) := λ t Tm39 var39 lam39 app tt pair fst snd left right case zero suc rec => lam39 (t Tm39 var39 lam39 app tt pair fst snd left right case zero suc rec) def app39 : ∀ {Γ A B} , Tm39 Γ (arr39 A B) → Tm39 Γ A → Tm39 Γ B := λ t u Tm39 var39 lam39 app39 tt pair fst snd left right case zero suc rec => app39 (t Tm39 var39 lam39 app39 tt pair fst snd left right case zero suc rec) (u Tm39 var39 lam39 app39 tt pair fst snd left right case zero suc rec) def tt39 : ∀ {Γ} , Tm39 Γ top39 := λ Tm39 var39 lam39 app39 tt39 pair fst snd left right case zero suc rec => tt39 def pair39 : ∀ {Γ A B} , Tm39 Γ A → Tm39 Γ B → Tm39 Γ (prod39 A B) := λ t u Tm39 var39 lam39 app39 tt39 pair39 fst snd left right case zero suc rec => pair39 (t Tm39 var39 lam39 app39 tt39 pair39 fst snd left right case zero suc rec) (u Tm39 var39 lam39 app39 tt39 pair39 fst snd left right case zero suc rec) def fst39 : ∀ {Γ A B} , Tm39 Γ (prod39 A B) → Tm39 Γ A := λ t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd left right case zero suc rec => fst39 (t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd left right case zero suc rec) def snd39 : ∀ {Γ A B} , Tm39 Γ (prod39 A B) → Tm39 Γ B := λ t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left right case zero suc rec => snd39 (t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left right case zero suc rec) def left39 : ∀ {Γ A B} , Tm39 Γ A → Tm39 Γ (sum39 A B) := λ t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right case zero suc rec => left39 (t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right case zero suc rec) def right39 : ∀ {Γ A B} , Tm39 Γ B → Tm39 Γ (sum39 A B) := λ t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case zero suc rec => right39 (t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case zero suc rec) def case39 : ∀ {Γ A B C} , Tm39 Γ (sum39 A B) → Tm39 Γ (arr39 A C) → Tm39 Γ (arr39 B C) → Tm39 Γ C := λ t u v Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case39 zero suc rec => case39 (t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case39 zero suc rec) (u Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case39 zero suc rec) (v Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case39 zero suc rec) def zero39 : ∀ {Γ} , Tm39 Γ nat39 := λ Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case39 zero39 suc rec => zero39 def suc39 : ∀ {Γ} , Tm39 Γ nat39 → Tm39 Γ nat39 := λ t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case39 zero39 suc39 rec => suc39 (t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case39 zero39 suc39 rec) def rec39 : ∀ {Γ A} , Tm39 Γ nat39 → Tm39 Γ (arr39 nat39 (arr39 A A)) → Tm39 Γ A → Tm39 Γ A := λ t u v Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case39 zero39 suc39 rec39 => rec39 (t Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case39 zero39 suc39 rec39) (u Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case39 zero39 suc39 rec39) (v Tm39 var39 lam39 app39 tt39 pair39 fst39 snd39 left39 right39 case39 zero39 suc39 rec39) def v039 : ∀ {Γ A}, Tm39 (snoc39 Γ A) A := var39 vz39 def v139 : ∀ {Γ A B}, Tm39 (snoc39 (snoc39 Γ A) B) A := var39 (vs39 vz39) def v239 : ∀ {Γ A B C}, Tm39 (snoc39 (snoc39 (snoc39 Γ A) B) C) A := var39 (vs39 (vs39 vz39)) def v339 : ∀ {Γ A B C D}, Tm39 (snoc39 (snoc39 (snoc39 (snoc39 Γ A) B) C) D) A := var39 (vs39 (vs39 (vs39 vz39))) def tbool39 : Ty39 := sum39 top39 top39 def ttrue39 : ∀ {Γ}, Tm39 Γ tbool39 := left39 tt39 def tfalse39 : ∀ {Γ}, Tm39 Γ tbool39 := right39 tt39 def ifthenelse39 : ∀ {Γ A}, Tm39 Γ (arr39 tbool39 (arr39 A (arr39 A A))) := lam39 (lam39 (lam39 (case39 v239 (lam39 v239) (lam39 v139)))) def times439 : ∀ {Γ A}, Tm39 Γ (arr39 (arr39 A A) (arr39 A A)) := lam39 (lam39 (app39 v139 (app39 v139 (app39 v139 (app39 v139 v039))))) def add39 : ∀ {Γ}, Tm39 Γ (arr39 nat39 (arr39 nat39 nat39)) := lam39 (rec39 v039 (lam39 (lam39 (lam39 (suc39 (app39 v139 v039))))) (lam39 v039)) def mul39 : ∀ {Γ}, Tm39 Γ (arr39 nat39 (arr39 nat39 nat39)) := lam39 (rec39 v039 (lam39 (lam39 (lam39 (app39 (app39 add39 (app39 v139 v039)) v039)))) (lam39 zero39)) def fact39 : ∀ {Γ}, Tm39 Γ (arr39 nat39 nat39) := lam39 (rec39 v039 (lam39 (lam39 (app39 (app39 mul39 (suc39 v139)) v039))) (suc39 zero39)) def Ty40 : Type 1 := ∀ (Ty40 : Type) (nat top bot : Ty40) (arr prod sum : Ty40 → Ty40 → Ty40) , Ty40 def nat40 : Ty40 := λ _ nat40 _ _ _ _ _ => nat40 def top40 : Ty40 := λ _ _ top40 _ _ _ _ => top40 def bot40 : Ty40 := λ _ _ _ bot40 _ _ _ => bot40 def arr40 : Ty40 → Ty40 → Ty40 := λ A B Ty40 nat40 top40 bot40 arr40 prod sum => arr40 (A Ty40 nat40 top40 bot40 arr40 prod sum) (B Ty40 nat40 top40 bot40 arr40 prod sum) def prod40 : Ty40 → Ty40 → Ty40 := λ A B Ty40 nat40 top40 bot40 arr40 prod40 sum => prod40 (A Ty40 nat40 top40 bot40 arr40 prod40 sum) (B Ty40 nat40 top40 bot40 arr40 prod40 sum) def sum40 : Ty40 → Ty40 → Ty40 := λ A B Ty40 nat40 top40 bot40 arr40 prod40 sum40 => sum40 (A Ty40 nat40 top40 bot40 arr40 prod40 sum40) (B Ty40 nat40 top40 bot40 arr40 prod40 sum40) def Con40 : Type 1 := ∀ (Con40 : Type) (nil : Con40) (snoc : Con40 → Ty40 → Con40) , Con40 def nil40 : Con40 := λ Con40 nil40 snoc => nil40 def snoc40 : Con40 → Ty40 → Con40 := λ Γ A Con40 nil40 snoc40 => snoc40 (Γ Con40 nil40 snoc40) A def Var40 : Con40 → Ty40 → Type 1 := λ Γ A => ∀ (Var40 : Con40 → Ty40 → Type) (vz : ∀{Γ A}, Var40 (snoc40 Γ A) A) (vs : ∀{Γ B A}, Var40 Γ A → Var40 (snoc40 Γ B) A) , Var40 Γ A def vz40 : ∀ {Γ A}, Var40 (snoc40 Γ A) A := λ Var40 vz40 vs => vz40 def vs40 : ∀ {Γ B A}, Var40 Γ A → Var40 (snoc40 Γ B) A := λ x Var40 vz40 vs40 => vs40 (x Var40 vz40 vs40) def Tm40 : Con40 → Ty40 → Type 1 := λ Γ A => ∀ (Tm40 : Con40 → Ty40 → Type) (var : ∀ {Γ A}, Var40 Γ A → Tm40 Γ A) (lam : ∀ {Γ A B}, (Tm40 (snoc40 Γ A) B → Tm40 Γ (arr40 A B))) (app : ∀ {Γ A B} , Tm40 Γ (arr40 A B) → Tm40 Γ A → Tm40 Γ B) (tt : ∀ {Γ} , Tm40 Γ top40) (pair : ∀ {Γ A B} , Tm40 Γ A → Tm40 Γ B → Tm40 Γ (prod40 A B)) (fst : ∀ {Γ A B} , Tm40 Γ (prod40 A B) → Tm40 Γ A) (snd : ∀ {Γ A B} , Tm40 Γ (prod40 A B) → Tm40 Γ B) (left : ∀ {Γ A B} , Tm40 Γ A → Tm40 Γ (sum40 A B)) (right : ∀ {Γ A B} , Tm40 Γ B → Tm40 Γ (sum40 A B)) (case : ∀ {Γ A B C} , Tm40 Γ (sum40 A B) → Tm40 Γ (arr40 A C) → Tm40 Γ (arr40 B C) → Tm40 Γ C) (zero : ∀ {Γ} , Tm40 Γ nat40) (suc : ∀ {Γ} , Tm40 Γ nat40 → Tm40 Γ nat40) (rec : ∀ {Γ A} , Tm40 Γ nat40 → Tm40 Γ (arr40 nat40 (arr40 A A)) → Tm40 Γ A → Tm40 Γ A) , Tm40 Γ A def var40 : ∀ {Γ A}, Var40 Γ A → Tm40 Γ A := λ x Tm40 var40 lam app tt pair fst snd left right case zero suc rec => var40 x def lam40 : ∀ {Γ A B} , Tm40 (snoc40 Γ A) B → Tm40 Γ (arr40 A B) := λ t Tm40 var40 lam40 app tt pair fst snd left right case zero suc rec => lam40 (t Tm40 var40 lam40 app tt pair fst snd left right case zero suc rec) def app40 : ∀ {Γ A B} , Tm40 Γ (arr40 A B) → Tm40 Γ A → Tm40 Γ B := λ t u Tm40 var40 lam40 app40 tt pair fst snd left right case zero suc rec => app40 (t Tm40 var40 lam40 app40 tt pair fst snd left right case zero suc rec) (u Tm40 var40 lam40 app40 tt pair fst snd left right case zero suc rec) def tt40 : ∀ {Γ} , Tm40 Γ top40 := λ Tm40 var40 lam40 app40 tt40 pair fst snd left right case zero suc rec => tt40 def pair40 : ∀ {Γ A B} , Tm40 Γ A → Tm40 Γ B → Tm40 Γ (prod40 A B) := λ t u Tm40 var40 lam40 app40 tt40 pair40 fst snd left right case zero suc rec => pair40 (t Tm40 var40 lam40 app40 tt40 pair40 fst snd left right case zero suc rec) (u Tm40 var40 lam40 app40 tt40 pair40 fst snd left right case zero suc rec) def fst40 : ∀ {Γ A B} , Tm40 Γ (prod40 A B) → Tm40 Γ A := λ t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd left right case zero suc rec => fst40 (t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd left right case zero suc rec) def snd40 : ∀ {Γ A B} , Tm40 Γ (prod40 A B) → Tm40 Γ B := λ t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left right case zero suc rec => snd40 (t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left right case zero suc rec) def left40 : ∀ {Γ A B} , Tm40 Γ A → Tm40 Γ (sum40 A B) := λ t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right case zero suc rec => left40 (t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right case zero suc rec) def right40 : ∀ {Γ A B} , Tm40 Γ B → Tm40 Γ (sum40 A B) := λ t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case zero suc rec => right40 (t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case zero suc rec) def case40 : ∀ {Γ A B C} , Tm40 Γ (sum40 A B) → Tm40 Γ (arr40 A C) → Tm40 Γ (arr40 B C) → Tm40 Γ C := λ t u v Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case40 zero suc rec => case40 (t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case40 zero suc rec) (u Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case40 zero suc rec) (v Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case40 zero suc rec) def zero40 : ∀ {Γ} , Tm40 Γ nat40 := λ Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case40 zero40 suc rec => zero40 def suc40 : ∀ {Γ} , Tm40 Γ nat40 → Tm40 Γ nat40 := λ t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case40 zero40 suc40 rec => suc40 (t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case40 zero40 suc40 rec) def rec40 : ∀ {Γ A} , Tm40 Γ nat40 → Tm40 Γ (arr40 nat40 (arr40 A A)) → Tm40 Γ A → Tm40 Γ A := λ t u v Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case40 zero40 suc40 rec40 => rec40 (t Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case40 zero40 suc40 rec40) (u Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case40 zero40 suc40 rec40) (v Tm40 var40 lam40 app40 tt40 pair40 fst40 snd40 left40 right40 case40 zero40 suc40 rec40) def v040 : ∀ {Γ A}, Tm40 (snoc40 Γ A) A := var40 vz40 def v140 : ∀ {Γ A B}, Tm40 (snoc40 (snoc40 Γ A) B) A := var40 (vs40 vz40) def v240 : ∀ {Γ A B C}, Tm40 (snoc40 (snoc40 (snoc40 Γ A) B) C) A := var40 (vs40 (vs40 vz40)) def v340 : ∀ {Γ A B C D}, Tm40 (snoc40 (snoc40 (snoc40 (snoc40 Γ A) B) C) D) A := var40 (vs40 (vs40 (vs40 vz40))) def tbool40 : Ty40 := sum40 top40 top40 def ttrue40 : ∀ {Γ}, Tm40 Γ tbool40 := left40 tt40 def tfalse40 : ∀ {Γ}, Tm40 Γ tbool40 := right40 tt40 def ifthenelse40 : ∀ {Γ A}, Tm40 Γ (arr40 tbool40 (arr40 A (arr40 A A))) := lam40 (lam40 (lam40 (case40 v240 (lam40 v240) (lam40 v140)))) def times440 : ∀ {Γ A}, Tm40 Γ (arr40 (arr40 A A) (arr40 A A)) := lam40 (lam40 (app40 v140 (app40 v140 (app40 v140 (app40 v140 v040))))) def add40 : ∀ {Γ}, Tm40 Γ (arr40 nat40 (arr40 nat40 nat40)) := lam40 (rec40 v040 (lam40 (lam40 (lam40 (suc40 (app40 v140 v040))))) (lam40 v040)) def mul40 : ∀ {Γ}, Tm40 Γ (arr40 nat40 (arr40 nat40 nat40)) := lam40 (rec40 v040 (lam40 (lam40 (lam40 (app40 (app40 add40 (app40 v140 v040)) v040)))) (lam40 zero40)) def fact40 : ∀ {Γ}, Tm40 Γ (arr40 nat40 nat40) := lam40 (rec40 v040 (lam40 (lam40 (app40 (app40 mul40 (suc40 v140)) v040))) (suc40 zero40)) def Ty41 : Type 1 := ∀ (Ty41 : Type) (nat top bot : Ty41) (arr prod sum : Ty41 → Ty41 → Ty41) , Ty41 def nat41 : Ty41 := λ _ nat41 _ _ _ _ _ => nat41 def top41 : Ty41 := λ _ _ top41 _ _ _ _ => top41 def bot41 : Ty41 := λ _ _ _ bot41 _ _ _ => bot41 def arr41 : Ty41 → Ty41 → Ty41 := λ A B Ty41 nat41 top41 bot41 arr41 prod sum => arr41 (A Ty41 nat41 top41 bot41 arr41 prod sum) (B Ty41 nat41 top41 bot41 arr41 prod sum) def prod41 : Ty41 → Ty41 → Ty41 := λ A B Ty41 nat41 top41 bot41 arr41 prod41 sum => prod41 (A Ty41 nat41 top41 bot41 arr41 prod41 sum) (B Ty41 nat41 top41 bot41 arr41 prod41 sum) def sum41 : Ty41 → Ty41 → Ty41 := λ A B Ty41 nat41 top41 bot41 arr41 prod41 sum41 => sum41 (A Ty41 nat41 top41 bot41 arr41 prod41 sum41) (B Ty41 nat41 top41 bot41 arr41 prod41 sum41) def Con41 : Type 1 := ∀ (Con41 : Type) (nil : Con41) (snoc : Con41 → Ty41 → Con41) , Con41 def nil41 : Con41 := λ Con41 nil41 snoc => nil41 def snoc41 : Con41 → Ty41 → Con41 := λ Γ A Con41 nil41 snoc41 => snoc41 (Γ Con41 nil41 snoc41) A def Var41 : Con41 → Ty41 → Type 1 := λ Γ A => ∀ (Var41 : Con41 → Ty41 → Type) (vz : ∀{Γ A}, Var41 (snoc41 Γ A) A) (vs : ∀{Γ B A}, Var41 Γ A → Var41 (snoc41 Γ B) A) , Var41 Γ A def vz41 : ∀ {Γ A}, Var41 (snoc41 Γ A) A := λ Var41 vz41 vs => vz41 def vs41 : ∀ {Γ B A}, Var41 Γ A → Var41 (snoc41 Γ B) A := λ x Var41 vz41 vs41 => vs41 (x Var41 vz41 vs41) def Tm41 : Con41 → Ty41 → Type 1 := λ Γ A => ∀ (Tm41 : Con41 → Ty41 → Type) (var : ∀ {Γ A}, Var41 Γ A → Tm41 Γ A) (lam : ∀ {Γ A B}, (Tm41 (snoc41 Γ A) B → Tm41 Γ (arr41 A B))) (app : ∀ {Γ A B} , Tm41 Γ (arr41 A B) → Tm41 Γ A → Tm41 Γ B) (tt : ∀ {Γ} , Tm41 Γ top41) (pair : ∀ {Γ A B} , Tm41 Γ A → Tm41 Γ B → Tm41 Γ (prod41 A B)) (fst : ∀ {Γ A B} , Tm41 Γ (prod41 A B) → Tm41 Γ A) (snd : ∀ {Γ A B} , Tm41 Γ (prod41 A B) → Tm41 Γ B) (left : ∀ {Γ A B} , Tm41 Γ A → Tm41 Γ (sum41 A B)) (right : ∀ {Γ A B} , Tm41 Γ B → Tm41 Γ (sum41 A B)) (case : ∀ {Γ A B C} , Tm41 Γ (sum41 A B) → Tm41 Γ (arr41 A C) → Tm41 Γ (arr41 B C) → Tm41 Γ C) (zero : ∀ {Γ} , Tm41 Γ nat41) (suc : ∀ {Γ} , Tm41 Γ nat41 → Tm41 Γ nat41) (rec : ∀ {Γ A} , Tm41 Γ nat41 → Tm41 Γ (arr41 nat41 (arr41 A A)) → Tm41 Γ A → Tm41 Γ A) , Tm41 Γ A def var41 : ∀ {Γ A}, Var41 Γ A → Tm41 Γ A := λ x Tm41 var41 lam app tt pair fst snd left right case zero suc rec => var41 x def lam41 : ∀ {Γ A B} , Tm41 (snoc41 Γ A) B → Tm41 Γ (arr41 A B) := λ t Tm41 var41 lam41 app tt pair fst snd left right case zero suc rec => lam41 (t Tm41 var41 lam41 app tt pair fst snd left right case zero suc rec) def app41 : ∀ {Γ A B} , Tm41 Γ (arr41 A B) → Tm41 Γ A → Tm41 Γ B := λ t u Tm41 var41 lam41 app41 tt pair fst snd left right case zero suc rec => app41 (t Tm41 var41 lam41 app41 tt pair fst snd left right case zero suc rec) (u Tm41 var41 lam41 app41 tt pair fst snd left right case zero suc rec) def tt41 : ∀ {Γ} , Tm41 Γ top41 := λ Tm41 var41 lam41 app41 tt41 pair fst snd left right case zero suc rec => tt41 def pair41 : ∀ {Γ A B} , Tm41 Γ A → Tm41 Γ B → Tm41 Γ (prod41 A B) := λ t u Tm41 var41 lam41 app41 tt41 pair41 fst snd left right case zero suc rec => pair41 (t Tm41 var41 lam41 app41 tt41 pair41 fst snd left right case zero suc rec) (u Tm41 var41 lam41 app41 tt41 pair41 fst snd left right case zero suc rec) def fst41 : ∀ {Γ A B} , Tm41 Γ (prod41 A B) → Tm41 Γ A := λ t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd left right case zero suc rec => fst41 (t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd left right case zero suc rec) def snd41 : ∀ {Γ A B} , Tm41 Γ (prod41 A B) → Tm41 Γ B := λ t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left right case zero suc rec => snd41 (t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left right case zero suc rec) def left41 : ∀ {Γ A B} , Tm41 Γ A → Tm41 Γ (sum41 A B) := λ t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right case zero suc rec => left41 (t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right case zero suc rec) def right41 : ∀ {Γ A B} , Tm41 Γ B → Tm41 Γ (sum41 A B) := λ t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case zero suc rec => right41 (t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case zero suc rec) def case41 : ∀ {Γ A B C} , Tm41 Γ (sum41 A B) → Tm41 Γ (arr41 A C) → Tm41 Γ (arr41 B C) → Tm41 Γ C := λ t u v Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case41 zero suc rec => case41 (t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case41 zero suc rec) (u Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case41 zero suc rec) (v Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case41 zero suc rec) def zero41 : ∀ {Γ} , Tm41 Γ nat41 := λ Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case41 zero41 suc rec => zero41 def suc41 : ∀ {Γ} , Tm41 Γ nat41 → Tm41 Γ nat41 := λ t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case41 zero41 suc41 rec => suc41 (t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case41 zero41 suc41 rec) def rec41 : ∀ {Γ A} , Tm41 Γ nat41 → Tm41 Γ (arr41 nat41 (arr41 A A)) → Tm41 Γ A → Tm41 Γ A := λ t u v Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case41 zero41 suc41 rec41 => rec41 (t Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case41 zero41 suc41 rec41) (u Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case41 zero41 suc41 rec41) (v Tm41 var41 lam41 app41 tt41 pair41 fst41 snd41 left41 right41 case41 zero41 suc41 rec41) def v041 : ∀ {Γ A}, Tm41 (snoc41 Γ A) A := var41 vz41 def v141 : ∀ {Γ A B}, Tm41 (snoc41 (snoc41 Γ A) B) A := var41 (vs41 vz41) def v241 : ∀ {Γ A B C}, Tm41 (snoc41 (snoc41 (snoc41 Γ A) B) C) A := var41 (vs41 (vs41 vz41)) def v341 : ∀ {Γ A B C D}, Tm41 (snoc41 (snoc41 (snoc41 (snoc41 Γ A) B) C) D) A := var41 (vs41 (vs41 (vs41 vz41))) def tbool41 : Ty41 := sum41 top41 top41 def ttrue41 : ∀ {Γ}, Tm41 Γ tbool41 := left41 tt41 def tfalse41 : ∀ {Γ}, Tm41 Γ tbool41 := right41 tt41 def ifthenelse41 : ∀ {Γ A}, Tm41 Γ (arr41 tbool41 (arr41 A (arr41 A A))) := lam41 (lam41 (lam41 (case41 v241 (lam41 v241) (lam41 v141)))) def times441 : ∀ {Γ A}, Tm41 Γ (arr41 (arr41 A A) (arr41 A A)) := lam41 (lam41 (app41 v141 (app41 v141 (app41 v141 (app41 v141 v041))))) def add41 : ∀ {Γ}, Tm41 Γ (arr41 nat41 (arr41 nat41 nat41)) := lam41 (rec41 v041 (lam41 (lam41 (lam41 (suc41 (app41 v141 v041))))) (lam41 v041)) def mul41 : ∀ {Γ}, Tm41 Γ (arr41 nat41 (arr41 nat41 nat41)) := lam41 (rec41 v041 (lam41 (lam41 (lam41 (app41 (app41 add41 (app41 v141 v041)) v041)))) (lam41 zero41)) def fact41 : ∀ {Γ}, Tm41 Γ (arr41 nat41 nat41) := lam41 (rec41 v041 (lam41 (lam41 (app41 (app41 mul41 (suc41 v141)) v041))) (suc41 zero41)) def Ty42 : Type 1 := ∀ (Ty42 : Type) (nat top bot : Ty42) (arr prod sum : Ty42 → Ty42 → Ty42) , Ty42 def nat42 : Ty42 := λ _ nat42 _ _ _ _ _ => nat42 def top42 : Ty42 := λ _ _ top42 _ _ _ _ => top42 def bot42 : Ty42 := λ _ _ _ bot42 _ _ _ => bot42 def arr42 : Ty42 → Ty42 → Ty42 := λ A B Ty42 nat42 top42 bot42 arr42 prod sum => arr42 (A Ty42 nat42 top42 bot42 arr42 prod sum) (B Ty42 nat42 top42 bot42 arr42 prod sum) def prod42 : Ty42 → Ty42 → Ty42 := λ A B Ty42 nat42 top42 bot42 arr42 prod42 sum => prod42 (A Ty42 nat42 top42 bot42 arr42 prod42 sum) (B Ty42 nat42 top42 bot42 arr42 prod42 sum) def sum42 : Ty42 → Ty42 → Ty42 := λ A B Ty42 nat42 top42 bot42 arr42 prod42 sum42 => sum42 (A Ty42 nat42 top42 bot42 arr42 prod42 sum42) (B Ty42 nat42 top42 bot42 arr42 prod42 sum42) def Con42 : Type 1 := ∀ (Con42 : Type) (nil : Con42) (snoc : Con42 → Ty42 → Con42) , Con42 def nil42 : Con42 := λ Con42 nil42 snoc => nil42 def snoc42 : Con42 → Ty42 → Con42 := λ Γ A Con42 nil42 snoc42 => snoc42 (Γ Con42 nil42 snoc42) A def Var42 : Con42 → Ty42 → Type 1 := λ Γ A => ∀ (Var42 : Con42 → Ty42 → Type) (vz : ∀{Γ A}, Var42 (snoc42 Γ A) A) (vs : ∀{Γ B A}, Var42 Γ A → Var42 (snoc42 Γ B) A) , Var42 Γ A def vz42 : ∀ {Γ A}, Var42 (snoc42 Γ A) A := λ Var42 vz42 vs => vz42 def vs42 : ∀ {Γ B A}, Var42 Γ A → Var42 (snoc42 Γ B) A := λ x Var42 vz42 vs42 => vs42 (x Var42 vz42 vs42) def Tm42 : Con42 → Ty42 → Type 1 := λ Γ A => ∀ (Tm42 : Con42 → Ty42 → Type) (var : ∀ {Γ A}, Var42 Γ A → Tm42 Γ A) (lam : ∀ {Γ A B}, (Tm42 (snoc42 Γ A) B → Tm42 Γ (arr42 A B))) (app : ∀ {Γ A B} , Tm42 Γ (arr42 A B) → Tm42 Γ A → Tm42 Γ B) (tt : ∀ {Γ} , Tm42 Γ top42) (pair : ∀ {Γ A B} , Tm42 Γ A → Tm42 Γ B → Tm42 Γ (prod42 A B)) (fst : ∀ {Γ A B} , Tm42 Γ (prod42 A B) → Tm42 Γ A) (snd : ∀ {Γ A B} , Tm42 Γ (prod42 A B) → Tm42 Γ B) (left : ∀ {Γ A B} , Tm42 Γ A → Tm42 Γ (sum42 A B)) (right : ∀ {Γ A B} , Tm42 Γ B → Tm42 Γ (sum42 A B)) (case : ∀ {Γ A B C} , Tm42 Γ (sum42 A B) → Tm42 Γ (arr42 A C) → Tm42 Γ (arr42 B C) → Tm42 Γ C) (zero : ∀ {Γ} , Tm42 Γ nat42) (suc : ∀ {Γ} , Tm42 Γ nat42 → Tm42 Γ nat42) (rec : ∀ {Γ A} , Tm42 Γ nat42 → Tm42 Γ (arr42 nat42 (arr42 A A)) → Tm42 Γ A → Tm42 Γ A) , Tm42 Γ A def var42 : ∀ {Γ A}, Var42 Γ A → Tm42 Γ A := λ x Tm42 var42 lam app tt pair fst snd left right case zero suc rec => var42 x def lam42 : ∀ {Γ A B} , Tm42 (snoc42 Γ A) B → Tm42 Γ (arr42 A B) := λ t Tm42 var42 lam42 app tt pair fst snd left right case zero suc rec => lam42 (t Tm42 var42 lam42 app tt pair fst snd left right case zero suc rec) def app42 : ∀ {Γ A B} , Tm42 Γ (arr42 A B) → Tm42 Γ A → Tm42 Γ B := λ t u Tm42 var42 lam42 app42 tt pair fst snd left right case zero suc rec => app42 (t Tm42 var42 lam42 app42 tt pair fst snd left right case zero suc rec) (u Tm42 var42 lam42 app42 tt pair fst snd left right case zero suc rec) def tt42 : ∀ {Γ} , Tm42 Γ top42 := λ Tm42 var42 lam42 app42 tt42 pair fst snd left right case zero suc rec => tt42 def pair42 : ∀ {Γ A B} , Tm42 Γ A → Tm42 Γ B → Tm42 Γ (prod42 A B) := λ t u Tm42 var42 lam42 app42 tt42 pair42 fst snd left right case zero suc rec => pair42 (t Tm42 var42 lam42 app42 tt42 pair42 fst snd left right case zero suc rec) (u Tm42 var42 lam42 app42 tt42 pair42 fst snd left right case zero suc rec) def fst42 : ∀ {Γ A B} , Tm42 Γ (prod42 A B) → Tm42 Γ A := λ t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd left right case zero suc rec => fst42 (t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd left right case zero suc rec) def snd42 : ∀ {Γ A B} , Tm42 Γ (prod42 A B) → Tm42 Γ B := λ t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left right case zero suc rec => snd42 (t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left right case zero suc rec) def left42 : ∀ {Γ A B} , Tm42 Γ A → Tm42 Γ (sum42 A B) := λ t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right case zero suc rec => left42 (t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right case zero suc rec) def right42 : ∀ {Γ A B} , Tm42 Γ B → Tm42 Γ (sum42 A B) := λ t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case zero suc rec => right42 (t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case zero suc rec) def case42 : ∀ {Γ A B C} , Tm42 Γ (sum42 A B) → Tm42 Γ (arr42 A C) → Tm42 Γ (arr42 B C) → Tm42 Γ C := λ t u v Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case42 zero suc rec => case42 (t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case42 zero suc rec) (u Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case42 zero suc rec) (v Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case42 zero suc rec) def zero42 : ∀ {Γ} , Tm42 Γ nat42 := λ Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case42 zero42 suc rec => zero42 def suc42 : ∀ {Γ} , Tm42 Γ nat42 → Tm42 Γ nat42 := λ t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case42 zero42 suc42 rec => suc42 (t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case42 zero42 suc42 rec) def rec42 : ∀ {Γ A} , Tm42 Γ nat42 → Tm42 Γ (arr42 nat42 (arr42 A A)) → Tm42 Γ A → Tm42 Γ A := λ t u v Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case42 zero42 suc42 rec42 => rec42 (t Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case42 zero42 suc42 rec42) (u Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case42 zero42 suc42 rec42) (v Tm42 var42 lam42 app42 tt42 pair42 fst42 snd42 left42 right42 case42 zero42 suc42 rec42) def v042 : ∀ {Γ A}, Tm42 (snoc42 Γ A) A := var42 vz42 def v142 : ∀ {Γ A B}, Tm42 (snoc42 (snoc42 Γ A) B) A := var42 (vs42 vz42) def v242 : ∀ {Γ A B C}, Tm42 (snoc42 (snoc42 (snoc42 Γ A) B) C) A := var42 (vs42 (vs42 vz42)) def v342 : ∀ {Γ A B C D}, Tm42 (snoc42 (snoc42 (snoc42 (snoc42 Γ A) B) C) D) A := var42 (vs42 (vs42 (vs42 vz42))) def tbool42 : Ty42 := sum42 top42 top42 def ttrue42 : ∀ {Γ}, Tm42 Γ tbool42 := left42 tt42 def tfalse42 : ∀ {Γ}, Tm42 Γ tbool42 := right42 tt42 def ifthenelse42 : ∀ {Γ A}, Tm42 Γ (arr42 tbool42 (arr42 A (arr42 A A))) := lam42 (lam42 (lam42 (case42 v242 (lam42 v242) (lam42 v142)))) def times442 : ∀ {Γ A}, Tm42 Γ (arr42 (arr42 A A) (arr42 A A)) := lam42 (lam42 (app42 v142 (app42 v142 (app42 v142 (app42 v142 v042))))) def add42 : ∀ {Γ}, Tm42 Γ (arr42 nat42 (arr42 nat42 nat42)) := lam42 (rec42 v042 (lam42 (lam42 (lam42 (suc42 (app42 v142 v042))))) (lam42 v042)) def mul42 : ∀ {Γ}, Tm42 Γ (arr42 nat42 (arr42 nat42 nat42)) := lam42 (rec42 v042 (lam42 (lam42 (lam42 (app42 (app42 add42 (app42 v142 v042)) v042)))) (lam42 zero42)) def fact42 : ∀ {Γ}, Tm42 Γ (arr42 nat42 nat42) := lam42 (rec42 v042 (lam42 (lam42 (app42 (app42 mul42 (suc42 v142)) v042))) (suc42 zero42)) def Ty43 : Type 1 := ∀ (Ty43 : Type) (nat top bot : Ty43) (arr prod sum : Ty43 → Ty43 → Ty43) , Ty43 def nat43 : Ty43 := λ _ nat43 _ _ _ _ _ => nat43 def top43 : Ty43 := λ _ _ top43 _ _ _ _ => top43 def bot43 : Ty43 := λ _ _ _ bot43 _ _ _ => bot43 def arr43 : Ty43 → Ty43 → Ty43 := λ A B Ty43 nat43 top43 bot43 arr43 prod sum => arr43 (A Ty43 nat43 top43 bot43 arr43 prod sum) (B Ty43 nat43 top43 bot43 arr43 prod sum) def prod43 : Ty43 → Ty43 → Ty43 := λ A B Ty43 nat43 top43 bot43 arr43 prod43 sum => prod43 (A Ty43 nat43 top43 bot43 arr43 prod43 sum) (B Ty43 nat43 top43 bot43 arr43 prod43 sum) def sum43 : Ty43 → Ty43 → Ty43 := λ A B Ty43 nat43 top43 bot43 arr43 prod43 sum43 => sum43 (A Ty43 nat43 top43 bot43 arr43 prod43 sum43) (B Ty43 nat43 top43 bot43 arr43 prod43 sum43) def Con43 : Type 1 := ∀ (Con43 : Type) (nil : Con43) (snoc : Con43 → Ty43 → Con43) , Con43 def nil43 : Con43 := λ Con43 nil43 snoc => nil43 def snoc43 : Con43 → Ty43 → Con43 := λ Γ A Con43 nil43 snoc43 => snoc43 (Γ Con43 nil43 snoc43) A def Var43 : Con43 → Ty43 → Type 1 := λ Γ A => ∀ (Var43 : Con43 → Ty43 → Type) (vz : ∀{Γ A}, Var43 (snoc43 Γ A) A) (vs : ∀{Γ B A}, Var43 Γ A → Var43 (snoc43 Γ B) A) , Var43 Γ A def vz43 : ∀ {Γ A}, Var43 (snoc43 Γ A) A := λ Var43 vz43 vs => vz43 def vs43 : ∀ {Γ B A}, Var43 Γ A → Var43 (snoc43 Γ B) A := λ x Var43 vz43 vs43 => vs43 (x Var43 vz43 vs43) def Tm43 : Con43 → Ty43 → Type 1 := λ Γ A => ∀ (Tm43 : Con43 → Ty43 → Type) (var : ∀ {Γ A}, Var43 Γ A → Tm43 Γ A) (lam : ∀ {Γ A B}, (Tm43 (snoc43 Γ A) B → Tm43 Γ (arr43 A B))) (app : ∀ {Γ A B} , Tm43 Γ (arr43 A B) → Tm43 Γ A → Tm43 Γ B) (tt : ∀ {Γ} , Tm43 Γ top43) (pair : ∀ {Γ A B} , Tm43 Γ A → Tm43 Γ B → Tm43 Γ (prod43 A B)) (fst : ∀ {Γ A B} , Tm43 Γ (prod43 A B) → Tm43 Γ A) (snd : ∀ {Γ A B} , Tm43 Γ (prod43 A B) → Tm43 Γ B) (left : ∀ {Γ A B} , Tm43 Γ A → Tm43 Γ (sum43 A B)) (right : ∀ {Γ A B} , Tm43 Γ B → Tm43 Γ (sum43 A B)) (case : ∀ {Γ A B C} , Tm43 Γ (sum43 A B) → Tm43 Γ (arr43 A C) → Tm43 Γ (arr43 B C) → Tm43 Γ C) (zero : ∀ {Γ} , Tm43 Γ nat43) (suc : ∀ {Γ} , Tm43 Γ nat43 → Tm43 Γ nat43) (rec : ∀ {Γ A} , Tm43 Γ nat43 → Tm43 Γ (arr43 nat43 (arr43 A A)) → Tm43 Γ A → Tm43 Γ A) , Tm43 Γ A def var43 : ∀ {Γ A}, Var43 Γ A → Tm43 Γ A := λ x Tm43 var43 lam app tt pair fst snd left right case zero suc rec => var43 x def lam43 : ∀ {Γ A B} , Tm43 (snoc43 Γ A) B → Tm43 Γ (arr43 A B) := λ t Tm43 var43 lam43 app tt pair fst snd left right case zero suc rec => lam43 (t Tm43 var43 lam43 app tt pair fst snd left right case zero suc rec) def app43 : ∀ {Γ A B} , Tm43 Γ (arr43 A B) → Tm43 Γ A → Tm43 Γ B := λ t u Tm43 var43 lam43 app43 tt pair fst snd left right case zero suc rec => app43 (t Tm43 var43 lam43 app43 tt pair fst snd left right case zero suc rec) (u Tm43 var43 lam43 app43 tt pair fst snd left right case zero suc rec) def tt43 : ∀ {Γ} , Tm43 Γ top43 := λ Tm43 var43 lam43 app43 tt43 pair fst snd left right case zero suc rec => tt43 def pair43 : ∀ {Γ A B} , Tm43 Γ A → Tm43 Γ B → Tm43 Γ (prod43 A B) := λ t u Tm43 var43 lam43 app43 tt43 pair43 fst snd left right case zero suc rec => pair43 (t Tm43 var43 lam43 app43 tt43 pair43 fst snd left right case zero suc rec) (u Tm43 var43 lam43 app43 tt43 pair43 fst snd left right case zero suc rec) def fst43 : ∀ {Γ A B} , Tm43 Γ (prod43 A B) → Tm43 Γ A := λ t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd left right case zero suc rec => fst43 (t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd left right case zero suc rec) def snd43 : ∀ {Γ A B} , Tm43 Γ (prod43 A B) → Tm43 Γ B := λ t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left right case zero suc rec => snd43 (t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left right case zero suc rec) def left43 : ∀ {Γ A B} , Tm43 Γ A → Tm43 Γ (sum43 A B) := λ t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right case zero suc rec => left43 (t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right case zero suc rec) def right43 : ∀ {Γ A B} , Tm43 Γ B → Tm43 Γ (sum43 A B) := λ t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case zero suc rec => right43 (t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case zero suc rec) def case43 : ∀ {Γ A B C} , Tm43 Γ (sum43 A B) → Tm43 Γ (arr43 A C) → Tm43 Γ (arr43 B C) → Tm43 Γ C := λ t u v Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case43 zero suc rec => case43 (t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case43 zero suc rec) (u Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case43 zero suc rec) (v Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case43 zero suc rec) def zero43 : ∀ {Γ} , Tm43 Γ nat43 := λ Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case43 zero43 suc rec => zero43 def suc43 : ∀ {Γ} , Tm43 Γ nat43 → Tm43 Γ nat43 := λ t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case43 zero43 suc43 rec => suc43 (t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case43 zero43 suc43 rec) def rec43 : ∀ {Γ A} , Tm43 Γ nat43 → Tm43 Γ (arr43 nat43 (arr43 A A)) → Tm43 Γ A → Tm43 Γ A := λ t u v Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case43 zero43 suc43 rec43 => rec43 (t Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case43 zero43 suc43 rec43) (u Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case43 zero43 suc43 rec43) (v Tm43 var43 lam43 app43 tt43 pair43 fst43 snd43 left43 right43 case43 zero43 suc43 rec43) def v043 : ∀ {Γ A}, Tm43 (snoc43 Γ A) A := var43 vz43 def v143 : ∀ {Γ A B}, Tm43 (snoc43 (snoc43 Γ A) B) A := var43 (vs43 vz43) def v243 : ∀ {Γ A B C}, Tm43 (snoc43 (snoc43 (snoc43 Γ A) B) C) A := var43 (vs43 (vs43 vz43)) def v343 : ∀ {Γ A B C D}, Tm43 (snoc43 (snoc43 (snoc43 (snoc43 Γ A) B) C) D) A := var43 (vs43 (vs43 (vs43 vz43))) def tbool43 : Ty43 := sum43 top43 top43 def ttrue43 : ∀ {Γ}, Tm43 Γ tbool43 := left43 tt43 def tfalse43 : ∀ {Γ}, Tm43 Γ tbool43 := right43 tt43 def ifthenelse43 : ∀ {Γ A}, Tm43 Γ (arr43 tbool43 (arr43 A (arr43 A A))) := lam43 (lam43 (lam43 (case43 v243 (lam43 v243) (lam43 v143)))) def times443 : ∀ {Γ A}, Tm43 Γ (arr43 (arr43 A A) (arr43 A A)) := lam43 (lam43 (app43 v143 (app43 v143 (app43 v143 (app43 v143 v043))))) def add43 : ∀ {Γ}, Tm43 Γ (arr43 nat43 (arr43 nat43 nat43)) := lam43 (rec43 v043 (lam43 (lam43 (lam43 (suc43 (app43 v143 v043))))) (lam43 v043)) def mul43 : ∀ {Γ}, Tm43 Γ (arr43 nat43 (arr43 nat43 nat43)) := lam43 (rec43 v043 (lam43 (lam43 (lam43 (app43 (app43 add43 (app43 v143 v043)) v043)))) (lam43 zero43)) def fact43 : ∀ {Γ}, Tm43 Γ (arr43 nat43 nat43) := lam43 (rec43 v043 (lam43 (lam43 (app43 (app43 mul43 (suc43 v143)) v043))) (suc43 zero43)) def Ty44 : Type 1 := ∀ (Ty44 : Type) (nat top bot : Ty44) (arr prod sum : Ty44 → Ty44 → Ty44) , Ty44 def nat44 : Ty44 := λ _ nat44 _ _ _ _ _ => nat44 def top44 : Ty44 := λ _ _ top44 _ _ _ _ => top44 def bot44 : Ty44 := λ _ _ _ bot44 _ _ _ => bot44 def arr44 : Ty44 → Ty44 → Ty44 := λ A B Ty44 nat44 top44 bot44 arr44 prod sum => arr44 (A Ty44 nat44 top44 bot44 arr44 prod sum) (B Ty44 nat44 top44 bot44 arr44 prod sum) def prod44 : Ty44 → Ty44 → Ty44 := λ A B Ty44 nat44 top44 bot44 arr44 prod44 sum => prod44 (A Ty44 nat44 top44 bot44 arr44 prod44 sum) (B Ty44 nat44 top44 bot44 arr44 prod44 sum) def sum44 : Ty44 → Ty44 → Ty44 := λ A B Ty44 nat44 top44 bot44 arr44 prod44 sum44 => sum44 (A Ty44 nat44 top44 bot44 arr44 prod44 sum44) (B Ty44 nat44 top44 bot44 arr44 prod44 sum44) def Con44 : Type 1 := ∀ (Con44 : Type) (nil : Con44) (snoc : Con44 → Ty44 → Con44) , Con44 def nil44 : Con44 := λ Con44 nil44 snoc => nil44 def snoc44 : Con44 → Ty44 → Con44 := λ Γ A Con44 nil44 snoc44 => snoc44 (Γ Con44 nil44 snoc44) A def Var44 : Con44 → Ty44 → Type 1 := λ Γ A => ∀ (Var44 : Con44 → Ty44 → Type) (vz : ∀{Γ A}, Var44 (snoc44 Γ A) A) (vs : ∀{Γ B A}, Var44 Γ A → Var44 (snoc44 Γ B) A) , Var44 Γ A def vz44 : ∀ {Γ A}, Var44 (snoc44 Γ A) A := λ Var44 vz44 vs => vz44 def vs44 : ∀ {Γ B A}, Var44 Γ A → Var44 (snoc44 Γ B) A := λ x Var44 vz44 vs44 => vs44 (x Var44 vz44 vs44) def Tm44 : Con44 → Ty44 → Type 1 := λ Γ A => ∀ (Tm44 : Con44 → Ty44 → Type) (var : ∀ {Γ A}, Var44 Γ A → Tm44 Γ A) (lam : ∀ {Γ A B}, (Tm44 (snoc44 Γ A) B → Tm44 Γ (arr44 A B))) (app : ∀ {Γ A B} , Tm44 Γ (arr44 A B) → Tm44 Γ A → Tm44 Γ B) (tt : ∀ {Γ} , Tm44 Γ top44) (pair : ∀ {Γ A B} , Tm44 Γ A → Tm44 Γ B → Tm44 Γ (prod44 A B)) (fst : ∀ {Γ A B} , Tm44 Γ (prod44 A B) → Tm44 Γ A) (snd : ∀ {Γ A B} , Tm44 Γ (prod44 A B) → Tm44 Γ B) (left : ∀ {Γ A B} , Tm44 Γ A → Tm44 Γ (sum44 A B)) (right : ∀ {Γ A B} , Tm44 Γ B → Tm44 Γ (sum44 A B)) (case : ∀ {Γ A B C} , Tm44 Γ (sum44 A B) → Tm44 Γ (arr44 A C) → Tm44 Γ (arr44 B C) → Tm44 Γ C) (zero : ∀ {Γ} , Tm44 Γ nat44) (suc : ∀ {Γ} , Tm44 Γ nat44 → Tm44 Γ nat44) (rec : ∀ {Γ A} , Tm44 Γ nat44 → Tm44 Γ (arr44 nat44 (arr44 A A)) → Tm44 Γ A → Tm44 Γ A) , Tm44 Γ A def var44 : ∀ {Γ A}, Var44 Γ A → Tm44 Γ A := λ x Tm44 var44 lam app tt pair fst snd left right case zero suc rec => var44 x def lam44 : ∀ {Γ A B} , Tm44 (snoc44 Γ A) B → Tm44 Γ (arr44 A B) := λ t Tm44 var44 lam44 app tt pair fst snd left right case zero suc rec => lam44 (t Tm44 var44 lam44 app tt pair fst snd left right case zero suc rec) def app44 : ∀ {Γ A B} , Tm44 Γ (arr44 A B) → Tm44 Γ A → Tm44 Γ B := λ t u Tm44 var44 lam44 app44 tt pair fst snd left right case zero suc rec => app44 (t Tm44 var44 lam44 app44 tt pair fst snd left right case zero suc rec) (u Tm44 var44 lam44 app44 tt pair fst snd left right case zero suc rec) def tt44 : ∀ {Γ} , Tm44 Γ top44 := λ Tm44 var44 lam44 app44 tt44 pair fst snd left right case zero suc rec => tt44 def pair44 : ∀ {Γ A B} , Tm44 Γ A → Tm44 Γ B → Tm44 Γ (prod44 A B) := λ t u Tm44 var44 lam44 app44 tt44 pair44 fst snd left right case zero suc rec => pair44 (t Tm44 var44 lam44 app44 tt44 pair44 fst snd left right case zero suc rec) (u Tm44 var44 lam44 app44 tt44 pair44 fst snd left right case zero suc rec) def fst44 : ∀ {Γ A B} , Tm44 Γ (prod44 A B) → Tm44 Γ A := λ t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd left right case zero suc rec => fst44 (t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd left right case zero suc rec) def snd44 : ∀ {Γ A B} , Tm44 Γ (prod44 A B) → Tm44 Γ B := λ t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left right case zero suc rec => snd44 (t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left right case zero suc rec) def left44 : ∀ {Γ A B} , Tm44 Γ A → Tm44 Γ (sum44 A B) := λ t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right case zero suc rec => left44 (t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right case zero suc rec) def right44 : ∀ {Γ A B} , Tm44 Γ B → Tm44 Γ (sum44 A B) := λ t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case zero suc rec => right44 (t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case zero suc rec) def case44 : ∀ {Γ A B C} , Tm44 Γ (sum44 A B) → Tm44 Γ (arr44 A C) → Tm44 Γ (arr44 B C) → Tm44 Γ C := λ t u v Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case44 zero suc rec => case44 (t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case44 zero suc rec) (u Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case44 zero suc rec) (v Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case44 zero suc rec) def zero44 : ∀ {Γ} , Tm44 Γ nat44 := λ Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case44 zero44 suc rec => zero44 def suc44 : ∀ {Γ} , Tm44 Γ nat44 → Tm44 Γ nat44 := λ t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case44 zero44 suc44 rec => suc44 (t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case44 zero44 suc44 rec) def rec44 : ∀ {Γ A} , Tm44 Γ nat44 → Tm44 Γ (arr44 nat44 (arr44 A A)) → Tm44 Γ A → Tm44 Γ A := λ t u v Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case44 zero44 suc44 rec44 => rec44 (t Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case44 zero44 suc44 rec44) (u Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case44 zero44 suc44 rec44) (v Tm44 var44 lam44 app44 tt44 pair44 fst44 snd44 left44 right44 case44 zero44 suc44 rec44) def v044 : ∀ {Γ A}, Tm44 (snoc44 Γ A) A := var44 vz44 def v144 : ∀ {Γ A B}, Tm44 (snoc44 (snoc44 Γ A) B) A := var44 (vs44 vz44) def v244 : ∀ {Γ A B C}, Tm44 (snoc44 (snoc44 (snoc44 Γ A) B) C) A := var44 (vs44 (vs44 vz44)) def v344 : ∀ {Γ A B C D}, Tm44 (snoc44 (snoc44 (snoc44 (snoc44 Γ A) B) C) D) A := var44 (vs44 (vs44 (vs44 vz44))) def tbool44 : Ty44 := sum44 top44 top44 def ttrue44 : ∀ {Γ}, Tm44 Γ tbool44 := left44 tt44 def tfalse44 : ∀ {Γ}, Tm44 Γ tbool44 := right44 tt44 def ifthenelse44 : ∀ {Γ A}, Tm44 Γ (arr44 tbool44 (arr44 A (arr44 A A))) := lam44 (lam44 (lam44 (case44 v244 (lam44 v244) (lam44 v144)))) def times444 : ∀ {Γ A}, Tm44 Γ (arr44 (arr44 A A) (arr44 A A)) := lam44 (lam44 (app44 v144 (app44 v144 (app44 v144 (app44 v144 v044))))) def add44 : ∀ {Γ}, Tm44 Γ (arr44 nat44 (arr44 nat44 nat44)) := lam44 (rec44 v044 (lam44 (lam44 (lam44 (suc44 (app44 v144 v044))))) (lam44 v044)) def mul44 : ∀ {Γ}, Tm44 Γ (arr44 nat44 (arr44 nat44 nat44)) := lam44 (rec44 v044 (lam44 (lam44 (lam44 (app44 (app44 add44 (app44 v144 v044)) v044)))) (lam44 zero44)) def fact44 : ∀ {Γ}, Tm44 Γ (arr44 nat44 nat44) := lam44 (rec44 v044 (lam44 (lam44 (app44 (app44 mul44 (suc44 v144)) v044))) (suc44 zero44)) def Ty45 : Type 1 := ∀ (Ty45 : Type) (nat top bot : Ty45) (arr prod sum : Ty45 → Ty45 → Ty45) , Ty45 def nat45 : Ty45 := λ _ nat45 _ _ _ _ _ => nat45 def top45 : Ty45 := λ _ _ top45 _ _ _ _ => top45 def bot45 : Ty45 := λ _ _ _ bot45 _ _ _ => bot45 def arr45 : Ty45 → Ty45 → Ty45 := λ A B Ty45 nat45 top45 bot45 arr45 prod sum => arr45 (A Ty45 nat45 top45 bot45 arr45 prod sum) (B Ty45 nat45 top45 bot45 arr45 prod sum) def prod45 : Ty45 → Ty45 → Ty45 := λ A B Ty45 nat45 top45 bot45 arr45 prod45 sum => prod45 (A Ty45 nat45 top45 bot45 arr45 prod45 sum) (B Ty45 nat45 top45 bot45 arr45 prod45 sum) def sum45 : Ty45 → Ty45 → Ty45 := λ A B Ty45 nat45 top45 bot45 arr45 prod45 sum45 => sum45 (A Ty45 nat45 top45 bot45 arr45 prod45 sum45) (B Ty45 nat45 top45 bot45 arr45 prod45 sum45) def Con45 : Type 1 := ∀ (Con45 : Type) (nil : Con45) (snoc : Con45 → Ty45 → Con45) , Con45 def nil45 : Con45 := λ Con45 nil45 snoc => nil45 def snoc45 : Con45 → Ty45 → Con45 := λ Γ A Con45 nil45 snoc45 => snoc45 (Γ Con45 nil45 snoc45) A def Var45 : Con45 → Ty45 → Type 1 := λ Γ A => ∀ (Var45 : Con45 → Ty45 → Type) (vz : ∀{Γ A}, Var45 (snoc45 Γ A) A) (vs : ∀{Γ B A}, Var45 Γ A → Var45 (snoc45 Γ B) A) , Var45 Γ A def vz45 : ∀ {Γ A}, Var45 (snoc45 Γ A) A := λ Var45 vz45 vs => vz45 def vs45 : ∀ {Γ B A}, Var45 Γ A → Var45 (snoc45 Γ B) A := λ x Var45 vz45 vs45 => vs45 (x Var45 vz45 vs45) def Tm45 : Con45 → Ty45 → Type 1 := λ Γ A => ∀ (Tm45 : Con45 → Ty45 → Type) (var : ∀ {Γ A}, Var45 Γ A → Tm45 Γ A) (lam : ∀ {Γ A B}, (Tm45 (snoc45 Γ A) B → Tm45 Γ (arr45 A B))) (app : ∀ {Γ A B} , Tm45 Γ (arr45 A B) → Tm45 Γ A → Tm45 Γ B) (tt : ∀ {Γ} , Tm45 Γ top45) (pair : ∀ {Γ A B} , Tm45 Γ A → Tm45 Γ B → Tm45 Γ (prod45 A B)) (fst : ∀ {Γ A B} , Tm45 Γ (prod45 A B) → Tm45 Γ A) (snd : ∀ {Γ A B} , Tm45 Γ (prod45 A B) → Tm45 Γ B) (left : ∀ {Γ A B} , Tm45 Γ A → Tm45 Γ (sum45 A B)) (right : ∀ {Γ A B} , Tm45 Γ B → Tm45 Γ (sum45 A B)) (case : ∀ {Γ A B C} , Tm45 Γ (sum45 A B) → Tm45 Γ (arr45 A C) → Tm45 Γ (arr45 B C) → Tm45 Γ C) (zero : ∀ {Γ} , Tm45 Γ nat45) (suc : ∀ {Γ} , Tm45 Γ nat45 → Tm45 Γ nat45) (rec : ∀ {Γ A} , Tm45 Γ nat45 → Tm45 Γ (arr45 nat45 (arr45 A A)) → Tm45 Γ A → Tm45 Γ A) , Tm45 Γ A def var45 : ∀ {Γ A}, Var45 Γ A → Tm45 Γ A := λ x Tm45 var45 lam app tt pair fst snd left right case zero suc rec => var45 x def lam45 : ∀ {Γ A B} , Tm45 (snoc45 Γ A) B → Tm45 Γ (arr45 A B) := λ t Tm45 var45 lam45 app tt pair fst snd left right case zero suc rec => lam45 (t Tm45 var45 lam45 app tt pair fst snd left right case zero suc rec) def app45 : ∀ {Γ A B} , Tm45 Γ (arr45 A B) → Tm45 Γ A → Tm45 Γ B := λ t u Tm45 var45 lam45 app45 tt pair fst snd left right case zero suc rec => app45 (t Tm45 var45 lam45 app45 tt pair fst snd left right case zero suc rec) (u Tm45 var45 lam45 app45 tt pair fst snd left right case zero suc rec) def tt45 : ∀ {Γ} , Tm45 Γ top45 := λ Tm45 var45 lam45 app45 tt45 pair fst snd left right case zero suc rec => tt45 def pair45 : ∀ {Γ A B} , Tm45 Γ A → Tm45 Γ B → Tm45 Γ (prod45 A B) := λ t u Tm45 var45 lam45 app45 tt45 pair45 fst snd left right case zero suc rec => pair45 (t Tm45 var45 lam45 app45 tt45 pair45 fst snd left right case zero suc rec) (u Tm45 var45 lam45 app45 tt45 pair45 fst snd left right case zero suc rec) def fst45 : ∀ {Γ A B} , Tm45 Γ (prod45 A B) → Tm45 Γ A := λ t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd left right case zero suc rec => fst45 (t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd left right case zero suc rec) def snd45 : ∀ {Γ A B} , Tm45 Γ (prod45 A B) → Tm45 Γ B := λ t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left right case zero suc rec => snd45 (t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left right case zero suc rec) def left45 : ∀ {Γ A B} , Tm45 Γ A → Tm45 Γ (sum45 A B) := λ t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right case zero suc rec => left45 (t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right case zero suc rec) def right45 : ∀ {Γ A B} , Tm45 Γ B → Tm45 Γ (sum45 A B) := λ t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case zero suc rec => right45 (t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case zero suc rec) def case45 : ∀ {Γ A B C} , Tm45 Γ (sum45 A B) → Tm45 Γ (arr45 A C) → Tm45 Γ (arr45 B C) → Tm45 Γ C := λ t u v Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case45 zero suc rec => case45 (t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case45 zero suc rec) (u Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case45 zero suc rec) (v Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case45 zero suc rec) def zero45 : ∀ {Γ} , Tm45 Γ nat45 := λ Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case45 zero45 suc rec => zero45 def suc45 : ∀ {Γ} , Tm45 Γ nat45 → Tm45 Γ nat45 := λ t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case45 zero45 suc45 rec => suc45 (t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case45 zero45 suc45 rec) def rec45 : ∀ {Γ A} , Tm45 Γ nat45 → Tm45 Γ (arr45 nat45 (arr45 A A)) → Tm45 Γ A → Tm45 Γ A := λ t u v Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case45 zero45 suc45 rec45 => rec45 (t Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case45 zero45 suc45 rec45) (u Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case45 zero45 suc45 rec45) (v Tm45 var45 lam45 app45 tt45 pair45 fst45 snd45 left45 right45 case45 zero45 suc45 rec45) def v045 : ∀ {Γ A}, Tm45 (snoc45 Γ A) A := var45 vz45 def v145 : ∀ {Γ A B}, Tm45 (snoc45 (snoc45 Γ A) B) A := var45 (vs45 vz45) def v245 : ∀ {Γ A B C}, Tm45 (snoc45 (snoc45 (snoc45 Γ A) B) C) A := var45 (vs45 (vs45 vz45)) def v345 : ∀ {Γ A B C D}, Tm45 (snoc45 (snoc45 (snoc45 (snoc45 Γ A) B) C) D) A := var45 (vs45 (vs45 (vs45 vz45))) def tbool45 : Ty45 := sum45 top45 top45 def ttrue45 : ∀ {Γ}, Tm45 Γ tbool45 := left45 tt45 def tfalse45 : ∀ {Γ}, Tm45 Γ tbool45 := right45 tt45 def ifthenelse45 : ∀ {Γ A}, Tm45 Γ (arr45 tbool45 (arr45 A (arr45 A A))) := lam45 (lam45 (lam45 (case45 v245 (lam45 v245) (lam45 v145)))) def times445 : ∀ {Γ A}, Tm45 Γ (arr45 (arr45 A A) (arr45 A A)) := lam45 (lam45 (app45 v145 (app45 v145 (app45 v145 (app45 v145 v045))))) def add45 : ∀ {Γ}, Tm45 Γ (arr45 nat45 (arr45 nat45 nat45)) := lam45 (rec45 v045 (lam45 (lam45 (lam45 (suc45 (app45 v145 v045))))) (lam45 v045)) def mul45 : ∀ {Γ}, Tm45 Γ (arr45 nat45 (arr45 nat45 nat45)) := lam45 (rec45 v045 (lam45 (lam45 (lam45 (app45 (app45 add45 (app45 v145 v045)) v045)))) (lam45 zero45)) def fact45 : ∀ {Γ}, Tm45 Γ (arr45 nat45 nat45) := lam45 (rec45 v045 (lam45 (lam45 (app45 (app45 mul45 (suc45 v145)) v045))) (suc45 zero45)) def Ty46 : Type 1 := ∀ (Ty46 : Type) (nat top bot : Ty46) (arr prod sum : Ty46 → Ty46 → Ty46) , Ty46 def nat46 : Ty46 := λ _ nat46 _ _ _ _ _ => nat46 def top46 : Ty46 := λ _ _ top46 _ _ _ _ => top46 def bot46 : Ty46 := λ _ _ _ bot46 _ _ _ => bot46 def arr46 : Ty46 → Ty46 → Ty46 := λ A B Ty46 nat46 top46 bot46 arr46 prod sum => arr46 (A Ty46 nat46 top46 bot46 arr46 prod sum) (B Ty46 nat46 top46 bot46 arr46 prod sum) def prod46 : Ty46 → Ty46 → Ty46 := λ A B Ty46 nat46 top46 bot46 arr46 prod46 sum => prod46 (A Ty46 nat46 top46 bot46 arr46 prod46 sum) (B Ty46 nat46 top46 bot46 arr46 prod46 sum) def sum46 : Ty46 → Ty46 → Ty46 := λ A B Ty46 nat46 top46 bot46 arr46 prod46 sum46 => sum46 (A Ty46 nat46 top46 bot46 arr46 prod46 sum46) (B Ty46 nat46 top46 bot46 arr46 prod46 sum46) def Con46 : Type 1 := ∀ (Con46 : Type) (nil : Con46) (snoc : Con46 → Ty46 → Con46) , Con46 def nil46 : Con46 := λ Con46 nil46 snoc => nil46 def snoc46 : Con46 → Ty46 → Con46 := λ Γ A Con46 nil46 snoc46 => snoc46 (Γ Con46 nil46 snoc46) A def Var46 : Con46 → Ty46 → Type 1 := λ Γ A => ∀ (Var46 : Con46 → Ty46 → Type) (vz : ∀{Γ A}, Var46 (snoc46 Γ A) A) (vs : ∀{Γ B A}, Var46 Γ A → Var46 (snoc46 Γ B) A) , Var46 Γ A def vz46 : ∀ {Γ A}, Var46 (snoc46 Γ A) A := λ Var46 vz46 vs => vz46 def vs46 : ∀ {Γ B A}, Var46 Γ A → Var46 (snoc46 Γ B) A := λ x Var46 vz46 vs46 => vs46 (x Var46 vz46 vs46) def Tm46 : Con46 → Ty46 → Type 1 := λ Γ A => ∀ (Tm46 : Con46 → Ty46 → Type) (var : ∀ {Γ A}, Var46 Γ A → Tm46 Γ A) (lam : ∀ {Γ A B}, (Tm46 (snoc46 Γ A) B → Tm46 Γ (arr46 A B))) (app : ∀ {Γ A B} , Tm46 Γ (arr46 A B) → Tm46 Γ A → Tm46 Γ B) (tt : ∀ {Γ} , Tm46 Γ top46) (pair : ∀ {Γ A B} , Tm46 Γ A → Tm46 Γ B → Tm46 Γ (prod46 A B)) (fst : ∀ {Γ A B} , Tm46 Γ (prod46 A B) → Tm46 Γ A) (snd : ∀ {Γ A B} , Tm46 Γ (prod46 A B) → Tm46 Γ B) (left : ∀ {Γ A B} , Tm46 Γ A → Tm46 Γ (sum46 A B)) (right : ∀ {Γ A B} , Tm46 Γ B → Tm46 Γ (sum46 A B)) (case : ∀ {Γ A B C} , Tm46 Γ (sum46 A B) → Tm46 Γ (arr46 A C) → Tm46 Γ (arr46 B C) → Tm46 Γ C) (zero : ∀ {Γ} , Tm46 Γ nat46) (suc : ∀ {Γ} , Tm46 Γ nat46 → Tm46 Γ nat46) (rec : ∀ {Γ A} , Tm46 Γ nat46 → Tm46 Γ (arr46 nat46 (arr46 A A)) → Tm46 Γ A → Tm46 Γ A) , Tm46 Γ A def var46 : ∀ {Γ A}, Var46 Γ A → Tm46 Γ A := λ x Tm46 var46 lam app tt pair fst snd left right case zero suc rec => var46 x def lam46 : ∀ {Γ A B} , Tm46 (snoc46 Γ A) B → Tm46 Γ (arr46 A B) := λ t Tm46 var46 lam46 app tt pair fst snd left right case zero suc rec => lam46 (t Tm46 var46 lam46 app tt pair fst snd left right case zero suc rec) def app46 : ∀ {Γ A B} , Tm46 Γ (arr46 A B) → Tm46 Γ A → Tm46 Γ B := λ t u Tm46 var46 lam46 app46 tt pair fst snd left right case zero suc rec => app46 (t Tm46 var46 lam46 app46 tt pair fst snd left right case zero suc rec) (u Tm46 var46 lam46 app46 tt pair fst snd left right case zero suc rec) def tt46 : ∀ {Γ} , Tm46 Γ top46 := λ Tm46 var46 lam46 app46 tt46 pair fst snd left right case zero suc rec => tt46 def pair46 : ∀ {Γ A B} , Tm46 Γ A → Tm46 Γ B → Tm46 Γ (prod46 A B) := λ t u Tm46 var46 lam46 app46 tt46 pair46 fst snd left right case zero suc rec => pair46 (t Tm46 var46 lam46 app46 tt46 pair46 fst snd left right case zero suc rec) (u Tm46 var46 lam46 app46 tt46 pair46 fst snd left right case zero suc rec) def fst46 : ∀ {Γ A B} , Tm46 Γ (prod46 A B) → Tm46 Γ A := λ t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd left right case zero suc rec => fst46 (t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd left right case zero suc rec) def snd46 : ∀ {Γ A B} , Tm46 Γ (prod46 A B) → Tm46 Γ B := λ t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left right case zero suc rec => snd46 (t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left right case zero suc rec) def left46 : ∀ {Γ A B} , Tm46 Γ A → Tm46 Γ (sum46 A B) := λ t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right case zero suc rec => left46 (t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right case zero suc rec) def right46 : ∀ {Γ A B} , Tm46 Γ B → Tm46 Γ (sum46 A B) := λ t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case zero suc rec => right46 (t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case zero suc rec) def case46 : ∀ {Γ A B C} , Tm46 Γ (sum46 A B) → Tm46 Γ (arr46 A C) → Tm46 Γ (arr46 B C) → Tm46 Γ C := λ t u v Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case46 zero suc rec => case46 (t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case46 zero suc rec) (u Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case46 zero suc rec) (v Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case46 zero suc rec) def zero46 : ∀ {Γ} , Tm46 Γ nat46 := λ Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case46 zero46 suc rec => zero46 def suc46 : ∀ {Γ} , Tm46 Γ nat46 → Tm46 Γ nat46 := λ t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case46 zero46 suc46 rec => suc46 (t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case46 zero46 suc46 rec) def rec46 : ∀ {Γ A} , Tm46 Γ nat46 → Tm46 Γ (arr46 nat46 (arr46 A A)) → Tm46 Γ A → Tm46 Γ A := λ t u v Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case46 zero46 suc46 rec46 => rec46 (t Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case46 zero46 suc46 rec46) (u Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case46 zero46 suc46 rec46) (v Tm46 var46 lam46 app46 tt46 pair46 fst46 snd46 left46 right46 case46 zero46 suc46 rec46) def v046 : ∀ {Γ A}, Tm46 (snoc46 Γ A) A := var46 vz46 def v146 : ∀ {Γ A B}, Tm46 (snoc46 (snoc46 Γ A) B) A := var46 (vs46 vz46) def v246 : ∀ {Γ A B C}, Tm46 (snoc46 (snoc46 (snoc46 Γ A) B) C) A := var46 (vs46 (vs46 vz46)) def v346 : ∀ {Γ A B C D}, Tm46 (snoc46 (snoc46 (snoc46 (snoc46 Γ A) B) C) D) A := var46 (vs46 (vs46 (vs46 vz46))) def tbool46 : Ty46 := sum46 top46 top46 def ttrue46 : ∀ {Γ}, Tm46 Γ tbool46 := left46 tt46 def tfalse46 : ∀ {Γ}, Tm46 Γ tbool46 := right46 tt46 def ifthenelse46 : ∀ {Γ A}, Tm46 Γ (arr46 tbool46 (arr46 A (arr46 A A))) := lam46 (lam46 (lam46 (case46 v246 (lam46 v246) (lam46 v146)))) def times446 : ∀ {Γ A}, Tm46 Γ (arr46 (arr46 A A) (arr46 A A)) := lam46 (lam46 (app46 v146 (app46 v146 (app46 v146 (app46 v146 v046))))) def add46 : ∀ {Γ}, Tm46 Γ (arr46 nat46 (arr46 nat46 nat46)) := lam46 (rec46 v046 (lam46 (lam46 (lam46 (suc46 (app46 v146 v046))))) (lam46 v046)) def mul46 : ∀ {Γ}, Tm46 Γ (arr46 nat46 (arr46 nat46 nat46)) := lam46 (rec46 v046 (lam46 (lam46 (lam46 (app46 (app46 add46 (app46 v146 v046)) v046)))) (lam46 zero46)) def fact46 : ∀ {Γ}, Tm46 Γ (arr46 nat46 nat46) := lam46 (rec46 v046 (lam46 (lam46 (app46 (app46 mul46 (suc46 v146)) v046))) (suc46 zero46)) def Ty47 : Type 1 := ∀ (Ty47 : Type) (nat top bot : Ty47) (arr prod sum : Ty47 → Ty47 → Ty47) , Ty47 def nat47 : Ty47 := λ _ nat47 _ _ _ _ _ => nat47 def top47 : Ty47 := λ _ _ top47 _ _ _ _ => top47 def bot47 : Ty47 := λ _ _ _ bot47 _ _ _ => bot47 def arr47 : Ty47 → Ty47 → Ty47 := λ A B Ty47 nat47 top47 bot47 arr47 prod sum => arr47 (A Ty47 nat47 top47 bot47 arr47 prod sum) (B Ty47 nat47 top47 bot47 arr47 prod sum) def prod47 : Ty47 → Ty47 → Ty47 := λ A B Ty47 nat47 top47 bot47 arr47 prod47 sum => prod47 (A Ty47 nat47 top47 bot47 arr47 prod47 sum) (B Ty47 nat47 top47 bot47 arr47 prod47 sum) def sum47 : Ty47 → Ty47 → Ty47 := λ A B Ty47 nat47 top47 bot47 arr47 prod47 sum47 => sum47 (A Ty47 nat47 top47 bot47 arr47 prod47 sum47) (B Ty47 nat47 top47 bot47 arr47 prod47 sum47) def Con47 : Type 1 := ∀ (Con47 : Type) (nil : Con47) (snoc : Con47 → Ty47 → Con47) , Con47 def nil47 : Con47 := λ Con47 nil47 snoc => nil47 def snoc47 : Con47 → Ty47 → Con47 := λ Γ A Con47 nil47 snoc47 => snoc47 (Γ Con47 nil47 snoc47) A def Var47 : Con47 → Ty47 → Type 1 := λ Γ A => ∀ (Var47 : Con47 → Ty47 → Type) (vz : ∀{Γ A}, Var47 (snoc47 Γ A) A) (vs : ∀{Γ B A}, Var47 Γ A → Var47 (snoc47 Γ B) A) , Var47 Γ A def vz47 : ∀ {Γ A}, Var47 (snoc47 Γ A) A := λ Var47 vz47 vs => vz47 def vs47 : ∀ {Γ B A}, Var47 Γ A → Var47 (snoc47 Γ B) A := λ x Var47 vz47 vs47 => vs47 (x Var47 vz47 vs47) def Tm47 : Con47 → Ty47 → Type 1 := λ Γ A => ∀ (Tm47 : Con47 → Ty47 → Type) (var : ∀ {Γ A}, Var47 Γ A → Tm47 Γ A) (lam : ∀ {Γ A B}, (Tm47 (snoc47 Γ A) B → Tm47 Γ (arr47 A B))) (app : ∀ {Γ A B} , Tm47 Γ (arr47 A B) → Tm47 Γ A → Tm47 Γ B) (tt : ∀ {Γ} , Tm47 Γ top47) (pair : ∀ {Γ A B} , Tm47 Γ A → Tm47 Γ B → Tm47 Γ (prod47 A B)) (fst : ∀ {Γ A B} , Tm47 Γ (prod47 A B) → Tm47 Γ A) (snd : ∀ {Γ A B} , Tm47 Γ (prod47 A B) → Tm47 Γ B) (left : ∀ {Γ A B} , Tm47 Γ A → Tm47 Γ (sum47 A B)) (right : ∀ {Γ A B} , Tm47 Γ B → Tm47 Γ (sum47 A B)) (case : ∀ {Γ A B C} , Tm47 Γ (sum47 A B) → Tm47 Γ (arr47 A C) → Tm47 Γ (arr47 B C) → Tm47 Γ C) (zero : ∀ {Γ} , Tm47 Γ nat47) (suc : ∀ {Γ} , Tm47 Γ nat47 → Tm47 Γ nat47) (rec : ∀ {Γ A} , Tm47 Γ nat47 → Tm47 Γ (arr47 nat47 (arr47 A A)) → Tm47 Γ A → Tm47 Γ A) , Tm47 Γ A def var47 : ∀ {Γ A}, Var47 Γ A → Tm47 Γ A := λ x Tm47 var47 lam app tt pair fst snd left right case zero suc rec => var47 x def lam47 : ∀ {Γ A B} , Tm47 (snoc47 Γ A) B → Tm47 Γ (arr47 A B) := λ t Tm47 var47 lam47 app tt pair fst snd left right case zero suc rec => lam47 (t Tm47 var47 lam47 app tt pair fst snd left right case zero suc rec) def app47 : ∀ {Γ A B} , Tm47 Γ (arr47 A B) → Tm47 Γ A → Tm47 Γ B := λ t u Tm47 var47 lam47 app47 tt pair fst snd left right case zero suc rec => app47 (t Tm47 var47 lam47 app47 tt pair fst snd left right case zero suc rec) (u Tm47 var47 lam47 app47 tt pair fst snd left right case zero suc rec) def tt47 : ∀ {Γ} , Tm47 Γ top47 := λ Tm47 var47 lam47 app47 tt47 pair fst snd left right case zero suc rec => tt47 def pair47 : ∀ {Γ A B} , Tm47 Γ A → Tm47 Γ B → Tm47 Γ (prod47 A B) := λ t u Tm47 var47 lam47 app47 tt47 pair47 fst snd left right case zero suc rec => pair47 (t Tm47 var47 lam47 app47 tt47 pair47 fst snd left right case zero suc rec) (u Tm47 var47 lam47 app47 tt47 pair47 fst snd left right case zero suc rec) def fst47 : ∀ {Γ A B} , Tm47 Γ (prod47 A B) → Tm47 Γ A := λ t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd left right case zero suc rec => fst47 (t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd left right case zero suc rec) def snd47 : ∀ {Γ A B} , Tm47 Γ (prod47 A B) → Tm47 Γ B := λ t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left right case zero suc rec => snd47 (t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left right case zero suc rec) def left47 : ∀ {Γ A B} , Tm47 Γ A → Tm47 Γ (sum47 A B) := λ t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right case zero suc rec => left47 (t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right case zero suc rec) def right47 : ∀ {Γ A B} , Tm47 Γ B → Tm47 Γ (sum47 A B) := λ t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case zero suc rec => right47 (t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case zero suc rec) def case47 : ∀ {Γ A B C} , Tm47 Γ (sum47 A B) → Tm47 Γ (arr47 A C) → Tm47 Γ (arr47 B C) → Tm47 Γ C := λ t u v Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case47 zero suc rec => case47 (t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case47 zero suc rec) (u Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case47 zero suc rec) (v Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case47 zero suc rec) def zero47 : ∀ {Γ} , Tm47 Γ nat47 := λ Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case47 zero47 suc rec => zero47 def suc47 : ∀ {Γ} , Tm47 Γ nat47 → Tm47 Γ nat47 := λ t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case47 zero47 suc47 rec => suc47 (t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case47 zero47 suc47 rec) def rec47 : ∀ {Γ A} , Tm47 Γ nat47 → Tm47 Γ (arr47 nat47 (arr47 A A)) → Tm47 Γ A → Tm47 Γ A := λ t u v Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case47 zero47 suc47 rec47 => rec47 (t Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case47 zero47 suc47 rec47) (u Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case47 zero47 suc47 rec47) (v Tm47 var47 lam47 app47 tt47 pair47 fst47 snd47 left47 right47 case47 zero47 suc47 rec47) def v047 : ∀ {Γ A}, Tm47 (snoc47 Γ A) A := var47 vz47 def v147 : ∀ {Γ A B}, Tm47 (snoc47 (snoc47 Γ A) B) A := var47 (vs47 vz47) def v247 : ∀ {Γ A B C}, Tm47 (snoc47 (snoc47 (snoc47 Γ A) B) C) A := var47 (vs47 (vs47 vz47)) def v347 : ∀ {Γ A B C D}, Tm47 (snoc47 (snoc47 (snoc47 (snoc47 Γ A) B) C) D) A := var47 (vs47 (vs47 (vs47 vz47))) def tbool47 : Ty47 := sum47 top47 top47 def ttrue47 : ∀ {Γ}, Tm47 Γ tbool47 := left47 tt47 def tfalse47 : ∀ {Γ}, Tm47 Γ tbool47 := right47 tt47 def ifthenelse47 : ∀ {Γ A}, Tm47 Γ (arr47 tbool47 (arr47 A (arr47 A A))) := lam47 (lam47 (lam47 (case47 v247 (lam47 v247) (lam47 v147)))) def times447 : ∀ {Γ A}, Tm47 Γ (arr47 (arr47 A A) (arr47 A A)) := lam47 (lam47 (app47 v147 (app47 v147 (app47 v147 (app47 v147 v047))))) def add47 : ∀ {Γ}, Tm47 Γ (arr47 nat47 (arr47 nat47 nat47)) := lam47 (rec47 v047 (lam47 (lam47 (lam47 (suc47 (app47 v147 v047))))) (lam47 v047)) def mul47 : ∀ {Γ}, Tm47 Γ (arr47 nat47 (arr47 nat47 nat47)) := lam47 (rec47 v047 (lam47 (lam47 (lam47 (app47 (app47 add47 (app47 v147 v047)) v047)))) (lam47 zero47)) def fact47 : ∀ {Γ}, Tm47 Γ (arr47 nat47 nat47) := lam47 (rec47 v047 (lam47 (lam47 (app47 (app47 mul47 (suc47 v147)) v047))) (suc47 zero47)) def Ty48 : Type 1 := ∀ (Ty48 : Type) (nat top bot : Ty48) (arr prod sum : Ty48 → Ty48 → Ty48) , Ty48 def nat48 : Ty48 := λ _ nat48 _ _ _ _ _ => nat48 def top48 : Ty48 := λ _ _ top48 _ _ _ _ => top48 def bot48 : Ty48 := λ _ _ _ bot48 _ _ _ => bot48 def arr48 : Ty48 → Ty48 → Ty48 := λ A B Ty48 nat48 top48 bot48 arr48 prod sum => arr48 (A Ty48 nat48 top48 bot48 arr48 prod sum) (B Ty48 nat48 top48 bot48 arr48 prod sum) def prod48 : Ty48 → Ty48 → Ty48 := λ A B Ty48 nat48 top48 bot48 arr48 prod48 sum => prod48 (A Ty48 nat48 top48 bot48 arr48 prod48 sum) (B Ty48 nat48 top48 bot48 arr48 prod48 sum) def sum48 : Ty48 → Ty48 → Ty48 := λ A B Ty48 nat48 top48 bot48 arr48 prod48 sum48 => sum48 (A Ty48 nat48 top48 bot48 arr48 prod48 sum48) (B Ty48 nat48 top48 bot48 arr48 prod48 sum48) def Con48 : Type 1 := ∀ (Con48 : Type) (nil : Con48) (snoc : Con48 → Ty48 → Con48) , Con48 def nil48 : Con48 := λ Con48 nil48 snoc => nil48 def snoc48 : Con48 → Ty48 → Con48 := λ Γ A Con48 nil48 snoc48 => snoc48 (Γ Con48 nil48 snoc48) A def Var48 : Con48 → Ty48 → Type 1 := λ Γ A => ∀ (Var48 : Con48 → Ty48 → Type) (vz : ∀{Γ A}, Var48 (snoc48 Γ A) A) (vs : ∀{Γ B A}, Var48 Γ A → Var48 (snoc48 Γ B) A) , Var48 Γ A def vz48 : ∀ {Γ A}, Var48 (snoc48 Γ A) A := λ Var48 vz48 vs => vz48 def vs48 : ∀ {Γ B A}, Var48 Γ A → Var48 (snoc48 Γ B) A := λ x Var48 vz48 vs48 => vs48 (x Var48 vz48 vs48) def Tm48 : Con48 → Ty48 → Type 1 := λ Γ A => ∀ (Tm48 : Con48 → Ty48 → Type) (var : ∀ {Γ A}, Var48 Γ A → Tm48 Γ A) (lam : ∀ {Γ A B}, (Tm48 (snoc48 Γ A) B → Tm48 Γ (arr48 A B))) (app : ∀ {Γ A B} , Tm48 Γ (arr48 A B) → Tm48 Γ A → Tm48 Γ B) (tt : ∀ {Γ} , Tm48 Γ top48) (pair : ∀ {Γ A B} , Tm48 Γ A → Tm48 Γ B → Tm48 Γ (prod48 A B)) (fst : ∀ {Γ A B} , Tm48 Γ (prod48 A B) → Tm48 Γ A) (snd : ∀ {Γ A B} , Tm48 Γ (prod48 A B) → Tm48 Γ B) (left : ∀ {Γ A B} , Tm48 Γ A → Tm48 Γ (sum48 A B)) (right : ∀ {Γ A B} , Tm48 Γ B → Tm48 Γ (sum48 A B)) (case : ∀ {Γ A B C} , Tm48 Γ (sum48 A B) → Tm48 Γ (arr48 A C) → Tm48 Γ (arr48 B C) → Tm48 Γ C) (zero : ∀ {Γ} , Tm48 Γ nat48) (suc : ∀ {Γ} , Tm48 Γ nat48 → Tm48 Γ nat48) (rec : ∀ {Γ A} , Tm48 Γ nat48 → Tm48 Γ (arr48 nat48 (arr48 A A)) → Tm48 Γ A → Tm48 Γ A) , Tm48 Γ A def var48 : ∀ {Γ A}, Var48 Γ A → Tm48 Γ A := λ x Tm48 var48 lam app tt pair fst snd left right case zero suc rec => var48 x def lam48 : ∀ {Γ A B} , Tm48 (snoc48 Γ A) B → Tm48 Γ (arr48 A B) := λ t Tm48 var48 lam48 app tt pair fst snd left right case zero suc rec => lam48 (t Tm48 var48 lam48 app tt pair fst snd left right case zero suc rec) def app48 : ∀ {Γ A B} , Tm48 Γ (arr48 A B) → Tm48 Γ A → Tm48 Γ B := λ t u Tm48 var48 lam48 app48 tt pair fst snd left right case zero suc rec => app48 (t Tm48 var48 lam48 app48 tt pair fst snd left right case zero suc rec) (u Tm48 var48 lam48 app48 tt pair fst snd left right case zero suc rec) def tt48 : ∀ {Γ} , Tm48 Γ top48 := λ Tm48 var48 lam48 app48 tt48 pair fst snd left right case zero suc rec => tt48 def pair48 : ∀ {Γ A B} , Tm48 Γ A → Tm48 Γ B → Tm48 Γ (prod48 A B) := λ t u Tm48 var48 lam48 app48 tt48 pair48 fst snd left right case zero suc rec => pair48 (t Tm48 var48 lam48 app48 tt48 pair48 fst snd left right case zero suc rec) (u Tm48 var48 lam48 app48 tt48 pair48 fst snd left right case zero suc rec) def fst48 : ∀ {Γ A B} , Tm48 Γ (prod48 A B) → Tm48 Γ A := λ t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd left right case zero suc rec => fst48 (t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd left right case zero suc rec) def snd48 : ∀ {Γ A B} , Tm48 Γ (prod48 A B) → Tm48 Γ B := λ t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left right case zero suc rec => snd48 (t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left right case zero suc rec) def left48 : ∀ {Γ A B} , Tm48 Γ A → Tm48 Γ (sum48 A B) := λ t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right case zero suc rec => left48 (t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right case zero suc rec) def right48 : ∀ {Γ A B} , Tm48 Γ B → Tm48 Γ (sum48 A B) := λ t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case zero suc rec => right48 (t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case zero suc rec) def case48 : ∀ {Γ A B C} , Tm48 Γ (sum48 A B) → Tm48 Γ (arr48 A C) → Tm48 Γ (arr48 B C) → Tm48 Γ C := λ t u v Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case48 zero suc rec => case48 (t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case48 zero suc rec) (u Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case48 zero suc rec) (v Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case48 zero suc rec) def zero48 : ∀ {Γ} , Tm48 Γ nat48 := λ Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case48 zero48 suc rec => zero48 def suc48 : ∀ {Γ} , Tm48 Γ nat48 → Tm48 Γ nat48 := λ t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case48 zero48 suc48 rec => suc48 (t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case48 zero48 suc48 rec) def rec48 : ∀ {Γ A} , Tm48 Γ nat48 → Tm48 Γ (arr48 nat48 (arr48 A A)) → Tm48 Γ A → Tm48 Γ A := λ t u v Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case48 zero48 suc48 rec48 => rec48 (t Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case48 zero48 suc48 rec48) (u Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case48 zero48 suc48 rec48) (v Tm48 var48 lam48 app48 tt48 pair48 fst48 snd48 left48 right48 case48 zero48 suc48 rec48) def v048 : ∀ {Γ A}, Tm48 (snoc48 Γ A) A := var48 vz48 def v148 : ∀ {Γ A B}, Tm48 (snoc48 (snoc48 Γ A) B) A := var48 (vs48 vz48) def v248 : ∀ {Γ A B C}, Tm48 (snoc48 (snoc48 (snoc48 Γ A) B) C) A := var48 (vs48 (vs48 vz48)) def v348 : ∀ {Γ A B C D}, Tm48 (snoc48 (snoc48 (snoc48 (snoc48 Γ A) B) C) D) A := var48 (vs48 (vs48 (vs48 vz48))) def tbool48 : Ty48 := sum48 top48 top48 def ttrue48 : ∀ {Γ}, Tm48 Γ tbool48 := left48 tt48 def tfalse48 : ∀ {Γ}, Tm48 Γ tbool48 := right48 tt48 def ifthenelse48 : ∀ {Γ A}, Tm48 Γ (arr48 tbool48 (arr48 A (arr48 A A))) := lam48 (lam48 (lam48 (case48 v248 (lam48 v248) (lam48 v148)))) def times448 : ∀ {Γ A}, Tm48 Γ (arr48 (arr48 A A) (arr48 A A)) := lam48 (lam48 (app48 v148 (app48 v148 (app48 v148 (app48 v148 v048))))) def add48 : ∀ {Γ}, Tm48 Γ (arr48 nat48 (arr48 nat48 nat48)) := lam48 (rec48 v048 (lam48 (lam48 (lam48 (suc48 (app48 v148 v048))))) (lam48 v048)) def mul48 : ∀ {Γ}, Tm48 Γ (arr48 nat48 (arr48 nat48 nat48)) := lam48 (rec48 v048 (lam48 (lam48 (lam48 (app48 (app48 add48 (app48 v148 v048)) v048)))) (lam48 zero48)) def fact48 : ∀ {Γ}, Tm48 Γ (arr48 nat48 nat48) := lam48 (rec48 v048 (lam48 (lam48 (app48 (app48 mul48 (suc48 v148)) v048))) (suc48 zero48)) def Ty49 : Type 1 := ∀ (Ty49 : Type) (nat top bot : Ty49) (arr prod sum : Ty49 → Ty49 → Ty49) , Ty49 def nat49 : Ty49 := λ _ nat49 _ _ _ _ _ => nat49 def top49 : Ty49 := λ _ _ top49 _ _ _ _ => top49 def bot49 : Ty49 := λ _ _ _ bot49 _ _ _ => bot49 def arr49 : Ty49 → Ty49 → Ty49 := λ A B Ty49 nat49 top49 bot49 arr49 prod sum => arr49 (A Ty49 nat49 top49 bot49 arr49 prod sum) (B Ty49 nat49 top49 bot49 arr49 prod sum) def prod49 : Ty49 → Ty49 → Ty49 := λ A B Ty49 nat49 top49 bot49 arr49 prod49 sum => prod49 (A Ty49 nat49 top49 bot49 arr49 prod49 sum) (B Ty49 nat49 top49 bot49 arr49 prod49 sum) def sum49 : Ty49 → Ty49 → Ty49 := λ A B Ty49 nat49 top49 bot49 arr49 prod49 sum49 => sum49 (A Ty49 nat49 top49 bot49 arr49 prod49 sum49) (B Ty49 nat49 top49 bot49 arr49 prod49 sum49) def Con49 : Type 1 := ∀ (Con49 : Type) (nil : Con49) (snoc : Con49 → Ty49 → Con49) , Con49 def nil49 : Con49 := λ Con49 nil49 snoc => nil49 def snoc49 : Con49 → Ty49 → Con49 := λ Γ A Con49 nil49 snoc49 => snoc49 (Γ Con49 nil49 snoc49) A def Var49 : Con49 → Ty49 → Type 1 := λ Γ A => ∀ (Var49 : Con49 → Ty49 → Type) (vz : ∀{Γ A}, Var49 (snoc49 Γ A) A) (vs : ∀{Γ B A}, Var49 Γ A → Var49 (snoc49 Γ B) A) , Var49 Γ A def vz49 : ∀ {Γ A}, Var49 (snoc49 Γ A) A := λ Var49 vz49 vs => vz49 def vs49 : ∀ {Γ B A}, Var49 Γ A → Var49 (snoc49 Γ B) A := λ x Var49 vz49 vs49 => vs49 (x Var49 vz49 vs49) def Tm49 : Con49 → Ty49 → Type 1 := λ Γ A => ∀ (Tm49 : Con49 → Ty49 → Type) (var : ∀ {Γ A}, Var49 Γ A → Tm49 Γ A) (lam : ∀ {Γ A B}, (Tm49 (snoc49 Γ A) B → Tm49 Γ (arr49 A B))) (app : ∀ {Γ A B} , Tm49 Γ (arr49 A B) → Tm49 Γ A → Tm49 Γ B) (tt : ∀ {Γ} , Tm49 Γ top49) (pair : ∀ {Γ A B} , Tm49 Γ A → Tm49 Γ B → Tm49 Γ (prod49 A B)) (fst : ∀ {Γ A B} , Tm49 Γ (prod49 A B) → Tm49 Γ A) (snd : ∀ {Γ A B} , Tm49 Γ (prod49 A B) → Tm49 Γ B) (left : ∀ {Γ A B} , Tm49 Γ A → Tm49 Γ (sum49 A B)) (right : ∀ {Γ A B} , Tm49 Γ B → Tm49 Γ (sum49 A B)) (case : ∀ {Γ A B C} , Tm49 Γ (sum49 A B) → Tm49 Γ (arr49 A C) → Tm49 Γ (arr49 B C) → Tm49 Γ C) (zero : ∀ {Γ} , Tm49 Γ nat49) (suc : ∀ {Γ} , Tm49 Γ nat49 → Tm49 Γ nat49) (rec : ∀ {Γ A} , Tm49 Γ nat49 → Tm49 Γ (arr49 nat49 (arr49 A A)) → Tm49 Γ A → Tm49 Γ A) , Tm49 Γ A def var49 : ∀ {Γ A}, Var49 Γ A → Tm49 Γ A := λ x Tm49 var49 lam app tt pair fst snd left right case zero suc rec => var49 x def lam49 : ∀ {Γ A B} , Tm49 (snoc49 Γ A) B → Tm49 Γ (arr49 A B) := λ t Tm49 var49 lam49 app tt pair fst snd left right case zero suc rec => lam49 (t Tm49 var49 lam49 app tt pair fst snd left right case zero suc rec) def app49 : ∀ {Γ A B} , Tm49 Γ (arr49 A B) → Tm49 Γ A → Tm49 Γ B := λ t u Tm49 var49 lam49 app49 tt pair fst snd left right case zero suc rec => app49 (t Tm49 var49 lam49 app49 tt pair fst snd left right case zero suc rec) (u Tm49 var49 lam49 app49 tt pair fst snd left right case zero suc rec) def tt49 : ∀ {Γ} , Tm49 Γ top49 := λ Tm49 var49 lam49 app49 tt49 pair fst snd left right case zero suc rec => tt49 def pair49 : ∀ {Γ A B} , Tm49 Γ A → Tm49 Γ B → Tm49 Γ (prod49 A B) := λ t u Tm49 var49 lam49 app49 tt49 pair49 fst snd left right case zero suc rec => pair49 (t Tm49 var49 lam49 app49 tt49 pair49 fst snd left right case zero suc rec) (u Tm49 var49 lam49 app49 tt49 pair49 fst snd left right case zero suc rec) def fst49 : ∀ {Γ A B} , Tm49 Γ (prod49 A B) → Tm49 Γ A := λ t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd left right case zero suc rec => fst49 (t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd left right case zero suc rec) def snd49 : ∀ {Γ A B} , Tm49 Γ (prod49 A B) → Tm49 Γ B := λ t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left right case zero suc rec => snd49 (t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left right case zero suc rec) def left49 : ∀ {Γ A B} , Tm49 Γ A → Tm49 Γ (sum49 A B) := λ t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right case zero suc rec => left49 (t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right case zero suc rec) def right49 : ∀ {Γ A B} , Tm49 Γ B → Tm49 Γ (sum49 A B) := λ t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case zero suc rec => right49 (t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case zero suc rec) def case49 : ∀ {Γ A B C} , Tm49 Γ (sum49 A B) → Tm49 Γ (arr49 A C) → Tm49 Γ (arr49 B C) → Tm49 Γ C := λ t u v Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case49 zero suc rec => case49 (t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case49 zero suc rec) (u Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case49 zero suc rec) (v Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case49 zero suc rec) def zero49 : ∀ {Γ} , Tm49 Γ nat49 := λ Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case49 zero49 suc rec => zero49 def suc49 : ∀ {Γ} , Tm49 Γ nat49 → Tm49 Γ nat49 := λ t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case49 zero49 suc49 rec => suc49 (t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case49 zero49 suc49 rec) def rec49 : ∀ {Γ A} , Tm49 Γ nat49 → Tm49 Γ (arr49 nat49 (arr49 A A)) → Tm49 Γ A → Tm49 Γ A := λ t u v Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case49 zero49 suc49 rec49 => rec49 (t Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case49 zero49 suc49 rec49) (u Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case49 zero49 suc49 rec49) (v Tm49 var49 lam49 app49 tt49 pair49 fst49 snd49 left49 right49 case49 zero49 suc49 rec49) def v049 : ∀ {Γ A}, Tm49 (snoc49 Γ A) A := var49 vz49 def v149 : ∀ {Γ A B}, Tm49 (snoc49 (snoc49 Γ A) B) A := var49 (vs49 vz49) def v249 : ∀ {Γ A B C}, Tm49 (snoc49 (snoc49 (snoc49 Γ A) B) C) A := var49 (vs49 (vs49 vz49)) def v349 : ∀ {Γ A B C D}, Tm49 (snoc49 (snoc49 (snoc49 (snoc49 Γ A) B) C) D) A := var49 (vs49 (vs49 (vs49 vz49))) def tbool49 : Ty49 := sum49 top49 top49 def ttrue49 : ∀ {Γ}, Tm49 Γ tbool49 := left49 tt49 def tfalse49 : ∀ {Γ}, Tm49 Γ tbool49 := right49 tt49 def ifthenelse49 : ∀ {Γ A}, Tm49 Γ (arr49 tbool49 (arr49 A (arr49 A A))) := lam49 (lam49 (lam49 (case49 v249 (lam49 v249) (lam49 v149)))) def times449 : ∀ {Γ A}, Tm49 Γ (arr49 (arr49 A A) (arr49 A A)) := lam49 (lam49 (app49 v149 (app49 v149 (app49 v149 (app49 v149 v049))))) def add49 : ∀ {Γ}, Tm49 Γ (arr49 nat49 (arr49 nat49 nat49)) := lam49 (rec49 v049 (lam49 (lam49 (lam49 (suc49 (app49 v149 v049))))) (lam49 v049)) def mul49 : ∀ {Γ}, Tm49 Γ (arr49 nat49 (arr49 nat49 nat49)) := lam49 (rec49 v049 (lam49 (lam49 (lam49 (app49 (app49 add49 (app49 v149 v049)) v049)))) (lam49 zero49)) def fact49 : ∀ {Γ}, Tm49 Γ (arr49 nat49 nat49) := lam49 (rec49 v049 (lam49 (lam49 (app49 (app49 mul49 (suc49 v149)) v049))) (suc49 zero49)) def Ty50 : Type 1 := ∀ (Ty50 : Type) (nat top bot : Ty50) (arr prod sum : Ty50 → Ty50 → Ty50) , Ty50 def nat50 : Ty50 := λ _ nat50 _ _ _ _ _ => nat50 def top50 : Ty50 := λ _ _ top50 _ _ _ _ => top50 def bot50 : Ty50 := λ _ _ _ bot50 _ _ _ => bot50 def arr50 : Ty50 → Ty50 → Ty50 := λ A B Ty50 nat50 top50 bot50 arr50 prod sum => arr50 (A Ty50 nat50 top50 bot50 arr50 prod sum) (B Ty50 nat50 top50 bot50 arr50 prod sum) def prod50 : Ty50 → Ty50 → Ty50 := λ A B Ty50 nat50 top50 bot50 arr50 prod50 sum => prod50 (A Ty50 nat50 top50 bot50 arr50 prod50 sum) (B Ty50 nat50 top50 bot50 arr50 prod50 sum) def sum50 : Ty50 → Ty50 → Ty50 := λ A B Ty50 nat50 top50 bot50 arr50 prod50 sum50 => sum50 (A Ty50 nat50 top50 bot50 arr50 prod50 sum50) (B Ty50 nat50 top50 bot50 arr50 prod50 sum50) def Con50 : Type 1 := ∀ (Con50 : Type) (nil : Con50) (snoc : Con50 → Ty50 → Con50) , Con50 def nil50 : Con50 := λ Con50 nil50 snoc => nil50 def snoc50 : Con50 → Ty50 → Con50 := λ Γ A Con50 nil50 snoc50 => snoc50 (Γ Con50 nil50 snoc50) A def Var50 : Con50 → Ty50 → Type 1 := λ Γ A => ∀ (Var50 : Con50 → Ty50 → Type) (vz : ∀{Γ A}, Var50 (snoc50 Γ A) A) (vs : ∀{Γ B A}, Var50 Γ A → Var50 (snoc50 Γ B) A) , Var50 Γ A def vz50 : ∀ {Γ A}, Var50 (snoc50 Γ A) A := λ Var50 vz50 vs => vz50 def vs50 : ∀ {Γ B A}, Var50 Γ A → Var50 (snoc50 Γ B) A := λ x Var50 vz50 vs50 => vs50 (x Var50 vz50 vs50) def Tm50 : Con50 → Ty50 → Type 1 := λ Γ A => ∀ (Tm50 : Con50 → Ty50 → Type) (var : ∀ {Γ A}, Var50 Γ A → Tm50 Γ A) (lam : ∀ {Γ A B}, (Tm50 (snoc50 Γ A) B → Tm50 Γ (arr50 A B))) (app : ∀ {Γ A B} , Tm50 Γ (arr50 A B) → Tm50 Γ A → Tm50 Γ B) (tt : ∀ {Γ} , Tm50 Γ top50) (pair : ∀ {Γ A B} , Tm50 Γ A → Tm50 Γ B → Tm50 Γ (prod50 A B)) (fst : ∀ {Γ A B} , Tm50 Γ (prod50 A B) → Tm50 Γ A) (snd : ∀ {Γ A B} , Tm50 Γ (prod50 A B) → Tm50 Γ B) (left : ∀ {Γ A B} , Tm50 Γ A → Tm50 Γ (sum50 A B)) (right : ∀ {Γ A B} , Tm50 Γ B → Tm50 Γ (sum50 A B)) (case : ∀ {Γ A B C} , Tm50 Γ (sum50 A B) → Tm50 Γ (arr50 A C) → Tm50 Γ (arr50 B C) → Tm50 Γ C) (zero : ∀ {Γ} , Tm50 Γ nat50) (suc : ∀ {Γ} , Tm50 Γ nat50 → Tm50 Γ nat50) (rec : ∀ {Γ A} , Tm50 Γ nat50 → Tm50 Γ (arr50 nat50 (arr50 A A)) → Tm50 Γ A → Tm50 Γ A) , Tm50 Γ A def var50 : ∀ {Γ A}, Var50 Γ A → Tm50 Γ A := λ x Tm50 var50 lam app tt pair fst snd left right case zero suc rec => var50 x def lam50 : ∀ {Γ A B} , Tm50 (snoc50 Γ A) B → Tm50 Γ (arr50 A B) := λ t Tm50 var50 lam50 app tt pair fst snd left right case zero suc rec => lam50 (t Tm50 var50 lam50 app tt pair fst snd left right case zero suc rec) def app50 : ∀ {Γ A B} , Tm50 Γ (arr50 A B) → Tm50 Γ A → Tm50 Γ B := λ t u Tm50 var50 lam50 app50 tt pair fst snd left right case zero suc rec => app50 (t Tm50 var50 lam50 app50 tt pair fst snd left right case zero suc rec) (u Tm50 var50 lam50 app50 tt pair fst snd left right case zero suc rec) def tt50 : ∀ {Γ} , Tm50 Γ top50 := λ Tm50 var50 lam50 app50 tt50 pair fst snd left right case zero suc rec => tt50 def pair50 : ∀ {Γ A B} , Tm50 Γ A → Tm50 Γ B → Tm50 Γ (prod50 A B) := λ t u Tm50 var50 lam50 app50 tt50 pair50 fst snd left right case zero suc rec => pair50 (t Tm50 var50 lam50 app50 tt50 pair50 fst snd left right case zero suc rec) (u Tm50 var50 lam50 app50 tt50 pair50 fst snd left right case zero suc rec) def fst50 : ∀ {Γ A B} , Tm50 Γ (prod50 A B) → Tm50 Γ A := λ t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd left right case zero suc rec => fst50 (t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd left right case zero suc rec) def snd50 : ∀ {Γ A B} , Tm50 Γ (prod50 A B) → Tm50 Γ B := λ t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left right case zero suc rec => snd50 (t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left right case zero suc rec) def left50 : ∀ {Γ A B} , Tm50 Γ A → Tm50 Γ (sum50 A B) := λ t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right case zero suc rec => left50 (t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right case zero suc rec) def right50 : ∀ {Γ A B} , Tm50 Γ B → Tm50 Γ (sum50 A B) := λ t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case zero suc rec => right50 (t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case zero suc rec) def case50 : ∀ {Γ A B C} , Tm50 Γ (sum50 A B) → Tm50 Γ (arr50 A C) → Tm50 Γ (arr50 B C) → Tm50 Γ C := λ t u v Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case50 zero suc rec => case50 (t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case50 zero suc rec) (u Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case50 zero suc rec) (v Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case50 zero suc rec) def zero50 : ∀ {Γ} , Tm50 Γ nat50 := λ Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case50 zero50 suc rec => zero50 def suc50 : ∀ {Γ} , Tm50 Γ nat50 → Tm50 Γ nat50 := λ t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case50 zero50 suc50 rec => suc50 (t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case50 zero50 suc50 rec) def rec50 : ∀ {Γ A} , Tm50 Γ nat50 → Tm50 Γ (arr50 nat50 (arr50 A A)) → Tm50 Γ A → Tm50 Γ A := λ t u v Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case50 zero50 suc50 rec50 => rec50 (t Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case50 zero50 suc50 rec50) (u Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case50 zero50 suc50 rec50) (v Tm50 var50 lam50 app50 tt50 pair50 fst50 snd50 left50 right50 case50 zero50 suc50 rec50) def v050 : ∀ {Γ A}, Tm50 (snoc50 Γ A) A := var50 vz50 def v150 : ∀ {Γ A B}, Tm50 (snoc50 (snoc50 Γ A) B) A := var50 (vs50 vz50) def v250 : ∀ {Γ A B C}, Tm50 (snoc50 (snoc50 (snoc50 Γ A) B) C) A := var50 (vs50 (vs50 vz50)) def v350 : ∀ {Γ A B C D}, Tm50 (snoc50 (snoc50 (snoc50 (snoc50 Γ A) B) C) D) A := var50 (vs50 (vs50 (vs50 vz50))) def tbool50 : Ty50 := sum50 top50 top50 def ttrue50 : ∀ {Γ}, Tm50 Γ tbool50 := left50 tt50 def tfalse50 : ∀ {Γ}, Tm50 Γ tbool50 := right50 tt50 def ifthenelse50 : ∀ {Γ A}, Tm50 Γ (arr50 tbool50 (arr50 A (arr50 A A))) := lam50 (lam50 (lam50 (case50 v250 (lam50 v250) (lam50 v150)))) def times450 : ∀ {Γ A}, Tm50 Γ (arr50 (arr50 A A) (arr50 A A)) := lam50 (lam50 (app50 v150 (app50 v150 (app50 v150 (app50 v150 v050))))) def add50 : ∀ {Γ}, Tm50 Γ (arr50 nat50 (arr50 nat50 nat50)) := lam50 (rec50 v050 (lam50 (lam50 (lam50 (suc50 (app50 v150 v050))))) (lam50 v050)) def mul50 : ∀ {Γ}, Tm50 Γ (arr50 nat50 (arr50 nat50 nat50)) := lam50 (rec50 v050 (lam50 (lam50 (lam50 (app50 (app50 add50 (app50 v150 v050)) v050)))) (lam50 zero50)) def fact50 : ∀ {Γ}, Tm50 Γ (arr50 nat50 nat50) := lam50 (rec50 v050 (lam50 (lam50 (app50 (app50 mul50 (suc50 v150)) v050))) (suc50 zero50)) def Ty51 : Type 1 := ∀ (Ty51 : Type) (nat top bot : Ty51) (arr prod sum : Ty51 → Ty51 → Ty51) , Ty51 def nat51 : Ty51 := λ _ nat51 _ _ _ _ _ => nat51 def top51 : Ty51 := λ _ _ top51 _ _ _ _ => top51 def bot51 : Ty51 := λ _ _ _ bot51 _ _ _ => bot51 def arr51 : Ty51 → Ty51 → Ty51 := λ A B Ty51 nat51 top51 bot51 arr51 prod sum => arr51 (A Ty51 nat51 top51 bot51 arr51 prod sum) (B Ty51 nat51 top51 bot51 arr51 prod sum) def prod51 : Ty51 → Ty51 → Ty51 := λ A B Ty51 nat51 top51 bot51 arr51 prod51 sum => prod51 (A Ty51 nat51 top51 bot51 arr51 prod51 sum) (B Ty51 nat51 top51 bot51 arr51 prod51 sum) def sum51 : Ty51 → Ty51 → Ty51 := λ A B Ty51 nat51 top51 bot51 arr51 prod51 sum51 => sum51 (A Ty51 nat51 top51 bot51 arr51 prod51 sum51) (B Ty51 nat51 top51 bot51 arr51 prod51 sum51) def Con51 : Type 1 := ∀ (Con51 : Type) (nil : Con51) (snoc : Con51 → Ty51 → Con51) , Con51 def nil51 : Con51 := λ Con51 nil51 snoc => nil51 def snoc51 : Con51 → Ty51 → Con51 := λ Γ A Con51 nil51 snoc51 => snoc51 (Γ Con51 nil51 snoc51) A def Var51 : Con51 → Ty51 → Type 1 := λ Γ A => ∀ (Var51 : Con51 → Ty51 → Type) (vz : ∀{Γ A}, Var51 (snoc51 Γ A) A) (vs : ∀{Γ B A}, Var51 Γ A → Var51 (snoc51 Γ B) A) , Var51 Γ A def vz51 : ∀ {Γ A}, Var51 (snoc51 Γ A) A := λ Var51 vz51 vs => vz51 def vs51 : ∀ {Γ B A}, Var51 Γ A → Var51 (snoc51 Γ B) A := λ x Var51 vz51 vs51 => vs51 (x Var51 vz51 vs51) def Tm51 : Con51 → Ty51 → Type 1 := λ Γ A => ∀ (Tm51 : Con51 → Ty51 → Type) (var : ∀ {Γ A}, Var51 Γ A → Tm51 Γ A) (lam : ∀ {Γ A B}, (Tm51 (snoc51 Γ A) B → Tm51 Γ (arr51 A B))) (app : ∀ {Γ A B} , Tm51 Γ (arr51 A B) → Tm51 Γ A → Tm51 Γ B) (tt : ∀ {Γ} , Tm51 Γ top51) (pair : ∀ {Γ A B} , Tm51 Γ A → Tm51 Γ B → Tm51 Γ (prod51 A B)) (fst : ∀ {Γ A B} , Tm51 Γ (prod51 A B) → Tm51 Γ A) (snd : ∀ {Γ A B} , Tm51 Γ (prod51 A B) → Tm51 Γ B) (left : ∀ {Γ A B} , Tm51 Γ A → Tm51 Γ (sum51 A B)) (right : ∀ {Γ A B} , Tm51 Γ B → Tm51 Γ (sum51 A B)) (case : ∀ {Γ A B C} , Tm51 Γ (sum51 A B) → Tm51 Γ (arr51 A C) → Tm51 Γ (arr51 B C) → Tm51 Γ C) (zero : ∀ {Γ} , Tm51 Γ nat51) (suc : ∀ {Γ} , Tm51 Γ nat51 → Tm51 Γ nat51) (rec : ∀ {Γ A} , Tm51 Γ nat51 → Tm51 Γ (arr51 nat51 (arr51 A A)) → Tm51 Γ A → Tm51 Γ A) , Tm51 Γ A def var51 : ∀ {Γ A}, Var51 Γ A → Tm51 Γ A := λ x Tm51 var51 lam app tt pair fst snd left right case zero suc rec => var51 x def lam51 : ∀ {Γ A B} , Tm51 (snoc51 Γ A) B → Tm51 Γ (arr51 A B) := λ t Tm51 var51 lam51 app tt pair fst snd left right case zero suc rec => lam51 (t Tm51 var51 lam51 app tt pair fst snd left right case zero suc rec) def app51 : ∀ {Γ A B} , Tm51 Γ (arr51 A B) → Tm51 Γ A → Tm51 Γ B := λ t u Tm51 var51 lam51 app51 tt pair fst snd left right case zero suc rec => app51 (t Tm51 var51 lam51 app51 tt pair fst snd left right case zero suc rec) (u Tm51 var51 lam51 app51 tt pair fst snd left right case zero suc rec) def tt51 : ∀ {Γ} , Tm51 Γ top51 := λ Tm51 var51 lam51 app51 tt51 pair fst snd left right case zero suc rec => tt51 def pair51 : ∀ {Γ A B} , Tm51 Γ A → Tm51 Γ B → Tm51 Γ (prod51 A B) := λ t u Tm51 var51 lam51 app51 tt51 pair51 fst snd left right case zero suc rec => pair51 (t Tm51 var51 lam51 app51 tt51 pair51 fst snd left right case zero suc rec) (u Tm51 var51 lam51 app51 tt51 pair51 fst snd left right case zero suc rec) def fst51 : ∀ {Γ A B} , Tm51 Γ (prod51 A B) → Tm51 Γ A := λ t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd left right case zero suc rec => fst51 (t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd left right case zero suc rec) def snd51 : ∀ {Γ A B} , Tm51 Γ (prod51 A B) → Tm51 Γ B := λ t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left right case zero suc rec => snd51 (t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left right case zero suc rec) def left51 : ∀ {Γ A B} , Tm51 Γ A → Tm51 Γ (sum51 A B) := λ t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right case zero suc rec => left51 (t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right case zero suc rec) def right51 : ∀ {Γ A B} , Tm51 Γ B → Tm51 Γ (sum51 A B) := λ t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case zero suc rec => right51 (t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case zero suc rec) def case51 : ∀ {Γ A B C} , Tm51 Γ (sum51 A B) → Tm51 Γ (arr51 A C) → Tm51 Γ (arr51 B C) → Tm51 Γ C := λ t u v Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case51 zero suc rec => case51 (t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case51 zero suc rec) (u Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case51 zero suc rec) (v Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case51 zero suc rec) def zero51 : ∀ {Γ} , Tm51 Γ nat51 := λ Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case51 zero51 suc rec => zero51 def suc51 : ∀ {Γ} , Tm51 Γ nat51 → Tm51 Γ nat51 := λ t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case51 zero51 suc51 rec => suc51 (t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case51 zero51 suc51 rec) def rec51 : ∀ {Γ A} , Tm51 Γ nat51 → Tm51 Γ (arr51 nat51 (arr51 A A)) → Tm51 Γ A → Tm51 Γ A := λ t u v Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case51 zero51 suc51 rec51 => rec51 (t Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case51 zero51 suc51 rec51) (u Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case51 zero51 suc51 rec51) (v Tm51 var51 lam51 app51 tt51 pair51 fst51 snd51 left51 right51 case51 zero51 suc51 rec51) def v051 : ∀ {Γ A}, Tm51 (snoc51 Γ A) A := var51 vz51 def v151 : ∀ {Γ A B}, Tm51 (snoc51 (snoc51 Γ A) B) A := var51 (vs51 vz51) def v251 : ∀ {Γ A B C}, Tm51 (snoc51 (snoc51 (snoc51 Γ A) B) C) A := var51 (vs51 (vs51 vz51)) def v351 : ∀ {Γ A B C D}, Tm51 (snoc51 (snoc51 (snoc51 (snoc51 Γ A) B) C) D) A := var51 (vs51 (vs51 (vs51 vz51))) def tbool51 : Ty51 := sum51 top51 top51 def ttrue51 : ∀ {Γ}, Tm51 Γ tbool51 := left51 tt51 def tfalse51 : ∀ {Γ}, Tm51 Γ tbool51 := right51 tt51 def ifthenelse51 : ∀ {Γ A}, Tm51 Γ (arr51 tbool51 (arr51 A (arr51 A A))) := lam51 (lam51 (lam51 (case51 v251 (lam51 v251) (lam51 v151)))) def times451 : ∀ {Γ A}, Tm51 Γ (arr51 (arr51 A A) (arr51 A A)) := lam51 (lam51 (app51 v151 (app51 v151 (app51 v151 (app51 v151 v051))))) def add51 : ∀ {Γ}, Tm51 Γ (arr51 nat51 (arr51 nat51 nat51)) := lam51 (rec51 v051 (lam51 (lam51 (lam51 (suc51 (app51 v151 v051))))) (lam51 v051)) def mul51 : ∀ {Γ}, Tm51 Γ (arr51 nat51 (arr51 nat51 nat51)) := lam51 (rec51 v051 (lam51 (lam51 (lam51 (app51 (app51 add51 (app51 v151 v051)) v051)))) (lam51 zero51)) def fact51 : ∀ {Γ}, Tm51 Γ (arr51 nat51 nat51) := lam51 (rec51 v051 (lam51 (lam51 (app51 (app51 mul51 (suc51 v151)) v051))) (suc51 zero51)) def Ty52 : Type 1 := ∀ (Ty52 : Type) (nat top bot : Ty52) (arr prod sum : Ty52 → Ty52 → Ty52) , Ty52 def nat52 : Ty52 := λ _ nat52 _ _ _ _ _ => nat52 def top52 : Ty52 := λ _ _ top52 _ _ _ _ => top52 def bot52 : Ty52 := λ _ _ _ bot52 _ _ _ => bot52 def arr52 : Ty52 → Ty52 → Ty52 := λ A B Ty52 nat52 top52 bot52 arr52 prod sum => arr52 (A Ty52 nat52 top52 bot52 arr52 prod sum) (B Ty52 nat52 top52 bot52 arr52 prod sum) def prod52 : Ty52 → Ty52 → Ty52 := λ A B Ty52 nat52 top52 bot52 arr52 prod52 sum => prod52 (A Ty52 nat52 top52 bot52 arr52 prod52 sum) (B Ty52 nat52 top52 bot52 arr52 prod52 sum) def sum52 : Ty52 → Ty52 → Ty52 := λ A B Ty52 nat52 top52 bot52 arr52 prod52 sum52 => sum52 (A Ty52 nat52 top52 bot52 arr52 prod52 sum52) (B Ty52 nat52 top52 bot52 arr52 prod52 sum52) def Con52 : Type 1 := ∀ (Con52 : Type) (nil : Con52) (snoc : Con52 → Ty52 → Con52) , Con52 def nil52 : Con52 := λ Con52 nil52 snoc => nil52 def snoc52 : Con52 → Ty52 → Con52 := λ Γ A Con52 nil52 snoc52 => snoc52 (Γ Con52 nil52 snoc52) A def Var52 : Con52 → Ty52 → Type 1 := λ Γ A => ∀ (Var52 : Con52 → Ty52 → Type) (vz : ∀{Γ A}, Var52 (snoc52 Γ A) A) (vs : ∀{Γ B A}, Var52 Γ A → Var52 (snoc52 Γ B) A) , Var52 Γ A def vz52 : ∀ {Γ A}, Var52 (snoc52 Γ A) A := λ Var52 vz52 vs => vz52 def vs52 : ∀ {Γ B A}, Var52 Γ A → Var52 (snoc52 Γ B) A := λ x Var52 vz52 vs52 => vs52 (x Var52 vz52 vs52) def Tm52 : Con52 → Ty52 → Type 1 := λ Γ A => ∀ (Tm52 : Con52 → Ty52 → Type) (var : ∀ {Γ A}, Var52 Γ A → Tm52 Γ A) (lam : ∀ {Γ A B}, (Tm52 (snoc52 Γ A) B → Tm52 Γ (arr52 A B))) (app : ∀ {Γ A B} , Tm52 Γ (arr52 A B) → Tm52 Γ A → Tm52 Γ B) (tt : ∀ {Γ} , Tm52 Γ top52) (pair : ∀ {Γ A B} , Tm52 Γ A → Tm52 Γ B → Tm52 Γ (prod52 A B)) (fst : ∀ {Γ A B} , Tm52 Γ (prod52 A B) → Tm52 Γ A) (snd : ∀ {Γ A B} , Tm52 Γ (prod52 A B) → Tm52 Γ B) (left : ∀ {Γ A B} , Tm52 Γ A → Tm52 Γ (sum52 A B)) (right : ∀ {Γ A B} , Tm52 Γ B → Tm52 Γ (sum52 A B)) (case : ∀ {Γ A B C} , Tm52 Γ (sum52 A B) → Tm52 Γ (arr52 A C) → Tm52 Γ (arr52 B C) → Tm52 Γ C) (zero : ∀ {Γ} , Tm52 Γ nat52) (suc : ∀ {Γ} , Tm52 Γ nat52 → Tm52 Γ nat52) (rec : ∀ {Γ A} , Tm52 Γ nat52 → Tm52 Γ (arr52 nat52 (arr52 A A)) → Tm52 Γ A → Tm52 Γ A) , Tm52 Γ A def var52 : ∀ {Γ A}, Var52 Γ A → Tm52 Γ A := λ x Tm52 var52 lam app tt pair fst snd left right case zero suc rec => var52 x def lam52 : ∀ {Γ A B} , Tm52 (snoc52 Γ A) B → Tm52 Γ (arr52 A B) := λ t Tm52 var52 lam52 app tt pair fst snd left right case zero suc rec => lam52 (t Tm52 var52 lam52 app tt pair fst snd left right case zero suc rec) def app52 : ∀ {Γ A B} , Tm52 Γ (arr52 A B) → Tm52 Γ A → Tm52 Γ B := λ t u Tm52 var52 lam52 app52 tt pair fst snd left right case zero suc rec => app52 (t Tm52 var52 lam52 app52 tt pair fst snd left right case zero suc rec) (u Tm52 var52 lam52 app52 tt pair fst snd left right case zero suc rec) def tt52 : ∀ {Γ} , Tm52 Γ top52 := λ Tm52 var52 lam52 app52 tt52 pair fst snd left right case zero suc rec => tt52 def pair52 : ∀ {Γ A B} , Tm52 Γ A → Tm52 Γ B → Tm52 Γ (prod52 A B) := λ t u Tm52 var52 lam52 app52 tt52 pair52 fst snd left right case zero suc rec => pair52 (t Tm52 var52 lam52 app52 tt52 pair52 fst snd left right case zero suc rec) (u Tm52 var52 lam52 app52 tt52 pair52 fst snd left right case zero suc rec) def fst52 : ∀ {Γ A B} , Tm52 Γ (prod52 A B) → Tm52 Γ A := λ t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd left right case zero suc rec => fst52 (t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd left right case zero suc rec) def snd52 : ∀ {Γ A B} , Tm52 Γ (prod52 A B) → Tm52 Γ B := λ t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left right case zero suc rec => snd52 (t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left right case zero suc rec) def left52 : ∀ {Γ A B} , Tm52 Γ A → Tm52 Γ (sum52 A B) := λ t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right case zero suc rec => left52 (t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right case zero suc rec) def right52 : ∀ {Γ A B} , Tm52 Γ B → Tm52 Γ (sum52 A B) := λ t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case zero suc rec => right52 (t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case zero suc rec) def case52 : ∀ {Γ A B C} , Tm52 Γ (sum52 A B) → Tm52 Γ (arr52 A C) → Tm52 Γ (arr52 B C) → Tm52 Γ C := λ t u v Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case52 zero suc rec => case52 (t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case52 zero suc rec) (u Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case52 zero suc rec) (v Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case52 zero suc rec) def zero52 : ∀ {Γ} , Tm52 Γ nat52 := λ Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case52 zero52 suc rec => zero52 def suc52 : ∀ {Γ} , Tm52 Γ nat52 → Tm52 Γ nat52 := λ t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case52 zero52 suc52 rec => suc52 (t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case52 zero52 suc52 rec) def rec52 : ∀ {Γ A} , Tm52 Γ nat52 → Tm52 Γ (arr52 nat52 (arr52 A A)) → Tm52 Γ A → Tm52 Γ A := λ t u v Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case52 zero52 suc52 rec52 => rec52 (t Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case52 zero52 suc52 rec52) (u Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case52 zero52 suc52 rec52) (v Tm52 var52 lam52 app52 tt52 pair52 fst52 snd52 left52 right52 case52 zero52 suc52 rec52) def v052 : ∀ {Γ A}, Tm52 (snoc52 Γ A) A := var52 vz52 def v152 : ∀ {Γ A B}, Tm52 (snoc52 (snoc52 Γ A) B) A := var52 (vs52 vz52) def v252 : ∀ {Γ A B C}, Tm52 (snoc52 (snoc52 (snoc52 Γ A) B) C) A := var52 (vs52 (vs52 vz52)) def v352 : ∀ {Γ A B C D}, Tm52 (snoc52 (snoc52 (snoc52 (snoc52 Γ A) B) C) D) A := var52 (vs52 (vs52 (vs52 vz52))) def tbool52 : Ty52 := sum52 top52 top52 def ttrue52 : ∀ {Γ}, Tm52 Γ tbool52 := left52 tt52 def tfalse52 : ∀ {Γ}, Tm52 Γ tbool52 := right52 tt52 def ifthenelse52 : ∀ {Γ A}, Tm52 Γ (arr52 tbool52 (arr52 A (arr52 A A))) := lam52 (lam52 (lam52 (case52 v252 (lam52 v252) (lam52 v152)))) def times452 : ∀ {Γ A}, Tm52 Γ (arr52 (arr52 A A) (arr52 A A)) := lam52 (lam52 (app52 v152 (app52 v152 (app52 v152 (app52 v152 v052))))) def add52 : ∀ {Γ}, Tm52 Γ (arr52 nat52 (arr52 nat52 nat52)) := lam52 (rec52 v052 (lam52 (lam52 (lam52 (suc52 (app52 v152 v052))))) (lam52 v052)) def mul52 : ∀ {Γ}, Tm52 Γ (arr52 nat52 (arr52 nat52 nat52)) := lam52 (rec52 v052 (lam52 (lam52 (lam52 (app52 (app52 add52 (app52 v152 v052)) v052)))) (lam52 zero52)) def fact52 : ∀ {Γ}, Tm52 Γ (arr52 nat52 nat52) := lam52 (rec52 v052 (lam52 (lam52 (app52 (app52 mul52 (suc52 v152)) v052))) (suc52 zero52)) def Ty53 : Type 1 := ∀ (Ty53 : Type) (nat top bot : Ty53) (arr prod sum : Ty53 → Ty53 → Ty53) , Ty53 def nat53 : Ty53 := λ _ nat53 _ _ _ _ _ => nat53 def top53 : Ty53 := λ _ _ top53 _ _ _ _ => top53 def bot53 : Ty53 := λ _ _ _ bot53 _ _ _ => bot53 def arr53 : Ty53 → Ty53 → Ty53 := λ A B Ty53 nat53 top53 bot53 arr53 prod sum => arr53 (A Ty53 nat53 top53 bot53 arr53 prod sum) (B Ty53 nat53 top53 bot53 arr53 prod sum) def prod53 : Ty53 → Ty53 → Ty53 := λ A B Ty53 nat53 top53 bot53 arr53 prod53 sum => prod53 (A Ty53 nat53 top53 bot53 arr53 prod53 sum) (B Ty53 nat53 top53 bot53 arr53 prod53 sum) def sum53 : Ty53 → Ty53 → Ty53 := λ A B Ty53 nat53 top53 bot53 arr53 prod53 sum53 => sum53 (A Ty53 nat53 top53 bot53 arr53 prod53 sum53) (B Ty53 nat53 top53 bot53 arr53 prod53 sum53) def Con53 : Type 1 := ∀ (Con53 : Type) (nil : Con53) (snoc : Con53 → Ty53 → Con53) , Con53 def nil53 : Con53 := λ Con53 nil53 snoc => nil53 def snoc53 : Con53 → Ty53 → Con53 := λ Γ A Con53 nil53 snoc53 => snoc53 (Γ Con53 nil53 snoc53) A def Var53 : Con53 → Ty53 → Type 1 := λ Γ A => ∀ (Var53 : Con53 → Ty53 → Type) (vz : ∀{Γ A}, Var53 (snoc53 Γ A) A) (vs : ∀{Γ B A}, Var53 Γ A → Var53 (snoc53 Γ B) A) , Var53 Γ A def vz53 : ∀ {Γ A}, Var53 (snoc53 Γ A) A := λ Var53 vz53 vs => vz53 def vs53 : ∀ {Γ B A}, Var53 Γ A → Var53 (snoc53 Γ B) A := λ x Var53 vz53 vs53 => vs53 (x Var53 vz53 vs53) def Tm53 : Con53 → Ty53 → Type 1 := λ Γ A => ∀ (Tm53 : Con53 → Ty53 → Type) (var : ∀ {Γ A}, Var53 Γ A → Tm53 Γ A) (lam : ∀ {Γ A B}, (Tm53 (snoc53 Γ A) B → Tm53 Γ (arr53 A B))) (app : ∀ {Γ A B} , Tm53 Γ (arr53 A B) → Tm53 Γ A → Tm53 Γ B) (tt : ∀ {Γ} , Tm53 Γ top53) (pair : ∀ {Γ A B} , Tm53 Γ A → Tm53 Γ B → Tm53 Γ (prod53 A B)) (fst : ∀ {Γ A B} , Tm53 Γ (prod53 A B) → Tm53 Γ A) (snd : ∀ {Γ A B} , Tm53 Γ (prod53 A B) → Tm53 Γ B) (left : ∀ {Γ A B} , Tm53 Γ A → Tm53 Γ (sum53 A B)) (right : ∀ {Γ A B} , Tm53 Γ B → Tm53 Γ (sum53 A B)) (case : ∀ {Γ A B C} , Tm53 Γ (sum53 A B) → Tm53 Γ (arr53 A C) → Tm53 Γ (arr53 B C) → Tm53 Γ C) (zero : ∀ {Γ} , Tm53 Γ nat53) (suc : ∀ {Γ} , Tm53 Γ nat53 → Tm53 Γ nat53) (rec : ∀ {Γ A} , Tm53 Γ nat53 → Tm53 Γ (arr53 nat53 (arr53 A A)) → Tm53 Γ A → Tm53 Γ A) , Tm53 Γ A def var53 : ∀ {Γ A}, Var53 Γ A → Tm53 Γ A := λ x Tm53 var53 lam app tt pair fst snd left right case zero suc rec => var53 x def lam53 : ∀ {Γ A B} , Tm53 (snoc53 Γ A) B → Tm53 Γ (arr53 A B) := λ t Tm53 var53 lam53 app tt pair fst snd left right case zero suc rec => lam53 (t Tm53 var53 lam53 app tt pair fst snd left right case zero suc rec) def app53 : ∀ {Γ A B} , Tm53 Γ (arr53 A B) → Tm53 Γ A → Tm53 Γ B := λ t u Tm53 var53 lam53 app53 tt pair fst snd left right case zero suc rec => app53 (t Tm53 var53 lam53 app53 tt pair fst snd left right case zero suc rec) (u Tm53 var53 lam53 app53 tt pair fst snd left right case zero suc rec) def tt53 : ∀ {Γ} , Tm53 Γ top53 := λ Tm53 var53 lam53 app53 tt53 pair fst snd left right case zero suc rec => tt53 def pair53 : ∀ {Γ A B} , Tm53 Γ A → Tm53 Γ B → Tm53 Γ (prod53 A B) := λ t u Tm53 var53 lam53 app53 tt53 pair53 fst snd left right case zero suc rec => pair53 (t Tm53 var53 lam53 app53 tt53 pair53 fst snd left right case zero suc rec) (u Tm53 var53 lam53 app53 tt53 pair53 fst snd left right case zero suc rec) def fst53 : ∀ {Γ A B} , Tm53 Γ (prod53 A B) → Tm53 Γ A := λ t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd left right case zero suc rec => fst53 (t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd left right case zero suc rec) def snd53 : ∀ {Γ A B} , Tm53 Γ (prod53 A B) → Tm53 Γ B := λ t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left right case zero suc rec => snd53 (t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left right case zero suc rec) def left53 : ∀ {Γ A B} , Tm53 Γ A → Tm53 Γ (sum53 A B) := λ t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right case zero suc rec => left53 (t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right case zero suc rec) def right53 : ∀ {Γ A B} , Tm53 Γ B → Tm53 Γ (sum53 A B) := λ t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case zero suc rec => right53 (t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case zero suc rec) def case53 : ∀ {Γ A B C} , Tm53 Γ (sum53 A B) → Tm53 Γ (arr53 A C) → Tm53 Γ (arr53 B C) → Tm53 Γ C := λ t u v Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case53 zero suc rec => case53 (t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case53 zero suc rec) (u Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case53 zero suc rec) (v Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case53 zero suc rec) def zero53 : ∀ {Γ} , Tm53 Γ nat53 := λ Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case53 zero53 suc rec => zero53 def suc53 : ∀ {Γ} , Tm53 Γ nat53 → Tm53 Γ nat53 := λ t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case53 zero53 suc53 rec => suc53 (t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case53 zero53 suc53 rec) def rec53 : ∀ {Γ A} , Tm53 Γ nat53 → Tm53 Γ (arr53 nat53 (arr53 A A)) → Tm53 Γ A → Tm53 Γ A := λ t u v Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case53 zero53 suc53 rec53 => rec53 (t Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case53 zero53 suc53 rec53) (u Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case53 zero53 suc53 rec53) (v Tm53 var53 lam53 app53 tt53 pair53 fst53 snd53 left53 right53 case53 zero53 suc53 rec53) def v053 : ∀ {Γ A}, Tm53 (snoc53 Γ A) A := var53 vz53 def v153 : ∀ {Γ A B}, Tm53 (snoc53 (snoc53 Γ A) B) A := var53 (vs53 vz53) def v253 : ∀ {Γ A B C}, Tm53 (snoc53 (snoc53 (snoc53 Γ A) B) C) A := var53 (vs53 (vs53 vz53)) def v353 : ∀ {Γ A B C D}, Tm53 (snoc53 (snoc53 (snoc53 (snoc53 Γ A) B) C) D) A := var53 (vs53 (vs53 (vs53 vz53))) def tbool53 : Ty53 := sum53 top53 top53 def ttrue53 : ∀ {Γ}, Tm53 Γ tbool53 := left53 tt53 def tfalse53 : ∀ {Γ}, Tm53 Γ tbool53 := right53 tt53 def ifthenelse53 : ∀ {Γ A}, Tm53 Γ (arr53 tbool53 (arr53 A (arr53 A A))) := lam53 (lam53 (lam53 (case53 v253 (lam53 v253) (lam53 v153)))) def times453 : ∀ {Γ A}, Tm53 Γ (arr53 (arr53 A A) (arr53 A A)) := lam53 (lam53 (app53 v153 (app53 v153 (app53 v153 (app53 v153 v053))))) def add53 : ∀ {Γ}, Tm53 Γ (arr53 nat53 (arr53 nat53 nat53)) := lam53 (rec53 v053 (lam53 (lam53 (lam53 (suc53 (app53 v153 v053))))) (lam53 v053)) def mul53 : ∀ {Γ}, Tm53 Γ (arr53 nat53 (arr53 nat53 nat53)) := lam53 (rec53 v053 (lam53 (lam53 (lam53 (app53 (app53 add53 (app53 v153 v053)) v053)))) (lam53 zero53)) def fact53 : ∀ {Γ}, Tm53 Γ (arr53 nat53 nat53) := lam53 (rec53 v053 (lam53 (lam53 (app53 (app53 mul53 (suc53 v153)) v053))) (suc53 zero53)) def Ty54 : Type 1 := ∀ (Ty54 : Type) (nat top bot : Ty54) (arr prod sum : Ty54 → Ty54 → Ty54) , Ty54 def nat54 : Ty54 := λ _ nat54 _ _ _ _ _ => nat54 def top54 : Ty54 := λ _ _ top54 _ _ _ _ => top54 def bot54 : Ty54 := λ _ _ _ bot54 _ _ _ => bot54 def arr54 : Ty54 → Ty54 → Ty54 := λ A B Ty54 nat54 top54 bot54 arr54 prod sum => arr54 (A Ty54 nat54 top54 bot54 arr54 prod sum) (B Ty54 nat54 top54 bot54 arr54 prod sum) def prod54 : Ty54 → Ty54 → Ty54 := λ A B Ty54 nat54 top54 bot54 arr54 prod54 sum => prod54 (A Ty54 nat54 top54 bot54 arr54 prod54 sum) (B Ty54 nat54 top54 bot54 arr54 prod54 sum) def sum54 : Ty54 → Ty54 → Ty54 := λ A B Ty54 nat54 top54 bot54 arr54 prod54 sum54 => sum54 (A Ty54 nat54 top54 bot54 arr54 prod54 sum54) (B Ty54 nat54 top54 bot54 arr54 prod54 sum54) def Con54 : Type 1 := ∀ (Con54 : Type) (nil : Con54) (snoc : Con54 → Ty54 → Con54) , Con54 def nil54 : Con54 := λ Con54 nil54 snoc => nil54 def snoc54 : Con54 → Ty54 → Con54 := λ Γ A Con54 nil54 snoc54 => snoc54 (Γ Con54 nil54 snoc54) A def Var54 : Con54 → Ty54 → Type 1 := λ Γ A => ∀ (Var54 : Con54 → Ty54 → Type) (vz : ∀{Γ A}, Var54 (snoc54 Γ A) A) (vs : ∀{Γ B A}, Var54 Γ A → Var54 (snoc54 Γ B) A) , Var54 Γ A def vz54 : ∀ {Γ A}, Var54 (snoc54 Γ A) A := λ Var54 vz54 vs => vz54 def vs54 : ∀ {Γ B A}, Var54 Γ A → Var54 (snoc54 Γ B) A := λ x Var54 vz54 vs54 => vs54 (x Var54 vz54 vs54) def Tm54 : Con54 → Ty54 → Type 1 := λ Γ A => ∀ (Tm54 : Con54 → Ty54 → Type) (var : ∀ {Γ A}, Var54 Γ A → Tm54 Γ A) (lam : ∀ {Γ A B}, (Tm54 (snoc54 Γ A) B → Tm54 Γ (arr54 A B))) (app : ∀ {Γ A B} , Tm54 Γ (arr54 A B) → Tm54 Γ A → Tm54 Γ B) (tt : ∀ {Γ} , Tm54 Γ top54) (pair : ∀ {Γ A B} , Tm54 Γ A → Tm54 Γ B → Tm54 Γ (prod54 A B)) (fst : ∀ {Γ A B} , Tm54 Γ (prod54 A B) → Tm54 Γ A) (snd : ∀ {Γ A B} , Tm54 Γ (prod54 A B) → Tm54 Γ B) (left : ∀ {Γ A B} , Tm54 Γ A → Tm54 Γ (sum54 A B)) (right : ∀ {Γ A B} , Tm54 Γ B → Tm54 Γ (sum54 A B)) (case : ∀ {Γ A B C} , Tm54 Γ (sum54 A B) → Tm54 Γ (arr54 A C) → Tm54 Γ (arr54 B C) → Tm54 Γ C) (zero : ∀ {Γ} , Tm54 Γ nat54) (suc : ∀ {Γ} , Tm54 Γ nat54 → Tm54 Γ nat54) (rec : ∀ {Γ A} , Tm54 Γ nat54 → Tm54 Γ (arr54 nat54 (arr54 A A)) → Tm54 Γ A → Tm54 Γ A) , Tm54 Γ A def var54 : ∀ {Γ A}, Var54 Γ A → Tm54 Γ A := λ x Tm54 var54 lam app tt pair fst snd left right case zero suc rec => var54 x def lam54 : ∀ {Γ A B} , Tm54 (snoc54 Γ A) B → Tm54 Γ (arr54 A B) := λ t Tm54 var54 lam54 app tt pair fst snd left right case zero suc rec => lam54 (t Tm54 var54 lam54 app tt pair fst snd left right case zero suc rec) def app54 : ∀ {Γ A B} , Tm54 Γ (arr54 A B) → Tm54 Γ A → Tm54 Γ B := λ t u Tm54 var54 lam54 app54 tt pair fst snd left right case zero suc rec => app54 (t Tm54 var54 lam54 app54 tt pair fst snd left right case zero suc rec) (u Tm54 var54 lam54 app54 tt pair fst snd left right case zero suc rec) def tt54 : ∀ {Γ} , Tm54 Γ top54 := λ Tm54 var54 lam54 app54 tt54 pair fst snd left right case zero suc rec => tt54 def pair54 : ∀ {Γ A B} , Tm54 Γ A → Tm54 Γ B → Tm54 Γ (prod54 A B) := λ t u Tm54 var54 lam54 app54 tt54 pair54 fst snd left right case zero suc rec => pair54 (t Tm54 var54 lam54 app54 tt54 pair54 fst snd left right case zero suc rec) (u Tm54 var54 lam54 app54 tt54 pair54 fst snd left right case zero suc rec) def fst54 : ∀ {Γ A B} , Tm54 Γ (prod54 A B) → Tm54 Γ A := λ t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd left right case zero suc rec => fst54 (t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd left right case zero suc rec) def snd54 : ∀ {Γ A B} , Tm54 Γ (prod54 A B) → Tm54 Γ B := λ t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left right case zero suc rec => snd54 (t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left right case zero suc rec) def left54 : ∀ {Γ A B} , Tm54 Γ A → Tm54 Γ (sum54 A B) := λ t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right case zero suc rec => left54 (t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right case zero suc rec) def right54 : ∀ {Γ A B} , Tm54 Γ B → Tm54 Γ (sum54 A B) := λ t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case zero suc rec => right54 (t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case zero suc rec) def case54 : ∀ {Γ A B C} , Tm54 Γ (sum54 A B) → Tm54 Γ (arr54 A C) → Tm54 Γ (arr54 B C) → Tm54 Γ C := λ t u v Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case54 zero suc rec => case54 (t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case54 zero suc rec) (u Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case54 zero suc rec) (v Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case54 zero suc rec) def zero54 : ∀ {Γ} , Tm54 Γ nat54 := λ Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case54 zero54 suc rec => zero54 def suc54 : ∀ {Γ} , Tm54 Γ nat54 → Tm54 Γ nat54 := λ t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case54 zero54 suc54 rec => suc54 (t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case54 zero54 suc54 rec) def rec54 : ∀ {Γ A} , Tm54 Γ nat54 → Tm54 Γ (arr54 nat54 (arr54 A A)) → Tm54 Γ A → Tm54 Γ A := λ t u v Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case54 zero54 suc54 rec54 => rec54 (t Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case54 zero54 suc54 rec54) (u Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case54 zero54 suc54 rec54) (v Tm54 var54 lam54 app54 tt54 pair54 fst54 snd54 left54 right54 case54 zero54 suc54 rec54) def v054 : ∀ {Γ A}, Tm54 (snoc54 Γ A) A := var54 vz54 def v154 : ∀ {Γ A B}, Tm54 (snoc54 (snoc54 Γ A) B) A := var54 (vs54 vz54) def v254 : ∀ {Γ A B C}, Tm54 (snoc54 (snoc54 (snoc54 Γ A) B) C) A := var54 (vs54 (vs54 vz54)) def v354 : ∀ {Γ A B C D}, Tm54 (snoc54 (snoc54 (snoc54 (snoc54 Γ A) B) C) D) A := var54 (vs54 (vs54 (vs54 vz54))) def tbool54 : Ty54 := sum54 top54 top54 def ttrue54 : ∀ {Γ}, Tm54 Γ tbool54 := left54 tt54 def tfalse54 : ∀ {Γ}, Tm54 Γ tbool54 := right54 tt54 def ifthenelse54 : ∀ {Γ A}, Tm54 Γ (arr54 tbool54 (arr54 A (arr54 A A))) := lam54 (lam54 (lam54 (case54 v254 (lam54 v254) (lam54 v154)))) def times454 : ∀ {Γ A}, Tm54 Γ (arr54 (arr54 A A) (arr54 A A)) := lam54 (lam54 (app54 v154 (app54 v154 (app54 v154 (app54 v154 v054))))) def add54 : ∀ {Γ}, Tm54 Γ (arr54 nat54 (arr54 nat54 nat54)) := lam54 (rec54 v054 (lam54 (lam54 (lam54 (suc54 (app54 v154 v054))))) (lam54 v054)) def mul54 : ∀ {Γ}, Tm54 Γ (arr54 nat54 (arr54 nat54 nat54)) := lam54 (rec54 v054 (lam54 (lam54 (lam54 (app54 (app54 add54 (app54 v154 v054)) v054)))) (lam54 zero54)) def fact54 : ∀ {Γ}, Tm54 Γ (arr54 nat54 nat54) := lam54 (rec54 v054 (lam54 (lam54 (app54 (app54 mul54 (suc54 v154)) v054))) (suc54 zero54)) def Ty55 : Type 1 := ∀ (Ty55 : Type) (nat top bot : Ty55) (arr prod sum : Ty55 → Ty55 → Ty55) , Ty55 def nat55 : Ty55 := λ _ nat55 _ _ _ _ _ => nat55 def top55 : Ty55 := λ _ _ top55 _ _ _ _ => top55 def bot55 : Ty55 := λ _ _ _ bot55 _ _ _ => bot55 def arr55 : Ty55 → Ty55 → Ty55 := λ A B Ty55 nat55 top55 bot55 arr55 prod sum => arr55 (A Ty55 nat55 top55 bot55 arr55 prod sum) (B Ty55 nat55 top55 bot55 arr55 prod sum) def prod55 : Ty55 → Ty55 → Ty55 := λ A B Ty55 nat55 top55 bot55 arr55 prod55 sum => prod55 (A Ty55 nat55 top55 bot55 arr55 prod55 sum) (B Ty55 nat55 top55 bot55 arr55 prod55 sum) def sum55 : Ty55 → Ty55 → Ty55 := λ A B Ty55 nat55 top55 bot55 arr55 prod55 sum55 => sum55 (A Ty55 nat55 top55 bot55 arr55 prod55 sum55) (B Ty55 nat55 top55 bot55 arr55 prod55 sum55) def Con55 : Type 1 := ∀ (Con55 : Type) (nil : Con55) (snoc : Con55 → Ty55 → Con55) , Con55 def nil55 : Con55 := λ Con55 nil55 snoc => nil55 def snoc55 : Con55 → Ty55 → Con55 := λ Γ A Con55 nil55 snoc55 => snoc55 (Γ Con55 nil55 snoc55) A def Var55 : Con55 → Ty55 → Type 1 := λ Γ A => ∀ (Var55 : Con55 → Ty55 → Type) (vz : ∀{Γ A}, Var55 (snoc55 Γ A) A) (vs : ∀{Γ B A}, Var55 Γ A → Var55 (snoc55 Γ B) A) , Var55 Γ A def vz55 : ∀ {Γ A}, Var55 (snoc55 Γ A) A := λ Var55 vz55 vs => vz55 def vs55 : ∀ {Γ B A}, Var55 Γ A → Var55 (snoc55 Γ B) A := λ x Var55 vz55 vs55 => vs55 (x Var55 vz55 vs55) def Tm55 : Con55 → Ty55 → Type 1 := λ Γ A => ∀ (Tm55 : Con55 → Ty55 → Type) (var : ∀ {Γ A}, Var55 Γ A → Tm55 Γ A) (lam : ∀ {Γ A B}, (Tm55 (snoc55 Γ A) B → Tm55 Γ (arr55 A B))) (app : ∀ {Γ A B} , Tm55 Γ (arr55 A B) → Tm55 Γ A → Tm55 Γ B) (tt : ∀ {Γ} , Tm55 Γ top55) (pair : ∀ {Γ A B} , Tm55 Γ A → Tm55 Γ B → Tm55 Γ (prod55 A B)) (fst : ∀ {Γ A B} , Tm55 Γ (prod55 A B) → Tm55 Γ A) (snd : ∀ {Γ A B} , Tm55 Γ (prod55 A B) → Tm55 Γ B) (left : ∀ {Γ A B} , Tm55 Γ A → Tm55 Γ (sum55 A B)) (right : ∀ {Γ A B} , Tm55 Γ B → Tm55 Γ (sum55 A B)) (case : ∀ {Γ A B C} , Tm55 Γ (sum55 A B) → Tm55 Γ (arr55 A C) → Tm55 Γ (arr55 B C) → Tm55 Γ C) (zero : ∀ {Γ} , Tm55 Γ nat55) (suc : ∀ {Γ} , Tm55 Γ nat55 → Tm55 Γ nat55) (rec : ∀ {Γ A} , Tm55 Γ nat55 → Tm55 Γ (arr55 nat55 (arr55 A A)) → Tm55 Γ A → Tm55 Γ A) , Tm55 Γ A def var55 : ∀ {Γ A}, Var55 Γ A → Tm55 Γ A := λ x Tm55 var55 lam app tt pair fst snd left right case zero suc rec => var55 x def lam55 : ∀ {Γ A B} , Tm55 (snoc55 Γ A) B → Tm55 Γ (arr55 A B) := λ t Tm55 var55 lam55 app tt pair fst snd left right case zero suc rec => lam55 (t Tm55 var55 lam55 app tt pair fst snd left right case zero suc rec) def app55 : ∀ {Γ A B} , Tm55 Γ (arr55 A B) → Tm55 Γ A → Tm55 Γ B := λ t u Tm55 var55 lam55 app55 tt pair fst snd left right case zero suc rec => app55 (t Tm55 var55 lam55 app55 tt pair fst snd left right case zero suc rec) (u Tm55 var55 lam55 app55 tt pair fst snd left right case zero suc rec) def tt55 : ∀ {Γ} , Tm55 Γ top55 := λ Tm55 var55 lam55 app55 tt55 pair fst snd left right case zero suc rec => tt55 def pair55 : ∀ {Γ A B} , Tm55 Γ A → Tm55 Γ B → Tm55 Γ (prod55 A B) := λ t u Tm55 var55 lam55 app55 tt55 pair55 fst snd left right case zero suc rec => pair55 (t Tm55 var55 lam55 app55 tt55 pair55 fst snd left right case zero suc rec) (u Tm55 var55 lam55 app55 tt55 pair55 fst snd left right case zero suc rec) def fst55 : ∀ {Γ A B} , Tm55 Γ (prod55 A B) → Tm55 Γ A := λ t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd left right case zero suc rec => fst55 (t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd left right case zero suc rec) def snd55 : ∀ {Γ A B} , Tm55 Γ (prod55 A B) → Tm55 Γ B := λ t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left right case zero suc rec => snd55 (t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left right case zero suc rec) def left55 : ∀ {Γ A B} , Tm55 Γ A → Tm55 Γ (sum55 A B) := λ t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right case zero suc rec => left55 (t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right case zero suc rec) def right55 : ∀ {Γ A B} , Tm55 Γ B → Tm55 Γ (sum55 A B) := λ t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case zero suc rec => right55 (t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case zero suc rec) def case55 : ∀ {Γ A B C} , Tm55 Γ (sum55 A B) → Tm55 Γ (arr55 A C) → Tm55 Γ (arr55 B C) → Tm55 Γ C := λ t u v Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case55 zero suc rec => case55 (t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case55 zero suc rec) (u Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case55 zero suc rec) (v Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case55 zero suc rec) def zero55 : ∀ {Γ} , Tm55 Γ nat55 := λ Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case55 zero55 suc rec => zero55 def suc55 : ∀ {Γ} , Tm55 Γ nat55 → Tm55 Γ nat55 := λ t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case55 zero55 suc55 rec => suc55 (t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case55 zero55 suc55 rec) def rec55 : ∀ {Γ A} , Tm55 Γ nat55 → Tm55 Γ (arr55 nat55 (arr55 A A)) → Tm55 Γ A → Tm55 Γ A := λ t u v Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case55 zero55 suc55 rec55 => rec55 (t Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case55 zero55 suc55 rec55) (u Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case55 zero55 suc55 rec55) (v Tm55 var55 lam55 app55 tt55 pair55 fst55 snd55 left55 right55 case55 zero55 suc55 rec55) def v055 : ∀ {Γ A}, Tm55 (snoc55 Γ A) A := var55 vz55 def v155 : ∀ {Γ A B}, Tm55 (snoc55 (snoc55 Γ A) B) A := var55 (vs55 vz55) def v255 : ∀ {Γ A B C}, Tm55 (snoc55 (snoc55 (snoc55 Γ A) B) C) A := var55 (vs55 (vs55 vz55)) def v355 : ∀ {Γ A B C D}, Tm55 (snoc55 (snoc55 (snoc55 (snoc55 Γ A) B) C) D) A := var55 (vs55 (vs55 (vs55 vz55))) def tbool55 : Ty55 := sum55 top55 top55 def ttrue55 : ∀ {Γ}, Tm55 Γ tbool55 := left55 tt55 def tfalse55 : ∀ {Γ}, Tm55 Γ tbool55 := right55 tt55 def ifthenelse55 : ∀ {Γ A}, Tm55 Γ (arr55 tbool55 (arr55 A (arr55 A A))) := lam55 (lam55 (lam55 (case55 v255 (lam55 v255) (lam55 v155)))) def times455 : ∀ {Γ A}, Tm55 Γ (arr55 (arr55 A A) (arr55 A A)) := lam55 (lam55 (app55 v155 (app55 v155 (app55 v155 (app55 v155 v055))))) def add55 : ∀ {Γ}, Tm55 Γ (arr55 nat55 (arr55 nat55 nat55)) := lam55 (rec55 v055 (lam55 (lam55 (lam55 (suc55 (app55 v155 v055))))) (lam55 v055)) def mul55 : ∀ {Γ}, Tm55 Γ (arr55 nat55 (arr55 nat55 nat55)) := lam55 (rec55 v055 (lam55 (lam55 (lam55 (app55 (app55 add55 (app55 v155 v055)) v055)))) (lam55 zero55)) def fact55 : ∀ {Γ}, Tm55 Γ (arr55 nat55 nat55) := lam55 (rec55 v055 (lam55 (lam55 (app55 (app55 mul55 (suc55 v155)) v055))) (suc55 zero55)) def Ty56 : Type 1 := ∀ (Ty56 : Type) (nat top bot : Ty56) (arr prod sum : Ty56 → Ty56 → Ty56) , Ty56 def nat56 : Ty56 := λ _ nat56 _ _ _ _ _ => nat56 def top56 : Ty56 := λ _ _ top56 _ _ _ _ => top56 def bot56 : Ty56 := λ _ _ _ bot56 _ _ _ => bot56 def arr56 : Ty56 → Ty56 → Ty56 := λ A B Ty56 nat56 top56 bot56 arr56 prod sum => arr56 (A Ty56 nat56 top56 bot56 arr56 prod sum) (B Ty56 nat56 top56 bot56 arr56 prod sum) def prod56 : Ty56 → Ty56 → Ty56 := λ A B Ty56 nat56 top56 bot56 arr56 prod56 sum => prod56 (A Ty56 nat56 top56 bot56 arr56 prod56 sum) (B Ty56 nat56 top56 bot56 arr56 prod56 sum) def sum56 : Ty56 → Ty56 → Ty56 := λ A B Ty56 nat56 top56 bot56 arr56 prod56 sum56 => sum56 (A Ty56 nat56 top56 bot56 arr56 prod56 sum56) (B Ty56 nat56 top56 bot56 arr56 prod56 sum56) def Con56 : Type 1 := ∀ (Con56 : Type) (nil : Con56) (snoc : Con56 → Ty56 → Con56) , Con56 def nil56 : Con56 := λ Con56 nil56 snoc => nil56 def snoc56 : Con56 → Ty56 → Con56 := λ Γ A Con56 nil56 snoc56 => snoc56 (Γ Con56 nil56 snoc56) A def Var56 : Con56 → Ty56 → Type 1 := λ Γ A => ∀ (Var56 : Con56 → Ty56 → Type) (vz : ∀{Γ A}, Var56 (snoc56 Γ A) A) (vs : ∀{Γ B A}, Var56 Γ A → Var56 (snoc56 Γ B) A) , Var56 Γ A def vz56 : ∀ {Γ A}, Var56 (snoc56 Γ A) A := λ Var56 vz56 vs => vz56 def vs56 : ∀ {Γ B A}, Var56 Γ A → Var56 (snoc56 Γ B) A := λ x Var56 vz56 vs56 => vs56 (x Var56 vz56 vs56) def Tm56 : Con56 → Ty56 → Type 1 := λ Γ A => ∀ (Tm56 : Con56 → Ty56 → Type) (var : ∀ {Γ A}, Var56 Γ A → Tm56 Γ A) (lam : ∀ {Γ A B}, (Tm56 (snoc56 Γ A) B → Tm56 Γ (arr56 A B))) (app : ∀ {Γ A B} , Tm56 Γ (arr56 A B) → Tm56 Γ A → Tm56 Γ B) (tt : ∀ {Γ} , Tm56 Γ top56) (pair : ∀ {Γ A B} , Tm56 Γ A → Tm56 Γ B → Tm56 Γ (prod56 A B)) (fst : ∀ {Γ A B} , Tm56 Γ (prod56 A B) → Tm56 Γ A) (snd : ∀ {Γ A B} , Tm56 Γ (prod56 A B) → Tm56 Γ B) (left : ∀ {Γ A B} , Tm56 Γ A → Tm56 Γ (sum56 A B)) (right : ∀ {Γ A B} , Tm56 Γ B → Tm56 Γ (sum56 A B)) (case : ∀ {Γ A B C} , Tm56 Γ (sum56 A B) → Tm56 Γ (arr56 A C) → Tm56 Γ (arr56 B C) → Tm56 Γ C) (zero : ∀ {Γ} , Tm56 Γ nat56) (suc : ∀ {Γ} , Tm56 Γ nat56 → Tm56 Γ nat56) (rec : ∀ {Γ A} , Tm56 Γ nat56 → Tm56 Γ (arr56 nat56 (arr56 A A)) → Tm56 Γ A → Tm56 Γ A) , Tm56 Γ A def var56 : ∀ {Γ A}, Var56 Γ A → Tm56 Γ A := λ x Tm56 var56 lam app tt pair fst snd left right case zero suc rec => var56 x def lam56 : ∀ {Γ A B} , Tm56 (snoc56 Γ A) B → Tm56 Γ (arr56 A B) := λ t Tm56 var56 lam56 app tt pair fst snd left right case zero suc rec => lam56 (t Tm56 var56 lam56 app tt pair fst snd left right case zero suc rec) def app56 : ∀ {Γ A B} , Tm56 Γ (arr56 A B) → Tm56 Γ A → Tm56 Γ B := λ t u Tm56 var56 lam56 app56 tt pair fst snd left right case zero suc rec => app56 (t Tm56 var56 lam56 app56 tt pair fst snd left right case zero suc rec) (u Tm56 var56 lam56 app56 tt pair fst snd left right case zero suc rec) def tt56 : ∀ {Γ} , Tm56 Γ top56 := λ Tm56 var56 lam56 app56 tt56 pair fst snd left right case zero suc rec => tt56 def pair56 : ∀ {Γ A B} , Tm56 Γ A → Tm56 Γ B → Tm56 Γ (prod56 A B) := λ t u Tm56 var56 lam56 app56 tt56 pair56 fst snd left right case zero suc rec => pair56 (t Tm56 var56 lam56 app56 tt56 pair56 fst snd left right case zero suc rec) (u Tm56 var56 lam56 app56 tt56 pair56 fst snd left right case zero suc rec) def fst56 : ∀ {Γ A B} , Tm56 Γ (prod56 A B) → Tm56 Γ A := λ t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd left right case zero suc rec => fst56 (t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd left right case zero suc rec) def snd56 : ∀ {Γ A B} , Tm56 Γ (prod56 A B) → Tm56 Γ B := λ t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left right case zero suc rec => snd56 (t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left right case zero suc rec) def left56 : ∀ {Γ A B} , Tm56 Γ A → Tm56 Γ (sum56 A B) := λ t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right case zero suc rec => left56 (t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right case zero suc rec) def right56 : ∀ {Γ A B} , Tm56 Γ B → Tm56 Γ (sum56 A B) := λ t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case zero suc rec => right56 (t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case zero suc rec) def case56 : ∀ {Γ A B C} , Tm56 Γ (sum56 A B) → Tm56 Γ (arr56 A C) → Tm56 Γ (arr56 B C) → Tm56 Γ C := λ t u v Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case56 zero suc rec => case56 (t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case56 zero suc rec) (u Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case56 zero suc rec) (v Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case56 zero suc rec) def zero56 : ∀ {Γ} , Tm56 Γ nat56 := λ Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case56 zero56 suc rec => zero56 def suc56 : ∀ {Γ} , Tm56 Γ nat56 → Tm56 Γ nat56 := λ t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case56 zero56 suc56 rec => suc56 (t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case56 zero56 suc56 rec) def rec56 : ∀ {Γ A} , Tm56 Γ nat56 → Tm56 Γ (arr56 nat56 (arr56 A A)) → Tm56 Γ A → Tm56 Γ A := λ t u v Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case56 zero56 suc56 rec56 => rec56 (t Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case56 zero56 suc56 rec56) (u Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case56 zero56 suc56 rec56) (v Tm56 var56 lam56 app56 tt56 pair56 fst56 snd56 left56 right56 case56 zero56 suc56 rec56) def v056 : ∀ {Γ A}, Tm56 (snoc56 Γ A) A := var56 vz56 def v156 : ∀ {Γ A B}, Tm56 (snoc56 (snoc56 Γ A) B) A := var56 (vs56 vz56) def v256 : ∀ {Γ A B C}, Tm56 (snoc56 (snoc56 (snoc56 Γ A) B) C) A := var56 (vs56 (vs56 vz56)) def v356 : ∀ {Γ A B C D}, Tm56 (snoc56 (snoc56 (snoc56 (snoc56 Γ A) B) C) D) A := var56 (vs56 (vs56 (vs56 vz56))) def tbool56 : Ty56 := sum56 top56 top56 def ttrue56 : ∀ {Γ}, Tm56 Γ tbool56 := left56 tt56 def tfalse56 : ∀ {Γ}, Tm56 Γ tbool56 := right56 tt56 def ifthenelse56 : ∀ {Γ A}, Tm56 Γ (arr56 tbool56 (arr56 A (arr56 A A))) := lam56 (lam56 (lam56 (case56 v256 (lam56 v256) (lam56 v156)))) def times456 : ∀ {Γ A}, Tm56 Γ (arr56 (arr56 A A) (arr56 A A)) := lam56 (lam56 (app56 v156 (app56 v156 (app56 v156 (app56 v156 v056))))) def add56 : ∀ {Γ}, Tm56 Γ (arr56 nat56 (arr56 nat56 nat56)) := lam56 (rec56 v056 (lam56 (lam56 (lam56 (suc56 (app56 v156 v056))))) (lam56 v056)) def mul56 : ∀ {Γ}, Tm56 Γ (arr56 nat56 (arr56 nat56 nat56)) := lam56 (rec56 v056 (lam56 (lam56 (lam56 (app56 (app56 add56 (app56 v156 v056)) v056)))) (lam56 zero56)) def fact56 : ∀ {Γ}, Tm56 Γ (arr56 nat56 nat56) := lam56 (rec56 v056 (lam56 (lam56 (app56 (app56 mul56 (suc56 v156)) v056))) (suc56 zero56)) def Ty57 : Type 1 := ∀ (Ty57 : Type) (nat top bot : Ty57) (arr prod sum : Ty57 → Ty57 → Ty57) , Ty57 def nat57 : Ty57 := λ _ nat57 _ _ _ _ _ => nat57 def top57 : Ty57 := λ _ _ top57 _ _ _ _ => top57 def bot57 : Ty57 := λ _ _ _ bot57 _ _ _ => bot57 def arr57 : Ty57 → Ty57 → Ty57 := λ A B Ty57 nat57 top57 bot57 arr57 prod sum => arr57 (A Ty57 nat57 top57 bot57 arr57 prod sum) (B Ty57 nat57 top57 bot57 arr57 prod sum) def prod57 : Ty57 → Ty57 → Ty57 := λ A B Ty57 nat57 top57 bot57 arr57 prod57 sum => prod57 (A Ty57 nat57 top57 bot57 arr57 prod57 sum) (B Ty57 nat57 top57 bot57 arr57 prod57 sum) def sum57 : Ty57 → Ty57 → Ty57 := λ A B Ty57 nat57 top57 bot57 arr57 prod57 sum57 => sum57 (A Ty57 nat57 top57 bot57 arr57 prod57 sum57) (B Ty57 nat57 top57 bot57 arr57 prod57 sum57) def Con57 : Type 1 := ∀ (Con57 : Type) (nil : Con57) (snoc : Con57 → Ty57 → Con57) , Con57 def nil57 : Con57 := λ Con57 nil57 snoc => nil57 def snoc57 : Con57 → Ty57 → Con57 := λ Γ A Con57 nil57 snoc57 => snoc57 (Γ Con57 nil57 snoc57) A def Var57 : Con57 → Ty57 → Type 1 := λ Γ A => ∀ (Var57 : Con57 → Ty57 → Type) (vz : ∀{Γ A}, Var57 (snoc57 Γ A) A) (vs : ∀{Γ B A}, Var57 Γ A → Var57 (snoc57 Γ B) A) , Var57 Γ A def vz57 : ∀ {Γ A}, Var57 (snoc57 Γ A) A := λ Var57 vz57 vs => vz57 def vs57 : ∀ {Γ B A}, Var57 Γ A → Var57 (snoc57 Γ B) A := λ x Var57 vz57 vs57 => vs57 (x Var57 vz57 vs57) def Tm57 : Con57 → Ty57 → Type 1 := λ Γ A => ∀ (Tm57 : Con57 → Ty57 → Type) (var : ∀ {Γ A}, Var57 Γ A → Tm57 Γ A) (lam : ∀ {Γ A B}, (Tm57 (snoc57 Γ A) B → Tm57 Γ (arr57 A B))) (app : ∀ {Γ A B} , Tm57 Γ (arr57 A B) → Tm57 Γ A → Tm57 Γ B) (tt : ∀ {Γ} , Tm57 Γ top57) (pair : ∀ {Γ A B} , Tm57 Γ A → Tm57 Γ B → Tm57 Γ (prod57 A B)) (fst : ∀ {Γ A B} , Tm57 Γ (prod57 A B) → Tm57 Γ A) (snd : ∀ {Γ A B} , Tm57 Γ (prod57 A B) → Tm57 Γ B) (left : ∀ {Γ A B} , Tm57 Γ A → Tm57 Γ (sum57 A B)) (right : ∀ {Γ A B} , Tm57 Γ B → Tm57 Γ (sum57 A B)) (case : ∀ {Γ A B C} , Tm57 Γ (sum57 A B) → Tm57 Γ (arr57 A C) → Tm57 Γ (arr57 B C) → Tm57 Γ C) (zero : ∀ {Γ} , Tm57 Γ nat57) (suc : ∀ {Γ} , Tm57 Γ nat57 → Tm57 Γ nat57) (rec : ∀ {Γ A} , Tm57 Γ nat57 → Tm57 Γ (arr57 nat57 (arr57 A A)) → Tm57 Γ A → Tm57 Γ A) , Tm57 Γ A def var57 : ∀ {Γ A}, Var57 Γ A → Tm57 Γ A := λ x Tm57 var57 lam app tt pair fst snd left right case zero suc rec => var57 x def lam57 : ∀ {Γ A B} , Tm57 (snoc57 Γ A) B → Tm57 Γ (arr57 A B) := λ t Tm57 var57 lam57 app tt pair fst snd left right case zero suc rec => lam57 (t Tm57 var57 lam57 app tt pair fst snd left right case zero suc rec) def app57 : ∀ {Γ A B} , Tm57 Γ (arr57 A B) → Tm57 Γ A → Tm57 Γ B := λ t u Tm57 var57 lam57 app57 tt pair fst snd left right case zero suc rec => app57 (t Tm57 var57 lam57 app57 tt pair fst snd left right case zero suc rec) (u Tm57 var57 lam57 app57 tt pair fst snd left right case zero suc rec) def tt57 : ∀ {Γ} , Tm57 Γ top57 := λ Tm57 var57 lam57 app57 tt57 pair fst snd left right case zero suc rec => tt57 def pair57 : ∀ {Γ A B} , Tm57 Γ A → Tm57 Γ B → Tm57 Γ (prod57 A B) := λ t u Tm57 var57 lam57 app57 tt57 pair57 fst snd left right case zero suc rec => pair57 (t Tm57 var57 lam57 app57 tt57 pair57 fst snd left right case zero suc rec) (u Tm57 var57 lam57 app57 tt57 pair57 fst snd left right case zero suc rec) def fst57 : ∀ {Γ A B} , Tm57 Γ (prod57 A B) → Tm57 Γ A := λ t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd left right case zero suc rec => fst57 (t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd left right case zero suc rec) def snd57 : ∀ {Γ A B} , Tm57 Γ (prod57 A B) → Tm57 Γ B := λ t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left right case zero suc rec => snd57 (t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left right case zero suc rec) def left57 : ∀ {Γ A B} , Tm57 Γ A → Tm57 Γ (sum57 A B) := λ t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right case zero suc rec => left57 (t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right case zero suc rec) def right57 : ∀ {Γ A B} , Tm57 Γ B → Tm57 Γ (sum57 A B) := λ t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case zero suc rec => right57 (t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case zero suc rec) def case57 : ∀ {Γ A B C} , Tm57 Γ (sum57 A B) → Tm57 Γ (arr57 A C) → Tm57 Γ (arr57 B C) → Tm57 Γ C := λ t u v Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case57 zero suc rec => case57 (t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case57 zero suc rec) (u Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case57 zero suc rec) (v Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case57 zero suc rec) def zero57 : ∀ {Γ} , Tm57 Γ nat57 := λ Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case57 zero57 suc rec => zero57 def suc57 : ∀ {Γ} , Tm57 Γ nat57 → Tm57 Γ nat57 := λ t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case57 zero57 suc57 rec => suc57 (t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case57 zero57 suc57 rec) def rec57 : ∀ {Γ A} , Tm57 Γ nat57 → Tm57 Γ (arr57 nat57 (arr57 A A)) → Tm57 Γ A → Tm57 Γ A := λ t u v Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case57 zero57 suc57 rec57 => rec57 (t Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case57 zero57 suc57 rec57) (u Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case57 zero57 suc57 rec57) (v Tm57 var57 lam57 app57 tt57 pair57 fst57 snd57 left57 right57 case57 zero57 suc57 rec57) def v057 : ∀ {Γ A}, Tm57 (snoc57 Γ A) A := var57 vz57 def v157 : ∀ {Γ A B}, Tm57 (snoc57 (snoc57 Γ A) B) A := var57 (vs57 vz57) def v257 : ∀ {Γ A B C}, Tm57 (snoc57 (snoc57 (snoc57 Γ A) B) C) A := var57 (vs57 (vs57 vz57)) def v357 : ∀ {Γ A B C D}, Tm57 (snoc57 (snoc57 (snoc57 (snoc57 Γ A) B) C) D) A := var57 (vs57 (vs57 (vs57 vz57))) def tbool57 : Ty57 := sum57 top57 top57 def ttrue57 : ∀ {Γ}, Tm57 Γ tbool57 := left57 tt57 def tfalse57 : ∀ {Γ}, Tm57 Γ tbool57 := right57 tt57 def ifthenelse57 : ∀ {Γ A}, Tm57 Γ (arr57 tbool57 (arr57 A (arr57 A A))) := lam57 (lam57 (lam57 (case57 v257 (lam57 v257) (lam57 v157)))) def times457 : ∀ {Γ A}, Tm57 Γ (arr57 (arr57 A A) (arr57 A A)) := lam57 (lam57 (app57 v157 (app57 v157 (app57 v157 (app57 v157 v057))))) def add57 : ∀ {Γ}, Tm57 Γ (arr57 nat57 (arr57 nat57 nat57)) := lam57 (rec57 v057 (lam57 (lam57 (lam57 (suc57 (app57 v157 v057))))) (lam57 v057)) def mul57 : ∀ {Γ}, Tm57 Γ (arr57 nat57 (arr57 nat57 nat57)) := lam57 (rec57 v057 (lam57 (lam57 (lam57 (app57 (app57 add57 (app57 v157 v057)) v057)))) (lam57 zero57)) def fact57 : ∀ {Γ}, Tm57 Γ (arr57 nat57 nat57) := lam57 (rec57 v057 (lam57 (lam57 (app57 (app57 mul57 (suc57 v157)) v057))) (suc57 zero57)) def Ty58 : Type 1 := ∀ (Ty58 : Type) (nat top bot : Ty58) (arr prod sum : Ty58 → Ty58 → Ty58) , Ty58 def nat58 : Ty58 := λ _ nat58 _ _ _ _ _ => nat58 def top58 : Ty58 := λ _ _ top58 _ _ _ _ => top58 def bot58 : Ty58 := λ _ _ _ bot58 _ _ _ => bot58 def arr58 : Ty58 → Ty58 → Ty58 := λ A B Ty58 nat58 top58 bot58 arr58 prod sum => arr58 (A Ty58 nat58 top58 bot58 arr58 prod sum) (B Ty58 nat58 top58 bot58 arr58 prod sum) def prod58 : Ty58 → Ty58 → Ty58 := λ A B Ty58 nat58 top58 bot58 arr58 prod58 sum => prod58 (A Ty58 nat58 top58 bot58 arr58 prod58 sum) (B Ty58 nat58 top58 bot58 arr58 prod58 sum) def sum58 : Ty58 → Ty58 → Ty58 := λ A B Ty58 nat58 top58 bot58 arr58 prod58 sum58 => sum58 (A Ty58 nat58 top58 bot58 arr58 prod58 sum58) (B Ty58 nat58 top58 bot58 arr58 prod58 sum58) def Con58 : Type 1 := ∀ (Con58 : Type) (nil : Con58) (snoc : Con58 → Ty58 → Con58) , Con58 def nil58 : Con58 := λ Con58 nil58 snoc => nil58 def snoc58 : Con58 → Ty58 → Con58 := λ Γ A Con58 nil58 snoc58 => snoc58 (Γ Con58 nil58 snoc58) A def Var58 : Con58 → Ty58 → Type 1 := λ Γ A => ∀ (Var58 : Con58 → Ty58 → Type) (vz : ∀{Γ A}, Var58 (snoc58 Γ A) A) (vs : ∀{Γ B A}, Var58 Γ A → Var58 (snoc58 Γ B) A) , Var58 Γ A def vz58 : ∀ {Γ A}, Var58 (snoc58 Γ A) A := λ Var58 vz58 vs => vz58 def vs58 : ∀ {Γ B A}, Var58 Γ A → Var58 (snoc58 Γ B) A := λ x Var58 vz58 vs58 => vs58 (x Var58 vz58 vs58) def Tm58 : Con58 → Ty58 → Type 1 := λ Γ A => ∀ (Tm58 : Con58 → Ty58 → Type) (var : ∀ {Γ A}, Var58 Γ A → Tm58 Γ A) (lam : ∀ {Γ A B}, (Tm58 (snoc58 Γ A) B → Tm58 Γ (arr58 A B))) (app : ∀ {Γ A B} , Tm58 Γ (arr58 A B) → Tm58 Γ A → Tm58 Γ B) (tt : ∀ {Γ} , Tm58 Γ top58) (pair : ∀ {Γ A B} , Tm58 Γ A → Tm58 Γ B → Tm58 Γ (prod58 A B)) (fst : ∀ {Γ A B} , Tm58 Γ (prod58 A B) → Tm58 Γ A) (snd : ∀ {Γ A B} , Tm58 Γ (prod58 A B) → Tm58 Γ B) (left : ∀ {Γ A B} , Tm58 Γ A → Tm58 Γ (sum58 A B)) (right : ∀ {Γ A B} , Tm58 Γ B → Tm58 Γ (sum58 A B)) (case : ∀ {Γ A B C} , Tm58 Γ (sum58 A B) → Tm58 Γ (arr58 A C) → Tm58 Γ (arr58 B C) → Tm58 Γ C) (zero : ∀ {Γ} , Tm58 Γ nat58) (suc : ∀ {Γ} , Tm58 Γ nat58 → Tm58 Γ nat58) (rec : ∀ {Γ A} , Tm58 Γ nat58 → Tm58 Γ (arr58 nat58 (arr58 A A)) → Tm58 Γ A → Tm58 Γ A) , Tm58 Γ A def var58 : ∀ {Γ A}, Var58 Γ A → Tm58 Γ A := λ x Tm58 var58 lam app tt pair fst snd left right case zero suc rec => var58 x def lam58 : ∀ {Γ A B} , Tm58 (snoc58 Γ A) B → Tm58 Γ (arr58 A B) := λ t Tm58 var58 lam58 app tt pair fst snd left right case zero suc rec => lam58 (t Tm58 var58 lam58 app tt pair fst snd left right case zero suc rec) def app58 : ∀ {Γ A B} , Tm58 Γ (arr58 A B) → Tm58 Γ A → Tm58 Γ B := λ t u Tm58 var58 lam58 app58 tt pair fst snd left right case zero suc rec => app58 (t Tm58 var58 lam58 app58 tt pair fst snd left right case zero suc rec) (u Tm58 var58 lam58 app58 tt pair fst snd left right case zero suc rec) def tt58 : ∀ {Γ} , Tm58 Γ top58 := λ Tm58 var58 lam58 app58 tt58 pair fst snd left right case zero suc rec => tt58 def pair58 : ∀ {Γ A B} , Tm58 Γ A → Tm58 Γ B → Tm58 Γ (prod58 A B) := λ t u Tm58 var58 lam58 app58 tt58 pair58 fst snd left right case zero suc rec => pair58 (t Tm58 var58 lam58 app58 tt58 pair58 fst snd left right case zero suc rec) (u Tm58 var58 lam58 app58 tt58 pair58 fst snd left right case zero suc rec) def fst58 : ∀ {Γ A B} , Tm58 Γ (prod58 A B) → Tm58 Γ A := λ t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd left right case zero suc rec => fst58 (t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd left right case zero suc rec) def snd58 : ∀ {Γ A B} , Tm58 Γ (prod58 A B) → Tm58 Γ B := λ t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left right case zero suc rec => snd58 (t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left right case zero suc rec) def left58 : ∀ {Γ A B} , Tm58 Γ A → Tm58 Γ (sum58 A B) := λ t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right case zero suc rec => left58 (t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right case zero suc rec) def right58 : ∀ {Γ A B} , Tm58 Γ B → Tm58 Γ (sum58 A B) := λ t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case zero suc rec => right58 (t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case zero suc rec) def case58 : ∀ {Γ A B C} , Tm58 Γ (sum58 A B) → Tm58 Γ (arr58 A C) → Tm58 Γ (arr58 B C) → Tm58 Γ C := λ t u v Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case58 zero suc rec => case58 (t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case58 zero suc rec) (u Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case58 zero suc rec) (v Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case58 zero suc rec) def zero58 : ∀ {Γ} , Tm58 Γ nat58 := λ Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case58 zero58 suc rec => zero58 def suc58 : ∀ {Γ} , Tm58 Γ nat58 → Tm58 Γ nat58 := λ t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case58 zero58 suc58 rec => suc58 (t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case58 zero58 suc58 rec) def rec58 : ∀ {Γ A} , Tm58 Γ nat58 → Tm58 Γ (arr58 nat58 (arr58 A A)) → Tm58 Γ A → Tm58 Γ A := λ t u v Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case58 zero58 suc58 rec58 => rec58 (t Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case58 zero58 suc58 rec58) (u Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case58 zero58 suc58 rec58) (v Tm58 var58 lam58 app58 tt58 pair58 fst58 snd58 left58 right58 case58 zero58 suc58 rec58) def v058 : ∀ {Γ A}, Tm58 (snoc58 Γ A) A := var58 vz58 def v158 : ∀ {Γ A B}, Tm58 (snoc58 (snoc58 Γ A) B) A := var58 (vs58 vz58) def v258 : ∀ {Γ A B C}, Tm58 (snoc58 (snoc58 (snoc58 Γ A) B) C) A := var58 (vs58 (vs58 vz58)) def v358 : ∀ {Γ A B C D}, Tm58 (snoc58 (snoc58 (snoc58 (snoc58 Γ A) B) C) D) A := var58 (vs58 (vs58 (vs58 vz58))) def tbool58 : Ty58 := sum58 top58 top58 def ttrue58 : ∀ {Γ}, Tm58 Γ tbool58 := left58 tt58 def tfalse58 : ∀ {Γ}, Tm58 Γ tbool58 := right58 tt58 def ifthenelse58 : ∀ {Γ A}, Tm58 Γ (arr58 tbool58 (arr58 A (arr58 A A))) := lam58 (lam58 (lam58 (case58 v258 (lam58 v258) (lam58 v158)))) def times458 : ∀ {Γ A}, Tm58 Γ (arr58 (arr58 A A) (arr58 A A)) := lam58 (lam58 (app58 v158 (app58 v158 (app58 v158 (app58 v158 v058))))) def add58 : ∀ {Γ}, Tm58 Γ (arr58 nat58 (arr58 nat58 nat58)) := lam58 (rec58 v058 (lam58 (lam58 (lam58 (suc58 (app58 v158 v058))))) (lam58 v058)) def mul58 : ∀ {Γ}, Tm58 Γ (arr58 nat58 (arr58 nat58 nat58)) := lam58 (rec58 v058 (lam58 (lam58 (lam58 (app58 (app58 add58 (app58 v158 v058)) v058)))) (lam58 zero58)) def fact58 : ∀ {Γ}, Tm58 Γ (arr58 nat58 nat58) := lam58 (rec58 v058 (lam58 (lam58 (app58 (app58 mul58 (suc58 v158)) v058))) (suc58 zero58)) def Ty59 : Type 1 := ∀ (Ty59 : Type) (nat top bot : Ty59) (arr prod sum : Ty59 → Ty59 → Ty59) , Ty59 def nat59 : Ty59 := λ _ nat59 _ _ _ _ _ => nat59 def top59 : Ty59 := λ _ _ top59 _ _ _ _ => top59 def bot59 : Ty59 := λ _ _ _ bot59 _ _ _ => bot59 def arr59 : Ty59 → Ty59 → Ty59 := λ A B Ty59 nat59 top59 bot59 arr59 prod sum => arr59 (A Ty59 nat59 top59 bot59 arr59 prod sum) (B Ty59 nat59 top59 bot59 arr59 prod sum) def prod59 : Ty59 → Ty59 → Ty59 := λ A B Ty59 nat59 top59 bot59 arr59 prod59 sum => prod59 (A Ty59 nat59 top59 bot59 arr59 prod59 sum) (B Ty59 nat59 top59 bot59 arr59 prod59 sum) def sum59 : Ty59 → Ty59 → Ty59 := λ A B Ty59 nat59 top59 bot59 arr59 prod59 sum59 => sum59 (A Ty59 nat59 top59 bot59 arr59 prod59 sum59) (B Ty59 nat59 top59 bot59 arr59 prod59 sum59) def Con59 : Type 1 := ∀ (Con59 : Type) (nil : Con59) (snoc : Con59 → Ty59 → Con59) , Con59 def nil59 : Con59 := λ Con59 nil59 snoc => nil59 def snoc59 : Con59 → Ty59 → Con59 := λ Γ A Con59 nil59 snoc59 => snoc59 (Γ Con59 nil59 snoc59) A def Var59 : Con59 → Ty59 → Type 1 := λ Γ A => ∀ (Var59 : Con59 → Ty59 → Type) (vz : ∀{Γ A}, Var59 (snoc59 Γ A) A) (vs : ∀{Γ B A}, Var59 Γ A → Var59 (snoc59 Γ B) A) , Var59 Γ A def vz59 : ∀ {Γ A}, Var59 (snoc59 Γ A) A := λ Var59 vz59 vs => vz59 def vs59 : ∀ {Γ B A}, Var59 Γ A → Var59 (snoc59 Γ B) A := λ x Var59 vz59 vs59 => vs59 (x Var59 vz59 vs59) def Tm59 : Con59 → Ty59 → Type 1 := λ Γ A => ∀ (Tm59 : Con59 → Ty59 → Type) (var : ∀ {Γ A}, Var59 Γ A → Tm59 Γ A) (lam : ∀ {Γ A B}, (Tm59 (snoc59 Γ A) B → Tm59 Γ (arr59 A B))) (app : ∀ {Γ A B} , Tm59 Γ (arr59 A B) → Tm59 Γ A → Tm59 Γ B) (tt : ∀ {Γ} , Tm59 Γ top59) (pair : ∀ {Γ A B} , Tm59 Γ A → Tm59 Γ B → Tm59 Γ (prod59 A B)) (fst : ∀ {Γ A B} , Tm59 Γ (prod59 A B) → Tm59 Γ A) (snd : ∀ {Γ A B} , Tm59 Γ (prod59 A B) → Tm59 Γ B) (left : ∀ {Γ A B} , Tm59 Γ A → Tm59 Γ (sum59 A B)) (right : ∀ {Γ A B} , Tm59 Γ B → Tm59 Γ (sum59 A B)) (case : ∀ {Γ A B C} , Tm59 Γ (sum59 A B) → Tm59 Γ (arr59 A C) → Tm59 Γ (arr59 B C) → Tm59 Γ C) (zero : ∀ {Γ} , Tm59 Γ nat59) (suc : ∀ {Γ} , Tm59 Γ nat59 → Tm59 Γ nat59) (rec : ∀ {Γ A} , Tm59 Γ nat59 → Tm59 Γ (arr59 nat59 (arr59 A A)) → Tm59 Γ A → Tm59 Γ A) , Tm59 Γ A def var59 : ∀ {Γ A}, Var59 Γ A → Tm59 Γ A := λ x Tm59 var59 lam app tt pair fst snd left right case zero suc rec => var59 x def lam59 : ∀ {Γ A B} , Tm59 (snoc59 Γ A) B → Tm59 Γ (arr59 A B) := λ t Tm59 var59 lam59 app tt pair fst snd left right case zero suc rec => lam59 (t Tm59 var59 lam59 app tt pair fst snd left right case zero suc rec) def app59 : ∀ {Γ A B} , Tm59 Γ (arr59 A B) → Tm59 Γ A → Tm59 Γ B := λ t u Tm59 var59 lam59 app59 tt pair fst snd left right case zero suc rec => app59 (t Tm59 var59 lam59 app59 tt pair fst snd left right case zero suc rec) (u Tm59 var59 lam59 app59 tt pair fst snd left right case zero suc rec) def tt59 : ∀ {Γ} , Tm59 Γ top59 := λ Tm59 var59 lam59 app59 tt59 pair fst snd left right case zero suc rec => tt59 def pair59 : ∀ {Γ A B} , Tm59 Γ A → Tm59 Γ B → Tm59 Γ (prod59 A B) := λ t u Tm59 var59 lam59 app59 tt59 pair59 fst snd left right case zero suc rec => pair59 (t Tm59 var59 lam59 app59 tt59 pair59 fst snd left right case zero suc rec) (u Tm59 var59 lam59 app59 tt59 pair59 fst snd left right case zero suc rec) def fst59 : ∀ {Γ A B} , Tm59 Γ (prod59 A B) → Tm59 Γ A := λ t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd left right case zero suc rec => fst59 (t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd left right case zero suc rec) def snd59 : ∀ {Γ A B} , Tm59 Γ (prod59 A B) → Tm59 Γ B := λ t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left right case zero suc rec => snd59 (t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left right case zero suc rec) def left59 : ∀ {Γ A B} , Tm59 Γ A → Tm59 Γ (sum59 A B) := λ t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right case zero suc rec => left59 (t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right case zero suc rec) def right59 : ∀ {Γ A B} , Tm59 Γ B → Tm59 Γ (sum59 A B) := λ t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case zero suc rec => right59 (t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case zero suc rec) def case59 : ∀ {Γ A B C} , Tm59 Γ (sum59 A B) → Tm59 Γ (arr59 A C) → Tm59 Γ (arr59 B C) → Tm59 Γ C := λ t u v Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case59 zero suc rec => case59 (t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case59 zero suc rec) (u Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case59 zero suc rec) (v Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case59 zero suc rec) def zero59 : ∀ {Γ} , Tm59 Γ nat59 := λ Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case59 zero59 suc rec => zero59 def suc59 : ∀ {Γ} , Tm59 Γ nat59 → Tm59 Γ nat59 := λ t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case59 zero59 suc59 rec => suc59 (t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case59 zero59 suc59 rec) def rec59 : ∀ {Γ A} , Tm59 Γ nat59 → Tm59 Γ (arr59 nat59 (arr59 A A)) → Tm59 Γ A → Tm59 Γ A := λ t u v Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case59 zero59 suc59 rec59 => rec59 (t Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case59 zero59 suc59 rec59) (u Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case59 zero59 suc59 rec59) (v Tm59 var59 lam59 app59 tt59 pair59 fst59 snd59 left59 right59 case59 zero59 suc59 rec59) def v059 : ∀ {Γ A}, Tm59 (snoc59 Γ A) A := var59 vz59 def v159 : ∀ {Γ A B}, Tm59 (snoc59 (snoc59 Γ A) B) A := var59 (vs59 vz59) def v259 : ∀ {Γ A B C}, Tm59 (snoc59 (snoc59 (snoc59 Γ A) B) C) A := var59 (vs59 (vs59 vz59)) def v359 : ∀ {Γ A B C D}, Tm59 (snoc59 (snoc59 (snoc59 (snoc59 Γ A) B) C) D) A := var59 (vs59 (vs59 (vs59 vz59))) def tbool59 : Ty59 := sum59 top59 top59 def ttrue59 : ∀ {Γ}, Tm59 Γ tbool59 := left59 tt59 def tfalse59 : ∀ {Γ}, Tm59 Γ tbool59 := right59 tt59 def ifthenelse59 : ∀ {Γ A}, Tm59 Γ (arr59 tbool59 (arr59 A (arr59 A A))) := lam59 (lam59 (lam59 (case59 v259 (lam59 v259) (lam59 v159)))) def times459 : ∀ {Γ A}, Tm59 Γ (arr59 (arr59 A A) (arr59 A A)) := lam59 (lam59 (app59 v159 (app59 v159 (app59 v159 (app59 v159 v059))))) def add59 : ∀ {Γ}, Tm59 Γ (arr59 nat59 (arr59 nat59 nat59)) := lam59 (rec59 v059 (lam59 (lam59 (lam59 (suc59 (app59 v159 v059))))) (lam59 v059)) def mul59 : ∀ {Γ}, Tm59 Γ (arr59 nat59 (arr59 nat59 nat59)) := lam59 (rec59 v059 (lam59 (lam59 (lam59 (app59 (app59 add59 (app59 v159 v059)) v059)))) (lam59 zero59)) def fact59 : ∀ {Γ}, Tm59 Γ (arr59 nat59 nat59) := lam59 (rec59 v059 (lam59 (lam59 (app59 (app59 mul59 (suc59 v159)) v059))) (suc59 zero59)) def Ty60 : Type 1 := ∀ (Ty60 : Type) (nat top bot : Ty60) (arr prod sum : Ty60 → Ty60 → Ty60) , Ty60 def nat60 : Ty60 := λ _ nat60 _ _ _ _ _ => nat60 def top60 : Ty60 := λ _ _ top60 _ _ _ _ => top60 def bot60 : Ty60 := λ _ _ _ bot60 _ _ _ => bot60 def arr60 : Ty60 → Ty60 → Ty60 := λ A B Ty60 nat60 top60 bot60 arr60 prod sum => arr60 (A Ty60 nat60 top60 bot60 arr60 prod sum) (B Ty60 nat60 top60 bot60 arr60 prod sum) def prod60 : Ty60 → Ty60 → Ty60 := λ A B Ty60 nat60 top60 bot60 arr60 prod60 sum => prod60 (A Ty60 nat60 top60 bot60 arr60 prod60 sum) (B Ty60 nat60 top60 bot60 arr60 prod60 sum) def sum60 : Ty60 → Ty60 → Ty60 := λ A B Ty60 nat60 top60 bot60 arr60 prod60 sum60 => sum60 (A Ty60 nat60 top60 bot60 arr60 prod60 sum60) (B Ty60 nat60 top60 bot60 arr60 prod60 sum60) def Con60 : Type 1 := ∀ (Con60 : Type) (nil : Con60) (snoc : Con60 → Ty60 → Con60) , Con60 def nil60 : Con60 := λ Con60 nil60 snoc => nil60 def snoc60 : Con60 → Ty60 → Con60 := λ Γ A Con60 nil60 snoc60 => snoc60 (Γ Con60 nil60 snoc60) A def Var60 : Con60 → Ty60 → Type 1 := λ Γ A => ∀ (Var60 : Con60 → Ty60 → Type) (vz : ∀{Γ A}, Var60 (snoc60 Γ A) A) (vs : ∀{Γ B A}, Var60 Γ A → Var60 (snoc60 Γ B) A) , Var60 Γ A def vz60 : ∀ {Γ A}, Var60 (snoc60 Γ A) A := λ Var60 vz60 vs => vz60 def vs60 : ∀ {Γ B A}, Var60 Γ A → Var60 (snoc60 Γ B) A := λ x Var60 vz60 vs60 => vs60 (x Var60 vz60 vs60) def Tm60 : Con60 → Ty60 → Type 1 := λ Γ A => ∀ (Tm60 : Con60 → Ty60 → Type) (var : ∀ {Γ A}, Var60 Γ A → Tm60 Γ A) (lam : ∀ {Γ A B}, (Tm60 (snoc60 Γ A) B → Tm60 Γ (arr60 A B))) (app : ∀ {Γ A B} , Tm60 Γ (arr60 A B) → Tm60 Γ A → Tm60 Γ B) (tt : ∀ {Γ} , Tm60 Γ top60) (pair : ∀ {Γ A B} , Tm60 Γ A → Tm60 Γ B → Tm60 Γ (prod60 A B)) (fst : ∀ {Γ A B} , Tm60 Γ (prod60 A B) → Tm60 Γ A) (snd : ∀ {Γ A B} , Tm60 Γ (prod60 A B) → Tm60 Γ B) (left : ∀ {Γ A B} , Tm60 Γ A → Tm60 Γ (sum60 A B)) (right : ∀ {Γ A B} , Tm60 Γ B → Tm60 Γ (sum60 A B)) (case : ∀ {Γ A B C} , Tm60 Γ (sum60 A B) → Tm60 Γ (arr60 A C) → Tm60 Γ (arr60 B C) → Tm60 Γ C) (zero : ∀ {Γ} , Tm60 Γ nat60) (suc : ∀ {Γ} , Tm60 Γ nat60 → Tm60 Γ nat60) (rec : ∀ {Γ A} , Tm60 Γ nat60 → Tm60 Γ (arr60 nat60 (arr60 A A)) → Tm60 Γ A → Tm60 Γ A) , Tm60 Γ A def var60 : ∀ {Γ A}, Var60 Γ A → Tm60 Γ A := λ x Tm60 var60 lam app tt pair fst snd left right case zero suc rec => var60 x def lam60 : ∀ {Γ A B} , Tm60 (snoc60 Γ A) B → Tm60 Γ (arr60 A B) := λ t Tm60 var60 lam60 app tt pair fst snd left right case zero suc rec => lam60 (t Tm60 var60 lam60 app tt pair fst snd left right case zero suc rec) def app60 : ∀ {Γ A B} , Tm60 Γ (arr60 A B) → Tm60 Γ A → Tm60 Γ B := λ t u Tm60 var60 lam60 app60 tt pair fst snd left right case zero suc rec => app60 (t Tm60 var60 lam60 app60 tt pair fst snd left right case zero suc rec) (u Tm60 var60 lam60 app60 tt pair fst snd left right case zero suc rec) def tt60 : ∀ {Γ} , Tm60 Γ top60 := λ Tm60 var60 lam60 app60 tt60 pair fst snd left right case zero suc rec => tt60 def pair60 : ∀ {Γ A B} , Tm60 Γ A → Tm60 Γ B → Tm60 Γ (prod60 A B) := λ t u Tm60 var60 lam60 app60 tt60 pair60 fst snd left right case zero suc rec => pair60 (t Tm60 var60 lam60 app60 tt60 pair60 fst snd left right case zero suc rec) (u Tm60 var60 lam60 app60 tt60 pair60 fst snd left right case zero suc rec) def fst60 : ∀ {Γ A B} , Tm60 Γ (prod60 A B) → Tm60 Γ A := λ t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd left right case zero suc rec => fst60 (t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd left right case zero suc rec) def snd60 : ∀ {Γ A B} , Tm60 Γ (prod60 A B) → Tm60 Γ B := λ t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left right case zero suc rec => snd60 (t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left right case zero suc rec) def left60 : ∀ {Γ A B} , Tm60 Γ A → Tm60 Γ (sum60 A B) := λ t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right case zero suc rec => left60 (t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right case zero suc rec) def right60 : ∀ {Γ A B} , Tm60 Γ B → Tm60 Γ (sum60 A B) := λ t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case zero suc rec => right60 (t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case zero suc rec) def case60 : ∀ {Γ A B C} , Tm60 Γ (sum60 A B) → Tm60 Γ (arr60 A C) → Tm60 Γ (arr60 B C) → Tm60 Γ C := λ t u v Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case60 zero suc rec => case60 (t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case60 zero suc rec) (u Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case60 zero suc rec) (v Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case60 zero suc rec) def zero60 : ∀ {Γ} , Tm60 Γ nat60 := λ Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case60 zero60 suc rec => zero60 def suc60 : ∀ {Γ} , Tm60 Γ nat60 → Tm60 Γ nat60 := λ t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case60 zero60 suc60 rec => suc60 (t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case60 zero60 suc60 rec) def rec60 : ∀ {Γ A} , Tm60 Γ nat60 → Tm60 Γ (arr60 nat60 (arr60 A A)) → Tm60 Γ A → Tm60 Γ A := λ t u v Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case60 zero60 suc60 rec60 => rec60 (t Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case60 zero60 suc60 rec60) (u Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case60 zero60 suc60 rec60) (v Tm60 var60 lam60 app60 tt60 pair60 fst60 snd60 left60 right60 case60 zero60 suc60 rec60) def v060 : ∀ {Γ A}, Tm60 (snoc60 Γ A) A := var60 vz60 def v160 : ∀ {Γ A B}, Tm60 (snoc60 (snoc60 Γ A) B) A := var60 (vs60 vz60) def v260 : ∀ {Γ A B C}, Tm60 (snoc60 (snoc60 (snoc60 Γ A) B) C) A := var60 (vs60 (vs60 vz60)) def v360 : ∀ {Γ A B C D}, Tm60 (snoc60 (snoc60 (snoc60 (snoc60 Γ A) B) C) D) A := var60 (vs60 (vs60 (vs60 vz60))) def tbool60 : Ty60 := sum60 top60 top60 def ttrue60 : ∀ {Γ}, Tm60 Γ tbool60 := left60 tt60 def tfalse60 : ∀ {Γ}, Tm60 Γ tbool60 := right60 tt60 def ifthenelse60 : ∀ {Γ A}, Tm60 Γ (arr60 tbool60 (arr60 A (arr60 A A))) := lam60 (lam60 (lam60 (case60 v260 (lam60 v260) (lam60 v160)))) def times460 : ∀ {Γ A}, Tm60 Γ (arr60 (arr60 A A) (arr60 A A)) := lam60 (lam60 (app60 v160 (app60 v160 (app60 v160 (app60 v160 v060))))) def add60 : ∀ {Γ}, Tm60 Γ (arr60 nat60 (arr60 nat60 nat60)) := lam60 (rec60 v060 (lam60 (lam60 (lam60 (suc60 (app60 v160 v060))))) (lam60 v060)) def mul60 : ∀ {Γ}, Tm60 Γ (arr60 nat60 (arr60 nat60 nat60)) := lam60 (rec60 v060 (lam60 (lam60 (lam60 (app60 (app60 add60 (app60 v160 v060)) v060)))) (lam60 zero60)) def fact60 : ∀ {Γ}, Tm60 Γ (arr60 nat60 nat60) := lam60 (rec60 v060 (lam60 (lam60 (app60 (app60 mul60 (suc60 v160)) v060))) (suc60 zero60)) def Ty61 : Type 1 := ∀ (Ty61 : Type) (nat top bot : Ty61) (arr prod sum : Ty61 → Ty61 → Ty61) , Ty61 def nat61 : Ty61 := λ _ nat61 _ _ _ _ _ => nat61 def top61 : Ty61 := λ _ _ top61 _ _ _ _ => top61 def bot61 : Ty61 := λ _ _ _ bot61 _ _ _ => bot61 def arr61 : Ty61 → Ty61 → Ty61 := λ A B Ty61 nat61 top61 bot61 arr61 prod sum => arr61 (A Ty61 nat61 top61 bot61 arr61 prod sum) (B Ty61 nat61 top61 bot61 arr61 prod sum) def prod61 : Ty61 → Ty61 → Ty61 := λ A B Ty61 nat61 top61 bot61 arr61 prod61 sum => prod61 (A Ty61 nat61 top61 bot61 arr61 prod61 sum) (B Ty61 nat61 top61 bot61 arr61 prod61 sum) def sum61 : Ty61 → Ty61 → Ty61 := λ A B Ty61 nat61 top61 bot61 arr61 prod61 sum61 => sum61 (A Ty61 nat61 top61 bot61 arr61 prod61 sum61) (B Ty61 nat61 top61 bot61 arr61 prod61 sum61) def Con61 : Type 1 := ∀ (Con61 : Type) (nil : Con61) (snoc : Con61 → Ty61 → Con61) , Con61 def nil61 : Con61 := λ Con61 nil61 snoc => nil61 def snoc61 : Con61 → Ty61 → Con61 := λ Γ A Con61 nil61 snoc61 => snoc61 (Γ Con61 nil61 snoc61) A def Var61 : Con61 → Ty61 → Type 1 := λ Γ A => ∀ (Var61 : Con61 → Ty61 → Type) (vz : ∀{Γ A}, Var61 (snoc61 Γ A) A) (vs : ∀{Γ B A}, Var61 Γ A → Var61 (snoc61 Γ B) A) , Var61 Γ A def vz61 : ∀ {Γ A}, Var61 (snoc61 Γ A) A := λ Var61 vz61 vs => vz61 def vs61 : ∀ {Γ B A}, Var61 Γ A → Var61 (snoc61 Γ B) A := λ x Var61 vz61 vs61 => vs61 (x Var61 vz61 vs61) def Tm61 : Con61 → Ty61 → Type 1 := λ Γ A => ∀ (Tm61 : Con61 → Ty61 → Type) (var : ∀ {Γ A}, Var61 Γ A → Tm61 Γ A) (lam : ∀ {Γ A B}, (Tm61 (snoc61 Γ A) B → Tm61 Γ (arr61 A B))) (app : ∀ {Γ A B} , Tm61 Γ (arr61 A B) → Tm61 Γ A → Tm61 Γ B) (tt : ∀ {Γ} , Tm61 Γ top61) (pair : ∀ {Γ A B} , Tm61 Γ A → Tm61 Γ B → Tm61 Γ (prod61 A B)) (fst : ∀ {Γ A B} , Tm61 Γ (prod61 A B) → Tm61 Γ A) (snd : ∀ {Γ A B} , Tm61 Γ (prod61 A B) → Tm61 Γ B) (left : ∀ {Γ A B} , Tm61 Γ A → Tm61 Γ (sum61 A B)) (right : ∀ {Γ A B} , Tm61 Γ B → Tm61 Γ (sum61 A B)) (case : ∀ {Γ A B C} , Tm61 Γ (sum61 A B) → Tm61 Γ (arr61 A C) → Tm61 Γ (arr61 B C) → Tm61 Γ C) (zero : ∀ {Γ} , Tm61 Γ nat61) (suc : ∀ {Γ} , Tm61 Γ nat61 → Tm61 Γ nat61) (rec : ∀ {Γ A} , Tm61 Γ nat61 → Tm61 Γ (arr61 nat61 (arr61 A A)) → Tm61 Γ A → Tm61 Γ A) , Tm61 Γ A def var61 : ∀ {Γ A}, Var61 Γ A → Tm61 Γ A := λ x Tm61 var61 lam app tt pair fst snd left right case zero suc rec => var61 x def lam61 : ∀ {Γ A B} , Tm61 (snoc61 Γ A) B → Tm61 Γ (arr61 A B) := λ t Tm61 var61 lam61 app tt pair fst snd left right case zero suc rec => lam61 (t Tm61 var61 lam61 app tt pair fst snd left right case zero suc rec) def app61 : ∀ {Γ A B} , Tm61 Γ (arr61 A B) → Tm61 Γ A → Tm61 Γ B := λ t u Tm61 var61 lam61 app61 tt pair fst snd left right case zero suc rec => app61 (t Tm61 var61 lam61 app61 tt pair fst snd left right case zero suc rec) (u Tm61 var61 lam61 app61 tt pair fst snd left right case zero suc rec) def tt61 : ∀ {Γ} , Tm61 Γ top61 := λ Tm61 var61 lam61 app61 tt61 pair fst snd left right case zero suc rec => tt61 def pair61 : ∀ {Γ A B} , Tm61 Γ A → Tm61 Γ B → Tm61 Γ (prod61 A B) := λ t u Tm61 var61 lam61 app61 tt61 pair61 fst snd left right case zero suc rec => pair61 (t Tm61 var61 lam61 app61 tt61 pair61 fst snd left right case zero suc rec) (u Tm61 var61 lam61 app61 tt61 pair61 fst snd left right case zero suc rec) def fst61 : ∀ {Γ A B} , Tm61 Γ (prod61 A B) → Tm61 Γ A := λ t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd left right case zero suc rec => fst61 (t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd left right case zero suc rec) def snd61 : ∀ {Γ A B} , Tm61 Γ (prod61 A B) → Tm61 Γ B := λ t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left right case zero suc rec => snd61 (t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left right case zero suc rec) def left61 : ∀ {Γ A B} , Tm61 Γ A → Tm61 Γ (sum61 A B) := λ t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right case zero suc rec => left61 (t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right case zero suc rec) def right61 : ∀ {Γ A B} , Tm61 Γ B → Tm61 Γ (sum61 A B) := λ t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case zero suc rec => right61 (t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case zero suc rec) def case61 : ∀ {Γ A B C} , Tm61 Γ (sum61 A B) → Tm61 Γ (arr61 A C) → Tm61 Γ (arr61 B C) → Tm61 Γ C := λ t u v Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case61 zero suc rec => case61 (t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case61 zero suc rec) (u Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case61 zero suc rec) (v Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case61 zero suc rec) def zero61 : ∀ {Γ} , Tm61 Γ nat61 := λ Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case61 zero61 suc rec => zero61 def suc61 : ∀ {Γ} , Tm61 Γ nat61 → Tm61 Γ nat61 := λ t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case61 zero61 suc61 rec => suc61 (t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case61 zero61 suc61 rec) def rec61 : ∀ {Γ A} , Tm61 Γ nat61 → Tm61 Γ (arr61 nat61 (arr61 A A)) → Tm61 Γ A → Tm61 Γ A := λ t u v Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case61 zero61 suc61 rec61 => rec61 (t Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case61 zero61 suc61 rec61) (u Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case61 zero61 suc61 rec61) (v Tm61 var61 lam61 app61 tt61 pair61 fst61 snd61 left61 right61 case61 zero61 suc61 rec61) def v061 : ∀ {Γ A}, Tm61 (snoc61 Γ A) A := var61 vz61 def v161 : ∀ {Γ A B}, Tm61 (snoc61 (snoc61 Γ A) B) A := var61 (vs61 vz61) def v261 : ∀ {Γ A B C}, Tm61 (snoc61 (snoc61 (snoc61 Γ A) B) C) A := var61 (vs61 (vs61 vz61)) def v361 : ∀ {Γ A B C D}, Tm61 (snoc61 (snoc61 (snoc61 (snoc61 Γ A) B) C) D) A := var61 (vs61 (vs61 (vs61 vz61))) def tbool61 : Ty61 := sum61 top61 top61 def ttrue61 : ∀ {Γ}, Tm61 Γ tbool61 := left61 tt61 def tfalse61 : ∀ {Γ}, Tm61 Γ tbool61 := right61 tt61 def ifthenelse61 : ∀ {Γ A}, Tm61 Γ (arr61 tbool61 (arr61 A (arr61 A A))) := lam61 (lam61 (lam61 (case61 v261 (lam61 v261) (lam61 v161)))) def times461 : ∀ {Γ A}, Tm61 Γ (arr61 (arr61 A A) (arr61 A A)) := lam61 (lam61 (app61 v161 (app61 v161 (app61 v161 (app61 v161 v061))))) def add61 : ∀ {Γ}, Tm61 Γ (arr61 nat61 (arr61 nat61 nat61)) := lam61 (rec61 v061 (lam61 (lam61 (lam61 (suc61 (app61 v161 v061))))) (lam61 v061)) def mul61 : ∀ {Γ}, Tm61 Γ (arr61 nat61 (arr61 nat61 nat61)) := lam61 (rec61 v061 (lam61 (lam61 (lam61 (app61 (app61 add61 (app61 v161 v061)) v061)))) (lam61 zero61)) def fact61 : ∀ {Γ}, Tm61 Γ (arr61 nat61 nat61) := lam61 (rec61 v061 (lam61 (lam61 (app61 (app61 mul61 (suc61 v161)) v061))) (suc61 zero61)) def Ty62 : Type 1 := ∀ (Ty62 : Type) (nat top bot : Ty62) (arr prod sum : Ty62 → Ty62 → Ty62) , Ty62 def nat62 : Ty62 := λ _ nat62 _ _ _ _ _ => nat62 def top62 : Ty62 := λ _ _ top62 _ _ _ _ => top62 def bot62 : Ty62 := λ _ _ _ bot62 _ _ _ => bot62 def arr62 : Ty62 → Ty62 → Ty62 := λ A B Ty62 nat62 top62 bot62 arr62 prod sum => arr62 (A Ty62 nat62 top62 bot62 arr62 prod sum) (B Ty62 nat62 top62 bot62 arr62 prod sum) def prod62 : Ty62 → Ty62 → Ty62 := λ A B Ty62 nat62 top62 bot62 arr62 prod62 sum => prod62 (A Ty62 nat62 top62 bot62 arr62 prod62 sum) (B Ty62 nat62 top62 bot62 arr62 prod62 sum) def sum62 : Ty62 → Ty62 → Ty62 := λ A B Ty62 nat62 top62 bot62 arr62 prod62 sum62 => sum62 (A Ty62 nat62 top62 bot62 arr62 prod62 sum62) (B Ty62 nat62 top62 bot62 arr62 prod62 sum62) def Con62 : Type 1 := ∀ (Con62 : Type) (nil : Con62) (snoc : Con62 → Ty62 → Con62) , Con62 def nil62 : Con62 := λ Con62 nil62 snoc => nil62 def snoc62 : Con62 → Ty62 → Con62 := λ Γ A Con62 nil62 snoc62 => snoc62 (Γ Con62 nil62 snoc62) A def Var62 : Con62 → Ty62 → Type 1 := λ Γ A => ∀ (Var62 : Con62 → Ty62 → Type) (vz : ∀{Γ A}, Var62 (snoc62 Γ A) A) (vs : ∀{Γ B A}, Var62 Γ A → Var62 (snoc62 Γ B) A) , Var62 Γ A def vz62 : ∀ {Γ A}, Var62 (snoc62 Γ A) A := λ Var62 vz62 vs => vz62 def vs62 : ∀ {Γ B A}, Var62 Γ A → Var62 (snoc62 Γ B) A := λ x Var62 vz62 vs62 => vs62 (x Var62 vz62 vs62) def Tm62 : Con62 → Ty62 → Type 1 := λ Γ A => ∀ (Tm62 : Con62 → Ty62 → Type) (var : ∀ {Γ A}, Var62 Γ A → Tm62 Γ A) (lam : ∀ {Γ A B}, (Tm62 (snoc62 Γ A) B → Tm62 Γ (arr62 A B))) (app : ∀ {Γ A B} , Tm62 Γ (arr62 A B) → Tm62 Γ A → Tm62 Γ B) (tt : ∀ {Γ} , Tm62 Γ top62) (pair : ∀ {Γ A B} , Tm62 Γ A → Tm62 Γ B → Tm62 Γ (prod62 A B)) (fst : ∀ {Γ A B} , Tm62 Γ (prod62 A B) → Tm62 Γ A) (snd : ∀ {Γ A B} , Tm62 Γ (prod62 A B) → Tm62 Γ B) (left : ∀ {Γ A B} , Tm62 Γ A → Tm62 Γ (sum62 A B)) (right : ∀ {Γ A B} , Tm62 Γ B → Tm62 Γ (sum62 A B)) (case : ∀ {Γ A B C} , Tm62 Γ (sum62 A B) → Tm62 Γ (arr62 A C) → Tm62 Γ (arr62 B C) → Tm62 Γ C) (zero : ∀ {Γ} , Tm62 Γ nat62) (suc : ∀ {Γ} , Tm62 Γ nat62 → Tm62 Γ nat62) (rec : ∀ {Γ A} , Tm62 Γ nat62 → Tm62 Γ (arr62 nat62 (arr62 A A)) → Tm62 Γ A → Tm62 Γ A) , Tm62 Γ A def var62 : ∀ {Γ A}, Var62 Γ A → Tm62 Γ A := λ x Tm62 var62 lam app tt pair fst snd left right case zero suc rec => var62 x def lam62 : ∀ {Γ A B} , Tm62 (snoc62 Γ A) B → Tm62 Γ (arr62 A B) := λ t Tm62 var62 lam62 app tt pair fst snd left right case zero suc rec => lam62 (t Tm62 var62 lam62 app tt pair fst snd left right case zero suc rec) def app62 : ∀ {Γ A B} , Tm62 Γ (arr62 A B) → Tm62 Γ A → Tm62 Γ B := λ t u Tm62 var62 lam62 app62 tt pair fst snd left right case zero suc rec => app62 (t Tm62 var62 lam62 app62 tt pair fst snd left right case zero suc rec) (u Tm62 var62 lam62 app62 tt pair fst snd left right case zero suc rec) def tt62 : ∀ {Γ} , Tm62 Γ top62 := λ Tm62 var62 lam62 app62 tt62 pair fst snd left right case zero suc rec => tt62 def pair62 : ∀ {Γ A B} , Tm62 Γ A → Tm62 Γ B → Tm62 Γ (prod62 A B) := λ t u Tm62 var62 lam62 app62 tt62 pair62 fst snd left right case zero suc rec => pair62 (t Tm62 var62 lam62 app62 tt62 pair62 fst snd left right case zero suc rec) (u Tm62 var62 lam62 app62 tt62 pair62 fst snd left right case zero suc rec) def fst62 : ∀ {Γ A B} , Tm62 Γ (prod62 A B) → Tm62 Γ A := λ t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd left right case zero suc rec => fst62 (t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd left right case zero suc rec) def snd62 : ∀ {Γ A B} , Tm62 Γ (prod62 A B) → Tm62 Γ B := λ t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left right case zero suc rec => snd62 (t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left right case zero suc rec) def left62 : ∀ {Γ A B} , Tm62 Γ A → Tm62 Γ (sum62 A B) := λ t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right case zero suc rec => left62 (t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right case zero suc rec) def right62 : ∀ {Γ A B} , Tm62 Γ B → Tm62 Γ (sum62 A B) := λ t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case zero suc rec => right62 (t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case zero suc rec) def case62 : ∀ {Γ A B C} , Tm62 Γ (sum62 A B) → Tm62 Γ (arr62 A C) → Tm62 Γ (arr62 B C) → Tm62 Γ C := λ t u v Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case62 zero suc rec => case62 (t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case62 zero suc rec) (u Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case62 zero suc rec) (v Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case62 zero suc rec) def zero62 : ∀ {Γ} , Tm62 Γ nat62 := λ Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case62 zero62 suc rec => zero62 def suc62 : ∀ {Γ} , Tm62 Γ nat62 → Tm62 Γ nat62 := λ t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case62 zero62 suc62 rec => suc62 (t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case62 zero62 suc62 rec) def rec62 : ∀ {Γ A} , Tm62 Γ nat62 → Tm62 Γ (arr62 nat62 (arr62 A A)) → Tm62 Γ A → Tm62 Γ A := λ t u v Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case62 zero62 suc62 rec62 => rec62 (t Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case62 zero62 suc62 rec62) (u Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case62 zero62 suc62 rec62) (v Tm62 var62 lam62 app62 tt62 pair62 fst62 snd62 left62 right62 case62 zero62 suc62 rec62) def v062 : ∀ {Γ A}, Tm62 (snoc62 Γ A) A := var62 vz62 def v162 : ∀ {Γ A B}, Tm62 (snoc62 (snoc62 Γ A) B) A := var62 (vs62 vz62) def v262 : ∀ {Γ A B C}, Tm62 (snoc62 (snoc62 (snoc62 Γ A) B) C) A := var62 (vs62 (vs62 vz62)) def v362 : ∀ {Γ A B C D}, Tm62 (snoc62 (snoc62 (snoc62 (snoc62 Γ A) B) C) D) A := var62 (vs62 (vs62 (vs62 vz62))) def tbool62 : Ty62 := sum62 top62 top62 def ttrue62 : ∀ {Γ}, Tm62 Γ tbool62 := left62 tt62 def tfalse62 : ∀ {Γ}, Tm62 Γ tbool62 := right62 tt62 def ifthenelse62 : ∀ {Γ A}, Tm62 Γ (arr62 tbool62 (arr62 A (arr62 A A))) := lam62 (lam62 (lam62 (case62 v262 (lam62 v262) (lam62 v162)))) def times462 : ∀ {Γ A}, Tm62 Γ (arr62 (arr62 A A) (arr62 A A)) := lam62 (lam62 (app62 v162 (app62 v162 (app62 v162 (app62 v162 v062))))) def add62 : ∀ {Γ}, Tm62 Γ (arr62 nat62 (arr62 nat62 nat62)) := lam62 (rec62 v062 (lam62 (lam62 (lam62 (suc62 (app62 v162 v062))))) (lam62 v062)) def mul62 : ∀ {Γ}, Tm62 Γ (arr62 nat62 (arr62 nat62 nat62)) := lam62 (rec62 v062 (lam62 (lam62 (lam62 (app62 (app62 add62 (app62 v162 v062)) v062)))) (lam62 zero62)) def fact62 : ∀ {Γ}, Tm62 Γ (arr62 nat62 nat62) := lam62 (rec62 v062 (lam62 (lam62 (app62 (app62 mul62 (suc62 v162)) v062))) (suc62 zero62)) def Ty63 : Type 1 := ∀ (Ty63 : Type) (nat top bot : Ty63) (arr prod sum : Ty63 → Ty63 → Ty63) , Ty63 def nat63 : Ty63 := λ _ nat63 _ _ _ _ _ => nat63 def top63 : Ty63 := λ _ _ top63 _ _ _ _ => top63 def bot63 : Ty63 := λ _ _ _ bot63 _ _ _ => bot63 def arr63 : Ty63 → Ty63 → Ty63 := λ A B Ty63 nat63 top63 bot63 arr63 prod sum => arr63 (A Ty63 nat63 top63 bot63 arr63 prod sum) (B Ty63 nat63 top63 bot63 arr63 prod sum) def prod63 : Ty63 → Ty63 → Ty63 := λ A B Ty63 nat63 top63 bot63 arr63 prod63 sum => prod63 (A Ty63 nat63 top63 bot63 arr63 prod63 sum) (B Ty63 nat63 top63 bot63 arr63 prod63 sum) def sum63 : Ty63 → Ty63 → Ty63 := λ A B Ty63 nat63 top63 bot63 arr63 prod63 sum63 => sum63 (A Ty63 nat63 top63 bot63 arr63 prod63 sum63) (B Ty63 nat63 top63 bot63 arr63 prod63 sum63) def Con63 : Type 1 := ∀ (Con63 : Type) (nil : Con63) (snoc : Con63 → Ty63 → Con63) , Con63 def nil63 : Con63 := λ Con63 nil63 snoc => nil63 def snoc63 : Con63 → Ty63 → Con63 := λ Γ A Con63 nil63 snoc63 => snoc63 (Γ Con63 nil63 snoc63) A def Var63 : Con63 → Ty63 → Type 1 := λ Γ A => ∀ (Var63 : Con63 → Ty63 → Type) (vz : ∀{Γ A}, Var63 (snoc63 Γ A) A) (vs : ∀{Γ B A}, Var63 Γ A → Var63 (snoc63 Γ B) A) , Var63 Γ A def vz63 : ∀ {Γ A}, Var63 (snoc63 Γ A) A := λ Var63 vz63 vs => vz63 def vs63 : ∀ {Γ B A}, Var63 Γ A → Var63 (snoc63 Γ B) A := λ x Var63 vz63 vs63 => vs63 (x Var63 vz63 vs63) def Tm63 : Con63 → Ty63 → Type 1 := λ Γ A => ∀ (Tm63 : Con63 → Ty63 → Type) (var : ∀ {Γ A}, Var63 Γ A → Tm63 Γ A) (lam : ∀ {Γ A B}, (Tm63 (snoc63 Γ A) B → Tm63 Γ (arr63 A B))) (app : ∀ {Γ A B} , Tm63 Γ (arr63 A B) → Tm63 Γ A → Tm63 Γ B) (tt : ∀ {Γ} , Tm63 Γ top63) (pair : ∀ {Γ A B} , Tm63 Γ A → Tm63 Γ B → Tm63 Γ (prod63 A B)) (fst : ∀ {Γ A B} , Tm63 Γ (prod63 A B) → Tm63 Γ A) (snd : ∀ {Γ A B} , Tm63 Γ (prod63 A B) → Tm63 Γ B) (left : ∀ {Γ A B} , Tm63 Γ A → Tm63 Γ (sum63 A B)) (right : ∀ {Γ A B} , Tm63 Γ B → Tm63 Γ (sum63 A B)) (case : ∀ {Γ A B C} , Tm63 Γ (sum63 A B) → Tm63 Γ (arr63 A C) → Tm63 Γ (arr63 B C) → Tm63 Γ C) (zero : ∀ {Γ} , Tm63 Γ nat63) (suc : ∀ {Γ} , Tm63 Γ nat63 → Tm63 Γ nat63) (rec : ∀ {Γ A} , Tm63 Γ nat63 → Tm63 Γ (arr63 nat63 (arr63 A A)) → Tm63 Γ A → Tm63 Γ A) , Tm63 Γ A def var63 : ∀ {Γ A}, Var63 Γ A → Tm63 Γ A := λ x Tm63 var63 lam app tt pair fst snd left right case zero suc rec => var63 x def lam63 : ∀ {Γ A B} , Tm63 (snoc63 Γ A) B → Tm63 Γ (arr63 A B) := λ t Tm63 var63 lam63 app tt pair fst snd left right case zero suc rec => lam63 (t Tm63 var63 lam63 app tt pair fst snd left right case zero suc rec) def app63 : ∀ {Γ A B} , Tm63 Γ (arr63 A B) → Tm63 Γ A → Tm63 Γ B := λ t u Tm63 var63 lam63 app63 tt pair fst snd left right case zero suc rec => app63 (t Tm63 var63 lam63 app63 tt pair fst snd left right case zero suc rec) (u Tm63 var63 lam63 app63 tt pair fst snd left right case zero suc rec) def tt63 : ∀ {Γ} , Tm63 Γ top63 := λ Tm63 var63 lam63 app63 tt63 pair fst snd left right case zero suc rec => tt63 def pair63 : ∀ {Γ A B} , Tm63 Γ A → Tm63 Γ B → Tm63 Γ (prod63 A B) := λ t u Tm63 var63 lam63 app63 tt63 pair63 fst snd left right case zero suc rec => pair63 (t Tm63 var63 lam63 app63 tt63 pair63 fst snd left right case zero suc rec) (u Tm63 var63 lam63 app63 tt63 pair63 fst snd left right case zero suc rec) def fst63 : ∀ {Γ A B} , Tm63 Γ (prod63 A B) → Tm63 Γ A := λ t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd left right case zero suc rec => fst63 (t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd left right case zero suc rec) def snd63 : ∀ {Γ A B} , Tm63 Γ (prod63 A B) → Tm63 Γ B := λ t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left right case zero suc rec => snd63 (t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left right case zero suc rec) def left63 : ∀ {Γ A B} , Tm63 Γ A → Tm63 Γ (sum63 A B) := λ t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right case zero suc rec => left63 (t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right case zero suc rec) def right63 : ∀ {Γ A B} , Tm63 Γ B → Tm63 Γ (sum63 A B) := λ t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case zero suc rec => right63 (t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case zero suc rec) def case63 : ∀ {Γ A B C} , Tm63 Γ (sum63 A B) → Tm63 Γ (arr63 A C) → Tm63 Γ (arr63 B C) → Tm63 Γ C := λ t u v Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case63 zero suc rec => case63 (t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case63 zero suc rec) (u Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case63 zero suc rec) (v Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case63 zero suc rec) def zero63 : ∀ {Γ} , Tm63 Γ nat63 := λ Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case63 zero63 suc rec => zero63 def suc63 : ∀ {Γ} , Tm63 Γ nat63 → Tm63 Γ nat63 := λ t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case63 zero63 suc63 rec => suc63 (t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case63 zero63 suc63 rec) def rec63 : ∀ {Γ A} , Tm63 Γ nat63 → Tm63 Γ (arr63 nat63 (arr63 A A)) → Tm63 Γ A → Tm63 Γ A := λ t u v Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case63 zero63 suc63 rec63 => rec63 (t Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case63 zero63 suc63 rec63) (u Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case63 zero63 suc63 rec63) (v Tm63 var63 lam63 app63 tt63 pair63 fst63 snd63 left63 right63 case63 zero63 suc63 rec63) def v063 : ∀ {Γ A}, Tm63 (snoc63 Γ A) A := var63 vz63 def v163 : ∀ {Γ A B}, Tm63 (snoc63 (snoc63 Γ A) B) A := var63 (vs63 vz63) def v263 : ∀ {Γ A B C}, Tm63 (snoc63 (snoc63 (snoc63 Γ A) B) C) A := var63 (vs63 (vs63 vz63)) def v363 : ∀ {Γ A B C D}, Tm63 (snoc63 (snoc63 (snoc63 (snoc63 Γ A) B) C) D) A := var63 (vs63 (vs63 (vs63 vz63))) def tbool63 : Ty63 := sum63 top63 top63 def ttrue63 : ∀ {Γ}, Tm63 Γ tbool63 := left63 tt63 def tfalse63 : ∀ {Γ}, Tm63 Γ tbool63 := right63 tt63 def ifthenelse63 : ∀ {Γ A}, Tm63 Γ (arr63 tbool63 (arr63 A (arr63 A A))) := lam63 (lam63 (lam63 (case63 v263 (lam63 v263) (lam63 v163)))) def times463 : ∀ {Γ A}, Tm63 Γ (arr63 (arr63 A A) (arr63 A A)) := lam63 (lam63 (app63 v163 (app63 v163 (app63 v163 (app63 v163 v063))))) def add63 : ∀ {Γ}, Tm63 Γ (arr63 nat63 (arr63 nat63 nat63)) := lam63 (rec63 v063 (lam63 (lam63 (lam63 (suc63 (app63 v163 v063))))) (lam63 v063)) def mul63 : ∀ {Γ}, Tm63 Γ (arr63 nat63 (arr63 nat63 nat63)) := lam63 (rec63 v063 (lam63 (lam63 (lam63 (app63 (app63 add63 (app63 v163 v063)) v063)))) (lam63 zero63)) def fact63 : ∀ {Γ}, Tm63 Γ (arr63 nat63 nat63) := lam63 (rec63 v063 (lam63 (lam63 (app63 (app63 mul63 (suc63 v163)) v063))) (suc63 zero63)) def Ty64 : Type 1 := ∀ (Ty64 : Type) (nat top bot : Ty64) (arr prod sum : Ty64 → Ty64 → Ty64) , Ty64 def nat64 : Ty64 := λ _ nat64 _ _ _ _ _ => nat64 def top64 : Ty64 := λ _ _ top64 _ _ _ _ => top64 def bot64 : Ty64 := λ _ _ _ bot64 _ _ _ => bot64 def arr64 : Ty64 → Ty64 → Ty64 := λ A B Ty64 nat64 top64 bot64 arr64 prod sum => arr64 (A Ty64 nat64 top64 bot64 arr64 prod sum) (B Ty64 nat64 top64 bot64 arr64 prod sum) def prod64 : Ty64 → Ty64 → Ty64 := λ A B Ty64 nat64 top64 bot64 arr64 prod64 sum => prod64 (A Ty64 nat64 top64 bot64 arr64 prod64 sum) (B Ty64 nat64 top64 bot64 arr64 prod64 sum) def sum64 : Ty64 → Ty64 → Ty64 := λ A B Ty64 nat64 top64 bot64 arr64 prod64 sum64 => sum64 (A Ty64 nat64 top64 bot64 arr64 prod64 sum64) (B Ty64 nat64 top64 bot64 arr64 prod64 sum64) def Con64 : Type 1 := ∀ (Con64 : Type) (nil : Con64) (snoc : Con64 → Ty64 → Con64) , Con64 def nil64 : Con64 := λ Con64 nil64 snoc => nil64 def snoc64 : Con64 → Ty64 → Con64 := λ Γ A Con64 nil64 snoc64 => snoc64 (Γ Con64 nil64 snoc64) A def Var64 : Con64 → Ty64 → Type 1 := λ Γ A => ∀ (Var64 : Con64 → Ty64 → Type) (vz : ∀{Γ A}, Var64 (snoc64 Γ A) A) (vs : ∀{Γ B A}, Var64 Γ A → Var64 (snoc64 Γ B) A) , Var64 Γ A def vz64 : ∀ {Γ A}, Var64 (snoc64 Γ A) A := λ Var64 vz64 vs => vz64 def vs64 : ∀ {Γ B A}, Var64 Γ A → Var64 (snoc64 Γ B) A := λ x Var64 vz64 vs64 => vs64 (x Var64 vz64 vs64) def Tm64 : Con64 → Ty64 → Type 1 := λ Γ A => ∀ (Tm64 : Con64 → Ty64 → Type) (var : ∀ {Γ A}, Var64 Γ A → Tm64 Γ A) (lam : ∀ {Γ A B}, (Tm64 (snoc64 Γ A) B → Tm64 Γ (arr64 A B))) (app : ∀ {Γ A B} , Tm64 Γ (arr64 A B) → Tm64 Γ A → Tm64 Γ B) (tt : ∀ {Γ} , Tm64 Γ top64) (pair : ∀ {Γ A B} , Tm64 Γ A → Tm64 Γ B → Tm64 Γ (prod64 A B)) (fst : ∀ {Γ A B} , Tm64 Γ (prod64 A B) → Tm64 Γ A) (snd : ∀ {Γ A B} , Tm64 Γ (prod64 A B) → Tm64 Γ B) (left : ∀ {Γ A B} , Tm64 Γ A → Tm64 Γ (sum64 A B)) (right : ∀ {Γ A B} , Tm64 Γ B → Tm64 Γ (sum64 A B)) (case : ∀ {Γ A B C} , Tm64 Γ (sum64 A B) → Tm64 Γ (arr64 A C) → Tm64 Γ (arr64 B C) → Tm64 Γ C) (zero : ∀ {Γ} , Tm64 Γ nat64) (suc : ∀ {Γ} , Tm64 Γ nat64 → Tm64 Γ nat64) (rec : ∀ {Γ A} , Tm64 Γ nat64 → Tm64 Γ (arr64 nat64 (arr64 A A)) → Tm64 Γ A → Tm64 Γ A) , Tm64 Γ A def var64 : ∀ {Γ A}, Var64 Γ A → Tm64 Γ A := λ x Tm64 var64 lam app tt pair fst snd left right case zero suc rec => var64 x def lam64 : ∀ {Γ A B} , Tm64 (snoc64 Γ A) B → Tm64 Γ (arr64 A B) := λ t Tm64 var64 lam64 app tt pair fst snd left right case zero suc rec => lam64 (t Tm64 var64 lam64 app tt pair fst snd left right case zero suc rec) def app64 : ∀ {Γ A B} , Tm64 Γ (arr64 A B) → Tm64 Γ A → Tm64 Γ B := λ t u Tm64 var64 lam64 app64 tt pair fst snd left right case zero suc rec => app64 (t Tm64 var64 lam64 app64 tt pair fst snd left right case zero suc rec) (u Tm64 var64 lam64 app64 tt pair fst snd left right case zero suc rec) def tt64 : ∀ {Γ} , Tm64 Γ top64 := λ Tm64 var64 lam64 app64 tt64 pair fst snd left right case zero suc rec => tt64 def pair64 : ∀ {Γ A B} , Tm64 Γ A → Tm64 Γ B → Tm64 Γ (prod64 A B) := λ t u Tm64 var64 lam64 app64 tt64 pair64 fst snd left right case zero suc rec => pair64 (t Tm64 var64 lam64 app64 tt64 pair64 fst snd left right case zero suc rec) (u Tm64 var64 lam64 app64 tt64 pair64 fst snd left right case zero suc rec) def fst64 : ∀ {Γ A B} , Tm64 Γ (prod64 A B) → Tm64 Γ A := λ t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd left right case zero suc rec => fst64 (t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd left right case zero suc rec) def snd64 : ∀ {Γ A B} , Tm64 Γ (prod64 A B) → Tm64 Γ B := λ t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left right case zero suc rec => snd64 (t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left right case zero suc rec) def left64 : ∀ {Γ A B} , Tm64 Γ A → Tm64 Γ (sum64 A B) := λ t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right case zero suc rec => left64 (t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right case zero suc rec) def right64 : ∀ {Γ A B} , Tm64 Γ B → Tm64 Γ (sum64 A B) := λ t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case zero suc rec => right64 (t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case zero suc rec) def case64 : ∀ {Γ A B C} , Tm64 Γ (sum64 A B) → Tm64 Γ (arr64 A C) → Tm64 Γ (arr64 B C) → Tm64 Γ C := λ t u v Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case64 zero suc rec => case64 (t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case64 zero suc rec) (u Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case64 zero suc rec) (v Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case64 zero suc rec) def zero64 : ∀ {Γ} , Tm64 Γ nat64 := λ Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case64 zero64 suc rec => zero64 def suc64 : ∀ {Γ} , Tm64 Γ nat64 → Tm64 Γ nat64 := λ t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case64 zero64 suc64 rec => suc64 (t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case64 zero64 suc64 rec) def rec64 : ∀ {Γ A} , Tm64 Γ nat64 → Tm64 Γ (arr64 nat64 (arr64 A A)) → Tm64 Γ A → Tm64 Γ A := λ t u v Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case64 zero64 suc64 rec64 => rec64 (t Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case64 zero64 suc64 rec64) (u Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case64 zero64 suc64 rec64) (v Tm64 var64 lam64 app64 tt64 pair64 fst64 snd64 left64 right64 case64 zero64 suc64 rec64) def v064 : ∀ {Γ A}, Tm64 (snoc64 Γ A) A := var64 vz64 def v164 : ∀ {Γ A B}, Tm64 (snoc64 (snoc64 Γ A) B) A := var64 (vs64 vz64) def v264 : ∀ {Γ A B C}, Tm64 (snoc64 (snoc64 (snoc64 Γ A) B) C) A := var64 (vs64 (vs64 vz64)) def v364 : ∀ {Γ A B C D}, Tm64 (snoc64 (snoc64 (snoc64 (snoc64 Γ A) B) C) D) A := var64 (vs64 (vs64 (vs64 vz64))) def tbool64 : Ty64 := sum64 top64 top64 def ttrue64 : ∀ {Γ}, Tm64 Γ tbool64 := left64 tt64 def tfalse64 : ∀ {Γ}, Tm64 Γ tbool64 := right64 tt64 def ifthenelse64 : ∀ {Γ A}, Tm64 Γ (arr64 tbool64 (arr64 A (arr64 A A))) := lam64 (lam64 (lam64 (case64 v264 (lam64 v264) (lam64 v164)))) def times464 : ∀ {Γ A}, Tm64 Γ (arr64 (arr64 A A) (arr64 A A)) := lam64 (lam64 (app64 v164 (app64 v164 (app64 v164 (app64 v164 v064))))) def add64 : ∀ {Γ}, Tm64 Γ (arr64 nat64 (arr64 nat64 nat64)) := lam64 (rec64 v064 (lam64 (lam64 (lam64 (suc64 (app64 v164 v064))))) (lam64 v064)) def mul64 : ∀ {Γ}, Tm64 Γ (arr64 nat64 (arr64 nat64 nat64)) := lam64 (rec64 v064 (lam64 (lam64 (lam64 (app64 (app64 add64 (app64 v164 v064)) v064)))) (lam64 zero64)) def fact64 : ∀ {Γ}, Tm64 Γ (arr64 nat64 nat64) := lam64 (rec64 v064 (lam64 (lam64 (app64 (app64 mul64 (suc64 v164)) v064))) (suc64 zero64)) def Ty65 : Type 1 := ∀ (Ty65 : Type) (nat top bot : Ty65) (arr prod sum : Ty65 → Ty65 → Ty65) , Ty65 def nat65 : Ty65 := λ _ nat65 _ _ _ _ _ => nat65 def top65 : Ty65 := λ _ _ top65 _ _ _ _ => top65 def bot65 : Ty65 := λ _ _ _ bot65 _ _ _ => bot65 def arr65 : Ty65 → Ty65 → Ty65 := λ A B Ty65 nat65 top65 bot65 arr65 prod sum => arr65 (A Ty65 nat65 top65 bot65 arr65 prod sum) (B Ty65 nat65 top65 bot65 arr65 prod sum) def prod65 : Ty65 → Ty65 → Ty65 := λ A B Ty65 nat65 top65 bot65 arr65 prod65 sum => prod65 (A Ty65 nat65 top65 bot65 arr65 prod65 sum) (B Ty65 nat65 top65 bot65 arr65 prod65 sum) def sum65 : Ty65 → Ty65 → Ty65 := λ A B Ty65 nat65 top65 bot65 arr65 prod65 sum65 => sum65 (A Ty65 nat65 top65 bot65 arr65 prod65 sum65) (B Ty65 nat65 top65 bot65 arr65 prod65 sum65) def Con65 : Type 1 := ∀ (Con65 : Type) (nil : Con65) (snoc : Con65 → Ty65 → Con65) , Con65 def nil65 : Con65 := λ Con65 nil65 snoc => nil65 def snoc65 : Con65 → Ty65 → Con65 := λ Γ A Con65 nil65 snoc65 => snoc65 (Γ Con65 nil65 snoc65) A def Var65 : Con65 → Ty65 → Type 1 := λ Γ A => ∀ (Var65 : Con65 → Ty65 → Type) (vz : ∀{Γ A}, Var65 (snoc65 Γ A) A) (vs : ∀{Γ B A}, Var65 Γ A → Var65 (snoc65 Γ B) A) , Var65 Γ A def vz65 : ∀ {Γ A}, Var65 (snoc65 Γ A) A := λ Var65 vz65 vs => vz65 def vs65 : ∀ {Γ B A}, Var65 Γ A → Var65 (snoc65 Γ B) A := λ x Var65 vz65 vs65 => vs65 (x Var65 vz65 vs65) def Tm65 : Con65 → Ty65 → Type 1 := λ Γ A => ∀ (Tm65 : Con65 → Ty65 → Type) (var : ∀ {Γ A}, Var65 Γ A → Tm65 Γ A) (lam : ∀ {Γ A B}, (Tm65 (snoc65 Γ A) B → Tm65 Γ (arr65 A B))) (app : ∀ {Γ A B} , Tm65 Γ (arr65 A B) → Tm65 Γ A → Tm65 Γ B) (tt : ∀ {Γ} , Tm65 Γ top65) (pair : ∀ {Γ A B} , Tm65 Γ A → Tm65 Γ B → Tm65 Γ (prod65 A B)) (fst : ∀ {Γ A B} , Tm65 Γ (prod65 A B) → Tm65 Γ A) (snd : ∀ {Γ A B} , Tm65 Γ (prod65 A B) → Tm65 Γ B) (left : ∀ {Γ A B} , Tm65 Γ A → Tm65 Γ (sum65 A B)) (right : ∀ {Γ A B} , Tm65 Γ B → Tm65 Γ (sum65 A B)) (case : ∀ {Γ A B C} , Tm65 Γ (sum65 A B) → Tm65 Γ (arr65 A C) → Tm65 Γ (arr65 B C) → Tm65 Γ C) (zero : ∀ {Γ} , Tm65 Γ nat65) (suc : ∀ {Γ} , Tm65 Γ nat65 → Tm65 Γ nat65) (rec : ∀ {Γ A} , Tm65 Γ nat65 → Tm65 Γ (arr65 nat65 (arr65 A A)) → Tm65 Γ A → Tm65 Γ A) , Tm65 Γ A def var65 : ∀ {Γ A}, Var65 Γ A → Tm65 Γ A := λ x Tm65 var65 lam app tt pair fst snd left right case zero suc rec => var65 x def lam65 : ∀ {Γ A B} , Tm65 (snoc65 Γ A) B → Tm65 Γ (arr65 A B) := λ t Tm65 var65 lam65 app tt pair fst snd left right case zero suc rec => lam65 (t Tm65 var65 lam65 app tt pair fst snd left right case zero suc rec) def app65 : ∀ {Γ A B} , Tm65 Γ (arr65 A B) → Tm65 Γ A → Tm65 Γ B := λ t u Tm65 var65 lam65 app65 tt pair fst snd left right case zero suc rec => app65 (t Tm65 var65 lam65 app65 tt pair fst snd left right case zero suc rec) (u Tm65 var65 lam65 app65 tt pair fst snd left right case zero suc rec) def tt65 : ∀ {Γ} , Tm65 Γ top65 := λ Tm65 var65 lam65 app65 tt65 pair fst snd left right case zero suc rec => tt65 def pair65 : ∀ {Γ A B} , Tm65 Γ A → Tm65 Γ B → Tm65 Γ (prod65 A B) := λ t u Tm65 var65 lam65 app65 tt65 pair65 fst snd left right case zero suc rec => pair65 (t Tm65 var65 lam65 app65 tt65 pair65 fst snd left right case zero suc rec) (u Tm65 var65 lam65 app65 tt65 pair65 fst snd left right case zero suc rec) def fst65 : ∀ {Γ A B} , Tm65 Γ (prod65 A B) → Tm65 Γ A := λ t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd left right case zero suc rec => fst65 (t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd left right case zero suc rec) def snd65 : ∀ {Γ A B} , Tm65 Γ (prod65 A B) → Tm65 Γ B := λ t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left right case zero suc rec => snd65 (t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left right case zero suc rec) def left65 : ∀ {Γ A B} , Tm65 Γ A → Tm65 Γ (sum65 A B) := λ t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right case zero suc rec => left65 (t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right case zero suc rec) def right65 : ∀ {Γ A B} , Tm65 Γ B → Tm65 Γ (sum65 A B) := λ t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case zero suc rec => right65 (t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case zero suc rec) def case65 : ∀ {Γ A B C} , Tm65 Γ (sum65 A B) → Tm65 Γ (arr65 A C) → Tm65 Γ (arr65 B C) → Tm65 Γ C := λ t u v Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case65 zero suc rec => case65 (t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case65 zero suc rec) (u Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case65 zero suc rec) (v Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case65 zero suc rec) def zero65 : ∀ {Γ} , Tm65 Γ nat65 := λ Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case65 zero65 suc rec => zero65 def suc65 : ∀ {Γ} , Tm65 Γ nat65 → Tm65 Γ nat65 := λ t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case65 zero65 suc65 rec => suc65 (t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case65 zero65 suc65 rec) def rec65 : ∀ {Γ A} , Tm65 Γ nat65 → Tm65 Γ (arr65 nat65 (arr65 A A)) → Tm65 Γ A → Tm65 Γ A := λ t u v Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case65 zero65 suc65 rec65 => rec65 (t Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case65 zero65 suc65 rec65) (u Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case65 zero65 suc65 rec65) (v Tm65 var65 lam65 app65 tt65 pair65 fst65 snd65 left65 right65 case65 zero65 suc65 rec65) def v065 : ∀ {Γ A}, Tm65 (snoc65 Γ A) A := var65 vz65 def v165 : ∀ {Γ A B}, Tm65 (snoc65 (snoc65 Γ A) B) A := var65 (vs65 vz65) def v265 : ∀ {Γ A B C}, Tm65 (snoc65 (snoc65 (snoc65 Γ A) B) C) A := var65 (vs65 (vs65 vz65)) def v365 : ∀ {Γ A B C D}, Tm65 (snoc65 (snoc65 (snoc65 (snoc65 Γ A) B) C) D) A := var65 (vs65 (vs65 (vs65 vz65))) def tbool65 : Ty65 := sum65 top65 top65 def ttrue65 : ∀ {Γ}, Tm65 Γ tbool65 := left65 tt65 def tfalse65 : ∀ {Γ}, Tm65 Γ tbool65 := right65 tt65 def ifthenelse65 : ∀ {Γ A}, Tm65 Γ (arr65 tbool65 (arr65 A (arr65 A A))) := lam65 (lam65 (lam65 (case65 v265 (lam65 v265) (lam65 v165)))) def times465 : ∀ {Γ A}, Tm65 Γ (arr65 (arr65 A A) (arr65 A A)) := lam65 (lam65 (app65 v165 (app65 v165 (app65 v165 (app65 v165 v065))))) def add65 : ∀ {Γ}, Tm65 Γ (arr65 nat65 (arr65 nat65 nat65)) := lam65 (rec65 v065 (lam65 (lam65 (lam65 (suc65 (app65 v165 v065))))) (lam65 v065)) def mul65 : ∀ {Γ}, Tm65 Γ (arr65 nat65 (arr65 nat65 nat65)) := lam65 (rec65 v065 (lam65 (lam65 (lam65 (app65 (app65 add65 (app65 v165 v065)) v065)))) (lam65 zero65)) def fact65 : ∀ {Γ}, Tm65 Γ (arr65 nat65 nat65) := lam65 (rec65 v065 (lam65 (lam65 (app65 (app65 mul65 (suc65 v165)) v065))) (suc65 zero65)) def Ty66 : Type 1 := ∀ (Ty66 : Type) (nat top bot : Ty66) (arr prod sum : Ty66 → Ty66 → Ty66) , Ty66 def nat66 : Ty66 := λ _ nat66 _ _ _ _ _ => nat66 def top66 : Ty66 := λ _ _ top66 _ _ _ _ => top66 def bot66 : Ty66 := λ _ _ _ bot66 _ _ _ => bot66 def arr66 : Ty66 → Ty66 → Ty66 := λ A B Ty66 nat66 top66 bot66 arr66 prod sum => arr66 (A Ty66 nat66 top66 bot66 arr66 prod sum) (B Ty66 nat66 top66 bot66 arr66 prod sum) def prod66 : Ty66 → Ty66 → Ty66 := λ A B Ty66 nat66 top66 bot66 arr66 prod66 sum => prod66 (A Ty66 nat66 top66 bot66 arr66 prod66 sum) (B Ty66 nat66 top66 bot66 arr66 prod66 sum) def sum66 : Ty66 → Ty66 → Ty66 := λ A B Ty66 nat66 top66 bot66 arr66 prod66 sum66 => sum66 (A Ty66 nat66 top66 bot66 arr66 prod66 sum66) (B Ty66 nat66 top66 bot66 arr66 prod66 sum66) def Con66 : Type 1 := ∀ (Con66 : Type) (nil : Con66) (snoc : Con66 → Ty66 → Con66) , Con66 def nil66 : Con66 := λ Con66 nil66 snoc => nil66 def snoc66 : Con66 → Ty66 → Con66 := λ Γ A Con66 nil66 snoc66 => snoc66 (Γ Con66 nil66 snoc66) A def Var66 : Con66 → Ty66 → Type 1 := λ Γ A => ∀ (Var66 : Con66 → Ty66 → Type) (vz : ∀{Γ A}, Var66 (snoc66 Γ A) A) (vs : ∀{Γ B A}, Var66 Γ A → Var66 (snoc66 Γ B) A) , Var66 Γ A def vz66 : ∀ {Γ A}, Var66 (snoc66 Γ A) A := λ Var66 vz66 vs => vz66 def vs66 : ∀ {Γ B A}, Var66 Γ A → Var66 (snoc66 Γ B) A := λ x Var66 vz66 vs66 => vs66 (x Var66 vz66 vs66) def Tm66 : Con66 → Ty66 → Type 1 := λ Γ A => ∀ (Tm66 : Con66 → Ty66 → Type) (var : ∀ {Γ A}, Var66 Γ A → Tm66 Γ A) (lam : ∀ {Γ A B}, (Tm66 (snoc66 Γ A) B → Tm66 Γ (arr66 A B))) (app : ∀ {Γ A B} , Tm66 Γ (arr66 A B) → Tm66 Γ A → Tm66 Γ B) (tt : ∀ {Γ} , Tm66 Γ top66) (pair : ∀ {Γ A B} , Tm66 Γ A → Tm66 Γ B → Tm66 Γ (prod66 A B)) (fst : ∀ {Γ A B} , Tm66 Γ (prod66 A B) → Tm66 Γ A) (snd : ∀ {Γ A B} , Tm66 Γ (prod66 A B) → Tm66 Γ B) (left : ∀ {Γ A B} , Tm66 Γ A → Tm66 Γ (sum66 A B)) (right : ∀ {Γ A B} , Tm66 Γ B → Tm66 Γ (sum66 A B)) (case : ∀ {Γ A B C} , Tm66 Γ (sum66 A B) → Tm66 Γ (arr66 A C) → Tm66 Γ (arr66 B C) → Tm66 Γ C) (zero : ∀ {Γ} , Tm66 Γ nat66) (suc : ∀ {Γ} , Tm66 Γ nat66 → Tm66 Γ nat66) (rec : ∀ {Γ A} , Tm66 Γ nat66 → Tm66 Γ (arr66 nat66 (arr66 A A)) → Tm66 Γ A → Tm66 Γ A) , Tm66 Γ A def var66 : ∀ {Γ A}, Var66 Γ A → Tm66 Γ A := λ x Tm66 var66 lam app tt pair fst snd left right case zero suc rec => var66 x def lam66 : ∀ {Γ A B} , Tm66 (snoc66 Γ A) B → Tm66 Γ (arr66 A B) := λ t Tm66 var66 lam66 app tt pair fst snd left right case zero suc rec => lam66 (t Tm66 var66 lam66 app tt pair fst snd left right case zero suc rec) def app66 : ∀ {Γ A B} , Tm66 Γ (arr66 A B) → Tm66 Γ A → Tm66 Γ B := λ t u Tm66 var66 lam66 app66 tt pair fst snd left right case zero suc rec => app66 (t Tm66 var66 lam66 app66 tt pair fst snd left right case zero suc rec) (u Tm66 var66 lam66 app66 tt pair fst snd left right case zero suc rec) def tt66 : ∀ {Γ} , Tm66 Γ top66 := λ Tm66 var66 lam66 app66 tt66 pair fst snd left right case zero suc rec => tt66 def pair66 : ∀ {Γ A B} , Tm66 Γ A → Tm66 Γ B → Tm66 Γ (prod66 A B) := λ t u Tm66 var66 lam66 app66 tt66 pair66 fst snd left right case zero suc rec => pair66 (t Tm66 var66 lam66 app66 tt66 pair66 fst snd left right case zero suc rec) (u Tm66 var66 lam66 app66 tt66 pair66 fst snd left right case zero suc rec) def fst66 : ∀ {Γ A B} , Tm66 Γ (prod66 A B) → Tm66 Γ A := λ t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd left right case zero suc rec => fst66 (t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd left right case zero suc rec) def snd66 : ∀ {Γ A B} , Tm66 Γ (prod66 A B) → Tm66 Γ B := λ t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left right case zero suc rec => snd66 (t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left right case zero suc rec) def left66 : ∀ {Γ A B} , Tm66 Γ A → Tm66 Γ (sum66 A B) := λ t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right case zero suc rec => left66 (t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right case zero suc rec) def right66 : ∀ {Γ A B} , Tm66 Γ B → Tm66 Γ (sum66 A B) := λ t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case zero suc rec => right66 (t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case zero suc rec) def case66 : ∀ {Γ A B C} , Tm66 Γ (sum66 A B) → Tm66 Γ (arr66 A C) → Tm66 Γ (arr66 B C) → Tm66 Γ C := λ t u v Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case66 zero suc rec => case66 (t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case66 zero suc rec) (u Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case66 zero suc rec) (v Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case66 zero suc rec) def zero66 : ∀ {Γ} , Tm66 Γ nat66 := λ Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case66 zero66 suc rec => zero66 def suc66 : ∀ {Γ} , Tm66 Γ nat66 → Tm66 Γ nat66 := λ t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case66 zero66 suc66 rec => suc66 (t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case66 zero66 suc66 rec) def rec66 : ∀ {Γ A} , Tm66 Γ nat66 → Tm66 Γ (arr66 nat66 (arr66 A A)) → Tm66 Γ A → Tm66 Γ A := λ t u v Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case66 zero66 suc66 rec66 => rec66 (t Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case66 zero66 suc66 rec66) (u Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case66 zero66 suc66 rec66) (v Tm66 var66 lam66 app66 tt66 pair66 fst66 snd66 left66 right66 case66 zero66 suc66 rec66) def v066 : ∀ {Γ A}, Tm66 (snoc66 Γ A) A := var66 vz66 def v166 : ∀ {Γ A B}, Tm66 (snoc66 (snoc66 Γ A) B) A := var66 (vs66 vz66) def v266 : ∀ {Γ A B C}, Tm66 (snoc66 (snoc66 (snoc66 Γ A) B) C) A := var66 (vs66 (vs66 vz66)) def v366 : ∀ {Γ A B C D}, Tm66 (snoc66 (snoc66 (snoc66 (snoc66 Γ A) B) C) D) A := var66 (vs66 (vs66 (vs66 vz66))) def tbool66 : Ty66 := sum66 top66 top66 def ttrue66 : ∀ {Γ}, Tm66 Γ tbool66 := left66 tt66 def tfalse66 : ∀ {Γ}, Tm66 Γ tbool66 := right66 tt66 def ifthenelse66 : ∀ {Γ A}, Tm66 Γ (arr66 tbool66 (arr66 A (arr66 A A))) := lam66 (lam66 (lam66 (case66 v266 (lam66 v266) (lam66 v166)))) def times466 : ∀ {Γ A}, Tm66 Γ (arr66 (arr66 A A) (arr66 A A)) := lam66 (lam66 (app66 v166 (app66 v166 (app66 v166 (app66 v166 v066))))) def add66 : ∀ {Γ}, Tm66 Γ (arr66 nat66 (arr66 nat66 nat66)) := lam66 (rec66 v066 (lam66 (lam66 (lam66 (suc66 (app66 v166 v066))))) (lam66 v066)) def mul66 : ∀ {Γ}, Tm66 Γ (arr66 nat66 (arr66 nat66 nat66)) := lam66 (rec66 v066 (lam66 (lam66 (lam66 (app66 (app66 add66 (app66 v166 v066)) v066)))) (lam66 zero66)) def fact66 : ∀ {Γ}, Tm66 Γ (arr66 nat66 nat66) := lam66 (rec66 v066 (lam66 (lam66 (app66 (app66 mul66 (suc66 v166)) v066))) (suc66 zero66)) def Ty67 : Type 1 := ∀ (Ty67 : Type) (nat top bot : Ty67) (arr prod sum : Ty67 → Ty67 → Ty67) , Ty67 def nat67 : Ty67 := λ _ nat67 _ _ _ _ _ => nat67 def top67 : Ty67 := λ _ _ top67 _ _ _ _ => top67 def bot67 : Ty67 := λ _ _ _ bot67 _ _ _ => bot67 def arr67 : Ty67 → Ty67 → Ty67 := λ A B Ty67 nat67 top67 bot67 arr67 prod sum => arr67 (A Ty67 nat67 top67 bot67 arr67 prod sum) (B Ty67 nat67 top67 bot67 arr67 prod sum) def prod67 : Ty67 → Ty67 → Ty67 := λ A B Ty67 nat67 top67 bot67 arr67 prod67 sum => prod67 (A Ty67 nat67 top67 bot67 arr67 prod67 sum) (B Ty67 nat67 top67 bot67 arr67 prod67 sum) def sum67 : Ty67 → Ty67 → Ty67 := λ A B Ty67 nat67 top67 bot67 arr67 prod67 sum67 => sum67 (A Ty67 nat67 top67 bot67 arr67 prod67 sum67) (B Ty67 nat67 top67 bot67 arr67 prod67 sum67) def Con67 : Type 1 := ∀ (Con67 : Type) (nil : Con67) (snoc : Con67 → Ty67 → Con67) , Con67 def nil67 : Con67 := λ Con67 nil67 snoc => nil67 def snoc67 : Con67 → Ty67 → Con67 := λ Γ A Con67 nil67 snoc67 => snoc67 (Γ Con67 nil67 snoc67) A def Var67 : Con67 → Ty67 → Type 1 := λ Γ A => ∀ (Var67 : Con67 → Ty67 → Type) (vz : ∀{Γ A}, Var67 (snoc67 Γ A) A) (vs : ∀{Γ B A}, Var67 Γ A → Var67 (snoc67 Γ B) A) , Var67 Γ A def vz67 : ∀ {Γ A}, Var67 (snoc67 Γ A) A := λ Var67 vz67 vs => vz67 def vs67 : ∀ {Γ B A}, Var67 Γ A → Var67 (snoc67 Γ B) A := λ x Var67 vz67 vs67 => vs67 (x Var67 vz67 vs67) def Tm67 : Con67 → Ty67 → Type 1 := λ Γ A => ∀ (Tm67 : Con67 → Ty67 → Type) (var : ∀ {Γ A}, Var67 Γ A → Tm67 Γ A) (lam : ∀ {Γ A B}, (Tm67 (snoc67 Γ A) B → Tm67 Γ (arr67 A B))) (app : ∀ {Γ A B} , Tm67 Γ (arr67 A B) → Tm67 Γ A → Tm67 Γ B) (tt : ∀ {Γ} , Tm67 Γ top67) (pair : ∀ {Γ A B} , Tm67 Γ A → Tm67 Γ B → Tm67 Γ (prod67 A B)) (fst : ∀ {Γ A B} , Tm67 Γ (prod67 A B) → Tm67 Γ A) (snd : ∀ {Γ A B} , Tm67 Γ (prod67 A B) → Tm67 Γ B) (left : ∀ {Γ A B} , Tm67 Γ A → Tm67 Γ (sum67 A B)) (right : ∀ {Γ A B} , Tm67 Γ B → Tm67 Γ (sum67 A B)) (case : ∀ {Γ A B C} , Tm67 Γ (sum67 A B) → Tm67 Γ (arr67 A C) → Tm67 Γ (arr67 B C) → Tm67 Γ C) (zero : ∀ {Γ} , Tm67 Γ nat67) (suc : ∀ {Γ} , Tm67 Γ nat67 → Tm67 Γ nat67) (rec : ∀ {Γ A} , Tm67 Γ nat67 → Tm67 Γ (arr67 nat67 (arr67 A A)) → Tm67 Γ A → Tm67 Γ A) , Tm67 Γ A def var67 : ∀ {Γ A}, Var67 Γ A → Tm67 Γ A := λ x Tm67 var67 lam app tt pair fst snd left right case zero suc rec => var67 x def lam67 : ∀ {Γ A B} , Tm67 (snoc67 Γ A) B → Tm67 Γ (arr67 A B) := λ t Tm67 var67 lam67 app tt pair fst snd left right case zero suc rec => lam67 (t Tm67 var67 lam67 app tt pair fst snd left right case zero suc rec) def app67 : ∀ {Γ A B} , Tm67 Γ (arr67 A B) → Tm67 Γ A → Tm67 Γ B := λ t u Tm67 var67 lam67 app67 tt pair fst snd left right case zero suc rec => app67 (t Tm67 var67 lam67 app67 tt pair fst snd left right case zero suc rec) (u Tm67 var67 lam67 app67 tt pair fst snd left right case zero suc rec) def tt67 : ∀ {Γ} , Tm67 Γ top67 := λ Tm67 var67 lam67 app67 tt67 pair fst snd left right case zero suc rec => tt67 def pair67 : ∀ {Γ A B} , Tm67 Γ A → Tm67 Γ B → Tm67 Γ (prod67 A B) := λ t u Tm67 var67 lam67 app67 tt67 pair67 fst snd left right case zero suc rec => pair67 (t Tm67 var67 lam67 app67 tt67 pair67 fst snd left right case zero suc rec) (u Tm67 var67 lam67 app67 tt67 pair67 fst snd left right case zero suc rec) def fst67 : ∀ {Γ A B} , Tm67 Γ (prod67 A B) → Tm67 Γ A := λ t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd left right case zero suc rec => fst67 (t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd left right case zero suc rec) def snd67 : ∀ {Γ A B} , Tm67 Γ (prod67 A B) → Tm67 Γ B := λ t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left right case zero suc rec => snd67 (t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left right case zero suc rec) def left67 : ∀ {Γ A B} , Tm67 Γ A → Tm67 Γ (sum67 A B) := λ t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right case zero suc rec => left67 (t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right case zero suc rec) def right67 : ∀ {Γ A B} , Tm67 Γ B → Tm67 Γ (sum67 A B) := λ t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case zero suc rec => right67 (t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case zero suc rec) def case67 : ∀ {Γ A B C} , Tm67 Γ (sum67 A B) → Tm67 Γ (arr67 A C) → Tm67 Γ (arr67 B C) → Tm67 Γ C := λ t u v Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case67 zero suc rec => case67 (t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case67 zero suc rec) (u Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case67 zero suc rec) (v Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case67 zero suc rec) def zero67 : ∀ {Γ} , Tm67 Γ nat67 := λ Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case67 zero67 suc rec => zero67 def suc67 : ∀ {Γ} , Tm67 Γ nat67 → Tm67 Γ nat67 := λ t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case67 zero67 suc67 rec => suc67 (t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case67 zero67 suc67 rec) def rec67 : ∀ {Γ A} , Tm67 Γ nat67 → Tm67 Γ (arr67 nat67 (arr67 A A)) → Tm67 Γ A → Tm67 Γ A := λ t u v Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case67 zero67 suc67 rec67 => rec67 (t Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case67 zero67 suc67 rec67) (u Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case67 zero67 suc67 rec67) (v Tm67 var67 lam67 app67 tt67 pair67 fst67 snd67 left67 right67 case67 zero67 suc67 rec67) def v067 : ∀ {Γ A}, Tm67 (snoc67 Γ A) A := var67 vz67 def v167 : ∀ {Γ A B}, Tm67 (snoc67 (snoc67 Γ A) B) A := var67 (vs67 vz67) def v267 : ∀ {Γ A B C}, Tm67 (snoc67 (snoc67 (snoc67 Γ A) B) C) A := var67 (vs67 (vs67 vz67)) def v367 : ∀ {Γ A B C D}, Tm67 (snoc67 (snoc67 (snoc67 (snoc67 Γ A) B) C) D) A := var67 (vs67 (vs67 (vs67 vz67))) def tbool67 : Ty67 := sum67 top67 top67 def ttrue67 : ∀ {Γ}, Tm67 Γ tbool67 := left67 tt67 def tfalse67 : ∀ {Γ}, Tm67 Γ tbool67 := right67 tt67 def ifthenelse67 : ∀ {Γ A}, Tm67 Γ (arr67 tbool67 (arr67 A (arr67 A A))) := lam67 (lam67 (lam67 (case67 v267 (lam67 v267) (lam67 v167)))) def times467 : ∀ {Γ A}, Tm67 Γ (arr67 (arr67 A A) (arr67 A A)) := lam67 (lam67 (app67 v167 (app67 v167 (app67 v167 (app67 v167 v067))))) def add67 : ∀ {Γ}, Tm67 Γ (arr67 nat67 (arr67 nat67 nat67)) := lam67 (rec67 v067 (lam67 (lam67 (lam67 (suc67 (app67 v167 v067))))) (lam67 v067)) def mul67 : ∀ {Γ}, Tm67 Γ (arr67 nat67 (arr67 nat67 nat67)) := lam67 (rec67 v067 (lam67 (lam67 (lam67 (app67 (app67 add67 (app67 v167 v067)) v067)))) (lam67 zero67)) def fact67 : ∀ {Γ}, Tm67 Γ (arr67 nat67 nat67) := lam67 (rec67 v067 (lam67 (lam67 (app67 (app67 mul67 (suc67 v167)) v067))) (suc67 zero67)) def Ty68 : Type 1 := ∀ (Ty68 : Type) (nat top bot : Ty68) (arr prod sum : Ty68 → Ty68 → Ty68) , Ty68 def nat68 : Ty68 := λ _ nat68 _ _ _ _ _ => nat68 def top68 : Ty68 := λ _ _ top68 _ _ _ _ => top68 def bot68 : Ty68 := λ _ _ _ bot68 _ _ _ => bot68 def arr68 : Ty68 → Ty68 → Ty68 := λ A B Ty68 nat68 top68 bot68 arr68 prod sum => arr68 (A Ty68 nat68 top68 bot68 arr68 prod sum) (B Ty68 nat68 top68 bot68 arr68 prod sum) def prod68 : Ty68 → Ty68 → Ty68 := λ A B Ty68 nat68 top68 bot68 arr68 prod68 sum => prod68 (A Ty68 nat68 top68 bot68 arr68 prod68 sum) (B Ty68 nat68 top68 bot68 arr68 prod68 sum) def sum68 : Ty68 → Ty68 → Ty68 := λ A B Ty68 nat68 top68 bot68 arr68 prod68 sum68 => sum68 (A Ty68 nat68 top68 bot68 arr68 prod68 sum68) (B Ty68 nat68 top68 bot68 arr68 prod68 sum68) def Con68 : Type 1 := ∀ (Con68 : Type) (nil : Con68) (snoc : Con68 → Ty68 → Con68) , Con68 def nil68 : Con68 := λ Con68 nil68 snoc => nil68 def snoc68 : Con68 → Ty68 → Con68 := λ Γ A Con68 nil68 snoc68 => snoc68 (Γ Con68 nil68 snoc68) A def Var68 : Con68 → Ty68 → Type 1 := λ Γ A => ∀ (Var68 : Con68 → Ty68 → Type) (vz : ∀{Γ A}, Var68 (snoc68 Γ A) A) (vs : ∀{Γ B A}, Var68 Γ A → Var68 (snoc68 Γ B) A) , Var68 Γ A def vz68 : ∀ {Γ A}, Var68 (snoc68 Γ A) A := λ Var68 vz68 vs => vz68 def vs68 : ∀ {Γ B A}, Var68 Γ A → Var68 (snoc68 Γ B) A := λ x Var68 vz68 vs68 => vs68 (x Var68 vz68 vs68) def Tm68 : Con68 → Ty68 → Type 1 := λ Γ A => ∀ (Tm68 : Con68 → Ty68 → Type) (var : ∀ {Γ A}, Var68 Γ A → Tm68 Γ A) (lam : ∀ {Γ A B}, (Tm68 (snoc68 Γ A) B → Tm68 Γ (arr68 A B))) (app : ∀ {Γ A B} , Tm68 Γ (arr68 A B) → Tm68 Γ A → Tm68 Γ B) (tt : ∀ {Γ} , Tm68 Γ top68) (pair : ∀ {Γ A B} , Tm68 Γ A → Tm68 Γ B → Tm68 Γ (prod68 A B)) (fst : ∀ {Γ A B} , Tm68 Γ (prod68 A B) → Tm68 Γ A) (snd : ∀ {Γ A B} , Tm68 Γ (prod68 A B) → Tm68 Γ B) (left : ∀ {Γ A B} , Tm68 Γ A → Tm68 Γ (sum68 A B)) (right : ∀ {Γ A B} , Tm68 Γ B → Tm68 Γ (sum68 A B)) (case : ∀ {Γ A B C} , Tm68 Γ (sum68 A B) → Tm68 Γ (arr68 A C) → Tm68 Γ (arr68 B C) → Tm68 Γ C) (zero : ∀ {Γ} , Tm68 Γ nat68) (suc : ∀ {Γ} , Tm68 Γ nat68 → Tm68 Γ nat68) (rec : ∀ {Γ A} , Tm68 Γ nat68 → Tm68 Γ (arr68 nat68 (arr68 A A)) → Tm68 Γ A → Tm68 Γ A) , Tm68 Γ A def var68 : ∀ {Γ A}, Var68 Γ A → Tm68 Γ A := λ x Tm68 var68 lam app tt pair fst snd left right case zero suc rec => var68 x def lam68 : ∀ {Γ A B} , Tm68 (snoc68 Γ A) B → Tm68 Γ (arr68 A B) := λ t Tm68 var68 lam68 app tt pair fst snd left right case zero suc rec => lam68 (t Tm68 var68 lam68 app tt pair fst snd left right case zero suc rec) def app68 : ∀ {Γ A B} , Tm68 Γ (arr68 A B) → Tm68 Γ A → Tm68 Γ B := λ t u Tm68 var68 lam68 app68 tt pair fst snd left right case zero suc rec => app68 (t Tm68 var68 lam68 app68 tt pair fst snd left right case zero suc rec) (u Tm68 var68 lam68 app68 tt pair fst snd left right case zero suc rec) def tt68 : ∀ {Γ} , Tm68 Γ top68 := λ Tm68 var68 lam68 app68 tt68 pair fst snd left right case zero suc rec => tt68 def pair68 : ∀ {Γ A B} , Tm68 Γ A → Tm68 Γ B → Tm68 Γ (prod68 A B) := λ t u Tm68 var68 lam68 app68 tt68 pair68 fst snd left right case zero suc rec => pair68 (t Tm68 var68 lam68 app68 tt68 pair68 fst snd left right case zero suc rec) (u Tm68 var68 lam68 app68 tt68 pair68 fst snd left right case zero suc rec) def fst68 : ∀ {Γ A B} , Tm68 Γ (prod68 A B) → Tm68 Γ A := λ t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd left right case zero suc rec => fst68 (t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd left right case zero suc rec) def snd68 : ∀ {Γ A B} , Tm68 Γ (prod68 A B) → Tm68 Γ B := λ t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left right case zero suc rec => snd68 (t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left right case zero suc rec) def left68 : ∀ {Γ A B} , Tm68 Γ A → Tm68 Γ (sum68 A B) := λ t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right case zero suc rec => left68 (t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right case zero suc rec) def right68 : ∀ {Γ A B} , Tm68 Γ B → Tm68 Γ (sum68 A B) := λ t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case zero suc rec => right68 (t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case zero suc rec) def case68 : ∀ {Γ A B C} , Tm68 Γ (sum68 A B) → Tm68 Γ (arr68 A C) → Tm68 Γ (arr68 B C) → Tm68 Γ C := λ t u v Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case68 zero suc rec => case68 (t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case68 zero suc rec) (u Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case68 zero suc rec) (v Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case68 zero suc rec) def zero68 : ∀ {Γ} , Tm68 Γ nat68 := λ Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case68 zero68 suc rec => zero68 def suc68 : ∀ {Γ} , Tm68 Γ nat68 → Tm68 Γ nat68 := λ t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case68 zero68 suc68 rec => suc68 (t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case68 zero68 suc68 rec) def rec68 : ∀ {Γ A} , Tm68 Γ nat68 → Tm68 Γ (arr68 nat68 (arr68 A A)) → Tm68 Γ A → Tm68 Γ A := λ t u v Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case68 zero68 suc68 rec68 => rec68 (t Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case68 zero68 suc68 rec68) (u Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case68 zero68 suc68 rec68) (v Tm68 var68 lam68 app68 tt68 pair68 fst68 snd68 left68 right68 case68 zero68 suc68 rec68) def v068 : ∀ {Γ A}, Tm68 (snoc68 Γ A) A := var68 vz68 def v168 : ∀ {Γ A B}, Tm68 (snoc68 (snoc68 Γ A) B) A := var68 (vs68 vz68) def v268 : ∀ {Γ A B C}, Tm68 (snoc68 (snoc68 (snoc68 Γ A) B) C) A := var68 (vs68 (vs68 vz68)) def v368 : ∀ {Γ A B C D}, Tm68 (snoc68 (snoc68 (snoc68 (snoc68 Γ A) B) C) D) A := var68 (vs68 (vs68 (vs68 vz68))) def tbool68 : Ty68 := sum68 top68 top68 def ttrue68 : ∀ {Γ}, Tm68 Γ tbool68 := left68 tt68 def tfalse68 : ∀ {Γ}, Tm68 Γ tbool68 := right68 tt68 def ifthenelse68 : ∀ {Γ A}, Tm68 Γ (arr68 tbool68 (arr68 A (arr68 A A))) := lam68 (lam68 (lam68 (case68 v268 (lam68 v268) (lam68 v168)))) def times468 : ∀ {Γ A}, Tm68 Γ (arr68 (arr68 A A) (arr68 A A)) := lam68 (lam68 (app68 v168 (app68 v168 (app68 v168 (app68 v168 v068))))) def add68 : ∀ {Γ}, Tm68 Γ (arr68 nat68 (arr68 nat68 nat68)) := lam68 (rec68 v068 (lam68 (lam68 (lam68 (suc68 (app68 v168 v068))))) (lam68 v068)) def mul68 : ∀ {Γ}, Tm68 Γ (arr68 nat68 (arr68 nat68 nat68)) := lam68 (rec68 v068 (lam68 (lam68 (lam68 (app68 (app68 add68 (app68 v168 v068)) v068)))) (lam68 zero68)) def fact68 : ∀ {Γ}, Tm68 Γ (arr68 nat68 nat68) := lam68 (rec68 v068 (lam68 (lam68 (app68 (app68 mul68 (suc68 v168)) v068))) (suc68 zero68)) def Ty69 : Type 1 := ∀ (Ty69 : Type) (nat top bot : Ty69) (arr prod sum : Ty69 → Ty69 → Ty69) , Ty69 def nat69 : Ty69 := λ _ nat69 _ _ _ _ _ => nat69 def top69 : Ty69 := λ _ _ top69 _ _ _ _ => top69 def bot69 : Ty69 := λ _ _ _ bot69 _ _ _ => bot69 def arr69 : Ty69 → Ty69 → Ty69 := λ A B Ty69 nat69 top69 bot69 arr69 prod sum => arr69 (A Ty69 nat69 top69 bot69 arr69 prod sum) (B Ty69 nat69 top69 bot69 arr69 prod sum) def prod69 : Ty69 → Ty69 → Ty69 := λ A B Ty69 nat69 top69 bot69 arr69 prod69 sum => prod69 (A Ty69 nat69 top69 bot69 arr69 prod69 sum) (B Ty69 nat69 top69 bot69 arr69 prod69 sum) def sum69 : Ty69 → Ty69 → Ty69 := λ A B Ty69 nat69 top69 bot69 arr69 prod69 sum69 => sum69 (A Ty69 nat69 top69 bot69 arr69 prod69 sum69) (B Ty69 nat69 top69 bot69 arr69 prod69 sum69) def Con69 : Type 1 := ∀ (Con69 : Type) (nil : Con69) (snoc : Con69 → Ty69 → Con69) , Con69 def nil69 : Con69 := λ Con69 nil69 snoc => nil69 def snoc69 : Con69 → Ty69 → Con69 := λ Γ A Con69 nil69 snoc69 => snoc69 (Γ Con69 nil69 snoc69) A def Var69 : Con69 → Ty69 → Type 1 := λ Γ A => ∀ (Var69 : Con69 → Ty69 → Type) (vz : ∀{Γ A}, Var69 (snoc69 Γ A) A) (vs : ∀{Γ B A}, Var69 Γ A → Var69 (snoc69 Γ B) A) , Var69 Γ A def vz69 : ∀ {Γ A}, Var69 (snoc69 Γ A) A := λ Var69 vz69 vs => vz69 def vs69 : ∀ {Γ B A}, Var69 Γ A → Var69 (snoc69 Γ B) A := λ x Var69 vz69 vs69 => vs69 (x Var69 vz69 vs69) def Tm69 : Con69 → Ty69 → Type 1 := λ Γ A => ∀ (Tm69 : Con69 → Ty69 → Type) (var : ∀ {Γ A}, Var69 Γ A → Tm69 Γ A) (lam : ∀ {Γ A B}, (Tm69 (snoc69 Γ A) B → Tm69 Γ (arr69 A B))) (app : ∀ {Γ A B} , Tm69 Γ (arr69 A B) → Tm69 Γ A → Tm69 Γ B) (tt : ∀ {Γ} , Tm69 Γ top69) (pair : ∀ {Γ A B} , Tm69 Γ A → Tm69 Γ B → Tm69 Γ (prod69 A B)) (fst : ∀ {Γ A B} , Tm69 Γ (prod69 A B) → Tm69 Γ A) (snd : ∀ {Γ A B} , Tm69 Γ (prod69 A B) → Tm69 Γ B) (left : ∀ {Γ A B} , Tm69 Γ A → Tm69 Γ (sum69 A B)) (right : ∀ {Γ A B} , Tm69 Γ B → Tm69 Γ (sum69 A B)) (case : ∀ {Γ A B C} , Tm69 Γ (sum69 A B) → Tm69 Γ (arr69 A C) → Tm69 Γ (arr69 B C) → Tm69 Γ C) (zero : ∀ {Γ} , Tm69 Γ nat69) (suc : ∀ {Γ} , Tm69 Γ nat69 → Tm69 Γ nat69) (rec : ∀ {Γ A} , Tm69 Γ nat69 → Tm69 Γ (arr69 nat69 (arr69 A A)) → Tm69 Γ A → Tm69 Γ A) , Tm69 Γ A def var69 : ∀ {Γ A}, Var69 Γ A → Tm69 Γ A := λ x Tm69 var69 lam app tt pair fst snd left right case zero suc rec => var69 x def lam69 : ∀ {Γ A B} , Tm69 (snoc69 Γ A) B → Tm69 Γ (arr69 A B) := λ t Tm69 var69 lam69 app tt pair fst snd left right case zero suc rec => lam69 (t Tm69 var69 lam69 app tt pair fst snd left right case zero suc rec) def app69 : ∀ {Γ A B} , Tm69 Γ (arr69 A B) → Tm69 Γ A → Tm69 Γ B := λ t u Tm69 var69 lam69 app69 tt pair fst snd left right case zero suc rec => app69 (t Tm69 var69 lam69 app69 tt pair fst snd left right case zero suc rec) (u Tm69 var69 lam69 app69 tt pair fst snd left right case zero suc rec) def tt69 : ∀ {Γ} , Tm69 Γ top69 := λ Tm69 var69 lam69 app69 tt69 pair fst snd left right case zero suc rec => tt69 def pair69 : ∀ {Γ A B} , Tm69 Γ A → Tm69 Γ B → Tm69 Γ (prod69 A B) := λ t u Tm69 var69 lam69 app69 tt69 pair69 fst snd left right case zero suc rec => pair69 (t Tm69 var69 lam69 app69 tt69 pair69 fst snd left right case zero suc rec) (u Tm69 var69 lam69 app69 tt69 pair69 fst snd left right case zero suc rec) def fst69 : ∀ {Γ A B} , Tm69 Γ (prod69 A B) → Tm69 Γ A := λ t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd left right case zero suc rec => fst69 (t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd left right case zero suc rec) def snd69 : ∀ {Γ A B} , Tm69 Γ (prod69 A B) → Tm69 Γ B := λ t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left right case zero suc rec => snd69 (t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left right case zero suc rec) def left69 : ∀ {Γ A B} , Tm69 Γ A → Tm69 Γ (sum69 A B) := λ t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right case zero suc rec => left69 (t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right case zero suc rec) def right69 : ∀ {Γ A B} , Tm69 Γ B → Tm69 Γ (sum69 A B) := λ t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case zero suc rec => right69 (t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case zero suc rec) def case69 : ∀ {Γ A B C} , Tm69 Γ (sum69 A B) → Tm69 Γ (arr69 A C) → Tm69 Γ (arr69 B C) → Tm69 Γ C := λ t u v Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case69 zero suc rec => case69 (t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case69 zero suc rec) (u Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case69 zero suc rec) (v Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case69 zero suc rec) def zero69 : ∀ {Γ} , Tm69 Γ nat69 := λ Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case69 zero69 suc rec => zero69 def suc69 : ∀ {Γ} , Tm69 Γ nat69 → Tm69 Γ nat69 := λ t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case69 zero69 suc69 rec => suc69 (t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case69 zero69 suc69 rec) def rec69 : ∀ {Γ A} , Tm69 Γ nat69 → Tm69 Γ (arr69 nat69 (arr69 A A)) → Tm69 Γ A → Tm69 Γ A := λ t u v Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case69 zero69 suc69 rec69 => rec69 (t Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case69 zero69 suc69 rec69) (u Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case69 zero69 suc69 rec69) (v Tm69 var69 lam69 app69 tt69 pair69 fst69 snd69 left69 right69 case69 zero69 suc69 rec69) def v069 : ∀ {Γ A}, Tm69 (snoc69 Γ A) A := var69 vz69 def v169 : ∀ {Γ A B}, Tm69 (snoc69 (snoc69 Γ A) B) A := var69 (vs69 vz69) def v269 : ∀ {Γ A B C}, Tm69 (snoc69 (snoc69 (snoc69 Γ A) B) C) A := var69 (vs69 (vs69 vz69)) def v369 : ∀ {Γ A B C D}, Tm69 (snoc69 (snoc69 (snoc69 (snoc69 Γ A) B) C) D) A := var69 (vs69 (vs69 (vs69 vz69))) def tbool69 : Ty69 := sum69 top69 top69 def ttrue69 : ∀ {Γ}, Tm69 Γ tbool69 := left69 tt69 def tfalse69 : ∀ {Γ}, Tm69 Γ tbool69 := right69 tt69 def ifthenelse69 : ∀ {Γ A}, Tm69 Γ (arr69 tbool69 (arr69 A (arr69 A A))) := lam69 (lam69 (lam69 (case69 v269 (lam69 v269) (lam69 v169)))) def times469 : ∀ {Γ A}, Tm69 Γ (arr69 (arr69 A A) (arr69 A A)) := lam69 (lam69 (app69 v169 (app69 v169 (app69 v169 (app69 v169 v069))))) def add69 : ∀ {Γ}, Tm69 Γ (arr69 nat69 (arr69 nat69 nat69)) := lam69 (rec69 v069 (lam69 (lam69 (lam69 (suc69 (app69 v169 v069))))) (lam69 v069)) def mul69 : ∀ {Γ}, Tm69 Γ (arr69 nat69 (arr69 nat69 nat69)) := lam69 (rec69 v069 (lam69 (lam69 (lam69 (app69 (app69 add69 (app69 v169 v069)) v069)))) (lam69 zero69)) def fact69 : ∀ {Γ}, Tm69 Γ (arr69 nat69 nat69) := lam69 (rec69 v069 (lam69 (lam69 (app69 (app69 mul69 (suc69 v169)) v069))) (suc69 zero69)) def Ty70 : Type 1 := ∀ (Ty70 : Type) (nat top bot : Ty70) (arr prod sum : Ty70 → Ty70 → Ty70) , Ty70 def nat70 : Ty70 := λ _ nat70 _ _ _ _ _ => nat70 def top70 : Ty70 := λ _ _ top70 _ _ _ _ => top70 def bot70 : Ty70 := λ _ _ _ bot70 _ _ _ => bot70 def arr70 : Ty70 → Ty70 → Ty70 := λ A B Ty70 nat70 top70 bot70 arr70 prod sum => arr70 (A Ty70 nat70 top70 bot70 arr70 prod sum) (B Ty70 nat70 top70 bot70 arr70 prod sum) def prod70 : Ty70 → Ty70 → Ty70 := λ A B Ty70 nat70 top70 bot70 arr70 prod70 sum => prod70 (A Ty70 nat70 top70 bot70 arr70 prod70 sum) (B Ty70 nat70 top70 bot70 arr70 prod70 sum) def sum70 : Ty70 → Ty70 → Ty70 := λ A B Ty70 nat70 top70 bot70 arr70 prod70 sum70 => sum70 (A Ty70 nat70 top70 bot70 arr70 prod70 sum70) (B Ty70 nat70 top70 bot70 arr70 prod70 sum70) def Con70 : Type 1 := ∀ (Con70 : Type) (nil : Con70) (snoc : Con70 → Ty70 → Con70) , Con70 def nil70 : Con70 := λ Con70 nil70 snoc => nil70 def snoc70 : Con70 → Ty70 → Con70 := λ Γ A Con70 nil70 snoc70 => snoc70 (Γ Con70 nil70 snoc70) A def Var70 : Con70 → Ty70 → Type 1 := λ Γ A => ∀ (Var70 : Con70 → Ty70 → Type) (vz : ∀{Γ A}, Var70 (snoc70 Γ A) A) (vs : ∀{Γ B A}, Var70 Γ A → Var70 (snoc70 Γ B) A) , Var70 Γ A def vz70 : ∀ {Γ A}, Var70 (snoc70 Γ A) A := λ Var70 vz70 vs => vz70 def vs70 : ∀ {Γ B A}, Var70 Γ A → Var70 (snoc70 Γ B) A := λ x Var70 vz70 vs70 => vs70 (x Var70 vz70 vs70) def Tm70 : Con70 → Ty70 → Type 1 := λ Γ A => ∀ (Tm70 : Con70 → Ty70 → Type) (var : ∀ {Γ A}, Var70 Γ A → Tm70 Γ A) (lam : ∀ {Γ A B}, (Tm70 (snoc70 Γ A) B → Tm70 Γ (arr70 A B))) (app : ∀ {Γ A B} , Tm70 Γ (arr70 A B) → Tm70 Γ A → Tm70 Γ B) (tt : ∀ {Γ} , Tm70 Γ top70) (pair : ∀ {Γ A B} , Tm70 Γ A → Tm70 Γ B → Tm70 Γ (prod70 A B)) (fst : ∀ {Γ A B} , Tm70 Γ (prod70 A B) → Tm70 Γ A) (snd : ∀ {Γ A B} , Tm70 Γ (prod70 A B) → Tm70 Γ B) (left : ∀ {Γ A B} , Tm70 Γ A → Tm70 Γ (sum70 A B)) (right : ∀ {Γ A B} , Tm70 Γ B → Tm70 Γ (sum70 A B)) (case : ∀ {Γ A B C} , Tm70 Γ (sum70 A B) → Tm70 Γ (arr70 A C) → Tm70 Γ (arr70 B C) → Tm70 Γ C) (zero : ∀ {Γ} , Tm70 Γ nat70) (suc : ∀ {Γ} , Tm70 Γ nat70 → Tm70 Γ nat70) (rec : ∀ {Γ A} , Tm70 Γ nat70 → Tm70 Γ (arr70 nat70 (arr70 A A)) → Tm70 Γ A → Tm70 Γ A) , Tm70 Γ A def var70 : ∀ {Γ A}, Var70 Γ A → Tm70 Γ A := λ x Tm70 var70 lam app tt pair fst snd left right case zero suc rec => var70 x def lam70 : ∀ {Γ A B} , Tm70 (snoc70 Γ A) B → Tm70 Γ (arr70 A B) := λ t Tm70 var70 lam70 app tt pair fst snd left right case zero suc rec => lam70 (t Tm70 var70 lam70 app tt pair fst snd left right case zero suc rec) def app70 : ∀ {Γ A B} , Tm70 Γ (arr70 A B) → Tm70 Γ A → Tm70 Γ B := λ t u Tm70 var70 lam70 app70 tt pair fst snd left right case zero suc rec => app70 (t Tm70 var70 lam70 app70 tt pair fst snd left right case zero suc rec) (u Tm70 var70 lam70 app70 tt pair fst snd left right case zero suc rec) def tt70 : ∀ {Γ} , Tm70 Γ top70 := λ Tm70 var70 lam70 app70 tt70 pair fst snd left right case zero suc rec => tt70 def pair70 : ∀ {Γ A B} , Tm70 Γ A → Tm70 Γ B → Tm70 Γ (prod70 A B) := λ t u Tm70 var70 lam70 app70 tt70 pair70 fst snd left right case zero suc rec => pair70 (t Tm70 var70 lam70 app70 tt70 pair70 fst snd left right case zero suc rec) (u Tm70 var70 lam70 app70 tt70 pair70 fst snd left right case zero suc rec) def fst70 : ∀ {Γ A B} , Tm70 Γ (prod70 A B) → Tm70 Γ A := λ t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd left right case zero suc rec => fst70 (t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd left right case zero suc rec) def snd70 : ∀ {Γ A B} , Tm70 Γ (prod70 A B) → Tm70 Γ B := λ t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left right case zero suc rec => snd70 (t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left right case zero suc rec) def left70 : ∀ {Γ A B} , Tm70 Γ A → Tm70 Γ (sum70 A B) := λ t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right case zero suc rec => left70 (t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right case zero suc rec) def right70 : ∀ {Γ A B} , Tm70 Γ B → Tm70 Γ (sum70 A B) := λ t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case zero suc rec => right70 (t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case zero suc rec) def case70 : ∀ {Γ A B C} , Tm70 Γ (sum70 A B) → Tm70 Γ (arr70 A C) → Tm70 Γ (arr70 B C) → Tm70 Γ C := λ t u v Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case70 zero suc rec => case70 (t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case70 zero suc rec) (u Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case70 zero suc rec) (v Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case70 zero suc rec) def zero70 : ∀ {Γ} , Tm70 Γ nat70 := λ Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case70 zero70 suc rec => zero70 def suc70 : ∀ {Γ} , Tm70 Γ nat70 → Tm70 Γ nat70 := λ t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case70 zero70 suc70 rec => suc70 (t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case70 zero70 suc70 rec) def rec70 : ∀ {Γ A} , Tm70 Γ nat70 → Tm70 Γ (arr70 nat70 (arr70 A A)) → Tm70 Γ A → Tm70 Γ A := λ t u v Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case70 zero70 suc70 rec70 => rec70 (t Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case70 zero70 suc70 rec70) (u Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case70 zero70 suc70 rec70) (v Tm70 var70 lam70 app70 tt70 pair70 fst70 snd70 left70 right70 case70 zero70 suc70 rec70) def v070 : ∀ {Γ A}, Tm70 (snoc70 Γ A) A := var70 vz70 def v170 : ∀ {Γ A B}, Tm70 (snoc70 (snoc70 Γ A) B) A := var70 (vs70 vz70) def v270 : ∀ {Γ A B C}, Tm70 (snoc70 (snoc70 (snoc70 Γ A) B) C) A := var70 (vs70 (vs70 vz70)) def v370 : ∀ {Γ A B C D}, Tm70 (snoc70 (snoc70 (snoc70 (snoc70 Γ A) B) C) D) A := var70 (vs70 (vs70 (vs70 vz70))) def tbool70 : Ty70 := sum70 top70 top70 def ttrue70 : ∀ {Γ}, Tm70 Γ tbool70 := left70 tt70 def tfalse70 : ∀ {Γ}, Tm70 Γ tbool70 := right70 tt70 def ifthenelse70 : ∀ {Γ A}, Tm70 Γ (arr70 tbool70 (arr70 A (arr70 A A))) := lam70 (lam70 (lam70 (case70 v270 (lam70 v270) (lam70 v170)))) def times470 : ∀ {Γ A}, Tm70 Γ (arr70 (arr70 A A) (arr70 A A)) := lam70 (lam70 (app70 v170 (app70 v170 (app70 v170 (app70 v170 v070))))) def add70 : ∀ {Γ}, Tm70 Γ (arr70 nat70 (arr70 nat70 nat70)) := lam70 (rec70 v070 (lam70 (lam70 (lam70 (suc70 (app70 v170 v070))))) (lam70 v070)) def mul70 : ∀ {Γ}, Tm70 Γ (arr70 nat70 (arr70 nat70 nat70)) := lam70 (rec70 v070 (lam70 (lam70 (lam70 (app70 (app70 add70 (app70 v170 v070)) v070)))) (lam70 zero70)) def fact70 : ∀ {Γ}, Tm70 Γ (arr70 nat70 nat70) := lam70 (rec70 v070 (lam70 (lam70 (app70 (app70 mul70 (suc70 v170)) v070))) (suc70 zero70)) def Ty71 : Type 1 := ∀ (Ty71 : Type) (nat top bot : Ty71) (arr prod sum : Ty71 → Ty71 → Ty71) , Ty71 def nat71 : Ty71 := λ _ nat71 _ _ _ _ _ => nat71 def top71 : Ty71 := λ _ _ top71 _ _ _ _ => top71 def bot71 : Ty71 := λ _ _ _ bot71 _ _ _ => bot71 def arr71 : Ty71 → Ty71 → Ty71 := λ A B Ty71 nat71 top71 bot71 arr71 prod sum => arr71 (A Ty71 nat71 top71 bot71 arr71 prod sum) (B Ty71 nat71 top71 bot71 arr71 prod sum) def prod71 : Ty71 → Ty71 → Ty71 := λ A B Ty71 nat71 top71 bot71 arr71 prod71 sum => prod71 (A Ty71 nat71 top71 bot71 arr71 prod71 sum) (B Ty71 nat71 top71 bot71 arr71 prod71 sum) def sum71 : Ty71 → Ty71 → Ty71 := λ A B Ty71 nat71 top71 bot71 arr71 prod71 sum71 => sum71 (A Ty71 nat71 top71 bot71 arr71 prod71 sum71) (B Ty71 nat71 top71 bot71 arr71 prod71 sum71) def Con71 : Type 1 := ∀ (Con71 : Type) (nil : Con71) (snoc : Con71 → Ty71 → Con71) , Con71 def nil71 : Con71 := λ Con71 nil71 snoc => nil71 def snoc71 : Con71 → Ty71 → Con71 := λ Γ A Con71 nil71 snoc71 => snoc71 (Γ Con71 nil71 snoc71) A def Var71 : Con71 → Ty71 → Type 1 := λ Γ A => ∀ (Var71 : Con71 → Ty71 → Type) (vz : ∀{Γ A}, Var71 (snoc71 Γ A) A) (vs : ∀{Γ B A}, Var71 Γ A → Var71 (snoc71 Γ B) A) , Var71 Γ A def vz71 : ∀ {Γ A}, Var71 (snoc71 Γ A) A := λ Var71 vz71 vs => vz71 def vs71 : ∀ {Γ B A}, Var71 Γ A → Var71 (snoc71 Γ B) A := λ x Var71 vz71 vs71 => vs71 (x Var71 vz71 vs71) def Tm71 : Con71 → Ty71 → Type 1 := λ Γ A => ∀ (Tm71 : Con71 → Ty71 → Type) (var : ∀ {Γ A}, Var71 Γ A → Tm71 Γ A) (lam : ∀ {Γ A B}, (Tm71 (snoc71 Γ A) B → Tm71 Γ (arr71 A B))) (app : ∀ {Γ A B} , Tm71 Γ (arr71 A B) → Tm71 Γ A → Tm71 Γ B) (tt : ∀ {Γ} , Tm71 Γ top71) (pair : ∀ {Γ A B} , Tm71 Γ A → Tm71 Γ B → Tm71 Γ (prod71 A B)) (fst : ∀ {Γ A B} , Tm71 Γ (prod71 A B) → Tm71 Γ A) (snd : ∀ {Γ A B} , Tm71 Γ (prod71 A B) → Tm71 Γ B) (left : ∀ {Γ A B} , Tm71 Γ A → Tm71 Γ (sum71 A B)) (right : ∀ {Γ A B} , Tm71 Γ B → Tm71 Γ (sum71 A B)) (case : ∀ {Γ A B C} , Tm71 Γ (sum71 A B) → Tm71 Γ (arr71 A C) → Tm71 Γ (arr71 B C) → Tm71 Γ C) (zero : ∀ {Γ} , Tm71 Γ nat71) (suc : ∀ {Γ} , Tm71 Γ nat71 → Tm71 Γ nat71) (rec : ∀ {Γ A} , Tm71 Γ nat71 → Tm71 Γ (arr71 nat71 (arr71 A A)) → Tm71 Γ A → Tm71 Γ A) , Tm71 Γ A def var71 : ∀ {Γ A}, Var71 Γ A → Tm71 Γ A := λ x Tm71 var71 lam app tt pair fst snd left right case zero suc rec => var71 x def lam71 : ∀ {Γ A B} , Tm71 (snoc71 Γ A) B → Tm71 Γ (arr71 A B) := λ t Tm71 var71 lam71 app tt pair fst snd left right case zero suc rec => lam71 (t Tm71 var71 lam71 app tt pair fst snd left right case zero suc rec) def app71 : ∀ {Γ A B} , Tm71 Γ (arr71 A B) → Tm71 Γ A → Tm71 Γ B := λ t u Tm71 var71 lam71 app71 tt pair fst snd left right case zero suc rec => app71 (t Tm71 var71 lam71 app71 tt pair fst snd left right case zero suc rec) (u Tm71 var71 lam71 app71 tt pair fst snd left right case zero suc rec) def tt71 : ∀ {Γ} , Tm71 Γ top71 := λ Tm71 var71 lam71 app71 tt71 pair fst snd left right case zero suc rec => tt71 def pair71 : ∀ {Γ A B} , Tm71 Γ A → Tm71 Γ B → Tm71 Γ (prod71 A B) := λ t u Tm71 var71 lam71 app71 tt71 pair71 fst snd left right case zero suc rec => pair71 (t Tm71 var71 lam71 app71 tt71 pair71 fst snd left right case zero suc rec) (u Tm71 var71 lam71 app71 tt71 pair71 fst snd left right case zero suc rec) def fst71 : ∀ {Γ A B} , Tm71 Γ (prod71 A B) → Tm71 Γ A := λ t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd left right case zero suc rec => fst71 (t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd left right case zero suc rec) def snd71 : ∀ {Γ A B} , Tm71 Γ (prod71 A B) → Tm71 Γ B := λ t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left right case zero suc rec => snd71 (t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left right case zero suc rec) def left71 : ∀ {Γ A B} , Tm71 Γ A → Tm71 Γ (sum71 A B) := λ t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right case zero suc rec => left71 (t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right case zero suc rec) def right71 : ∀ {Γ A B} , Tm71 Γ B → Tm71 Γ (sum71 A B) := λ t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case zero suc rec => right71 (t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case zero suc rec) def case71 : ∀ {Γ A B C} , Tm71 Γ (sum71 A B) → Tm71 Γ (arr71 A C) → Tm71 Γ (arr71 B C) → Tm71 Γ C := λ t u v Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case71 zero suc rec => case71 (t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case71 zero suc rec) (u Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case71 zero suc rec) (v Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case71 zero suc rec) def zero71 : ∀ {Γ} , Tm71 Γ nat71 := λ Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case71 zero71 suc rec => zero71 def suc71 : ∀ {Γ} , Tm71 Γ nat71 → Tm71 Γ nat71 := λ t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case71 zero71 suc71 rec => suc71 (t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case71 zero71 suc71 rec) def rec71 : ∀ {Γ A} , Tm71 Γ nat71 → Tm71 Γ (arr71 nat71 (arr71 A A)) → Tm71 Γ A → Tm71 Γ A := λ t u v Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case71 zero71 suc71 rec71 => rec71 (t Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case71 zero71 suc71 rec71) (u Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case71 zero71 suc71 rec71) (v Tm71 var71 lam71 app71 tt71 pair71 fst71 snd71 left71 right71 case71 zero71 suc71 rec71) def v071 : ∀ {Γ A}, Tm71 (snoc71 Γ A) A := var71 vz71 def v171 : ∀ {Γ A B}, Tm71 (snoc71 (snoc71 Γ A) B) A := var71 (vs71 vz71) def v271 : ∀ {Γ A B C}, Tm71 (snoc71 (snoc71 (snoc71 Γ A) B) C) A := var71 (vs71 (vs71 vz71)) def v371 : ∀ {Γ A B C D}, Tm71 (snoc71 (snoc71 (snoc71 (snoc71 Γ A) B) C) D) A := var71 (vs71 (vs71 (vs71 vz71))) def tbool71 : Ty71 := sum71 top71 top71 def ttrue71 : ∀ {Γ}, Tm71 Γ tbool71 := left71 tt71 def tfalse71 : ∀ {Γ}, Tm71 Γ tbool71 := right71 tt71 def ifthenelse71 : ∀ {Γ A}, Tm71 Γ (arr71 tbool71 (arr71 A (arr71 A A))) := lam71 (lam71 (lam71 (case71 v271 (lam71 v271) (lam71 v171)))) def times471 : ∀ {Γ A}, Tm71 Γ (arr71 (arr71 A A) (arr71 A A)) := lam71 (lam71 (app71 v171 (app71 v171 (app71 v171 (app71 v171 v071))))) def add71 : ∀ {Γ}, Tm71 Γ (arr71 nat71 (arr71 nat71 nat71)) := lam71 (rec71 v071 (lam71 (lam71 (lam71 (suc71 (app71 v171 v071))))) (lam71 v071)) def mul71 : ∀ {Γ}, Tm71 Γ (arr71 nat71 (arr71 nat71 nat71)) := lam71 (rec71 v071 (lam71 (lam71 (lam71 (app71 (app71 add71 (app71 v171 v071)) v071)))) (lam71 zero71)) def fact71 : ∀ {Γ}, Tm71 Γ (arr71 nat71 nat71) := lam71 (rec71 v071 (lam71 (lam71 (app71 (app71 mul71 (suc71 v171)) v071))) (suc71 zero71)) def Ty72 : Type 1 := ∀ (Ty72 : Type) (nat top bot : Ty72) (arr prod sum : Ty72 → Ty72 → Ty72) , Ty72 def nat72 : Ty72 := λ _ nat72 _ _ _ _ _ => nat72 def top72 : Ty72 := λ _ _ top72 _ _ _ _ => top72 def bot72 : Ty72 := λ _ _ _ bot72 _ _ _ => bot72 def arr72 : Ty72 → Ty72 → Ty72 := λ A B Ty72 nat72 top72 bot72 arr72 prod sum => arr72 (A Ty72 nat72 top72 bot72 arr72 prod sum) (B Ty72 nat72 top72 bot72 arr72 prod sum) def prod72 : Ty72 → Ty72 → Ty72 := λ A B Ty72 nat72 top72 bot72 arr72 prod72 sum => prod72 (A Ty72 nat72 top72 bot72 arr72 prod72 sum) (B Ty72 nat72 top72 bot72 arr72 prod72 sum) def sum72 : Ty72 → Ty72 → Ty72 := λ A B Ty72 nat72 top72 bot72 arr72 prod72 sum72 => sum72 (A Ty72 nat72 top72 bot72 arr72 prod72 sum72) (B Ty72 nat72 top72 bot72 arr72 prod72 sum72) def Con72 : Type 1 := ∀ (Con72 : Type) (nil : Con72) (snoc : Con72 → Ty72 → Con72) , Con72 def nil72 : Con72 := λ Con72 nil72 snoc => nil72 def snoc72 : Con72 → Ty72 → Con72 := λ Γ A Con72 nil72 snoc72 => snoc72 (Γ Con72 nil72 snoc72) A def Var72 : Con72 → Ty72 → Type 1 := λ Γ A => ∀ (Var72 : Con72 → Ty72 → Type) (vz : ∀{Γ A}, Var72 (snoc72 Γ A) A) (vs : ∀{Γ B A}, Var72 Γ A → Var72 (snoc72 Γ B) A) , Var72 Γ A def vz72 : ∀ {Γ A}, Var72 (snoc72 Γ A) A := λ Var72 vz72 vs => vz72 def vs72 : ∀ {Γ B A}, Var72 Γ A → Var72 (snoc72 Γ B) A := λ x Var72 vz72 vs72 => vs72 (x Var72 vz72 vs72) def Tm72 : Con72 → Ty72 → Type 1 := λ Γ A => ∀ (Tm72 : Con72 → Ty72 → Type) (var : ∀ {Γ A}, Var72 Γ A → Tm72 Γ A) (lam : ∀ {Γ A B}, (Tm72 (snoc72 Γ A) B → Tm72 Γ (arr72 A B))) (app : ∀ {Γ A B} , Tm72 Γ (arr72 A B) → Tm72 Γ A → Tm72 Γ B) (tt : ∀ {Γ} , Tm72 Γ top72) (pair : ∀ {Γ A B} , Tm72 Γ A → Tm72 Γ B → Tm72 Γ (prod72 A B)) (fst : ∀ {Γ A B} , Tm72 Γ (prod72 A B) → Tm72 Γ A) (snd : ∀ {Γ A B} , Tm72 Γ (prod72 A B) → Tm72 Γ B) (left : ∀ {Γ A B} , Tm72 Γ A → Tm72 Γ (sum72 A B)) (right : ∀ {Γ A B} , Tm72 Γ B → Tm72 Γ (sum72 A B)) (case : ∀ {Γ A B C} , Tm72 Γ (sum72 A B) → Tm72 Γ (arr72 A C) → Tm72 Γ (arr72 B C) → Tm72 Γ C) (zero : ∀ {Γ} , Tm72 Γ nat72) (suc : ∀ {Γ} , Tm72 Γ nat72 → Tm72 Γ nat72) (rec : ∀ {Γ A} , Tm72 Γ nat72 → Tm72 Γ (arr72 nat72 (arr72 A A)) → Tm72 Γ A → Tm72 Γ A) , Tm72 Γ A def var72 : ∀ {Γ A}, Var72 Γ A → Tm72 Γ A := λ x Tm72 var72 lam app tt pair fst snd left right case zero suc rec => var72 x def lam72 : ∀ {Γ A B} , Tm72 (snoc72 Γ A) B → Tm72 Γ (arr72 A B) := λ t Tm72 var72 lam72 app tt pair fst snd left right case zero suc rec => lam72 (t Tm72 var72 lam72 app tt pair fst snd left right case zero suc rec) def app72 : ∀ {Γ A B} , Tm72 Γ (arr72 A B) → Tm72 Γ A → Tm72 Γ B := λ t u Tm72 var72 lam72 app72 tt pair fst snd left right case zero suc rec => app72 (t Tm72 var72 lam72 app72 tt pair fst snd left right case zero suc rec) (u Tm72 var72 lam72 app72 tt pair fst snd left right case zero suc rec) def tt72 : ∀ {Γ} , Tm72 Γ top72 := λ Tm72 var72 lam72 app72 tt72 pair fst snd left right case zero suc rec => tt72 def pair72 : ∀ {Γ A B} , Tm72 Γ A → Tm72 Γ B → Tm72 Γ (prod72 A B) := λ t u Tm72 var72 lam72 app72 tt72 pair72 fst snd left right case zero suc rec => pair72 (t Tm72 var72 lam72 app72 tt72 pair72 fst snd left right case zero suc rec) (u Tm72 var72 lam72 app72 tt72 pair72 fst snd left right case zero suc rec) def fst72 : ∀ {Γ A B} , Tm72 Γ (prod72 A B) → Tm72 Γ A := λ t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd left right case zero suc rec => fst72 (t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd left right case zero suc rec) def snd72 : ∀ {Γ A B} , Tm72 Γ (prod72 A B) → Tm72 Γ B := λ t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left right case zero suc rec => snd72 (t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left right case zero suc rec) def left72 : ∀ {Γ A B} , Tm72 Γ A → Tm72 Γ (sum72 A B) := λ t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right case zero suc rec => left72 (t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right case zero suc rec) def right72 : ∀ {Γ A B} , Tm72 Γ B → Tm72 Γ (sum72 A B) := λ t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case zero suc rec => right72 (t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case zero suc rec) def case72 : ∀ {Γ A B C} , Tm72 Γ (sum72 A B) → Tm72 Γ (arr72 A C) → Tm72 Γ (arr72 B C) → Tm72 Γ C := λ t u v Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case72 zero suc rec => case72 (t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case72 zero suc rec) (u Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case72 zero suc rec) (v Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case72 zero suc rec) def zero72 : ∀ {Γ} , Tm72 Γ nat72 := λ Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case72 zero72 suc rec => zero72 def suc72 : ∀ {Γ} , Tm72 Γ nat72 → Tm72 Γ nat72 := λ t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case72 zero72 suc72 rec => suc72 (t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case72 zero72 suc72 rec) def rec72 : ∀ {Γ A} , Tm72 Γ nat72 → Tm72 Γ (arr72 nat72 (arr72 A A)) → Tm72 Γ A → Tm72 Γ A := λ t u v Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case72 zero72 suc72 rec72 => rec72 (t Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case72 zero72 suc72 rec72) (u Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case72 zero72 suc72 rec72) (v Tm72 var72 lam72 app72 tt72 pair72 fst72 snd72 left72 right72 case72 zero72 suc72 rec72) def v072 : ∀ {Γ A}, Tm72 (snoc72 Γ A) A := var72 vz72 def v172 : ∀ {Γ A B}, Tm72 (snoc72 (snoc72 Γ A) B) A := var72 (vs72 vz72) def v272 : ∀ {Γ A B C}, Tm72 (snoc72 (snoc72 (snoc72 Γ A) B) C) A := var72 (vs72 (vs72 vz72)) def v372 : ∀ {Γ A B C D}, Tm72 (snoc72 (snoc72 (snoc72 (snoc72 Γ A) B) C) D) A := var72 (vs72 (vs72 (vs72 vz72))) def tbool72 : Ty72 := sum72 top72 top72 def ttrue72 : ∀ {Γ}, Tm72 Γ tbool72 := left72 tt72 def tfalse72 : ∀ {Γ}, Tm72 Γ tbool72 := right72 tt72 def ifthenelse72 : ∀ {Γ A}, Tm72 Γ (arr72 tbool72 (arr72 A (arr72 A A))) := lam72 (lam72 (lam72 (case72 v272 (lam72 v272) (lam72 v172)))) def times472 : ∀ {Γ A}, Tm72 Γ (arr72 (arr72 A A) (arr72 A A)) := lam72 (lam72 (app72 v172 (app72 v172 (app72 v172 (app72 v172 v072))))) def add72 : ∀ {Γ}, Tm72 Γ (arr72 nat72 (arr72 nat72 nat72)) := lam72 (rec72 v072 (lam72 (lam72 (lam72 (suc72 (app72 v172 v072))))) (lam72 v072)) def mul72 : ∀ {Γ}, Tm72 Γ (arr72 nat72 (arr72 nat72 nat72)) := lam72 (rec72 v072 (lam72 (lam72 (lam72 (app72 (app72 add72 (app72 v172 v072)) v072)))) (lam72 zero72)) def fact72 : ∀ {Γ}, Tm72 Γ (arr72 nat72 nat72) := lam72 (rec72 v072 (lam72 (lam72 (app72 (app72 mul72 (suc72 v172)) v072))) (suc72 zero72)) def Ty73 : Type 1 := ∀ (Ty73 : Type) (nat top bot : Ty73) (arr prod sum : Ty73 → Ty73 → Ty73) , Ty73 def nat73 : Ty73 := λ _ nat73 _ _ _ _ _ => nat73 def top73 : Ty73 := λ _ _ top73 _ _ _ _ => top73 def bot73 : Ty73 := λ _ _ _ bot73 _ _ _ => bot73 def arr73 : Ty73 → Ty73 → Ty73 := λ A B Ty73 nat73 top73 bot73 arr73 prod sum => arr73 (A Ty73 nat73 top73 bot73 arr73 prod sum) (B Ty73 nat73 top73 bot73 arr73 prod sum) def prod73 : Ty73 → Ty73 → Ty73 := λ A B Ty73 nat73 top73 bot73 arr73 prod73 sum => prod73 (A Ty73 nat73 top73 bot73 arr73 prod73 sum) (B Ty73 nat73 top73 bot73 arr73 prod73 sum) def sum73 : Ty73 → Ty73 → Ty73 := λ A B Ty73 nat73 top73 bot73 arr73 prod73 sum73 => sum73 (A Ty73 nat73 top73 bot73 arr73 prod73 sum73) (B Ty73 nat73 top73 bot73 arr73 prod73 sum73) def Con73 : Type 1 := ∀ (Con73 : Type) (nil : Con73) (snoc : Con73 → Ty73 → Con73) , Con73 def nil73 : Con73 := λ Con73 nil73 snoc => nil73 def snoc73 : Con73 → Ty73 → Con73 := λ Γ A Con73 nil73 snoc73 => snoc73 (Γ Con73 nil73 snoc73) A def Var73 : Con73 → Ty73 → Type 1 := λ Γ A => ∀ (Var73 : Con73 → Ty73 → Type) (vz : ∀{Γ A}, Var73 (snoc73 Γ A) A) (vs : ∀{Γ B A}, Var73 Γ A → Var73 (snoc73 Γ B) A) , Var73 Γ A def vz73 : ∀ {Γ A}, Var73 (snoc73 Γ A) A := λ Var73 vz73 vs => vz73 def vs73 : ∀ {Γ B A}, Var73 Γ A → Var73 (snoc73 Γ B) A := λ x Var73 vz73 vs73 => vs73 (x Var73 vz73 vs73) def Tm73 : Con73 → Ty73 → Type 1 := λ Γ A => ∀ (Tm73 : Con73 → Ty73 → Type) (var : ∀ {Γ A}, Var73 Γ A → Tm73 Γ A) (lam : ∀ {Γ A B}, (Tm73 (snoc73 Γ A) B → Tm73 Γ (arr73 A B))) (app : ∀ {Γ A B} , Tm73 Γ (arr73 A B) → Tm73 Γ A → Tm73 Γ B) (tt : ∀ {Γ} , Tm73 Γ top73) (pair : ∀ {Γ A B} , Tm73 Γ A → Tm73 Γ B → Tm73 Γ (prod73 A B)) (fst : ∀ {Γ A B} , Tm73 Γ (prod73 A B) → Tm73 Γ A) (snd : ∀ {Γ A B} , Tm73 Γ (prod73 A B) → Tm73 Γ B) (left : ∀ {Γ A B} , Tm73 Γ A → Tm73 Γ (sum73 A B)) (right : ∀ {Γ A B} , Tm73 Γ B → Tm73 Γ (sum73 A B)) (case : ∀ {Γ A B C} , Tm73 Γ (sum73 A B) → Tm73 Γ (arr73 A C) → Tm73 Γ (arr73 B C) → Tm73 Γ C) (zero : ∀ {Γ} , Tm73 Γ nat73) (suc : ∀ {Γ} , Tm73 Γ nat73 → Tm73 Γ nat73) (rec : ∀ {Γ A} , Tm73 Γ nat73 → Tm73 Γ (arr73 nat73 (arr73 A A)) → Tm73 Γ A → Tm73 Γ A) , Tm73 Γ A def var73 : ∀ {Γ A}, Var73 Γ A → Tm73 Γ A := λ x Tm73 var73 lam app tt pair fst snd left right case zero suc rec => var73 x def lam73 : ∀ {Γ A B} , Tm73 (snoc73 Γ A) B → Tm73 Γ (arr73 A B) := λ t Tm73 var73 lam73 app tt pair fst snd left right case zero suc rec => lam73 (t Tm73 var73 lam73 app tt pair fst snd left right case zero suc rec) def app73 : ∀ {Γ A B} , Tm73 Γ (arr73 A B) → Tm73 Γ A → Tm73 Γ B := λ t u Tm73 var73 lam73 app73 tt pair fst snd left right case zero suc rec => app73 (t Tm73 var73 lam73 app73 tt pair fst snd left right case zero suc rec) (u Tm73 var73 lam73 app73 tt pair fst snd left right case zero suc rec) def tt73 : ∀ {Γ} , Tm73 Γ top73 := λ Tm73 var73 lam73 app73 tt73 pair fst snd left right case zero suc rec => tt73 def pair73 : ∀ {Γ A B} , Tm73 Γ A → Tm73 Γ B → Tm73 Γ (prod73 A B) := λ t u Tm73 var73 lam73 app73 tt73 pair73 fst snd left right case zero suc rec => pair73 (t Tm73 var73 lam73 app73 tt73 pair73 fst snd left right case zero suc rec) (u Tm73 var73 lam73 app73 tt73 pair73 fst snd left right case zero suc rec) def fst73 : ∀ {Γ A B} , Tm73 Γ (prod73 A B) → Tm73 Γ A := λ t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd left right case zero suc rec => fst73 (t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd left right case zero suc rec) def snd73 : ∀ {Γ A B} , Tm73 Γ (prod73 A B) → Tm73 Γ B := λ t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left right case zero suc rec => snd73 (t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left right case zero suc rec) def left73 : ∀ {Γ A B} , Tm73 Γ A → Tm73 Γ (sum73 A B) := λ t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right case zero suc rec => left73 (t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right case zero suc rec) def right73 : ∀ {Γ A B} , Tm73 Γ B → Tm73 Γ (sum73 A B) := λ t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case zero suc rec => right73 (t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case zero suc rec) def case73 : ∀ {Γ A B C} , Tm73 Γ (sum73 A B) → Tm73 Γ (arr73 A C) → Tm73 Γ (arr73 B C) → Tm73 Γ C := λ t u v Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case73 zero suc rec => case73 (t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case73 zero suc rec) (u Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case73 zero suc rec) (v Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case73 zero suc rec) def zero73 : ∀ {Γ} , Tm73 Γ nat73 := λ Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case73 zero73 suc rec => zero73 def suc73 : ∀ {Γ} , Tm73 Γ nat73 → Tm73 Γ nat73 := λ t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case73 zero73 suc73 rec => suc73 (t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case73 zero73 suc73 rec) def rec73 : ∀ {Γ A} , Tm73 Γ nat73 → Tm73 Γ (arr73 nat73 (arr73 A A)) → Tm73 Γ A → Tm73 Γ A := λ t u v Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case73 zero73 suc73 rec73 => rec73 (t Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case73 zero73 suc73 rec73) (u Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case73 zero73 suc73 rec73) (v Tm73 var73 lam73 app73 tt73 pair73 fst73 snd73 left73 right73 case73 zero73 suc73 rec73) def v073 : ∀ {Γ A}, Tm73 (snoc73 Γ A) A := var73 vz73 def v173 : ∀ {Γ A B}, Tm73 (snoc73 (snoc73 Γ A) B) A := var73 (vs73 vz73) def v273 : ∀ {Γ A B C}, Tm73 (snoc73 (snoc73 (snoc73 Γ A) B) C) A := var73 (vs73 (vs73 vz73)) def v373 : ∀ {Γ A B C D}, Tm73 (snoc73 (snoc73 (snoc73 (snoc73 Γ A) B) C) D) A := var73 (vs73 (vs73 (vs73 vz73))) def tbool73 : Ty73 := sum73 top73 top73 def ttrue73 : ∀ {Γ}, Tm73 Γ tbool73 := left73 tt73 def tfalse73 : ∀ {Γ}, Tm73 Γ tbool73 := right73 tt73 def ifthenelse73 : ∀ {Γ A}, Tm73 Γ (arr73 tbool73 (arr73 A (arr73 A A))) := lam73 (lam73 (lam73 (case73 v273 (lam73 v273) (lam73 v173)))) def times473 : ∀ {Γ A}, Tm73 Γ (arr73 (arr73 A A) (arr73 A A)) := lam73 (lam73 (app73 v173 (app73 v173 (app73 v173 (app73 v173 v073))))) def add73 : ∀ {Γ}, Tm73 Γ (arr73 nat73 (arr73 nat73 nat73)) := lam73 (rec73 v073 (lam73 (lam73 (lam73 (suc73 (app73 v173 v073))))) (lam73 v073)) def mul73 : ∀ {Γ}, Tm73 Γ (arr73 nat73 (arr73 nat73 nat73)) := lam73 (rec73 v073 (lam73 (lam73 (lam73 (app73 (app73 add73 (app73 v173 v073)) v073)))) (lam73 zero73)) def fact73 : ∀ {Γ}, Tm73 Γ (arr73 nat73 nat73) := lam73 (rec73 v073 (lam73 (lam73 (app73 (app73 mul73 (suc73 v173)) v073))) (suc73 zero73)) def Ty74 : Type 1 := ∀ (Ty74 : Type) (nat top bot : Ty74) (arr prod sum : Ty74 → Ty74 → Ty74) , Ty74 def nat74 : Ty74 := λ _ nat74 _ _ _ _ _ => nat74 def top74 : Ty74 := λ _ _ top74 _ _ _ _ => top74 def bot74 : Ty74 := λ _ _ _ bot74 _ _ _ => bot74 def arr74 : Ty74 → Ty74 → Ty74 := λ A B Ty74 nat74 top74 bot74 arr74 prod sum => arr74 (A Ty74 nat74 top74 bot74 arr74 prod sum) (B Ty74 nat74 top74 bot74 arr74 prod sum) def prod74 : Ty74 → Ty74 → Ty74 := λ A B Ty74 nat74 top74 bot74 arr74 prod74 sum => prod74 (A Ty74 nat74 top74 bot74 arr74 prod74 sum) (B Ty74 nat74 top74 bot74 arr74 prod74 sum) def sum74 : Ty74 → Ty74 → Ty74 := λ A B Ty74 nat74 top74 bot74 arr74 prod74 sum74 => sum74 (A Ty74 nat74 top74 bot74 arr74 prod74 sum74) (B Ty74 nat74 top74 bot74 arr74 prod74 sum74) def Con74 : Type 1 := ∀ (Con74 : Type) (nil : Con74) (snoc : Con74 → Ty74 → Con74) , Con74 def nil74 : Con74 := λ Con74 nil74 snoc => nil74 def snoc74 : Con74 → Ty74 → Con74 := λ Γ A Con74 nil74 snoc74 => snoc74 (Γ Con74 nil74 snoc74) A def Var74 : Con74 → Ty74 → Type 1 := λ Γ A => ∀ (Var74 : Con74 → Ty74 → Type) (vz : ∀{Γ A}, Var74 (snoc74 Γ A) A) (vs : ∀{Γ B A}, Var74 Γ A → Var74 (snoc74 Γ B) A) , Var74 Γ A def vz74 : ∀ {Γ A}, Var74 (snoc74 Γ A) A := λ Var74 vz74 vs => vz74 def vs74 : ∀ {Γ B A}, Var74 Γ A → Var74 (snoc74 Γ B) A := λ x Var74 vz74 vs74 => vs74 (x Var74 vz74 vs74) def Tm74 : Con74 → Ty74 → Type 1 := λ Γ A => ∀ (Tm74 : Con74 → Ty74 → Type) (var : ∀ {Γ A}, Var74 Γ A → Tm74 Γ A) (lam : ∀ {Γ A B}, (Tm74 (snoc74 Γ A) B → Tm74 Γ (arr74 A B))) (app : ∀ {Γ A B} , Tm74 Γ (arr74 A B) → Tm74 Γ A → Tm74 Γ B) (tt : ∀ {Γ} , Tm74 Γ top74) (pair : ∀ {Γ A B} , Tm74 Γ A → Tm74 Γ B → Tm74 Γ (prod74 A B)) (fst : ∀ {Γ A B} , Tm74 Γ (prod74 A B) → Tm74 Γ A) (snd : ∀ {Γ A B} , Tm74 Γ (prod74 A B) → Tm74 Γ B) (left : ∀ {Γ A B} , Tm74 Γ A → Tm74 Γ (sum74 A B)) (right : ∀ {Γ A B} , Tm74 Γ B → Tm74 Γ (sum74 A B)) (case : ∀ {Γ A B C} , Tm74 Γ (sum74 A B) → Tm74 Γ (arr74 A C) → Tm74 Γ (arr74 B C) → Tm74 Γ C) (zero : ∀ {Γ} , Tm74 Γ nat74) (suc : ∀ {Γ} , Tm74 Γ nat74 → Tm74 Γ nat74) (rec : ∀ {Γ A} , Tm74 Γ nat74 → Tm74 Γ (arr74 nat74 (arr74 A A)) → Tm74 Γ A → Tm74 Γ A) , Tm74 Γ A def var74 : ∀ {Γ A}, Var74 Γ A → Tm74 Γ A := λ x Tm74 var74 lam app tt pair fst snd left right case zero suc rec => var74 x def lam74 : ∀ {Γ A B} , Tm74 (snoc74 Γ A) B → Tm74 Γ (arr74 A B) := λ t Tm74 var74 lam74 app tt pair fst snd left right case zero suc rec => lam74 (t Tm74 var74 lam74 app tt pair fst snd left right case zero suc rec) def app74 : ∀ {Γ A B} , Tm74 Γ (arr74 A B) → Tm74 Γ A → Tm74 Γ B := λ t u Tm74 var74 lam74 app74 tt pair fst snd left right case zero suc rec => app74 (t Tm74 var74 lam74 app74 tt pair fst snd left right case zero suc rec) (u Tm74 var74 lam74 app74 tt pair fst snd left right case zero suc rec) def tt74 : ∀ {Γ} , Tm74 Γ top74 := λ Tm74 var74 lam74 app74 tt74 pair fst snd left right case zero suc rec => tt74 def pair74 : ∀ {Γ A B} , Tm74 Γ A → Tm74 Γ B → Tm74 Γ (prod74 A B) := λ t u Tm74 var74 lam74 app74 tt74 pair74 fst snd left right case zero suc rec => pair74 (t Tm74 var74 lam74 app74 tt74 pair74 fst snd left right case zero suc rec) (u Tm74 var74 lam74 app74 tt74 pair74 fst snd left right case zero suc rec) def fst74 : ∀ {Γ A B} , Tm74 Γ (prod74 A B) → Tm74 Γ A := λ t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd left right case zero suc rec => fst74 (t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd left right case zero suc rec) def snd74 : ∀ {Γ A B} , Tm74 Γ (prod74 A B) → Tm74 Γ B := λ t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left right case zero suc rec => snd74 (t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left right case zero suc rec) def left74 : ∀ {Γ A B} , Tm74 Γ A → Tm74 Γ (sum74 A B) := λ t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right case zero suc rec => left74 (t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right case zero suc rec) def right74 : ∀ {Γ A B} , Tm74 Γ B → Tm74 Γ (sum74 A B) := λ t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case zero suc rec => right74 (t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case zero suc rec) def case74 : ∀ {Γ A B C} , Tm74 Γ (sum74 A B) → Tm74 Γ (arr74 A C) → Tm74 Γ (arr74 B C) → Tm74 Γ C := λ t u v Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case74 zero suc rec => case74 (t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case74 zero suc rec) (u Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case74 zero suc rec) (v Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case74 zero suc rec) def zero74 : ∀ {Γ} , Tm74 Γ nat74 := λ Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case74 zero74 suc rec => zero74 def suc74 : ∀ {Γ} , Tm74 Γ nat74 → Tm74 Γ nat74 := λ t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case74 zero74 suc74 rec => suc74 (t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case74 zero74 suc74 rec) def rec74 : ∀ {Γ A} , Tm74 Γ nat74 → Tm74 Γ (arr74 nat74 (arr74 A A)) → Tm74 Γ A → Tm74 Γ A := λ t u v Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case74 zero74 suc74 rec74 => rec74 (t Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case74 zero74 suc74 rec74) (u Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case74 zero74 suc74 rec74) (v Tm74 var74 lam74 app74 tt74 pair74 fst74 snd74 left74 right74 case74 zero74 suc74 rec74) def v074 : ∀ {Γ A}, Tm74 (snoc74 Γ A) A := var74 vz74 def v174 : ∀ {Γ A B}, Tm74 (snoc74 (snoc74 Γ A) B) A := var74 (vs74 vz74) def v274 : ∀ {Γ A B C}, Tm74 (snoc74 (snoc74 (snoc74 Γ A) B) C) A := var74 (vs74 (vs74 vz74)) def v374 : ∀ {Γ A B C D}, Tm74 (snoc74 (snoc74 (snoc74 (snoc74 Γ A) B) C) D) A := var74 (vs74 (vs74 (vs74 vz74))) def tbool74 : Ty74 := sum74 top74 top74 def ttrue74 : ∀ {Γ}, Tm74 Γ tbool74 := left74 tt74 def tfalse74 : ∀ {Γ}, Tm74 Γ tbool74 := right74 tt74 def ifthenelse74 : ∀ {Γ A}, Tm74 Γ (arr74 tbool74 (arr74 A (arr74 A A))) := lam74 (lam74 (lam74 (case74 v274 (lam74 v274) (lam74 v174)))) def times474 : ∀ {Γ A}, Tm74 Γ (arr74 (arr74 A A) (arr74 A A)) := lam74 (lam74 (app74 v174 (app74 v174 (app74 v174 (app74 v174 v074))))) def add74 : ∀ {Γ}, Tm74 Γ (arr74 nat74 (arr74 nat74 nat74)) := lam74 (rec74 v074 (lam74 (lam74 (lam74 (suc74 (app74 v174 v074))))) (lam74 v074)) def mul74 : ∀ {Γ}, Tm74 Γ (arr74 nat74 (arr74 nat74 nat74)) := lam74 (rec74 v074 (lam74 (lam74 (lam74 (app74 (app74 add74 (app74 v174 v074)) v074)))) (lam74 zero74)) def fact74 : ∀ {Γ}, Tm74 Γ (arr74 nat74 nat74) := lam74 (rec74 v074 (lam74 (lam74 (app74 (app74 mul74 (suc74 v174)) v074))) (suc74 zero74)) def Ty75 : Type 1 := ∀ (Ty75 : Type) (nat top bot : Ty75) (arr prod sum : Ty75 → Ty75 → Ty75) , Ty75 def nat75 : Ty75 := λ _ nat75 _ _ _ _ _ => nat75 def top75 : Ty75 := λ _ _ top75 _ _ _ _ => top75 def bot75 : Ty75 := λ _ _ _ bot75 _ _ _ => bot75 def arr75 : Ty75 → Ty75 → Ty75 := λ A B Ty75 nat75 top75 bot75 arr75 prod sum => arr75 (A Ty75 nat75 top75 bot75 arr75 prod sum) (B Ty75 nat75 top75 bot75 arr75 prod sum) def prod75 : Ty75 → Ty75 → Ty75 := λ A B Ty75 nat75 top75 bot75 arr75 prod75 sum => prod75 (A Ty75 nat75 top75 bot75 arr75 prod75 sum) (B Ty75 nat75 top75 bot75 arr75 prod75 sum) def sum75 : Ty75 → Ty75 → Ty75 := λ A B Ty75 nat75 top75 bot75 arr75 prod75 sum75 => sum75 (A Ty75 nat75 top75 bot75 arr75 prod75 sum75) (B Ty75 nat75 top75 bot75 arr75 prod75 sum75) def Con75 : Type 1 := ∀ (Con75 : Type) (nil : Con75) (snoc : Con75 → Ty75 → Con75) , Con75 def nil75 : Con75 := λ Con75 nil75 snoc => nil75 def snoc75 : Con75 → Ty75 → Con75 := λ Γ A Con75 nil75 snoc75 => snoc75 (Γ Con75 nil75 snoc75) A def Var75 : Con75 → Ty75 → Type 1 := λ Γ A => ∀ (Var75 : Con75 → Ty75 → Type) (vz : ∀{Γ A}, Var75 (snoc75 Γ A) A) (vs : ∀{Γ B A}, Var75 Γ A → Var75 (snoc75 Γ B) A) , Var75 Γ A def vz75 : ∀ {Γ A}, Var75 (snoc75 Γ A) A := λ Var75 vz75 vs => vz75 def vs75 : ∀ {Γ B A}, Var75 Γ A → Var75 (snoc75 Γ B) A := λ x Var75 vz75 vs75 => vs75 (x Var75 vz75 vs75) def Tm75 : Con75 → Ty75 → Type 1 := λ Γ A => ∀ (Tm75 : Con75 → Ty75 → Type) (var : ∀ {Γ A}, Var75 Γ A → Tm75 Γ A) (lam : ∀ {Γ A B}, (Tm75 (snoc75 Γ A) B → Tm75 Γ (arr75 A B))) (app : ∀ {Γ A B} , Tm75 Γ (arr75 A B) → Tm75 Γ A → Tm75 Γ B) (tt : ∀ {Γ} , Tm75 Γ top75) (pair : ∀ {Γ A B} , Tm75 Γ A → Tm75 Γ B → Tm75 Γ (prod75 A B)) (fst : ∀ {Γ A B} , Tm75 Γ (prod75 A B) → Tm75 Γ A) (snd : ∀ {Γ A B} , Tm75 Γ (prod75 A B) → Tm75 Γ B) (left : ∀ {Γ A B} , Tm75 Γ A → Tm75 Γ (sum75 A B)) (right : ∀ {Γ A B} , Tm75 Γ B → Tm75 Γ (sum75 A B)) (case : ∀ {Γ A B C} , Tm75 Γ (sum75 A B) → Tm75 Γ (arr75 A C) → Tm75 Γ (arr75 B C) → Tm75 Γ C) (zero : ∀ {Γ} , Tm75 Γ nat75) (suc : ∀ {Γ} , Tm75 Γ nat75 → Tm75 Γ nat75) (rec : ∀ {Γ A} , Tm75 Γ nat75 → Tm75 Γ (arr75 nat75 (arr75 A A)) → Tm75 Γ A → Tm75 Γ A) , Tm75 Γ A def var75 : ∀ {Γ A}, Var75 Γ A → Tm75 Γ A := λ x Tm75 var75 lam app tt pair fst snd left right case zero suc rec => var75 x def lam75 : ∀ {Γ A B} , Tm75 (snoc75 Γ A) B → Tm75 Γ (arr75 A B) := λ t Tm75 var75 lam75 app tt pair fst snd left right case zero suc rec => lam75 (t Tm75 var75 lam75 app tt pair fst snd left right case zero suc rec) def app75 : ∀ {Γ A B} , Tm75 Γ (arr75 A B) → Tm75 Γ A → Tm75 Γ B := λ t u Tm75 var75 lam75 app75 tt pair fst snd left right case zero suc rec => app75 (t Tm75 var75 lam75 app75 tt pair fst snd left right case zero suc rec) (u Tm75 var75 lam75 app75 tt pair fst snd left right case zero suc rec) def tt75 : ∀ {Γ} , Tm75 Γ top75 := λ Tm75 var75 lam75 app75 tt75 pair fst snd left right case zero suc rec => tt75 def pair75 : ∀ {Γ A B} , Tm75 Γ A → Tm75 Γ B → Tm75 Γ (prod75 A B) := λ t u Tm75 var75 lam75 app75 tt75 pair75 fst snd left right case zero suc rec => pair75 (t Tm75 var75 lam75 app75 tt75 pair75 fst snd left right case zero suc rec) (u Tm75 var75 lam75 app75 tt75 pair75 fst snd left right case zero suc rec) def fst75 : ∀ {Γ A B} , Tm75 Γ (prod75 A B) → Tm75 Γ A := λ t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd left right case zero suc rec => fst75 (t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd left right case zero suc rec) def snd75 : ∀ {Γ A B} , Tm75 Γ (prod75 A B) → Tm75 Γ B := λ t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left right case zero suc rec => snd75 (t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left right case zero suc rec) def left75 : ∀ {Γ A B} , Tm75 Γ A → Tm75 Γ (sum75 A B) := λ t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right case zero suc rec => left75 (t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right case zero suc rec) def right75 : ∀ {Γ A B} , Tm75 Γ B → Tm75 Γ (sum75 A B) := λ t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case zero suc rec => right75 (t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case zero suc rec) def case75 : ∀ {Γ A B C} , Tm75 Γ (sum75 A B) → Tm75 Γ (arr75 A C) → Tm75 Γ (arr75 B C) → Tm75 Γ C := λ t u v Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case75 zero suc rec => case75 (t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case75 zero suc rec) (u Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case75 zero suc rec) (v Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case75 zero suc rec) def zero75 : ∀ {Γ} , Tm75 Γ nat75 := λ Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case75 zero75 suc rec => zero75 def suc75 : ∀ {Γ} , Tm75 Γ nat75 → Tm75 Γ nat75 := λ t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case75 zero75 suc75 rec => suc75 (t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case75 zero75 suc75 rec) def rec75 : ∀ {Γ A} , Tm75 Γ nat75 → Tm75 Γ (arr75 nat75 (arr75 A A)) → Tm75 Γ A → Tm75 Γ A := λ t u v Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case75 zero75 suc75 rec75 => rec75 (t Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case75 zero75 suc75 rec75) (u Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case75 zero75 suc75 rec75) (v Tm75 var75 lam75 app75 tt75 pair75 fst75 snd75 left75 right75 case75 zero75 suc75 rec75) def v075 : ∀ {Γ A}, Tm75 (snoc75 Γ A) A := var75 vz75 def v175 : ∀ {Γ A B}, Tm75 (snoc75 (snoc75 Γ A) B) A := var75 (vs75 vz75) def v275 : ∀ {Γ A B C}, Tm75 (snoc75 (snoc75 (snoc75 Γ A) B) C) A := var75 (vs75 (vs75 vz75)) def v375 : ∀ {Γ A B C D}, Tm75 (snoc75 (snoc75 (snoc75 (snoc75 Γ A) B) C) D) A := var75 (vs75 (vs75 (vs75 vz75))) def tbool75 : Ty75 := sum75 top75 top75 def ttrue75 : ∀ {Γ}, Tm75 Γ tbool75 := left75 tt75 def tfalse75 : ∀ {Γ}, Tm75 Γ tbool75 := right75 tt75 def ifthenelse75 : ∀ {Γ A}, Tm75 Γ (arr75 tbool75 (arr75 A (arr75 A A))) := lam75 (lam75 (lam75 (case75 v275 (lam75 v275) (lam75 v175)))) def times475 : ∀ {Γ A}, Tm75 Γ (arr75 (arr75 A A) (arr75 A A)) := lam75 (lam75 (app75 v175 (app75 v175 (app75 v175 (app75 v175 v075))))) def add75 : ∀ {Γ}, Tm75 Γ (arr75 nat75 (arr75 nat75 nat75)) := lam75 (rec75 v075 (lam75 (lam75 (lam75 (suc75 (app75 v175 v075))))) (lam75 v075)) def mul75 : ∀ {Γ}, Tm75 Γ (arr75 nat75 (arr75 nat75 nat75)) := lam75 (rec75 v075 (lam75 (lam75 (lam75 (app75 (app75 add75 (app75 v175 v075)) v075)))) (lam75 zero75)) def fact75 : ∀ {Γ}, Tm75 Γ (arr75 nat75 nat75) := lam75 (rec75 v075 (lam75 (lam75 (app75 (app75 mul75 (suc75 v175)) v075))) (suc75 zero75)) def Ty76 : Type 1 := ∀ (Ty76 : Type) (nat top bot : Ty76) (arr prod sum : Ty76 → Ty76 → Ty76) , Ty76 def nat76 : Ty76 := λ _ nat76 _ _ _ _ _ => nat76 def top76 : Ty76 := λ _ _ top76 _ _ _ _ => top76 def bot76 : Ty76 := λ _ _ _ bot76 _ _ _ => bot76 def arr76 : Ty76 → Ty76 → Ty76 := λ A B Ty76 nat76 top76 bot76 arr76 prod sum => arr76 (A Ty76 nat76 top76 bot76 arr76 prod sum) (B Ty76 nat76 top76 bot76 arr76 prod sum) def prod76 : Ty76 → Ty76 → Ty76 := λ A B Ty76 nat76 top76 bot76 arr76 prod76 sum => prod76 (A Ty76 nat76 top76 bot76 arr76 prod76 sum) (B Ty76 nat76 top76 bot76 arr76 prod76 sum) def sum76 : Ty76 → Ty76 → Ty76 := λ A B Ty76 nat76 top76 bot76 arr76 prod76 sum76 => sum76 (A Ty76 nat76 top76 bot76 arr76 prod76 sum76) (B Ty76 nat76 top76 bot76 arr76 prod76 sum76) def Con76 : Type 1 := ∀ (Con76 : Type) (nil : Con76) (snoc : Con76 → Ty76 → Con76) , Con76 def nil76 : Con76 := λ Con76 nil76 snoc => nil76 def snoc76 : Con76 → Ty76 → Con76 := λ Γ A Con76 nil76 snoc76 => snoc76 (Γ Con76 nil76 snoc76) A def Var76 : Con76 → Ty76 → Type 1 := λ Γ A => ∀ (Var76 : Con76 → Ty76 → Type) (vz : ∀{Γ A}, Var76 (snoc76 Γ A) A) (vs : ∀{Γ B A}, Var76 Γ A → Var76 (snoc76 Γ B) A) , Var76 Γ A def vz76 : ∀ {Γ A}, Var76 (snoc76 Γ A) A := λ Var76 vz76 vs => vz76 def vs76 : ∀ {Γ B A}, Var76 Γ A → Var76 (snoc76 Γ B) A := λ x Var76 vz76 vs76 => vs76 (x Var76 vz76 vs76) def Tm76 : Con76 → Ty76 → Type 1 := λ Γ A => ∀ (Tm76 : Con76 → Ty76 → Type) (var : ∀ {Γ A}, Var76 Γ A → Tm76 Γ A) (lam : ∀ {Γ A B}, (Tm76 (snoc76 Γ A) B → Tm76 Γ (arr76 A B))) (app : ∀ {Γ A B} , Tm76 Γ (arr76 A B) → Tm76 Γ A → Tm76 Γ B) (tt : ∀ {Γ} , Tm76 Γ top76) (pair : ∀ {Γ A B} , Tm76 Γ A → Tm76 Γ B → Tm76 Γ (prod76 A B)) (fst : ∀ {Γ A B} , Tm76 Γ (prod76 A B) → Tm76 Γ A) (snd : ∀ {Γ A B} , Tm76 Γ (prod76 A B) → Tm76 Γ B) (left : ∀ {Γ A B} , Tm76 Γ A → Tm76 Γ (sum76 A B)) (right : ∀ {Γ A B} , Tm76 Γ B → Tm76 Γ (sum76 A B)) (case : ∀ {Γ A B C} , Tm76 Γ (sum76 A B) → Tm76 Γ (arr76 A C) → Tm76 Γ (arr76 B C) → Tm76 Γ C) (zero : ∀ {Γ} , Tm76 Γ nat76) (suc : ∀ {Γ} , Tm76 Γ nat76 → Tm76 Γ nat76) (rec : ∀ {Γ A} , Tm76 Γ nat76 → Tm76 Γ (arr76 nat76 (arr76 A A)) → Tm76 Γ A → Tm76 Γ A) , Tm76 Γ A def var76 : ∀ {Γ A}, Var76 Γ A → Tm76 Γ A := λ x Tm76 var76 lam app tt pair fst snd left right case zero suc rec => var76 x def lam76 : ∀ {Γ A B} , Tm76 (snoc76 Γ A) B → Tm76 Γ (arr76 A B) := λ t Tm76 var76 lam76 app tt pair fst snd left right case zero suc rec => lam76 (t Tm76 var76 lam76 app tt pair fst snd left right case zero suc rec) def app76 : ∀ {Γ A B} , Tm76 Γ (arr76 A B) → Tm76 Γ A → Tm76 Γ B := λ t u Tm76 var76 lam76 app76 tt pair fst snd left right case zero suc rec => app76 (t Tm76 var76 lam76 app76 tt pair fst snd left right case zero suc rec) (u Tm76 var76 lam76 app76 tt pair fst snd left right case zero suc rec) def tt76 : ∀ {Γ} , Tm76 Γ top76 := λ Tm76 var76 lam76 app76 tt76 pair fst snd left right case zero suc rec => tt76 def pair76 : ∀ {Γ A B} , Tm76 Γ A → Tm76 Γ B → Tm76 Γ (prod76 A B) := λ t u Tm76 var76 lam76 app76 tt76 pair76 fst snd left right case zero suc rec => pair76 (t Tm76 var76 lam76 app76 tt76 pair76 fst snd left right case zero suc rec) (u Tm76 var76 lam76 app76 tt76 pair76 fst snd left right case zero suc rec) def fst76 : ∀ {Γ A B} , Tm76 Γ (prod76 A B) → Tm76 Γ A := λ t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd left right case zero suc rec => fst76 (t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd left right case zero suc rec) def snd76 : ∀ {Γ A B} , Tm76 Γ (prod76 A B) → Tm76 Γ B := λ t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left right case zero suc rec => snd76 (t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left right case zero suc rec) def left76 : ∀ {Γ A B} , Tm76 Γ A → Tm76 Γ (sum76 A B) := λ t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right case zero suc rec => left76 (t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right case zero suc rec) def right76 : ∀ {Γ A B} , Tm76 Γ B → Tm76 Γ (sum76 A B) := λ t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case zero suc rec => right76 (t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case zero suc rec) def case76 : ∀ {Γ A B C} , Tm76 Γ (sum76 A B) → Tm76 Γ (arr76 A C) → Tm76 Γ (arr76 B C) → Tm76 Γ C := λ t u v Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case76 zero suc rec => case76 (t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case76 zero suc rec) (u Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case76 zero suc rec) (v Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case76 zero suc rec) def zero76 : ∀ {Γ} , Tm76 Γ nat76 := λ Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case76 zero76 suc rec => zero76 def suc76 : ∀ {Γ} , Tm76 Γ nat76 → Tm76 Γ nat76 := λ t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case76 zero76 suc76 rec => suc76 (t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case76 zero76 suc76 rec) def rec76 : ∀ {Γ A} , Tm76 Γ nat76 → Tm76 Γ (arr76 nat76 (arr76 A A)) → Tm76 Γ A → Tm76 Γ A := λ t u v Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case76 zero76 suc76 rec76 => rec76 (t Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case76 zero76 suc76 rec76) (u Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case76 zero76 suc76 rec76) (v Tm76 var76 lam76 app76 tt76 pair76 fst76 snd76 left76 right76 case76 zero76 suc76 rec76) def v076 : ∀ {Γ A}, Tm76 (snoc76 Γ A) A := var76 vz76 def v176 : ∀ {Γ A B}, Tm76 (snoc76 (snoc76 Γ A) B) A := var76 (vs76 vz76) def v276 : ∀ {Γ A B C}, Tm76 (snoc76 (snoc76 (snoc76 Γ A) B) C) A := var76 (vs76 (vs76 vz76)) def v376 : ∀ {Γ A B C D}, Tm76 (snoc76 (snoc76 (snoc76 (snoc76 Γ A) B) C) D) A := var76 (vs76 (vs76 (vs76 vz76))) def tbool76 : Ty76 := sum76 top76 top76 def ttrue76 : ∀ {Γ}, Tm76 Γ tbool76 := left76 tt76 def tfalse76 : ∀ {Γ}, Tm76 Γ tbool76 := right76 tt76 def ifthenelse76 : ∀ {Γ A}, Tm76 Γ (arr76 tbool76 (arr76 A (arr76 A A))) := lam76 (lam76 (lam76 (case76 v276 (lam76 v276) (lam76 v176)))) def times476 : ∀ {Γ A}, Tm76 Γ (arr76 (arr76 A A) (arr76 A A)) := lam76 (lam76 (app76 v176 (app76 v176 (app76 v176 (app76 v176 v076))))) def add76 : ∀ {Γ}, Tm76 Γ (arr76 nat76 (arr76 nat76 nat76)) := lam76 (rec76 v076 (lam76 (lam76 (lam76 (suc76 (app76 v176 v076))))) (lam76 v076)) def mul76 : ∀ {Γ}, Tm76 Γ (arr76 nat76 (arr76 nat76 nat76)) := lam76 (rec76 v076 (lam76 (lam76 (lam76 (app76 (app76 add76 (app76 v176 v076)) v076)))) (lam76 zero76)) def fact76 : ∀ {Γ}, Tm76 Γ (arr76 nat76 nat76) := lam76 (rec76 v076 (lam76 (lam76 (app76 (app76 mul76 (suc76 v176)) v076))) (suc76 zero76)) def Ty77 : Type 1 := ∀ (Ty77 : Type) (nat top bot : Ty77) (arr prod sum : Ty77 → Ty77 → Ty77) , Ty77 def nat77 : Ty77 := λ _ nat77 _ _ _ _ _ => nat77 def top77 : Ty77 := λ _ _ top77 _ _ _ _ => top77 def bot77 : Ty77 := λ _ _ _ bot77 _ _ _ => bot77 def arr77 : Ty77 → Ty77 → Ty77 := λ A B Ty77 nat77 top77 bot77 arr77 prod sum => arr77 (A Ty77 nat77 top77 bot77 arr77 prod sum) (B Ty77 nat77 top77 bot77 arr77 prod sum) def prod77 : Ty77 → Ty77 → Ty77 := λ A B Ty77 nat77 top77 bot77 arr77 prod77 sum => prod77 (A Ty77 nat77 top77 bot77 arr77 prod77 sum) (B Ty77 nat77 top77 bot77 arr77 prod77 sum) def sum77 : Ty77 → Ty77 → Ty77 := λ A B Ty77 nat77 top77 bot77 arr77 prod77 sum77 => sum77 (A Ty77 nat77 top77 bot77 arr77 prod77 sum77) (B Ty77 nat77 top77 bot77 arr77 prod77 sum77) def Con77 : Type 1 := ∀ (Con77 : Type) (nil : Con77) (snoc : Con77 → Ty77 → Con77) , Con77 def nil77 : Con77 := λ Con77 nil77 snoc => nil77 def snoc77 : Con77 → Ty77 → Con77 := λ Γ A Con77 nil77 snoc77 => snoc77 (Γ Con77 nil77 snoc77) A def Var77 : Con77 → Ty77 → Type 1 := λ Γ A => ∀ (Var77 : Con77 → Ty77 → Type) (vz : ∀{Γ A}, Var77 (snoc77 Γ A) A) (vs : ∀{Γ B A}, Var77 Γ A → Var77 (snoc77 Γ B) A) , Var77 Γ A def vz77 : ∀ {Γ A}, Var77 (snoc77 Γ A) A := λ Var77 vz77 vs => vz77 def vs77 : ∀ {Γ B A}, Var77 Γ A → Var77 (snoc77 Γ B) A := λ x Var77 vz77 vs77 => vs77 (x Var77 vz77 vs77) def Tm77 : Con77 → Ty77 → Type 1 := λ Γ A => ∀ (Tm77 : Con77 → Ty77 → Type) (var : ∀ {Γ A}, Var77 Γ A → Tm77 Γ A) (lam : ∀ {Γ A B}, (Tm77 (snoc77 Γ A) B → Tm77 Γ (arr77 A B))) (app : ∀ {Γ A B} , Tm77 Γ (arr77 A B) → Tm77 Γ A → Tm77 Γ B) (tt : ∀ {Γ} , Tm77 Γ top77) (pair : ∀ {Γ A B} , Tm77 Γ A → Tm77 Γ B → Tm77 Γ (prod77 A B)) (fst : ∀ {Γ A B} , Tm77 Γ (prod77 A B) → Tm77 Γ A) (snd : ∀ {Γ A B} , Tm77 Γ (prod77 A B) → Tm77 Γ B) (left : ∀ {Γ A B} , Tm77 Γ A → Tm77 Γ (sum77 A B)) (right : ∀ {Γ A B} , Tm77 Γ B → Tm77 Γ (sum77 A B)) (case : ∀ {Γ A B C} , Tm77 Γ (sum77 A B) → Tm77 Γ (arr77 A C) → Tm77 Γ (arr77 B C) → Tm77 Γ C) (zero : ∀ {Γ} , Tm77 Γ nat77) (suc : ∀ {Γ} , Tm77 Γ nat77 → Tm77 Γ nat77) (rec : ∀ {Γ A} , Tm77 Γ nat77 → Tm77 Γ (arr77 nat77 (arr77 A A)) → Tm77 Γ A → Tm77 Γ A) , Tm77 Γ A def var77 : ∀ {Γ A}, Var77 Γ A → Tm77 Γ A := λ x Tm77 var77 lam app tt pair fst snd left right case zero suc rec => var77 x def lam77 : ∀ {Γ A B} , Tm77 (snoc77 Γ A) B → Tm77 Γ (arr77 A B) := λ t Tm77 var77 lam77 app tt pair fst snd left right case zero suc rec => lam77 (t Tm77 var77 lam77 app tt pair fst snd left right case zero suc rec) def app77 : ∀ {Γ A B} , Tm77 Γ (arr77 A B) → Tm77 Γ A → Tm77 Γ B := λ t u Tm77 var77 lam77 app77 tt pair fst snd left right case zero suc rec => app77 (t Tm77 var77 lam77 app77 tt pair fst snd left right case zero suc rec) (u Tm77 var77 lam77 app77 tt pair fst snd left right case zero suc rec) def tt77 : ∀ {Γ} , Tm77 Γ top77 := λ Tm77 var77 lam77 app77 tt77 pair fst snd left right case zero suc rec => tt77 def pair77 : ∀ {Γ A B} , Tm77 Γ A → Tm77 Γ B → Tm77 Γ (prod77 A B) := λ t u Tm77 var77 lam77 app77 tt77 pair77 fst snd left right case zero suc rec => pair77 (t Tm77 var77 lam77 app77 tt77 pair77 fst snd left right case zero suc rec) (u Tm77 var77 lam77 app77 tt77 pair77 fst snd left right case zero suc rec) def fst77 : ∀ {Γ A B} , Tm77 Γ (prod77 A B) → Tm77 Γ A := λ t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd left right case zero suc rec => fst77 (t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd left right case zero suc rec) def snd77 : ∀ {Γ A B} , Tm77 Γ (prod77 A B) → Tm77 Γ B := λ t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left right case zero suc rec => snd77 (t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left right case zero suc rec) def left77 : ∀ {Γ A B} , Tm77 Γ A → Tm77 Γ (sum77 A B) := λ t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right case zero suc rec => left77 (t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right case zero suc rec) def right77 : ∀ {Γ A B} , Tm77 Γ B → Tm77 Γ (sum77 A B) := λ t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case zero suc rec => right77 (t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case zero suc rec) def case77 : ∀ {Γ A B C} , Tm77 Γ (sum77 A B) → Tm77 Γ (arr77 A C) → Tm77 Γ (arr77 B C) → Tm77 Γ C := λ t u v Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case77 zero suc rec => case77 (t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case77 zero suc rec) (u Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case77 zero suc rec) (v Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case77 zero suc rec) def zero77 : ∀ {Γ} , Tm77 Γ nat77 := λ Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case77 zero77 suc rec => zero77 def suc77 : ∀ {Γ} , Tm77 Γ nat77 → Tm77 Γ nat77 := λ t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case77 zero77 suc77 rec => suc77 (t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case77 zero77 suc77 rec) def rec77 : ∀ {Γ A} , Tm77 Γ nat77 → Tm77 Γ (arr77 nat77 (arr77 A A)) → Tm77 Γ A → Tm77 Γ A := λ t u v Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case77 zero77 suc77 rec77 => rec77 (t Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case77 zero77 suc77 rec77) (u Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case77 zero77 suc77 rec77) (v Tm77 var77 lam77 app77 tt77 pair77 fst77 snd77 left77 right77 case77 zero77 suc77 rec77) def v077 : ∀ {Γ A}, Tm77 (snoc77 Γ A) A := var77 vz77 def v177 : ∀ {Γ A B}, Tm77 (snoc77 (snoc77 Γ A) B) A := var77 (vs77 vz77) def v277 : ∀ {Γ A B C}, Tm77 (snoc77 (snoc77 (snoc77 Γ A) B) C) A := var77 (vs77 (vs77 vz77)) def v377 : ∀ {Γ A B C D}, Tm77 (snoc77 (snoc77 (snoc77 (snoc77 Γ A) B) C) D) A := var77 (vs77 (vs77 (vs77 vz77))) def tbool77 : Ty77 := sum77 top77 top77 def ttrue77 : ∀ {Γ}, Tm77 Γ tbool77 := left77 tt77 def tfalse77 : ∀ {Γ}, Tm77 Γ tbool77 := right77 tt77 def ifthenelse77 : ∀ {Γ A}, Tm77 Γ (arr77 tbool77 (arr77 A (arr77 A A))) := lam77 (lam77 (lam77 (case77 v277 (lam77 v277) (lam77 v177)))) def times477 : ∀ {Γ A}, Tm77 Γ (arr77 (arr77 A A) (arr77 A A)) := lam77 (lam77 (app77 v177 (app77 v177 (app77 v177 (app77 v177 v077))))) def add77 : ∀ {Γ}, Tm77 Γ (arr77 nat77 (arr77 nat77 nat77)) := lam77 (rec77 v077 (lam77 (lam77 (lam77 (suc77 (app77 v177 v077))))) (lam77 v077)) def mul77 : ∀ {Γ}, Tm77 Γ (arr77 nat77 (arr77 nat77 nat77)) := lam77 (rec77 v077 (lam77 (lam77 (lam77 (app77 (app77 add77 (app77 v177 v077)) v077)))) (lam77 zero77)) def fact77 : ∀ {Γ}, Tm77 Γ (arr77 nat77 nat77) := lam77 (rec77 v077 (lam77 (lam77 (app77 (app77 mul77 (suc77 v177)) v077))) (suc77 zero77)) def Ty78 : Type 1 := ∀ (Ty78 : Type) (nat top bot : Ty78) (arr prod sum : Ty78 → Ty78 → Ty78) , Ty78 def nat78 : Ty78 := λ _ nat78 _ _ _ _ _ => nat78 def top78 : Ty78 := λ _ _ top78 _ _ _ _ => top78 def bot78 : Ty78 := λ _ _ _ bot78 _ _ _ => bot78 def arr78 : Ty78 → Ty78 → Ty78 := λ A B Ty78 nat78 top78 bot78 arr78 prod sum => arr78 (A Ty78 nat78 top78 bot78 arr78 prod sum) (B Ty78 nat78 top78 bot78 arr78 prod sum) def prod78 : Ty78 → Ty78 → Ty78 := λ A B Ty78 nat78 top78 bot78 arr78 prod78 sum => prod78 (A Ty78 nat78 top78 bot78 arr78 prod78 sum) (B Ty78 nat78 top78 bot78 arr78 prod78 sum) def sum78 : Ty78 → Ty78 → Ty78 := λ A B Ty78 nat78 top78 bot78 arr78 prod78 sum78 => sum78 (A Ty78 nat78 top78 bot78 arr78 prod78 sum78) (B Ty78 nat78 top78 bot78 arr78 prod78 sum78) def Con78 : Type 1 := ∀ (Con78 : Type) (nil : Con78) (snoc : Con78 → Ty78 → Con78) , Con78 def nil78 : Con78 := λ Con78 nil78 snoc => nil78 def snoc78 : Con78 → Ty78 → Con78 := λ Γ A Con78 nil78 snoc78 => snoc78 (Γ Con78 nil78 snoc78) A def Var78 : Con78 → Ty78 → Type 1 := λ Γ A => ∀ (Var78 : Con78 → Ty78 → Type) (vz : ∀{Γ A}, Var78 (snoc78 Γ A) A) (vs : ∀{Γ B A}, Var78 Γ A → Var78 (snoc78 Γ B) A) , Var78 Γ A def vz78 : ∀ {Γ A}, Var78 (snoc78 Γ A) A := λ Var78 vz78 vs => vz78 def vs78 : ∀ {Γ B A}, Var78 Γ A → Var78 (snoc78 Γ B) A := λ x Var78 vz78 vs78 => vs78 (x Var78 vz78 vs78) def Tm78 : Con78 → Ty78 → Type 1 := λ Γ A => ∀ (Tm78 : Con78 → Ty78 → Type) (var : ∀ {Γ A}, Var78 Γ A → Tm78 Γ A) (lam : ∀ {Γ A B}, (Tm78 (snoc78 Γ A) B → Tm78 Γ (arr78 A B))) (app : ∀ {Γ A B} , Tm78 Γ (arr78 A B) → Tm78 Γ A → Tm78 Γ B) (tt : ∀ {Γ} , Tm78 Γ top78) (pair : ∀ {Γ A B} , Tm78 Γ A → Tm78 Γ B → Tm78 Γ (prod78 A B)) (fst : ∀ {Γ A B} , Tm78 Γ (prod78 A B) → Tm78 Γ A) (snd : ∀ {Γ A B} , Tm78 Γ (prod78 A B) → Tm78 Γ B) (left : ∀ {Γ A B} , Tm78 Γ A → Tm78 Γ (sum78 A B)) (right : ∀ {Γ A B} , Tm78 Γ B → Tm78 Γ (sum78 A B)) (case : ∀ {Γ A B C} , Tm78 Γ (sum78 A B) → Tm78 Γ (arr78 A C) → Tm78 Γ (arr78 B C) → Tm78 Γ C) (zero : ∀ {Γ} , Tm78 Γ nat78) (suc : ∀ {Γ} , Tm78 Γ nat78 → Tm78 Γ nat78) (rec : ∀ {Γ A} , Tm78 Γ nat78 → Tm78 Γ (arr78 nat78 (arr78 A A)) → Tm78 Γ A → Tm78 Γ A) , Tm78 Γ A def var78 : ∀ {Γ A}, Var78 Γ A → Tm78 Γ A := λ x Tm78 var78 lam app tt pair fst snd left right case zero suc rec => var78 x def lam78 : ∀ {Γ A B} , Tm78 (snoc78 Γ A) B → Tm78 Γ (arr78 A B) := λ t Tm78 var78 lam78 app tt pair fst snd left right case zero suc rec => lam78 (t Tm78 var78 lam78 app tt pair fst snd left right case zero suc rec) def app78 : ∀ {Γ A B} , Tm78 Γ (arr78 A B) → Tm78 Γ A → Tm78 Γ B := λ t u Tm78 var78 lam78 app78 tt pair fst snd left right case zero suc rec => app78 (t Tm78 var78 lam78 app78 tt pair fst snd left right case zero suc rec) (u Tm78 var78 lam78 app78 tt pair fst snd left right case zero suc rec) def tt78 : ∀ {Γ} , Tm78 Γ top78 := λ Tm78 var78 lam78 app78 tt78 pair fst snd left right case zero suc rec => tt78 def pair78 : ∀ {Γ A B} , Tm78 Γ A → Tm78 Γ B → Tm78 Γ (prod78 A B) := λ t u Tm78 var78 lam78 app78 tt78 pair78 fst snd left right case zero suc rec => pair78 (t Tm78 var78 lam78 app78 tt78 pair78 fst snd left right case zero suc rec) (u Tm78 var78 lam78 app78 tt78 pair78 fst snd left right case zero suc rec) def fst78 : ∀ {Γ A B} , Tm78 Γ (prod78 A B) → Tm78 Γ A := λ t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd left right case zero suc rec => fst78 (t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd left right case zero suc rec) def snd78 : ∀ {Γ A B} , Tm78 Γ (prod78 A B) → Tm78 Γ B := λ t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left right case zero suc rec => snd78 (t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left right case zero suc rec) def left78 : ∀ {Γ A B} , Tm78 Γ A → Tm78 Γ (sum78 A B) := λ t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right case zero suc rec => left78 (t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right case zero suc rec) def right78 : ∀ {Γ A B} , Tm78 Γ B → Tm78 Γ (sum78 A B) := λ t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case zero suc rec => right78 (t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case zero suc rec) def case78 : ∀ {Γ A B C} , Tm78 Γ (sum78 A B) → Tm78 Γ (arr78 A C) → Tm78 Γ (arr78 B C) → Tm78 Γ C := λ t u v Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case78 zero suc rec => case78 (t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case78 zero suc rec) (u Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case78 zero suc rec) (v Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case78 zero suc rec) def zero78 : ∀ {Γ} , Tm78 Γ nat78 := λ Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case78 zero78 suc rec => zero78 def suc78 : ∀ {Γ} , Tm78 Γ nat78 → Tm78 Γ nat78 := λ t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case78 zero78 suc78 rec => suc78 (t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case78 zero78 suc78 rec) def rec78 : ∀ {Γ A} , Tm78 Γ nat78 → Tm78 Γ (arr78 nat78 (arr78 A A)) → Tm78 Γ A → Tm78 Γ A := λ t u v Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case78 zero78 suc78 rec78 => rec78 (t Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case78 zero78 suc78 rec78) (u Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case78 zero78 suc78 rec78) (v Tm78 var78 lam78 app78 tt78 pair78 fst78 snd78 left78 right78 case78 zero78 suc78 rec78) def v078 : ∀ {Γ A}, Tm78 (snoc78 Γ A) A := var78 vz78 def v178 : ∀ {Γ A B}, Tm78 (snoc78 (snoc78 Γ A) B) A := var78 (vs78 vz78) def v278 : ∀ {Γ A B C}, Tm78 (snoc78 (snoc78 (snoc78 Γ A) B) C) A := var78 (vs78 (vs78 vz78)) def v378 : ∀ {Γ A B C D}, Tm78 (snoc78 (snoc78 (snoc78 (snoc78 Γ A) B) C) D) A := var78 (vs78 (vs78 (vs78 vz78))) def tbool78 : Ty78 := sum78 top78 top78 def ttrue78 : ∀ {Γ}, Tm78 Γ tbool78 := left78 tt78 def tfalse78 : ∀ {Γ}, Tm78 Γ tbool78 := right78 tt78 def ifthenelse78 : ∀ {Γ A}, Tm78 Γ (arr78 tbool78 (arr78 A (arr78 A A))) := lam78 (lam78 (lam78 (case78 v278 (lam78 v278) (lam78 v178)))) def times478 : ∀ {Γ A}, Tm78 Γ (arr78 (arr78 A A) (arr78 A A)) := lam78 (lam78 (app78 v178 (app78 v178 (app78 v178 (app78 v178 v078))))) def add78 : ∀ {Γ}, Tm78 Γ (arr78 nat78 (arr78 nat78 nat78)) := lam78 (rec78 v078 (lam78 (lam78 (lam78 (suc78 (app78 v178 v078))))) (lam78 v078)) def mul78 : ∀ {Γ}, Tm78 Γ (arr78 nat78 (arr78 nat78 nat78)) := lam78 (rec78 v078 (lam78 (lam78 (lam78 (app78 (app78 add78 (app78 v178 v078)) v078)))) (lam78 zero78)) def fact78 : ∀ {Γ}, Tm78 Γ (arr78 nat78 nat78) := lam78 (rec78 v078 (lam78 (lam78 (app78 (app78 mul78 (suc78 v178)) v078))) (suc78 zero78)) def Ty79 : Type 1 := ∀ (Ty79 : Type) (nat top bot : Ty79) (arr prod sum : Ty79 → Ty79 → Ty79) , Ty79 def nat79 : Ty79 := λ _ nat79 _ _ _ _ _ => nat79 def top79 : Ty79 := λ _ _ top79 _ _ _ _ => top79 def bot79 : Ty79 := λ _ _ _ bot79 _ _ _ => bot79 def arr79 : Ty79 → Ty79 → Ty79 := λ A B Ty79 nat79 top79 bot79 arr79 prod sum => arr79 (A Ty79 nat79 top79 bot79 arr79 prod sum) (B Ty79 nat79 top79 bot79 arr79 prod sum) def prod79 : Ty79 → Ty79 → Ty79 := λ A B Ty79 nat79 top79 bot79 arr79 prod79 sum => prod79 (A Ty79 nat79 top79 bot79 arr79 prod79 sum) (B Ty79 nat79 top79 bot79 arr79 prod79 sum) def sum79 : Ty79 → Ty79 → Ty79 := λ A B Ty79 nat79 top79 bot79 arr79 prod79 sum79 => sum79 (A Ty79 nat79 top79 bot79 arr79 prod79 sum79) (B Ty79 nat79 top79 bot79 arr79 prod79 sum79) def Con79 : Type 1 := ∀ (Con79 : Type) (nil : Con79) (snoc : Con79 → Ty79 → Con79) , Con79 def nil79 : Con79 := λ Con79 nil79 snoc => nil79 def snoc79 : Con79 → Ty79 → Con79 := λ Γ A Con79 nil79 snoc79 => snoc79 (Γ Con79 nil79 snoc79) A def Var79 : Con79 → Ty79 → Type 1 := λ Γ A => ∀ (Var79 : Con79 → Ty79 → Type) (vz : ∀{Γ A}, Var79 (snoc79 Γ A) A) (vs : ∀{Γ B A}, Var79 Γ A → Var79 (snoc79 Γ B) A) , Var79 Γ A def vz79 : ∀ {Γ A}, Var79 (snoc79 Γ A) A := λ Var79 vz79 vs => vz79 def vs79 : ∀ {Γ B A}, Var79 Γ A → Var79 (snoc79 Γ B) A := λ x Var79 vz79 vs79 => vs79 (x Var79 vz79 vs79) def Tm79 : Con79 → Ty79 → Type 1 := λ Γ A => ∀ (Tm79 : Con79 → Ty79 → Type) (var : ∀ {Γ A}, Var79 Γ A → Tm79 Γ A) (lam : ∀ {Γ A B}, (Tm79 (snoc79 Γ A) B → Tm79 Γ (arr79 A B))) (app : ∀ {Γ A B} , Tm79 Γ (arr79 A B) → Tm79 Γ A → Tm79 Γ B) (tt : ∀ {Γ} , Tm79 Γ top79) (pair : ∀ {Γ A B} , Tm79 Γ A → Tm79 Γ B → Tm79 Γ (prod79 A B)) (fst : ∀ {Γ A B} , Tm79 Γ (prod79 A B) → Tm79 Γ A) (snd : ∀ {Γ A B} , Tm79 Γ (prod79 A B) → Tm79 Γ B) (left : ∀ {Γ A B} , Tm79 Γ A → Tm79 Γ (sum79 A B)) (right : ∀ {Γ A B} , Tm79 Γ B → Tm79 Γ (sum79 A B)) (case : ∀ {Γ A B C} , Tm79 Γ (sum79 A B) → Tm79 Γ (arr79 A C) → Tm79 Γ (arr79 B C) → Tm79 Γ C) (zero : ∀ {Γ} , Tm79 Γ nat79) (suc : ∀ {Γ} , Tm79 Γ nat79 → Tm79 Γ nat79) (rec : ∀ {Γ A} , Tm79 Γ nat79 → Tm79 Γ (arr79 nat79 (arr79 A A)) → Tm79 Γ A → Tm79 Γ A) , Tm79 Γ A def var79 : ∀ {Γ A}, Var79 Γ A → Tm79 Γ A := λ x Tm79 var79 lam app tt pair fst snd left right case zero suc rec => var79 x def lam79 : ∀ {Γ A B} , Tm79 (snoc79 Γ A) B → Tm79 Γ (arr79 A B) := λ t Tm79 var79 lam79 app tt pair fst snd left right case zero suc rec => lam79 (t Tm79 var79 lam79 app tt pair fst snd left right case zero suc rec) def app79 : ∀ {Γ A B} , Tm79 Γ (arr79 A B) → Tm79 Γ A → Tm79 Γ B := λ t u Tm79 var79 lam79 app79 tt pair fst snd left right case zero suc rec => app79 (t Tm79 var79 lam79 app79 tt pair fst snd left right case zero suc rec) (u Tm79 var79 lam79 app79 tt pair fst snd left right case zero suc rec) def tt79 : ∀ {Γ} , Tm79 Γ top79 := λ Tm79 var79 lam79 app79 tt79 pair fst snd left right case zero suc rec => tt79 def pair79 : ∀ {Γ A B} , Tm79 Γ A → Tm79 Γ B → Tm79 Γ (prod79 A B) := λ t u Tm79 var79 lam79 app79 tt79 pair79 fst snd left right case zero suc rec => pair79 (t Tm79 var79 lam79 app79 tt79 pair79 fst snd left right case zero suc rec) (u Tm79 var79 lam79 app79 tt79 pair79 fst snd left right case zero suc rec) def fst79 : ∀ {Γ A B} , Tm79 Γ (prod79 A B) → Tm79 Γ A := λ t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd left right case zero suc rec => fst79 (t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd left right case zero suc rec) def snd79 : ∀ {Γ A B} , Tm79 Γ (prod79 A B) → Tm79 Γ B := λ t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left right case zero suc rec => snd79 (t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left right case zero suc rec) def left79 : ∀ {Γ A B} , Tm79 Γ A → Tm79 Γ (sum79 A B) := λ t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right case zero suc rec => left79 (t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right case zero suc rec) def right79 : ∀ {Γ A B} , Tm79 Γ B → Tm79 Γ (sum79 A B) := λ t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case zero suc rec => right79 (t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case zero suc rec) def case79 : ∀ {Γ A B C} , Tm79 Γ (sum79 A B) → Tm79 Γ (arr79 A C) → Tm79 Γ (arr79 B C) → Tm79 Γ C := λ t u v Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case79 zero suc rec => case79 (t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case79 zero suc rec) (u Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case79 zero suc rec) (v Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case79 zero suc rec) def zero79 : ∀ {Γ} , Tm79 Γ nat79 := λ Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case79 zero79 suc rec => zero79 def suc79 : ∀ {Γ} , Tm79 Γ nat79 → Tm79 Γ nat79 := λ t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case79 zero79 suc79 rec => suc79 (t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case79 zero79 suc79 rec) def rec79 : ∀ {Γ A} , Tm79 Γ nat79 → Tm79 Γ (arr79 nat79 (arr79 A A)) → Tm79 Γ A → Tm79 Γ A := λ t u v Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case79 zero79 suc79 rec79 => rec79 (t Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case79 zero79 suc79 rec79) (u Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case79 zero79 suc79 rec79) (v Tm79 var79 lam79 app79 tt79 pair79 fst79 snd79 left79 right79 case79 zero79 suc79 rec79) def v079 : ∀ {Γ A}, Tm79 (snoc79 Γ A) A := var79 vz79 def v179 : ∀ {Γ A B}, Tm79 (snoc79 (snoc79 Γ A) B) A := var79 (vs79 vz79) def v279 : ∀ {Γ A B C}, Tm79 (snoc79 (snoc79 (snoc79 Γ A) B) C) A := var79 (vs79 (vs79 vz79)) def v379 : ∀ {Γ A B C D}, Tm79 (snoc79 (snoc79 (snoc79 (snoc79 Γ A) B) C) D) A := var79 (vs79 (vs79 (vs79 vz79))) def tbool79 : Ty79 := sum79 top79 top79 def ttrue79 : ∀ {Γ}, Tm79 Γ tbool79 := left79 tt79 def tfalse79 : ∀ {Γ}, Tm79 Γ tbool79 := right79 tt79 def ifthenelse79 : ∀ {Γ A}, Tm79 Γ (arr79 tbool79 (arr79 A (arr79 A A))) := lam79 (lam79 (lam79 (case79 v279 (lam79 v279) (lam79 v179)))) def times479 : ∀ {Γ A}, Tm79 Γ (arr79 (arr79 A A) (arr79 A A)) := lam79 (lam79 (app79 v179 (app79 v179 (app79 v179 (app79 v179 v079))))) def add79 : ∀ {Γ}, Tm79 Γ (arr79 nat79 (arr79 nat79 nat79)) := lam79 (rec79 v079 (lam79 (lam79 (lam79 (suc79 (app79 v179 v079))))) (lam79 v079)) def mul79 : ∀ {Γ}, Tm79 Γ (arr79 nat79 (arr79 nat79 nat79)) := lam79 (rec79 v079 (lam79 (lam79 (lam79 (app79 (app79 add79 (app79 v179 v079)) v079)))) (lam79 zero79)) def fact79 : ∀ {Γ}, Tm79 Γ (arr79 nat79 nat79) := lam79 (rec79 v079 (lam79 (lam79 (app79 (app79 mul79 (suc79 v179)) v079))) (suc79 zero79))
2986670a997d13c73a7fb07fe94cec64f0e8c320
302c785c90d40ad3d6be43d33bc6a558354cc2cf
/test/linarith.lean
4462f76b987d94aaacea6d53d3c85fdbde2143b1
[ "Apache-2.0" ]
permissive
ilitzroth/mathlib
ea647e67f1fdfd19a0f7bdc5504e8acec6180011
5254ef14e3465f6504306132fe3ba9cec9ffff16
refs/heads/master
1,680,086,661,182
1,617,715,647,000
1,617,715,647,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
10,539
lean
import tactic.linarith import algebra.field_power example {α : Type} (_inst : Π (a : Prop), decidable a) [linear_ordered_field α] {a b c : α} (ha : a < 0) (hb : ¬b = 0) (hc' : c = 0) (h : (1 - a) * (b * b) ≤ 0) (hc : 0 ≤ 0) (this : -(a * -b * -b + b * -b + 0) = (1 - a) * (b * b)) (h : (1 - a) * (b * b) ≤ 0) : 0 < 1 - a := begin linarith end example (e b c a v0 v1 : ℚ) (h1 : v0 = 5*a) (h2 : v1 = 3*b) (h3 : v0 + v1 + c = 10) : v0 + 5 + (v1 - 3) + (c - 2) = 10 := by linarith example (u v r s t : ℚ) (h : 0 < u*(t*v + t*r + s)) : 0 < (t*(r + v) + s)*3*u := by linarith example (A B : ℚ) (h : 0 < A * B) : 0 < 8*A*B := begin linarith end example (A B : ℚ) (h : 0 < A * B) : 0 < A*8*B := begin linarith end example (A B : ℚ) (h : 0 < A * B) : 0 < A*B/8 := begin linarith end example (A B : ℚ) (h : 0 < A * B) : 0 < A/8*B := begin linarith end example (ε : ℚ) (h1 : ε > 0) : ε / 2 + ε / 3 + ε / 7 < ε := by linarith example (x y z : ℚ) (h1 : 2*x < 3*y) (h2 : -4*x + z/2 < 0) (h3 : 12*y - z < 0) : false := by linarith example (ε : ℚ) (h1 : ε > 0) : ε / 2 < ε := by linarith example (ε : ℚ) (h1 : ε > 0) : ε / 3 + ε / 3 + ε / 3 = ε := by linarith example (a b c : ℚ) (h2 : b + 2 > 3 + b) : false := by linarith {discharger := `[ring]} example (a b c : ℚ) (h2 : b + 2 > 3 + b) : false := by linarith example (a b c : ℚ) (x y : ℤ) (h1 : x ≤ 3*y) (h2 : b + 2 > 3 + b) : false := by linarith {restrict_type := ℚ} example (g v V c h : ℚ) (h1 : h = 0) (h2 : v = V) (h3 : V > 0) (h4 : g > 0) (h5 : 0 ≤ c) (h6 : c < 1) : v ≤ V := by linarith constant nat.prime : ℕ → Prop example (x y z : ℚ) (h1 : 2*x + ((-3)*y) < 0) (h2 : (-4)*x + 2*z < 0) (h3 : 12*y + (-4)* z < 0) (h4 : nat.prime 7) : false := by linarith example (x y z : ℚ) (h1 : 2*1*x + (3)*(y*(-1)) < 0) (h2 : (-2)*x*2 < -(z + z)) (h3 : 12*y + (-4)* z < 0) (h4 : nat.prime 7) : false := by linarith example (x y z : ℤ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0) (h3 : 12*y - 4* z < 0) : false := by linarith example (x y z : ℤ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0) (h3 : x*y < 5) (h3 : 12*y - 4* z < 0) : false := by linarith example (x y z : ℤ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0) (h3 : x*y < 5) : ¬ 12*y - 4* z < 0 := by linarith example (w x y z : ℤ) (h1 : 4*x + (-3)*y + 6*w ≤ 0) (h2 : (-1)*x < 0) (h3 : y < 0) (h4 : w ≥ 0) (h5 : nat.prime x.nat_abs) : false := by linarith example (a b c : ℚ) (h1 : a > 0) (h2 : b > 5) (h3 : c < -10) (h4 : a + b - c < 3) : false := by linarith example (a b c : ℚ) (h2 : b > 0) (h3 : ¬ b ≥ 0) : false := by linarith example (a b c : ℚ) (h2 : (2 : ℚ) > 3) : a + b - c ≥ 3 := by linarith {exfalso := ff} example (x : ℚ) (hx : x > 0) (h : x.num < 0) : false := by linarith [rat.num_pos_iff_pos.mpr hx, h] example (x : ℚ) (hx : x > 0) (h : x.num < 0) : false := by linarith only [rat.num_pos_iff_pos.mpr hx, h] example (x y z : ℚ) (hx : x ≤ 3*y) (h2 : y ≤ 2*z) (h3 : x ≥ 6*z) : x = 3*y := by linarith example (x y z : ℕ) (hx : x ≤ 3*y) (h2 : y ≤ 2*z) (h3 : x ≥ 6*z) : x = 3*y := by linarith example (x y z : ℚ) (hx : ¬ x > 3*y) (h2 : ¬ y > 2*z) (h3 : x ≥ 6*z) : x = 3*y := by linarith example (h1 : (1 : ℕ) < 1) : false := by linarith example (a b c : ℚ) (h2 : b > 0) (h3 : b < 0) : nat.prime 10 := by linarith example (a b c : ℕ) : a + b ≥ a := by linarith example (a b c : ℕ) : ¬ a + b < a := by linarith example (x y : ℚ) (h : 6 + ((x + 4) * x + (6 + 3 * y) * y) = 3) (h' : (x + 4) * x ≥ 0) (h'' : (6 + 3 * y) * y ≥ 0) : false := by linarith example (x y : ℚ) (h : 6 + ((x + 4) * x + (6 + 3 * y) * y) = 3 ∧ (x + 4) * x ≥ 0 ∧ (6 + 3 * y) * y ≥ 0) : false := by linarith example (a b i : ℕ) (h1 : ¬ a < i) (h2 : b < i) (h3 : a ≤ b) : false := by linarith example (n : ℕ) (h1 : n ≤ 3) (h2 : n > 2) : n = 3 := by linarith example (z : ℕ) (hz : ¬ z ≥ 2) (h2 : ¬ z + 1 ≤ 2) : false := by linarith example (z : ℕ) (hz : ¬ z ≥ 2) : z + 1 ≤ 2 := by linarith example (a b c : ℚ) (h1 : 1 / a < b) (h2 : b < c) : 1 / a < c := by linarith example (N : ℕ) (n : ℕ) (Hirrelevant : n > N) (A : ℚ) (l : ℚ) (h : A - l ≤ -(A - l)) (h_1 : ¬A ≤ -A) (h_2 : ¬l ≤ -l) (h_3 : -(A - l) < 1) : A < l + 1 := by linarith example (d : ℚ) (q n : ℕ) (h1 : ((q : ℚ) - 1)*n ≥ 0) (h2 : d = 2/3*(((q : ℚ) - 1)*n)) : d ≤ ((q : ℚ) - 1)*n := by linarith example (d : ℚ) (q n : ℕ) (h1 : ((q : ℚ) - 1)*n ≥ 0) (h2 : d = 2/3*(((q : ℚ) - 1)*n)) : ((q : ℚ) - 1)*n - d = 1/3 * (((q : ℚ) - 1)*n) := by linarith example (a : ℚ) (ha : 0 ≤ a) : 0 * 0 ≤ 2 * a := by linarith example (x : ℚ) : id x ≥ x := by success_if_fail {linarith}; linarith! example (x y z : ℚ) (hx : x < 5) (hx2 : x > 5) (hy : y < 5000000000) (hz : z > 34*y) : false := by linarith only [hx, hx2] example (x y z : ℚ) (hx : x < 5) (hy : y < 5000000000) (hz : z > 34*y) : x ≤ 5 := by linarith only [hx] example (x y : ℚ) (h : x < y) : x ≠ y := by linarith example (x y : ℚ) (h : x < y) : ¬ x = y := by linarith example (u v x y A B : ℚ) (a : 0 < A) (a_1 : 0 <= 1 - A) (a_2 : 0 <= B - 1) (a_3 : 0 <= B - x) (a_4 : 0 <= B - y) (a_5 : 0 <= u) (a_6 : 0 <= v) (a_7 : 0 < A - u) (a_8 : 0 < A - v) : u * y + v * x + u * v < 3 * A * B := by nlinarith example (u v x y A B : ℚ) : (0 < A) → (A ≤ 1) → (1 ≤ B) → (x ≤ B) → ( y ≤ B) → (0 ≤ u ) → (0 ≤ v ) → (u < A) → ( v < A) → (u * y + v * x + u * v < 3 * A * B) := begin intros, nlinarith end example (u v x y A B : ℚ) (a : 0 < A) (a_1 : 0 <= 1 - A) (a_2 : 0 <= B - 1) (a_3 : 0 <= B - x) (a_4 : 0 <= B - y) (a_5 : 0 <= u) (a_6 : 0 <= v) (a_7 : 0 < A - u) (a_8 : 0 < A - v) : (0 < A * A) -> (0 <= A * (1 - A)) -> (0 <= A * (B - 1)) -> (0 <= A * (B - x)) -> (0 <= A * (B - y)) -> (0 <= A * u) -> (0 <= A * v) -> (0 < A * (A - u)) -> (0 < A * (A - v)) -> (0 <= (1 - A) * A) -> (0 <= (1 - A) * (1 - A)) -> (0 <= (1 - A) * (B - 1)) -> (0 <= (1 - A) * (B - x)) -> (0 <= (1 - A) * (B - y)) -> (0 <= (1 - A) * u) -> (0 <= (1 - A) * v) -> (0 <= (1 - A) * (A - u)) -> (0 <= (1 - A) * (A - v)) -> (0 <= (B - 1) * A) -> (0 <= (B - 1) * (1 - A)) -> (0 <= (B - 1) * (B - 1)) -> (0 <= (B - 1) * (B - x)) -> (0 <= (B - 1) * (B - y)) -> (0 <= (B - 1) * u) -> (0 <= (B - 1) * v) -> (0 <= (B - 1) * (A - u)) -> (0 <= (B - 1) * (A - v)) -> (0 <= (B - x) * A) -> (0 <= (B - x) * (1 - A)) -> (0 <= (B - x) * (B - 1)) -> (0 <= (B - x) * (B - x)) -> (0 <= (B - x) * (B - y)) -> (0 <= (B - x) * u) -> (0 <= (B - x) * v) -> (0 <= (B - x) * (A - u)) -> (0 <= (B - x) * (A - v)) -> (0 <= (B - y) * A) -> (0 <= (B - y) * (1 - A)) -> (0 <= (B - y) * (B - 1)) -> (0 <= (B - y) * (B - x)) -> (0 <= (B - y) * (B - y)) -> (0 <= (B - y) * u) -> (0 <= (B - y) * v) -> (0 <= (B - y) * (A - u)) -> (0 <= (B - y) * (A - v)) -> (0 <= u * A) -> (0 <= u * (1 - A)) -> (0 <= u * (B - 1)) -> (0 <= u * (B - x)) -> (0 <= u * (B - y)) -> (0 <= u * u) -> (0 <= u * v) -> (0 <= u * (A - u)) -> (0 <= u * (A - v)) -> (0 <= v * A) -> (0 <= v * (1 - A)) -> (0 <= v * (B - 1)) -> (0 <= v * (B - x)) -> (0 <= v * (B - y)) -> (0 <= v * u) -> (0 <= v * v) -> (0 <= v * (A - u)) -> (0 <= v * (A - v)) -> (0 < (A - u) * A) -> (0 <= (A - u) * (1 - A)) -> (0 <= (A - u) * (B - 1)) -> (0 <= (A - u) * (B - x)) -> (0 <= (A - u) * (B - y)) -> (0 <= (A - u) * u) -> (0 <= (A - u) * v) -> (0 < (A - u) * (A - u)) -> (0 < (A - u) * (A - v)) -> (0 < (A - v) * A) -> (0 <= (A - v) * (1 - A)) -> (0 <= (A - v) * (B - 1)) -> (0 <= (A - v) * (B - x)) -> (0 <= (A - v) * (B - y)) -> (0 <= (A - v) * u) -> (0 <= (A - v) * v) -> (0 < (A - v) * (A - u)) -> (0 < (A - v) * (A - v)) -> u * y + v * x + u * v < 3 * A * B := begin intros, linarith end example (A B : ℚ) : (0 < A) → (1 ≤ B) → (0 < A / 8 * B) := begin intros, nlinarith end example (x y : ℚ) : 0 ≤ x ^2 + y ^2 := by nlinarith example (x y : ℚ) : 0 ≤ x*x + y*y := by nlinarith example (x y : ℚ) : x = 0 → y = 0 → x*x + y*y = 0 := by intros; nlinarith lemma norm_eq_zero_iff {x y : ℚ} : x * x + y * y = 0 ↔ x = 0 ∧ y = 0 := begin split, { intro, split; nlinarith }, { intro, nlinarith } end lemma norm_nonpos_right {x y : ℚ} (h1 : x * x + y * y ≤ 0) : y = 0 := by nlinarith lemma norm_nonpos_left (x y : ℚ) (h1 : x * x + y * y ≤ 0) : x = 0 := by nlinarith variables {E : Type*} [add_group E] example (f : ℤ → E) (h : 0 = f 0) : 1 ≤ 2 := by nlinarith example (a : E) (h : a = a) : 1 ≤ 2 := by nlinarith -- test that the apply bug doesn't affect linarith preprocessing constant α : Type variable [fact false] -- we work in an inconsistent context below def leα : α → α → Prop := λ a b, ∀ c : α, true noncomputable instance : linear_ordered_field α := by refine_struct { le := leα }; exact (fact.out false).elim example (a : α) (ha : a < 2) : a ≤ a := by linarith example (p q r s t u v w : ℕ) (h1 : p + u = q + t) (h2 : r + w = s + v) : p * r + q * s + (t * w + u * v) = p * s + q * r + (t * v + u * w) := by nlinarith -- Tests involving a norm, including that squares in a type where `pow_two_nonneg` does not apply -- do not cause an exception variables {R : Type*} [ring R] (abs : R → ℚ) lemma abs_nonneg' : ∀ r, 0 ≤ abs r := (fact.out false).elim example (t : R) (a b : ℚ) (h : a ≤ b) : abs (t^2) * a ≤ abs (t^2) * b := by nlinarith [abs_nonneg' abs (t^2)] example (t : R) (a b : ℚ) (h : a ≤ b) : a ≤ abs (t^2) + b := by linarith [abs_nonneg' abs (t^2)] example (t : R) (a b : ℚ) (h : a ≤ b) : abs t * a ≤ abs t * b := by nlinarith [abs_nonneg' abs t] constant T : Type attribute [instance] constant T_zero : ordered_ring T namespace T lemma zero_lt_one : (0 : T) < 1 := (fact.out false).elim lemma works {a b : ℕ} (hab : a ≤ b) (h : b < a) : false := begin linarith, end end T example (a b c : ℚ) (h : a ≠ b) (h3 : b ≠ c) (h2 : a ≥ b) : b ≠ c := by linarith {split_ne := tt} example (a b c : ℚ) (h : a ≠ b) (h2 : a ≥ b) (h3 : b ≠ c) : a > b := by linarith {split_ne := tt} example (x y : ℚ) (h₁ : 0 ≤ y) (h₂ : y ≤ x) : y * x ≤ x * x := by nlinarith example (x y : ℚ) (h₁ : 0 ≤ y) (h₂ : y ≤ x) : y * x ≤ x ^ 2 := by nlinarith axiom foo {x : int} : 1 ≤ x → 1 ≤ x*x lemma bar (x y: int)(h : 0 ≤ y ∧ 1 ≤ x) : 1 ≤ y + x*x := by linarith [foo h.2]
52f61a848d3b1720e71df128d0a15cb5f62658d0
36938939954e91f23dec66a02728db08a7acfcf9
/old-lean4/test_json_parse.lean
c7205eb35a9b7f5cb79baca971b8cf3dc7e51000
[]
no_license
pnwamk/reopt-vcg
f8b56dd0279392a5e1c6aee721be8138e6b558d3
c9f9f185fbefc25c36c4b506bbc85fd1a03c3b6d
refs/heads/master
1,631,145,017,772
1,593,549,019,000
1,593,549,143,000
254,191,418
0
0
null
1,586,377,077,000
1,586,377,077,000
null
UTF-8
Lean
false
false
445
lean
import json open json def mkTree : ℕ → Value | 0 := Value.null | (Nat.succ n) := let t := mkTree n in Value.listObj [("a", t), ("b", t)] open IO.Fs def main (xs : List String) : IO Unit := do let t := mkTree xs.head.toNat, let val := toString t, (match readFromString val Value.readValue with | (EState.Result.ok r _) := IO.println "Success" | (EState.Result.error e _) := do IO.println "Error", IO.println e)
6d99a91d11a16efff5991428b9da1ccdb09a65cb
26ac254ecb57ffcb886ff709cf018390161a9225
/src/tactic/linarith/frontend.lean
953b0ef92c98bc47d7f711429f46e8f17901add4
[ "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
17,882
lean
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Robert Y. Lewis -/ import tactic.linarith.verification import tactic.linarith.preprocessing /-! # `linarith`: solving linear arithmetic goals `linarith` is a tactic for solving goals with linear arithmetic. Suppose we have a set of hypotheses in `n` variables `S = {a₁x₁ + a₂x₂ + ... + aₙxₙ R b₁x₁ + b₂x₂ + ... + bₙxₙ}`, where `R ∈ {<, ≤, =, ≥, >}`. Our goal is to determine if the inequalities in `S` are jointly satisfiable, that is, if there is an assignment of values to `x₁, ..., xₙ` such that every inequality in `S` is true. Specifically, we aim to show that they are *not* satisfiable. This amounts to proving a contradiction. If our goal is also a linear inequality, we negate it and move it to a hypothesis before trying to prove `false`. When the inequalities are over a dense linear order, `linarith` is a decision procedure: it will prove `false` if and only if the inequalities are unsatisfiable. `linarith` will also run on some types like `ℤ` that are not dense orders, but it will fail to prove `false` on some unsatisfiable problems. It will run over concrete types like `ℕ`, `ℚ`, and `ℝ`, as well as abstract types that are instances of `linear_ordered_comm_ring`. ## Algorithm sketch First, the inequalities in the set `S` are rearranged into the form `tᵢ Rᵢ 0`, where `Rᵢ ∈ {<, ≤, =}` and each `tᵢ` is of the form `∑ cⱼxⱼ`. `linarith` uses an untrusted oracle to search for a certificate of unsatisfiability. The oracle searches for a list of natural number coefficients `kᵢ` such that `∑ kᵢtᵢ = 0`, where for at least one `i`, `kᵢ > 0` and `Rᵢ = <`. Given a list of such coefficients, `linarith` verifies that `∑ kᵢtᵢ = 0` using a normalization tactic such as `ring`. It proves that `∑ kᵢtᵢ < 0` by transitivity, since each component of the sum is either equal to, less than or equal to, or less than zero by hypothesis. This produces a contradiction. ## Preprocessing `linarith` does some basic preprocessing before running. Most relevantly, inequalities over natural numbers are cast into inequalities about integers, and rational division by numerals is canceled into multiplication. We do this so that we can guarantee the coefficients in the certificate are natural numbers, which allows the tactic to solve goals over types that are not fields. ## Fourier-Motzkin elimination The oracle implemented to search for certificates uses Fourier-Motzkin variable elimination. This technique transorms a set of inequalities in `n` variables to an equisatisfiable set in `n - 1` variables. Once all variables have been eliminated, we conclude that the original set was unsatisfiable iff the comparison `0 < 0` is in the resulting set. While performing this elimination, we track the history of each derived comparison. This allows us to represent any comparison at any step as a positive combination of comparisons from the original set. In particular, if we derive `0 < 0`, we can find our desired list of coefficients by counting how many copies of each original comparison appear in the history. ## Implementation details `linarith` homogenizes numerical constants: the expression `1` is treated as a variable `t₀`. Often `linarith` is called on goals that have comparison hypotheses over multiple types. This creates multiple `linarith` problems, each of which is handled separately; the goal is solved as soon as one problem is found to be contradictory. Disequality hypotheses `t ≠ 0` do not fit in this pattern. `linarith` will attempt to prove equality goals by splitting them into two weak inequalities and running twice. But it does not split disequality hypotheses, since this would lead to a number of runs exponential in the number of disequalities in the context. The Fourier-Motzkin oracle is very modular. It can easily be replaced with another function of type `list comp → ℕ → option (rb_map ℕ ℕ)`, which takes a list of comparisons and the largest variable index appearing in those comparisons, and returns a map from comparison indices to coefficients. Because we do not expect another oracle to be available any time soon, there is no convenient hook to replace it, but doing so requires only a few lines of code to change. A variant, `nlinarith`, adds an extra preprocessing step to handle some basic nonlinear goals. There is a hook in the `linarith_config` configuration object to add custom preprocessing routines. The certificate checking step is *not* by reflection. `linarith` converts the certificate into a proof term of type `false`. Some of the behavior of `linarith` can be inspected with the option `set_option trace.linarith true`. Because the variable elimination happens outside the tactic monad, we cannot trace intermediate steps there. ## File structure The components of `linarith` are spread between a number of files for the sake of organization. * `lemmas.lean` contains proofs of some arithmetic lemmas that are used in preprocessing and in verification. * `datatypes.lean` contains data structures that are used across multiple files, along with some useful auxiliary functions. * `preprocessing.lean` contains functions used at the beginning of the tactic to transform hypotheses into a shape suitable for the main routine. * `parsing.lean` contains functions used to compute the linear structure of an expression. * `elimination.lean` contains the Fourier-Motzkin elimination routine. * `verification.lean` contains the certificate checking functions that produce a proof of `false`. * `frontend.lean` contains the control methods and user-facing components of the tactic. ## Tags linarith, nlinarith, lra, nra, Fourier Motzkin, linear arithmetic, linear programming -/ open tactic native namespace linarith /-! ### Control -/ /-- If `e` is a comparison `a R b` or the negation of a comparison `¬ a R b`, found in the target, `get_contr_lemma_name_and_type e` returns the name of a lemma that will change the goal to an implication, along with the type of `a` and `b`. For example, if `e` is `(a : ℕ) < b`, returns ``(`lt_of_not_ge, ℕ)``. -/ meta def get_contr_lemma_name_and_type : expr → option (name × expr) | `(@has_lt.lt %%tp %%_ _ _) := return (`lt_of_not_ge, tp) | `(@has_le.le %%tp %%_ _ _) := return (`le_of_not_gt, tp) | `(@eq %%tp _ _) := return (``eq_of_not_lt_of_not_gt, tp) | `(@ne %%tp _ _) := return (`not.intro, tp) | `(@ge %%tp %%_ _ _) := return (`le_of_not_gt, tp) | `(@gt %%tp %%_ _ _) := return (`lt_of_not_ge, tp) | `(¬ @has_lt.lt %%tp %%_ _ _) := return (`not.intro, tp) | `(¬ @has_le.le %%tp %%_ _ _) := return (`not.intro, tp) | `(¬ @eq %%tp _ _) := return (``not.intro, tp) | `(¬ @ge %%tp %%_ _ _) := return (`not.intro, tp) | `(¬ @gt %%tp %%_ _ _) := return (`not.intro, tp) | _ := none /-- `apply_contr_lemma` inspects the target to see if it can be moved to a hypothesis by negation. For example, a goal `⊢ a ≤ b` can become `a > b ⊢ false`. If this is the case, it applies the appropriate lemma and introduces the new hypothesis. It returns the type of the terms in the comparison (e.g. the type of `a` and `b` above) and the newly introduced local constant. Otherwise returns `none`. -/ meta def apply_contr_lemma : tactic (option (expr × expr)) := do t ← target, match get_contr_lemma_name_and_type t with | some (nm, tp) := do refine ((expr.const nm []) pexpr.mk_placeholder), v ← intro1, return $ some (tp, v) | none := return none end /-- `partition_by_type l` takes a list `l` of proofs of comparisons. It sorts these proofs by the type of the variables in the comparison, e.g. `(a : ℚ) < 1` and `(b : ℤ) > c` will be separated. Returns a map from a type to a list of comparisons over that type. -/ meta def partition_by_type (l : list expr) : tactic (rb_lmap expr expr) := l.mfoldl (λ m h, do tp ← ineq_prf_tp h, return $ m.insert tp h) mk_rb_map /-- Given a list `ls` of lists of proofs of comparisons, `try_linarith_on_lists cfg ls` will try to prove `false` by calling `linarith` on each list in succession. It will stop at the first proof of `false`, and fail if no contradiction is found with any list. -/ meta def try_linarith_on_lists (cfg : linarith_config) (ls : list (list expr)) : tactic expr := (first $ ls.map $ prove_false_by_linarith cfg) <|> fail "linarith failed to find a contradiction" /-- Given a list `hyps` of proofs of comparisons, `run_linarith_on_pfs cfg hyps pref_type` preprocesses `hyps` according to the list of preprocessors in `cfg`. It then partitions the resulting list of hypotheses by type, and runs `linarith` on each class in the partition. If `pref_type` is given, it will first use the class of proofs of comparisons over that type. -/ meta def run_linarith_on_pfs (cfg : linarith_config) (hyps : list expr) (pref_type : option expr) : tactic expr := do hyps ← preprocess (cfg.preprocessors.get_or_else default_preprocessors) hyps, linarith_trace_proofs ("after preprocessing, linarith has " ++ to_string hyps.length ++ " facts:") hyps, hyp_set ← partition_by_type hyps, linarith_trace format!"hypotheses appear in {hyp_set.size} different types", match pref_type with | some t := prove_false_by_linarith cfg (hyp_set.ifind t) <|> try_linarith_on_lists cfg (rb_map.values (hyp_set.erase t)) | none := try_linarith_on_lists cfg (rb_map.values hyp_set) end /-- `filter_hyps_to_type restr_type hyps` takes a list of proofs of comparisons `hyps`, and filters it to only those that are comparisons over the type `restr_type`. -/ meta def filter_hyps_to_type (restr_type : expr) (hyps : list expr) : tactic (list expr) := hyps.mfilter $ λ h, do ht ← infer_type h, match get_contr_lemma_name_and_type ht with | some (_, htype) := succeeds $ unify htype restr_type | none := return ff end /-- A hack to allow users to write `{restr_type := ℚ}` in configuration structures. -/ meta def get_restrict_type (e : expr) : tactic expr := do m ← mk_mvar, unify `(some %%m : option Type) e, instantiate_mvars m end linarith /-! ### User facing functions -/ open linarith /-- `linarith reduce_semi only_on hyps cfg` tries to close the goal using linear arithmetic. It fails if it does not succeed at doing this. * If `reduce_semi` is true, it will unfold semireducible definitions when trying to match atomic expressions. * `hyps` is a list of proofs of comparisons to include in the search. * If `only_on` is true, the search will be restricted to `hyps`. Otherwise it will use all comparisons in the local context. -/ meta def tactic.linarith (reduce_semi : bool) (only_on : bool) (hyps : list pexpr) (cfg : linarith_config := {}) : tactic unit := do t ← target, -- if the target is an equality, we run `linarith` twice, to prove ≤ and ≥. if t.is_eq.is_some then linarith_trace "target is an equality: splitting" >> seq' (applyc ``eq_of_not_lt_of_not_gt) tactic.linarith else do when cfg.split_hypotheses (linarith_trace "trying to split hypotheses" >> try auto.split_hyps), /- If we are proving a comparison goal (and not just `false`), we consider the type of the elements in the comparison to be the "preferred" type. That is, if we find comparison hypotheses in multiple types, we will run `linarith` on the goal type first. In this case we also recieve a new variable from moving the goal to a hypothesis. Otherwise, there is no preferred type and no new variable; we simply change the goal to `false`. -/ pref_type_and_new_var_from_tgt ← apply_contr_lemma, when pref_type_and_new_var_from_tgt.is_none $ if cfg.exfalso then linarith_trace "using exfalso" >> exfalso else fail "linarith failed: target is not a valid comparison", let cfg := cfg.update_reducibility reduce_semi, let (pref_type, new_var) := pref_type_and_new_var_from_tgt.elim (none, none) (λ ⟨a, b⟩, (some a, some b)), -- set up the list of hypotheses, considering the `only_on` and `restrict_type` options hyps ← hyps.mmap i_to_expr, hyps ← if only_on then return (new_var.elim [] singleton ++ hyps) else (++ hyps) <$> local_context, hyps ← (do t ← get_restrict_type cfg.restrict_type_reflect, filter_hyps_to_type t hyps) <|> return hyps, linarith_trace_proofs "linarith is running on the following hypotheses:" hyps, run_linarith_on_pfs cfg hyps pref_type >>= exact setup_tactic_parser /-- Tries to prove a goal of `false` by linear arithmetic on hypotheses. If the goal is a linear (in)equality, tries to prove it by contradiction. If the goal is not `false` or an inequality, applies `exfalso` and tries linarith on the hypotheses. * `linarith` will use all relevant hypotheses in the local context. * `linarith [t1, t2, t3]` will add proof terms t1, t2, t3 to the local context. * `linarith only [h1, h2, h3, t1, t2, t3]` will use only the goal (if relevant), local hypotheses `h1`, `h2`, `h3`, and proofs `t1`, `t2`, `t3`. It will ignore the rest of the local context. * `linarith!` will use a stronger reducibility setting to identify atoms. Config options: * `linarith {exfalso := ff}` will fail on a goal that is neither an inequality nor `false` * `linarith {restrict_type := T}` will run only on hypotheses that are inequalities over `T` * `linarith {discharger := tac}` will use `tac` instead of `ring` for normalization. Options: `ring2`, `ring SOP`, `simp` * `linarith {split_hypotheses := ff}` will not destruct conjunctions in the context. -/ meta def tactic.interactive.linarith (red : parse ((tk "!")?)) (restr : parse ((tk "only")?)) (hyps : parse pexpr_list?) (cfg : linarith_config := {}) : tactic unit := tactic.linarith red.is_some restr.is_some (hyps.get_or_else []) cfg add_hint_tactic "linarith" /-- `linarith` attempts to find a contradiction between hypotheses that are linear (in)equalities. Equivalently, it can prove a linear inequality by assuming its negation and proving `false`. In theory, `linarith` should prove any goal that is true in the theory of linear arithmetic over the rationals. While there is some special handling for non-dense orders like `nat` and `int`, this tactic is not complete for these theories and will not prove every true goal. It will solve goals over arbitrary types that instantiate `linear_ordered_comm_ring`. An example: ```lean example (x y z : ℚ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0) (h3 : 12*y - 4* z < 0) : false := by linarith ``` `linarith` will use all appropriate hypotheses and the negation of the goal, if applicable. `linarith [t1, t2, t3]` will additionally use proof terms `t1, t2, t3`. `linarith only [h1, h2, h3, t1, t2, t3]` will use only the goal (if relevant), local hypotheses `h1`, `h2`, `h3`, and proofs `t1`, `t2`, `t3`. It will ignore the rest of the local context. `linarith!` will use a stronger reducibility setting to try to identify atoms. For example, ```lean example (x : ℚ) : id x ≥ x := by linarith ``` will fail, because `linarith` will not identify `x` and `id x`. `linarith!` will. This can sometimes be expensive. `linarith {discharger := tac, restrict_type := tp, exfalso := ff}` takes a config object with five optional arguments: * `discharger` specifies a tactic to be used for reducing an algebraic equation in the proof stage. The default is `ring`. Other options currently include `ring SOP` or `simp` for basic problems. * `restrict_type` will only use hypotheses that are inequalities over `tp`. This is useful if you have e.g. both integer and rational valued inequalities in the local context, which can sometimes confuse the tactic. * `transparency` controls how hard `linarith` will try to match atoms to each other. By default it will only unfold `reducible` definitions. * If `split_hypotheses` is true, `linarith` will split conjunctions in the context into separate hypotheses. * If `exfalso` is false, `linarith` will fail when the goal is neither an inequality nor `false`. (True by default.) A variant, `nlinarith`, does some basic preprocessing to handle some nonlinear goals. The option `set_option trace.linarith true` will trace certain intermediate stages of the `linarith` routine. -/ add_tactic_doc { name := "linarith", category := doc_category.tactic, decl_names := [`tactic.interactive.linarith], tags := ["arithmetic", "decision procedure", "finishing"] } /-- An extension of `linarith` with some preprocessing to allow it to solve some nonlinear arithmetic problems. (Based on Coq's `nra` tactic.) See `linarith` for the available syntax of options, which are inherited by `nlinarith`; that is, `nlinarith!` and `nlinarith only [h1, h2]` all work as in `linarith`. The preprocessing is as follows: * For every subterm `a ^ 2` or `a * a` in a hypothesis or the goal, the assumption `0 ≤ a ^ 2` or `0 ≤ a * a` is added to the context. * For every pair of hypotheses `a1 R1 b1`, `a2 R2 b2` in the context, `R1, R2 ∈ {<, ≤, =}`, the assumption `0 R' (b1 - a1) * (b2 - a2)` is added to the context (non-recursively), where `R ∈ {<, ≤, =}` is the appropriate comparison derived from `R1, R2`. -/ meta def tactic.interactive.nlinarith (red : parse ((tk "!")?)) (restr : parse ((tk "only")?)) (hyps : parse pexpr_list?) (cfg : linarith_config := {}) : tactic unit := tactic.linarith red.is_some restr.is_some (hyps.get_or_else []) { cfg with preprocessors := some $ cfg.preprocessors.get_or_else default_preprocessors ++ [nlinarith_extras] } add_hint_tactic "nlinarith" add_tactic_doc { name := "nlinarith", category := doc_category.tactic, decl_names := [`tactic.interactive.nlinarith], tags := ["arithmetic", "decision procedure", "finishing"] }
73efaa4d794b4c0341502401adf836ce164a99b1
4b846d8dabdc64e7ea03552bad8f7fa74763fc67
/library/init/category/functor.lean
7e4d925e731d2d4c70b1cdedcf6e05b2635df300
[ "Apache-2.0" ]
permissive
pacchiano/lean
9324b33f3ac3b5c5647285160f9f6ea8d0d767dc
fdadada3a970377a6df8afcd629a6f2eab6e84e8
refs/heads/master
1,611,357,380,399
1,489,870,101,000
1,489,870,101,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
845
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 -/ prelude import init.core init.function open function universes u v class functor (f : Type u → Type v) : Type (max u+1 v) := (map : Π {α β : Type u}, (α → β) → f α → f β) (map_const : Π {α : Type u} (β : Type u), α → f β → f α := λ α β, map ∘ const β) @[inline] def fmap {f : Type u → Type v} [functor f] {α β : Type u} : (α → β) → f α → f β := functor.map @[inline] def fmap_const {f : Type u → Type v} [functor f] {α : Type u} : Π (β : Type u), α → f β → f α := functor.map_const infixr ` <$> `:100 := fmap infixr ` <$ `:100 := fmap_const infixr ` $> `:100 := λ α a b, fmap_const α b a
1598a5194d1061bdc4237ee9dc9a75bc8c8de283
d1a52c3f208fa42c41df8278c3d280f075eb020c
/stage0/src/Lean/Compiler/IR/NormIds.lean
5a22dbe70c03c15f00547b98ddd9d0c8f2ec2eaa
[ "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
cipher1024/lean4
6e1f98bb58e7a92b28f5364eb38a14c8d0aae393
69114d3b50806264ef35b57394391c3e738a9822
refs/heads/master
1,642,227,983,603
1,642,011,696,000
1,642,011,696,000
228,607,691
0
0
Apache-2.0
1,576,584,269,000
1,576,584,268,000
null
UTF-8
Lean
false
false
7,637
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.Compiler.IR.Basic namespace Lean.IR.UniqueIds abbrev M := StateT IndexSet Id def checkId (id : Index) : M Bool := modifyGet fun s => if s.contains id then (false, s) else (true, s.insert id) def checkParams (ps : Array Param) : M Bool := ps.allM $ fun p => checkId p.x.idx partial def checkFnBody : FnBody → M Bool | FnBody.vdecl x _ _ b => checkId x.idx <&&> checkFnBody b | FnBody.jdecl j ys _ b => checkId j.idx <&&> checkParams ys <&&> checkFnBody b | FnBody.case _ _ _ alts => alts.allM fun alt => checkFnBody alt.body | b => if b.isTerminal then pure true else checkFnBody b.body partial def checkDecl : Decl → M Bool | Decl.fdecl (xs := xs) (body := b) .. => checkParams xs <&&> checkFnBody b | Decl.extern (xs := xs) .. => checkParams xs end UniqueIds /- Return true if variable, parameter and join point ids are unique -/ def Decl.uniqueIds (d : Decl) : Bool := (UniqueIds.checkDecl d).run' {} namespace NormalizeIds abbrev M := ReaderT IndexRenaming Id def normIndex (x : Index) : M Index := fun m => match m.find? x with | some y => y | none => x def normVar (x : VarId) : M VarId := VarId.mk <$> normIndex x.idx def normJP (x : JoinPointId) : M JoinPointId := JoinPointId.mk <$> normIndex x.idx def normArg : Arg → M Arg | Arg.var x => Arg.var <$> normVar x | other => pure other def normArgs (as : Array Arg) : M (Array Arg) := fun m => as.map $ fun a => normArg a m def normExpr : Expr → M Expr | Expr.ctor c ys, m => Expr.ctor c (normArgs ys m) | Expr.reset n x, m => Expr.reset n (normVar x m) | Expr.reuse x c u ys, m => Expr.reuse (normVar x m) c u (normArgs ys m) | Expr.proj i x, m => Expr.proj i (normVar x m) | Expr.uproj i x, m => Expr.uproj i (normVar x m) | Expr.sproj n o x, m => Expr.sproj n o (normVar x m) | Expr.fap c ys, m => Expr.fap c (normArgs ys m) | Expr.pap c ys, m => Expr.pap c (normArgs ys m) | Expr.ap x ys, m => Expr.ap (normVar x m) (normArgs ys m) | Expr.box t x, m => Expr.box t (normVar x m) | Expr.unbox x, m => Expr.unbox (normVar x m) | Expr.isShared x, m => Expr.isShared (normVar x m) | Expr.isTaggedPtr x, m => Expr.isTaggedPtr (normVar x m) | e@(Expr.lit v), m => e abbrev N := ReaderT IndexRenaming (StateM Nat) @[inline] def withVar {α : Type} (x : VarId) (k : VarId → N α) : N α := fun m => do let n ← getModify (fun n => n + 1) k { idx := n } (m.insert x.idx n) @[inline] def withJP {α : Type} (x : JoinPointId) (k : JoinPointId → N α) : N α := fun m => do let n ← getModify (fun n => n + 1) k { idx := n } (m.insert x.idx n) @[inline] def withParams {α : Type} (ps : Array Param) (k : Array Param → N α) : N α := fun m => do let m ← ps.foldlM (init := m) fun m p => do let n ← getModify fun n => n + 1 pure $ m.insert p.x.idx n let ps := ps.map fun p => { p with x := normVar p.x m } k ps m instance : MonadLift M N := ⟨fun x m => pure $ x m⟩ partial def normFnBody : FnBody → N FnBody | FnBody.vdecl x t v b => do let v ← normExpr v; withVar x fun x => return FnBody.vdecl x t v (← normFnBody b) | FnBody.jdecl j ys v b => do let (ys, v) ← withParams ys fun ys => do let v ← normFnBody v; pure (ys, v) withJP j fun j => return FnBody.jdecl j ys v (← normFnBody b) | FnBody.set x i y b => return FnBody.set (← normVar x) i (← normArg y) (← normFnBody b) | FnBody.uset x i y b => return FnBody.uset (← normVar x) i (← normVar y) (← normFnBody b) | FnBody.sset x i o y t b => return FnBody.sset (← normVar x) i o (← normVar y) t (← normFnBody b) | FnBody.setTag x i b => return FnBody.setTag (← normVar x) i (← normFnBody b) | FnBody.inc x n c p b => return FnBody.inc (← normVar x) n c p (← normFnBody b) | FnBody.dec x n c p b => return FnBody.dec (← normVar x) n c p (← normFnBody b) | FnBody.del x b => return FnBody.del (← normVar x) (← normFnBody b) | FnBody.mdata d b => return FnBody.mdata d (← normFnBody b) | FnBody.case tid x xType alts => do let x ← normVar x let alts ← alts.mapM fun alt => alt.mmodifyBody normFnBody return FnBody.case tid x xType alts | FnBody.jmp j ys => return FnBody.jmp (← normJP j) (← normArgs ys) | FnBody.ret x => return FnBody.ret (← normArg x) | FnBody.unreachable => pure FnBody.unreachable def normDecl (d : Decl) : N Decl := match d with | Decl.fdecl (xs := xs) (body := b) .. => withParams xs fun xs => return d.updateBody! (← normFnBody b) | other => pure other end NormalizeIds /- Create a declaration equivalent to `d` s.t. `d.normalizeIds.uniqueIds == true` -/ def Decl.normalizeIds (d : Decl) : Decl := (NormalizeIds.normDecl d {}).run' 1 /- Apply a function `f : VarId → VarId` to variable occurrences. The following functions assume the IR code does not have variable shadowing. -/ namespace MapVars @[inline] def mapArg (f : VarId → VarId) : Arg → Arg | Arg.var x => Arg.var (f x) | a => a @[specialize] def mapArgs (f : VarId → VarId) (as : Array Arg) : Array Arg := as.map (mapArg f) @[specialize] def mapExpr (f : VarId → VarId) : Expr → Expr | Expr.ctor c ys => Expr.ctor c (mapArgs f ys) | Expr.reset n x => Expr.reset n (f x) | Expr.reuse x c u ys => Expr.reuse (f x) c u (mapArgs f ys) | Expr.proj i x => Expr.proj i (f x) | Expr.uproj i x => Expr.uproj i (f x) | Expr.sproj n o x => Expr.sproj n o (f x) | Expr.fap c ys => Expr.fap c (mapArgs f ys) | Expr.pap c ys => Expr.pap c (mapArgs f ys) | Expr.ap x ys => Expr.ap (f x) (mapArgs f ys) | Expr.box t x => Expr.box t (f x) | Expr.unbox x => Expr.unbox (f x) | Expr.isShared x => Expr.isShared (f x) | Expr.isTaggedPtr x => Expr.isTaggedPtr (f x) | e@(Expr.lit v) => e @[specialize] partial def mapFnBody (f : VarId → VarId) : FnBody → FnBody | FnBody.vdecl x t v b => FnBody.vdecl x t (mapExpr f v) (mapFnBody f b) | FnBody.jdecl j ys v b => FnBody.jdecl j ys (mapFnBody f v) (mapFnBody f b) | FnBody.set x i y b => FnBody.set (f x) i (mapArg f y) (mapFnBody f b) | FnBody.setTag x i b => FnBody.setTag (f x) i (mapFnBody f b) | FnBody.uset x i y b => FnBody.uset (f x) i (f y) (mapFnBody f b) | FnBody.sset x i o y t b => FnBody.sset (f x) i o (f y) t (mapFnBody f b) | FnBody.inc x n c p b => FnBody.inc (f x) n c p (mapFnBody f b) | FnBody.dec x n c p b => FnBody.dec (f x) n c p (mapFnBody f b) | FnBody.del x b => FnBody.del (f x) (mapFnBody f b) | FnBody.mdata d b => FnBody.mdata d (mapFnBody f b) | FnBody.case tid x xType alts => FnBody.case tid (f x) xType (alts.map fun alt => alt.modifyBody (mapFnBody f)) | FnBody.jmp j ys => FnBody.jmp j (mapArgs f ys) | FnBody.ret x => FnBody.ret (mapArg f x) | FnBody.unreachable => FnBody.unreachable end MapVars @[inline] def FnBody.mapVars (f : VarId → VarId) (b : FnBody) : FnBody := MapVars.mapFnBody f b /- Replace `x` with `y` in `b`. This function assumes `b` does not shadow `x` -/ def FnBody.replaceVar (x y : VarId) (b : FnBody) : FnBody := b.mapVars fun z => if x == z then y else z end Lean.IR
4e27e8d3480db3cb1dfed8cf5c87eade089c09ca
7a468d7c7c0949ab8b191bb62ff6d4d2af9f3917
/src/smt2/builder.lean
b8067ea056aa624d5f67ad144642972061dc395d
[ "Apache-2.0" ]
permissive
seanpm2001/LeanProver_SMT2_Interface
c15b2fba021c406d965655b182eef54a14121b82
7ff0ce248b68ea4db2a2d4966a97b5786da05ed7
refs/heads/master
1,688,599,220,366
1,547,825,187,000
1,547,825,187,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
4,731
lean
import .syntax @[reducible] def smt2.builder := except_t string (state (list smt2.cmd)) instance smt2.builder.monad : monad smt2.builder := by apply_instance meta def smt2.builder.to_format {α : Type} (build : smt2.builder α) : format := format.join $ list.intersperse "\n" $ (list.map to_fmt $ (build.run.run []).snd).reverse meta def smt2.builder.run {α : Type} (build : smt2.builder α) : (except string α × list smt2.cmd) := state_t.run (except_t.run build) [] def smt2.builder.fail {α : Type} : string → smt2.builder α := fun msg, except_t.mk (state_t.mk (fun s, (except.error msg, s))) meta instance (α : Type) : has_to_format (smt2.builder α) := ⟨ smt2.builder.to_format ⟩ namespace smt2 namespace builder def equals (t u : term) : term := term.apply "=" [t, u] def not (t : term) : term := term.apply "not" [t] def implies (t u : term) : term := term.apply "implies" [t, u] def forallq (sym : symbol) (s : sort) (t : term) : term := term.forallq [(sym, s)] t def and (ts : list term) : term := term.apply "and" ts def and2 (t u : term) : term := and [t, u] def or (ts : list term) : term := term.apply "or" ts def or2 (t u : term) : term := or [t, u] def xor (ts : list term) : term := term.apply "xor" ts def xor2 (t u : term) : term := xor [t, u] def iff (t u : term) : term := term.apply "iff" [t, u] def lt (t u : term) : term := term.apply "<" [t, u] def lte (t u : term) : term := term.apply "<=" [t, u] def gt (t u : term) : term := term.apply ">" [t, u] def gte (t u : term) : term := term.apply ">=" [t, u] def add (t u : term) : term := term.apply "+" [t, u] def sub (t u : term) : term := term.apply "-" [t, u] def mul (t u : term) : term := term.apply "*" [t, u] def div (t u : term) : term := term.apply "div" [t, u] def mod (t u : term) : term := term.apply "mod" [t, u] def neg (t : term) : term := term.apply "-" [t] def ite (c t f : term) : term := term.apply "ite" [c, t, f] def int_const (i : int) : term := term.const $ special_constant.number i -- Begin bitvec operations def bv_const (bitwidth:nat) (i : int) : term := term.const $ special_constant.bitvec bitwidth i def bv_add (t u : term) : term := term.apply "bvadd" [t, u] def bv_sub (t u : term) : term := term.apply "bvsub" [t, u] def bv_mul (t u : term) : term := term.apply "bvmul" [t, u] def bv_udiv (t u : term) : term := term.apply "bvudiv" [t, u] def bv_sdiv (t u : term) : term := term.apply "bvsdiv" [t, u] def bv_urem (t u : term) : term := term.apply "bvurem" [t, u] def bv_smod (t u : term) : term := term.apply "bvsmod" [t, u] def bv_srem (t u : term) : term := term.apply "bvsrem" [t, u] def bv_or (t u : term) : term := term.apply "bvor" [t, u] def bv_and (t u : term) : term := term.apply "bvand" [t, u] def bv_xor (t u : term) : term := term.apply "bvxor" [t, u] def bv_shl (t u : term) : term := term.apply "bvshl" [t, u] def bv_lshr (t u : term) : term := term.apply "bvlshr" [t, u] def bv_ashr (t u : term) : term := term.apply "bvashr" [t, u] def bv_sle (t u : term) : term := term.apply "bvsle" [t, u] def bv_slt (t u : term) : term := term.apply "bvslt" [t, u] def bv_ule (t u : term) : term := term.apply "bvule" [t, u] def bv_ult (t u : term) : term := term.apply "bvult" [t, u] def bv_zext (bitsz : nat) (t : term) : term := term.apply2 (term.apply "_" [term.qual_id "zero_extend", term.const bitsz]) [t] def bv_sext (bitsz : nat) (t : term) : term := term.apply2 (term.apply "_" [term.qual_id "sign_extend", term.const bitsz]) [t] def bv_extract (upper lower : nat) (t : term) : term := term.apply2 (term.apply "_" [term.qual_id "extract", term.const ↑upper, term.const ↑lower]) [t] -- End bitvec operations def add_command (c : cmd) : builder unit := do cs ← except_t.lift get, except_t.lift $ put (c :: cs) def echo (msg : string) : builder unit := add_command (cmd.echo msg) def check_sat : builder unit := add_command cmd.check_sat def pop (n : nat) : builder unit := add_command $ cmd.pop n def push (n : nat) : builder unit := add_command $ cmd.push n def scope {α} (level : nat) (action : builder α) : builder α := do push level, res ← action, pop level, return res def assert (t : term) : builder unit := add_command $ cmd.assert_cmd t def reset : builder unit := add_command cmd.reset def exit' : builder unit := add_command cmd.exit_cmd def declare_const (sym : string) (s : sort) : builder unit := add_command $ cmd.declare_const sym s def declare_fun (sym : string) (ps : list sort) (ret : sort) : builder unit := add_command $ cmd.declare_fun sym ps ret def declare_sort (sym : string) (arity : nat) : builder unit := add_command $ cmd.declare_sort sym arity end builder end smt2
babf03602635bfb532ed0345c26129333e5077f3
97f752b44fd85ec3f635078a2dd125ddae7a82b6
/library/data/set/function.lean
f0bb4e9afc822341e691fdf0c3971d95c0e2ef67
[ "Apache-2.0" ]
permissive
tectronics/lean
ab977ba6be0fcd46047ddbb3c8e16e7c26710701
f38af35e0616f89c6e9d7e3eb1d48e47ee666efe
refs/heads/master
1,532,358,526,384
1,456,276,623,000
1,456,276,623,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
13,734
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad, Andrew Zipperer, Haitao Zhang Functions between subsets of finite types. -/ import .basic open function eq.ops namespace set variables {X Y Z : Type} /- preimages -/ definition preimage {A B:Type} (f : A → B) (Y : set B) : set A := { x | f x ∈ Y } notation f ` '- ` s := preimage f s theorem mem_preimage_iff (f : X → Y) (a : set Y) (x : X) : f x ∈ a ↔ x ∈ f '- a := !iff.refl theorem mem_preimage {f : X → Y} {a : set Y} {x : X} (H : f x ∈ a) : x ∈ f '- a := H theorem mem_of_mem_preimage {f : X → Y} {a : set Y} {x : X} (H : x ∈ f '- a) : f x ∈ a := proof H qed theorem preimage_comp (f : Y → Z) (g : X → Y) (a : set Z) : (f ∘ g) '- a = g '- (f '- a) := ext (take x, !iff.refl) lemma image_subset_iff {A B : Type} {f : A → B} {X : set A} {Y : set B} : f ' X ⊆ Y ↔ X ⊆ f '- Y := @bounded_forall_image_iff A B f X Y theorem preimage_subset {a b : set Y} (f : X → Y) (H : a ⊆ b) : f '- a ⊆ f '- b := λ x H', proof @H (f x) H' qed theorem preimage_id (s : set Y) : (λx, x) '- s = s := ext (take x, !iff.refl) theorem preimage_union (f : X → Y) (s t : set Y) : f '- (s ∪ t) = f '- s ∪ f '- t := ext (take x, !iff.refl) theorem preimage_inter (f : X → Y) (s t : set Y) : f '- (s ∩ t) = f '- s ∩ f '- t := ext (take x, !iff.refl) theorem preimage_compl (f : X → Y) (s : set Y) : f '- (-s) = -(f '- s) := ext (take x, !iff.refl) theorem preimage_diff (f : X → Y) (s t : set Y) : f '- (s \ t) = f '- s \ f '- t := ext (take x, !iff.refl) theorem image_preimage_subset (f : X → Y) (s : set Y) : f ' (f '- s) ⊆ s := take y, suppose y ∈ f ' (f '- s), obtain x [xfis fxeqy], from this, show y ∈ s, by rewrite -fxeqy; exact xfis theorem subset_preimage_image (s : set X) (f : X → Y) : s ⊆ f '- (f ' s) := take x, suppose x ∈ s, show f x ∈ f ' s, from mem_image_of_mem f this theorem inter_preimage_subset (s : set X) (t : set Y) (f : X → Y) : s ∩ f '- t ⊆ f '- (f ' s ∩ t) := take x, assume H : x ∈ s ∩ f '- t, mem_preimage (show f x ∈ f ' s ∩ t, from and.intro (mem_image_of_mem f (and.left H)) (mem_of_mem_preimage (and.right H))) theorem union_preimage_subset (s : set X) (t : set Y) (f : X → Y) : s ∪ f '- t ⊆ f '- (f ' s ∪ t) := take x, assume H : x ∈ s ∪ f '- t, mem_preimage (show f x ∈ f ' s ∪ t, from or.elim H (suppose x ∈ s, or.inl (mem_image_of_mem f this)) (suppose x ∈ f '- t, or.inr (mem_of_mem_preimage this))) theorem image_inter (f : X → Y) (s : set X) (t : set Y) : f ' s ∩ t = f ' (s ∩ f '- t) := ext (take y, iff.intro (suppose y ∈ f ' s ∩ t, obtain [x [xs fxeqy]] yt, from this, have x ∈ s ∩ f '- t, from and.intro xs (mem_preimage (show f x ∈ t, by rewrite fxeqy; exact yt)), mem_image this fxeqy) (suppose y ∈ f ' (s ∩ f '- t), obtain x [[xs xfit] fxeqy], from this, and.intro (mem_image xs fxeqy) (show y ∈ t, by rewrite -fxeqy; exact mem_of_mem_preimage xfit))) theorem image_union_supset (f : X → Y) (s : set X) (t : set Y) : f ' s ∪ t ⊇ f ' (s ∪ f '- t) := take y, assume H, obtain x [xmem fxeqy], from H, or.elim xmem (suppose x ∈ s, or.inl (mem_image this fxeqy)) (suppose x ∈ f '- t, or.inr (show y ∈ t, by+ rewrite -fxeqy; exact mem_of_mem_preimage this)) /- maps to -/ definition maps_to [reducible] (f : X → Y) (a : set X) (b : set Y) : Prop := ∀⦃x⦄, x ∈ a → f x ∈ b theorem maps_to_of_eq_on {f1 f2 : X → Y} {a : set X} {b : set Y} (eq_on_a : eq_on f1 f2 a) (maps_to_f1 : maps_to f1 a b) : maps_to f2 a b := take x, assume xa : x ∈ a, have H : f1 x ∈ b, from maps_to_f1 xa, show f2 x ∈ b, from eq_on_a xa ▸ H theorem maps_to_compose {g : Y → Z} {f : X → Y} {a : set X} {b : set Y} {c : set Z} (H1 : maps_to g b c) (H2 : maps_to f a b) : maps_to (g ∘ f) a c := take x, assume H : x ∈ a, H1 (H2 H) theorem maps_to_univ_univ (f : X → Y) : maps_to f univ univ := take x, assume H, trivial theorem image_subset_of_maps_to_of_subset {f : X → Y} {a : set X} {b : set Y} (mfab : maps_to f a b) {c : set X} (csuba : c ⊆ a) : f ' c ⊆ b := take y, suppose y ∈ f ' c, obtain x [(xc : x ∈ c) (yeq : f x = y)], from this, have x ∈ a, from csuba `x ∈ c`, have f x ∈ b, from mfab this, show y ∈ b, from yeq ▸ this theorem image_subset_of_maps_to {f : X → Y} {a : set X} {b : set Y} (mfab : maps_to f a b) : f ' a ⊆ b := image_subset_of_maps_to_of_subset mfab (subset.refl a) /- injectivity -/ definition inj_on [reducible] (f : X → Y) (a : set X) : Prop := ∀⦃x1 x2 : X⦄, x1 ∈ a → x2 ∈ a → f x1 = f x2 → x1 = x2 theorem inj_on_empty (f : X → Y) : inj_on f ∅ := take x₁ x₂, assume H₁ H₂ H₃, false.elim H₁ theorem inj_on_of_eq_on {f1 f2 : X → Y} {a : set X} (eq_f1_f2 : eq_on f1 f2 a) (inj_f1 : inj_on f1 a) : inj_on f2 a := take x1 x2 : X, assume ax1 : x1 ∈ a, assume ax2 : x2 ∈ a, assume H : f2 x1 = f2 x2, have H' : f1 x1 = f1 x2, from eq_f1_f2 ax1 ⬝ H ⬝ (eq_f1_f2 ax2)⁻¹, show x1 = x2, from inj_f1 ax1 ax2 H' theorem inj_on_compose {g : Y → Z} {f : X → Y} {a : set X} {b : set Y} (fab : maps_to f a b) (Hg : inj_on g b) (Hf: inj_on f a) : inj_on (g ∘ f) a := take x1 x2 : X, assume x1a : x1 ∈ a, assume x2a : x2 ∈ a, have fx1b : f x1 ∈ b, from fab x1a, have fx2b : f x2 ∈ b, from fab x2a, assume H1 : g (f x1) = g (f x2), have H2 : f x1 = f x2, from Hg fx1b fx2b H1, show x1 = x2, from Hf x1a x2a H2 theorem inj_on_of_inj_on_of_subset {f : X → Y} {a b : set X} (H1 : inj_on f b) (H2 : a ⊆ b) : inj_on f a := take x1 x2 : X, assume (x1a : x1 ∈ a) (x2a : x2 ∈ a), assume H : f x1 = f x2, show x1 = x2, from H1 (H2 x1a) (H2 x2a) H lemma injective_iff_inj_on_univ {f : X → Y} : injective f ↔ inj_on f univ := iff.intro (assume H, take x₁ x₂, assume ax₁ ax₂, H x₁ x₂) (assume H : inj_on f univ, take x₁ x₂ Heq, show x₁ = x₂, from H trivial trivial Heq) /- surjectivity -/ definition surj_on [reducible] (f : X → Y) (a : set X) (b : set Y) : Prop := b ⊆ f ' a theorem surj_on_of_eq_on {f1 f2 : X → Y} {a : set X} {b : set Y} (eq_f1_f2 : eq_on f1 f2 a) (surj_f1 : surj_on f1 a b) : surj_on f2 a b := take y, assume H : y ∈ b, obtain x (H1 : x ∈ a ∧ f1 x = y), from surj_f1 H, have H2 : x ∈ a, from and.left H1, have H3 : f2 x = y, from (eq_f1_f2 H2)⁻¹ ⬝ and.right H1, exists.intro x (and.intro H2 H3) theorem surj_on_compose {g : Y → Z} {f : X → Y} {a : set X} {b : set Y} {c : set Z} (Hg : surj_on g b c) (Hf: surj_on f a b) : surj_on (g ∘ f) a c := take z, assume zc : z ∈ c, obtain y (H1 : y ∈ b ∧ g y = z), from Hg zc, obtain x (H2 : x ∈ a ∧ f x = y), from Hf (and.left H1), show ∃x, x ∈ a ∧ g (f x) = z, from exists.intro x (and.intro (and.left H2) (calc g (f x) = g y : {and.right H2} ... = z : and.right H1)) lemma surjective_iff_surj_on_univ {f : X → Y} : surjective f ↔ surj_on f univ univ := iff.intro (assume H, take y, assume Hy, obtain x Hx, from H y, mem_image trivial Hx) (assume H, take y, obtain x H1x H2x, from H y trivial, exists.intro x H2x) lemma image_eq_of_maps_to_of_surj_on {f : X → Y} {a : set X} {b : set Y} (H1 : maps_to f a b) (H2 : surj_on f a b) : f ' a = b := eq_of_subset_of_subset (image_subset_of_maps_to H1) H2 /- bijectivity -/ definition bij_on [reducible] (f : X → Y) (a : set X) (b : set Y) : Prop := maps_to f a b ∧ inj_on f a ∧ surj_on f a b lemma maps_to_of_bij_on {f : X → Y} {a : set X} {b : set Y} (H : bij_on f a b) : maps_to f a b := and.left H lemma inj_on_of_bij_on {f : X → Y} {a : set X} {b : set Y} (H : bij_on f a b) : inj_on f a := and.left (and.right H) lemma surj_on_of_bij_on {f : X → Y} {a : set X} {b : set Y} (H : bij_on f a b) : surj_on f a b := and.right (and.right H) lemma bij_on.mk {f : X → Y} {a : set X} {b : set Y} (H₁ : maps_to f a b) (H₂ : inj_on f a) (H₃ : surj_on f a b) : bij_on f a b := and.intro H₁ (and.intro H₂ H₃) theorem bij_on_of_eq_on {f1 f2 : X → Y} {a : set X} {b : set Y} (eqf : eq_on f1 f2 a) (H : bij_on f1 a b) : bij_on f2 a b := match H with and.intro Hmap (and.intro Hinj Hsurj) := and.intro (maps_to_of_eq_on eqf Hmap) (and.intro (inj_on_of_eq_on eqf Hinj) (surj_on_of_eq_on eqf Hsurj)) end lemma image_eq_of_bij_on {f : X → Y} {a : set X} {b : set Y} (bfab : bij_on f a b) : f ' a = b := image_eq_of_maps_to_of_surj_on (and.left bfab) (and.right (and.right bfab)) theorem bij_on_compose {g : Y → Z} {f : X → Y} {a : set X} {b : set Y} {c : set Z} (Hg : bij_on g b c) (Hf: bij_on f a b) : bij_on (g ∘ f) a c := match Hg with and.intro Hgmap (and.intro Hginj Hgsurj) := match Hf with and.intro Hfmap (and.intro Hfinj Hfsurj) := and.intro (maps_to_compose Hgmap Hfmap) (and.intro (inj_on_compose Hfmap Hginj Hfinj) (surj_on_compose Hgsurj Hfsurj)) end end lemma bijective_iff_bij_on_univ {f : X → Y} : bijective f ↔ bij_on f univ univ := iff.intro (assume H, obtain Hinj Hsurj, from H, and.intro (maps_to_univ_univ f) (and.intro (iff.mp !injective_iff_inj_on_univ Hinj) (iff.mp !surjective_iff_surj_on_univ Hsurj))) (assume H, obtain Hmaps Hinj Hsurj, from H, (and.intro (iff.mpr !injective_iff_inj_on_univ Hinj) (iff.mpr !surjective_iff_surj_on_univ Hsurj))) /- left inverse -/ -- g is a left inverse to f on a definition left_inv_on [reducible] (g : Y → X) (f : X → Y) (a : set X) : Prop := ∀₀ x ∈ a, g (f x) = x theorem left_inv_on_of_eq_on_left {g1 g2 : Y → X} {f : X → Y} {a : set X} {b : set Y} (fab : maps_to f a b) (eqg : eq_on g1 g2 b) (H : left_inv_on g1 f a) : left_inv_on g2 f a := take x, assume xa : x ∈ a, calc g2 (f x) = g1 (f x) : (eqg (fab xa))⁻¹ ... = x : H xa theorem left_inv_on_of_eq_on_right {g : Y → X} {f1 f2 : X → Y} {a : set X} (eqf : eq_on f1 f2 a) (H : left_inv_on g f1 a) : left_inv_on g f2 a := take x, assume xa : x ∈ a, calc g (f2 x) = g (f1 x) : {(eqf xa)⁻¹} ... = x : H xa theorem inj_on_of_left_inv_on {g : Y → X} {f : X → Y} {a : set X} (H : left_inv_on g f a) : inj_on f a := take x1 x2, assume x1a : x1 ∈ a, assume x2a : x2 ∈ a, assume H1 : f x1 = f x2, calc x1 = g (f x1) : H x1a ... = g (f x2) : H1 ... = x2 : H x2a theorem left_inv_on_compose {f' : Y → X} {g' : Z → Y} {g : Y → Z} {f : X → Y} {a : set X} {b : set Y} (fab : maps_to f a b) (Hf : left_inv_on f' f a) (Hg : left_inv_on g' g b) : left_inv_on (f' ∘ g') (g ∘ f) a := take x : X, assume xa : x ∈ a, have fxb : f x ∈ b, from fab xa, calc f' (g' (g (f x))) = f' (f x) : Hg fxb ... = x : Hf xa /- right inverse -/ -- g is a right inverse to f on a definition right_inv_on [reducible] (g : Y → X) (f : X → Y) (b : set Y) : Prop := left_inv_on f g b theorem right_inv_on_of_eq_on_left {g1 g2 : Y → X} {f : X → Y} {a : set X} {b : set Y} (eqg : eq_on g1 g2 b) (H : right_inv_on g1 f b) : right_inv_on g2 f b := left_inv_on_of_eq_on_right eqg H theorem right_inv_on_of_eq_on_right {g : Y → X} {f1 f2 : X → Y} {a : set X} {b : set Y} (gba : maps_to g b a) (eqf : eq_on f1 f2 a) (H : right_inv_on g f1 b) : right_inv_on g f2 b := left_inv_on_of_eq_on_left gba eqf H theorem surj_on_of_right_inv_on {g : Y → X} {f : X → Y} {a : set X} {b : set Y} (gba : maps_to g b a) (H : right_inv_on g f b) : surj_on f a b := take y, assume yb : y ∈ b, have gya : g y ∈ a, from gba yb, have H1 : f (g y) = y, from H yb, exists.intro (g y) (and.intro gya H1) theorem right_inv_on_compose {f' : Y → X} {g' : Z → Y} {g : Y → Z} {f : X → Y} {c : set Z} {b : set Y} (g'cb : maps_to g' c b) (Hf : right_inv_on f' f b) (Hg : right_inv_on g' g c) : right_inv_on (f' ∘ g') (g ∘ f) c := left_inv_on_compose g'cb Hg Hf theorem right_inv_on_of_inj_on_of_left_inv_on {f : X → Y} {g : Y → X} {a : set X} {b : set Y} (fab : maps_to f a b) (gba : maps_to g b a) (injf : inj_on f a) (lfg : left_inv_on f g b) : right_inv_on f g a := take x, assume xa : x ∈ a, have H : f (g (f x)) = f x, from lfg (fab xa), injf (gba (fab xa)) xa H theorem eq_on_of_left_inv_of_right_inv {g1 g2 : Y → X} {f : X → Y} {a : set X} {b : set Y} (g2ba : maps_to g2 b a) (Hg1 : left_inv_on g1 f a) (Hg2 : right_inv_on g2 f b) : eq_on g1 g2 b := take y, assume yb : y ∈ b, calc g1 y = g1 (f (g2 y)) : {(Hg2 yb)⁻¹} ... = g2 y : Hg1 (g2ba yb) theorem left_inv_on_of_surj_on_right_inv_on {f : X → Y} {g : Y → X} {a : set X} {b : set Y} (surjf : surj_on f a b) (rfg : right_inv_on f g a) : left_inv_on f g b := take y, assume yb : y ∈ b, obtain x (xa : x ∈ a) (Hx : f x = y), from surjf yb, calc f (g y) = f (g (f x)) : Hx ... = f x : rfg xa ... = y : Hx /- inverses -/ -- g is an inverse to f viewed as a map from a to b definition inv_on [reducible] (g : Y → X) (f : X → Y) (a : set X) (b : set Y) : Prop := left_inv_on g f a ∧ right_inv_on g f b theorem bij_on_of_inv_on {g : Y → X} {f : X → Y} {a : set X} {b : set Y} (fab : maps_to f a b) (gba : maps_to g b a) (H : inv_on g f a b) : bij_on f a b := and.intro fab (and.intro (inj_on_of_left_inv_on (and.left H)) (surj_on_of_right_inv_on gba (and.right H))) end set
0c3c0fb72949d2a4df45d2b68b6e47be2020fec2
e61a235b8468b03aee0120bf26ec615c045005d2
/src/Init/Util.lean
716c0c03433eed4db23b3312b4e1d29948b3e606
[ "Apache-2.0" ]
permissive
SCKelemen/lean4
140dc63a80539f7c61c8e43e1c174d8500ec3230
e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc
refs/heads/master
1,660,973,595,917
1,590,278,033,000
1,590,278,033,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,125
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 -/ prelude import Init.Data.String.Basic import Init.Data.ToString universes u v /- debugging helper functions -/ @[neverExtract, extern "lean_dbg_trace"] def dbgTrace {α : Type u} (s : String) (f : Unit → α) : α := f () /- Display the given message if `a` is shared, that is, RC(a) > 1 -/ @[neverExtract, extern "lean_dbg_trace_if_shared"] def dbgTraceIfShared {α : Type u} (s : String) (a : α) : α := a @[extern "lean_dbg_sleep"] def dbgSleep {α : Type u} (ms : UInt32) (f : Unit → α) : α := f () @[extern c inline "#3"] unsafe def unsafeCast {α : Type u} {β : Type v} (a : α) : β := cast lcProof (PUnit.{v}) @[neverExtract, extern "lean_panic_fn"] constant panic {α : Type u} [Inhabited α] (msg : String) : α := arbitrary _ @[noinline] private def mkPanicMessage (modName : String) (line col : Nat) (msg : String) : String := "PANIC at " ++ modName ++ ":" ++ toString line ++ ":" ++ toString col ++ ": " ++ msg @[neverExtract, inline] def panicWithPos {α : Type u} [Inhabited α] (modName : String) (line col : Nat) (msg : String) : α := panic (mkPanicMessage modName line col msg) -- TODO: should be a macro @[neverExtract, noinline, nospecialize] def unreachable! {α : Type u} [Inhabited α] : α := panic! "unreachable" @[extern "lean_ptr_addr"] unsafe def ptrAddrUnsafe {α : Type u} (a : @& α) : USize := 0 @[inline] unsafe def withPtrAddrUnsafe {α : Type u} {β : Type v} (a : α) (k : USize → β) (h : ∀ u₁ u₂, k u₁ = k u₂) : β := k (ptrAddrUnsafe a) @[inline] unsafe def withPtrEqUnsafe {α : Type u} (a b : α) (k : Unit → Bool) (h : a = b → k () = true) : Bool := if ptrAddrUnsafe a == ptrAddrUnsafe b then true else k () inductive PtrEqResult {α : Type u} (x y : α) : Type | unknown : PtrEqResult | yesEqual (h : x = y) : PtrEqResult @[inline] unsafe def withPtrEqResultUnsafe {α : Type u} {β : Type v} [Subsingleton β] (a b : α) (k : PtrEqResult a b → β) : β := if ptrAddrUnsafe a == ptrAddrUnsafe b then k (PtrEqResult.yesEqual lcProof) else k PtrEqResult.unknown @[implementedBy withPtrEqUnsafe] def withPtrEq {α : Type u} (a b : α) (k : Unit → Bool) (h : a = b → k () = true) : Bool := k () /-- `withPtrEq` for `DecidableEq` -/ @[inline] def withPtrEqDecEq {α : Type u} (a b : α) (k : Unit → Decidable (a = b)) : Decidable (a = b) := let b := withPtrEq a b (fun _ => toBoolUsing (k ())) (toBoolUsingEqTrue (k ())); condEq b (fun h => isTrue (ofBoolUsingEqTrue h)) (fun h => isFalse (ofBoolUsingEqFalse h)) /-- Similar to `withPtrEq`, but executes the continuation `k` with the "result" of the pointer equality test. -/ @[implementedBy withPtrEqResultUnsafe] def withPtrEqResult {α : Type u} {β : Type v} [Subsingleton β] (a b : α) (k : PtrEqResult a b → β) : β := k PtrEqResult.unknown @[implementedBy withPtrAddrUnsafe] def withPtrAddr {α : Type u} {β : Type v} (a : α) (k : USize → β) (h : ∀ u₁ u₂, k u₁ = k u₂) : β := k 0
f9521b67e2ec919225f4b3d49956a885c329ead5
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/topology/uniform_space/separation.lean
e98ab331eb197cfe21ce2126046663eab8bb2010
[ "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
22,586
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 -/ import topology.uniform_space.basic import tactic.apply_fun import data.set.pairwise /-! # Hausdorff properties of uniform spaces. Separation quotient. This file studies uniform spaces whose underlying topological spaces are separated (also known as Hausdorff or T₂). This turns out to be equivalent to asking that the intersection of all entourages is the diagonal only. This condition actually implies the stronger separation property that the space is regular (T₃), hence those conditions are equivalent for topologies coming from a uniform structure. More generally, the intersection `𝓢 X` of all entourages of `X`, which has type `set (X × X)` is an equivalence relation on `X`. Points which are equivalent under the relation are basically undistinguishable from the point of view of the uniform structure. For instance any uniformly continuous function will send equivalent points to the same value. The quotient `separation_quotient X` of `X` by `𝓢 X` has a natural uniform structure which is separated, and satisfies a universal property: every uniformly continuous function from `X` to a separated uniform space uniquely factors through `separation_quotient X`. As usual, this allows to turn `separation_quotient` into a functor (but we don't use the category theory library in this file). These notions admit relative versions, one can ask that `s : set X` is separated, this is equivalent to asking that the uniform structure induced on `s` is separated. ## Main definitions * `separation_relation X : set (X × X)`: the separation relation * `separated_space X`: a predicate class asserting that `X` is separated * `is_separated s`: a predicate asserting that `s : set X` is separated * `separation_quotient X`: the maximal separated quotient of `X`. * `separation_quotient.lift f`: factors a map `f : X → Y` through the separation quotient of `X`. * `separation_quotient.map f`: turns a map `f : X → Y` into a map between the separation quotients of `X` and `Y`. ## Main results * `separated_iff_t2`: the equivalence between being separated and being Hausdorff for uniform spaces. * `separation_quotient.uniform_continuous_lift`: factoring a uniformly continuous map through the separation quotient gives a uniformly continuous map. * `separation_quotient.uniform_continuous_map`: maps induced between separation quotients are uniformly continuous. ## Notations Localized in `uniformity`, we have the notation `𝓢 X` for the separation relation on a uniform space `X`, ## Implementation notes The separation setoid `separation_setoid` is not declared as a global instance. It is made a local instance while building the theory of `separation_quotient`. The factored map `separation_quotient.lift f` is defined without imposing any condition on `f`, but returns junk if `f` is not uniformly continuous (constant junk hence it is always uniformly continuous). -/ open filter topological_space set classical function uniform_space open_locale classical topological_space uniformity filter 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 γ] /-! ### Separated uniform spaces -/ /-- 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 localized "notation `𝓢` := separation_rel" in uniformity lemma separated_equiv : equivalence (λx y, (x, y) ∈ 𝓢 α) := ⟨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) ∈ 𝓢 α) (hyz : (y, z) ∈ 𝓢 α) 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⟩⟩ /-- A uniform space is separated if its separation relation is trivial (each point is related only to itself). -/ class separated_space (α : Type u) [uniform_space α] : Prop := (out : 𝓢 α = id_rel) theorem separated_space_iff {α : Type u} [uniform_space α] : separated_space α ↔ 𝓢 α = id_rel := ⟨λ h, h.1, λ h, ⟨h⟩⟩ theorem separated_def {α : Type u} [uniform_space α] : separated_space α ↔ ∀ x y, (∀ r ∈ 𝓤 α, (x, y) ∈ r) → x = y := by simp [separated_space_iff, id_rel_subset.2 separated_equiv.1, subset.antisymm_iff]; simp [subset_def, separation_rel] theorem separated_def' {α : Type u} [uniform_space α] : separated_space α ↔ ∀ x y, x ≠ y → ∃ r ∈ 𝓤 α, (x, y) ∉ r := separated_def.trans $ forall_congr $ λ x, forall_congr $ λ y, by rw ← not_imp_not; simp [not_forall] lemma eq_of_uniformity {α : Type*} [uniform_space α] [separated_space α] {x y : α} (h : ∀ {V}, V ∈ 𝓤 α → (x, y) ∈ V) : x = y := separated_def.mp ‹separated_space α› x y (λ _, h) lemma eq_of_uniformity_basis {α : Type*} [uniform_space α] [separated_space α] {ι : Type*} {p : ι → Prop} {s : ι → set (α × α)} (hs : (𝓤 α).has_basis p s) {x y : α} (h : ∀ {i}, p i → (x, y) ∈ s i) : x = y := eq_of_uniformity (λ V V_in, let ⟨i, hi, H⟩ := hs.mem_iff.mp V_in in H (h hi)) lemma eq_of_forall_symmetric {α : Type*} [uniform_space α] [separated_space α] {x y : α} (h : ∀ {V}, V ∈ 𝓤 α → symmetric_rel V → (x, y) ∈ V) : x = y := eq_of_uniformity_basis has_basis_symmetric (by simpa [and_imp] using λ _, h) lemma id_rel_sub_separation_relation (α : Type*) [uniform_space α] : id_rel ⊆ 𝓢 α := begin unfold separation_rel, rw id_rel_subset, intros x, suffices : ∀ t ∈ 𝓤 α, (x, x) ∈ t, by simpa only [refl_mem_uniformity], exact λ t, refl_mem_uniformity, end lemma separation_rel_comap {f : α → β} (h : ‹uniform_space α› = uniform_space.comap f ‹uniform_space β›) : 𝓢 α = (prod.map f f) ⁻¹' 𝓢 β := begin dsimp [separation_rel], simp_rw [uniformity_comap h, (filter.comap_has_basis (prod.map f f) (𝓤 β)).sInter_sets, ← preimage_Inter, sInter_eq_bInter], refl, end protected lemma filter.has_basis.separation_rel {ι : Sort*} {p : ι → Prop} {s : ι → set (α × α)} (h : has_basis (𝓤 α) p s) : 𝓢 α = ⋂ i (hi : p i), s i := by { unfold separation_rel, rw h.sInter_sets } lemma separation_rel_eq_inter_closure : 𝓢 α = ⋂₀ (closure '' (𝓤 α).sets) := by simp [uniformity_has_basis_closure.separation_rel] lemma is_closed_separation_rel : is_closed (𝓢 α) := begin rw separation_rel_eq_inter_closure, apply is_closed_sInter, rintros _ ⟨t, t_in, rfl⟩, exact is_closed_closure, end lemma separated_iff_t2 : separated_space α ↔ t2_space α := begin classical, split ; introI h, { rw [t2_iff_is_closed_diagonal, ← show 𝓢 α = diagonal α, from h.1], exact is_closed_separation_rel }, { rw separated_def', intros x y hxy, rcases t2_separation hxy with ⟨u, v, uo, vo, hx, hy, h⟩, rcases is_open_iff_ball_subset.1 uo x hx with ⟨r, hrU, hr⟩, exact ⟨r, hrU, λ H, disjoint_iff.2 h ⟨hr H, hy⟩⟩ } end @[priority 100] -- see Note [lower instance priority] instance separated_regular [separated_space α] : regular_space α := { t0 := by { haveI := separated_iff_t2.mp ‹_›, exact t1_space.t0_space.t0 }, regular := λs a hs ha, have sᶜ ∈ 𝓝 a, from is_open.mem_nhds hs.is_open_compl ha, have {p : α × α | p.1 = a → p.2 ∈ sᶜ} ∈ 𝓤 α, from mem_nhds_uniformity_iff_right.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 ∈ 𝓝 a, from (𝓝 a).sets_of_superset (mem_nhds_left a hd) subset_closure, have 𝓝 a ⊓ 𝓟 (closure e)ᶜ = ⊥, from (is_compl_principal (closure e)).inf_right_eq_bot_iff.2 (le_principal_iff.2 this), ⟨(closure e)ᶜ, is_closed_closure.is_open_compl, assume x h₁ h₂, @e_subset x h₂ h₁, this⟩, ..@t2_space.t1_space _ _ (separated_iff_t2.mp ‹_›) } lemma is_closed_of_spaced_out [separated_space α] {V₀ : set (α × α)} (V₀_in : V₀ ∈ 𝓤 α) {s : set α} (hs : s.pairwise (λ x y, (x, y) ∉ V₀)) : is_closed s := begin rcases comp_symm_mem_uniformity_sets V₀_in with ⟨V₁, V₁_in, V₁_symm, h_comp⟩, apply is_closed_of_closure_subset, intros x hx, rw mem_closure_iff_ball at hx, rcases hx V₁_in with ⟨y, hy, hy'⟩, suffices : x = y, by rwa this, apply eq_of_forall_symmetric, intros V V_in V_symm, rcases hx (inter_mem V₁_in V_in) with ⟨z, hz, hz'⟩, obtain rfl : z = y, { by_contra hzy, exact hs z hz' y hy' hzy (h_comp $ mem_comp_of_mem_ball V₁_symm (ball_inter_left x _ _ hz) hy) }, exact ball_inter_right x _ _ hz end lemma is_closed_range_of_spaced_out {ι} [separated_space α] {V₀ : set (α × α)} (V₀_in : V₀ ∈ 𝓤 α) {f : ι → α} (hf : pairwise (λ x y, (f x, f y) ∉ V₀)) : is_closed (range f) := is_closed_of_spaced_out V₀_in $ by { rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ h, exact hf x y (mt (congr_arg f) h) } /-! ### Separated sets -/ /-- A set `s` in a uniform space `α` is separated if the separation relation `𝓢 α` induces the trivial relation on `s`. -/ def is_separated (s : set α) : Prop := ∀ x y ∈ s, (x, y) ∈ 𝓢 α → x = y lemma is_separated_def (s : set α) : is_separated s ↔ ∀ x y ∈ s, (x, y) ∈ 𝓢 α → x = y := iff.rfl lemma is_separated_def' (s : set α) : is_separated s ↔ (s.prod s) ∩ 𝓢 α ⊆ id_rel := begin rw is_separated_def, split, { rintros h ⟨x, y⟩ ⟨⟨x_in, y_in⟩, H⟩, simp [h x y x_in y_in H] }, { intros h x y x_in y_in xy_in, rw ← mem_id_rel, exact h ⟨mk_mem_prod x_in y_in, xy_in⟩ } end lemma univ_separated_iff : is_separated (univ : set α) ↔ separated_space α := begin simp only [is_separated, mem_univ, true_implies_iff, separated_space_iff], split, { intro h, exact subset.antisymm (λ ⟨x, y⟩ xy_in, h x y xy_in) (id_rel_sub_separation_relation α), }, { intros h x y xy_in, rwa h at xy_in }, end lemma is_separated_of_separated_space [separated_space α] (s : set α) : is_separated s := begin rw [is_separated, separated_space.out], tauto, end lemma is_separated_iff_induced {s : set α} : is_separated s ↔ separated_space s := begin rw separated_space_iff, change _ ↔ 𝓢 {x // x ∈ s} = _, rw [separation_rel_comap rfl, is_separated_def'], split; intro h, { ext ⟨⟨x, x_in⟩, ⟨y, y_in⟩⟩, suffices : (x, y) ∈ 𝓢 α ↔ x = y, by simpa only [mem_id_rel], refine ⟨λ H, h ⟨mk_mem_prod x_in y_in, H⟩, _⟩, rintro rfl, exact id_rel_sub_separation_relation α rfl }, { rintros ⟨x, y⟩ ⟨⟨x_in, y_in⟩, hS⟩, have A : (⟨⟨x, x_in⟩, ⟨y, y_in⟩⟩ : ↥s × ↥s) ∈ prod.map (coe : s → α) (coe : s → α) ⁻¹' 𝓢 α, from hS, simpa using h.subset A } end lemma eq_of_uniformity_inf_nhds_of_is_separated {s : set α} (hs : is_separated s) : ∀ {x y : α}, x ∈ s → y ∈ s → cluster_pt (x, y) (𝓤 α) → x = y := begin intros x y x_in y_in H, have : ∀ V ∈ 𝓤 α, (x, y) ∈ closure V, { intros V V_in, rw mem_closure_iff_cluster_pt, have : 𝓤 α ≤ 𝓟 V, by rwa le_principal_iff, exact H.mono this }, apply hs x y x_in y_in, simpa [separation_rel_eq_inter_closure], end lemma eq_of_uniformity_inf_nhds [separated_space α] : ∀ {x y : α}, cluster_pt (x, y) (𝓤 α) → x = y := begin have : is_separated (univ : set α), { rw univ_separated_iff, assumption }, introv, simpa using eq_of_uniformity_inf_nhds_of_is_separated this, end /-! ### Separation quotient -/ namespace uniform_space /-- The separation relation of a uniform space seen as a setoid. -/ def separation_setoid (α : Type u) [uniform_space α] : setoid α := ⟨λx y, (x, y) ∈ 𝓢 α, separated_equiv⟩ local attribute [instance] separation_setoid instance separation_setoid.uniform_space {α : 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_map.comp tendsto_swap_uniformity, 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₁) ∈ 𝓢 α := 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) ∈ 𝓢 α → 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₂ {f : α → β → γ} {h : ∀a c b d, (a, b) ∈ 𝓢 α → (c, d) ∈ 𝓢 β → 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_space (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 [preimage], 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_space β] {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 /-- The maximal separated quotient of a uniform space `α`. -/ 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_space (separation_quotient α) := by dunfold separation_quotient ; apply_instance instance [inhabited α] : inhabited (separation_quotient α) := by unfold separation_quotient; apply_instance /-- Factoring functions to a separated space through the separation quotient. -/ def lift [separated_space β] (f : α → β) : (separation_quotient α → β) := if h : uniform_continuous f then quotient.lift f (λ x y, eq_of_separated_of_uniform_continuous h) else λ x, f (nonempty.some ⟨x.out⟩) lemma lift_mk [separated_space β] {f : α → β} (h : uniform_continuous f) (a : α) : lift f ⟦a⟧ = f a := by rw [lift, dif_pos h]; refl lemma uniform_continuous_lift [separated_space β] (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 /-- The separation quotient functor acting on functions. -/ 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 (uniform_continuous_quotient_mk.comp h)] 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 (hg.comp hf) $ 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_β⟩, rfl⟩, 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_α key_α, h_β key_β⟩ }, end instance separated.prod [separated_space α] [separated_space β] : separated_space (α × β) := 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
3a8a14f0c04303d04eff8fb5e56754578ce544fd
4f643cce24b2d005aeeb5004c2316a8d6cc7f3b1
/src/for_mathlib/nat.lean
90c5899d4e44c17925290012a45fe35e5f6f346f
[]
no_license
rwbarton/lean-omin
da209ed061d64db65a8f7f71f198064986f30eb9
fd733c6d95ef6f4743aae97de5e15df79877c00e
refs/heads/master
1,674,408,673,325
1,607,343,535,000
1,607,343,535,000
285,150,399
9
0
null
null
null
null
UTF-8
Lean
false
false
234
lean
/-- Recursor for `nat` that uses `n+1` rather than `n.succ` in the inductive step. -/ @[elab_as_eliminator] def nat.rec_plus_one {C : ℕ → Sort*} (h₁ : C 0) (h₂ : Π (n : ℕ), C n → C (n+1)) : Π n, C n := nat.rec h₁ h₂
210f51545f3005fc6fccd815a4e6653d219f907d
f618aea02cb4104ad34ecf3b9713065cc0d06103
/src/group_theory/sylow.lean
5edfe94ce2f4012f11d3d2ec495cf84c432ad553
[ "Apache-2.0" ]
permissive
joehendrix/mathlib
84b6603f6be88a7e4d62f5b1b0cbb523bb82b9a5
c15eab34ad754f9ecd738525cb8b5a870e834ddc
refs/heads/master
1,589,606,591,630
1,555,946,393,000
1,555,946,393,000
182,813,854
0
0
null
1,555,946,309,000
1,555,946,308,000
null
UTF-8
Lean
false
false
11,459
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 group_theory.group_action group_theory.quotient_group import group_theory.order_of_element data.zmod.basic algebra.pi_instances local attribute [instance, priority 0] nat.cast_coe open equiv fintype finset mul_action function open equiv.perm is_subgroup list quotient_group universes u v w variables {G : Type u} {α : Type v} {β : Type w} [group G] local attribute [instance, priority 0] subtype.fintype set_fintype classical.prop_decidable namespace mul_action variables [mul_action G α] lemma mem_fixed_points_iff_card_orbit_eq_one {a : α} [fintype (orbit G a)] : a ∈ fixed_points G α ↔ card (orbit G a) = 1 := begin rw [fintype.card_eq_one_iff, mem_fixed_points], split, { exact λ h, ⟨⟨a, mem_orbit_self _⟩, λ ⟨b, ⟨x, hx⟩⟩, subtype.eq $ by simp [h x, hx.symm]⟩ }, { assume h x, rcases h with ⟨⟨z, hz⟩, hz₁⟩, exact calc x • a = z : subtype.mk.inj (hz₁ ⟨x • a, mem_orbit _ _⟩) ... = a : (subtype.mk.inj (hz₁ ⟨a, mem_orbit_self _⟩)).symm } end lemma card_modeq_card_fixed_points [fintype α] [fintype G] [fintype (fixed_points G α)] {p n : ℕ} (hp : nat.prime p) (h : card G = p ^ n) : card α ≡ card (fixed_points G α) [MOD p] := calc card α = card (Σ y : quotient (orbit_rel G α), {x // quotient.mk' x = y}) : card_congr (equiv_fib (@quotient.mk' _ (orbit_rel G α))) ... = univ.sum (λ a : quotient (orbit_rel G α), card {x // quotient.mk' x = a}) : card_sigma _ ... ≡ (@univ (fixed_points G α) _).sum (λ _, 1) [MOD p] : begin rw [← zmodp.eq_iff_modeq_nat hp, sum_nat_cast, sum_nat_cast], refine eq.symm (sum_bij_ne_zero (λ a _ _, quotient.mk' a.1) (λ _ _ _, mem_univ _) (λ a₁ a₂ _ _ _ _ h, subtype.eq ((mem_fixed_points' α).1 a₂.2 a₁.1 (quotient.exact' h))) (λ b, _) (λ a ha _, by rw [← mem_fixed_points_iff_card_orbit_eq_one.1 a.2]; simp only [quotient.eq']; congr)), { refine quotient.induction_on' b (λ b _ hb, _), have : card (orbit G b) ∣ p ^ n, { rw [← h, fintype.card_congr (orbit_equiv_quotient_stabilizer G b)]; exact card_quotient_dvd_card _ }, rcases (nat.dvd_prime_pow hp).1 this with ⟨k, _, hk⟩, have hb' :¬ p ^ 1 ∣ p ^ k, { rw [nat.pow_one, ← hk, ← nat.modeq.modeq_zero_iff, ← zmodp.eq_iff_modeq_nat hp, nat.cast_zero, ← ne.def], exact eq.mpr (by simp only [quotient.eq']; congr) hb }, have : k = 0 := nat.le_zero_iff.1 (nat.le_of_lt_succ (lt_of_not_ge (mt (nat.pow_dvd_pow p) hb'))), refine ⟨⟨b, mem_fixed_points_iff_card_orbit_eq_one.2 $ by rw [hk, this, nat.pow_zero]⟩, mem_univ _, by simp [zero_ne_one], rfl⟩ } end ... = _ : by simp; refl end mul_action lemma quotient_group.card_preimage_mk [fintype G] (s : set G) [is_subgroup s] (t : set (quotient s)) : fintype.card (quotient_group.mk ⁻¹' t) = fintype.card s * fintype.card t := by rw [← fintype.card_prod, fintype.card_congr (preimage_mk_equiv_subgroup_times_set _ _)] namespace sylow def mk_vector_prod_eq_one (n : ℕ) (v : vector G n) : vector G (n+1) := v.to_list.prod⁻¹ :: v lemma mk_vector_prod_eq_one_inj (n : ℕ) : injective (@mk_vector_prod_eq_one G _ n) := λ ⟨v, _⟩ ⟨w, _⟩ h, subtype.eq (show v = w, by injection h with h; injection h) def vectors_prod_eq_one (G : Type*) [group G] (n : ℕ) : set (vector G n) := {v | v.to_list.prod = 1} lemma mem_vectors_prod_eq_one {n : ℕ} (v : vector G n) : v ∈ vectors_prod_eq_one G n ↔ v.to_list.prod = 1 := iff.rfl lemma mem_vectors_prod_eq_one_iff {n : ℕ} (v : vector G (n + 1)) : v ∈ vectors_prod_eq_one G (n + 1) ↔ v ∈ set.range (@mk_vector_prod_eq_one G _ n) := ⟨λ (h : v.to_list.prod = 1), ⟨v.tail, begin unfold mk_vector_prod_eq_one, conv {to_rhs, rw ← vector.cons_head_tail v}, suffices : (v.tail.to_list.prod)⁻¹ = v.head, { rw this }, rw [← mul_right_inj v.tail.to_list.prod, inv_mul_self, ← list.prod_cons, ← vector.to_list_cons, vector.cons_head_tail, h] end⟩, λ ⟨w, hw⟩, by rw [mem_vectors_prod_eq_one, ← hw, mk_vector_prod_eq_one, vector.to_list_cons, list.prod_cons, inv_mul_self]⟩ def rotate_vectors_prod_eq_one (G : Type*) [group G] (n : ℕ+) (m : multiplicative (zmod n)) (v : vectors_prod_eq_one G n) : vectors_prod_eq_one G n := ⟨⟨v.1.to_list.rotate m.1, by simp⟩, prod_rotate_eq_one_of_prod_eq_one v.2 _⟩ instance rotate_vectors_prod_eq_one.mul_action (n : ℕ+) : mul_action (multiplicative (zmod n)) (vectors_prod_eq_one G n) := { smul := (rotate_vectors_prod_eq_one G n), one_smul := λ v, subtype.eq $ vector.eq _ _ $ rotate_zero v.1.to_list, mul_smul := λ a b ⟨⟨v, hv₁⟩, hv₂⟩, subtype.eq $ vector.eq _ _ $ show v.rotate ((a + b : zmod n).val) = list.rotate (list.rotate v (b.val)) (a.val), by rw [zmod.add_val, rotate_rotate, ← rotate_mod _ (b.1 + a.1), add_comm, hv₁] } lemma one_mem_vectors_prod_eq_one (n : ℕ) : vector.repeat (1 : G) n ∈ vectors_prod_eq_one G n := by simp [vector.repeat, vectors_prod_eq_one] lemma one_mem_fixed_points_rotate (n : ℕ+) : (⟨vector.repeat (1 : G) n, one_mem_vectors_prod_eq_one n⟩ : vectors_prod_eq_one G n) ∈ fixed_points (multiplicative (zmod n)) (vectors_prod_eq_one G n) := λ m, subtype.eq $ vector.eq _ _ $ by haveI : nonempty G := ⟨1⟩; exact rotate_eq_self_iff_eq_repeat.2 ⟨(1 : G), show list.repeat (1 : G) n = list.repeat 1 (list.repeat (1 : G) n).length, by simp⟩ _ /-- Cauchy's theorem -/ lemma exists_prime_order_of_dvd_card [fintype G] {p : ℕ} (hp : nat.prime p) (hdvd : p ∣ card G) : ∃ x : G, order_of x = p := let n : ℕ+ := ⟨p - 1, nat.sub_pos_of_lt hp.gt_one⟩ in let p' : ℕ+ := ⟨p, hp.pos⟩ in have hn : p' = n + 1 := subtype.eq (nat.succ_sub hp.pos), have hcard : card (vectors_prod_eq_one G (n + 1)) = card G ^ (n : ℕ), by rw [set.ext mem_vectors_prod_eq_one_iff, set.card_range_of_injective (mk_vector_prod_eq_one_inj _), card_vector], have hzmod : fintype.card (multiplicative (zmod p')) = (p' : ℕ) ^ 1 := (nat.pow_one p').symm ▸ card_fin _, have hmodeq : _ = _ := @mul_action.card_modeq_card_fixed_points (multiplicative (zmod p')) (vectors_prod_eq_one G p') _ _ _ _ _ _ 1 hp hzmod, have hdvdcard : p ∣ fintype.card (vectors_prod_eq_one G (n + 1)) := calc p ∣ card G ^ 1 : by rwa nat.pow_one ... ∣ card G ^ (n : ℕ) : nat.pow_dvd_pow _ n.2 ... = card (vectors_prod_eq_one G (n + 1)) : hcard.symm, have hdvdcard₂ : p ∣ card (fixed_points (multiplicative (zmod p')) (vectors_prod_eq_one G p')) := nat.dvd_of_mod_eq_zero (hmodeq ▸ hn.symm ▸ nat.mod_eq_zero_of_dvd hdvdcard), have hcard_pos : 0 < card (fixed_points (multiplicative (zmod p')) (vectors_prod_eq_one G p')) := fintype.card_pos_iff.2 ⟨⟨⟨vector.repeat 1 p', one_mem_vectors_prod_eq_one _⟩, one_mem_fixed_points_rotate _⟩⟩, have hlt : 1 < card (fixed_points (multiplicative (zmod p')) (vectors_prod_eq_one G p')) := calc (1 : ℕ) < p' : hp.gt_one ... ≤ _ : nat.le_of_dvd hcard_pos hdvdcard₂, let ⟨⟨⟨⟨x, hx₁⟩, hx₂⟩, hx₃⟩, hx₄⟩ := fintype.exists_ne_of_card_gt_one hlt ⟨_, one_mem_fixed_points_rotate p'⟩ in have hx : x ≠ list.repeat (1 : G) p', from λ h, by simpa [h, vector.repeat] using hx₄, have nG : nonempty G, from ⟨1⟩, have ∃ a, x = list.repeat a x.length := by exactI rotate_eq_self_iff_eq_repeat.1 (λ n, have list.rotate x (n : zmod p').val = x := subtype.mk.inj (subtype.mk.inj (hx₃ (n : zmod p'))), by rwa [zmod.val_cast_nat, ← hx₁, rotate_mod] at this), let ⟨a, ha⟩ := this in ⟨a, have hx1 : x.prod = 1 := hx₂, have ha1: a ≠ 1, from λ h, hx (ha.symm ▸ h ▸ hx₁ ▸ rfl), have a ^ p = 1, by rwa [ha, list.prod_repeat, hx₁] at hx1, (hp.2 _ (order_of_dvd_of_pow_eq_one this)).resolve_left (λ h, ha1 (order_of_eq_one_iff.1 h))⟩ open is_subgroup is_submonoid is_group_hom mul_action lemma mem_fixed_points_mul_left_cosets_iff_mem_normalizer {H : set G} [is_subgroup H] [fintype H] {x : G} : (x : quotient H) ∈ fixed_points H (quotient H) ↔ x ∈ normalizer H := ⟨λ hx, have ha : ∀ {y : quotient H}, y ∈ orbit H (x : quotient H) → y = x, from λ _, ((mem_fixed_points' _).1 hx _), (inv_mem_iff _).1 (mem_normalizer_fintype (λ n hn, have (n⁻¹ * x)⁻¹ * x ∈ H := quotient_group.eq.1 (ha (mem_orbit _ ⟨n⁻¹, inv_mem hn⟩)), by simpa only [mul_inv_rev, inv_inv] using this)), λ (hx : ∀ (n : G), n ∈ H ↔ x * n * x⁻¹ ∈ H), (mem_fixed_points' _).2 $ λ y, quotient.induction_on' y $ λ y hy, quotient_group.eq.2 (let ⟨⟨b, hb₁⟩, hb₂⟩ := hy in have hb₂ : (b * x)⁻¹ * y ∈ H := quotient_group.eq.1 hb₂, (inv_mem_iff H).1 $ (hx _).2 $ (mul_mem_cancel_right H (inv_mem hb₁)).1 $ by rw hx at hb₂; simpa [mul_inv_rev, mul_assoc] using hb₂)⟩ lemma fixed_points_mul_left_cosets_equiv_quotient (H : set G) [is_subgroup H] [fintype H] : fixed_points H (quotient H) ≃ quotient (subtype.val ⁻¹' H : set (normalizer H)) := @subtype_quotient_equiv_quotient_subtype G (normalizer H) (id _) (id _) (fixed_points _ _) (λ a, mem_fixed_points_mul_left_cosets_iff_mem_normalizer.symm) (by intros; refl) local attribute [instance] set_fintype lemma exists_subgroup_card_pow_prime [fintype G] {p : ℕ} : ∀ {n : ℕ} (hp : nat.prime p) (hdvd : p ^ n ∣ card G), ∃ H : set G, is_subgroup H ∧ fintype.card H = p ^ n | 0 := λ _ _, ⟨trivial G, by apply_instance, by simp⟩ | (n+1) := λ hp hdvd, let ⟨H, ⟨hH1, hH2⟩⟩ := exists_subgroup_card_pow_prime hp (dvd.trans (nat.pow_dvd_pow _ (nat.le_succ _)) hdvd) in let ⟨s, hs⟩ := exists_eq_mul_left_of_dvd hdvd in by exactI have hcard : card (quotient H) = s * p := (nat.mul_right_inj (show card H > 0, from fintype.card_pos_iff.2 ⟨⟨1, is_submonoid.one_mem H⟩⟩)).1 (by rwa [← card_eq_card_quotient_mul_card_subgroup, hH2, hs, nat.pow_succ, mul_assoc, mul_comm p]), have hm : s * p % p = card (quotient (subtype.val ⁻¹' H : set (normalizer H))) % p := card_congr (fixed_points_mul_left_cosets_equiv_quotient H) ▸ hcard ▸ card_modeq_card_fixed_points hp hH2, have hm' : p ∣ card (quotient (subtype.val ⁻¹' H : set (normalizer H))) := nat.dvd_of_mod_eq_zero (by rwa [nat.mod_eq_zero_of_dvd (dvd_mul_left _ _), eq_comm] at hm), let ⟨x, hx⟩ := @exists_prime_order_of_dvd_card _ (quotient_group.group _) _ _ hp hm' in have hxcard : ∀ {f : fintype (gpowers x)}, card (gpowers x) = p, from λ f, by rw [← hx, order_eq_card_gpowers]; congr, have is_subgroup (mk ⁻¹' gpowers x), from is_group_hom.preimage _ _, have fintype (mk ⁻¹' gpowers x), by apply_instance, have hequiv : H ≃ (subtype.val ⁻¹' H : set (normalizer H)):= ⟨λ a, ⟨⟨a.1, subset_normalizer _ a.2⟩, a.2⟩, λ a, ⟨a.1.1, a.2⟩, λ ⟨_, _⟩, rfl, λ ⟨⟨_, _⟩, _⟩, rfl⟩, ⟨subtype.val '' (mk ⁻¹' gpowers x), by apply_instance, by rw [set.card_image_of_injective (mk ⁻¹' gpowers x) subtype.val_injective, nat.pow_succ, ← hH2, fintype.card_congr hequiv, ← hx, order_eq_card_gpowers, ← fintype.card_prod]; exact @fintype.card_congr _ _ (id _) (id _) (preimage_mk_equiv_subgroup_times_set _ _)⟩ end sylow
32dfecf0d18f78ef1f4c70f9d42a746bd22fd134
b70031c8e2c5337b91d7e70f1e0c5f528f7b0e77
/archive/imo/imo1998_q2.lean
3a4366011ac2d7a9db581a475b0385ebbdea2435
[ "Apache-2.0" ]
permissive
molodiuc/mathlib
cae2ba3ef1601c1f42ca0b625c79b061b63fef5b
98ebe5a6739fbe254f9ee9d401882d4388f91035
refs/heads/master
1,674,237,127,059
1,606,353,533,000
1,606,353,533,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
9,719
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 data.fintype.basic import data.int.parity import algebra.big_operators.order import tactic.ring import tactic.noncomm_ring /-! # IMO 1998 Q2 In a competition, there are `a` contestants and `b` judges, where `b ≥ 3` is an odd integer. Each judge rates each contestant as either "pass" or "fail". Suppose `k` is a number such that, for any two judges, their ratings coincide for at most `k` contestants. Prove that `k / a ≥ (b - 1) / (2b)`. ## Solution The problem asks us to think about triples consisting of a contestant and two judges whose ratings agree for that contestant. We thus consider the subset `A ⊆ C × JJ` of all such incidences of agreement, where `C` and `J` are the sets of contestants and judges, and `JJ = J × J − {(j, j)}`. We have natural maps: `left : A → C` and `right: A → JJ`. We count the elements of `A` in two ways: as the sum of the cardinalities of the fibres of `left` and as the sum of the cardinalities of the fibres of `right`. We obtain an upper bound on the cardinality of `A` from the count for `right`, and a lower bound from the count for `left`. These two bounds combine to the required result. First consider the map `right : A → JJ`. Since the size of any fibre over a point in JJ is bounded by `k` and since `|JJ| = b^2 - b`, we obtain the upper bound: `|A| ≤ k(b^2−b)`. Now consider the map `left : A → C`. The fibre over a given contestant `c ∈ C` is the set of ordered pairs of (distinct) judges who agree about `c`. We seek to bound the cardinality of this fibre from below. Minimum agreement for a contestant occurs when the judges' ratings are split as evenly as possible. Since `b` is odd, this occurs when they are divided into groups of size `(b−1)/2` and `(b+1)/2`. This corresponds to a fibre of cardinality `(b-1)^2/2` and so we obtain the lower bound: `a(b-1)^2/2 ≤ |A|`. Rearranging gives the result. -/ open_locale classical noncomputable theory /-- An ordered pair of judges. -/ abbreviation judge_pair (J : Type*) := J × J /-- A triple consisting of contestant together with an ordered pair of judges. -/ abbreviation agreed_triple (C J : Type*) := C × (judge_pair J) variables {C J : Type*} (r : C → J → Prop) /-- The first judge from an ordered pair of judges. -/ abbreviation judge_pair.judge₁ : judge_pair J → J := prod.fst /-- The second judge from an ordered pair of judges. -/ abbreviation judge_pair.judge₂ : judge_pair J → J := prod.snd /-- The proposition that the judges in an ordered pair are distinct. -/ abbreviation judge_pair.distinct (p : judge_pair J) := p.judge₁ ≠ p.judge₂ /-- The proposition that the judges in an ordered pair agree about a contestant's rating. -/ abbreviation judge_pair.agree (p : judge_pair J) (c : C) := r c p.judge₁ ↔ r c p.judge₂ /-- The contestant from the triple consisting of a contestant and an ordered pair of judges. -/ abbreviation agreed_triple.contestant : agreed_triple C J → C := prod.fst /-- The ordered pair of judges from the triple consisting of a contestant and an ordered pair of judges. -/ abbreviation agreed_triple.judge_pair : agreed_triple C J → judge_pair J := prod.snd @[simp] lemma judge_pair.agree_iff_same_rating (p : judge_pair J) (c : C) : p.agree r c ↔ (r c p.judge₁ ↔ r c p.judge₂) := iff.rfl /-- The set of contestants on which two judges agree. -/ def agreed_contestants [fintype C] (p : judge_pair J) : finset C := finset.univ.filter (λ c, p.agree r c) section variables [fintype J] [fintype C] /-- All incidences of agreement. -/ def A : finset (agreed_triple C J) := finset.univ.filter (λ (a : agreed_triple C J), a.judge_pair.agree r a.contestant ∧ a.judge_pair.distinct) lemma A_maps_to_off_diag_judge_pair (a : agreed_triple C J) : a ∈ A r → a.judge_pair ∈ finset.off_diag (@finset.univ J _) := by simp [A, finset.mem_off_diag] lemma A_fibre_over_contestant (c : C) : finset.univ.filter (λ (p : judge_pair J), p.agree r c ∧ p.distinct) = ((A r).filter (λ (a : agreed_triple C J), a.contestant = c)).image prod.snd := begin ext p, simp only [A, finset.mem_univ, finset.mem_filter, finset.mem_image, true_and, exists_prop], split, { rintros ⟨h₁, h₂⟩, refine ⟨(c, p), _⟩, finish, }, { intros h, finish, }, end lemma A_fibre_over_contestant_card (c : C) : (finset.univ.filter (λ (p : judge_pair J), p.agree r c ∧ p.distinct)).card = ((A r).filter (λ (a : agreed_triple C J), a.contestant = c)).card := by { rw A_fibre_over_contestant r, apply finset.card_image_of_inj_on, tidy, } lemma A_fibre_over_judge_pair {p : judge_pair J} (h : p.distinct) : agreed_contestants r p = ((A r).filter(λ (a : agreed_triple C J), a.judge_pair = p)).image agreed_triple.contestant := begin dunfold A agreed_contestants, ext c, split; intros h, { rw finset.mem_image, refine ⟨⟨c, p⟩, _⟩, finish, }, { finish, }, end lemma A_fibre_over_judge_pair_card {p : judge_pair J} (h : p.distinct) : (agreed_contestants r p).card = ((A r).filter(λ (a : agreed_triple C J), a.judge_pair = p)).card := by { rw A_fibre_over_judge_pair r h, apply finset.card_image_of_inj_on, tidy, } lemma A_card_upper_bound {k : ℕ} (hk : ∀ (p : judge_pair J), p.distinct → (agreed_contestants r p).card ≤ k) : (A r).card ≤ k * ((fintype.card J) * (fintype.card J) - (fintype.card J)) := begin change _ ≤ k * ((finset.card _ ) * (finset.card _ ) - (finset.card _ )), rw ← finset.off_diag_card, apply finset.card_le_mul_card_image_of_maps_to (A_maps_to_off_diag_judge_pair r), intros p hp, have hp' : p.distinct, { simp [finset.mem_off_diag] at hp, exact hp, }, rw ← A_fibre_over_judge_pair_card r hp', apply hk, exact hp', end end lemma add_sq_add_sq_sub {α : Type*} [ring α] (x y : α) : (x + y) * (x + y) + (x - y) * (x - y) = 2*x*x + 2*y*y := by noncomm_ring lemma norm_bound_of_odd_sum {x y z : ℤ} (h : x + y = 2*z + 1) : 2*z*z + 2*z + 1 ≤ x*x + y*y := begin suffices : 4*z*z + 4*z + 1 + 1 ≤ 2*x*x + 2*y*y, { rw ← mul_le_mul_left (@zero_lt_two _ _ int.nontrivial), convert this; ring, }, have h' : (x + y) * (x + y) = 4*z*z + 4*z + 1, { rw h, ring, }, rw [← add_sq_add_sq_sub, h', add_le_add_iff_left], suffices : 0 < (x - y) * (x - y), { apply int.add_one_le_of_lt this, }, apply mul_self_pos, rw sub_ne_zero, apply int.ne_of_odd_sum ⟨z, h⟩, end section variables [fintype J] lemma judge_pairs_card_lower_bound {z : ℕ} (hJ : fintype.card J = 2*z + 1) (c : C) : 2*z*z + 2*z + 1 ≤ (finset.univ.filter (λ (p : judge_pair J), p.agree r c)).card := begin let x := (finset.univ.filter (λ j, r c j)).card, let y := (finset.univ.filter (λ j, ¬ r c j)).card, have h : (finset.univ.filter (λ (p : judge_pair J), p.agree r c)).card = x*x + y*y, { simp [← finset.filter_product_card], }, rw h, apply int.le_of_coe_nat_le_coe_nat, simp only [int.coe_nat_add, int.coe_nat_mul], apply norm_bound_of_odd_sum, suffices : x + y = 2*z + 1, { simp [← int.coe_nat_add, this], }, rw [finset.filter_card_add_filter_neg_card_eq_card, ← hJ], refl, end lemma distinct_judge_pairs_card_lower_bound {z : ℕ} (hJ : fintype.card J = 2*z + 1) (c : C) : 2*z*z ≤ (finset.univ.filter (λ (p : judge_pair J), p.agree r c ∧ p.distinct)).card := begin let s := finset.univ.filter (λ (p : judge_pair J), p.agree r c), let t := finset.univ.filter (λ (p : judge_pair J), p.distinct), have hs : 2*z*z + 2*z + 1 ≤ s.card, { exact judge_pairs_card_lower_bound r hJ c, }, have hst : s \ t = finset.univ.diag, { ext p, split; intros, { finish, }, { suffices : p.judge₁ = p.judge₂, { simp [this], }, finish, }, }, have hst' : (s \ t).card = 2*z + 1, { rw [hst, finset.diag_card, ← hJ], refl, }, rw [finset.filter_and, ← finset.sdiff_sdiff_self_left s t, finset.card_sdiff], { rw hst', rw add_assoc at hs, apply nat.le_sub_right_of_add_le hs, }, { apply finset.sdiff_subset_self, }, end lemma A_card_lower_bound [fintype C] {z : ℕ} (hJ : fintype.card J = 2*z + 1) : 2*z*z * (fintype.card C) ≤ (A r).card := begin have h : ∀ a, a ∈ A r → prod.fst a ∈ @finset.univ C _, { intros, apply finset.mem_univ, }, apply finset.mul_card_image_le_card_of_maps_to h, intros c hc, rw ← A_fibre_over_contestant_card, apply distinct_judge_pairs_card_lower_bound r hJ, end end local notation x `/` y := (x : ℚ) / y lemma clear_denominators {a b k : ℕ} (ha : 0 < a) (hb : 0 < b) : (b - 1) / (2 * b) ≤ k / a ↔ (b - 1) * a ≤ k * (2 * b) := begin rw div_le_div_iff, { convert nat.cast_le; finish, }, { simp only [hb, zero_lt_mul_right, zero_lt_bit0, nat.cast_pos, zero_lt_one], }, { simp only [ha, nat.cast_pos], }, end theorem imo1998_q2 [fintype J] [fintype C] (a b k : ℕ) (hC : fintype.card C = a) (hJ : fintype.card J = b) (ha : 0 < a) (hb : odd b) (hk : ∀ (p : judge_pair J), p.distinct → (agreed_contestants r p).card ≤ k) : (b - 1) / (2 * b) ≤ k / a := begin rw clear_denominators ha (nat.odd_gt_zero hb), obtain ⟨z, hz⟩ := hb, rw hz at hJ, rw hz, have h := le_trans (A_card_lower_bound r hJ) (A_card_upper_bound r hk), rw [hC, hJ] at h, -- We are now essentially done; we just need to bash `h` into exactly the right shape. have hl : k * ((2 * z + 1) * (2 * z + 1) - (2 * z + 1)) = (k * (2 * (2 * z + 1))) * z, { simp only [add_mul, two_mul, mul_comm, mul_assoc], finish, }, have hr : 2 * z * z * a = 2 * z * a * z, { ring, }, rw [hl, hr] at h, cases z, { simp, }, { exact le_of_mul_le_mul_right h z.succ_pos, }, end
1312ab8e8f9dcc07e9843a871e24fa33483cc98a
4727251e0cd73359b15b664c3170e5d754078599
/src/algebra/order/archimedean.lean
3a307b1cb228101fbe255af4e9cc2bfdeff9691b
[ "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
15,813
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import algebra.field_power import data.int.least_greatest import data.rat.floor /-! # Archimedean groups and fields. This file defines the archimedean property for ordered groups and proves several results connected to this notion. Being archimedean means that for all elements `x` and `y>0` there exists a natural number `n` such that `x ≤ n • y`. ## Main definitions * `archimedean` is a typeclass for an ordered additive commutative monoid to have the archimedean property. * `archimedean.floor_ring` defines a floor function on an archimedean linearly ordered ring making it into a `floor_ring`. * `round` defines a function rounding to the nearest integer for a linearly ordered field which is also a floor ring. ## Main statements * `ℕ`, `ℤ`, and `ℚ` are archimedean. -/ open int set variables {α : Type*} /-- An ordered additive commutative monoid is called `archimedean` if for any two elements `x`, `y` such that `0 < y` there exists a natural number `n` such that `x ≤ n • y`. -/ class archimedean (α) [ordered_add_comm_monoid α] : Prop := (arch : ∀ (x : α) {y}, 0 < y → ∃ n : ℕ, x ≤ n • y) instance order_dual.archimedean [ordered_add_comm_group α] [archimedean α] : archimedean αᵒᵈ := ⟨λ x y hy, let ⟨n, hn⟩ := archimedean.arch (-x : α) (neg_pos.2 hy) in ⟨n, by rwa [neg_nsmul, neg_le_neg_iff] at hn⟩⟩ section linear_ordered_add_comm_group variables [linear_ordered_add_comm_group α] [archimedean α] /-- An archimedean decidable linearly ordered `add_comm_group` has a version of the floor: for `a > 0`, any `g` in the group lies between some two consecutive multiples of `a`. -/ lemma exists_unique_zsmul_near_of_pos {a : α} (ha : 0 < a) (g : α) : ∃! k : ℤ, k • a ≤ g ∧ g < (k + 1) • a := begin let s : set ℤ := {n : ℤ | n • a ≤ g}, obtain ⟨k, hk : -g ≤ k • a⟩ := archimedean.arch (-g) ha, have h_ne : s.nonempty := ⟨-k, by simpa using neg_le_neg hk⟩, obtain ⟨k, hk⟩ := archimedean.arch g ha, have h_bdd : ∀ n ∈ s, n ≤ (k : ℤ), { assume n hn, apply (zsmul_le_zsmul_iff ha).mp, rw ← coe_nat_zsmul at hk, exact le_trans hn hk }, obtain ⟨m, hm, hm'⟩ := int.exists_greatest_of_bdd ⟨k, h_bdd⟩ h_ne, have hm'' : g < (m + 1) • a, { contrapose! hm', exact ⟨m + 1, hm', lt_add_one _⟩, }, refine ⟨m, ⟨hm, hm''⟩, λ n hn, (hm' n hn.1).antisymm $ int.le_of_lt_add_one _⟩, rw ← zsmul_lt_zsmul_iff ha, exact lt_of_le_of_lt hm hn.2 end lemma exists_unique_zsmul_near_of_pos' {a : α} (ha : 0 < a) (g : α) : ∃! k : ℤ, 0 ≤ g - k • a ∧ g - k • a < a := by simpa only [sub_nonneg, add_zsmul, one_zsmul, sub_lt_iff_lt_add'] using exists_unique_zsmul_near_of_pos ha g lemma exists_unique_add_zsmul_mem_Ico {a : α} (ha : 0 < a) (b c : α) : ∃! m : ℤ, b + m • a ∈ set.Ico c (c + a) := (equiv.neg ℤ).bijective.exists_unique_iff.2 $ by simpa only [equiv.neg_apply, mem_Ico, neg_zsmul, ← sub_eq_add_neg, le_sub_iff_add_le, zero_add, add_comm c, sub_lt_iff_lt_add', add_assoc] using exists_unique_zsmul_near_of_pos' ha (b - c) lemma exists_unique_add_zsmul_mem_Ioc {a : α} (ha : 0 < a) (b c : α) : ∃! m : ℤ, b + m • a ∈ set.Ioc c (c + a) := (equiv.add_right (1 : ℤ)).bijective.exists_unique_iff.2 $ by simpa only [add_zsmul, sub_lt_iff_lt_add', le_sub_iff_add_le', ← add_assoc, and.comm, mem_Ioc, equiv.coe_add_right, one_zsmul, add_le_add_iff_right] using exists_unique_zsmul_near_of_pos ha (c - b) end linear_ordered_add_comm_group theorem exists_nat_gt [ordered_semiring α] [nontrivial α] [archimedean α] (x : α) : ∃ n : ℕ, x < n := let ⟨n, h⟩ := archimedean.arch x zero_lt_one in ⟨n+1, lt_of_le_of_lt (by rwa ← nsmul_one) (nat.cast_lt.2 (nat.lt_succ_self _))⟩ theorem exists_nat_ge [ordered_semiring α] [archimedean α] (x : α) : ∃ n : ℕ, x ≤ n := begin nontriviality α, exact (exists_nat_gt x).imp (λ n, le_of_lt) end lemma add_one_pow_unbounded_of_pos [ordered_semiring α] [nontrivial α] [archimedean α] (x : α) {y : α} (hy : 0 < y) : ∃ n : ℕ, x < (y + 1) ^ n := have 0 ≤ 1 + y, from add_nonneg zero_le_one hy.le, let ⟨n, h⟩ := archimedean.arch x hy in ⟨n, calc x ≤ n • y : h ... = n * y : nsmul_eq_mul _ _ ... < 1 + n * y : lt_one_add _ ... ≤ (1 + y) ^ n : one_add_mul_le_pow' (mul_nonneg hy.le hy.le) (mul_nonneg this this) (add_nonneg zero_le_two hy.le) _ ... = (y + 1) ^ n : by rw [add_comm]⟩ section linear_ordered_ring variables [linear_ordered_ring α] [archimedean α] lemma pow_unbounded_of_one_lt (x : α) {y : α} (hy1 : 1 < y) : ∃ n : ℕ, x < y ^ n := sub_add_cancel y 1 ▸ add_one_pow_unbounded_of_pos _ (sub_pos.2 hy1) /-- Every x greater than or equal to 1 is between two successive natural-number powers of every y greater than one. -/ lemma exists_nat_pow_near {x : α} {y : α} (hx : 1 ≤ x) (hy : 1 < y) : ∃ n : ℕ, y ^ n ≤ x ∧ x < y ^ (n + 1) := have h : ∃ n : ℕ, x < y ^ n, from pow_unbounded_of_one_lt _ hy, by classical; exact let n := nat.find h in have hn : x < y ^ n, from nat.find_spec h, have hnp : 0 < n, from pos_iff_ne_zero.2 (λ hn0, by rw [hn0, pow_zero] at hn; exact (not_le_of_gt hn hx)), have hnsp : nat.pred n + 1 = n, from nat.succ_pred_eq_of_pos hnp, have hltn : nat.pred n < n, from nat.pred_lt (ne_of_gt hnp), ⟨nat.pred n, le_of_not_lt (nat.find_min h hltn), by rwa hnsp⟩ theorem exists_int_gt (x : α) : ∃ n : ℤ, x < n := let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa ← coe_coe⟩ theorem exists_int_lt (x : α) : ∃ n : ℤ, (n : α) < x := let ⟨n, h⟩ := exists_int_gt (-x) in ⟨-n, by rw int.cast_neg; exact neg_lt.1 h⟩ theorem exists_floor (x : α) : ∃ (fl : ℤ), ∀ (z : ℤ), z ≤ fl ↔ (z : α) ≤ x := begin haveI := classical.prop_decidable, have : ∃ (ub : ℤ), (ub:α) ≤ x ∧ ∀ (z : ℤ), (z:α) ≤ x → z ≤ ub := int.exists_greatest_of_bdd (let ⟨n, hn⟩ := exists_int_gt x in ⟨n, λ z h', int.cast_le.1 $ le_trans h' $ le_of_lt hn⟩) (let ⟨n, hn⟩ := exists_int_lt x in ⟨n, le_of_lt hn⟩), refine this.imp (λ fl h z, _), cases h with h₁ h₂, exact ⟨λ h, le_trans (int.cast_le.2 h) h₁, h₂ z⟩, end end linear_ordered_ring section linear_ordered_field variables [linear_ordered_field α] /-- Every positive `x` is between two successive integer powers of another `y` greater than one. This is the same as `exists_mem_Ioc_zpow`, but with ≤ and < the other way around. -/ lemma exists_mem_Ico_zpow [archimedean α] {x : α} {y : α} (hx : 0 < x) (hy : 1 < y) : ∃ n : ℤ, x ∈ set.Ico (y ^ n) (y ^ (n + 1)) := by classical; exact let ⟨N, hN⟩ := pow_unbounded_of_one_lt x⁻¹ hy in have he: ∃ m : ℤ, y ^ m ≤ x, from ⟨-N, le_of_lt (by { rw [zpow_neg₀ y (↑N), zpow_coe_nat], exact (inv_lt hx (lt_trans (inv_pos.2 hx) hN)).1 hN })⟩, let ⟨M, hM⟩ := pow_unbounded_of_one_lt x hy in have hb: ∃ b : ℤ, ∀ m, y ^ m ≤ x → m ≤ b, from ⟨M, λ m hm, le_of_not_lt (λ hlt, not_lt_of_ge (zpow_le_of_le hy.le hlt.le) (lt_of_le_of_lt hm (by rwa ← zpow_coe_nat at hM)))⟩, let ⟨n, hn₁, hn₂⟩ := int.exists_greatest_of_bdd hb he in ⟨n, hn₁, lt_of_not_ge (λ hge, not_le_of_gt (int.lt_succ _) (hn₂ _ hge))⟩ /-- Every positive `x` is between two successive integer powers of another `y` greater than one. This is the same as `exists_mem_Ico_zpow`, but with ≤ and < the other way around. -/ lemma exists_mem_Ioc_zpow [archimedean α] {x : α} {y : α} (hx : 0 < x) (hy : 1 < y) : ∃ n : ℤ, x ∈ set.Ioc (y ^ n) (y ^ (n + 1)) := let ⟨m, hle, hlt⟩ := exists_mem_Ico_zpow (inv_pos.2 hx) hy in have hyp : 0 < y, from lt_trans zero_lt_one hy, ⟨-(m+1), by rwa [zpow_neg₀, inv_lt (zpow_pos_of_pos hyp _) hx], by rwa [neg_add, neg_add_cancel_right, zpow_neg₀, le_inv hx (zpow_pos_of_pos hyp _)]⟩ /-- For any `y < 1` and any positive `x`, there exists `n : ℕ` with `y ^ n < x`. -/ lemma exists_pow_lt_of_lt_one [archimedean α] {x y : α} (hx : 0 < x) (hy : y < 1) : ∃ n : ℕ, y ^ n < x := begin by_cases y_pos : y ≤ 0, { use 1, simp only [pow_one], linarith, }, rw [not_le] at y_pos, rcases pow_unbounded_of_one_lt (x⁻¹) (one_lt_inv y_pos hy) with ⟨q, hq⟩, exact ⟨q, by rwa [inv_pow₀, inv_lt_inv hx (pow_pos y_pos _)] at hq⟩ end /-- Given `x` and `y` between `0` and `1`, `x` is between two successive powers of `y`. This is the same as `exists_nat_pow_near`, but for elements between `0` and `1` -/ lemma exists_nat_pow_near_of_lt_one [archimedean α] {x : α} {y : α} (xpos : 0 < x) (hx : x ≤ 1) (ypos : 0 < y) (hy : y < 1) : ∃ n : ℕ, y ^ (n + 1) < x ∧ x ≤ y ^ n := begin rcases exists_nat_pow_near (one_le_inv_iff.2 ⟨xpos, hx⟩) (one_lt_inv_iff.2 ⟨ypos, hy⟩) with ⟨n, hn, h'n⟩, refine ⟨n, _, _⟩, { rwa [inv_pow₀, inv_lt_inv xpos (pow_pos ypos _)] at h'n }, { rwa [inv_pow₀, inv_le_inv (pow_pos ypos _) xpos] at hn } end variables [floor_ring α] lemma sub_floor_div_mul_nonneg (x : α) {y : α} (hy : 0 < y) : 0 ≤ x - ⌊x / y⌋ * y := begin conv in x {rw ← div_mul_cancel x (ne_of_lt hy).symm}, rw ← sub_mul, exact mul_nonneg (sub_nonneg.2 (floor_le _)) (le_of_lt hy) end lemma sub_floor_div_mul_lt (x : α) {y : α} (hy : 0 < y) : x - ⌊x / y⌋ * y < y := sub_lt_iff_lt_add.2 begin conv in y {rw ← one_mul y}, conv in x {rw ← div_mul_cancel x (ne_of_lt hy).symm}, rw ← add_mul, exact (mul_lt_mul_right hy).2 (by rw add_comm; exact lt_floor_add_one _), end end linear_ordered_field instance : archimedean ℕ := ⟨λ n m m0, ⟨n, by simpa only [mul_one, nat.nsmul_eq_mul] using nat.mul_le_mul_left n m0⟩⟩ instance : archimedean ℤ := ⟨λ n m m0, ⟨n.to_nat, le_trans (int.le_to_nat _) $ by simpa only [nsmul_eq_mul, int.nat_cast_eq_coe_nat, zero_add, mul_one] using mul_le_mul_of_nonneg_left (int.add_one_le_iff.2 m0) (int.coe_zero_le n.to_nat)⟩⟩ /-- A linear ordered archimedean ring is a floor ring. This is not an `instance` because in some cases we have a computable `floor` function. -/ noncomputable def archimedean.floor_ring (α) [linear_ordered_ring α] [archimedean α] : floor_ring α := floor_ring.of_floor α (λ a, classical.some (exists_floor a)) (λ z a, (classical.some_spec (exists_floor a) z).symm) section linear_ordered_field variables [linear_ordered_field α] theorem archimedean_iff_nat_lt : archimedean α ↔ ∀ x : α, ∃ n : ℕ, x < n := ⟨@exists_nat_gt α _ _, λ H, ⟨λ x y y0, (H (x / y)).imp $ λ n h, le_of_lt $ by rwa [div_lt_iff y0, ← nsmul_eq_mul] at h⟩⟩ theorem archimedean_iff_nat_le : archimedean α ↔ ∀ x : α, ∃ n : ℕ, x ≤ n := archimedean_iff_nat_lt.trans ⟨λ H x, (H x).imp $ λ _, le_of_lt, λ H x, let ⟨n, h⟩ := H x in ⟨n+1, lt_of_le_of_lt h (nat.cast_lt.2 (lt_add_one _))⟩⟩ theorem exists_rat_gt [archimedean α] (x : α) : ∃ q : ℚ, x < q := let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa rat.cast_coe_nat⟩ theorem archimedean_iff_rat_lt : archimedean α ↔ ∀ x : α, ∃ q : ℚ, x < q := ⟨@exists_rat_gt α _, λ H, archimedean_iff_nat_lt.2 $ λ x, let ⟨q, h⟩ := H x in ⟨⌈q⌉₊, lt_of_lt_of_le h $ by simpa only [rat.cast_coe_nat] using (@rat.cast_le α _ _ _).2 (nat.le_ceil _)⟩⟩ theorem archimedean_iff_rat_le : archimedean α ↔ ∀ x : α, ∃ q : ℚ, x ≤ q := archimedean_iff_rat_lt.trans ⟨λ H x, (H x).imp $ λ _, le_of_lt, λ H x, let ⟨n, h⟩ := H x in ⟨n+1, lt_of_le_of_lt h (rat.cast_lt.2 (lt_add_one _))⟩⟩ variables [archimedean α] {x y : α} theorem exists_rat_lt (x : α) : ∃ q : ℚ, (q : α) < x := let ⟨n, h⟩ := exists_int_lt x in ⟨n, by rwa rat.cast_coe_int⟩ theorem exists_rat_btwn {x y : α} (h : x < y) : ∃ q : ℚ, x < q ∧ (q:α) < y := begin cases exists_nat_gt (y - x)⁻¹ with n nh, cases exists_floor (x * n) with z zh, refine ⟨(z + 1 : ℤ) / n, _⟩, have n0' := (inv_pos.2 (sub_pos.2 h)).trans nh, have n0 := nat.cast_pos.1 n0', rw [rat.cast_div_of_ne_zero, rat.cast_coe_nat, rat.cast_coe_int, div_lt_iff n0'], refine ⟨(lt_div_iff n0').2 $ (lt_iff_lt_of_le_iff_le (zh _)).1 (lt_add_one _), _⟩, rw [int.cast_add, int.cast_one], refine lt_of_le_of_lt (add_le_add_right ((zh _).1 le_rfl) _) _, rwa [← lt_sub_iff_add_lt', ← sub_mul, ← div_lt_iff' (sub_pos.2 h), one_div], { rw [rat.coe_int_denom, nat.cast_one], exact one_ne_zero }, { intro H, rw [rat.coe_nat_num, ← coe_coe, nat.cast_eq_zero] at H, subst H, cases n0 }, { rw [rat.coe_nat_denom, nat.cast_one], exact one_ne_zero } end lemma le_of_forall_rat_lt_imp_le (h : ∀ q : ℚ, (q : α) < x → (q : α) ≤ y) : x ≤ y := le_of_not_lt $ λ hyx, let ⟨q, hy, hx⟩ := exists_rat_btwn hyx in hy.not_le $ h _ hx lemma le_of_forall_lt_rat_imp_le (h : ∀ q : ℚ, y < q → x ≤ q) : x ≤ y := le_of_not_lt $ λ hyx, let ⟨q, hy, hx⟩ := exists_rat_btwn hyx in hx.not_le $ h _ hy lemma eq_of_forall_rat_lt_iff_lt (h : ∀ q : ℚ, (q : α) < x ↔ (q : α) < y) : x = y := (le_of_forall_rat_lt_imp_le $ λ q hq, ((h q).1 hq).le).antisymm $ le_of_forall_rat_lt_imp_le $ λ q hq, ((h q).2 hq).le lemma eq_of_forall_lt_rat_iff_lt (h : ∀ q : ℚ, x < q ↔ y < q) : x = y := (le_of_forall_lt_rat_imp_le $ λ q hq, ((h q).2 hq).le).antisymm $ le_of_forall_lt_rat_imp_le $ λ q hq, ((h q).1 hq).le theorem exists_nat_one_div_lt {ε : α} (hε : 0 < ε) : ∃ n : ℕ, 1 / (n + 1: α) < ε := begin cases exists_nat_gt (1/ε) with n hn, use n, rw [div_lt_iff, ← div_lt_iff' hε], { apply hn.trans, simp [zero_lt_one] }, { exact n.cast_add_one_pos } end theorem exists_pos_rat_lt {x : α} (x0 : 0 < x) : ∃ q : ℚ, 0 < q ∧ (q : α) < x := by simpa only [rat.cast_pos] using exists_rat_btwn x0 end linear_ordered_field section variables [linear_ordered_field α] [floor_ring α] /-- `round` rounds a number to the nearest integer. `round (1 / 2) = 1` -/ def round (x : α) : ℤ := ⌊x + 1 / 2⌋ @[simp] lemma round_zero : round (0 : α) = 0 := floor_eq_iff.2 (by norm_num) @[simp] lemma round_one : round (1 : α) = 1 := floor_eq_iff.2 (by norm_num) lemma abs_sub_round (x : α) : |x - round x| ≤ 1 / 2 := begin rw [round, abs_sub_le_iff], have := floor_le (x + 1 / 2), have := lt_floor_add_one (x + 1 / 2), split; linarith end @[simp, norm_cast] theorem rat.floor_cast (x : ℚ) : ⌊(x:α)⌋ = ⌊x⌋ := floor_eq_iff.2 (by exact_mod_cast floor_eq_iff.1 (eq.refl ⌊x⌋)) @[simp, norm_cast] theorem rat.ceil_cast (x : ℚ) : ⌈(x:α)⌉ = ⌈x⌉ := by rw [←neg_inj, ←floor_neg, ←floor_neg, ← rat.cast_neg, rat.floor_cast] @[simp, norm_cast] theorem rat.round_cast (x : ℚ) : round (x:α) = round x := have ((x + 1 / 2 : ℚ) : α) = x + 1 / 2, by simp, by rw [round, round, ← this, rat.floor_cast] @[simp, norm_cast] theorem rat.cast_fract (x : ℚ) : (↑(fract x) : α) = fract x := by { simp only [fract, rat.cast_sub], simp } end section variables [linear_ordered_field α] [archimedean α] theorem exists_rat_near (x : α) {ε : α} (ε0 : 0 < ε) : ∃ q : ℚ, |x - q| < ε := let ⟨q, h₁, h₂⟩ := exists_rat_btwn $ lt_trans ((sub_lt_self_iff x).2 ε0) ((lt_add_iff_pos_left x).2 ε0) in ⟨q, abs_sub_lt_iff.2 ⟨sub_lt.1 h₁, sub_lt_iff_lt_add.2 h₂⟩⟩ instance : archimedean ℚ := archimedean_iff_rat_le.2 $ λ q, ⟨q, by rw rat.cast_id⟩ end
64d2d28a1a7815b003a19612368d92c5a6b93179
367134ba5a65885e863bdc4507601606690974c1
/src/data/polynomial/integral_normalization.lean
25973a5665194c876c48cbef7a3bec48d7100c47
[ "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
5,316
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.algebra_map import data.polynomial.monic /-! # Theory of monic polynomials We define `integral_normalization`, which relate arbitrary polynomials to monic ones. -/ noncomputable theory open finsupp namespace polynomial universes u v y variables {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y} section integral_normalization section semiring variables [semiring R] /-- If `f : polynomial R` is a nonzero polynomial with root `z`, `integral_normalization f` is a monic polynomial with root `leading_coeff f * z`. Moreover, `integral_normalization 0 = 0`. -/ noncomputable def integral_normalization (f : polynomial R) : polynomial R := on_finset f.support (λ i, if f.degree = i then 1 else coeff f i * f.leading_coeff ^ (f.nat_degree - 1 - i)) begin intros i h, apply mem_support_iff.mpr, split_ifs at h with hi, { exact coeff_ne_zero_of_eq_degree hi }, { exact left_ne_zero_of_mul h }, end lemma integral_normalization_coeff_degree {f : polynomial R} {i : ℕ} (hi : f.degree = i) : (integral_normalization f).coeff i = 1 := if_pos hi lemma integral_normalization_coeff_nat_degree {f : polynomial R} (hf : f ≠ 0) : (integral_normalization f).coeff (nat_degree f) = 1 := integral_normalization_coeff_degree (degree_eq_nat_degree hf) lemma integral_normalization_coeff_ne_degree {f : polynomial R} {i : ℕ} (hi : f.degree ≠ i) : coeff (integral_normalization f) i = coeff f i * f.leading_coeff ^ (f.nat_degree - 1 - i) := if_neg hi lemma integral_normalization_coeff_ne_nat_degree {f : polynomial R} {i : ℕ} (hi : i ≠ nat_degree f) : coeff (integral_normalization f) i = coeff f i * f.leading_coeff ^ (f.nat_degree - 1 - i) := integral_normalization_coeff_ne_degree (degree_ne_of_nat_degree_ne hi.symm) lemma monic_integral_normalization {f : polynomial R} (hf : f ≠ 0) : monic (integral_normalization f) := begin apply monic_of_degree_le f.nat_degree, { refine finset.sup_le (λ i h, _), rw [integral_normalization, mem_support_iff, coeff, on_finset_apply] at h, split_ifs at h with hi, { exact le_trans (le_of_eq hi.symm) degree_le_nat_degree }, { erw [with_bot.some_le_some], apply le_nat_degree_of_ne_zero, exact left_ne_zero_of_mul h } }, { exact integral_normalization_coeff_nat_degree hf } end end semiring section domain variables [integral_domain R] @[simp] lemma support_integral_normalization {f : polynomial R} (hf : f ≠ 0) : (integral_normalization f).support = f.support := begin ext i, simp only [integral_normalization, coeff, on_finset_apply, mem_support_iff], split_ifs with hi, { simp only [ne.def, not_false_iff, true_iff, one_ne_zero, hi], exact coeff_ne_zero_of_eq_degree hi }, split, { intro h, exact left_ne_zero_of_mul h }, { intro h, refine mul_ne_zero h (pow_ne_zero _ _), exact λ h, hf (leading_coeff_eq_zero.mp h) } end variables [comm_ring S] lemma integral_normalization_eval₂_eq_zero {p : polynomial R} (hp : p ≠ 0) (f : R →+* S) {z : S} (hz : eval₂ f z p = 0) (inj : ∀ (x : R), f x = 0 → x = 0) : eval₂ f (z * f p.leading_coeff) (integral_normalization p) = 0 := calc eval₂ f (z * f p.leading_coeff) (integral_normalization p) = p.support.attach.sum (λ i, f (coeff (integral_normalization p) i.1 * p.leading_coeff ^ i.1) * z ^ i.1) : by { rw [eval₂, sum_def, support_integral_normalization hp], simp only [mul_comm z, mul_pow, mul_assoc, ring_hom.map_pow, ring_hom.map_mul], exact finset.sum_attach.symm } ... = p.support.attach.sum (λ i, f (coeff p i.1 * p.leading_coeff ^ (nat_degree p - 1)) * z ^ i.1) : begin have one_le_deg : 1 ≤ nat_degree p := nat.succ_le_of_lt (nat_degree_pos_of_eval₂_root hp f hz inj), congr' with i, congr' 2, by_cases hi : i.1 = nat_degree p, { rw [hi, integral_normalization_coeff_degree, one_mul, leading_coeff, ←pow_succ, nat.sub_add_cancel one_le_deg], exact degree_eq_nat_degree hp }, { have : i.1 ≤ p.nat_degree - 1 := nat.le_pred_of_lt (lt_of_le_of_ne (le_nat_degree_of_ne_zero (finsupp.mem_support_iff.mp i.2)) hi), rw [integral_normalization_coeff_ne_nat_degree hi, mul_assoc, ←pow_add, nat.sub_add_cancel this] } end ... = f p.leading_coeff ^ (nat_degree p - 1) * eval₂ f z p : by { simp_rw [eval₂, finsupp.sum, λ i, mul_comm (coeff p i), ring_hom.map_mul, ring_hom.map_pow, mul_assoc, ←finset.mul_sum], congr' 1, exact @finset.sum_attach _ _ p.support _ (λ i, f (p.coeff i) * z ^ i) } ... = 0 : by rw [hz, _root_.mul_zero] lemma integral_normalization_aeval_eq_zero [algebra R S] {f : polynomial R} (hf : f ≠ 0) {z : S} (hz : aeval z f = 0) (inj : ∀ (x : R), algebra_map R S x = 0 → x = 0) : aeval (z * algebra_map R S f.leading_coeff) (integral_normalization f) = 0 := integral_normalization_eval₂_eq_zero hf (algebra_map R S) hz inj end domain end integral_normalization end polynomial
4df9f4ba547006ad0f2c562294967f5b4cb722d5
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/normed_space/is_R_or_C.lean
403f56e8030ab72b4eddca1d2df6c19a517feb2e
[ "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
4,016
lean
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import data.is_R_or_C.basic import analysis.normed_space.operator_norm import analysis.normed_space.pointwise /-! # Normed spaces over R or C > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file is about results on normed spaces over the fields `ℝ` and `ℂ`. ## Main definitions None. ## Main theorems * `continuous_linear_map.op_norm_bound_of_ball_bound`: A bound on the norms of values of a linear map in a ball yields a bound on the operator norm. ## Notes This file exists mainly to avoid importing `is_R_or_C` in the main normed space theory files. -/ open metric variables {𝕜 : Type*} [is_R_or_C 𝕜] {E : Type*} [normed_add_comm_group E] lemma is_R_or_C.norm_coe_norm {z : E} : ‖(‖z‖ : 𝕜)‖ = ‖z‖ := by simp variables [normed_space 𝕜 E] /-- Lemma to normalize a vector in a normed space `E` over either `ℂ` or `ℝ` to unit length. -/ @[simp] lemma norm_smul_inv_norm {x : E} (hx : x ≠ 0) : ‖(‖x‖⁻¹ : 𝕜) • x‖ = 1 := begin have : ‖x‖ ≠ 0 := by simp [hx], field_simp [norm_smul] end /-- Lemma to normalize a vector in a normed space `E` over either `ℂ` or `ℝ` to length `r`. -/ lemma norm_smul_inv_norm' {r : ℝ} (r_nonneg : 0 ≤ r) {x : E} (hx : x ≠ 0) : ‖(r * ‖x‖⁻¹ : 𝕜) • x‖ = r := begin have : ‖x‖ ≠ 0 := by simp [hx], field_simp [norm_smul, r_nonneg] with is_R_or_C_simps end lemma linear_map.bound_of_sphere_bound {r : ℝ} (r_pos : 0 < r) (c : ℝ) (f : E →ₗ[𝕜] 𝕜) (h : ∀ z ∈ sphere (0 : E) r, ‖f z‖ ≤ c) (z : E) : ‖f z‖ ≤ c / r * ‖z‖ := begin by_cases z_zero : z = 0, { rw z_zero, simp only [linear_map.map_zero, norm_zero, mul_zero], }, set z₁ := (r * ‖z‖⁻¹ : 𝕜) • z with hz₁, have norm_f_z₁ : ‖f z₁‖ ≤ c, { apply h, rw mem_sphere_zero_iff_norm, exact norm_smul_inv_norm' r_pos.le z_zero }, have r_ne_zero : (r : 𝕜) ≠ 0 := is_R_or_C.of_real_ne_zero.mpr r_pos.ne', have eq : f z = ‖z‖ / r * (f z₁), { rw [hz₁, linear_map.map_smul, smul_eq_mul], rw [← mul_assoc, ← mul_assoc, div_mul_cancel _ r_ne_zero, mul_inv_cancel, one_mul], simp only [z_zero, is_R_or_C.of_real_eq_zero, norm_eq_zero, ne.def, not_false_iff], }, rw [eq, norm_mul, norm_div, is_R_or_C.norm_coe_norm, is_R_or_C.norm_of_nonneg r_pos.le, div_mul_eq_mul_div, div_mul_eq_mul_div, mul_comm], apply div_le_div _ _ r_pos rfl.ge, { exact mul_nonneg ((norm_nonneg _).trans norm_f_z₁) (norm_nonneg z), }, apply mul_le_mul norm_f_z₁ rfl.le (norm_nonneg z) ((norm_nonneg _).trans norm_f_z₁), end /-- `linear_map.bound_of_ball_bound` is a version of this over arbitrary nontrivially normed fields. It produces a less precise bound so we keep both versions. -/ lemma linear_map.bound_of_ball_bound' {r : ℝ} (r_pos : 0 < r) (c : ℝ) (f : E →ₗ[𝕜] 𝕜) (h : ∀ z ∈ closed_ball (0 : E) r, ‖f z‖ ≤ c) (z : E) : ‖f z‖ ≤ c / r * ‖z‖ := f.bound_of_sphere_bound r_pos c (λ z hz, h z hz.le) z lemma continuous_linear_map.op_norm_bound_of_ball_bound {r : ℝ} (r_pos : 0 < r) (c : ℝ) (f : E →L[𝕜] 𝕜) (h : ∀ z ∈ closed_ball (0 : E) r, ‖f z‖ ≤ c) : ‖f‖ ≤ c / r := begin apply continuous_linear_map.op_norm_le_bound, { apply div_nonneg _ r_pos.le, exact (norm_nonneg _).trans (h 0 (by simp only [norm_zero, mem_closed_ball, dist_zero_left, r_pos.le])), }, apply linear_map.bound_of_ball_bound' r_pos, exact λ z hz, h z hz, end variables (𝕜) include 𝕜 lemma normed_space.sphere_nonempty_is_R_or_C [nontrivial E] {r : ℝ} (hr : 0 ≤ r) : nonempty (sphere (0:E) r) := begin letI : normed_space ℝ E := normed_space.restrict_scalars ℝ 𝕜 E, exact (normed_space.sphere_nonempty.mpr hr).coe_sort, end
f9ad8c78788b968620e31e270ad46134772f3646
4727251e0cd73359b15b664c3170e5d754078599
/src/data/fintype/sort.lean
551e297a1002d17a1e0f98be36bffc7c8efc96ed
[ "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
2,243
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 data.finset.sort import data.fintype.basic /-! # Sorting a finite type This file provides two equivalences for linearly ordered fintypes: * `mono_equiv_of_fin`: Order isomorphism between `α` and `fin (card α)`. * `fin_sum_equiv_of_finset`: Equivalence between `α` and `fin m ⊕ fin n` where `m` and `n` are respectively the cardinalities of some `finset α` and its complement. -/ open finset /-- Given a linearly ordered fintype `α` of cardinal `k`, the order isomorphism `mono_equiv_of_fin α h` is the increasing bijection between `fin k` and `α`. Here, `h` is a proof that the cardinality of `α` is `k`. We use this instead of an isomorphism `fin (card α) ≃o α` to avoid casting issues in further uses of this function. -/ def mono_equiv_of_fin (α : Type*) [fintype α] [linear_order α] {k : ℕ} (h : fintype.card α = k) : fin k ≃o α := (univ.order_iso_of_fin h).trans $ (order_iso.set_congr _ _ coe_univ).trans order_iso.set.univ variables {α : Type*} [decidable_eq α] [fintype α] [linear_order α] {m n : ℕ} {s : finset α} /-- If `α` is a linearly ordered fintype, `s : finset α` has cardinality `m` and its complement has cardinality `n`, then `fin m ⊕ fin n ≃ α`. The equivalence sends elements of `fin m` to elements of `s` and elements of `fin n` to elements of `sᶜ` while preserving order on each "half" of `fin m ⊕ fin n` (using `set.order_iso_of_fin`). -/ def fin_sum_equiv_of_finset (hm : s.card = m) (hn : sᶜ.card = n) : fin m ⊕ fin n ≃ α := calc fin m ⊕ fin n ≃ (s : set α) ⊕ (sᶜ : set α) : equiv.sum_congr (s.order_iso_of_fin hm).to_equiv $ (sᶜ.order_iso_of_fin hn).to_equiv.trans $ equiv.set.of_eq s.coe_compl ... ≃ α : equiv.set.sum_compl _ @[simp] lemma fin_sum_equiv_of_finset_inl (hm : s.card = m) (hn : sᶜ.card = n) (i : fin m) : fin_sum_equiv_of_finset hm hn (sum.inl i) = s.order_emb_of_fin hm i := rfl @[simp] lemma fin_sum_equiv_of_finset_inr (hm : s.card = m) (hn : sᶜ.card = n) (i : fin n) : fin_sum_equiv_of_finset hm hn (sum.inr i) = sᶜ.order_emb_of_fin hn i := rfl
3817b7d2374bd0cb1994c351d07adc1b79fb818b
556aeb81a103e9e0ac4e1fe0ce1bc6e6161c3c5e
/src/starkware/cairo/common/cairo_secp/bigint_spec.lean
0005a434ab6ffade4639ed243c34a7a057e76cc7
[]
permissive
starkware-libs/formal-proofs
d6b731604461bf99e6ba820e68acca62a21709e8
f5fa4ba6a471357fd171175183203d0b437f6527
refs/heads/master
1,691,085,444,753
1,690,507,386,000
1,690,507,386,000
410,476,629
32
9
Apache-2.0
1,690,506,773,000
1,632,639,790,000
Lean
UTF-8
Lean
false
false
23,869
lean
/- Specifications file for bigint_spec.cairo Do not modify the constant definitions, structure definitions, or automatic specifications. Do not change the name or arguments of the user specifications and soundness theorems. You may freely move the definitions around in the file. You may add definitions and theorems wherever you wish in this file. -/ import starkware.cairo.lean.semantics.soundness.prelude import starkware.cairo.common.cairo_secp.constants_spec open starkware.cairo.common.cairo_secp.constants namespace starkware.cairo.common.cairo_secp.bigint variables {F : Type} [field F] [decidable_eq F] [prelude_hyps F] -- End of automatically generated prelude. -- Main scope definitions. @[ext] structure BigInt3 (F : Type) := ( d0 : F ) ( d1 : F ) ( d2 : F ) attribute [derive decidable_eq] BigInt3 @[ext] structure π_BigInt3 (F : Type) := ( σ_ptr : F ) ( d0 : F ) ( d1 : F ) ( d2 : F ) @[reducible] def φ_BigInt3.d0 := 0 @[reducible] def φ_BigInt3.d1 := 1 @[reducible] def φ_BigInt3.d2 := 2 @[reducible] def φ_BigInt3.SIZE := 3 @[reducible] def cast_BigInt3 (mem : F → F) (p : F) : BigInt3 F := { d0 := mem (p + φ_BigInt3.d0), d1 := mem (p + φ_BigInt3.d1), d2 := mem (p + φ_BigInt3.d2) } @[reducible] def cast_π_BigInt3 (mem : F → F) (p : F) : π_BigInt3 F := { σ_ptr := mem p, d0 := mem ((mem p) + φ_BigInt3.d0), d1 := mem ((mem p) + φ_BigInt3.d1), d2 := mem ((mem p) + φ_BigInt3.d2) } instance π_BigInt3_to_F : has_coe (π_BigInt3 F) F := ⟨λ s, s.σ_ptr⟩ @[ext] structure UnreducedBigInt5 (F : Type) := ( d0 : F ) ( d1 : F ) ( d2 : F ) ( d3 : F ) ( d4 : F ) @[ext] structure π_UnreducedBigInt5 (F : Type) := ( σ_ptr : F ) ( d0 : F ) ( d1 : F ) ( d2 : F ) ( d3 : F ) ( d4 : F ) @[reducible] def φ_UnreducedBigInt5.d0 := 0 @[reducible] def φ_UnreducedBigInt5.d1 := 1 @[reducible] def φ_UnreducedBigInt5.d2 := 2 @[reducible] def φ_UnreducedBigInt5.d3 := 3 @[reducible] def φ_UnreducedBigInt5.d4 := 4 @[reducible] def φ_UnreducedBigInt5.SIZE := 5 @[reducible] def cast_UnreducedBigInt5 (mem : F → F) (p : F) : UnreducedBigInt5 F := { d0 := mem (p + φ_UnreducedBigInt5.d0), d1 := mem (p + φ_UnreducedBigInt5.d1), d2 := mem (p + φ_UnreducedBigInt5.d2), d3 := mem (p + φ_UnreducedBigInt5.d3), d4 := mem (p + φ_UnreducedBigInt5.d4) } @[reducible] def cast_π_UnreducedBigInt5 (mem : F → F) (p : F) : π_UnreducedBigInt5 F := { σ_ptr := mem p, d0 := mem ((mem p) + φ_UnreducedBigInt5.d0), d1 := mem ((mem p) + φ_UnreducedBigInt5.d1), d2 := mem ((mem p) + φ_UnreducedBigInt5.d2), d3 := mem ((mem p) + φ_UnreducedBigInt5.d3), d4 := mem ((mem p) + φ_UnreducedBigInt5.d4) } instance π_UnreducedBigInt5_to_F : has_coe (π_UnreducedBigInt5 F) F := ⟨λ s, s.σ_ptr⟩ @[ext] structure UnreducedBigInt3 (F : Type) := ( d0 : F ) ( d1 : F ) ( d2 : F ) @[ext] structure π_UnreducedBigInt3 (F : Type) := ( σ_ptr : F ) ( d0 : F ) ( d1 : F ) ( d2 : F ) @[reducible] def φ_UnreducedBigInt3.d0 := 0 @[reducible] def φ_UnreducedBigInt3.d1 := 1 @[reducible] def φ_UnreducedBigInt3.d2 := 2 @[reducible] def φ_UnreducedBigInt3.SIZE := 3 @[reducible] def cast_UnreducedBigInt3 (mem : F → F) (p : F) : UnreducedBigInt3 F := { d0 := mem (p + φ_UnreducedBigInt3.d0), d1 := mem (p + φ_UnreducedBigInt3.d1), d2 := mem (p + φ_UnreducedBigInt3.d2) } @[reducible] def cast_π_UnreducedBigInt3 (mem : F → F) (p : F) : π_UnreducedBigInt3 F := { σ_ptr := mem p, d0 := mem ((mem p) + φ_UnreducedBigInt3.d0), d1 := mem ((mem p) + φ_UnreducedBigInt3.d1), d2 := mem ((mem p) + φ_UnreducedBigInt3.d2) } instance π_UnreducedBigInt3_to_F : has_coe (π_UnreducedBigInt3 F) F := ⟨λ s, s.σ_ptr⟩ -- End of main scope definitions. namespace nondet_bigint3 @[reducible] def MAX_SUM := 3 * (BASE - 1) end nondet_bigint3 namespace BigInt3 def add (x y : BigInt3 F) : BigInt3 F := { d0 := x.d0 + y.d0, d1 := x.d1 + y.d1, d2 := x.d2 + y.d2 } def sub (x y : BigInt3 F) : BigInt3 F := { d0 := x.d0 - y.d0, d1 := x.d1 - y.d1, d2 := x.d2 - y.d2 } end BigInt3 namespace UnreducedBigInt3 def add (x y : UnreducedBigInt3 F) : UnreducedBigInt3 F := { d0 := x.d0 + y.d0, d1 := x.d1 + y.d1, d2 := x.d2 + y.d2 } def sub (x y : UnreducedBigInt3 F) : UnreducedBigInt3 F := { d0 := x.d0 - y.d0, d1 := x.d1 - y.d1, d2 := x.d2 - y.d2 } end UnreducedBigInt3 @[ext] structure bigint3 := (i0 i1 i2 : ℤ) namespace bigint3 def val (x : bigint3) : int := x.i2 * ↑BASE^2 + x.i1 * ↑BASE + x.i0 def toBigInt3 (x : bigint3) : BigInt3 F := ⟨x.i0, x.i1, x.i2⟩ def toUnreducedBigInt3 (x : bigint3) : UnreducedBigInt3 F := ⟨x.i0, x.i1, x.i2⟩ def add (x y : bigint3) : bigint3 := { i0 := x.i0 + y.i0, i1 := x.i1 + y.i1, i2 := x.i2 + y.i2 } theorem toBigInt3_add (x y : bigint3) : ((x.add y).toBigInt3 : BigInt3 F) = BigInt3.add (x.toBigInt3) (y.toBigInt3) := by simp [BigInt3.add, toBigInt3, bigint3.add] theorem toUnreducedBigInt3_add (x y : bigint3) : ((x.add y).toUnreducedBigInt3 : UnreducedBigInt3 F) = UnreducedBigInt3.add (x.toUnreducedBigInt3) (y.toUnreducedBigInt3) := by simp [UnreducedBigInt3.add, toUnreducedBigInt3, bigint3.add] theorem add_val (x y : bigint3) : (x.add y).val = x.val + y.val := by { simp [val, add], ring } def sub (x y : bigint3) : bigint3 := { i0 := x.i0 - y.i0, i1 := x.i1 - y.i1, i2 := x.i2 - y.i2 } theorem toBigInt3_sub (x y : bigint3) : ((x.sub y).toBigInt3 : BigInt3 F) = BigInt3.sub (x.toBigInt3) (y.toBigInt3) := by simp [BigInt3.sub, toBigInt3, bigint3.sub] theorem toUnreducedBigInt3_sub (x y : bigint3) : ((x.sub y).toUnreducedBigInt3 : UnreducedBigInt3 F) = UnreducedBigInt3.sub (x.toUnreducedBigInt3) (y.toUnreducedBigInt3) := by simp [UnreducedBigInt3.sub, toUnreducedBigInt3, bigint3.sub] theorem sub_val (x y : bigint3) : (x.sub y).val = x.val - y.val := by { simp [val, sub], ring } def cmul (c : ℤ) (x : bigint3) : bigint3 := { i0 := c * x.i0, i1 := c * x.i1, i2 := c * x.i2} theorem cmul_val (c : ℤ) (x : bigint3) : (x.cmul c).val = c * x.val := by { simp [val, cmul], ring } def mul (x y : bigint3) : bigint3 := { i0 := x.i0 * y.i0 + (x.i1 * y.i2 + x.i2 * y.i1) * (4 * SECP_REM), i1 := x.i0 * y.i1 + x.i1 * y.i0 + (x.i2 * y.i2) * (4 * SECP_REM), i2 := x.i0 * y.i2 + x.i1 * y.i1 + x.i2 * y.i0 } theorem mul_val (x y : bigint3) : (x.mul y).val ≡ x.val * y.val [ZMOD ↑SECP_PRIME] := begin have aux : (4 : ℤ) ∣ ↑BASE ^ 3, { dsimp only [BASE], simp_int_casts, norm_num1 }, rw [int.modeq_iff_dvd], use [4 * (x.i1 * y.i2 + x.i2 * y.i1 + BASE * (x.i2 * y.i2))], rw SECP_PRIME_eq, simp only [val, mul], conv { to_rhs, rw [←mul_assoc, sub_mul, int.div_mul_cancel aux] }, generalize : SECP_REM = S, generalize : BASE = B, ring end def sqr (x : bigint3) : bigint3 := x.mul x theorem sqr_val (x : bigint3) : x.sqr.val ≡ x.val^2 [ZMOD ↑SECP_PRIME] := by { rw pow_two, exact mul_val x x } def bounded (x : bigint3) (b : ℤ) := abs x.i0 ≤ b ∧ abs x.i1 ≤ b ∧ abs x.i2 ≤ b theorem bounded_of_bounded_of_le {x : bigint3} {b₁ b₂ : ℤ} (bddx : x.bounded b₁) (hle : b₁ ≤ b₂) : x.bounded b₂ := ⟨bddx.1.trans hle, bddx.2.1.trans hle, bddx.2.2.trans hle⟩ theorem bounded_add {x y : bigint3} {b₁ b₂ : int} (bddx : x.bounded b₁) (bddy : y.bounded b₂) : (x.add y).bounded (b₁ + b₂) := ⟨(abs_add _ _).trans (add_le_add bddx.1 bddy.1), (abs_add _ _).trans (add_le_add bddx.2.1 bddy.2.1), (abs_add _ _).trans (add_le_add bddx.2.2 bddy.2.2)⟩ theorem bounded_sub {x y : bigint3} {b₁ b₂ : int} (bddx : x.bounded b₁) (bddy : y.bounded b₂) : (x.sub y).bounded (b₁ + b₂) := ⟨(abs_sub _ _).trans (add_le_add bddx.1 bddy.1), (abs_sub _ _).trans (add_le_add bddx.2.1 bddy.2.1), (abs_sub _ _).trans (add_le_add bddx.2.2 bddy.2.2)⟩ theorem bounded_cmul {x : bigint3} {c b : int} (bddx : x.bounded b) : (x.cmul c).bounded (abs c * b) := begin simp [cmul, bigint3.bounded, abs_mul], exact ⟨mul_le_mul_of_nonneg_left bddx.1 (abs_nonneg _), mul_le_mul_of_nonneg_left bddx.2.1 (abs_nonneg _), mul_le_mul_of_nonneg_left bddx.2.2 (abs_nonneg _)⟩ end theorem bounded_cmul' {x : bigint3} {c b : int} (h : 0 ≤ c) (bddx : x.bounded b) : (x.cmul c).bounded (c * b) := by { convert bounded_cmul bddx, rw abs_of_nonneg h } theorem bounded_mul {x y : bigint3} {b : ℤ} (hx : x.bounded b) (hy : y.bounded b) : (x.mul y).bounded (b^2 * (8 * SECP_REM + 1)) := begin have bnonneg : 0 ≤ b := le_trans (abs_nonneg _) hx.1, have secp4nonneg : (0 : ℤ) ≤ 4 * ↑SECP_REM, { apply mul_nonneg, norm_num1, rw [SECP_REM], simp_int_casts, norm_num1 }, have secp4ge1 : (1 : ℤ) ≤ 4 * ↑SECP_REM, { rw [SECP_REM], simp_int_casts, norm_num1 }, simp only [bigint3.mul, bigint3.bounded], split, { transitivity b * b + (b * b + b * b) * (4 * ↑SECP_REM), { apply le_trans, apply abs_add, apply add_le_add, rw abs_mul, apply mul_le_mul hx.1 hy.1 (abs_nonneg _) bnonneg, rw [abs_mul, abs_of_nonneg secp4nonneg], apply mul_le_mul_of_nonneg_right _ secp4nonneg, apply le_trans, apply abs_add, rw [abs_mul, abs_mul], apply add_le_add, apply mul_le_mul hx.2.1 hy.2.2 (abs_nonneg _) bnonneg, apply mul_le_mul hx.2.2 hy.2.1 (abs_nonneg _) bnonneg }, apply le_of_eq, ring }, split, { transitivity b * b + b * (b * (4 * ↑SECP_REM)) + (b * b) * (4 * ↑SECP_REM), { apply le_trans, apply abs_add, apply add_le_add, apply le_trans, apply abs_add, rw [abs_mul, abs_mul], apply add_le_add, apply mul_le_mul hx.1 hy.2.1 (abs_nonneg _) bnonneg, apply mul_le_mul hx.2.1 _ (abs_nonneg _) bnonneg, rw [←mul_one(abs y.i0)], apply mul_le_mul hy.1 secp4ge1 zero_le_one bnonneg, rw [abs_mul, abs_mul, abs_of_nonneg secp4nonneg], apply mul_le_mul_of_nonneg_right _ secp4nonneg, apply mul_le_mul hx.2.2 hy.2.2 (abs_nonneg _) bnonneg, }, apply le_of_eq, ring }, transitivity (b * b + b * b + b * b), apply le_trans, apply abs_add, apply add_le_add, apply le_trans, apply abs_add, rw [abs_mul, abs_mul], apply add_le_add, apply mul_le_mul hx.1 hy.2.2 (abs_nonneg _) bnonneg, apply mul_le_mul hx.2.1 hy.2.1 (abs_nonneg _) bnonneg, rw abs_mul, apply mul_le_mul hx.2.2 hy.1 (abs_nonneg _) bnonneg, transitivity (b^2 * 3), apply le_of_eq, ring, apply mul_le_mul_of_nonneg_left _ (pow_two_nonneg b), rw [SECP_REM], simp_int_casts, norm_num1 end theorem bounded_sqr {x : bigint3} {b : ℤ} (hx : x.bounded b) : (x.sqr).bounded (b^2 * (8 * SECP_REM + 1)) := bounded_mul hx hx end bigint3 theorem bigint3_eqs {x : BigInt3 F} {i0 i1 i2 : ℤ} (h : x = (bigint3.mk i0 i1 i2).toBigInt3) : x.d0 = i0 ∧ x.d1 = i1 ∧ x.d2 = i2 := by { rwa BigInt3.ext_iff at h } theorem unreduced_bigint3_eqs {x : UnreducedBigInt3 F} {i0 i1 i2 : ℤ} (h : x = (bigint3.mk i0 i1 i2).toUnreducedBigInt3) : x.d0 = i0 ∧ x.d1 = i1 ∧ x.d2 = i2 := by { rwa UnreducedBigInt3.ext_iff at h } theorem cast_int_eq_of_bdd_3BASE {i j : int} (heq : (i : F) = (j : F)) (ibdd : abs i ≤ 3 * BASE - 1) (jbdd : abs j ≤ 3 * BASE - 1) : i = j := begin apply PRIME.int_coe_inj heq, apply lt_of_le_of_lt, apply abs_sub, apply lt_of_le_of_lt, apply add_le_add jbdd ibdd, dsimp only [BASE, PRIME], simp_int_casts, norm_num end theorem toBigInt3_eq_toBigInt3_of_bounded_3BASE {a b : bigint3} (heq : (a.toBigInt3 : BigInt3 F) = b.toBigInt3) (abdd : a.bounded (3 * BASE - 1)) (bbdd : b.bounded (3 * BASE - 1)) : a = b := begin simp [BigInt3.ext_iff, bigint3.toBigInt3] at heq, ext, { apply cast_int_eq_of_bdd_3BASE heq.1 abdd.1 bbdd.1 }, { apply cast_int_eq_of_bdd_3BASE heq.2.1 abdd.2.1 bbdd.2.1 }, { apply cast_int_eq_of_bdd_3BASE heq.2.2 abdd.2.2 bbdd.2.2 } end theorem toBigInt3_eq_zero_of_bounded_3BASE {a : bigint3} (heq : (a.toBigInt3 : BigInt3 F) = ⟨0, 0, 0⟩) (abdd : a.bounded (3 * BASE - 1)) : a = ⟨0, 0, 0⟩ := begin have : (a.toBigInt3 : BigInt3 F) = bigint3.toBigInt3 ⟨0, 0, 0⟩, { rw heq, simp [bigint3.toBigInt3] }, apply toBigInt3_eq_toBigInt3_of_bounded_3BASE this abdd, simp [bigint3.bounded], norm_num end @[ext] structure bigint5 := (i0 i1 i2 i3 i4 : ℤ) def bigint3.bigint5_mul (ix iy : bigint3) : bigint5 := { i0 := ix.i0 * iy.i0, i1 := ix.i0 * iy.i1 + ix.i1 * iy.i0, i2 := ix.i0 * iy.i2 + ix.i1 * iy.i1 + ix.i2 * iy.i0, i3 := ix.i1 * iy.i2 + ix.i2 * iy.i1, i4 := ix.i2 * iy.i2 } def BigInt3.UnreducedBigInt5_mul (x y : BigInt3 F) : UnreducedBigInt5 F := { d0 := x.d0 * y.d0, d1 := x.d0 * y.d1 + x.d1 * y.d0, d2 := x.d0 * y.d2 + x.d1 * y.d1 + x.d2 * y.d0, d3 := x.d1 * y.d2 + x.d2 * y.d1, d4 := x.d2 * y.d2 } def bigint5.toUnreducedBigInt5 (x : bigint5) : UnreducedBigInt5 F := ⟨x.i0, x.i1, x.i2, x.i3, x.i4⟩ theorem bigint3.bigint5_mul_toUnreducedBigInt5 (ix iy : bigint3) : ((ix.bigint5_mul iy).toUnreducedBigInt5 : UnreducedBigInt5 F) = (ix.toBigInt3).UnreducedBigInt5_mul (iy.toBigInt3) := by simp [bigint5.toUnreducedBigInt5, bigint3.toBigInt3, bigint3.bigint5_mul, BigInt3.UnreducedBigInt5_mul] def bigint3.to_bigint5 (ix : bigint3) : bigint5 := ⟨ix.i0, ix.i1, ix.i2, 0, 0⟩ def BigInt3.toUnreducedBigInt5 {F : Type} [field F] (x : BigInt3 F) : UnreducedBigInt5 F := ⟨x.d0, x.d1, x.d2, 0, 0⟩ theorem bigint3.to_bigint5_to_Unreduced_BigInt5 (ix : bigint3) : (ix.to_bigint5.toUnreducedBigInt5 : UnreducedBigInt5 F) = ix.toBigInt3.toUnreducedBigInt5 := begin simp [bigint5.toUnreducedBigInt5, bigint3.to_bigint5, bigint3.toBigInt3, BigInt3.toUnreducedBigInt5] end namespace UnreducedBigInt5 def add (x y : UnreducedBigInt5 F) : UnreducedBigInt5 F := { d0 := x.d0 + y.d0, d1 := x.d1 + y.d1, d2 := x.d2 + y.d2, d3 := x.d3 + y.d3, d4 := x.d4 + y.d4 } def sub (x y : UnreducedBigInt5 F) : UnreducedBigInt5 F := { d0 := x.d0 - y.d0, d1 := x.d1 - y.d1, d2 := x.d2 - y.d2, d3 := x.d3 - y.d3, d4 := x.d4 - y.d4 } end UnreducedBigInt5 namespace bigint5 def val (x : bigint5) : int := x.i4 * ↑BASE^4 + x.i3 * ↑BASE^3 + x.i2 * ↑BASE^2 + x.i1 * ↑BASE + x.i0 def add (x y : bigint5) : bigint5 := { i0 := x.i0 + y.i0, i1 := x.i1 + y.i1, i2 := x.i2 + y.i2, i3 := x.i3 + y.i3, i4 := x.i4 + y.i4 } theorem toUnreducedBigInt5_add (x y : bigint5) : ((x.add y).toUnreducedBigInt5 : UnreducedBigInt5 F) = UnreducedBigInt5.add (x.toUnreducedBigInt5) (y.toUnreducedBigInt5) := by simp [UnreducedBigInt5.add, toUnreducedBigInt5, bigint5.add] theorem add_val (x y : bigint5) : (x.add y).val = x.val + y.val := by { simp [val, add], ring } def sub (x y : bigint5) : bigint5 := { i0 := x.i0 - y.i0, i1 := x.i1 - y.i1, i2 := x.i2 - y.i2, i3 := x.i3 - y.i3, i4 := x.i4 - y.i4 } theorem toUnreducedBigInt5_sub (x y : bigint5) : ((x.sub y).toUnreducedBigInt5 : UnreducedBigInt5 F) = UnreducedBigInt5.sub (x.toUnreducedBigInt5) (y.toUnreducedBigInt5) := by simp [UnreducedBigInt5.sub, toUnreducedBigInt5, bigint5.sub] theorem sub_val (x y : bigint5) : (x.sub y).val = x.val - y.val := by { simp [val, sub], ring } def cmul (c : ℤ) (x : bigint5) : bigint5 := { i0 := c * x.i0, i1 := c * x.i1, i2 := c * x.i2, i3 := c * x.i3, i4 := c * x.i4 } def bounded (x : bigint5) (b : ℤ) := abs x.i0 ≤ b ∧ abs x.i1 ≤ b ∧ abs x.i2 ≤ b ∧ abs x.i3 ≤ b ∧ abs x.i4 ≤ b theorem bounded_of_bounded_of_le {x : bigint5} {b₁ b₂ : ℤ} (bddx : x.bounded b₁) (hle : b₁ ≤ b₂) : x.bounded b₂ := ⟨bddx.1.trans hle, bddx.2.1.trans hle, bddx.2.2.1.trans hle, bddx.2.2.2.1.trans hle, bddx.2.2.2.2.trans hle⟩ theorem bounded_add {x y : bigint5} {b₁ b₂ : int} (bddx : x.bounded b₁) (bddy : y.bounded b₂) : (x.add y).bounded (b₁ + b₂) := ⟨(abs_add _ _).trans (add_le_add bddx.1 bddy.1), (abs_add _ _).trans (add_le_add bddx.2.1 bddy.2.1), (abs_add _ _).trans (add_le_add bddx.2.2.1 bddy.2.2.1), (abs_add _ _).trans (add_le_add bddx.2.2.2.1 bddy.2.2.2.1), (abs_add _ _).trans (add_le_add bddx.2.2.2.2 bddy.2.2.2.2)⟩ theorem bounded_sub {x y : bigint5} {b₁ b₂ : int} (bddx : x.bounded b₁) (bddy : y.bounded b₂) : (x.sub y).bounded (b₁ + b₂) := ⟨(abs_sub _ _).trans (add_le_add bddx.1 bddy.1), (abs_sub _ _).trans (add_le_add bddx.2.1 bddy.2.1), (abs_sub _ _).trans (add_le_add bddx.2.2.1 bddy.2.2.1), (abs_sub _ _).trans (add_le_add bddx.2.2.2.1 bddy.2.2.2.1), (abs_sub _ _).trans (add_le_add bddx.2.2.2.2 bddy.2.2.2.2) ⟩ theorem bounded_cmul {x : bigint5} {c b : int} (bddx : x.bounded b) : (x.cmul c).bounded (abs c * b) := begin simp [cmul, bigint5.bounded, abs_mul], exact ⟨mul_le_mul_of_nonneg_left bddx.1 (abs_nonneg _), mul_le_mul_of_nonneg_left bddx.2.1 (abs_nonneg _), mul_le_mul_of_nonneg_left bddx.2.2.1 (abs_nonneg _), mul_le_mul_of_nonneg_left bddx.2.2.2.1 (abs_nonneg _), mul_le_mul_of_nonneg_left bddx.2.2.2.2 (abs_nonneg _)⟩ end theorem bounded_cmul' {x : bigint5} {c b : int} (h : 0 ≤ c) (bddx : x.bounded b) : (x.cmul c).bounded (c * b) := by { convert bounded_cmul bddx, rw abs_of_nonneg h } theorem toUnreducedBigInt5_eq_of_sub_bounded {a b : bigint5} (heq : (a.toUnreducedBigInt5 : UnreducedBigInt5 F) = b.toUnreducedBigInt5) (bdd : (b.sub a).bounded (PRIME - 1)) : a = b := begin simp [UnreducedBigInt5.ext_iff, bigint5.toUnreducedBigInt5] at heq, have h : (PRIME : ℤ) - 1 < PRIME, by norm_num, ext, exact PRIME.int_coe_inj heq.1 (lt_of_le_of_lt bdd.1 h), exact PRIME.int_coe_inj heq.2.1 (lt_of_le_of_lt bdd.2.1 h), exact PRIME.int_coe_inj heq.2.2.1 (lt_of_le_of_lt bdd.2.2.1 h), exact PRIME.int_coe_inj heq.2.2.2.1 (lt_of_le_of_lt bdd.2.2.2.1 h), exact PRIME.int_coe_inj heq.2.2.2.2 (lt_of_le_of_lt bdd.2.2.2.2 h), end end bigint5 theorem bigint3.bounded_bigint5_mul {x y : bigint3} {b : ℤ} (hx : x.bounded b) (hy : y.bounded b) : (x.bigint5_mul y).bounded (3 * b^2) := begin have bnn : 0 ≤ b := le_trans (abs_nonneg _) hx.1, have b2nn: 0 ≤ b^2 := sq_nonneg b, have b2le3b2 : b^2 ≤ 3 * b^2, by linarith, have b2b2le3b2 : b^2 + b^2 ≤ 3 * b^2, by linarith, have b23eq : 3 * b^2 = b^2 + b^2 + b^2, by linarith, simp [bigint3.bigint5_mul], split, { apply le_trans _ b2le3b2, rw [abs_mul, pow_two], exact mul_le_mul hx.1 hy.1 (abs_nonneg _) bnn }, split, { apply le_trans _ b2b2le3b2, refine le_trans (abs_add _ _) _, simp_rw [abs_mul, pow_two], apply add_le_add, exact mul_le_mul hx.1 hy.2.1 (abs_nonneg _) bnn, exact mul_le_mul hx.2.1 hy.1 (abs_nonneg _) bnn }, split, { rw [b23eq, pow_two], refine le_trans (abs_add _ _) _, apply add_le_add, refine le_trans (abs_add _ _) _, simp_rw abs_mul, apply add_le_add, exact mul_le_mul hx.1 hy.2.2 (abs_nonneg _) bnn, exact mul_le_mul hx.2.1 hy.2.1 (abs_nonneg _) bnn, rw abs_mul, exact mul_le_mul hx.2.2 hy.1 (abs_nonneg _) bnn }, split, { apply le_trans _ b2b2le3b2, refine le_trans (abs_add _ _) _, simp_rw [abs_mul, pow_two], apply add_le_add, exact mul_le_mul hx.2.1 hy.2.2 (abs_nonneg _) bnn, exact mul_le_mul hx.2.2 hy.2.1 (abs_nonneg _) bnn }, apply le_trans _ b2le3b2, rw [abs_mul, pow_two], exact mul_le_mul hx.2.2 hy.2.2 (abs_nonneg _) bnn end theorem bigint3.to_bigint5_bounded {x : bigint3} {b : ℤ} (hx : x.bounded b) : x.to_bigint5.bounded b := begin use [hx.1, hx.2.1, hx.2.2], simp [bigint3.to_bigint5], apply le_trans (abs_nonneg _ ) hx.1 end /- -- Function: bigint_mul -/ /- bigint_mul autogenerated specification -/ -- Do not change this definition. def auto_spec_bigint_mul (mem : F → F) (κ : ℕ) (x y : BigInt3 F) (ρ_res : UnreducedBigInt5 F) : Prop := 14 ≤ κ ∧ ρ_res = { d0 := x.d0 * y.d0, d1 := x.d0 * y.d1 + x.d1 * y.d0, d2 := x.d0 * y.d2 + x.d1 * y.d1 + x.d2 * y.d0, d3 := x.d1 * y.d2 + x.d2 * y.d1, d4 := x.d2 * y.d2 } -- You may change anything in this definition except the name and arguments. def spec_bigint_mul (mem : F → F) (κ : ℕ) (x y : BigInt3 F) (ρ_res : UnreducedBigInt5 F) : Prop := ρ_res = x.UnreducedBigInt5_mul y /- bigint_mul soundness theorem -/ -- Do not change the statement of this theorem. You may change the proof. theorem sound_bigint_mul {mem : F → F} (κ : ℕ) (x y : BigInt3 F) (ρ_res : UnreducedBigInt5 F) (h_auto : auto_spec_bigint_mul mem κ x y ρ_res) : spec_bigint_mul mem κ x y ρ_res := begin exact h_auto.2 end /- -- Function: nondet_bigint3 -/ /- nondet_bigint3 autogenerated specification -/ -- Do not change this definition. def auto_spec_nondet_bigint3 (mem : F → F) (κ : ℕ) (range_check_ptr ρ_range_check_ptr : F) (ρ_res : BigInt3 F) : Prop := ∃ res : BigInt3 F, ∃ MAX_SUM : F, MAX_SUM = 232113757366008801543585789 ∧ mem (range_check_ptr) = MAX_SUM - (res.d0 + res.d1 + res.d2) ∧ is_range_checked (rc_bound F) (MAX_SUM - (res.d0 + res.d1 + res.d2)) ∧ ∃ range_check_ptr₁ : F, range_check_ptr₁ = range_check_ptr + 4 ∧ mem (range_check_ptr₁ - 3) = res.d0 ∧ is_range_checked (rc_bound F) (res.d0) ∧ mem (range_check_ptr₁ - 2) = res.d1 ∧ is_range_checked (rc_bound F) (res.d1) ∧ mem (range_check_ptr₁ - 1) = res.d2 ∧ is_range_checked (rc_bound F) (res.d2) ∧ 10 ≤ κ ∧ ρ_range_check_ptr = range_check_ptr₁ ∧ ρ_res = res -- You may change anything in this definition except the name and arguments. def spec_nondet_bigint3 (mem : F → F) (κ : ℕ) (range_check_ptr ρ_range_check_ptr : F) (ρ_res : BigInt3 F) : Prop := ∃ nd0 nd1 nd2 slack : ℕ, nd0 < rc_bound F ∧ nd1 < rc_bound F ∧ nd2 < rc_bound F ∧ slack < rc_bound F ∧ ρ_res = bigint3.toBigInt3 { i0 := nd0, i1 := nd1, i2 := nd2 } ∧ nd0 + nd1 + nd2 + slack = 3 * (BASE - 1) theorem nondet_bigint3_corr {mem : F → F} {k : ℕ} {range_check_ptr : F} {ret0 : F} {x : BigInt3 F} (h : spec_nondet_bigint3 mem k range_check_ptr ret0 x) : ∃ ix : bigint3, x = ix.toBigInt3 ∧ ix.bounded (3 * (BASE - 1)) := begin have BASEge1: 1 ≤ BASE, by { unfold BASE, norm_num1 }, rcases h with ⟨nd0, nd1, nd2, _, _, _, _, _, xeq, sumeq⟩, refine ⟨_, xeq, _⟩, simp only [bigint3.bounded], have : (3 : ℤ) * (↑BASE - 1) = ↑(3 * (BASE - 1)), { rw [int.coe_nat_mul, int.coe_nat_sub BASEge1], simp }, rw [this, ←sumeq], norm_cast, simp only [add_assoc], split, apply nat.le_add_right, split, apply le_trans (nat.le_add_right _ _) (nat.le_add_left _ _), apply le_trans _ (nat.le_add_left _ _), apply le_trans (nat.le_add_right _ _) (nat.le_add_left _ _), end /- nondet_bigint3 soundness theorem -/ -- Do not change the statement of this theorem. You may change the proof. theorem sound_nondet_bigint3 {mem : F → F} (κ : ℕ) (range_check_ptr ρ_range_check_ptr : F) (ρ_res : BigInt3 F) (h_auto : auto_spec_nondet_bigint3 mem κ range_check_ptr ρ_range_check_ptr ρ_res) : spec_nondet_bigint3 mem κ range_check_ptr ρ_range_check_ptr ρ_res := begin rcases h_auto with ⟨res, MAX_SUM, MAX_SUM_eq, _, ⟨slack, slack_lt, slack_eq⟩, rp1, rp1eq, resd0eq, ⟨nd0, nd0_lt, nd0_eq⟩, resd1eq, ⟨nd1, nd1_lt, nd1_eq⟩, resd2eq, ⟨nd2, nd2_lt, nd2_eq⟩, _, rp1eq', reseq⟩, use [nd0, nd1, nd2, slack, nd0_lt, nd1_lt, nd2_lt, slack_lt], split, { rw reseq, ext; simp [bigint3.toBigInt3]; assumption }, rw BASE, norm_num1, apply @PRIME.nat_coe_field_inj F, transitivity 4 * rc_bound F, linarith, apply lt_of_le_of_lt (mul_le_mul_left' (rc_bound_hyp F) 4), rw PRIME, norm_num1, rw PRIME, norm_num1, simp only [nat.cast_add, ←slack_eq, ←nd0_eq, ←nd1_eq, ←nd2_eq, add_sub_cancel'_right, nat.cast_bit0, nat.cast_bit1, nat.cast_one], rw MAX_SUM_eq end end starkware.cairo.common.cairo_secp.bigint
2581680e10c9f6204e891060ffc774b9655d3a56
ce6917c5bacabee346655160b74a307b4a5ab620
/src/ch5/ex0719.lean
5a8c5c8245c6d63c8314a306dfde0008209ce1cf
[]
no_license
Ailrun/Theorem_Proving_in_Lean
ae6a23f3c54d62d401314d6a771e8ff8b4132db2
2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68
refs/heads/master
1,609,838,270,467
1,586,846,743,000
1,586,846,743,000
240,967,761
1
0
null
null
null
null
UTF-8
Lean
false
false
536
lean
import data.list.basic open list universe u variables {α : Type} (x y z : α) (xs ys zs : list α) def mk_symm (xs : list α) := xs ++ reverse xs theorem reverse_mk_symm (xs : list α) : reverse (mk_symm xs) = mk_symm xs := by simp [mk_symm] attribute [simp] reverse_mk_symm example (xs ys : list ℕ) : reverse (xs ++ mk_symm ys) = mk_symm ys ++ reverse xs := by simp example (xs ys : list ℕ) (p : list ℕ → Prop) (h : p (reverse (xs ++ (mk_symm ys)))) : p (mk_symm ys ++ reverse xs) := by simp at h; assumption
c8fd0cfef46a274cc42efd5225ba269883e16f84
4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d
/src/Lean/Util/Trace.lean
67ae1512e979a8e7debef0d2bc0f5dca6745a2f8
[ "Apache-2.0" ]
permissive
subfish-zhou/leanprover-zh_CN.github.io
30b9fba9bd790720bd95764e61ae796697d2f603
8b2985d4a3d458ceda9361ac454c28168d920d3f
refs/heads/master
1,689,709,967,820
1,632,503,056,000
1,632,503,056,000
409,962,097
1
0
null
null
null
null
UTF-8
Lean
false
false
5,727
lean
/- Copyright (c) 2018 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sebastian Ullrich, Leonardo de Moura -/ import Lean.Message import Lean.MonadEnv universe u namespace Lean open Std (PersistentArray) structure TraceElem where ref : Syntax msg : MessageData deriving Inhabited structure TraceState where enabled : Bool := true traces : PersistentArray TraceElem := {} deriving Inhabited namespace TraceState private def toFormat (traces : PersistentArray TraceElem) (sep : Format) : IO Format := traces.size.foldM (fun i r => do let curr ← (traces.get! i).msg.format pure $ if i > 0 then r ++ sep ++ curr else r ++ curr) Format.nil end TraceState class MonadTrace (m : Type → Type) where modifyTraceState : (TraceState → TraceState) → m Unit getTraceState : m TraceState export MonadTrace (getTraceState modifyTraceState) instance (m n) [MonadLift m n] [MonadTrace m] : MonadTrace n where modifyTraceState := fun f => liftM (modifyTraceState f : m _) getTraceState := liftM (getTraceState : m _) variable {α : Type} {m : Type → Type} [Monad m] [MonadTrace m] def printTraces {m} [Monad m] [MonadTrace m] [MonadLiftT IO m] : m Unit := do let traceState ← getTraceState traceState.traces.forM fun m => do let d ← m.msg.format IO.println d def resetTraceState {m} [MonadTrace m] : m Unit := modifyTraceState (fun _ => {}) private def checkTraceOptionAux (opts : Options) : Name → Bool | n@(Name.str p _ _) => opts.getBool n || (!opts.contains n && checkTraceOptionAux opts p) | _ => false def checkTraceOption (opts : Options) (cls : Name) : Bool := if opts.isEmpty then false else checkTraceOptionAux opts (`trace ++ cls) private def checkTraceOptionM [MonadOptions m] (cls : Name) : m Bool := do let opts ← getOptions pure $ checkTraceOption opts cls @[inline] def isTracingEnabledFor [MonadOptions m] (cls : Name) : m Bool := do let s ← getTraceState if !s.enabled then pure false else checkTraceOptionM cls @[inline] def enableTracing (b : Bool) : m Bool := do let s ← getTraceState let oldEnabled := s.enabled modifyTraceState fun s => { s with enabled := b } pure oldEnabled @[inline] def getTraces : m (PersistentArray TraceElem) := do let s ← getTraceState pure s.traces @[inline] def modifyTraces (f : PersistentArray TraceElem → PersistentArray TraceElem) : m Unit := modifyTraceState fun s => { s with traces := f s.traces } @[inline] def setTraceState (s : TraceState) : m Unit := modifyTraceState fun _ => s private def addNode (oldTraces : PersistentArray TraceElem) (cls : Name) (ref : Syntax) : m Unit := modifyTraces fun traces => if traces.isEmpty then oldTraces else let d := MessageData.tagged (cls ++ `_traceCtx) (MessageData.node (traces.toArray.map fun elem => elem.msg)) oldTraces.push { ref := ref, msg := d } private def getResetTraces : m (PersistentArray TraceElem) := do let oldTraces ← getTraces modifyTraces fun _ => {} pure oldTraces section variable [MonadRef m] [AddMessageContext m] [MonadOptions m] def addTrace (cls : Name) (msg : MessageData) : m Unit := do let ref ← getRef let msg ← addMessageContext msg let msg := addTraceOptions msg modifyTraces fun traces => traces.push { ref := ref, msg := MessageData.tagged (cls ++ `_traceMsg) m!"[{cls}] {msg}" } where addTraceOptions : MessageData → MessageData | MessageData.withContext ctx msg => MessageData.withContext { ctx with opts := ctx.opts.setBool `pp.analyze false } msg | msg => msg @[inline] def trace (cls : Name) (msg : Unit → MessageData) : m Unit := do if (← isTracingEnabledFor cls) then addTrace cls (msg ()) @[inline] def traceM (cls : Name) (mkMsg : m MessageData) : m Unit := do if (← isTracingEnabledFor cls) then let msg ← mkMsg addTrace cls msg @[inline] def traceCtx [MonadFinally m] (cls : Name) (ctx : m α) : m α := do let b ← isTracingEnabledFor cls if !b then let old ← enableTracing false try ctx finally enableTracing old else let ref ← getRef let oldCurrTraces ← getResetTraces try ctx finally addNode oldCurrTraces cls ref -- TODO: delete after fix old frontend def MonadTracer.trace (cls : Name) (msg : Unit → MessageData) : m Unit := Lean.trace cls msg end def registerTraceClass (traceClassName : Name) : IO Unit := registerOption (`trace ++ traceClassName) { group := "trace", defValue := false, descr := "enable/disable tracing for the given module and submodules" } macro "trace[" id:ident "]" s:(interpolatedStr(term) <|> term) : doElem => do let msg ← if s.getKind == interpolatedStrKind then `(m! $s) else `(($s : MessageData)) `(doElem| do let cls := $(quote id.getId) if (← Lean.isTracingEnabledFor cls) then Lean.addTrace cls $msg) private def withNestedTracesFinalizer [Monad m] [MonadTrace m] (ref : Syntax) (currTraces : PersistentArray TraceElem) : m Unit := do modifyTraces fun traces => if traces.size == 0 then currTraces else if traces.size == 1 && traces[0].msg.isNest then currTraces ++ traces -- No nest of nest else let d := traces.foldl (init := MessageData.nil) fun d elem => if d.isNil then elem.msg else m!"{d}\n{elem.msg}" currTraces.push { ref := ref, msg := MessageData.nestD d } @[inline] def withNestedTraces [Monad m] [MonadFinally m] [MonadTrace m] [MonadRef m] (x : m α) : m α := do let currTraces ← getTraces modifyTraces fun _ => {} let ref ← getRef try x finally withNestedTracesFinalizer ref currTraces end Lean
b8d2b5221b18cd4f260024e8ce90a81c8b0925a9
491068d2ad28831e7dade8d6dff871c3e49d9431
/library/logic/examples/instances_test.lean
c0181cb1f9369d1af17ffc788df1a81787604757
[ "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
1,236
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad Illustrates substitution and congruence with iff. -/ import ..instances open relation open relation.general_subst open relation.iff_ops open eq.ops example (a b : Prop) (H : a ↔ b) (H1 : a) : b := mp H H1 set_option class.conservative false example (a b c d e : Prop) (H1 : a ↔ b) (H2 : a ∨ c → ¬(d → a)) : b ∨ c → ¬(d → b) := subst iff H1 H2 /- exit example (a b c d e : Prop) (H1 : a ↔ b) (H2 : a ∨ c → ¬(d → a)) : b ∨ c → ¬(d → b) := H1 ▸ H2 example (a b c d e : Prop) (H1 : a ↔ b) : (a ∨ c → ¬(d → a)) ↔ (b ∨ c → ¬(d → b)) := is_congruence.congr iff (λa, (a ∨ c → ¬(d → a))) H1 example (T : Type) (a b c d : T) (H1 : a = b) (H2 : c = b) (H3 : c = d) : a = d := H1 ⬝ H2⁻¹ ⬝ H3 example (a b c d : Prop) (H1 : a ↔ b) (H2 : c ↔ b) (H3 : c ↔ d) : a ↔ d := H1 ⬝ (H2⁻¹ ⬝ H3) example (T : Type) (a b c d : T) (H1 : a = b) (H2 : c = b) (H3 : c = d) : a = d := H1 ⬝ H2⁻¹ ⬝ H3 example (a b c d : Prop) (H1 : a ↔ b) (H2 : c ↔ b) (H3 : c ↔ d) : a ↔ d := H1 ⬝ H2⁻¹ ⬝ H3 -/
9c9a27d9370fe71b603911b156e1ee5f6c56f444
1e561612e7479c100cd9302e3fe08cbd2914aa25
/mathlib4_experiments/Data/Equiv/Basic.lean
00feb48747fbc0ae076564c055cc8b6f6c2bfa48
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib4_experiments
8de8ed7193f70748a7529e05d831203a7c64eedb
87cb879b4d602c8ecfd9283b7c0b06015abdbab1
refs/heads/master
1,687,971,389,316
1,620,336,942,000
1,620,336,942,000
353,994,588
7
4
Apache-2.0
1,622,410,748,000
1,617,361,732,000
Lean
UTF-8
Lean
false
false
2,561
lean
/- Quick&dirty port of some parts of `data.equiv.basic` from Lean 3. Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import mathlib4_experiments.Data.Notation set_option autoBoundImplicitLocal false universes u₁ u₂ u₃ u₄ v structure Equiv (α : Sort u₁) (β : Sort u₂) where (toFun : α → β) (invFun : β → α) (leftInv : ∀ x, invFun (toFun x) = x) (rightInv : ∀ y, toFun (invFun y) = y) namespace Equiv instance : HasEquivalence (Sort u₁) (Sort u₂) := ⟨Equiv⟩ instance (α : Sort u₁) (β : Sort u₂) : CoeFun (α ≃ β) (λ _ => α → β) := ⟨Equiv.toFun⟩ def refl (α : Sort u₁) : α ≃ α := ⟨id, id, λ x => rfl, λ y => rfl⟩ def symm {α : Sort u₁} {β : Sort u₂} (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun, e.rightInv, e.leftInv⟩ theorem trans_leftInv {α : Sort u₁} {β : Sort u₂} {γ : Sort u₃} (e₁ : α ≃ β) (e₂ : β ≃ γ) (x : α) : e₁.invFun (e₂.invFun (e₂.toFun (e₁.toFun x))) = x := Eq.trans (congrArg e₁.invFun (e₂.leftInv (e₁.toFun x))) (e₁.leftInv x) def trans {α : Sort u₁} {β : Sort u₂} {γ : Sort u₃} (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂.toFun ∘ e₁.toFun, e₁.invFun ∘ e₂.invFun, trans_leftInv e₁ e₂, trans_leftInv (symm e₂) (symm e₁)⟩ variable {α : Sort u₁} {β : Sort u₂} {γ : Sort u₃} {δ : Sort u₄} @[simp] theorem symm_symm (e : α ≃ β) : symm (symm e) = e := match e with | ⟨toFun, invFun, leftInv, rightInv⟩ => rfl @[simp] theorem trans_refl (e : α ≃ β) : trans e (refl β) = e := match e with | ⟨toFun, invFun, leftInv, rightInv⟩ => rfl @[simp] theorem refl_symm : symm (refl α) = refl α := rfl @[simp] theorem refl_trans (e : α ≃ β) : trans (refl α) e = e := match e with | ⟨toFun, invFun, leftInv, rightInv⟩ => rfl @[simp] theorem symm_trans (e : α ≃ β) : trans (symm e) e = refl β := let h₁ : e.toFun ∘ e.invFun = id := funext e.rightInv; -- Need to figure out how to recover injectivity of constructors in Lean 4. sorry @[simp] theorem trans_symm (e : α ≃ β) : trans e (symm e) = refl α := symm_trans (symm e) @[simp] theorem symm_trans_symm (ab : α ≃ β) (bc : β ≃ γ) : symm (trans ab bc) = trans (symm bc) (symm ab) := rfl theorem trans_assoc (ab : α ≃ β) (bc : β ≃ γ) (cd : γ ≃ δ) : trans (trans ab bc) cd = trans ab (trans bc cd) := rfl end Equiv
1d3c01cde5658c906f699667594b93e0154d6891
1abd1ed12aa68b375cdef28959f39531c6e95b84
/src/data/int/basic.lean
cbcd47b7f968721130277a6104d2151398d16402
[ "Apache-2.0" ]
permissive
jumpy4/mathlib
d3829e75173012833e9f15ac16e481e17596de0f
af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13
refs/heads/master
1,693,508,842,818
1,636,203,271,000
1,636,203,271,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
55,741
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import data.nat.pow import order.min_max /-! # Basic operations on the integers This file contains: * instances on `ℤ`. The stronger one is `int.linear_ordered_comm_ring`. * some basic lemmas about integers ## Recursors * `int.rec`: Sign disjunction. Something is true/defined on `ℤ` if it's true/defined for nonnegative and for negative values. * `int.bit_cases_on`: Parity disjunction. Something is true/defined on `ℤ` if it's true/defined for even and for odd values. * `int.induction_on`: Simple growing induction on positive numbers, plus simple decreasing induction on negative numbers. Note that this recursor is currently only `Prop`-valued. * `int.induction_on'`: Simple growing induction for numbers greater than `b`, plus simple decreasing induction on numbers less than `b`. -/ open nat namespace int instance : inhabited ℤ := ⟨int.zero⟩ instance : nontrivial ℤ := ⟨⟨0, 1, int.zero_ne_one⟩⟩ instance : comm_ring int := { add := int.add, add_assoc := int.add_assoc, zero := int.zero, zero_add := int.zero_add, add_zero := int.add_zero, neg := int.neg, add_left_neg := int.add_left_neg, add_comm := int.add_comm, mul := int.mul, mul_assoc := int.mul_assoc, one := int.one, one_mul := int.one_mul, mul_one := int.mul_one, sub := int.sub, left_distrib := int.distrib_left, right_distrib := int.distrib_right, mul_comm := int.mul_comm, zsmul := (*), zsmul_zero' := int.zero_mul, zsmul_succ' := λ n x, by rw [succ_eq_one_add, of_nat_add, int.distrib_right, of_nat_one, int.one_mul], zsmul_neg' := λ n x, neg_mul_eq_neg_mul_symm (n.succ : ℤ) x } /-! ### Extra instances to short-circuit type class resolution These also prevent non-computable instances like `int.normed_comm_ring` being used to construct these instances non-computably. -/ -- instance : has_sub int := by apply_instance -- This is in core instance : add_comm_monoid int := by apply_instance instance : add_monoid int := by apply_instance instance : monoid int := by apply_instance instance : comm_monoid int := by apply_instance instance : comm_semigroup int := by apply_instance instance : semigroup int := by apply_instance instance : add_comm_group int := by apply_instance instance : add_group int := by apply_instance instance : add_comm_semigroup int := by apply_instance instance : add_semigroup int := by apply_instance instance : comm_semiring int := by apply_instance instance : semiring int := by apply_instance instance : ring int := by apply_instance instance : distrib int := by apply_instance instance : linear_ordered_comm_ring int := { add_le_add_left := @int.add_le_add_left, mul_pos := @int.mul_pos, zero_le_one := le_of_lt int.zero_lt_one, .. int.comm_ring, .. int.linear_order, .. int.nontrivial } instance : linear_ordered_add_comm_group int := by apply_instance @[simp] lemma add_neg_one (i : ℤ) : i + -1 = i - 1 := rfl theorem abs_eq_nat_abs : ∀ a : ℤ, |a| = nat_abs a | (n : ℕ) := abs_of_nonneg $ coe_zero_le _ | -[1+ n] := abs_of_nonpos $ le_of_lt $ neg_succ_lt_zero _ theorem nat_abs_abs (a : ℤ) : nat_abs (|a|) = nat_abs a := by rw [abs_eq_nat_abs]; refl theorem sign_mul_abs (a : ℤ) : sign a * |a| = a := by rw [abs_eq_nat_abs, sign_mul_nat_abs] @[simp] lemma default_eq_zero : default ℤ = 0 := rfl meta instance : has_to_format ℤ := ⟨λ z, to_string z⟩ meta instance : has_reflect ℤ := by tactic.mk_has_reflect_instance attribute [simp] int.coe_nat_add int.coe_nat_mul int.coe_nat_zero int.coe_nat_one int.coe_nat_succ attribute [simp] int.of_nat_eq_coe int.bodd @[simp] theorem add_def {a b : ℤ} : int.add a b = a + b := rfl @[simp] theorem mul_def {a b : ℤ} : int.mul a b = a * b := rfl @[simp] lemma neg_succ_not_nonneg (n : ℕ) : 0 ≤ -[1+ n] ↔ false := by { simp only [not_le, iff_false], exact int.neg_succ_lt_zero n, } @[simp] lemma neg_succ_not_pos (n : ℕ) : 0 < -[1+ n] ↔ false := by simp only [not_lt, iff_false] @[simp] lemma neg_succ_sub_one (n : ℕ) : -[1+ n] - 1 = -[1+ (n+1)] := rfl @[simp] theorem coe_nat_mul_neg_succ (m n : ℕ) : (m : ℤ) * -[1+ n] = -(m * succ n) := rfl @[simp] theorem neg_succ_mul_coe_nat (m n : ℕ) : -[1+ m] * n = -(succ m * n) := rfl @[simp] theorem neg_succ_mul_neg_succ (m n : ℕ) : -[1+ m] * -[1+ n] = succ m * succ n := rfl @[simp, norm_cast] theorem coe_nat_le {m n : ℕ} : (↑m : ℤ) ≤ ↑n ↔ m ≤ n := coe_nat_le_coe_nat_iff m n @[simp, norm_cast] theorem coe_nat_lt {m n : ℕ} : (↑m : ℤ) < ↑n ↔ m < n := coe_nat_lt_coe_nat_iff m n @[simp, norm_cast] theorem coe_nat_inj' {m n : ℕ} : (↑m : ℤ) = ↑n ↔ m = n := int.coe_nat_eq_coe_nat_iff m n @[simp] theorem coe_nat_pos {n : ℕ} : (0 : ℤ) < n ↔ 0 < n := by rw [← int.coe_nat_zero, coe_nat_lt] @[simp] theorem coe_nat_eq_zero {n : ℕ} : (n : ℤ) = 0 ↔ n = 0 := by rw [← int.coe_nat_zero, coe_nat_inj'] theorem coe_nat_ne_zero {n : ℕ} : (n : ℤ) ≠ 0 ↔ n ≠ 0 := not_congr coe_nat_eq_zero @[simp] lemma coe_nat_nonneg (n : ℕ) : 0 ≤ (n : ℤ) := coe_nat_le.2 (nat.zero_le _) lemma coe_nat_ne_zero_iff_pos {n : ℕ} : (n : ℤ) ≠ 0 ↔ 0 < n := ⟨λ h, nat.pos_of_ne_zero (coe_nat_ne_zero.1 h), λ h, (ne_of_lt (coe_nat_lt.2 h)).symm⟩ lemma coe_nat_succ_pos (n : ℕ) : 0 < (n.succ : ℤ) := int.coe_nat_pos.2 (succ_pos n) @[simp, norm_cast] theorem coe_nat_abs (n : ℕ) : |(n : ℤ)| = n := abs_of_nonneg (coe_nat_nonneg n) /-! ### succ and pred -/ /-- Immediate successor of an integer: `succ n = n + 1` -/ def succ (a : ℤ) := a + 1 /-- Immediate predecessor of an integer: `pred n = n - 1` -/ def pred (a : ℤ) := a - 1 theorem nat_succ_eq_int_succ (n : ℕ) : (nat.succ n : ℤ) = int.succ n := rfl theorem pred_succ (a : ℤ) : pred (succ a) = a := add_sub_cancel _ _ theorem succ_pred (a : ℤ) : succ (pred a) = a := sub_add_cancel _ _ theorem neg_succ (a : ℤ) : -succ a = pred (-a) := neg_add _ _ theorem succ_neg_succ (a : ℤ) : succ (-succ a) = -a := by rw [neg_succ, succ_pred] theorem neg_pred (a : ℤ) : -pred a = succ (-a) := by rw [eq_neg_of_eq_neg (neg_succ (-a)).symm, neg_neg] theorem pred_neg_pred (a : ℤ) : pred (-pred a) = -a := by rw [neg_pred, pred_succ] theorem pred_nat_succ (n : ℕ) : pred (nat.succ n) = n := pred_succ n theorem neg_nat_succ (n : ℕ) : -(nat.succ n : ℤ) = pred (-n) := neg_succ n theorem succ_neg_nat_succ (n : ℕ) : succ (-nat.succ n) = -n := succ_neg_succ n theorem lt_succ_self (a : ℤ) : a < succ a := lt_add_of_pos_right _ zero_lt_one theorem pred_self_lt (a : ℤ) : pred a < a := sub_lt_self _ zero_lt_one theorem add_one_le_iff {a b : ℤ} : a + 1 ≤ b ↔ a < b := iff.rfl theorem lt_add_one_iff {a b : ℤ} : a < b + 1 ↔ a ≤ b := add_le_add_iff_right _ @[simp] lemma succ_coe_nat_pos (n : ℕ) : 0 < (n : ℤ) + 1 := lt_add_one_iff.mpr (by simp) @[norm_cast] lemma coe_pred_of_pos {n : ℕ} (h : 0 < n) : ((n - 1 : ℕ) : ℤ) = (n : ℤ) - 1 := by { cases n, cases h, simp, } lemma le_add_one {a b : ℤ} (h : a ≤ b) : a ≤ b + 1 := le_of_lt (int.lt_add_one_iff.mpr h) theorem sub_one_lt_iff {a b : ℤ} : a - 1 < b ↔ a ≤ b := sub_lt_iff_lt_add.trans lt_add_one_iff theorem le_sub_one_iff {a b : ℤ} : a ≤ b - 1 ↔ a < b := le_sub_iff_add_le @[simp] lemma eq_zero_iff_abs_lt_one {a : ℤ} : |a| < 1 ↔ a = 0 := ⟨λ a0, let ⟨hn, hp⟩ := abs_lt.mp a0 in (le_of_lt_add_one (by exact hp)).antisymm hn, λ a0, (abs_eq_zero.mpr a0).le.trans_lt zero_lt_one⟩ @[elab_as_eliminator] protected lemma induction_on {p : ℤ → Prop} (i : ℤ) (hz : p 0) (hp : ∀ i : ℕ, p i → p (i + 1)) (hn : ∀ i : ℕ, p (-i) → p (-i - 1)) : p i := begin induction i, { induction i, { exact hz }, { exact hp _ i_ih } }, { have : ∀ n:ℕ, p (- n), { intro n, induction n, { simp [hz] }, { convert hn _ n_ih using 1, simp [sub_eq_neg_add] } }, exact this (i + 1) } end /-- Inductively define a function on `ℤ` by defining it at `b`, for the `succ` of a number greater than `b`, and the `pred` of a number less than `b`. -/ protected def induction_on' {C : ℤ → Sort*} (z : ℤ) (b : ℤ) : C b → (∀ k, b ≤ k → C k → C (k + 1)) → (∀ k ≤ b, C k → C (k - 1)) → C z := λ H0 Hs Hp, begin rw ←sub_add_cancel z b, induction (z - b) with n n, { induction n with n ih, { rwa [of_nat_zero, zero_add] }, rw [of_nat_succ, add_assoc, add_comm 1 b, ←add_assoc], exact Hs _ (le_add_of_nonneg_left (of_nat_nonneg _)) ih }, { induction n with n ih, { rw [neg_succ_of_nat_eq, ←of_nat_eq_coe, of_nat_zero, zero_add, neg_add_eq_sub], exact Hp _ (le_refl _) H0 }, { rw [neg_succ_of_nat_coe', nat.succ_eq_add_one, ←neg_succ_of_nat_coe, sub_add_eq_add_sub], exact Hp _ (le_of_lt (add_lt_of_neg_of_le (neg_succ_lt_zero _) (le_refl _))) ih } } end /-! ### nat abs -/ attribute [simp] nat_abs nat_abs_of_nat nat_abs_zero nat_abs_one theorem nat_abs_add_le (a b : ℤ) : nat_abs (a + b) ≤ nat_abs a + nat_abs b := begin have : ∀ (a b : ℕ), nat_abs (sub_nat_nat a (nat.succ b)) ≤ nat.succ (a + b), { refine (λ a b : ℕ, sub_nat_nat_elim a b.succ (λ m n i, n = b.succ → nat_abs i ≤ (m + b).succ) _ _ rfl); intros i n e, { subst e, rw [add_comm _ i, add_assoc], exact nat.le_add_right i (b.succ + b).succ }, { apply succ_le_succ, rw [← succ.inj e, ← add_assoc, add_comm], apply nat.le_add_right } }, cases a; cases b with b b; simp [nat_abs, nat.succ_add]; try {refl}; [skip, rw add_comm a b]; apply this end lemma nat_abs_sub_le (a b : ℤ) : nat_abs (a - b) ≤ nat_abs a + nat_abs b := by { rw [sub_eq_add_neg, ← int.nat_abs_neg b], apply nat_abs_add_le } theorem nat_abs_neg_of_nat (n : ℕ) : nat_abs (neg_of_nat n) = n := by cases n; refl theorem nat_abs_mul (a b : ℤ) : nat_abs (a * b) = (nat_abs a) * (nat_abs b) := by cases a; cases b; simp only [← int.mul_def, int.mul, nat_abs_neg_of_nat, eq_self_iff_true, int.nat_abs] lemma nat_abs_mul_nat_abs_eq {a b : ℤ} {c : ℕ} (h : a * b = (c : ℤ)) : a.nat_abs * b.nat_abs = c := by rw [← nat_abs_mul, h, nat_abs_of_nat] @[simp] lemma nat_abs_mul_self' (a : ℤ) : (nat_abs a * nat_abs a : ℤ) = a * a := by rw [← int.coe_nat_mul, nat_abs_mul_self] theorem neg_succ_of_nat_eq' (m : ℕ) : -[1+ m] = -m - 1 := by simp [neg_succ_of_nat_eq, sub_eq_neg_add] lemma nat_abs_ne_zero_of_ne_zero {z : ℤ} (hz : z ≠ 0) : z.nat_abs ≠ 0 := λ h, hz $ int.eq_zero_of_nat_abs_eq_zero h @[simp] lemma nat_abs_eq_zero {a : ℤ} : a.nat_abs = 0 ↔ a = 0 := ⟨int.eq_zero_of_nat_abs_eq_zero, λ h, h.symm ▸ rfl⟩ lemma nat_abs_ne_zero {a : ℤ} : a.nat_abs ≠ 0 ↔ a ≠ 0 := not_congr int.nat_abs_eq_zero lemma nat_abs_lt_nat_abs_of_nonneg_of_lt {a b : ℤ} (w₁ : 0 ≤ a) (w₂ : a < b) : a.nat_abs < b.nat_abs := begin lift b to ℕ using le_trans w₁ (le_of_lt w₂), lift a to ℕ using w₁, simpa using w₂, end lemma nat_abs_eq_nat_abs_iff {a b : ℤ} : a.nat_abs = b.nat_abs ↔ a = b ∨ a = -b := begin split; intro h, { cases int.nat_abs_eq a with h₁ h₁; cases int.nat_abs_eq b with h₂ h₂; rw [h₁, h₂]; simp [h], }, { cases h; rw h, rw int.nat_abs_neg, }, end lemma nat_abs_eq_iff {a : ℤ} {n : ℕ} : a.nat_abs = n ↔ a = n ∨ a = -n := by rw [←int.nat_abs_eq_nat_abs_iff, int.nat_abs_of_nat] lemma nat_abs_eq_iff_mul_self_eq {a b : ℤ} : a.nat_abs = b.nat_abs ↔ a * a = b * b := begin rw [← abs_eq_iff_mul_self_eq, abs_eq_nat_abs, abs_eq_nat_abs], exact int.coe_nat_inj'.symm end lemma nat_abs_lt_iff_mul_self_lt {a b : ℤ} : a.nat_abs < b.nat_abs ↔ a * a < b * b := begin rw [← abs_lt_iff_mul_self_lt, abs_eq_nat_abs, abs_eq_nat_abs], exact int.coe_nat_lt.symm end lemma nat_abs_le_iff_mul_self_le {a b : ℤ} : a.nat_abs ≤ b.nat_abs ↔ a * a ≤ b * b := begin rw [← abs_le_iff_mul_self_le, abs_eq_nat_abs, abs_eq_nat_abs], exact int.coe_nat_le.symm end lemma nat_abs_eq_iff_sq_eq {a b : ℤ} : a.nat_abs = b.nat_abs ↔ a ^ 2 = b ^ 2 := by { rw [sq, sq], exact nat_abs_eq_iff_mul_self_eq } lemma nat_abs_lt_iff_sq_lt {a b : ℤ} : a.nat_abs < b.nat_abs ↔ a ^ 2 < b ^ 2 := by { rw [sq, sq], exact nat_abs_lt_iff_mul_self_lt } lemma nat_abs_le_iff_sq_le {a b : ℤ} : a.nat_abs ≤ b.nat_abs ↔ a ^ 2 ≤ b ^ 2 := by { rw [sq, sq], exact nat_abs_le_iff_mul_self_le } /-! ### `/` -/ @[simp] theorem of_nat_div (m n : ℕ) : of_nat (m / n) = (of_nat m) / (of_nat n) := rfl @[simp, norm_cast] theorem coe_nat_div (m n : ℕ) : ((m / n : ℕ) : ℤ) = m / n := rfl theorem neg_succ_of_nat_div (m : ℕ) {b : ℤ} (H : 0 < b) : -[1+m] / b = -(m / b + 1) := match b, eq_succ_of_zero_lt H with ._, ⟨n, rfl⟩ := rfl end -- Will be generalized to Euclidean domains. local attribute [simp] protected theorem zero_div : ∀ (b : ℤ), 0 / b = 0 | 0 := show of_nat _ = _, by simp | (n+1:ℕ) := show of_nat _ = _, by simp | -[1+ n] := show -of_nat _ = _, by simp local attribute [simp] -- Will be generalized to Euclidean domains. protected theorem div_zero : ∀ (a : ℤ), a / 0 = 0 | 0 := show of_nat _ = _, by simp | (n+1:ℕ) := show of_nat _ = _, by simp | -[1+ n] := rfl @[simp] protected theorem div_neg : ∀ (a b : ℤ), a / -b = -(a / b) | (m : ℕ) 0 := show of_nat (m / 0) = -(m / 0 : ℕ), by rw nat.div_zero; refl | (m : ℕ) (n+1:ℕ) := rfl | 0 -[1+ n] := by simp | (m+1:ℕ) -[1+ n] := (neg_neg _).symm | -[1+ m] 0 := rfl | -[1+ m] (n+1:ℕ) := rfl | -[1+ m] -[1+ n] := rfl theorem div_of_neg_of_pos {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b = -((-a - 1) / b + 1) := match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := by change (- -[1+ m] : ℤ) with (m+1 : ℤ); rw add_sub_cancel; refl end protected theorem div_nonneg {a b : ℤ} (Ha : 0 ≤ a) (Hb : 0 ≤ b) : 0 ≤ a / b := match a, b, eq_coe_of_zero_le Ha, eq_coe_of_zero_le Hb with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := coe_zero_le _ end protected theorem div_nonpos {a b : ℤ} (Ha : 0 ≤ a) (Hb : b ≤ 0) : a / b ≤ 0 := nonpos_of_neg_nonneg $ by rw [← int.div_neg]; exact int.div_nonneg Ha (neg_nonneg_of_nonpos Hb) theorem div_neg' {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b < 0 := match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := neg_succ_lt_zero _ end @[simp] protected theorem div_one : ∀ (a : ℤ), a / 1 = a | 0 := show of_nat _ = _, by simp | (n+1:ℕ) := congr_arg of_nat (nat.div_one _) | -[1+ n] := congr_arg neg_succ_of_nat (nat.div_one _) theorem div_eq_zero_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a / b = 0 := match a, b, eq_coe_of_zero_le H1, eq_succ_of_zero_lt (lt_of_le_of_lt H1 H2), H2 with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 := congr_arg of_nat $ nat.div_eq_of_lt $ lt_of_coe_nat_lt_coe_nat H2 end theorem div_eq_zero_of_lt_abs {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < |b|) : a / b = 0 := match b, |b|, abs_eq_nat_abs b, H2 with | (n : ℕ), ._, rfl, H2 := div_eq_zero_of_lt H1 H2 | -[1+ n], ._, rfl, H2 := neg_injective $ by rw [← int.div_neg]; exact div_eq_zero_of_lt H1 H2 end protected theorem add_mul_div_right (a b : ℤ) {c : ℤ} (H : c ≠ 0) : (a + b * c) / c = a / c + b := have ∀ {k n : ℕ} {a : ℤ}, (a + n * k.succ) / k.succ = a / k.succ + n, from λ k n a, match a with | (m : ℕ) := congr_arg of_nat $ nat.add_mul_div_right _ _ k.succ_pos | -[1+ m] := show ((n * k.succ:ℕ) - m.succ : ℤ) / k.succ = n - (m / k.succ + 1 : ℕ), begin cases lt_or_ge m (n*k.succ) with h h, { rw [← int.coe_nat_sub h, ← int.coe_nat_sub ((nat.div_lt_iff_lt_mul _ _ k.succ_pos).2 h)], apply congr_arg of_nat, rw [mul_comm, nat.mul_sub_div], rwa mul_comm }, { change (↑(n * nat.succ k) - (m + 1) : ℤ) / ↑(nat.succ k) = ↑n - ((m / nat.succ k : ℕ) + 1), rw [← sub_sub, ← sub_sub, ← neg_sub (m:ℤ), ← neg_sub _ (n:ℤ), ← int.coe_nat_sub h, ← int.coe_nat_sub ((nat.le_div_iff_mul_le _ _ k.succ_pos).2 h), ← neg_succ_of_nat_coe', ← neg_succ_of_nat_coe'], { apply congr_arg neg_succ_of_nat, rw [mul_comm, nat.sub_mul_div], rwa mul_comm } } end end, have ∀ {a b c : ℤ}, 0 < c → (a + b * c) / c = a / c + b, from λ a b c H, match c, eq_succ_of_zero_lt H, b with | ._, ⟨k, rfl⟩, (n : ℕ) := this | ._, ⟨k, rfl⟩, -[1+ n] := show (a - n.succ * k.succ) / k.succ = (a / k.succ) - n.succ, from eq_sub_of_add_eq $ by rw [← this, sub_add_cancel] end, match lt_trichotomy c 0 with | or.inl hlt := neg_inj.1 $ by rw [← int.div_neg, neg_add, ← int.div_neg, ← neg_mul_neg]; apply this (neg_pos_of_neg hlt) | or.inr (or.inl heq) := absurd heq H | or.inr (or.inr hgt) := this hgt end protected theorem add_mul_div_left (a : ℤ) {b : ℤ} (c : ℤ) (H : b ≠ 0) : (a + b * c) / b = a / b + c := by rw [mul_comm, int.add_mul_div_right _ _ H] protected theorem add_div_of_dvd_right {a b c : ℤ} (H : c ∣ b) : (a + b) / c = a / c + b / c := begin by_cases h1 : c = 0, { simp [h1] }, cases H with k hk, rw hk, change c ≠ 0 at h1, rw [mul_comm c k, int.add_mul_div_right _ _ h1, ←zero_add (k * c), int.add_mul_div_right _ _ h1, int.zero_div, zero_add] end protected theorem add_div_of_dvd_left {a b c : ℤ} (H : c ∣ a) : (a + b) / c = a / c + b / c := by rw [add_comm, int.add_div_of_dvd_right H, add_comm] @[simp] protected theorem mul_div_cancel (a : ℤ) {b : ℤ} (H : b ≠ 0) : a * b / b = a := by have := int.add_mul_div_right 0 a H; rwa [zero_add, int.zero_div, zero_add] at this @[simp] protected theorem mul_div_cancel_left {a : ℤ} (b : ℤ) (H : a ≠ 0) : a * b / a = b := by rw [mul_comm, int.mul_div_cancel _ H] @[simp] protected theorem div_self {a : ℤ} (H : a ≠ 0) : a / a = 1 := by have := int.mul_div_cancel 1 H; rwa one_mul at this /-! ### mod -/ theorem of_nat_mod (m n : nat) : (m % n : ℤ) = of_nat (m % n) := rfl @[simp, norm_cast] theorem coe_nat_mod (m n : ℕ) : (↑(m % n) : ℤ) = ↑m % ↑n := rfl theorem neg_succ_of_nat_mod (m : ℕ) {b : ℤ} (bpos : 0 < b) : -[1+m] % b = b - 1 - m % b := by rw [sub_sub, add_comm]; exact match b, eq_succ_of_zero_lt bpos with ._, ⟨n, rfl⟩ := rfl end @[simp] theorem mod_neg : ∀ (a b : ℤ), a % -b = a % b | (m : ℕ) n := @congr_arg ℕ ℤ _ _ (λ i, ↑(m % i)) (nat_abs_neg _) | -[1+ m] n := @congr_arg ℕ ℤ _ _ (λ i, sub_nat_nat i (nat.succ (m % i))) (nat_abs_neg _) @[simp] theorem mod_abs (a b : ℤ) : a % (|b|) = a % b := abs_by_cases (λ i, a % i = a % b) rfl (mod_neg _ _) local attribute [simp] -- Will be generalized to Euclidean domains. theorem zero_mod (b : ℤ) : 0 % b = 0 := rfl local attribute [simp] -- Will be generalized to Euclidean domains. theorem mod_zero : ∀ (a : ℤ), a % 0 = a | (m : ℕ) := congr_arg of_nat $ nat.mod_zero _ | -[1+ m] := congr_arg neg_succ_of_nat $ nat.mod_zero _ local attribute [simp] -- Will be generalized to Euclidean domains. theorem mod_one : ∀ (a : ℤ), a % 1 = 0 | (m : ℕ) := congr_arg of_nat $ nat.mod_one _ | -[1+ m] := show (1 - (m % 1).succ : ℤ) = 0, by rw nat.mod_one; refl theorem mod_eq_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a % b = a := match a, b, eq_coe_of_zero_le H1, eq_coe_of_zero_le (le_trans H1 (le_of_lt H2)), H2 with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 := congr_arg of_nat $ nat.mod_eq_of_lt (lt_of_coe_nat_lt_coe_nat H2) end theorem mod_nonneg : ∀ (a : ℤ) {b : ℤ}, b ≠ 0 → 0 ≤ a % b | (m : ℕ) n H := coe_zero_le _ | -[1+ m] n H := sub_nonneg_of_le $ coe_nat_le_coe_nat_of_le $ nat.mod_lt _ (nat_abs_pos_of_ne_zero H) theorem mod_lt_of_pos (a : ℤ) {b : ℤ} (H : 0 < b) : a % b < b := match a, b, eq_succ_of_zero_lt H with | (m : ℕ), ._, ⟨n, rfl⟩ := coe_nat_lt_coe_nat_of_lt (nat.mod_lt _ (nat.succ_pos _)) | -[1+ m], ._, ⟨n, rfl⟩ := sub_lt_self _ (coe_nat_lt_coe_nat_of_lt $ nat.succ_pos _) end theorem mod_lt (a : ℤ) {b : ℤ} (H : b ≠ 0) : a % b < |b| := by rw [← mod_abs]; exact mod_lt_of_pos _ (abs_pos.2 H) theorem mod_add_div_aux (m n : ℕ) : (n - (m % n + 1) - (n * (m / n) + n) : ℤ) = -[1+ m] := begin rw [← sub_sub, neg_succ_of_nat_coe, sub_sub (n:ℤ)], apply eq_neg_of_eq_neg, rw [neg_sub, sub_sub_self, add_right_comm], exact @congr_arg ℕ ℤ _ _ (λi, (i + 1 : ℤ)) (nat.mod_add_div _ _).symm end theorem mod_add_div : ∀ (a b : ℤ), a % b + b * (a / b) = a | (m : ℕ) 0 := congr_arg of_nat (nat.mod_add_div _ _) | (m : ℕ) (n+1:ℕ) := congr_arg of_nat (nat.mod_add_div _ _) | 0 -[1+ n] := by simp | (m+1:ℕ) -[1+ n] := show (_ + -(n+1) * -((m + 1) / (n + 1) : ℕ) : ℤ) = _, by rw [neg_mul_neg]; exact congr_arg of_nat (nat.mod_add_div _ _) | -[1+ m] 0 := by rw [mod_zero, int.div_zero]; refl | -[1+ m] (n+1:ℕ) := mod_add_div_aux m n.succ | -[1+ m] -[1+ n] := mod_add_div_aux m n.succ theorem div_add_mod (a b : ℤ) : b * (a / b) + a % b = a := (add_comm _ _).trans (mod_add_div _ _) lemma mod_add_div' (m k : ℤ) : m % k + (m / k) * k = m := by { rw mul_comm, exact mod_add_div _ _ } lemma div_add_mod' (m k : ℤ) : (m / k) * k + m % k = m := by { rw mul_comm, exact div_add_mod _ _ } theorem mod_def (a b : ℤ) : a % b = a - b * (a / b) := eq_sub_of_add_eq (mod_add_div _ _) @[simp] theorem add_mul_mod_self {a b c : ℤ} : (a + b * c) % c = a % c := if cz : c = 0 then by rw [cz, mul_zero, add_zero] else by rw [mod_def, mod_def, int.add_mul_div_right _ _ cz, mul_add, mul_comm, add_sub_add_right_eq_sub] @[simp] theorem add_mul_mod_self_left (a b c : ℤ) : (a + b * c) % b = a % b := by rw [mul_comm, add_mul_mod_self] @[simp] theorem add_mod_self {a b : ℤ} : (a + b) % b = a % b := by have := add_mul_mod_self_left a b 1; rwa mul_one at this @[simp] theorem add_mod_self_left {a b : ℤ} : (a + b) % a = b % a := by rw [add_comm, add_mod_self] @[simp] theorem mod_add_mod (m n k : ℤ) : (m % n + k) % n = (m + k) % n := by have := (add_mul_mod_self_left (m % n + k) n (m / n)).symm; rwa [add_right_comm, mod_add_div] at this @[simp] theorem add_mod_mod (m n k : ℤ) : (m + n % k) % k = (m + n) % k := by rw [add_comm, mod_add_mod, add_comm] lemma add_mod (a b n : ℤ) : (a + b) % n = ((a % n) + (b % n)) % n := by rw [add_mod_mod, mod_add_mod] theorem add_mod_eq_add_mod_right {m n k : ℤ} (i : ℤ) (H : m % n = k % n) : (m + i) % n = (k + i) % n := by rw [← mod_add_mod, ← mod_add_mod k, H] theorem add_mod_eq_add_mod_left {m n k : ℤ} (i : ℤ) (H : m % n = k % n) : (i + m) % n = (i + k) % n := by rw [add_comm, add_mod_eq_add_mod_right _ H, add_comm] theorem mod_add_cancel_right {m n k : ℤ} (i) : (m + i) % n = (k + i) % n ↔ m % n = k % n := ⟨λ H, by have := add_mod_eq_add_mod_right (-i) H; rwa [add_neg_cancel_right, add_neg_cancel_right] at this, add_mod_eq_add_mod_right _⟩ theorem mod_add_cancel_left {m n k i : ℤ} : (i + m) % n = (i + k) % n ↔ m % n = k % n := by rw [add_comm, add_comm i, mod_add_cancel_right] theorem mod_sub_cancel_right {m n k : ℤ} (i) : (m - i) % n = (k - i) % n ↔ m % n = k % n := mod_add_cancel_right _ theorem mod_eq_mod_iff_mod_sub_eq_zero {m n k : ℤ} : m % n = k % n ↔ (m - k) % n = 0 := (mod_sub_cancel_right k).symm.trans $ by simp @[simp] theorem mul_mod_left (a b : ℤ) : (a * b) % b = 0 := by rw [← zero_add (a * b), add_mul_mod_self, zero_mod] @[simp] theorem mul_mod_right (a b : ℤ) : (a * b) % a = 0 := by rw [mul_comm, mul_mod_left] lemma mul_mod (a b n : ℤ) : (a * b) % n = ((a % n) * (b % n)) % n := begin conv_lhs { rw [←mod_add_div a n, ←mod_add_div' b n, right_distrib, left_distrib, left_distrib, mul_assoc, mul_assoc, ←left_distrib n _ _, add_mul_mod_self_left, ← mul_assoc, add_mul_mod_self] } end @[simp] lemma neg_mod_two (i : ℤ) : (-i) % 2 = i % 2 := begin apply int.mod_eq_mod_iff_mod_sub_eq_zero.mpr, convert int.mul_mod_right 2 (-i), simp only [two_mul, sub_eq_add_neg] end local attribute [simp] -- Will be generalized to Euclidean domains. theorem mod_self {a : ℤ} : a % a = 0 := by have := mul_mod_left 1 a; rwa one_mul at this @[simp] theorem mod_mod_of_dvd (n : ℤ) {m k : ℤ} (h : m ∣ k) : n % k % m = n % m := begin conv { to_rhs, rw ←mod_add_div n k }, rcases h with ⟨t, rfl⟩, rw [mul_assoc, add_mul_mod_self_left] end @[simp] theorem mod_mod (a b : ℤ) : a % b % b = a % b := by conv {to_rhs, rw [← mod_add_div a b, add_mul_mod_self_left]} lemma sub_mod (a b n : ℤ) : (a - b) % n = ((a % n) - (b % n)) % n := begin apply (mod_add_cancel_right b).mp, rw [sub_add_cancel, ← add_mod_mod, sub_add_cancel, mod_mod] end /-! ### properties of `/` and `%` -/ @[simp] theorem mul_div_mul_of_pos {a : ℤ} (b c : ℤ) (H : 0 < a) : a * b / (a * c) = b / c := suffices ∀ (m k : ℕ) (b : ℤ), (m.succ * b / (m.succ * k) : ℤ) = b / k, from match a, eq_succ_of_zero_lt H, c, eq_coe_or_neg c with | ._, ⟨m, rfl⟩, ._, ⟨k, or.inl rfl⟩ := this _ _ _ | ._, ⟨m, rfl⟩, ._, ⟨k, or.inr rfl⟩ := by rw [← neg_mul_eq_mul_neg, int.div_neg, int.div_neg]; apply congr_arg has_neg.neg; apply this end, λ m k b, match b, k with | (n : ℕ), k := congr_arg of_nat (nat.mul_div_mul _ _ m.succ_pos) | -[1+ n], 0 := by rw [int.coe_nat_zero, mul_zero, int.div_zero, int.div_zero] | -[1+ n], k+1 := congr_arg neg_succ_of_nat $ show (m.succ * n + m) / (m.succ * k.succ) = n / k.succ, begin apply nat.div_eq_of_lt_le, { refine le_trans _ (nat.le_add_right _ _), rw [← nat.mul_div_mul _ _ m.succ_pos], apply nat.div_mul_le_self }, { change m.succ * n.succ ≤ _, rw [mul_left_comm], apply nat.mul_le_mul_left, apply (nat.div_lt_iff_lt_mul _ _ k.succ_pos).1, apply nat.lt_succ_self } end end @[simp] theorem mul_div_mul_of_pos_left (a : ℤ) {b : ℤ} (H : 0 < b) (c : ℤ) : a * b / (c * b) = a / c := by rw [mul_comm, mul_comm c, mul_div_mul_of_pos _ _ H] @[simp] theorem mul_mod_mul_of_pos {a : ℤ} (H : 0 < a) (b c : ℤ) : a * b % (a * c) = a * (b % c) := by rw [mod_def, mod_def, mul_div_mul_of_pos _ _ H, mul_sub_left_distrib, mul_assoc] theorem lt_div_add_one_mul_self (a : ℤ) {b : ℤ} (H : 0 < b) : a < (a / b + 1) * b := by { rw [add_mul, one_mul, mul_comm, ← sub_lt_iff_lt_add', ← mod_def], exact mod_lt_of_pos _ H } theorem abs_div_le_abs : ∀ (a b : ℤ), |a / b| ≤ |a| := suffices ∀ (a : ℤ) (n : ℕ), |a / n| ≤ |a|, from λ a b, match b, eq_coe_or_neg b with | ._, ⟨n, or.inl rfl⟩ := this _ _ | ._, ⟨n, or.inr rfl⟩ := by rw [int.div_neg, abs_neg]; apply this end, λ a n, by rw [abs_eq_nat_abs, abs_eq_nat_abs]; exact coe_nat_le_coe_nat_of_le (match a, n with | (m : ℕ), n := nat.div_le_self _ _ | -[1+ m], 0 := nat.zero_le _ | -[1+ m], n+1 := nat.succ_le_succ (nat.div_le_self _ _) end) theorem div_le_self {a : ℤ} (b : ℤ) (Ha : 0 ≤ a) : a / b ≤ a := by have := le_trans (le_abs_self _) (abs_div_le_abs a b); rwa [abs_of_nonneg Ha] at this theorem mul_div_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : b * (a / b) = a := by have := mod_add_div a b; rwa [H, zero_add] at this theorem div_mul_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : a / b * b = a := by rw [mul_comm, mul_div_cancel_of_mod_eq_zero H] lemma mod_two_eq_zero_or_one (n : ℤ) : n % 2 = 0 ∨ n % 2 = 1 := have h : n % 2 < 2 := abs_of_nonneg (show 0 ≤ (2 : ℤ), from dec_trivial) ▸ int.mod_lt _ dec_trivial, have h₁ : 0 ≤ n % 2 := int.mod_nonneg _ dec_trivial, match (n % 2), h, h₁ with | (0 : ℕ) := λ _ _, or.inl rfl | (1 : ℕ) := λ _ _, or.inr rfl | (k + 2 : ℕ) := λ h _, absurd h dec_trivial | -[1+ a] := λ _ h₁, absurd h₁ dec_trivial end /-! ### dvd -/ @[norm_cast] theorem coe_nat_dvd {m n : ℕ} : (↑m : ℤ) ∣ ↑n ↔ m ∣ n := ⟨λ ⟨a, ae⟩, m.eq_zero_or_pos.elim (λm0, by simp [m0] at ae; simp [ae, m0]) (λm0l, by { cases eq_coe_of_zero_le (@nonneg_of_mul_nonneg_left ℤ _ m a (by simp [ae.symm]) (by simpa using m0l)) with k e, subst a, exact ⟨k, int.coe_nat_inj ae⟩ }), λ ⟨k, e⟩, dvd.intro k $ by rw [e, int.coe_nat_mul]⟩ theorem coe_nat_dvd_left {n : ℕ} {z : ℤ} : (↑n : ℤ) ∣ z ↔ n ∣ z.nat_abs := by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd] theorem coe_nat_dvd_right {n : ℕ} {z : ℤ} : z ∣ (↑n : ℤ) ↔ z.nat_abs ∣ n := by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd] theorem dvd_antisymm {a b : ℤ} (H1 : 0 ≤ a) (H2 : 0 ≤ b) : a ∣ b → b ∣ a → a = b := begin rw [← abs_of_nonneg H1, ← abs_of_nonneg H2, abs_eq_nat_abs, abs_eq_nat_abs], rw [coe_nat_dvd, coe_nat_dvd, coe_nat_inj'], apply nat.dvd_antisymm end theorem dvd_of_mod_eq_zero {a b : ℤ} (H : b % a = 0) : a ∣ b := ⟨b / a, (mul_div_cancel_of_mod_eq_zero H).symm⟩ theorem mod_eq_zero_of_dvd : ∀ {a b : ℤ}, a ∣ b → b % a = 0 | a ._ ⟨c, rfl⟩ := mul_mod_right _ _ theorem dvd_iff_mod_eq_zero (a b : ℤ) : a ∣ b ↔ b % a = 0 := ⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩ /-- If `a % b = c` then `b` divides `a - c`. -/ lemma dvd_sub_of_mod_eq {a b c : ℤ} (h : a % b = c) : b ∣ a - c := begin have hx : a % b % b = c % b, { rw h }, rw [mod_mod, ←mod_sub_cancel_right c, sub_self, zero_mod] at hx, exact dvd_of_mod_eq_zero hx end theorem nat_abs_dvd {a b : ℤ} : (a.nat_abs : ℤ) ∣ b ↔ a ∣ b := (nat_abs_eq a).elim (λ e, by rw ← e) (λ e, by rw [← neg_dvd, ← e]) theorem dvd_nat_abs {a b : ℤ} : a ∣ b.nat_abs ↔ a ∣ b := (nat_abs_eq b).elim (λ e, by rw ← e) (λ e, by rw [← dvd_neg, ← e]) instance decidable_dvd : @decidable_rel ℤ (∣) := assume a n, decidable_of_decidable_of_iff (by apply_instance) (dvd_iff_mod_eq_zero _ _).symm protected theorem div_mul_cancel {a b : ℤ} (H : b ∣ a) : a / b * b = a := div_mul_cancel_of_mod_eq_zero (mod_eq_zero_of_dvd H) protected theorem mul_div_cancel' {a b : ℤ} (H : a ∣ b) : a * (b / a) = b := by rw [mul_comm, int.div_mul_cancel H] protected theorem mul_div_assoc (a : ℤ) : ∀ {b c : ℤ}, c ∣ b → (a * b) / c = a * (b / c) | ._ c ⟨d, rfl⟩ := if cz : c = 0 then by simp [cz] else by rw [mul_left_comm, int.mul_div_cancel_left _ cz, int.mul_div_cancel_left _ cz] protected theorem mul_div_assoc' (b : ℤ) {a c : ℤ} (h : c ∣ a) : a * b / c = a / c * b := by rw [mul_comm, int.mul_div_assoc _ h, mul_comm] theorem div_dvd_div : ∀ {a b c : ℤ} (H1 : a ∣ b) (H2 : b ∣ c), b / a ∣ c / a | a ._ ._ ⟨b, rfl⟩ ⟨c, rfl⟩ := if az : a = 0 then by simp [az] else by rw [int.mul_div_cancel_left _ az, mul_assoc, int.mul_div_cancel_left _ az]; apply dvd_mul_right protected theorem eq_mul_of_div_eq_right {a b c : ℤ} (H1 : b ∣ a) (H2 : a / b = c) : a = b * c := by rw [← H2, int.mul_div_cancel' H1] protected theorem div_eq_of_eq_mul_right {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = b * c) : a / b = c := by rw [H2, int.mul_div_cancel_left _ H1] protected theorem eq_div_of_mul_eq_right {a b c : ℤ} (H1 : a ≠ 0) (H2 : a * b = c) : b = c / a := eq.symm $ int.div_eq_of_eq_mul_right H1 H2.symm protected theorem div_eq_iff_eq_mul_right {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) : a / b = c ↔ a = b * c := ⟨int.eq_mul_of_div_eq_right H', int.div_eq_of_eq_mul_right H⟩ protected theorem div_eq_iff_eq_mul_left {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) : a / b = c ↔ a = c * b := by rw mul_comm; exact int.div_eq_iff_eq_mul_right H H' protected theorem eq_mul_of_div_eq_left {a b c : ℤ} (H1 : b ∣ a) (H2 : a / b = c) : a = c * b := by rw [mul_comm, int.eq_mul_of_div_eq_right H1 H2] protected theorem div_eq_of_eq_mul_left {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = c * b) : a / b = c := int.div_eq_of_eq_mul_right H1 (by rw [mul_comm, H2]) protected lemma eq_zero_of_div_eq_zero {d n : ℤ} (h : d ∣ n) (H : n / d = 0) : n = 0 := by rw [← int.mul_div_cancel' h, H, mul_zero] theorem neg_div_of_dvd : ∀ {a b : ℤ} (H : b ∣ a), -a / b = -(a / b) | ._ b ⟨c, rfl⟩ := if bz : b = 0 then by simp [bz] else by rw [neg_mul_eq_mul_neg, int.mul_div_cancel_left _ bz, int.mul_div_cancel_left _ bz] lemma sub_div_of_dvd (a : ℤ) {b c : ℤ} (hcb : c ∣ b) : (a - b) / c = a / c - b / c := begin rw [sub_eq_add_neg, sub_eq_add_neg, int.add_div_of_dvd_right ((dvd_neg c b).mpr hcb)], congr, exact neg_div_of_dvd hcb, end lemma sub_div_of_dvd_sub {a b c : ℤ} (hcab : c ∣ (a - b)) : (a - b) / c = a / c - b / c := by rw [eq_sub_iff_add_eq, ← int.add_div_of_dvd_left hcab, sub_add_cancel] theorem div_sign : ∀ a b, a / sign b = a * sign b | a (n+1:ℕ) := by unfold sign; simp | a 0 := by simp [sign] | a -[1+ n] := by simp [sign] @[simp] theorem sign_mul : ∀ a b, sign (a * b) = sign a * sign b | a 0 := by simp | 0 b := by simp | (m+1:ℕ) (n+1:ℕ) := rfl | (m+1:ℕ) -[1+ n] := rfl | -[1+ m] (n+1:ℕ) := rfl | -[1+ m] -[1+ n] := rfl protected theorem sign_eq_div_abs (a : ℤ) : sign a = a / |a| := if az : a = 0 then by simp [az] else (int.div_eq_of_eq_mul_left (mt abs_eq_zero.1 az) (sign_mul_abs _).symm).symm theorem mul_sign : ∀ (i : ℤ), i * sign i = nat_abs i | (n+1:ℕ) := mul_one _ | 0 := mul_zero _ | -[1+ n] := mul_neg_one _ @[simp] theorem sign_pow_bit1 (k : ℕ) : ∀ n : ℤ, n.sign ^ (bit1 k) = n.sign | (n+1:ℕ) := one_pow (bit1 k) | 0 := zero_pow (nat.zero_lt_bit1 k) | -[1+ n] := (neg_pow_bit1 1 k).trans (congr_arg (λ x, -x) (one_pow (bit1 k))) theorem le_of_dvd {a b : ℤ} (bpos : 0 < b) (H : a ∣ b) : a ≤ b := match a, b, eq_succ_of_zero_lt bpos, H with | (m : ℕ), ._, ⟨n, rfl⟩, H := coe_nat_le_coe_nat_of_le $ nat.le_of_dvd n.succ_pos $ coe_nat_dvd.1 H | -[1+ m], ._, ⟨n, rfl⟩, _ := le_trans (le_of_lt $ neg_succ_lt_zero _) (coe_zero_le _) end theorem eq_one_of_dvd_one {a : ℤ} (H : 0 ≤ a) (H' : a ∣ 1) : a = 1 := match a, eq_coe_of_zero_le H, H' with | ._, ⟨n, rfl⟩, H' := congr_arg coe $ nat.eq_one_of_dvd_one $ coe_nat_dvd.1 H' end theorem eq_one_of_mul_eq_one_right {a b : ℤ} (H : 0 ≤ a) (H' : a * b = 1) : a = 1 := eq_one_of_dvd_one H ⟨b, H'.symm⟩ theorem eq_one_of_mul_eq_one_left {a b : ℤ} (H : 0 ≤ b) (H' : a * b = 1) : b = 1 := eq_one_of_mul_eq_one_right H (by rw [mul_comm, H']) lemma of_nat_dvd_of_dvd_nat_abs {a : ℕ} : ∀ {z : ℤ} (haz : a ∣ z.nat_abs), ↑a ∣ z | (int.of_nat _) haz := int.coe_nat_dvd.2 haz | -[1+k] haz := begin change ↑a ∣ -(k+1 : ℤ), apply dvd_neg_of_dvd, apply int.coe_nat_dvd.2, exact haz end lemma dvd_nat_abs_of_of_nat_dvd {a : ℕ} : ∀ {z : ℤ} (haz : ↑a ∣ z), a ∣ z.nat_abs | (int.of_nat _) haz := int.coe_nat_dvd.1 (int.dvd_nat_abs.2 haz) | -[1+k] haz := have haz' : (↑a:ℤ) ∣ (↑(k+1):ℤ), from dvd_of_dvd_neg haz, int.coe_nat_dvd.1 haz' lemma pow_dvd_of_le_of_pow_dvd {p m n : ℕ} {k : ℤ} (hmn : m ≤ n) (hdiv : ↑(p ^ n) ∣ k) : ↑(p ^ m) ∣ k := begin induction k, { apply int.coe_nat_dvd.2, apply pow_dvd_of_le_of_pow_dvd hmn, apply int.coe_nat_dvd.1 hdiv }, change -[1+k] with -(↑(k+1) : ℤ), apply dvd_neg_of_dvd, apply int.coe_nat_dvd.2, apply pow_dvd_of_le_of_pow_dvd hmn, apply int.coe_nat_dvd.1, apply dvd_of_dvd_neg, exact hdiv, end 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 /-- If `n > 0` then `m` is not divisible by `n` iff it is between `n * k` and `n * (k + 1)` for some `k`. -/ lemma exists_lt_and_lt_iff_not_dvd (m : ℤ) {n : ℤ} (hn : 0 < n) : (∃ k, n * k < m ∧ m < n * (k + 1)) ↔ ¬ n ∣ m := begin split, { rintro ⟨k, h1k, h2k⟩ ⟨l, rfl⟩, rw [mul_lt_mul_left hn] at h1k h2k, rw [lt_add_one_iff, ← not_lt] at h2k, exact h2k h1k }, { intro h, rw [dvd_iff_mod_eq_zero, ← ne.def] at h, have := (mod_nonneg m hn.ne.symm).lt_of_ne h.symm, simp only [← mod_add_div m n] {single_pass := tt}, refine ⟨m / n, lt_add_of_pos_left _ this, _⟩, rw [add_comm _ (1 : ℤ), left_distrib, mul_one], exact add_lt_add_right (mod_lt_of_pos _ hn) _ } end /-! ### `/` and ordering -/ protected theorem div_mul_le (a : ℤ) {b : ℤ} (H : b ≠ 0) : a / b * b ≤ a := le_of_sub_nonneg $ by rw [mul_comm, ← mod_def]; apply mod_nonneg _ H protected theorem div_le_of_le_mul {a b c : ℤ} (H : 0 < c) (H' : a ≤ b * c) : a / c ≤ b := le_of_mul_le_mul_right (le_trans (int.div_mul_le _ (ne_of_gt H)) H') H protected theorem mul_lt_of_lt_div {a b c : ℤ} (H : 0 < c) (H3 : a < b / c) : a * c < b := lt_of_not_ge $ mt (int.div_le_of_le_mul H) (not_le_of_gt H3) protected theorem mul_le_of_le_div {a b c : ℤ} (H1 : 0 < c) (H2 : a ≤ b / c) : a * c ≤ b := le_trans (decidable.mul_le_mul_of_nonneg_right H2 (le_of_lt H1)) (int.div_mul_le _ (ne_of_gt H1)) protected theorem le_div_of_mul_le {a b c : ℤ} (H1 : 0 < c) (H2 : a * c ≤ b) : a ≤ b / c := le_of_lt_add_one $ lt_of_mul_lt_mul_right (lt_of_le_of_lt H2 (lt_div_add_one_mul_self _ H1)) (le_of_lt H1) protected theorem le_div_iff_mul_le {a b c : ℤ} (H : 0 < c) : a ≤ b / c ↔ a * c ≤ b := ⟨int.mul_le_of_le_div H, int.le_div_of_mul_le H⟩ protected theorem div_le_div {a b c : ℤ} (H : 0 < c) (H' : a ≤ b) : a / c ≤ b / c := int.le_div_of_mul_le H (le_trans (int.div_mul_le _ (ne_of_gt H)) H') protected theorem div_lt_of_lt_mul {a b c : ℤ} (H : 0 < c) (H' : a < b * c) : a / c < b := lt_of_not_ge $ mt (int.mul_le_of_le_div H) (not_le_of_gt H') protected theorem lt_mul_of_div_lt {a b c : ℤ} (H1 : 0 < c) (H2 : a / c < b) : a < b * c := lt_of_not_ge $ mt (int.le_div_of_mul_le H1) (not_le_of_gt H2) protected theorem div_lt_iff_lt_mul {a b c : ℤ} (H : 0 < c) : a / c < b ↔ a < b * c := ⟨int.lt_mul_of_div_lt H, int.div_lt_of_lt_mul H⟩ protected theorem le_mul_of_div_le {a b c : ℤ} (H1 : 0 ≤ b) (H2 : b ∣ a) (H3 : a / b ≤ c) : a ≤ c * b := by rw [← int.div_mul_cancel H2]; exact decidable.mul_le_mul_of_nonneg_right H3 H1 protected theorem lt_div_of_mul_lt {a b c : ℤ} (H1 : 0 ≤ b) (H2 : b ∣ c) (H3 : a * b < c) : a < c / b := lt_of_not_ge $ mt (int.le_mul_of_div_le H1 H2) (not_le_of_gt H3) protected theorem lt_div_iff_mul_lt {a b : ℤ} (c : ℤ) (H : 0 < c) (H' : c ∣ b) : a < b / c ↔ a * c < b := ⟨int.mul_lt_of_lt_div H, int.lt_div_of_mul_lt (le_of_lt H) H'⟩ theorem div_pos_of_pos_of_dvd {a b : ℤ} (H1 : 0 < a) (H2 : 0 ≤ b) (H3 : b ∣ a) : 0 < a / b := int.lt_div_of_mul_lt H2 H3 (by rwa zero_mul) theorem div_eq_div_of_mul_eq_mul {a b c d : ℤ} (H2 : d ∣ c) (H3 : b ≠ 0) (H4 : d ≠ 0) (H5 : a * d = b * c) : a / b = c / d := int.div_eq_of_eq_mul_right H3 $ by rw [← int.mul_div_assoc _ H2]; exact (int.div_eq_of_eq_mul_left H4 H5.symm).symm theorem eq_mul_div_of_mul_eq_mul_of_dvd_left {a b c d : ℤ} (hb : b ≠ 0) (hbc : b ∣ c) (h : b * a = c * d) : a = c / b * d := begin cases hbc with k hk, subst hk, rw [int.mul_div_cancel_left _ hb], rw mul_assoc at h, apply mul_left_cancel₀ hb h end /-- If an integer with larger absolute value divides an integer, it is zero. -/ lemma eq_zero_of_dvd_of_nat_abs_lt_nat_abs {a b : ℤ} (w : a ∣ b) (h : nat_abs b < nat_abs a) : b = 0 := begin rw [←nat_abs_dvd, ←dvd_nat_abs, coe_nat_dvd] at w, rw ←nat_abs_eq_zero, exact eq_zero_of_dvd_of_lt w h end lemma eq_zero_of_dvd_of_nonneg_of_lt {a b : ℤ} (w₁ : 0 ≤ a) (w₂ : a < b) (h : b ∣ a) : a = 0 := eq_zero_of_dvd_of_nat_abs_lt_nat_abs h (nat_abs_lt_nat_abs_of_nonneg_of_lt w₁ w₂) /-- If two integers are congruent to a sufficiently large modulus, they are equal. -/ lemma eq_of_mod_eq_of_nat_abs_sub_lt_nat_abs {a b c : ℤ} (h1 : a % b = c) (h2 : nat_abs (a - c) < nat_abs b) : a = c := eq_of_sub_eq_zero (eq_zero_of_dvd_of_nat_abs_lt_nat_abs (dvd_sub_of_mod_eq h1) h2) theorem of_nat_add_neg_succ_of_nat_of_lt {m n : ℕ} (h : m < n.succ) : of_nat m + -[1+n] = -[1+ n - m] := begin change sub_nat_nat _ _ = _, have h' : n.succ - m = (n - m).succ, apply succ_sub, apply le_of_lt_succ h, simp [*, sub_nat_nat] end theorem of_nat_add_neg_succ_of_nat_of_ge {m n : ℕ} (h : n.succ ≤ m) : of_nat m + -[1+n] = of_nat (m - n.succ) := begin change sub_nat_nat _ _ = _, have h' : n.succ - m = 0, apply tsub_eq_zero_iff_le.mpr h, simp [*, sub_nat_nat] end @[simp] theorem neg_add_neg (m n : ℕ) : -[1+m] + -[1+n] = -[1+nat.succ(m+n)] := rfl /-! ### to_nat -/ theorem to_nat_eq_max : ∀ (a : ℤ), (to_nat a : ℤ) = max a 0 | (n : ℕ) := (max_eq_left (coe_zero_le n)).symm | -[1+ n] := (max_eq_right (le_of_lt (neg_succ_lt_zero n))).symm @[simp] lemma to_nat_zero : (0 : ℤ).to_nat = 0 := rfl @[simp] lemma to_nat_one : (1 : ℤ).to_nat = 1 := rfl @[simp] theorem to_nat_of_nonneg {a : ℤ} (h : 0 ≤ a) : (to_nat a : ℤ) = a := by rw [to_nat_eq_max, max_eq_left h] @[simp] lemma to_nat_sub_of_le {a b : ℤ} (h : b ≤ a) : (to_nat (a - b) : ℤ) = a - b := int.to_nat_of_nonneg (sub_nonneg_of_le h) @[simp] theorem to_nat_coe_nat (n : ℕ) : to_nat ↑n = n := rfl @[simp] lemma to_nat_coe_nat_add_one {n : ℕ} : ((n : ℤ) + 1).to_nat = n + 1 := rfl theorem le_to_nat (a : ℤ) : a ≤ to_nat a := by rw [to_nat_eq_max]; apply le_max_left @[simp] theorem to_nat_le {a : ℤ} {n : ℕ} : to_nat a ≤ n ↔ a ≤ n := by rw [(coe_nat_le_coe_nat_iff _ _).symm, to_nat_eq_max, max_le_iff]; exact and_iff_left (coe_zero_le _) @[simp] theorem lt_to_nat {n : ℕ} {a : ℤ} : n < to_nat a ↔ (n : ℤ) < a := le_iff_le_iff_lt_iff_lt.1 to_nat_le @[simp]lemma le_to_nat_iff {n : ℕ} {z : ℤ} (h : 0 ≤ z) : n ≤ z.to_nat ↔ (n : ℤ) ≤ z := by rw [←int.coe_nat_le_coe_nat_iff, int.to_nat_of_nonneg h] theorem to_nat_le_to_nat {a b : ℤ} (h : a ≤ b) : to_nat a ≤ to_nat b := by rw to_nat_le; exact le_trans h (le_to_nat b) theorem to_nat_lt_to_nat {a b : ℤ} (hb : 0 < b) : to_nat a < to_nat b ↔ a < b := ⟨λ h, begin cases a, exact lt_to_nat.1 h, exact lt_trans (neg_succ_of_nat_lt_zero a) hb, end, λ h, begin rw lt_to_nat, cases a, exact h, exact hb end⟩ theorem lt_of_to_nat_lt {a b : ℤ} (h : to_nat a < to_nat b) : a < b := (to_nat_lt_to_nat $ lt_to_nat.1 $ lt_of_le_of_lt (nat.zero_le _) h).1 h lemma to_nat_add {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : (a + b).to_nat = a.to_nat + b.to_nat := begin lift a to ℕ using ha, lift b to ℕ using hb, norm_cast, end lemma to_nat_add_nat {a : ℤ} (ha : 0 ≤ a) (n : ℕ) : (a + n).to_nat = a.to_nat + n := begin lift a to ℕ using ha, norm_cast, end @[simp] lemma pred_to_nat : ∀ (i : ℤ), (i - 1).to_nat = i.to_nat - 1 | (0:ℕ) := rfl | (n+1:ℕ) := by simp | -[1+ n] := rfl @[simp] lemma to_nat_pred_coe_of_pos {i : ℤ} (h : 0 < i) : ((i.to_nat - 1 : ℕ) : ℤ) = i - 1 := by simp [h, le_of_lt h] with push_cast @[simp] lemma to_nat_sub_to_nat_neg : ∀ (n : ℤ), ↑n.to_nat - ↑((-n).to_nat) = n | (0 : ℕ) := rfl | (n+1 : ℕ) := show ↑(n+1) - (0:ℤ) = n+1, from sub_zero _ | -[1+ n] := show 0 - (n+1 : ℤ) = _, from zero_sub _ @[simp] lemma to_nat_add_to_nat_neg_eq_nat_abs : ∀ (n : ℤ), (n.to_nat) + ((-n).to_nat) = n.nat_abs | (0 : ℕ) := rfl | (n+1 : ℕ) := show (n+1) + 0 = n+1, from add_zero _ | -[1+ n] := show 0 + (n+1) = n+1, from zero_add _ /-- If `n : ℕ`, then `int.to_nat' n = some n`, if `n : ℤ` is negative, then `int.to_nat' n = none`. -/ def to_nat' : ℤ → option ℕ | (n : ℕ) := some n | -[1+ n] := none theorem mem_to_nat' : ∀ (a : ℤ) (n : ℕ), n ∈ to_nat' a ↔ a = n | (m : ℕ) n := option.some_inj.trans coe_nat_inj'.symm | -[1+ m] n := by split; intro h; cases h lemma to_nat_of_nonpos : ∀ {z : ℤ}, z ≤ 0 → z.to_nat = 0 | (0 : ℕ) := λ _, rfl | (n + 1 : ℕ) := λ h, (h.not_lt (by { exact_mod_cast nat.succ_pos n })).elim | (-[1+ n]) := λ _, rfl /-! ### units -/ @[simp] theorem units_nat_abs (u : units ℤ) : nat_abs u = 1 := units.ext_iff.1 $ nat.units_eq_one ⟨nat_abs u, nat_abs ↑u⁻¹, by rw [← nat_abs_mul, units.mul_inv]; refl, by rw [← nat_abs_mul, units.inv_mul]; refl⟩ theorem units_eq_one_or (u : units ℤ) : u = 1 ∨ u = -1 := by simpa only [units.ext_iff, units_nat_abs] using nat_abs_eq u lemma is_unit_eq_one_or {a : ℤ} : is_unit a → a = 1 ∨ a = -1 | ⟨x, hx⟩ := hx ▸ (units_eq_one_or _).imp (congr_arg coe) (congr_arg coe) lemma is_unit_iff {a : ℤ} : is_unit a ↔ a = 1 ∨ a = -1 := begin refine ⟨λ h, is_unit_eq_one_or h, λ h, _⟩, rcases h with rfl | rfl, { exact is_unit_one }, { exact is_unit_one.neg } end theorem is_unit_iff_nat_abs_eq {n : ℤ} : is_unit n ↔ n.nat_abs = 1 := by simp [nat_abs_eq_iff, is_unit_iff] lemma units_inv_eq_self (u : units ℤ) : u⁻¹ = u := (units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl) @[simp] lemma units_mul_self (u : units ℤ) : u * u = 1 := (units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl) -- `units.coe_mul` is a "wrong turn" for the simplifier, this undoes it and simplifies further @[simp] lemma units_coe_mul_self (u : units ℤ) : (u * u : ℤ) = 1 := by rw [←units.coe_mul, units_mul_self, units.coe_one] @[simp] lemma neg_one_pow_ne_zero {n : ℕ} : (-1 : ℤ)^n ≠ 0 := pow_ne_zero _ (abs_pos.mp trivial) /-! ### bitwise ops -/ @[simp] lemma bodd_zero : bodd 0 = ff := rfl @[simp] lemma bodd_one : bodd 1 = tt := rfl lemma bodd_two : bodd 2 = ff := rfl @[simp, norm_cast] lemma bodd_coe (n : ℕ) : int.bodd n = nat.bodd n := rfl @[simp] lemma bodd_sub_nat_nat (m n : ℕ) : bodd (sub_nat_nat m n) = bxor m.bodd n.bodd := by apply sub_nat_nat_elim m n (λ m n i, bodd i = bxor m.bodd n.bodd); intros; simp; cases i.bodd; simp @[simp] lemma bodd_neg_of_nat (n : ℕ) : bodd (neg_of_nat n) = n.bodd := by cases n; simp; refl @[simp] lemma bodd_neg (n : ℤ) : bodd (-n) = bodd n := by cases n; simp [has_neg.neg, int.coe_nat_eq, int.neg, bodd, -of_nat_eq_coe] @[simp] lemma bodd_add (m n : ℤ) : bodd (m + n) = bxor (bodd m) (bodd n) := by cases m with m m; cases n with n n; unfold has_add.add; simp [int.add, -of_nat_eq_coe, bool.bxor_comm] @[simp] lemma bodd_mul (m n : ℤ) : bodd (m * n) = bodd m && bodd n := by cases m with m m; cases n with n n; simp [← int.mul_def, int.mul, -of_nat_eq_coe, bool.bxor_comm] theorem bodd_add_div2 : ∀ n, cond (bodd n) 1 0 + 2 * div2 n = n | (n : ℕ) := by rw [show (cond (bodd n) 1 0 : ℤ) = (cond (bodd n) 1 0 : ℕ), by cases bodd n; refl]; exact congr_arg of_nat n.bodd_add_div2 | -[1+ n] := begin refine eq.trans _ (congr_arg neg_succ_of_nat n.bodd_add_div2), dsimp [bodd], cases nat.bodd n; dsimp [cond, bnot, div2, int.mul], { change -[1+ 2 * nat.div2 n] = _, rw zero_add }, { rw [zero_add, add_comm], refl } end theorem div2_val : ∀ n, div2 n = n / 2 | (n : ℕ) := congr_arg of_nat n.div2_val | -[1+ n] := congr_arg neg_succ_of_nat n.div2_val lemma bit0_val (n : ℤ) : bit0 n = 2 * n := (two_mul _).symm lemma bit1_val (n : ℤ) : bit1 n = 2 * n + 1 := congr_arg (+(1:ℤ)) (bit0_val _) lemma bit_val (b n) : bit b n = 2 * n + cond b 1 0 := by { cases b, apply (bit0_val n).trans (add_zero _).symm, apply bit1_val } lemma bit_decomp (n : ℤ) : bit (bodd n) (div2 n) = n := (bit_val _ _).trans $ (add_comm _ _).trans $ bodd_add_div2 _ /-- Defines a function from `ℤ` conditionally, if it is defined for odd and even integers separately using `bit`. -/ def {u} bit_cases_on {C : ℤ → Sort u} (n) (h : ∀ b n, C (bit b n)) : C n := by rw [← bit_decomp n]; apply h @[simp] lemma bit_zero : bit ff 0 = 0 := rfl @[simp] lemma bit_coe_nat (b) (n : ℕ) : bit b n = nat.bit b n := by rw [bit_val, nat.bit_val]; cases b; refl @[simp] lemma bit_neg_succ (b) (n : ℕ) : bit b -[1+ n] = -[1+ nat.bit (bnot b) n] := by rw [bit_val, nat.bit_val]; cases b; refl @[simp] lemma bodd_bit (b n) : bodd (bit b n) = b := by rw bit_val; simp; cases b; cases bodd n; refl @[simp] lemma bodd_bit0 (n : ℤ) : bodd (bit0 n) = ff := bodd_bit ff n @[simp] lemma bodd_bit1 (n : ℤ) : bodd (bit1 n) = tt := bodd_bit tt n @[simp] lemma div2_bit (b n) : div2 (bit b n) = n := begin rw [bit_val, div2_val, add_comm, int.add_mul_div_left, (_ : (_/2:ℤ) = 0), zero_add], cases b, { simp }, { show of_nat _ = _, rw nat.div_eq_zero; simp }, { cc } end lemma bit0_ne_bit1 (m n : ℤ) : bit0 m ≠ bit1 n := mt (congr_arg bodd) $ by simp lemma bit1_ne_bit0 (m n : ℤ) : bit1 m ≠ bit0 n := (bit0_ne_bit1 _ _).symm lemma bit1_ne_zero (m : ℤ) : bit1 m ≠ 0 := by simpa only [bit0_zero] using bit1_ne_bit0 m 0 @[simp] lemma test_bit_zero (b) : ∀ n, test_bit (bit b n) 0 = b | (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_zero | -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_zero]; clear test_bit_zero; cases b; refl @[simp] lemma test_bit_succ (m b) : ∀ n, test_bit (bit b n) (nat.succ m) = test_bit n m | (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_succ | -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_succ] private meta def bitwise_tac : tactic unit := `[ funext m, funext n, cases m with m m; cases n with n n; try {refl}, all_goals { apply congr_arg of_nat <|> apply congr_arg neg_succ_of_nat, try {dsimp [nat.land, nat.ldiff, nat.lor]}, try {rw [ show nat.bitwise (λ a b, a && bnot b) n m = nat.bitwise (λ a b, b && bnot a) m n, from congr_fun (congr_fun (@nat.bitwise_swap (λ a b, b && bnot a) rfl) n) m]}, apply congr_arg (λ f, nat.bitwise f m n), funext a, funext b, cases a; cases b; refl }, all_goals {unfold nat.land nat.ldiff nat.lor} ] theorem bitwise_or : bitwise bor = lor := by bitwise_tac theorem bitwise_and : bitwise band = land := by bitwise_tac theorem bitwise_diff : bitwise (λ a b, a && bnot b) = ldiff := by bitwise_tac theorem bitwise_xor : bitwise bxor = lxor := by bitwise_tac @[simp] lemma bitwise_bit (f : bool → bool → bool) (a m b n) : bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) := begin cases m with m m; cases n with n n; repeat { rw [← int.coe_nat_eq] <|> rw bit_coe_nat <|> rw bit_neg_succ }; unfold bitwise nat_bitwise bnot; [ induction h : f ff ff, induction h : f ff tt, induction h : f tt ff, induction h : f tt tt ], all_goals { unfold cond, rw nat.bitwise_bit, repeat { rw bit_coe_nat <|> rw bit_neg_succ <|> rw bnot_bnot } }, all_goals { unfold bnot {fail_if_unchanged := ff}; rw h; refl } end @[simp] lemma lor_bit (a m b n) : lor (bit a m) (bit b n) = bit (a || b) (lor m n) := by rw [← bitwise_or, bitwise_bit] @[simp] lemma land_bit (a m b n) : land (bit a m) (bit b n) = bit (a && b) (land m n) := by rw [← bitwise_and, bitwise_bit] @[simp] lemma ldiff_bit (a m b n) : ldiff (bit a m) (bit b n) = bit (a && bnot b) (ldiff m n) := by rw [← bitwise_diff, bitwise_bit] @[simp] lemma lxor_bit (a m b n) : lxor (bit a m) (bit b n) = bit (bxor a b) (lxor m n) := by rw [← bitwise_xor, bitwise_bit] @[simp] lemma lnot_bit (b) : ∀ n, lnot (bit b n) = bit (bnot b) (lnot n) | (n : ℕ) := by simp [lnot] | -[1+ n] := by simp [lnot] @[simp] lemma test_bit_bitwise (f : bool → bool → bool) (m n k) : test_bit (bitwise f m n) k = f (test_bit m k) (test_bit n k) := begin induction k with k IH generalizing m n; apply bit_cases_on m; intros a m'; apply bit_cases_on n; intros b n'; rw bitwise_bit, { simp [test_bit_zero] }, { simp [test_bit_succ, IH] } end @[simp] lemma test_bit_lor (m n k) : test_bit (lor m n) k = test_bit m k || test_bit n k := by rw [← bitwise_or, test_bit_bitwise] @[simp] lemma test_bit_land (m n k) : test_bit (land m n) k = test_bit m k && test_bit n k := by rw [← bitwise_and, test_bit_bitwise] @[simp] lemma test_bit_ldiff (m n k) : test_bit (ldiff m n) k = test_bit m k && bnot (test_bit n k) := by rw [← bitwise_diff, test_bit_bitwise] @[simp] lemma test_bit_lxor (m n k) : test_bit (lxor m n) k = bxor (test_bit m k) (test_bit n k) := by rw [← bitwise_xor, test_bit_bitwise] @[simp] lemma test_bit_lnot : ∀ n k, test_bit (lnot n) k = bnot (test_bit n k) | (n : ℕ) k := by simp [lnot, test_bit] | -[1+ n] k := by simp [lnot, test_bit] lemma shiftl_add : ∀ (m : ℤ) (n : ℕ) (k : ℤ), shiftl m (n + k) = shiftl (shiftl m n) k | (m : ℕ) n (k:ℕ) := congr_arg of_nat (nat.shiftl_add _ _ _) | -[1+ m] n (k:ℕ) := congr_arg neg_succ_of_nat (nat.shiftl'_add _ _ _ _) | (m : ℕ) n -[1+k] := sub_nat_nat_elim n k.succ (λ n k i, shiftl ↑m i = nat.shiftr (nat.shiftl m n) k) (λ i n, congr_arg coe $ by rw [← nat.shiftl_sub, add_tsub_cancel_left]; apply nat.le_add_right) (λ i n, congr_arg coe $ by rw [add_assoc, nat.shiftr_add, ← nat.shiftl_sub, tsub_self]; refl) | -[1+ m] n -[1+k] := sub_nat_nat_elim n k.succ (λ n k i, shiftl -[1+ m] i = -[1+ nat.shiftr (nat.shiftl' tt m n) k]) (λ i n, congr_arg neg_succ_of_nat $ by rw [← nat.shiftl'_sub, add_tsub_cancel_left]; apply nat.le_add_right) (λ i n, congr_arg neg_succ_of_nat $ by rw [add_assoc, nat.shiftr_add, ← nat.shiftl'_sub, tsub_self]; refl) lemma shiftl_sub (m : ℤ) (n : ℕ) (k : ℤ) : shiftl m (n - k) = shiftr (shiftl m n) k := shiftl_add _ _ _ @[simp] lemma shiftl_neg (m n : ℤ) : shiftl m (-n) = shiftr m n := rfl @[simp] lemma shiftr_neg (m n : ℤ) : shiftr m (-n) = shiftl m n := by rw [← shiftl_neg, neg_neg] @[simp] lemma shiftl_coe_nat (m n : ℕ) : shiftl m n = nat.shiftl m n := rfl @[simp] lemma shiftr_coe_nat (m n : ℕ) : shiftr m n = nat.shiftr m n := by cases n; refl @[simp] lemma shiftl_neg_succ (m n : ℕ) : shiftl -[1+ m] n = -[1+ nat.shiftl' tt m n] := rfl @[simp] lemma shiftr_neg_succ (m n : ℕ) : shiftr -[1+ m] n = -[1+ nat.shiftr m n] := by cases n; refl lemma shiftr_add : ∀ (m : ℤ) (n k : ℕ), shiftr m (n + k) = shiftr (shiftr m n) k | (m : ℕ) n k := by rw [shiftr_coe_nat, shiftr_coe_nat, ← int.coe_nat_add, shiftr_coe_nat, nat.shiftr_add] | -[1+ m] n k := by rw [shiftr_neg_succ, shiftr_neg_succ, ← int.coe_nat_add, shiftr_neg_succ, nat.shiftr_add] lemma shiftl_eq_mul_pow : ∀ (m : ℤ) (n : ℕ), shiftl m n = m * ↑(2 ^ n) | (m : ℕ) n := congr_arg coe (nat.shiftl_eq_mul_pow _ _) | -[1+ m] n := @congr_arg ℕ ℤ _ _ (λi, -i) (nat.shiftl'_tt_eq_mul_pow _ _) lemma shiftr_eq_div_pow : ∀ (m : ℤ) (n : ℕ), shiftr m n = m / ↑(2 ^ n) | (m : ℕ) n := by rw shiftr_coe_nat; exact congr_arg coe (nat.shiftr_eq_div_pow _ _) | -[1+ m] n := begin rw [shiftr_neg_succ, neg_succ_of_nat_div, nat.shiftr_eq_div_pow], refl, exact coe_nat_lt_coe_nat_of_lt (pow_pos dec_trivial _) end lemma one_shiftl (n : ℕ) : shiftl 1 n = (2 ^ n : ℕ) := congr_arg coe (nat.one_shiftl _) @[simp] lemma zero_shiftl : ∀ n : ℤ, shiftl 0 n = 0 | (n : ℕ) := congr_arg coe (nat.zero_shiftl _) | -[1+ n] := congr_arg coe (nat.zero_shiftr _) @[simp] lemma zero_shiftr (n) : shiftr 0 n = 0 := zero_shiftl _ end int attribute [irreducible] int.nonneg
9c869cd47f6fad975af666b157e400aa0be5607a
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/linear_algebra/basis.lean
413fcd6ff3d9d373b746e07622f5e592a7d00bfd
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
48,715
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, Mario Carneiro, Alexander Bentkamp -/ import algebra.big_operators.finsupp import algebra.big_operators.finprod import data.fintype.card import linear_algebra.finsupp import linear_algebra.linear_independent import linear_algebra.linear_pmap import linear_algebra.projection /-! # Bases This file defines bases in a module or vector space. It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light. ## Main definitions All definitions are given for families of vectors, i.e. `v : ι → M` where `M` is the module or vector space and `ι : Type*` is an arbitrary indexing type. * `basis ι R M` is the type of `ι`-indexed `R`-bases for a module `M`, represented by a linear equiv `M ≃ₗ[R] ι →₀ R`. * the basis vectors of a basis `b : basis ι R M` are available as `b i`, where `i : ι` * `basis.repr` is the isomorphism sending `x : M` to its coordinates `basis.repr x : ι →₀ R`. The converse, turning this isomorphism into a basis, is called `basis.of_repr`. * If `ι` is finite, there is a variant of `repr` called `basis.equiv_fun b : M ≃ₗ[R] ι → R` (saving you from having to work with `finsupp`). The converse, turning this isomorphism into a basis, is called `basis.of_equiv_fun`. * `basis.constr hv f` constructs a linear map `M₁ →ₗ[R] M₂` given the values `f : ι → M₂` at the basis elements `⇑b : ι → M₁`. * `basis.reindex` uses an equiv to map a basis to a different indexing set. * `basis.map` uses a linear equiv to map a basis to a different module. ## Main statements * `basis.mk`: a linear independent set of vectors spanning the whole module determines a basis * `basis.ext` states that two linear maps are equal if they coincide on a basis. Similar results are available for linear equivs (if they coincide on the basis vectors), elements (if their coordinates coincide) and the functions `b.repr` and `⇑b`. * `basis.of_vector_space` states that every vector space has a basis. ## Implementation notes We use families instead of sets because it allows us to say that two identical vectors are linearly dependent. For bases, this is useful as well because we can easily derive ordered bases by using an ordered index type `ι`. ## Tags basis, bases -/ noncomputable theory universe u open function set submodule open_locale classical big_operators variables {ι : Type*} {ι' : Type*} {R : Type*} {K : Type*} variables {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*} section module variables [semiring R] variables [add_comm_monoid M] [module R M] [add_comm_monoid M'] [module R M'] section variables (ι) (R) (M) /-- A `basis ι R M` for a module `M` is the type of `ι`-indexed `R`-bases of `M`. The basis vectors are available as `coe_fn (b : basis ι R M) : ι → M`. To turn a linear independent family of vectors spanning `M` into a basis, use `basis.mk`. They are internally represented as linear equivs `M ≃ₗ[R] (ι →₀ R)`, available as `basis.repr`. -/ structure basis := of_repr :: (repr : M ≃ₗ[R] (ι →₀ R)) end namespace basis instance : inhabited (basis ι R (ι →₀ R)) := ⟨basis.of_repr (linear_equiv.refl _ _)⟩ variables (b b₁ : basis ι R M) (i : ι) (c : R) (x : M) section repr /-- `b i` is the `i`th basis vector. -/ instance : has_coe_to_fun (basis ι R M) (λ _, ι → M) := { coe := λ b i, b.repr.symm (finsupp.single i 1) } @[simp] lemma coe_of_repr (e : M ≃ₗ[R] (ι →₀ R)) : ⇑(of_repr e) = λ i, e.symm (finsupp.single i 1) := rfl protected lemma injective [nontrivial R] : injective b := b.repr.symm.injective.comp (λ _ _, (finsupp.single_left_inj (one_ne_zero : (1 : R) ≠ 0)).mp) lemma repr_symm_single_one : b.repr.symm (finsupp.single i 1) = b i := rfl lemma repr_symm_single : b.repr.symm (finsupp.single i c) = c • b i := calc b.repr.symm (finsupp.single i c) = b.repr.symm (c • finsupp.single i 1) : by rw [finsupp.smul_single', mul_one] ... = c • b i : by rw [linear_equiv.map_smul, repr_symm_single_one] @[simp] lemma repr_self : b.repr (b i) = finsupp.single i 1 := linear_equiv.apply_symm_apply _ _ lemma repr_self_apply (j) [decidable (i = j)] : b.repr (b i) j = if i = j then 1 else 0 := by rw [repr_self, finsupp.single_apply] @[simp] lemma repr_symm_apply (v) : b.repr.symm v = finsupp.total ι M R b v := calc b.repr.symm v = b.repr.symm (v.sum finsupp.single) : by simp ... = ∑ i in v.support, b.repr.symm (finsupp.single i (v i)) : by rw [finsupp.sum, linear_equiv.map_sum] ... = finsupp.total ι M R b v : by simp [repr_symm_single, finsupp.total_apply, finsupp.sum] @[simp] lemma coe_repr_symm : ↑b.repr.symm = finsupp.total ι M R b := linear_map.ext (λ v, b.repr_symm_apply v) @[simp] lemma repr_total (v) : b.repr (finsupp.total _ _ _ b v) = v := by { rw ← b.coe_repr_symm, exact b.repr.apply_symm_apply v } @[simp] lemma total_repr : finsupp.total _ _ _ b (b.repr x) = x := by { rw ← b.coe_repr_symm, exact b.repr.symm_apply_apply x } lemma repr_range : (b.repr : M →ₗ[R] (ι →₀ R)).range = finsupp.supported R R univ := by rw [linear_equiv.range, finsupp.supported_univ] lemma mem_span_repr_support {ι : Type*} (b : basis ι R M) (m : M) : m ∈ span R (b '' (b.repr m).support) := (finsupp.mem_span_image_iff_total _).2 ⟨b.repr m, (by simp [finsupp.mem_supported_support])⟩ end repr section coord /-- `b.coord i` is the linear function giving the `i`'th coordinate of a vector with respect to the basis `b`. `b.coord i` is an element of the dual space. In particular, for finite-dimensional spaces it is the `ι`th basis vector of the dual space. -/ @[simps] def coord : M →ₗ[R] R := (finsupp.lapply i) ∘ₗ ↑b.repr lemma forall_coord_eq_zero_iff {x : M} : (∀ i, b.coord i x = 0) ↔ x = 0 := iff.trans (by simp only [b.coord_apply, finsupp.ext_iff, finsupp.zero_apply]) b.repr.map_eq_zero_iff /-- The sum of the coordinates of an element `m : M` with respect to a basis. -/ noncomputable def sum_coords : M →ₗ[R] R := finsupp.lsum ℕ (λ i, linear_map.id) ∘ₗ (b.repr : M →ₗ[R] ι →₀ R) @[simp] lemma coe_sum_coords : (b.sum_coords : M → R) = λ m, (b.repr m).sum (λ i, id) := rfl lemma coe_sum_coords_eq_finsum : (b.sum_coords : M → R) = λ m, ∑ᶠ i, b.coord i m := begin ext m, simp only [basis.sum_coords, basis.coord, finsupp.lapply_apply, linear_map.id_coe, linear_equiv.coe_coe, function.comp_app, finsupp.coe_lsum, linear_map.coe_comp, finsum_eq_sum _ (b.repr m).finite_support, finsupp.sum, finset.finite_to_set_to_finset, id.def, finsupp.fun_support_eq], end @[simp] lemma coe_sum_coords_of_fintype [fintype ι] : (b.sum_coords : M → R) = ∑ i, b.coord i := begin ext m, simp only [sum_coords, finsupp.sum_fintype, linear_map.id_coe, linear_equiv.coe_coe, coord_apply, id.def, fintype.sum_apply, implies_true_iff, eq_self_iff_true, finsupp.coe_lsum, linear_map.coe_comp], end @[simp] lemma sum_coords_self_apply : b.sum_coords (b i) = 1 := by simp only [basis.sum_coords, linear_map.id_coe, linear_equiv.coe_coe, id.def, basis.repr_self, function.comp_app, finsupp.coe_lsum, linear_map.coe_comp, finsupp.sum_single_index] end coord section ext variables {R₁ : Type*} [semiring R₁] {σ : R →+* R₁} {σ' : R₁ →+* R} variables [ring_hom_inv_pair σ σ'] [ring_hom_inv_pair σ' σ] variables {M₁ : Type*} [add_comm_monoid M₁] [module R₁ M₁] /-- Two linear maps are equal if they are equal on basis vectors. -/ theorem ext {f₁ f₂ : M →ₛₗ[σ] M₁} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := by { ext x, rw [← b.total_repr x, finsupp.total_apply, finsupp.sum], simp only [linear_map.map_sum, linear_map.map_smulₛₗ, h] } include σ' /-- Two linear equivs are equal if they are equal on basis vectors. -/ theorem ext' {f₁ f₂ : M ≃ₛₗ[σ] M₁} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := by { ext x, rw [← b.total_repr x, finsupp.total_apply, finsupp.sum], simp only [linear_equiv.map_sum, linear_equiv.map_smulₛₗ, h] } omit σ' /-- Two elements are equal if their coordinates are equal. -/ theorem ext_elem {x y : M} (h : ∀ i, b.repr x i = b.repr y i) : x = y := by { rw [← b.total_repr x, ← b.total_repr y], congr' 1, ext i, exact h i } lemma repr_eq_iff {b : basis ι R M} {f : M →ₗ[R] ι →₀ R} : ↑b.repr = f ↔ ∀ i, f (b i) = finsupp.single i 1 := ⟨λ h i, h ▸ b.repr_self i, λ h, b.ext (λ i, (b.repr_self i).trans (h i).symm)⟩ lemma repr_eq_iff' {b : basis ι R M} {f : M ≃ₗ[R] ι →₀ R} : b.repr = f ↔ ∀ i, f (b i) = finsupp.single i 1 := ⟨λ h i, h ▸ b.repr_self i, λ h, b.ext' (λ i, (b.repr_self i).trans (h i).symm)⟩ lemma apply_eq_iff {b : basis ι R M} {x : M} {i : ι} : b i = x ↔ b.repr x = finsupp.single i 1 := ⟨λ h, h ▸ b.repr_self i, λ h, b.repr.injective ((b.repr_self i).trans h.symm)⟩ /-- An unbundled version of `repr_eq_iff` -/ lemma repr_apply_eq (f : M → ι → R) (hadd : ∀ x y, f (x + y) = f x + f y) (hsmul : ∀ (c : R) (x : M), f (c • x) = c • f x) (f_eq : ∀ i, f (b i) = finsupp.single i 1) (x : M) (i : ι) : b.repr x i = f x i := begin let f_i : M →ₗ[R] R := { to_fun := λ x, f x i, map_add' := λ _ _, by rw [hadd, pi.add_apply], map_smul' := λ _ _, by { simp [hsmul, pi.smul_apply] } }, have : (finsupp.lapply i) ∘ₗ ↑b.repr = f_i, { refine b.ext (λ j, _), show b.repr (b j) i = f (b j) i, rw [b.repr_self, f_eq] }, calc b.repr x i = f_i x : by { rw ← this, refl } ... = f x i : rfl end /-- Two bases are equal if they assign the same coordinates. -/ lemma eq_of_repr_eq_repr {b₁ b₂ : basis ι R M} (h : ∀ x i, b₁.repr x i = b₂.repr x i) : b₁ = b₂ := have b₁.repr = b₂.repr, by { ext, apply h }, by { cases b₁, cases b₂, simpa } /-- Two bases are equal if their basis vectors are the same. -/ @[ext] lemma eq_of_apply_eq {b₁ b₂ : basis ι R M} (h : ∀ i, b₁ i = b₂ i) : b₁ = b₂ := suffices b₁.repr = b₂.repr, by { cases b₁, cases b₂, simpa }, repr_eq_iff'.mpr (λ i, by rw [h, b₂.repr_self]) end ext section map variables (f : M ≃ₗ[R] M') /-- Apply the linear equivalence `f` to the basis vectors. -/ @[simps] protected def map : basis ι R M' := of_repr (f.symm.trans b.repr) @[simp] lemma map_apply (i) : b.map f i = f (b i) := rfl end map section map_coeffs variables {R' : Type*} [semiring R'] [module R' M] (f : R ≃+* R') (h : ∀ c (x : M), f c • x = c • x) include f h b local attribute [instance] has_scalar.comp.is_scalar_tower /-- If `R` and `R'` are isomorphic rings that act identically on a module `M`, then a basis for `M` as `R`-module is also a basis for `M` as `R'`-module. See also `basis.algebra_map_coeffs` for the case where `f` is equal to `algebra_map`. -/ @[simps {simp_rhs := tt}] def map_coeffs : basis ι R' M := begin letI : module R' R := module.comp_hom R (↑f.symm : R' →+* R), haveI : is_scalar_tower R' R M := { smul_assoc := λ x y z, begin dsimp [(•)], rw [mul_smul, ←h, f.apply_symm_apply], end }, exact (of_repr $ (b.repr.restrict_scalars R').trans $ finsupp.map_range.linear_equiv (module.comp_hom.to_linear_equiv f.symm).symm ) end lemma map_coeffs_apply (i : ι) : b.map_coeffs f h i = b i := apply_eq_iff.mpr $ by simp [f.to_add_equiv_eq_coe] @[simp] lemma coe_map_coeffs : (b.map_coeffs f h : ι → M) = b := funext $ b.map_coeffs_apply f h end map_coeffs section reindex variables (b' : basis ι' R M') variables (e : ι ≃ ι') /-- `b.reindex (e : ι ≃ ι')` is a basis indexed by `ι'` -/ def reindex : basis ι' R M := basis.of_repr (b.repr.trans (finsupp.dom_lcongr e)) lemma reindex_apply (i' : ι') : b.reindex e i' = b (e.symm i') := show (b.repr.trans (finsupp.dom_lcongr e)).symm (finsupp.single i' 1) = b.repr.symm (finsupp.single (e.symm i') 1), by rw [linear_equiv.symm_trans_apply, finsupp.dom_lcongr_symm, finsupp.dom_lcongr_single] @[simp] lemma coe_reindex : (b.reindex e : ι' → M) = b ∘ e.symm := funext (b.reindex_apply e) @[simp] lemma coe_reindex_repr : ((b.reindex e).repr x : ι' → R) = b.repr x ∘ e.symm := funext $ λ i', show (finsupp.dom_lcongr e : _ ≃ₗ[R] _) (b.repr x) i' = _, by simp @[simp] lemma reindex_repr (i' : ι') : (b.reindex e).repr x i' = b.repr x (e.symm i') := by rw coe_reindex_repr @[simp] lemma reindex_refl : b.reindex (equiv.refl ι) = b := eq_of_apply_eq $ λ i, by simp /-- `simp` normal form version of `range_reindex` -/ @[simp] lemma range_reindex' : set.range (b ∘ e.symm) = set.range b := by rw [range_comp, equiv.range_eq_univ, set.image_univ] lemma range_reindex : set.range (b.reindex e) = set.range b := by rw [coe_reindex, range_reindex'] /-- `b.reindex_range` is a basis indexed by `range b`, the basis vectors themselves. -/ def reindex_range : basis (range b) R M := if h : nontrivial R then by letI := h; exact b.reindex (equiv.of_injective b (basis.injective b)) else by letI : subsingleton R := not_nontrivial_iff_subsingleton.mp h; exact basis.of_repr (module.subsingleton_equiv R M (range b)) lemma finsupp.single_apply_left {α β γ : Type*} [has_zero γ] {f : α → β} (hf : function.injective f) (x z : α) (y : γ) : finsupp.single (f x) y (f z) = finsupp.single x y z := by simp [finsupp.single_apply, hf.eq_iff] lemma reindex_range_self (i : ι) (h := set.mem_range_self i) : b.reindex_range ⟨b i, h⟩ = b i := begin by_cases htr : nontrivial R, { letI := htr, simp [htr, reindex_range, reindex_apply, equiv.apply_of_injective_symm b.injective, subtype.coe_mk] }, { letI : subsingleton R := not_nontrivial_iff_subsingleton.mp htr, letI := module.subsingleton R M, simp [reindex_range] } end lemma reindex_range_repr_self (i : ι) : b.reindex_range.repr (b i) = finsupp.single ⟨b i, mem_range_self i⟩ 1 := calc b.reindex_range.repr (b i) = b.reindex_range.repr (b.reindex_range ⟨b i, mem_range_self i⟩) : congr_arg _ (b.reindex_range_self _ _).symm ... = finsupp.single ⟨b i, mem_range_self i⟩ 1 : b.reindex_range.repr_self _ @[simp] lemma reindex_range_apply (x : range b) : b.reindex_range x = x := by { rcases x with ⟨bi, ⟨i, rfl⟩⟩, exact b.reindex_range_self i, } lemma reindex_range_repr' (x : M) {bi : M} {i : ι} (h : b i = bi) : b.reindex_range.repr x ⟨bi, ⟨i, h⟩⟩ = b.repr x i := begin nontriviality, subst h, refine (b.repr_apply_eq (λ x i, b.reindex_range.repr x ⟨b i, _⟩) _ _ _ x i).symm, { intros x y, ext i, simp only [pi.add_apply, linear_equiv.map_add, finsupp.coe_add] }, { intros c x, ext i, simp only [pi.smul_apply, linear_equiv.map_smul, finsupp.coe_smul] }, { intros i, ext j, simp only [reindex_range_repr_self], refine @finsupp.single_apply_left _ _ _ _ (λ i, (⟨b i, _⟩ : set.range b)) _ _ _ _, exact λ i j h, b.injective (subtype.mk.inj h) } end @[simp] lemma reindex_range_repr (x : M) (i : ι) (h := set.mem_range_self i) : b.reindex_range.repr x ⟨b i, h⟩ = b.repr x i := b.reindex_range_repr' _ rfl section fintype variables [fintype ι] /-- `b.reindex_finset_range` is a basis indexed by `finset.univ.image b`, the finite set of basis vectors themselves. -/ def reindex_finset_range : basis (finset.univ.image b) R M := b.reindex_range.reindex ((equiv.refl M).subtype_equiv (by simp)) lemma reindex_finset_range_self (i : ι) (h := finset.mem_image_of_mem b (finset.mem_univ i)) : b.reindex_finset_range ⟨b i, h⟩ = b i := by { rw [reindex_finset_range, reindex_apply, reindex_range_apply], refl } @[simp] lemma reindex_finset_range_apply (x : finset.univ.image b) : b.reindex_finset_range x = x := by { rcases x with ⟨bi, hbi⟩, rcases finset.mem_image.mp hbi with ⟨i, -, rfl⟩, exact b.reindex_finset_range_self i } lemma reindex_finset_range_repr_self (i : ι) : b.reindex_finset_range.repr (b i) = finsupp.single ⟨b i, finset.mem_image_of_mem b (finset.mem_univ i)⟩ 1 := begin ext ⟨bi, hbi⟩, rw [reindex_finset_range, reindex_repr, reindex_range_repr_self], convert finsupp.single_apply_left ((equiv.refl M).subtype_equiv _).symm.injective _ _ _, refl end @[simp] lemma reindex_finset_range_repr (x : M) (i : ι) (h := finset.mem_image_of_mem b (finset.mem_univ i)) : b.reindex_finset_range.repr x ⟨b i, h⟩ = b.repr x i := by simp [reindex_finset_range] end fintype end reindex protected lemma linear_independent : linear_independent R b := linear_independent_iff.mpr $ λ l hl, calc l = b.repr (finsupp.total _ _ _ b l) : (b.repr_total l).symm ... = 0 : by rw [hl, linear_equiv.map_zero] protected lemma ne_zero [nontrivial R] (i) : b i ≠ 0 := b.linear_independent.ne_zero i protected lemma mem_span (x : M) : x ∈ span R (range b) := by { rw [← b.total_repr x, finsupp.total_apply, finsupp.sum], exact submodule.sum_mem _ (λ i hi, submodule.smul_mem _ _ (submodule.subset_span ⟨i, rfl⟩)) } protected lemma span_eq : span R (range b) = ⊤ := eq_top_iff.mpr $ λ x _, b.mem_span x lemma index_nonempty (b : basis ι R M) [nontrivial M] : nonempty ι := begin obtain ⟨x, y, ne⟩ : ∃ (x y : M), x ≠ y := nontrivial.exists_pair_ne, obtain ⟨i, _⟩ := not_forall.mp (mt b.ext_elem ne), exact ⟨i⟩ end section constr variables (S : Type*) [semiring S] [module S M'] variables [smul_comm_class R S M'] /-- Construct a linear map given the value at the basis. This definition is parameterized over an extra `semiring S`, such that `smul_comm_class R S M'` holds. If `R` is commutative, you can set `S := R`; if `R` is not commutative, you can recover an `add_equiv` by setting `S := ℕ`. See library note [bundled maps over different rings]. -/ def constr : (ι → M') ≃ₗ[S] (M →ₗ[R] M') := { to_fun := λ f, (finsupp.total M' M' R id).comp $ (finsupp.lmap_domain R R f) ∘ₗ ↑b.repr, inv_fun := λ f i, f (b i), left_inv := λ f, by { ext, simp }, right_inv := λ f, by { refine b.ext (λ i, _), simp }, map_add' := λ f g, by { refine b.ext (λ i, _), simp }, map_smul' := λ c f, by { refine b.ext (λ i, _), simp } } theorem constr_def (f : ι → M') : b.constr S f = (finsupp.total M' M' R id) ∘ₗ ((finsupp.lmap_domain R R f) ∘ₗ ↑b.repr) := rfl theorem constr_apply (f : ι → M') (x : M) : b.constr S f x = (b.repr x).sum (λ b a, a • f b) := by { simp only [constr_def, linear_map.comp_apply, finsupp.lmap_domain_apply, finsupp.total_apply], rw finsupp.sum_map_domain_index; simp [add_smul] } @[simp] lemma constr_basis (f : ι → M') (i : ι) : (b.constr S f : M → M') (b i) = f i := by simp [basis.constr_apply, b.repr_self] lemma constr_eq {g : ι → M'} {f : M →ₗ[R] M'} (h : ∀i, g i = f (b i)) : b.constr S g = f := b.ext $ λ i, (b.constr_basis S g i).trans (h i) lemma constr_self (f : M →ₗ[R] M') : b.constr S (λ i, f (b i)) = f := b.constr_eq S $ λ x, rfl lemma constr_range [nonempty ι] {f : ι → M'} : (b.constr S f).range = span R (range f) := by rw [b.constr_def S f, linear_map.range_comp, linear_map.range_comp, linear_equiv.range, ← finsupp.supported_univ, finsupp.lmap_domain_supported, ←set.image_univ, ← finsupp.span_image_eq_map_total, set.image_id] @[simp] lemma constr_comp (f : M' →ₗ[R] M') (v : ι → M') : b.constr S (f ∘ v) = f.comp (b.constr S v) := b.ext (λ i, by simp only [basis.constr_basis, linear_map.comp_apply]) end constr section equiv variables (b' : basis ι' R M') (e : ι ≃ ι') variables [add_comm_monoid M''] [module R M''] /-- If `b` is a basis for `M` and `b'` a basis for `M'`, and the index types are equivalent, `b.equiv b' e` is a linear equivalence `M ≃ₗ[R] M'`, mapping `b i` to `b' (e i)`. -/ protected def equiv : M ≃ₗ[R] M' := b.repr.trans (b'.reindex e.symm).repr.symm @[simp] lemma equiv_apply : b.equiv b' e (b i) = b' (e i) := by simp [basis.equiv] @[simp] lemma equiv_refl : b.equiv b (equiv.refl ι) = linear_equiv.refl R M := b.ext' (λ i, by simp) @[simp] lemma equiv_symm : (b.equiv b' e).symm = b'.equiv b e.symm := b'.ext' $ λ i, (b.equiv b' e).injective (by simp) @[simp] lemma equiv_trans {ι'' : Type*} (b'' : basis ι'' R M'') (e : ι ≃ ι') (e' : ι' ≃ ι'') : (b.equiv b' e).trans (b'.equiv b'' e') = b.equiv b'' (e.trans e') := b.ext' (λ i, by simp) @[simp] lemma map_equiv (b : basis ι R M) (b' : basis ι' R M') (e : ι ≃ ι') : b.map (b.equiv b' e) = b'.reindex e.symm := by { ext i, simp } end equiv section prod variables (b' : basis ι' R M') /-- `basis.prod` maps a `ι`-indexed basis for `M` and a `ι'`-indexed basis for `M'` to a `ι ⊕ ι'`-index basis for `M × M'`. -/ protected def prod : basis (ι ⊕ ι') R (M × M') := of_repr ((b.repr.prod b'.repr).trans (finsupp.sum_finsupp_lequiv_prod_finsupp R).symm) @[simp] lemma prod_repr_inl (x) (i) : (b.prod b').repr x (sum.inl i) = b.repr x.1 i := rfl @[simp] lemma prod_repr_inr (x) (i) : (b.prod b').repr x (sum.inr i) = b'.repr x.2 i := rfl lemma prod_apply_inl_fst (i) : (b.prod b' (sum.inl i)).1 = b i := b.repr.injective $ by { ext j, simp only [basis.prod, basis.coe_of_repr, linear_equiv.symm_trans_apply, linear_equiv.prod_symm, linear_equiv.prod_apply, b.repr.apply_symm_apply, linear_equiv.symm_symm, repr_self, equiv.to_fun_as_coe, finsupp.fst_sum_finsupp_lequiv_prod_finsupp], apply finsupp.single_apply_left sum.inl_injective } lemma prod_apply_inr_fst (i) : (b.prod b' (sum.inr i)).1 = 0 := b.repr.injective $ by { ext i, simp only [basis.prod, basis.coe_of_repr, linear_equiv.symm_trans_apply, linear_equiv.prod_symm, linear_equiv.prod_apply, b.repr.apply_symm_apply, linear_equiv.symm_symm, repr_self, equiv.to_fun_as_coe, finsupp.fst_sum_finsupp_lequiv_prod_finsupp, linear_equiv.map_zero, finsupp.zero_apply], apply finsupp.single_eq_of_ne sum.inr_ne_inl } lemma prod_apply_inl_snd (i) : (b.prod b' (sum.inl i)).2 = 0 := b'.repr.injective $ by { ext j, simp only [basis.prod, basis.coe_of_repr, linear_equiv.symm_trans_apply, linear_equiv.prod_symm, linear_equiv.prod_apply, b'.repr.apply_symm_apply, linear_equiv.symm_symm, repr_self, equiv.to_fun_as_coe, finsupp.snd_sum_finsupp_lequiv_prod_finsupp, linear_equiv.map_zero, finsupp.zero_apply], apply finsupp.single_eq_of_ne sum.inl_ne_inr } lemma prod_apply_inr_snd (i) : (b.prod b' (sum.inr i)).2 = b' i := b'.repr.injective $ by { ext i, simp only [basis.prod, basis.coe_of_repr, linear_equiv.symm_trans_apply, linear_equiv.prod_symm, linear_equiv.prod_apply, b'.repr.apply_symm_apply, linear_equiv.symm_symm, repr_self, equiv.to_fun_as_coe, finsupp.snd_sum_finsupp_lequiv_prod_finsupp], apply finsupp.single_apply_left sum.inr_injective } @[simp] lemma prod_apply (i) : b.prod b' i = sum.elim (linear_map.inl R M M' ∘ b) (linear_map.inr R M M' ∘ b') i := by { ext; cases i; simp only [prod_apply_inl_fst, sum.elim_inl, linear_map.inl_apply, prod_apply_inr_fst, sum.elim_inr, linear_map.inr_apply, prod_apply_inl_snd, prod_apply_inr_snd, comp_app] } end prod section no_zero_smul_divisors -- Can't be an instance because the basis can't be inferred. protected lemma no_zero_smul_divisors [no_zero_divisors R] (b : basis ι R M) : no_zero_smul_divisors R M := ⟨λ c x hcx, or_iff_not_imp_right.mpr (λ hx, begin rw [← b.total_repr x, ← linear_map.map_smul] at hcx, have := linear_independent_iff.mp b.linear_independent (c • b.repr x) hcx, rw smul_eq_zero at this, exact this.resolve_right (λ hr, hx (b.repr.map_eq_zero_iff.mp hr)) end)⟩ protected lemma smul_eq_zero [no_zero_divisors R] (b : basis ι R M) {c : R} {x : M} : c • x = 0 ↔ c = 0 ∨ x = 0 := @smul_eq_zero _ _ _ _ _ b.no_zero_smul_divisors _ _ lemma _root_.eq_bot_of_rank_eq_zero [no_zero_divisors R] (b : basis ι R M) (N : submodule R M) (rank_eq : ∀ {m : ℕ} (v : fin m → N), linear_independent R (coe ∘ v : fin m → M) → m = 0) : N = ⊥ := begin rw submodule.eq_bot_iff, intros x hx, contrapose! rank_eq with x_ne, refine ⟨1, λ _, ⟨x, hx⟩, _, one_ne_zero⟩, rw fintype.linear_independent_iff, rintros g sum_eq i, cases i, simp only [function.const_apply, fin.default_eq_zero, submodule.coe_mk, finset.univ_unique, function.comp_const, finset.sum_singleton] at sum_eq, convert (b.smul_eq_zero.mp sum_eq).resolve_right x_ne end end no_zero_smul_divisors section singleton /-- `basis.singleton ι R` is the basis sending the unique element of `ι` to `1 : R`. -/ protected def singleton (ι R : Type*) [unique ι] [semiring R] : basis ι R R := of_repr { to_fun := λ x, finsupp.single default x, inv_fun := λ f, f default, left_inv := λ x, by simp, right_inv := λ f, finsupp.unique_ext (by simp), map_add' := λ x y, by simp, map_smul' := λ c x, by simp } @[simp] lemma singleton_apply (ι R : Type*) [unique ι] [semiring R] (i) : basis.singleton ι R i = 1 := apply_eq_iff.mpr (by simp [basis.singleton]) @[simp] lemma singleton_repr (ι R : Type*) [unique ι] [semiring R] (x i) : (basis.singleton ι R).repr x i = x := by simp [basis.singleton, unique.eq_default i] lemma basis_singleton_iff {R M : Type*} [ring R] [nontrivial R] [add_comm_group M] [module R M] [no_zero_smul_divisors R M] (ι : Type*) [unique ι] : nonempty (basis ι R M) ↔ ∃ x ≠ 0, ∀ y : M, ∃ r : R, r • x = y := begin fsplit, { rintro ⟨b⟩, refine ⟨b default, b.linear_independent.ne_zero _, _⟩, simpa [span_singleton_eq_top_iff, set.range_unique] using b.span_eq }, { rintro ⟨x, nz, w⟩, refine ⟨of_repr $ linear_equiv.symm { to_fun := λ f, f default • x, inv_fun := λ y, finsupp.single default (w y).some, left_inv := λ f, finsupp.unique_ext _, right_inv := λ y, _, map_add' := λ y z, _, map_smul' := λ c y, _ }⟩, { rw [finsupp.add_apply, add_smul] }, { rw [finsupp.smul_apply, smul_assoc], simp }, { refine smul_left_injective _ nz _, simp only [finsupp.single_eq_same], exact (w (f default • x)).some_spec }, { simp only [finsupp.single_eq_same], exact (w y).some_spec } } end end singleton section empty variables (M) /-- If `M` is a subsingleton and `ι` is empty, this is the unique `ι`-indexed basis for `M`. -/ protected def empty [subsingleton M] [is_empty ι] : basis ι R M := of_repr 0 instance empty_unique [subsingleton M] [is_empty ι] : unique (basis ι R M) := { default := basis.empty M, uniq := λ ⟨x⟩, congr_arg of_repr $ subsingleton.elim _ _ } end empty end basis section fintype open basis open fintype variables [fintype ι] (b : basis ι R M) /-- A module over `R` with a finite basis is linearly equivalent to functions from its basis to `R`. -/ def basis.equiv_fun : M ≃ₗ[R] (ι → R) := linear_equiv.trans b.repr ({ to_fun := coe_fn, map_add' := finsupp.coe_add, map_smul' := finsupp.coe_smul, ..finsupp.equiv_fun_on_fintype } : (ι →₀ R) ≃ₗ[R] (ι → R)) /-- A module over a finite ring that admits a finite basis is finite. -/ def module.fintype_of_fintype [fintype R] : fintype M := fintype.of_equiv _ b.equiv_fun.to_equiv.symm theorem module.card_fintype [fintype R] [fintype M] : card M = (card R) ^ (card ι) := calc card M = card (ι → R) : card_congr b.equiv_fun.to_equiv ... = card R ^ card ι : card_fun /-- Given a basis `v` indexed by `ι`, the canonical linear equivalence between `ι → R` and `M` maps a function `x : ι → R` to the linear combination `∑_i x i • v i`. -/ @[simp] lemma basis.equiv_fun_symm_apply (x : ι → R) : b.equiv_fun.symm x = ∑ i, x i • b i := by simp [basis.equiv_fun, finsupp.total_apply, finsupp.sum_fintype] @[simp] lemma basis.equiv_fun_apply (u : M) : b.equiv_fun u = b.repr u := rfl lemma basis.sum_equiv_fun (u : M) : ∑ i, b.equiv_fun u i • b i = u := begin conv_rhs { rw ← b.total_repr u }, simp [finsupp.total_apply, finsupp.sum_fintype, b.equiv_fun_apply] end lemma basis.sum_repr (u : M) : ∑ i, b.repr u i • b i = u := b.sum_equiv_fun u @[simp] lemma basis.equiv_fun_self (i j : ι) : b.equiv_fun (b i) j = if i = j then 1 else 0 := by { rw [b.equiv_fun_apply, b.repr_self_apply] } /-- Define a basis by mapping each vector `x : M` to its coordinates `e x : ι → R`, as long as `ι` is finite. -/ def basis.of_equiv_fun (e : M ≃ₗ[R] (ι → R)) : basis ι R M := basis.of_repr $ e.trans $ linear_equiv.symm $ finsupp.linear_equiv_fun_on_fintype R R ι @[simp] lemma basis.of_equiv_fun_repr_apply (e : M ≃ₗ[R] (ι → R)) (x : M) (i : ι) : (basis.of_equiv_fun e).repr x i = e x i := rfl @[simp] lemma basis.coe_of_equiv_fun (e : M ≃ₗ[R] (ι → R)) : (basis.of_equiv_fun e : ι → M) = λ i, e.symm (function.update 0 i 1) := funext $ λ i, e.injective $ funext $ λ j, by simp [basis.of_equiv_fun, ←finsupp.single_eq_pi_single, finsupp.single_eq_update] variables (S : Type*) [semiring S] [module S M'] variables [smul_comm_class R S M'] @[simp] theorem basis.constr_apply_fintype (f : ι → M') (x : M) : (b.constr S f : M → M') x = ∑ i, (b.equiv_fun x i) • f i := by simp [b.constr_apply, b.equiv_fun_apply, finsupp.sum_fintype] end fintype end module section comm_semiring namespace basis variables [comm_semiring R] variables [add_comm_monoid M] [module R M] [add_comm_monoid M'] [module R M'] variables (b : basis ι R M) (b' : basis ι' R M') /-- If `b` is a basis for `M` and `b'` a basis for `M'`, and `f`, `g` form a bijection between the basis vectors, `b.equiv' b' f g hf hg hgf hfg` is a linear equivalence `M ≃ₗ[R] M'`, mapping `b i` to `f (b i)`. -/ def equiv' (f : M → M') (g : M' → M) (hf : ∀ i, f (b i) ∈ range b') (hg : ∀ i, g (b' i) ∈ range b) (hgf : ∀i, g (f (b i)) = b i) (hfg : ∀i, f (g (b' i)) = b' i) : M ≃ₗ[R] M' := { inv_fun := b'.constr R (g ∘ b'), left_inv := have (b'.constr R (g ∘ b')).comp (b.constr R (f ∘ b)) = linear_map.id, from (b.ext $ λ i, exists.elim (hf i) (λ i' hi', by rw [linear_map.comp_apply, b.constr_basis, function.comp_apply, ← hi', b'.constr_basis, function.comp_apply, hi', hgf, linear_map.id_apply])), λ x, congr_arg (λ (h : M →ₗ[R] M), h x) this, right_inv := have (b.constr R (f ∘ b)).comp (b'.constr R (g ∘ b')) = linear_map.id, from (b'.ext $ λ i, exists.elim (hg i) (λ i' hi', by rw [linear_map.comp_apply, b'.constr_basis, function.comp_apply, ← hi', b.constr_basis, function.comp_apply, hi', hfg, linear_map.id_apply])), λ x, congr_arg (λ (h : M' →ₗ[R] M'), h x) this, .. b.constr R (f ∘ b) } @[simp] lemma equiv'_apply (f : M → M') (g : M' → M) (hf hg hgf hfg) (i : ι) : b.equiv' b' f g hf hg hgf hfg (b i) = f (b i) := b.constr_basis R _ _ @[simp] lemma equiv'_symm_apply (f : M → M') (g : M' → M) (hf hg hgf hfg) (i : ι') : (b.equiv' b' f g hf hg hgf hfg).symm (b' i) = g (b' i) := b'.constr_basis R _ _ lemma sum_repr_mul_repr {ι'} [fintype ι'] (b' : basis ι' R M) (x : M) (i : ι) : ∑ (j : ι'), b.repr (b' j) i * b'.repr x j = b.repr x i := begin conv_rhs { rw [← b'.sum_repr x] }, simp_rw [linear_equiv.map_sum, linear_equiv.map_smul, finset.sum_apply'], refine finset.sum_congr rfl (λ j _, _), rw [finsupp.smul_apply, smul_eq_mul, mul_comm] end end basis end comm_semiring section module open linear_map variables {v : ι → M} variables [ring R] [add_comm_group M] [add_comm_group M'] [add_comm_group M''] variables [module R M] [module R M'] [module R M''] variables {c d : R} {x y : M} variables (b : basis ι R M) namespace basis /-- Any basis is a maximal linear independent set. -/ lemma maximal [nontrivial R] (b : basis ι R M) : b.linear_independent.maximal := λ w hi h, begin -- If `range w` is strictly bigger than `range b`, apply le_antisymm h, -- then choose some `x ∈ range w \ range b`, intros x p, by_contradiction q, -- and write it in terms of the basis. have e := b.total_repr x, -- This then expresses `x` as a linear combination -- of elements of `w` which are in the range of `b`, let u : ι ↪ w := ⟨λ i, ⟨b i, h ⟨i, rfl⟩⟩, λ i i' r, b.injective (by simpa only [subtype.mk_eq_mk] using r)⟩, have r : ∀ i, b i = u i := λ i, rfl, simp_rw [finsupp.total_apply, r] at e, change (b.repr x).sum (λ (i : ι) (a : R), (λ (x : w) (r : R), r • (x : M)) (u i) a) = ((⟨x, p⟩ : w) : M) at e, rw [←finsupp.sum_emb_domain, ←finsupp.total_apply] at e, -- Now we can contradict the linear independence of `hi` refine hi.total_ne_of_not_mem_support _ _ e, simp only [finset.mem_map, finsupp.support_emb_domain], rintro ⟨j, -, W⟩, simp only [embedding.coe_fn_mk, subtype.mk_eq_mk, ←r] at W, apply q ⟨j, W⟩, end section mk variables (hli : linear_independent R v) (hsp : span R (range v) = ⊤) /-- A linear independent family of vectors spanning the whole module is a basis. -/ protected noncomputable def mk : basis ι R M := basis.of_repr { inv_fun := finsupp.total _ _ _ v, left_inv := λ x, hli.total_repr ⟨x, _⟩, right_inv := λ x, hli.repr_eq rfl, .. hli.repr.comp (linear_map.id.cod_restrict _ (λ h, hsp.symm ▸ submodule.mem_top)) } @[simp] lemma mk_repr : (basis.mk hli hsp).repr x = hli.repr ⟨x, hsp.symm ▸ submodule.mem_top⟩ := rfl lemma mk_apply (i : ι) : basis.mk hli hsp i = v i := show finsupp.total _ _ _ v _ = v i, by simp @[simp] lemma coe_mk : ⇑(basis.mk hli hsp) = v := funext (mk_apply _ _) variables {hli hsp} /-- Given a basis, the `i`th element of the dual basis evaluates to 1 on the `i`th element of the basis. -/ lemma mk_coord_apply_eq (i : ι) : (basis.mk hli hsp).coord i (v i) = 1 := show hli.repr ⟨v i, submodule.subset_span (mem_range_self i)⟩ i = 1, by simp [hli.repr_eq_single i] /-- Given a basis, the `i`th element of the dual basis evaluates to 0 on the `j`th element of the basis if `j ≠ i`. -/ lemma mk_coord_apply_ne {i j : ι} (h : j ≠ i) : (basis.mk hli hsp).coord i (v j) = 0 := show hli.repr ⟨v j, submodule.subset_span (mem_range_self j)⟩ i = 0, by simp [hli.repr_eq_single j, h] /-- Given a basis, the `i`th element of the dual basis evaluates to the Kronecker delta on the `j`th element of the basis. -/ lemma mk_coord_apply {i j : ι} : (basis.mk hli hsp).coord i (v j) = if j = i then 1 else 0 := begin cases eq_or_ne j i, { simp only [h, if_true, eq_self_iff_true, mk_coord_apply_eq i], }, { simp only [h, if_false, mk_coord_apply_ne h], }, end end mk section span variables (hli : linear_independent R v) /-- A linear independent family of vectors is a basis for their span. -/ protected noncomputable def span : basis ι R (span R (range v)) := basis.mk (linear_independent_span hli) $ begin rw eq_top_iff, intros x _, have h₁ : (coe : span R (range v) → M) '' set.range (λ i, subtype.mk (v i) _) = range v, { rw ← set.range_comp, refl }, have h₂ : map (submodule.subtype _) (span R (set.range (λ i, subtype.mk (v i) _))) = span R (range v), { rw [← span_image, submodule.coe_subtype, h₁] }, have h₃ : (x : M) ∈ map (submodule.subtype _) (span R (set.range (λ i, subtype.mk (v i) _))), { rw h₂, apply subtype.mem x }, rcases mem_map.1 h₃ with ⟨y, hy₁, hy₂⟩, have h_x_eq_y : x = y, { rw [subtype.ext_iff, ← hy₂], simp }, rwa h_x_eq_y end end span lemma group_smul_span_eq_top {G : Type*} [group G] [distrib_mul_action G R] [distrib_mul_action G M] [is_scalar_tower G R M] {v : ι → M} (hv : submodule.span R (set.range v) = ⊤) {w : ι → G} : submodule.span R (set.range (w • v)) = ⊤ := begin rw eq_top_iff, intros j hj, rw ← hv at hj, rw submodule.mem_span at hj ⊢, refine λ p hp, hj p (λ u hu, _), obtain ⟨i, rfl⟩ := hu, have : ((w i)⁻¹ • 1 : R) • w i • v i ∈ p := p.smul_mem ((w i)⁻¹ • 1 : R) (hp ⟨i, rfl⟩), rwa [smul_one_smul, inv_smul_smul] at this, end /-- Given a basis `v` and a map `w` such that for all `i`, `w i` are elements of a group, `group_smul` provides the basis corresponding to `w • v`. -/ def group_smul {G : Type*} [group G] [distrib_mul_action G R] [distrib_mul_action G M] [is_scalar_tower G R M] [smul_comm_class G R M] (v : basis ι R M) (w : ι → G) : basis ι R M := @basis.mk ι R M (w • v) _ _ _ (v.linear_independent.group_smul w) (group_smul_span_eq_top v.span_eq) lemma group_smul_apply {G : Type*} [group G] [distrib_mul_action G R] [distrib_mul_action G M] [is_scalar_tower G R M] [smul_comm_class G R M] {v : basis ι R M} {w : ι → G} (i : ι) : v.group_smul w i = (w • v : ι → M) i := mk_apply (v.linear_independent.group_smul w) (group_smul_span_eq_top v.span_eq) i lemma units_smul_span_eq_top {v : ι → M} (hv : submodule.span R (set.range v) = ⊤) {w : ι → Rˣ} : submodule.span R (set.range (w • v)) = ⊤ := group_smul_span_eq_top hv /-- Given a basis `v` and a map `w` such that for all `i`, `w i` is a unit, `smul_of_is_unit` provides the basis corresponding to `w • v`. -/ def units_smul (v : basis ι R M) (w : ι → Rˣ) : basis ι R M := @basis.mk ι R M (w • v) _ _ _ (v.linear_independent.units_smul w) (units_smul_span_eq_top v.span_eq) lemma units_smul_apply {v : basis ι R M} {w : ι → Rˣ} (i : ι) : v.units_smul w i = w i • v i := mk_apply (v.linear_independent.units_smul w) (units_smul_span_eq_top v.span_eq) i /-- A version of `smul_of_units` that uses `is_unit`. -/ def is_unit_smul (v : basis ι R M) {w : ι → R} (hw : ∀ i, is_unit (w i)): basis ι R M := units_smul v (λ i, (hw i).unit) lemma is_unit_smul_apply {v : basis ι R M} {w : ι → R} (hw : ∀ i, is_unit (w i)) (i : ι) : v.is_unit_smul hw i = w i • v i := units_smul_apply i section fin /-- Let `b` be a basis for a submodule `N` of `M`. If `y : M` is linear independent of `N` and `y` and `N` together span the whole of `M`, then there is a basis for `M` whose basis vectors are given by `fin.cons y b`. -/ noncomputable def mk_fin_cons {n : ℕ} {N : submodule R M} (y : M) (b : basis (fin n) R N) (hli : ∀ (c : R) (x ∈ N), c • y + x = 0 → c = 0) (hsp : ∀ (z : M), ∃ (c : R), z + c • y ∈ N) : basis (fin (n + 1)) R M := have span_b : submodule.span R (set.range (N.subtype ∘ b)) = N, { rw [set.range_comp, submodule.span_image, b.span_eq, submodule.map_subtype_top] }, @basis.mk _ _ _ (fin.cons y (N.subtype ∘ b) : fin (n + 1) → M) _ _ _ ((b.linear_independent.map' N.subtype (submodule.ker_subtype _)) .fin_cons' _ _ $ by { rintros c ⟨x, hx⟩ hc, rw span_b at hx, exact hli c x hx hc }) (eq_top_iff.mpr (λ x _, by { rw [fin.range_cons, submodule.mem_span_insert', span_b], exact hsp x })) @[simp] lemma coe_mk_fin_cons {n : ℕ} {N : submodule R M} (y : M) (b : basis (fin n) R N) (hli : ∀ (c : R) (x ∈ N), c • y + x = 0 → c = 0) (hsp : ∀ (z : M), ∃ (c : R), z + c • y ∈ N) : (mk_fin_cons y b hli hsp : fin (n + 1) → M) = fin.cons y (coe ∘ b) := coe_mk _ _ /-- Let `b` be a basis for a submodule `N ≤ O`. If `y ∈ O` is linear independent of `N` and `y` and `N` together span the whole of `O`, then there is a basis for `O` whose basis vectors are given by `fin.cons y b`. -/ noncomputable def mk_fin_cons_of_le {n : ℕ} {N O : submodule R M} (y : M) (yO : y ∈ O) (b : basis (fin n) R N) (hNO : N ≤ O) (hli : ∀ (c : R) (x ∈ N), c • y + x = 0 → c = 0) (hsp : ∀ (z ∈ O), ∃ (c : R), z + c • y ∈ N) : basis (fin (n + 1)) R O := mk_fin_cons ⟨y, yO⟩ (b.map (submodule.comap_subtype_equiv_of_le hNO).symm) (λ c x hc hx, hli c x (submodule.mem_comap.mp hc) (congr_arg coe hx)) (λ z, hsp z z.2) @[simp] lemma coe_mk_fin_cons_of_le {n : ℕ} {N O : submodule R M} (y : M) (yO : y ∈ O) (b : basis (fin n) R N) (hNO : N ≤ O) (hli : ∀ (c : R) (x ∈ N), c • y + x = 0 → c = 0) (hsp : ∀ (z ∈ O), ∃ (c : R), z + c • y ∈ N) : (mk_fin_cons_of_le y yO b hNO hli hsp : fin (n + 1) → O) = fin.cons ⟨y, yO⟩ (submodule.of_le hNO ∘ b) := coe_mk_fin_cons _ _ _ _ end fin end basis end module section induction variables [ring R] [is_domain R] variables [add_comm_group M] [module R M] {b : ι → M} /-- If `N` is a submodule with finite rank, do induction on adjoining a linear independent element to a submodule. -/ def submodule.induction_on_rank_aux (b : basis ι R M) (P : submodule R M → Sort*) (ih : ∀ (N : submodule R M), (∀ (N' ≤ N) (x ∈ N), (∀ (c : R) (y ∈ N'), c • x + y = (0 : M) → c = 0) → P N') → P N) (n : ℕ) (N : submodule R M) (rank_le : ∀ {m : ℕ} (v : fin m → N), linear_independent R (coe ∘ v : fin m → M) → m ≤ n) : P N := begin haveI : decidable_eq M := classical.dec_eq M, have Pbot : P ⊥, { apply ih, intros N N_le x x_mem x_ortho, exfalso, simpa using x_ortho 1 0 N.zero_mem }, induction n with n rank_ih generalizing N, { suffices : N = ⊥, { rwa this }, apply eq_bot_of_rank_eq_zero b _ (λ m v hv, nat.le_zero_iff.mp (rank_le v hv)) }, apply ih, intros N' N'_le x x_mem x_ortho, apply rank_ih, intros m v hli, refine nat.succ_le_succ_iff.mp (rank_le (fin.cons ⟨x, x_mem⟩ (λ i, ⟨v i, N'_le (v i).2⟩)) _), convert hli.fin_cons' x _ _, { ext i, refine fin.cases _ _ i; simp }, { intros c y hcy, refine x_ortho c y (submodule.span_le.mpr _ y.2) hcy, rintros _ ⟨z, rfl⟩, exact (v z).2 } end end induction section division_ring variables [division_ring K] [add_comm_group V] [add_comm_group V'] [module K V] [module K V'] variables {v : ι → V} {s t : set V} {x y z : V} include K open submodule namespace basis section exists_basis /-- If `s` is a linear independent set of vectors, we can extend it to a basis. -/ noncomputable def extend (hs : linear_independent K (coe : s → V)) : basis _ K V := basis.mk (@linear_independent.restrict_of_comp_subtype _ _ _ id _ _ _ _ (hs.linear_independent_extend _)) (eq_top_iff.mpr $ set_like.coe_subset_coe.mp $ by simpa using hs.subset_span_extend (subset_univ s)) lemma extend_apply_self (hs : linear_independent K (coe : s → V)) (x : hs.extend _) : basis.extend hs x = x := basis.mk_apply _ _ _ @[simp] lemma coe_extend (hs : linear_independent K (coe : s → V)) : ⇑(basis.extend hs) = coe := funext (extend_apply_self hs) lemma range_extend (hs : linear_independent K (coe : s → V)) : range (basis.extend hs) = hs.extend (subset_univ _) := by rw [coe_extend, subtype.range_coe_subtype, set_of_mem_eq] /-- If `v` is a linear independent family of vectors, extend it to a basis indexed by a sum type. -/ noncomputable def sum_extend (hs : linear_independent K v) : basis (ι ⊕ _) K V := let s := set.range v, e : ι ≃ s := equiv.of_injective v hs.injective, b := hs.to_subtype_range.extend (subset_univ (set.range v)) in (basis.extend hs.to_subtype_range).reindex $ equiv.symm $ calc ι ⊕ (b \ s : set V) ≃ s ⊕ (b \ s : set V) : equiv.sum_congr e (equiv.refl _) ... ≃ b : equiv.set.sum_diff_subset (hs.to_subtype_range.subset_extend _) lemma subset_extend {s : set V} (hs : linear_independent K (coe : s → V)) : s ⊆ hs.extend (set.subset_univ _) := hs.subset_extend _ section variables (K V) /-- A set used to index `basis.of_vector_space`. -/ noncomputable def of_vector_space_index : set V := (linear_independent_empty K V).extend (subset_univ _) /-- Each vector space has a basis. -/ noncomputable def of_vector_space : basis (of_vector_space_index K V) K V := basis.extend (linear_independent_empty K V) lemma of_vector_space_apply_self (x : of_vector_space_index K V) : of_vector_space K V x = x := basis.mk_apply _ _ _ @[simp] lemma coe_of_vector_space : ⇑(of_vector_space K V) = coe := funext (λ x, of_vector_space_apply_self K V x) lemma of_vector_space_index.linear_independent : linear_independent K (coe : of_vector_space_index K V → V) := by { convert (of_vector_space K V).linear_independent, ext x, rw of_vector_space_apply_self } lemma range_of_vector_space : range (of_vector_space K V) = of_vector_space_index K V := range_extend _ lemma exists_basis : ∃ s : set V, nonempty (basis s K V) := ⟨of_vector_space_index K V, ⟨of_vector_space K V⟩⟩ end end exists_basis end basis open fintype variables (K V) theorem vector_space.card_fintype [fintype K] [fintype V] : ∃ n : ℕ, card V = (card K) ^ n := ⟨card (basis.of_vector_space_index K V), module.card_fintype (basis.of_vector_space K V)⟩ end division_ring section field variables [field K] [add_comm_group V] [add_comm_group V'] [module K V] [module K V'] variables {v : ι → V} {s t : set V} {x y z : V} lemma linear_map.exists_left_inverse_of_injective (f : V →ₗ[K] V') (hf_inj : f.ker = ⊥) : ∃g:V' →ₗ[K] V, g.comp f = linear_map.id := begin let B := basis.of_vector_space_index K V, let hB := basis.of_vector_space K V, have hB₀ : _ := hB.linear_independent.to_subtype_range, have : linear_independent K (λ x, x : f '' B → V'), { have h₁ : linear_independent K (λ (x : ↥(⇑f '' range (basis.of_vector_space _ _))), ↑x) := @linear_independent.image_subtype _ _ _ _ _ _ _ _ _ f hB₀ (show disjoint _ _, by simp [hf_inj]), rwa [basis.range_of_vector_space K V] at h₁ }, let C := this.extend (subset_univ _), have BC := this.subset_extend (subset_univ _), let hC := basis.extend this, haveI : inhabited V := ⟨0⟩, refine ⟨hC.constr K (C.restrict (inv_fun f)), hB.ext (λ b, _)⟩, rw image_subset_iff at BC, have fb_eq : f b = hC ⟨f b, BC b.2⟩, { change f b = basis.extend this _, rw [basis.extend_apply_self, subtype.coe_mk] }, dsimp [hB], rw [basis.of_vector_space_apply_self, fb_eq, hC.constr_basis], exact left_inverse_inv_fun (linear_map.ker_eq_bot.1 hf_inj) _ end lemma submodule.exists_is_compl (p : submodule K V) : ∃ q : submodule K V, is_compl p q := let ⟨f, hf⟩ := p.subtype.exists_left_inverse_of_injective p.ker_subtype in ⟨f.ker, linear_map.is_compl_of_proj $ linear_map.ext_iff.1 hf⟩ instance module.submodule.is_complemented : is_complemented (submodule K V) := ⟨submodule.exists_is_compl⟩ lemma linear_map.exists_right_inverse_of_surjective (f : V →ₗ[K] V') (hf_surj : f.range = ⊤) : ∃g:V' →ₗ[K] V, f.comp g = linear_map.id := begin let C := basis.of_vector_space_index K V', let hC := basis.of_vector_space K V', haveI : inhabited V := ⟨0⟩, use hC.constr K (C.restrict (inv_fun f)), refine hC.ext (λ c, _), rw [linear_map.comp_apply, hC.constr_basis], simp [right_inverse_inv_fun (linear_map.range_eq_top.1 hf_surj) c] end /-- Any linear map `f : p →ₗ[K] V'` defined on a subspace `p` can be extended to the whole space. -/ lemma linear_map.exists_extend {p : submodule K V} (f : p →ₗ[K] V') : ∃ g : V →ₗ[K] V', g.comp p.subtype = f := let ⟨g, hg⟩ := p.subtype.exists_left_inverse_of_injective p.ker_subtype in ⟨f.comp g, by rw [linear_map.comp_assoc, hg, f.comp_id]⟩ open submodule linear_map /-- If `p < ⊤` is a subspace of a vector space `V`, then there exists a nonzero linear map `f : V →ₗ[K] K` such that `p ≤ ker f`. -/ lemma submodule.exists_le_ker_of_lt_top (p : submodule K V) (hp : p < ⊤) : ∃ f ≠ (0 : V →ₗ[K] K), p ≤ ker f := begin rcases set_like.exists_of_lt hp with ⟨v, -, hpv⟩, clear hp, rcases (linear_pmap.sup_span_singleton ⟨p, 0⟩ v (1 : K) hpv).to_fun.exists_extend with ⟨f, hf⟩, refine ⟨f, _, _⟩, { rintro rfl, rw [linear_map.zero_comp] at hf, have := linear_pmap.sup_span_singleton_apply_mk ⟨p, 0⟩ v (1 : K) hpv 0 p.zero_mem 1, simpa using (linear_map.congr_fun hf _).trans this }, { refine λ x hx, mem_ker.2 _, have := linear_pmap.sup_span_singleton_apply_mk ⟨p, 0⟩ v (1 : K) hpv x hx 0, simpa using (linear_map.congr_fun hf _).trans this } end theorem quotient_prod_linear_equiv (p : submodule K V) : nonempty (((V ⧸ p) × p) ≃ₗ[K] V) := let ⟨q, hq⟩ := p.exists_is_compl in nonempty.intro $ ((quotient_equiv_of_is_compl p q hq).prod (linear_equiv.refl _ _)).trans (prod_equiv_of_is_compl q p hq.symm) end field
b1df105d9b4f416d974c0e4f2da1f0b63bc3e895
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/measure_theory/outer_measure.lean
83a420076f7190800216cca011c7c841d0f21f65
[ "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
21,331
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, Mario Carneiro -/ import analysis.specific_limits import measure_theory.measurable_space import topology.algebra.infinite_sum /-! # Outer Measures An outer measure is a function `μ : set α → ennreal`, from the powerset of a type to the extended nonnegative real numbers that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is monotone; 3. `μ` is countably subadditive. This means that the outer measure of a countable union is at most the sum of the outer measure on the individual sets. Note that we do not need `α` to be measurable to define an outer measure. The outer measures on a type `α` form a complete lattice. Given an arbitrary function `m : set α → ennreal` that sends `∅` to `0` we can define an outer measure on `α` that on `s` is defined to be the infimum of `∑ᵢ, m (sᵢ)` for all collections of sets `sᵢ` that cover `s`. This is the unique maximal outer measure that is at most the given function. Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space. ## Main statements * `outer_measure.of_function` is the greatest outer measure that is at most the given function. * `caratheodory` is the Carathéodory-measurable space of an outer measure. * `Inf_eq_of_function_Inf_gen` is a characterization of the infimum of outer measures. ## References * <https://en.wikipedia.org/wiki/Outer_measure> * <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion> ## Tags outer measure, Carathéodory-measurable, Carathéodory's criterion -/ noncomputable theory open set finset function filter encodable open_locale classical big_operators namespace measure_theory /-- An outer measure is a countably subadditive monotone function that sends `∅` to `0`. -/ structure outer_measure (α : Type*) := (measure_of : set α → ennreal) (empty : measure_of ∅ = 0) (mono : ∀{s₁ s₂}, s₁ ⊆ s₂ → measure_of s₁ ≤ measure_of s₂) (Union_nat : ∀(s:ℕ → set α), measure_of (⋃i, s i) ≤ (∑'i, measure_of (s i))) namespace outer_measure section basic variables {α : Type*} {β : Type*} {ms : set (outer_measure α)} {m : outer_measure α} instance : has_coe_to_fun (outer_measure α) := ⟨_, λ m, m.measure_of⟩ @[simp] lemma measure_of_eq_coe (m : outer_measure α) : m.measure_of = m := rfl @[simp] theorem empty' (m : outer_measure α) : m ∅ = 0 := m.empty theorem mono' (m : outer_measure α) {s₁ s₂} (h : s₁ ⊆ s₂) : m s₁ ≤ m s₂ := m.mono h protected theorem Union (m : outer_measure α) {β} [encodable β] (s : β → set α) : m (⋃i, s i) ≤ (∑'i, m (s i)) := rel_supr_tsum m m.empty (≤) m.Union_nat s lemma Union_null (m : outer_measure α) {β} [encodable β] {s : β → set α} (h : ∀ i, m (s i) = 0) : m (⋃i, s i) = 0 := by simpa [h] using m.Union s protected lemma Union_finset (m : outer_measure α) (s : β → set α) (t : finset β) : m (⋃i ∈ t, s i) ≤ ∑ i in t, m (s i) := rel_supr_sum m m.empty (≤) m.Union_nat s t protected lemma union (m : outer_measure α) (s₁ s₂ : set α) : m (s₁ ∪ s₂) ≤ m s₁ + m s₂ := rel_sup_add m m.empty (≤) m.Union_nat s₁ s₂ lemma le_inter_add_diff {m : outer_measure α} {t : set α} (s : set α) : m t ≤ m (t ∩ s) + m (t \ s) := by { convert m.union _ _, rw inter_union_diff t s } lemma union_null (m : outer_measure α) {s₁ s₂ : set α} (h₁ : m s₁ = 0) (h₂ : m s₂ = 0) : m (s₁ ∪ s₂) = 0 := by simpa [h₁, h₂] using m.union s₁ s₂ lemma coe_fn_injective ⦃μ₁ μ₂ : outer_measure α⦄ (h : ⇑μ₁ = μ₂) : μ₁ = μ₂ := by { cases μ₁, cases μ₂, congr, exact h } @[ext] lemma ext {μ₁ μ₂ : outer_measure α} (h : ∀ s, μ₁ s = μ₂ s) : μ₁ = μ₂ := coe_fn_injective $ funext h instance : has_zero (outer_measure α) := ⟨{ measure_of := λ_, 0, empty := rfl, mono := assume _ _ _, le_refl 0, Union_nat := assume s, zero_le _ }⟩ @[simp] theorem coe_zero : ⇑(0 : outer_measure α) = 0 := rfl instance : inhabited (outer_measure α) := ⟨0⟩ instance : has_add (outer_measure α) := ⟨λm₁ m₂, { measure_of := λs, m₁ s + m₂ s, empty := show m₁ ∅ + m₂ ∅ = 0, by simp [outer_measure.empty], mono := assume s₁ s₂ h, add_le_add (m₁.mono h) (m₂.mono h), Union_nat := assume s, calc m₁ (⋃i, s i) + m₂ (⋃i, s i) ≤ (∑'i, m₁ (s i)) + (∑'i, m₂ (s i)) : add_le_add (m₁.Union_nat s) (m₂.Union_nat s) ... = _ : ennreal.tsum_add.symm}⟩ @[simp] theorem coe_add (m₁ m₂ : outer_measure α) : ⇑(m₁ + m₂) = m₁ + m₂ := rfl theorem add_apply (m₁ m₂ : outer_measure α) (s : set α) : (m₁ + m₂) s = m₁ s + m₂ s := rfl instance add_comm_monoid : add_comm_monoid (outer_measure α) := { zero := 0, add := (+), .. injective.add_comm_monoid (show outer_measure α → set α → ennreal, from coe_fn) coe_fn_injective rfl (λ _ _, rfl) } instance : has_scalar ennreal (outer_measure α) := ⟨λ c m, { measure_of := λ s, c * m s, empty := by simp, mono := λ s t h, ennreal.mul_left_mono $ m.mono h, Union_nat := λ s, by { rw [ennreal.tsum_mul_left], exact ennreal.mul_left_mono (m.Union _) } }⟩ @[simp] lemma coe_smul (c : ennreal) (m : outer_measure α) : ⇑(c • m) = c • m := rfl lemma smul_apply (c : ennreal) (m : outer_measure α) (s : set α) : (c • m) s = c * m s := rfl instance : semimodule ennreal (outer_measure α) := { smul := (•), .. injective.semimodule ennreal ⟨show outer_measure α → set α → ennreal, from coe_fn, coe_zero, coe_add⟩ coe_fn_injective coe_smul } instance : has_bot (outer_measure α) := ⟨0⟩ instance outer_measure.order_bot : order_bot (outer_measure α) := { le := λm₁ m₂, ∀s, m₁ s ≤ m₂ s, bot := 0, le_refl := assume a s, le_refl _, le_trans := assume a b c hab hbc s, le_trans (hab s) (hbc s), le_antisymm := assume a b hab hba, ext $ assume s, le_antisymm (hab s) (hba s), bot_le := assume a s, zero_le _ } section supremum instance : has_Sup (outer_measure α) := ⟨λms, { measure_of := λs, ⨆ m ∈ ms, (m : outer_measure α) s, empty := le_zero_iff_eq.1 $ bsupr_le $ λ m h, le_of_eq m.empty, mono := assume s₁ s₂ hs, bsupr_le_bsupr $ assume m hm, m.mono hs, Union_nat := assume f, bsupr_le $ assume m hm, calc m (⋃i, f i) ≤ (∑' (i : ℕ), m (f i)) : m.Union_nat _ ... ≤ (∑'i, ⨆ m ∈ ms, (m : outer_measure α) (f i)) : ennreal.tsum_le_tsum $ assume i, le_bsupr m hm }⟩ instance : complete_lattice (outer_measure α) := { .. outer_measure.order_bot, .. complete_lattice_of_Sup (outer_measure α) (λ ms, ⟨λ m hm s, le_bsupr m hm, λ m hm s, bsupr_le (λ m' hm', hm hm' s)⟩) } @[simp] theorem Sup_apply (ms : set (outer_measure α)) (s : set α) : (Sup ms) s = ⨆ m ∈ ms, (m : outer_measure α) s := rfl @[simp] theorem supr_apply {ι} (f : ι → outer_measure α) (s : set α) : (⨆ i : ι, f i) s = ⨆ i, f i s := by rw [supr, Sup_apply, supr_range, supr] @[norm_cast] theorem coe_supr {ι} (f : ι → outer_measure α) : ⇑(⨆ i, f i) = ⨆ i, f i := funext $ λ s, by rw [supr_apply, _root_.supr_apply] @[simp] theorem sup_apply (m₁ m₂ : outer_measure α) (s : set α) : (m₁ ⊔ m₂) s = m₁ s ⊔ m₂ s := by have := supr_apply (λ b, cond b m₁ m₂) s; rwa [supr_bool_eq, supr_bool_eq] at this end supremum /-- The pushforward of `m` along `f`. The outer measure on `s` is defined to be `m (f ⁻¹' s)`. -/ def map {β} (f : α → β) : outer_measure α →ₗ[ennreal] outer_measure β := { to_fun := λ m, { measure_of := λs, m (f ⁻¹' s), empty := m.empty, mono := λ s t h, m.mono (preimage_mono h), Union_nat := λ s, by rw [preimage_Union]; exact m.Union_nat (λ i, f ⁻¹' s i) }, map_add' := λ m₁ m₂, coe_fn_injective rfl, map_smul' := λ c m, coe_fn_injective rfl } @[simp] theorem map_apply {β} (f : α → β) (m : outer_measure α) (s : set β) : map f m s = m (f ⁻¹' s) := rfl @[simp] theorem map_id (m : outer_measure α) : map id m = m := ext $ λ s, rfl @[simp] theorem map_map {β γ} (f : α → β) (g : β → γ) (m : outer_measure α) : map g (map f m) = map (g ∘ f) m := ext $ λ s, rfl instance : functor outer_measure := {map := λ α β f, map f} instance : is_lawful_functor outer_measure := { id_map := λ α, map_id, comp_map := λ α β γ f g m, (map_map f g m).symm } /-- The dirac outer measure. -/ def dirac (a : α) : outer_measure α := { measure_of := λs, ⨆ h : a ∈ s, 1, empty := by simp, mono := λ s t h, supr_le_supr2 (λ h', ⟨h h', le_refl _⟩), Union_nat := λ s, supr_le $ λ h, let ⟨i, h⟩ := mem_Union.1 h in le_trans (by exact le_supr _ h) (ennreal.le_tsum i) } @[simp] theorem dirac_apply (a : α) (s : set α) : dirac a s = ⨆ h : a ∈ s, 1 := rfl /-- The sum of an (arbitrary) collection of outer measures. -/ def sum {ι} (f : ι → outer_measure α) : outer_measure α := { measure_of := λs, ∑' i, f i s, empty := by simp, mono := λ s t h, ennreal.tsum_le_tsum (λ i, (f i).mono' h), Union_nat := λ s, by rw ennreal.tsum_comm; exact ennreal.tsum_le_tsum (λ i, (f i).Union_nat _) } @[simp] theorem sum_apply {ι} (f : ι → outer_measure α) (s : set α) : sum f s = ∑' i, f i s := rfl theorem smul_dirac_apply (a : ennreal) (b : α) (s : set α) : (a • dirac b) s = ⨆ h : b ∈ s, a := by by_cases b ∈ s; simp [h] /-- Pullback of an `outer_measure`: `comap f μ s = μ (f '' s)`. -/ def comap {β} (f : α → β) : outer_measure β →ₗ[ennreal] outer_measure α := { to_fun := λ m, { measure_of := λ s, m (f '' s), empty := by simp, mono := λ s t h, m.mono $ image_subset f h, Union_nat := λ s, by { rw [image_Union], apply m.Union_nat } }, map_add' := λ m₁ m₂, rfl, map_smul' := λ c m, rfl } @[simp] lemma comap_apply {β} (f : α → β) (m : outer_measure β) (s : set α) : comap f m s = m (f '' s) := rfl /-- Restrict an `outer_measure` to a set. -/ def restrict (s : set α) : outer_measure α →ₗ[ennreal] outer_measure α := (map coe).comp (comap (coe : s → α)) @[simp] lemma restrict_apply (s t : set α) (m : outer_measure α) : restrict s m t = m (t ∩ s) := by simp [restrict] theorem top_apply {s : set α} (h : s.nonempty) : (⊤ : outer_measure α) s = ⊤ := let ⟨a, as⟩ := h in top_unique $ le_trans (by simp [smul_dirac_apply, as]) (le_bsupr ((⊤ : ennreal) • dirac a) trivial) end basic section of_function set_option eqn_compiler.zeta true /-- Given any function `m` assigning measures to sets satisying `m ∅ = 0`, there is a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : set α`. -/ protected def of_function {α : Type*} (m : set α → ennreal) (m_empty : m ∅ = 0) : outer_measure α := let μ := λs, ⨅{f : ℕ → set α} (h : s ⊆ ⋃i, f i), ∑'i, m (f i) in { measure_of := μ, empty := le_antisymm (infi_le_of_le (λ_, ∅) $ infi_le_of_le (empty_subset _) $ by simp [m_empty]) (zero_le _), mono := assume s₁ s₂ hs, infi_le_infi $ assume f, infi_le_infi2 $ assume hb, ⟨subset.trans hs hb, le_refl _⟩, Union_nat := assume s, ennreal.le_of_forall_epsilon_le $ begin assume ε hε (hb : (∑'i, μ (s i)) < ⊤), rcases ennreal.exists_pos_sum_of_encodable (ennreal.coe_lt_coe.2 hε) ℕ with ⟨ε', hε', hl⟩, refine le_trans _ (add_le_add_left (le_of_lt hl) _), rw ← ennreal.tsum_add, choose f hf using show ∀i, ∃f:ℕ → set α, s i ⊆ (⋃i, f i) ∧ (∑'i, m (f i)) < μ (s i) + ε' i, { intro, have : μ (s i) < μ (s i) + ε' i := ennreal.lt_add_right (lt_of_le_of_lt (by apply ennreal.le_tsum) hb) (by simpa using hε' i), simpa [μ, infi_lt_iff] }, refine le_trans _ (ennreal.tsum_le_tsum $ λ i, le_of_lt (hf i).2), rw [← ennreal.tsum_prod, ← equiv.nat_prod_nat_equiv_nat.symm.tsum_eq], swap, {apply_instance}, refine infi_le_of_le _ (infi_le _ _), exact Union_subset (λ i, subset.trans (hf i).1 $ Union_subset $ λ j, subset.trans (by simp) $ subset_Union _ $ equiv.nat_prod_nat_equiv_nat (i, j)), end } theorem of_function_le {α : Type*} (m : set α → ennreal) (m_empty s) : outer_measure.of_function m m_empty s ≤ m s := let f : ℕ → set α := λi, nat.rec_on i s (λn s, ∅) in infi_le_of_le f $ infi_le_of_le (subset_Union f 0) $ le_of_eq $ calc (∑'i, m (f i)) = ∑ i in {0}, m (f i) : tsum_eq_sum $ by intro i; cases i; simp [m_empty] ... = m s : by simp; refl theorem le_of_function {α : Type*} {m m_empty} {μ : outer_measure α} : μ ≤ outer_measure.of_function m m_empty ↔ ∀ s, μ s ≤ m s := ⟨λ H s, le_trans (H _) (of_function_le _ _ _), λ H s, le_infi $ λ f, le_infi $ λ hs, le_trans (μ.mono hs) $ le_trans (μ.Union f) $ ennreal.tsum_le_tsum $ λ i, H _⟩ end of_function section caratheodory_measurable universe u parameters {α : Type u} (m : outer_measure α) include m local attribute [simp] set.inter_comm set.inter_left_comm set.inter_assoc variables {s s₁ s₂ : set α} /-- A set `s` is Carathéodory-measurable for an outer measure `m` if for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. -/ private def C (s : set α) : Prop := ∀t, m t = m (t ∩ s) + m (t \ s) private lemma C_iff_le {s : set α} : C s ↔ ∀t, m (t ∩ s) + m (t \ s) ≤ m t := forall_congr $ λ t, le_antisymm_iff.trans $ and_iff_right $ le_inter_add_diff _ @[simp] private lemma C_empty : C ∅ := by simp [C, m.empty, diff_empty] private lemma C_compl : C s₁ → C s₁ᶜ := by simp [C, diff_eq, add_comm] @[simp] private lemma C_compl_iff : C sᶜ ↔ C s := ⟨λ h, by simpa using C_compl m h, C_compl⟩ private lemma C_union (h₁ : C s₁) (h₂ : C s₂) : C (s₁ ∪ s₂) := λ t, begin rw [h₁ t, h₂ (t ∩ s₁), h₂ (t \ s₁), h₁ (t ∩ (s₁ ∪ s₂)), inter_diff_assoc _ _ s₁, set.inter_assoc _ _ s₁, inter_eq_self_of_subset_right (set.subset_union_left _ _), union_diff_left, h₂ (t ∩ s₁)], simp [diff_eq, add_assoc] end private lemma measure_inter_union (h : s₁ ∩ s₂ ⊆ ∅) (h₁ : C s₁) {t : set α} : m (t ∩ (s₁ ∪ s₂)) = m (t ∩ s₁) + m (t ∩ s₂) := by rw [h₁, set.inter_assoc, set.union_inter_cancel_left, inter_diff_assoc, union_diff_cancel_left h] private lemma C_Union_lt {s : ℕ → set α} : ∀{n:ℕ}, (∀i<n, C (s i)) → C (⋃i<n, s i) | 0 h := by simp [nat.not_lt_zero] | (n + 1) h := by rw Union_lt_succ; exact C_union m (h n (le_refl (n + 1))) (C_Union_lt $ assume i hi, h i $ lt_of_lt_of_le hi $ nat.le_succ _) private lemma C_inter (h₁ : C s₁) (h₂ : C s₂) : C (s₁ ∩ s₂) := by rw [← C_compl_iff, compl_inter]; from C_union _ (C_compl _ h₁) (C_compl _ h₂) private lemma C_sum {s : ℕ → set α} (h : ∀i, C (s i)) (hd : pairwise (disjoint on s)) {t : set α} : ∀ {n}, ∑ i in finset.range n, m (t ∩ s i) = m (t ∩ ⋃i<n, s i) | 0 := by simp [nat.not_lt_zero, m.empty] | (nat.succ n) := begin simp [Union_lt_succ, range_succ], rw [measure_inter_union m _ (h n), C_sum], intro a, simpa [range_succ] using λ h₁ i hi h₂, hd _ _ (ne_of_gt hi) ⟨h₁, h₂⟩ end private lemma C_Union_nat {s : ℕ → set α} (h : ∀i, C (s i)) (hd : pairwise (disjoint on s)) : C (⋃i, s i) := C_iff_le.2 $ λ t, begin have hp : m (t ∩ ⋃i, s i) ≤ (⨆n, m (t ∩ ⋃i<n, s i)), { convert m.Union (λ i, t ∩ s i), { rw inter_Union }, { simp [ennreal.tsum_eq_supr_nat, C_sum m h hd] } }, refine le_trans (add_le_add_right hp _) _, rw ennreal.supr_add, refine supr_le (λ n, le_trans (add_le_add_left _ _) (ge_of_eq (C_Union_lt m (λ i _, h i) _))), refine m.mono (diff_subset_diff_right _), exact bUnion_subset (λ i _, subset_Union _ i), end private lemma f_Union {s : ℕ → set α} (h : ∀i, C (s i)) (hd : pairwise (disjoint on s)) : m (⋃i, s i) = ∑'i, m (s i) := begin refine le_antisymm (m.Union_nat s) _, rw ennreal.tsum_eq_supr_nat, refine supr_le (λ n, _), have := @C_sum _ m _ h hd univ n, simp at this, simp [this], exact m.mono (bUnion_subset (λ i _, subset_Union _ i)), end /-- The Carathéodory-measurable sets for an outer measure `m` form a Dynkin system. -/ private def caratheodory_dynkin : measurable_space.dynkin_system α := { has := C, has_empty := C_empty, has_compl := assume s, C_compl, has_Union_nat := assume f hf hn, C_Union_nat hn hf } /-- Given an outer measure `μ`, the Carathéodory-measurable space is defined such that `s` is measurable if `∀t, μ t = μ (t ∩ s) + μ (t \ s)`. -/ protected def caratheodory : measurable_space α := caratheodory_dynkin.to_measurable_space $ assume s₁ s₂, C_inter lemma is_caratheodory {s : set α} : caratheodory.is_measurable s ↔ ∀t, m t = m (t ∩ s) + m (t \ s) := iff.rfl lemma is_caratheodory_le {s : set α} : caratheodory.is_measurable s ↔ ∀t, m (t ∩ s) + m (t \ s) ≤ m t := C_iff_le protected lemma Union_eq_of_caratheodory {s : ℕ → set α} (h : ∀i, caratheodory.is_measurable (s i)) (hd : pairwise (disjoint on s)) : m (⋃i, s i) = ∑'i, m (s i) := f_Union h hd end caratheodory_measurable variables {α : Type*} lemma caratheodory_is_measurable {m : set α → ennreal} {s : set α} {h₀ : m ∅ = 0} (hs : ∀t, m (t ∩ s) + m (t \ s) ≤ m t) : (outer_measure.of_function m h₀).caratheodory.is_measurable s := let o := (outer_measure.of_function m h₀) in (is_caratheodory_le o).2 $ λ t, le_infi $ λ f, le_infi $ λ hf, begin refine le_trans (add_le_add (infi_le_of_le (λi, f i ∩ s) $ infi_le _ _) (infi_le_of_le (λi, f i \ s) $ infi_le _ _)) _, { rw ← Union_inter, exact inter_subset_inter_left _ hf }, { rw ← Union_diff, exact diff_subset_diff_left hf }, { rw ← ennreal.tsum_add, exact ennreal.tsum_le_tsum (λ i, hs _) } end @[simp] theorem zero_caratheodory : (0 : outer_measure α).caratheodory = ⊤ := top_unique $ λ s _ t, (add_zero _).symm theorem top_caratheodory : (⊤ : outer_measure α).caratheodory = ⊤ := top_unique $ assume s hs, (is_caratheodory_le _).2 $ assume t, t.eq_empty_or_nonempty.elim (λ ht, by simp [ht]) (λ ht, by simp only [ht, top_apply, le_top]) theorem le_add_caratheodory (m₁ m₂ : outer_measure α) : m₁.caratheodory ⊓ m₂.caratheodory ≤ (m₁ + m₂ : outer_measure α).caratheodory := λ s ⟨hs₁, hs₂⟩ t, by simp [hs₁ t, hs₂ t, add_left_comm, add_assoc] theorem le_sum_caratheodory {ι} (m : ι → outer_measure α) : (⨅ i, (m i).caratheodory) ≤ (sum m).caratheodory := λ s h t, by simp [λ i, measurable_space.is_measurable_infi.1 h i t, ennreal.tsum_add] theorem le_smul_caratheodory (a : ennreal) (m : outer_measure α) : m.caratheodory ≤ (a • m).caratheodory := λ s h t, by simp [h t, mul_add] @[simp] theorem dirac_caratheodory (a : α) : (dirac a).caratheodory = ⊤ := top_unique $ λ s _ t, begin by_cases a ∈ t; simp [h], by_cases a ∈ s; simp [h] end section Inf_gen /-- Given a set of outer measures, we define a new function that on a set `s` is defined to be the infimum of `μ(s)` for the outer measures `μ` in the collection. We ensure that this function is defined to be `0` on `∅`, even if the collection of outer measures is empty. The outer measure generated by this function is the infimum of the given outer measures. -/ def Inf_gen (m : set (outer_measure α)) (s : set α) : ennreal := ⨆(h : s.nonempty), ⨅ (μ : outer_measure α) (h : μ ∈ m), μ s @[simp] lemma Inf_gen_empty (m : set (outer_measure α)) : Inf_gen m ∅ = 0 := by simp [Inf_gen, empty_not_nonempty] lemma Inf_gen_nonempty1 (m : set (outer_measure α)) (t : set α) (h : t.nonempty) : Inf_gen m t = (⨅ (μ : outer_measure α) (h : μ ∈ m), μ t) := by rw [Inf_gen, supr_pos h] lemma Inf_gen_nonempty2 (m : set (outer_measure α)) (μ) (h : μ ∈ m) (t) : Inf_gen m t = (⨅ (μ : outer_measure α) (h : μ ∈ m), μ t) := begin cases t.eq_empty_or_nonempty with ht ht, { simp [ht], refine (bot_unique $ infi_le_of_le μ $ _).symm, refine infi_le_of_le h (le_refl ⊥) }, { exact Inf_gen_nonempty1 m t ht } end lemma Inf_eq_of_function_Inf_gen (m : set (outer_measure α)) : Inf m = outer_measure.of_function (Inf_gen m) (Inf_gen_empty m) := begin refine le_antisymm (assume t', le_of_function.2 (assume t, _) _) (_root_.le_Inf $ assume μ hμ t, le_trans (outer_measure.of_function_le _ _ _) _); cases t.eq_empty_or_nonempty with ht ht; simp [ht, Inf_gen_nonempty1], { assume μ hμ, exact (show Inf m ≤ μ, from _root_.Inf_le hμ) t }, { exact infi_le_of_le μ (infi_le _ hμ) } end end Inf_gen end outer_measure end measure_theory
f68ee6f9e0d16ed9d17a659dd82b1a33f91d7e66
3dc4623269159d02a444fe898d33e8c7e7e9461b
/.github/workflows/project_1_a_decrire/lean-scheme-submission/src/sheaves/stalk_of_rings_on_standard_basis.lean
7e1d459f82dcc36b67545c8d8431e2efc70fa780
[]
no_license
Or7ando/lean
cc003e6c41048eae7c34aa6bada51c9e9add9e66
d41169cf4e416a0d42092fb6bdc14131cee9dd15
refs/heads/master
1,650,600,589,722
1,587,262,906,000
1,587,262,906,000
255,387,160
0
0
null
null
null
null
UTF-8
Lean
false
false
14,192
lean
/- Stalk of rings on basis. https://stacks.math.columbia.edu/tag/007L (just says that the category of rings is a type of algebraic structure) -/ import to_mathlib.opens import topology.basic import sheaves.stalk_on_basis import sheaves.presheaf_of_rings_on_basis universe u open topological_space namespace stalk_of_rings_on_standard_basis variables {α : Type u} [topological_space α] variables {B : set (opens α )} {HB : opens.is_basis B} -- Standard basis. TODO: Move somewhere else? variables (Bstd : opens.univ ∈ B ∧ ∀ {U V}, U ∈ B → V ∈ B → U ∩ V ∈ B) variables (F : presheaf_of_rings_on_basis α HB) (x : α) include Bstd definition stalk_of_rings_on_standard_basis := stalk_on_basis F.to_presheaf_on_basis x section stalk_of_rings_on_standard_basis_is_ring open stalk_of_rings_on_standard_basis -- Add. protected def add_aux : stalk_on_basis.elem F.to_presheaf_on_basis x → stalk_on_basis.elem F.to_presheaf_on_basis x → stalk_on_basis F.to_presheaf_on_basis x := λ s t, ⟦{U := s.U ∩ t.U, BU := Bstd.2 s.BU t.BU, Hx := ⟨s.Hx, t.Hx⟩, s := F.res s.BU _ (set.inter_subset_left _ _) s.s + F.res t.BU _ (set.inter_subset_right _ _) t.s}⟧ instance has_add : has_add (stalk_of_rings_on_standard_basis Bstd F x) := { add := quotient.lift₂ (stalk_of_rings_on_standard_basis.add_aux Bstd F x) $ begin intros a1 a2 b1 b2 H1 H2, let F' := F.to_presheaf_on_basis, rcases H1 with ⟨U1, ⟨BU1, ⟨HxU1, ⟨HU1a1U, HU1b1U, HresU1⟩⟩⟩⟩, rcases H2 with ⟨U2, ⟨BU2, ⟨HxU2, ⟨HU2a2U, HU2b2U, HresU2⟩⟩⟩⟩, have BU1U2 := Bstd.2 BU1 BU2, apply quotient.sound, use [U1 ∩ U2, BU1U2, ⟨HxU1, HxU2⟩], use [set.inter_subset_inter HU1a1U HU2a2U, set.inter_subset_inter HU1b1U HU2b2U], repeat { rw (F.res_is_ring_hom _ _ _).map_add }, have HresU1' : (F'.res BU1 BU1U2 (set.inter_subset_left _ _) ((F'.res a1.BU BU1 HU1a1U) (a1.s))) = (F'.res BU1 BU1U2 (set.inter_subset_left _ _) ((F'.res b1.BU BU1 HU1b1U) (b1.s))) := by rw HresU1, have HresU2' : (F'.res BU2 BU1U2 (set.inter_subset_right _ _) ((F'.res a2.BU BU2 HU2a2U) (a2.s))) = (F'.res BU2 BU1U2 (set.inter_subset_right _ _) ((F'.res b2.BU BU2 HU2b2U) (b2.s))) := by rw HresU2, repeat { rw ←(presheaf_on_basis.Hcomp' F') at HresU1' }, repeat { rw ←(presheaf_on_basis.Hcomp' F') at HresU2' }, repeat { rw ←(presheaf_on_basis.Hcomp' F') }, rw [HresU1', HresU2'], end } @[simp] lemma has_add.mk : ∀ y z, (⟦y⟧ + ⟦z⟧ : stalk_of_rings_on_standard_basis Bstd F x) = (stalk_of_rings_on_standard_basis.add_aux Bstd F x) y z := λ y z, rfl instance add_semigroup : add_semigroup (stalk_of_rings_on_standard_basis Bstd F x) := { add_assoc := begin intros a b c, refine quotient.induction_on₃ a b c _, rintros ⟨U, BU, HxU, sU⟩ ⟨V, BV, HxV, sV⟩ ⟨W, BW, HxW, sW⟩, have BUVW := Bstd.2 (Bstd.2 BU BV) BW, have HUVWsub : U ∩ V ∩ W ⊆ U ∩ (V ∩ W) := λ x ⟨⟨HxU, HxV⟩, HxW⟩, ⟨HxU, ⟨HxV, HxW⟩⟩, apply quotient.sound, use [U ∩ V ∩ W, BUVW, ⟨⟨HxU, HxV⟩, HxW⟩], use [set.subset.refl _, HUVWsub], dsimp, repeat { rw (F.res_is_ring_hom _ _ _).map_add }, repeat { erw ←presheaf_on_basis.Hcomp' }, rw add_assoc, end, ..stalk_of_rings_on_standard_basis.has_add Bstd F x } instance add_comm_semigroup : add_comm_semigroup (stalk_of_rings_on_standard_basis Bstd F x) := { add_comm := begin intros a b, refine quotient.induction_on₂ a b _, rintros ⟨U, BU, HxU, sU⟩ ⟨V, BV, HxV, sV⟩, apply quotient.sound, have BUV : U ∩ V ∈ B := Bstd.2 BU BV, have HUVUV : U ∩ V ⊆ U ∩ V := λ x HxUV, HxUV, have HUVVU : U ∩ V ⊆ V ∩ U := λ x ⟨HxU, HxV⟩, ⟨HxV, HxU⟩, use [U ∩ V, BUV, ⟨HxU, HxV⟩, HUVUV, HUVVU], repeat { rw (F.res_is_ring_hom _ _ _).map_add }, repeat { rw ←presheaf_on_basis.Hcomp' }, rw add_comm, end, ..stalk_of_rings_on_standard_basis.add_semigroup Bstd F x } -- Zero. protected def zero : stalk_of_rings_on_standard_basis Bstd F x := ⟦{U := opens.univ, BU := Bstd.1, Hx := trivial, s:= 0}⟧ instance has_zero : has_zero (stalk_of_rings_on_standard_basis Bstd F x) := { zero := stalk_of_rings_on_standard_basis.zero Bstd F x } instance add_comm_monoid : add_comm_monoid (stalk_of_rings_on_standard_basis Bstd F x) := { zero_add := begin intros a, refine quotient.induction_on a _, rintros ⟨U, BU, HxU, sU⟩, apply quotient.sound, have HUsub : U ⊆ opens.univ ∩ U := λ x HxU, ⟨trivial, HxU⟩, use [U, BU, HxU, HUsub, set.subset.refl U], repeat { rw (F.res_is_ring_hom _ _ _).map_add }, repeat { rw ←presheaf_on_basis.Hcomp' }, erw (is_ring_hom.map_zero ((F.to_presheaf_on_basis).res _ _ _)); try { apply_instance }, rw zero_add, refl, end, add_zero := begin intros a, refine quotient.induction_on a _, rintros ⟨U, BU, HxU, sU⟩, apply quotient.sound, have HUsub : U ⊆ U ∩ opens.univ := λ x HxU, ⟨HxU, trivial⟩, use [U, BU, HxU, HUsub, set.subset.refl U], repeat { rw (F.res_is_ring_hom _ _ _).map_add }, repeat { rw ←presheaf_on_basis.Hcomp' }, dsimp, erw (is_ring_hom.map_zero ((F.to_presheaf_on_basis).res _ _ _)); try { apply_instance }, rw add_zero, refl, end, ..stalk_of_rings_on_standard_basis.has_zero Bstd F x, ..stalk_of_rings_on_standard_basis.add_comm_semigroup Bstd F x } -- Neg. protected def neg_aux : stalk_on_basis.elem F.to_presheaf_on_basis x → stalk_on_basis F.to_presheaf_on_basis x := λ s, ⟦{U := s.U, BU := s.BU, Hx := s.Hx, s := -s.s}⟧ instance has_neg : has_neg (stalk_of_rings_on_standard_basis Bstd F x) := { neg := quotient.lift (stalk_of_rings_on_standard_basis.neg_aux Bstd F x) $ begin intros a b H, rcases H with ⟨U, ⟨BU, ⟨HxU, ⟨HUaU, HUbU, HresU⟩⟩⟩⟩, apply quotient.sound, use [U, BU, HxU, HUaU, HUbU], repeat { rw @is_ring_hom.map_neg _ _ _ _ _ (F.res_is_ring_hom _ _ _) }, rw HresU, end } instance add_comm_group : add_comm_group (stalk_of_rings_on_standard_basis Bstd F x) := { add_left_neg := begin intros a, refine quotient.induction_on a _, rintros ⟨U, BU, HxU, sU⟩, apply quotient.sound, have HUUU : U ⊆ U ∩ U := λ x HxU, ⟨HxU, HxU⟩, have HUuniv : U ⊆ opens.univ := λ x HxU, trivial, use [U, BU, HxU, HUUU, HUuniv], repeat { rw (F.res_is_ring_hom _ _ _).map_add }, repeat { rw ←presheaf_on_basis.Hcomp' }, erw (is_ring_hom.map_neg ((F.to_presheaf_on_basis).res _ _ _)); try { apply_instance }, rw add_left_neg, erw (is_ring_hom.map_zero ((F.to_presheaf_on_basis).res _ _ _)); try { apply_instance }, end, ..stalk_of_rings_on_standard_basis.has_neg Bstd F x, ..stalk_of_rings_on_standard_basis.add_comm_monoid Bstd F x, } -- Mul. protected def mul_aux : stalk_on_basis.elem F.to_presheaf_on_basis x → stalk_on_basis.elem F.to_presheaf_on_basis x → stalk_on_basis F.to_presheaf_on_basis x := λ s t, ⟦{U := s.U ∩ t.U, BU := Bstd.2 s.BU t.BU, Hx := ⟨s.Hx, t.Hx⟩, s := F.res s.BU _ (set.inter_subset_left _ _) s.s * F.res t.BU _ (set.inter_subset_right _ _) t.s}⟧ instance has_mul : has_mul (stalk_of_rings_on_standard_basis Bstd F x) := { mul := quotient.lift₂ (stalk_of_rings_on_standard_basis.mul_aux Bstd F x) $ begin intros a1 a2 b1 b2 H1 H2, let F' := F.to_presheaf_on_basis, rcases H1 with ⟨U1, ⟨BU1, ⟨HxU1, ⟨HU1a1U, HU1b1U, HresU1⟩⟩⟩⟩, rcases H2 with ⟨U2, ⟨BU2, ⟨HxU2, ⟨HU2a2U, HU2b2U, HresU2⟩⟩⟩⟩, have BU1U2 := Bstd.2 BU1 BU2, apply quotient.sound, use [U1 ∩ U2, BU1U2, ⟨HxU1, HxU2⟩], use [set.inter_subset_inter HU1a1U HU2a2U, set.inter_subset_inter HU1b1U HU2b2U], repeat { rw (F.res_is_ring_hom _ _ _).map_mul }, have HresU1' : (F'.res BU1 BU1U2 (set.inter_subset_left _ _) ((F'.res a1.BU BU1 HU1a1U) (a1.s))) = (F'.res BU1 BU1U2 (set.inter_subset_left _ _) ((F'.res b1.BU BU1 HU1b1U) (b1.s))) := by rw HresU1, have HresU2' : (F'.res BU2 BU1U2 (set.inter_subset_right _ _) ((F'.res a2.BU BU2 HU2a2U) (a2.s))) = (F'.res BU2 BU1U2 (set.inter_subset_right _ _) ((F'.res b2.BU BU2 HU2b2U) (b2.s))) := by rw HresU2, repeat { rw ←(presheaf_on_basis.Hcomp' F') at HresU1' }, repeat { rw ←(presheaf_on_basis.Hcomp' F') at HresU2' }, repeat { rw ←(presheaf_on_basis.Hcomp' F') }, rw [HresU1', HresU2'], end} @[simp] lemma has_mul.mk : ∀ y z, (⟦y⟧ * ⟦z⟧ : stalk_of_rings_on_standard_basis Bstd F x) = (stalk_of_rings_on_standard_basis.mul_aux Bstd F x) y z := λ y z, rfl instance mul_semigroup : semigroup (stalk_of_rings_on_standard_basis Bstd F x) := { mul_assoc := begin intros a b c, refine quotient.induction_on₃ a b c _, rintros ⟨U, BU, HxU, sU⟩ ⟨V, BV, HxV, sV⟩ ⟨W, BW, HxW, sW⟩, have BUVW := Bstd.2 (Bstd.2 BU BV) BW, have HUVWsub : U ∩ V ∩ W ⊆ U ∩ (V ∩ W) := λ x ⟨⟨HxU, HxV⟩, HxW⟩, ⟨HxU, ⟨HxV, HxW⟩⟩, apply quotient.sound, use [U ∩ V ∩ W, BUVW, ⟨⟨HxU, HxV⟩, HxW⟩], use [set.subset.refl _, HUVWsub], repeat { rw (F.res_is_ring_hom _ _ _).map_mul }, repeat { rw ←presheaf_on_basis.Hcomp' }, rw mul_assoc, end, ..stalk_of_rings_on_standard_basis.has_mul Bstd F x } instance mul_comm_semigroup : comm_semigroup (stalk_of_rings_on_standard_basis Bstd F x) := { mul_comm := begin intros a b, refine quotient.induction_on₂ a b _, rintros ⟨U, BU, HxU, sU⟩ ⟨V, BV, HxV, sV⟩, apply quotient.sound, have BUV : U ∩ V ∈ B := Bstd.2 BU BV, have HUVUV : U ∩ V ⊆ U ∩ V := λ x HxUV, HxUV, have HUVVU : U ∩ V ⊆ V ∩ U := λ x ⟨HxU, HxV⟩, ⟨HxV, HxU⟩, use [U ∩ V, BUV, ⟨HxU, HxV⟩, HUVUV, HUVVU], repeat { rw (F.res_is_ring_hom _ _ _).map_mul }, repeat { rw ←presheaf_on_basis.Hcomp' }, rw mul_comm, end, ..stalk_of_rings_on_standard_basis.mul_semigroup Bstd F x } -- One. protected def one : stalk_of_rings_on_standard_basis Bstd F x := ⟦{U := opens.univ, BU := Bstd.1, Hx := trivial, s:= 1}⟧ instance has_one : has_one (stalk_of_rings_on_standard_basis Bstd F x) := { one := stalk_of_rings_on_standard_basis.one Bstd F x } instance mul_comm_monoid : comm_monoid (stalk_of_rings_on_standard_basis Bstd F x) := { one_mul := begin intros a, refine quotient.induction_on a _, rintros ⟨U, BU, HxU, sU⟩, apply quotient.sound, have HUsub : U ⊆ opens.univ ∩ U := λ x HxU, ⟨trivial, HxU⟩, use [U, BU, HxU, HUsub, set.subset.refl U], repeat { rw (F.res_is_ring_hom _ _ _).map_mul }, repeat { rw ←presheaf_on_basis.Hcomp' }, erw (is_ring_hom.map_one ((F.to_presheaf_on_basis).res _ _ _)); try { apply_instance }, rw one_mul, refl, end, mul_one := begin intros a, refine quotient.induction_on a _, rintros ⟨U, BU, HxU, sU⟩, apply quotient.sound, have HUsub : U ⊆ U ∩ opens.univ := λ x HxU, ⟨HxU, trivial⟩, use [U, BU, HxU, HUsub, set.subset.refl U], repeat { rw (F.res_is_ring_hom _ _ _).map_mul }, repeat { rw ←presheaf_on_basis.Hcomp' }, dsimp, erw (is_ring_hom.map_one ((F.to_presheaf_on_basis).res _ _ _)); try { apply_instance }, rw mul_one, refl, end, ..stalk_of_rings_on_standard_basis.has_one Bstd F x, ..stalk_of_rings_on_standard_basis.mul_comm_semigroup Bstd F x } -- Stalks of rings on standard basis are rings. instance comm_ring : comm_ring (stalk_of_rings_on_standard_basis Bstd F x) := { left_distrib := begin intros a b c, refine quotient.induction_on₃ a b c _, rintros ⟨U, BU, HxU, sU⟩ ⟨V, BV, HxV, sV⟩ ⟨W, BW, HxW, sW⟩, have BUVW := Bstd.2 (Bstd.2 BU BV) BW, have HUVWsub : U ∩ V ∩ W ⊆ U ∩ (V ∩ W) := λ x ⟨⟨HxU, HxV⟩, HxW⟩, ⟨HxU, ⟨HxV, HxW⟩⟩, have HUVWsub2 : U ∩ V ∩ W ⊆ U ∩ V ∩ (U ∩ W) := λ x ⟨⟨HxU, HxV⟩, HxW⟩, ⟨⟨HxU, HxV⟩, ⟨HxU, HxW⟩⟩, apply quotient.sound, use [U ∩ V ∩ W, BUVW, ⟨⟨HxU, HxV⟩, HxW⟩, HUVWsub, HUVWsub2], repeat { rw (F.res_is_ring_hom _ _ _).map_mul }, repeat { rw (F.res_is_ring_hom _ _ _).map_add }, repeat { rw ←presheaf_on_basis.Hcomp' }, repeat { rw (F.res_is_ring_hom _ _ _).map_mul }, repeat { rw (F.res_is_ring_hom _ _ _).map_add }, repeat { rw ←presheaf_on_basis.Hcomp' }, rw mul_add, end, right_distrib := begin intros a b c, refine quotient.induction_on₃ a b c _, rintros ⟨U, BU, HxU, sU⟩ ⟨V, BV, HxV, sV⟩ ⟨W, BW, HxW, sW⟩, have BUVW := Bstd.2 (Bstd.2 BU BV) BW, have HUVWrfl : U ∩ V ∩ W ⊆ U ∩ V ∩ W := λ x Hx, Hx, have HUVWsub : U ∩ V ∩ W ⊆ U ∩ W ∩ (V ∩ W) := λ x ⟨⟨HxU, HxV⟩, HxW⟩, ⟨⟨HxU, HxW⟩, ⟨HxV, HxW⟩⟩, apply quotient.sound, use [U ∩ V ∩ W, BUVW, ⟨⟨HxU, HxV⟩, HxW⟩, HUVWrfl, HUVWsub], repeat { rw (F.res_is_ring_hom _ _ _).map_mul }, repeat { rw (F.res_is_ring_hom _ _ _).map_add }, repeat { rw ←presheaf_on_basis.Hcomp' }, repeat { rw (F.res_is_ring_hom _ _ _).map_mul }, repeat { rw (F.res_is_ring_hom _ _ _).map_add }, repeat { rw ←presheaf_on_basis.Hcomp' }, rw add_mul, end, ..stalk_of_rings_on_standard_basis.add_comm_group Bstd F x, ..stalk_of_rings_on_standard_basis.mul_comm_monoid Bstd F x } end stalk_of_rings_on_standard_basis_is_ring end stalk_of_rings_on_standard_basis
e1c01e8b770a952b81135753154701bb266e3db9
3bdd27ffdff3ffa22d4bb010eba695afcc96bc4a
/src/combinatorics/simplicial_complex/to_move/continuous_linear_map.lean
00fbdc2c78d14d755bd814849f3954cb694264ce
[]
no_license
mmasdeu/brouwerfixedpoint
684d712c982c6a8b258b4e2c6b2eab923f2f1289
548270f79ecf12d7e20a256806ccb9fcf57b87e2
refs/heads/main
1,690,539,793,996
1,631,801,831,000
1,631,801,831,000
368,139,809
4
3
null
1,624,453,250,000
1,621,246,034,000
Lean
UTF-8
Lean
false
false
502
lean
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import topology.algebra.module theorem continuous_linear_map.is_linear {R : Type*} [semiring R] {M : Type*} [topological_space M] [add_comm_monoid M] {M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂] [module R M] [module R M₂] (f : M →L[R] M₂) : is_linear_map R ⇑f := f.to_linear_map.is_linear
d7f75f0a8c60cda96d2b8cb47dcc565640248da8
97f752b44fd85ec3f635078a2dd125ddae7a82b6
/library/theories/group_theory/cyclic.lean
3f861bafb11f0e66a9162000132c0496749f1480
[ "Apache-2.0" ]
permissive
tectronics/lean
ab977ba6be0fcd46047ddbb3c8e16e7c26710701
f38af35e0616f89c6e9d7e3eb1d48e47ee666efe
refs/heads/master
1,532,358,526,384
1,456,276,623,000
1,456,276,623,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
15,847
lean
/- Copyright (c) 2015 Haitao Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author : Haitao Zhang -/ import data algebra.group algebra.group_power .finsubg .hom .perm open function finset open eq.ops namespace group_theory section cyclic open nat fin list local attribute madd [reducible] variable {A : Type} variable [ambG : group A] include ambG lemma pow_mod {a : A} {n m : nat} : a ^ m = 1 → a ^ n = a ^ (n % m) := assume Pid, assert a ^ (n / m * m) = 1, from calc a ^ (n / m * m) = a ^ (m * (n / m)) : by rewrite (mul.comm (n / m) m) ... = (a ^ m) ^ (n / m) : by rewrite pow_mul ... = 1 ^ (n / m) : by rewrite Pid ... = 1 : one_pow (n / m), calc a ^ n = a ^ (n / m * m + n % m) : by rewrite -(eq_div_mul_add_mod n m) ... = a ^ (n / m * m) * a ^ (n % m) : by rewrite pow_add ... = 1 * a ^ (n % m) : by rewrite this ... = a ^ (n % m) : by rewrite one_mul lemma pow_sub_eq_one_of_pow_eq {a : A} {i j : nat} : a^i = a^j → a^(i - j) = 1 := assume Pe, or.elim (lt_or_ge i j) (assume Piltj, begin rewrite [sub_eq_zero_of_le (nat.le_of_lt Piltj)] end) (assume Pigej, begin rewrite [pow_sub a Pigej, Pe, mul.right_inv] end) lemma pow_dist_eq_one_of_pow_eq {a : A} {i j : nat} : a^i = a^j → a^(dist i j) = 1 := assume Pe, or.elim (lt_or_ge i j) (suppose i < j, by rewrite [dist_eq_sub_of_lt this]; exact pow_sub_eq_one_of_pow_eq (eq.symm Pe)) (suppose i ≥ j, by rewrite [dist_eq_sub_of_ge this]; exact pow_sub_eq_one_of_pow_eq Pe) lemma pow_madd {a : A} {n : nat} {i j : fin (succ n)} : a^(succ n) = 1 → a^(val (i + j)) = a^i * a^j := assume Pe, calc a^(val (i + j)) = a^((i + j) % (succ n)) : rfl ... = a^(val i + val j) : by rewrite [-pow_mod Pe] ... = a^i * a^j : by rewrite pow_add lemma mk_pow_mod {a : A} {n m : nat} : a ^ (succ m) = 1 → a ^ n = a ^ (mk_mod m n) := assume Pe, pow_mod Pe variable [finA : fintype A] include finA open fintype variable [deceqA : decidable_eq A] include deceqA lemma exists_pow_eq_one (a : A) : ∃ n, n < card A ∧ a ^ (succ n) = 1 := let f := (λ i : fin (succ (card A)), a ^ i) in assert Pninj : ¬(injective f), from assume Pinj, absurd (card_le_of_inj _ _ (exists.intro f Pinj)) (begin rewrite [card_fin], apply not_succ_le_self end), obtain i₁ P₁, from exists_not_of_not_forall Pninj, obtain i₂ P₂, from exists_not_of_not_forall P₁, obtain Pfe Pne, from and_not_of_not_implies P₂, assert Pvne : val i₁ ≠ val i₂, from assume Pveq, absurd (eq_of_veq Pveq) Pne, exists.intro (pred (dist i₁ i₂)) (begin rewrite [succ_pred_of_pos (dist_pos_of_ne Pvne)], apply and.intro, apply lt_of_succ_lt_succ, rewrite [succ_pred_of_pos (dist_pos_of_ne Pvne)], apply nat.lt_of_le_of_lt dist_le_max (max_lt i₁ i₂), apply pow_dist_eq_one_of_pow_eq Pfe end) -- Another possibility is to generate a list of powers and use find to get the first -- unity. -- The bound on bex is arbitrary as long as it is large enough (at least card A). Making -- it larger simplifies some proofs, such as a ∈ cyc a. definition cyc (a : A) : finset A := {x ∈ univ | bex (succ (card A)) (λ n, a ^ n = x)} definition order (a : A) := card (cyc a) definition pow_fin (a : A) (n : nat) (i : fin (order a)) := a ^ (i + n) definition cyc_pow_fin (a : A) (n : nat) : finset A := image (pow_fin a n) univ lemma order_le_group_order {a : A} : order a ≤ card A := card_le_card_of_subset !subset_univ lemma cyc_has_one (a : A) : 1 ∈ cyc a := begin apply mem_sep_of_mem !mem_univ, existsi 0, apply and.intro, apply zero_lt_succ, apply pow_zero end lemma order_pos (a : A) : 0 < order a := length_pos_of_mem (cyc_has_one a) lemma cyc_mul_closed (a : A) : finset_mul_closed_on (cyc a) := take g h, assume Pgin Phin, obtain n Plt Pe, from exists_pow_eq_one a, obtain i Pilt Pig, from of_mem_sep Pgin, obtain j Pjlt Pjh, from of_mem_sep Phin, begin rewrite [-Pig, -Pjh, -pow_add, pow_mod Pe], apply mem_sep_of_mem !mem_univ, existsi ((i + j) % (succ n)), apply and.intro, apply nat.lt_trans (mod_lt (i+j) !zero_lt_succ) (succ_lt_succ Plt), apply rfl end lemma cyc_has_inv (a : A) : finset_has_inv (cyc a) := take g, assume Pgin, obtain n Plt Pe, from exists_pow_eq_one a, obtain i Pilt Pig, from of_mem_sep Pgin, let ni := -(mk_mod n i) in assert Pinv : g*a^ni = 1, by rewrite [-Pig, mk_pow_mod Pe, -(pow_madd Pe), add.right_inv], begin rewrite [inv_eq_of_mul_eq_one Pinv], apply mem_sep_of_mem !mem_univ, existsi ni, apply and.intro, apply nat.lt_trans (is_lt ni) (succ_lt_succ Plt), apply rfl end lemma self_mem_cyc (a : A) : a ∈ cyc a := mem_sep_of_mem !mem_univ (exists.intro (1 : nat) (and.intro (succ_lt_succ card_pos) !pow_one)) lemma mem_cyc (a : A) : ∀ {n : nat}, a^n ∈ cyc a | 0 := cyc_has_one a | (succ n) := begin rewrite pow_succ', apply cyc_mul_closed a, exact mem_cyc, apply self_mem_cyc end lemma order_le {a : A} {n : nat} : a^(succ n) = 1 → order a ≤ succ n := assume Pe, let s := image (pow_nat a) (upto (succ n)) in assert Psub: cyc a ⊆ s, from subset_of_forall (take g, assume Pgin, obtain i Pilt Pig, from of_mem_sep Pgin, begin rewrite [-Pig, pow_mod Pe], apply mem_image, apply mem_upto_of_lt (mod_lt i !zero_lt_succ), exact rfl end), #nat calc order a ≤ card s : card_le_card_of_subset Psub ... ≤ card (upto (succ n)) : !card_image_le ... = succ n : card_upto (succ n) lemma pow_ne_of_lt_order {a : A} {n : nat} : succ n < order a → a^(succ n) ≠ 1 := assume Plt, not_imp_not_of_imp order_le (not_le_of_gt Plt) lemma eq_zero_of_pow_eq_one {a : A} : ∀ {n : nat}, a^n = 1 → n < order a → n = 0 | 0 := assume Pe Plt, rfl | (succ n) := assume Pe Plt, absurd Pe (pow_ne_of_lt_order Plt) lemma pow_fin_inj (a : A) (n : nat) : injective (pow_fin a n) := take i j : fin (order a), suppose a^(i + n) = a^(j + n), have a^(dist i j) = 1, begin apply !dist_add_add_right ▸ (pow_dist_eq_one_of_pow_eq this) end, have dist i j = 0, from eq_zero_of_pow_eq_one this (nat.lt_of_le_of_lt dist_le_max (max_lt i j)), eq_of_veq (eq_of_dist_eq_zero this) lemma cyc_eq_cyc (a : A) (n : nat) : cyc_pow_fin a n = cyc a := assert Psub : cyc_pow_fin a n ⊆ cyc a, from subset_of_forall (take g, assume Pgin, obtain i Pin Pig, from exists_of_mem_image Pgin, by rewrite [-Pig]; apply mem_cyc), eq_of_card_eq_of_subset (begin apply eq.trans, apply card_image_eq_of_inj_on, rewrite [to_set_univ, -set.injective_iff_inj_on_univ], exact pow_fin_inj a n, rewrite [card_fin] end) Psub lemma pow_order (a : A) : a^(order a) = 1 := obtain i Pin Pone, from exists_of_mem_image (eq.symm (cyc_eq_cyc a 1) ▸ cyc_has_one a), or.elim (eq_or_lt_of_le (succ_le_of_lt (is_lt i))) (assume P, P ▸ Pone) (assume P, absurd Pone (pow_ne_of_lt_order P)) lemma eq_one_of_order_eq_one {a : A} : order a = 1 → a = 1 := assume Porder, calc a = a^1 : by rewrite (pow_one a) ... = a^(order a) : by rewrite Porder ... = 1 : by rewrite pow_order lemma order_of_min_pow {a : A} {n : nat} (Pone : a^(succ n) = 1) (Pmin : ∀ i, i < n → a^(succ i) ≠ 1) : order a = succ n := or.elim (eq_or_lt_of_le (order_le Pone)) (λ P, P) (λ P : order a < succ n, begin assert Pn : a^(order a) ≠ 1, rewrite [-(succ_pred_of_pos (order_pos a))], apply Pmin, apply nat.lt_of_succ_lt_succ, rewrite [succ_pred_of_pos !order_pos], assumption, exact absurd (pow_order a) Pn end) lemma order_dvd_of_pow_eq_one {a : A} {n : nat} (Pone : a^n = 1) : order a ∣ n := assert Pe : a^(n % order a) = 1, from begin revert Pone, rewrite [eq_div_mul_add_mod n (order a) at {1}, pow_add, mul.comm _ (order a), pow_mul, pow_order, one_pow, one_mul], intros, assumption end, dvd_of_mod_eq_zero (eq_zero_of_pow_eq_one Pe (mod_lt n !order_pos)) definition cyc_is_finsubg [instance] (a : A) : is_finsubg (cyc a) := is_finsubg.mk (cyc_has_one a) (cyc_mul_closed a) (cyc_has_inv a) lemma order_dvd_group_order (a : A) : order a ∣ card A := dvd.intro (eq.symm (!mul.comm ▸ lagrange_theorem (subset_univ (cyc a)))) definition pow_fin' (a : A) (i : fin (succ (pred (order a)))) := pow_nat a i local attribute group_of_add_group [instance] lemma pow_fin_hom (a : A) : homomorphic (pow_fin' a) := take i j : fin (succ (pred (order a))), begin rewrite [↑pow_fin'], apply pow_madd, rewrite [succ_pred_of_pos !order_pos], exact pow_order a end definition pow_fin_is_iso (a : A) : is_iso_class (pow_fin' a) := is_iso_class.mk (pow_fin_hom a) (have H : injective (λ (i : fin (order a)), a ^ (val i + 0)), from pow_fin_inj a 0, begin+ rewrite [↑pow_fin', succ_pred_of_pos !order_pos]; exact H end) end cyclic section rot open nat list open fin fintype list section local attribute group_of_add_group [instance] lemma pow_eq_mul {n : nat} {i : fin (succ n)} : ∀ {k : nat}, i^k = mk_mod n (i*k) | 0 := by rewrite [pow_zero] | (succ k) := begin assert Psucc : i^(succ k) = madd (i^k) i, apply pow_succ', rewrite [Psucc, pow_eq_mul], apply eq_of_veq, rewrite [mul_succ, val_madd, ↑mk_mod, mod_add_mod] end end definition rotl : ∀ {n : nat} m : nat, fin n → fin n | 0 := take m i, elim0 i | (succ n) := take m, madd (mk_mod n (n*m)) definition rotr : ∀ {n : nat} m : nat, fin n → fin n | (0:nat) := take m i, elim0 i | (nat.succ n) := take m, madd (-(mk_mod n (n*m))) lemma rotl_succ' {n m : nat} : rotl m = madd (mk_mod n (n*m)) := rfl lemma rotl_zero : ∀ {n : nat}, @rotl n 0 = id | 0 := funext take i, elim0 i | (nat.succ n) := funext take i, begin rewrite [↑rotl, mul_zero, mk_mod_zero_eq, zero_madd] end lemma rotl_id : ∀ {n : nat}, @rotl n n = id | 0 := funext take i, elim0 i | (nat.succ n) := assert P : mk_mod n (n * succ n) = mk_mod n 0, from eq_of_veq (by rewrite [↑mk_mod, mul_mod_left]), begin rewrite [rotl_succ', P], apply rotl_zero end lemma rotl_to_zero {n i : nat} : rotl i (mk_mod n i) = 0 := eq_of_veq begin rewrite [↑rotl, val_madd], esimp [mk_mod], rewrite [ mod_add_mod, add_mod_mod, -succ_mul, mul_mod_right] end lemma rotl_compose : ∀ {n : nat} {j k : nat}, (@rotl n j) ∘ (rotl k) = rotl (j + k) | 0 := take j k, funext take i, elim0 i | (succ n) := take j k, funext take i, eq.symm begin rewrite [*rotl_succ', left_distrib, -(@madd_mk_mod n (n*j)), madd_assoc], end lemma rotr_rotl : ∀ {n : nat} (m : nat) {i : fin n}, rotr m (rotl m i) = i | 0 := take m i, elim0 i | (nat.succ n) := take m i, calc (-(mk_mod n (n*m))) + ((mk_mod n (n*m)) + i) = i : by rewrite neg_add_cancel_left lemma rotl_rotr : ∀ {n : nat} (m : nat), (@rotl n m) ∘ (rotr m) = id | 0 := take m, funext take i, elim0 i | (nat.succ n) := take m, funext take i, calc (mk_mod n (n*m)) + (-(mk_mod n (n*m)) + i) = i : add_neg_cancel_left lemma rotl_succ {n : nat} : (rotl 1) ∘ (@succ n) = lift_succ := funext (take i, eq_of_veq (begin rewrite [↑compose, ↑rotl, ↑madd, mul_one n, ↑mk_mod, mod_add_mod, ↑lift_succ, val_succ, -succ_add_eq_succ_add, add_mod_self_left, mod_eq_of_lt (lt.trans (is_lt i) !lt_succ_self), -val_lift] end)) definition list.rotl {A : Type} : ∀ l : list A, list A | [] := [] | (a::l) := l++[a] lemma rotl_cons {A : Type} {a : A} {l} : list.rotl (a::l) = l++[a] := rfl lemma rotl_map {A B : Type} {f : A → B} : ∀ {l : list A}, list.rotl (map f l) = map f (list.rotl l) | [] := rfl | (a::l) := begin rewrite [map_cons, *rotl_cons, map_append] end lemma rotl_eq_rotl : ∀ {n : nat}, map (rotl 1) (upto n) = list.rotl (upto n) | 0 := rfl | (succ n) := begin rewrite [upto_step at {1}, fin.upto_succ, rotl_cons, map_append], congruence, rewrite [map_map], congruence, exact rotl_succ, rewrite [map_singleton], congruence, rewrite [↑rotl, mul_one n, ↑mk_mod, ↑maxi, ↑madd], congruence, rewrite [ mod_add_mod, val_zero, add_zero, mod_eq_of_lt !lt_succ_self ] end definition seq [reducible] (A : Type) (n : nat) := fin n → A variable {A : Type} definition rotl_fun {n : nat} (m : nat) (f : seq A n) : seq A n := f ∘ (rotl m) definition rotr_fun {n : nat} (m : nat) (f : seq A n) : seq A n := f ∘ (rotr m) lemma rotl_seq_zero {n : nat} : rotl_fun 0 = @id (seq A n) := funext take f, begin rewrite [↑rotl_fun, rotl_zero] end lemma rotl_seq_ne_id : ∀ {n : nat}, (∃ a b : A, a ≠ b) → ∀ i, i < n → rotl_fun (succ i) ≠ (@id (seq A (succ n))) | 0 := assume Pex, take i, assume Piltn, absurd Piltn !not_lt_zero | (nat.succ n) := assume Pex, obtain a b Pne, from Pex, take i, assume Pilt, let f := (λ j : fin (succ (succ n)), if j = 0 then a else b), fi := mk_mod (succ n) (succ i) in have Pfne : rotl_fun (succ i) f fi ≠ f fi, from begin rewrite [↑rotl_fun, rotl_to_zero, mk_mod_of_lt (succ_lt_succ Pilt), if_pos rfl, if_neg mk_succ_ne_zero], assumption end, have P : rotl_fun (succ i) f ≠ f, from assume Peq, absurd (congr_fun Peq fi) Pfne, assume Peq, absurd (congr_fun Peq f) P lemma rotr_rotl_fun {n : nat} (m : nat) (f : seq A n) : rotr_fun m (rotl_fun m f) = f := calc f ∘ (rotl m) ∘ (rotr m) = f ∘ ((rotl m) ∘ (rotr m)) : by rewrite -compose.assoc ... = f ∘ id : by rewrite (rotl_rotr m) lemma rotl_fun_inj {n : nat} {m : nat} : @injective (seq A n) (seq A n) (rotl_fun m) := injective_of_has_left_inverse (exists.intro (rotr_fun m) (rotr_rotl_fun m)) lemma seq_rotl_eq_list_rotl {n : nat} (f : seq A n) : fun_to_list (rotl_fun 1 f) = list.rotl (fun_to_list f) := begin rewrite [↑fun_to_list, ↑rotl_fun, -map_map, rotl_map], congruence, exact rotl_eq_rotl end end rot section rotg open nat fin fintype definition rotl_perm [reducible] (A : Type) [finA : fintype A] [deceqA : decidable_eq A] (n : nat) (m : nat) : perm (seq A n) := perm.mk (rotl_fun m) rotl_fun_inj variable {A : Type} variable [finA : fintype A] variable [deceqA : decidable_eq A] variable {n : nat} include finA deceqA lemma rotl_perm_mul {i j : nat} : (rotl_perm A n i) * (rotl_perm A n j) = rotl_perm A n (j+i) := eq_of_feq (funext take f, calc f ∘ (rotl j) ∘ (rotl i) = f ∘ ((rotl j) ∘ (rotl i)) : by rewrite -compose.assoc ... = f ∘ (rotl (j+i)) : by rewrite rotl_compose) lemma rotl_perm_pow_eq : ∀ {i : nat}, (rotl_perm A n 1) ^ i = rotl_perm A n i | 0 := begin rewrite [pow_zero, ↑rotl_perm, perm_one, -eq_iff_feq], esimp, rewrite rotl_seq_zero end | (succ i) := begin rewrite [pow_succ', rotl_perm_pow_eq, rotl_perm_mul, one_add] end lemma rotl_perm_pow_eq_one : (rotl_perm A n 1) ^ n = 1 := eq.trans rotl_perm_pow_eq (eq_of_feq begin esimp [rotl_perm], rewrite [↑rotl_fun, rotl_id] end) lemma rotl_perm_mod {i : nat} : rotl_perm A n i = rotl_perm A n (i % n) := calc rotl_perm A n i = (rotl_perm A n 1) ^ i : by rewrite rotl_perm_pow_eq ... = (rotl_perm A n 1) ^ (i % n) : by rewrite (pow_mod rotl_perm_pow_eq_one) ... = rotl_perm A n (i % n) : by rewrite rotl_perm_pow_eq -- needs A to have at least two elements! lemma rotl_perm_pow_ne_one (Pex : ∃ a b : A, a ≠ b) : ∀ i, i < n → (rotl_perm A (succ n) 1)^(succ i) ≠ 1 := take i, assume Piltn, begin intro P, revert P, rewrite [rotl_perm_pow_eq, -eq_iff_feq, perm_one, *perm.f_mk], intro P, exact absurd P (rotl_seq_ne_id Pex i Piltn) end lemma rotl_perm_order (Pex : ∃ a b : A, a ≠ b) : order (rotl_perm A (succ n) 1) = (succ n) := order_of_min_pow rotl_perm_pow_eq_one (rotl_perm_pow_ne_one Pex) end rotg end group_theory
b3bf60b07a784b5b2d572ee04a69230df7210fd9
d9d511f37a523cd7659d6f573f990e2a0af93c6f
/src/topology/algebra/ring.lean
0986e29dd05397d7aeccf9d8e6a8407bfc889a84
[ "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
11,042
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 Theory of topological rings. -/ import topology.algebra.group import ring_theory.ideal.basic import ring_theory.subring import algebra.ring.prod /-! # Topological (semi)rings A topological (semi)ring is a (semi)ring equipped with a topology such that all operations are continuous. Besides this definition, this file proves that the topological closure of a subring (resp. an ideal) is a subring (resp. an ideal) and defines products and quotients of topological (semi)rings. ## Main Results - `subring.topological_closure`/`subsemiring.topological_closure`: the topological closure of a `subring`/`subsemiring` is itself a `sub(semi)ring`. - `prod.topological_ring`/`prod.topological_ring`: The product of two topological (semi)rings. - `pi.topological_ring`/`pi.topological_ring`: The arbitrary product of topological (semi)rings. - `ideal.closure`: The closure of an ideal is an ideal. - `topological_ring_quotient`: The quotient of a topological ring by an ideal is a topological ring. -/ open classical set filter topological_space open_locale classical section topological_ring variables (α : Type*) /-- A topological (semi)ring is a (semi)ring `R` where addition and multiplication are continuous. If `R` is a ring, then negation is automatically continuous, as it is multiplication with `-1`. -/ class topological_ring [topological_space α] [semiring α] extends has_continuous_add α, has_continuous_mul α : Prop section variables {α} [topological_space α] [semiring α] [topological_ring α] /-- The (topological-space) closure of a subsemiring of a topological semiring is itself a subsemiring. -/ def subsemiring.topological_closure (s : subsemiring α) : subsemiring α := { carrier := closure (s : set α), ..(s.to_submonoid.topological_closure), ..(s.to_add_submonoid.topological_closure ) } @[simp] lemma subsemiring.topological_closure_coe (s : subsemiring α) : (s.topological_closure : set α) = closure (s : set α) := rfl instance subsemiring.topological_closure_topological_ring (s : subsemiring α) : topological_ring (s.topological_closure) := { ..s.to_add_submonoid.topological_closure_has_continuous_add, ..s.to_submonoid.topological_closure_has_continuous_mul } lemma subsemiring.subring_topological_closure (s : subsemiring α) : s ≤ s.topological_closure := subset_closure lemma subsemiring.is_closed_topological_closure (s : subsemiring α) : is_closed (s.topological_closure : set α) := by convert is_closed_closure lemma subsemiring.topological_closure_minimal (s : subsemiring α) {t : subsemiring α} (h : s ≤ t) (ht : is_closed (t : set α)) : s.topological_closure ≤ t := closure_minimal h ht /-- The product topology on the cartesian product of two topological semirings makes the product into a topological semiring. -/ instance {β : Type*} [semiring β] [topological_space β] [topological_ring β] : topological_ring (α × β) := {} instance {β : Type*} {C : β → Type*} [∀ b, topological_space (C b)] [Π b, semiring (C b)] [Π b, topological_ring (C b)] : topological_ring (Π b, C b) := {} end variables {α} [ring α] [topological_space α] [topological_ring α] @[priority 100] -- See note [lower instance priority] instance topological_ring.to_topological_add_group : topological_add_group α := { continuous_add := continuous_add, continuous_neg := by simpa only [neg_one_mul, id.def] using (@continuous_const α α _ _ (-1)).mul continuous_id } /-- In a topological ring, the left-multiplication `add_monoid_hom` is continuous. -/ lemma mul_left_continuous (x : α) : continuous (add_monoid_hom.mul_left x) := continuous_const.mul continuous_id /-- In a topological ring, the right-multiplication `add_monoid_hom` is continuous. -/ lemma mul_right_continuous (x : α) : continuous (add_monoid_hom.mul_right x) := continuous_id.mul continuous_const /-- The (topological-space) closure of a subring of a topological semiring is itself a subring. -/ def subring.topological_closure (S : subring α) : subring α := { carrier := closure (S : set α), ..S.to_submonoid.topological_closure, ..S.to_add_subgroup.topological_closure } instance subring.topological_closure_topological_ring (s : subring α) : topological_ring (s.topological_closure) := { ..s.to_add_subgroup.topological_closure_topological_add_group, ..s.to_submonoid.topological_closure_has_continuous_mul } lemma subring.subring_topological_closure (s : subring α) : s ≤ s.topological_closure := subset_closure lemma subring.is_closed_topological_closure (s : subring α) : is_closed (s.topological_closure : set α) := by convert is_closed_closure lemma subring.topological_closure_minimal (s : subring α) {t : subring α} (h : s ≤ t) (ht : is_closed (t : set α)) : s.topological_closure ≤ t := closure_minimal h ht end topological_ring section topological_comm_ring variables {α : Type*} [topological_space α] [comm_ring α] [topological_ring α] /-- The closure of an ideal in a topological ring as an ideal. -/ def ideal.closure (S : ideal α) : ideal α := { carrier := closure S, smul_mem' := λ c x hx, map_mem_closure (mul_left_continuous _) hx $ λ a, S.mul_mem_left c, ..(add_submonoid.topological_closure S.to_add_submonoid) } @[simp] lemma ideal.coe_closure (S : ideal α) : (S.closure : set α) = closure S := rfl end topological_comm_ring section topological_ring variables {α : Type*} [topological_space α] [comm_ring α] (N : ideal α) open ideal.quotient instance topological_ring_quotient_topology : topological_space N.quotient := by dunfold ideal.quotient submodule.quotient; apply_instance -- note for the reader: in the following, `mk` is `ideal.quotient.mk`, the canonical map `R → R/I`. variable [topological_ring α] lemma quotient_ring.is_open_map_coe : is_open_map (mk N) := begin intros s s_op, change is_open (mk N ⁻¹' (mk N '' s)), rw quotient_ring_saturate, exact is_open_Union (λ ⟨n, _⟩, is_open_map_add_left n s s_op) end lemma quotient_ring.quotient_map_coe_coe : quotient_map (λ p : α × α, (mk N p.1, mk N p.2)) := is_open_map.to_quotient_map ((quotient_ring.is_open_map_coe N).prod (quotient_ring.is_open_map_coe N)) ((continuous_quot_mk.comp continuous_fst).prod_mk (continuous_quot_mk.comp continuous_snd)) (by rintro ⟨⟨x⟩, ⟨y⟩⟩; exact ⟨(x, y), rfl⟩) instance topological_ring_quotient : topological_ring N.quotient := { continuous_add := have cont : continuous (mk N ∘ (λ (p : α × α), p.fst + p.snd)) := continuous_quot_mk.comp continuous_add, (quotient_map.continuous_iff (quotient_ring.quotient_map_coe_coe N)).mpr cont, continuous_mul := have cont : continuous (mk N ∘ (λ (p : α × α), p.fst * p.snd)) := continuous_quot_mk.comp continuous_mul, (quotient_map.continuous_iff (quotient_ring.quotient_map_coe_coe N)).mpr cont } end topological_ring /-! ### Lattice of ring topologies We define a type class `ring_topology α` which endows a ring `α` with a topology such that all ring operations are continuous. Ring topologies on a fixed ring `α` are ordered, by reverse inclusion. They form a complete lattice, with `⊥` the discrete topology and `⊤` the indiscrete topology. Any function `f : α → β` induces `coinduced f : topological_space α → ring_topology β`. -/ universes u v /-- A ring topology on a ring `α` is a topology for which addition, negation and multiplication are continuous. -/ @[ext] structure ring_topology (α : Type u) [ring α] extends topological_space α, topological_ring α : Type u namespace ring_topology variables {α : Type*} [ring α] instance inhabited {α : Type u} [ring α] : inhabited (ring_topology α) := ⟨{to_topological_space := ⊤, continuous_add := continuous_top, continuous_mul := continuous_top}⟩ @[ext] lemma ext' {f g : ring_topology α} (h : f.is_open = g.is_open) : f = g := by { ext, rw h } /-- The ordering on ring topologies on the ring `α`. `t ≤ s` if every set open in `s` is also open in `t` (`t` is finer than `s`). -/ instance : partial_order (ring_topology α) := partial_order.lift ring_topology.to_topological_space $ ext local notation `cont` := @continuous _ _ private def def_Inf (S : set (ring_topology α)) : ring_topology α := let Inf_S' := Inf (to_topological_space '' S) in { to_topological_space := Inf_S', continuous_add := begin apply continuous_Inf_rng, rintros _ ⟨⟨t, tr⟩, haS, rfl⟩, resetI, have h := continuous_Inf_dom (set.mem_image_of_mem to_topological_space haS) continuous_id, have h_continuous_id := @continuous.prod_map _ _ _ _ t t Inf_S' Inf_S' _ _ h h, have h_continuous_add : cont (id _) t (λ (p : α × α), p.fst + p.snd) := continuous_add, exact @continuous.comp _ _ _ (id _) (id _) t _ _ h_continuous_add h_continuous_id, end, continuous_mul := begin apply continuous_Inf_rng, rintros _ ⟨⟨t, tr⟩, haS, rfl⟩, resetI, have h := continuous_Inf_dom (set.mem_image_of_mem to_topological_space haS) continuous_id, have h_continuous_id := @continuous.prod_map _ _ _ _ t t Inf_S' Inf_S' _ _ h h, have h_continuous_mul : cont (id _) t (λ (p : α × α), p.fst * p.snd) := continuous_mul, exact @continuous.comp _ _ _ (id _) (id _) t _ _ h_continuous_mul h_continuous_id, end } /-- Ring topologies on `α` form a complete lattice, with `⊥` the discrete topology and `⊤` the indiscrete topology. The infimum of a collection of ring topologies is the topology generated by all their open sets (which is a ring topology). The supremum of two ring topologies `s` and `t` is the infimum of the family of all ring topologies contained in the intersection of `s` and `t`. -/ instance : complete_semilattice_Inf (ring_topology α) := { Inf := def_Inf, Inf_le := λ S a haS, by { apply topological_space.complete_lattice.Inf_le, use [a, ⟨ haS, rfl⟩] }, le_Inf := begin intros S a hab, apply topological_space.complete_lattice.le_Inf, rintros _ ⟨b, hbS, rfl⟩, exact hab b hbS, end, ..ring_topology.partial_order } instance : complete_lattice (ring_topology α) := complete_lattice_of_complete_semilattice_Inf _ /-- Given `f : α → β` and a topology on `α`, the coinduced ring topology on `β` is the finest topology such that `f` is continuous and `β` is a topological ring. -/ def coinduced {α β : Type*} [t : topological_space α] [ring β] (f : α → β) : ring_topology β := Inf {b : ring_topology β | (topological_space.coinduced f t) ≤ b.to_topological_space} lemma coinduced_continuous {α β : Type*} [t : topological_space α] [ring β] (f : α → β) : cont t (coinduced f).to_topological_space f := begin rw continuous_iff_coinduced_le, refine le_Inf _, rintros _ ⟨t', ht', rfl⟩, exact ht', end end ring_topology
76e4e22edf71beb74b8e86fc565c58f961be95ad
ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5
/stage0/src/Lean/Elab/App.lean
8c8846dad722ae669997a4f5731a7f5a1366c5c3
[ "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
43,839
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.FindMVar import Lean.Elab.Term import Lean.Elab.Binders import Lean.Elab.SyntheticMVars namespace Lean.Elab.Term open Meta builtin_initialize elabWithoutExpectedTypeAttr : TagAttribute ← registerTagAttribute `elabWithoutExpectedType "mark that applications of the given declaration should be elaborated without the expected type" def hasElabWithoutExpectedType (env : Environment) (declName : Name) : Bool := elabWithoutExpectedTypeAttr.hasTag env declName /-- Auxiliary inductive datatype for combining unelaborated syntax and already elaborated expressions. It is used to elaborate applications. -/ inductive Arg where | stx (val : Syntax) | expr (val : Expr) deriving Inhabited instance : ToString Arg := ⟨fun | Arg.stx val => toString val | Arg.expr val => toString val⟩ /-- Named arguments created using the notation `(x := val)` -/ structure NamedArg where ref : Syntax := Syntax.missing name : Name val : Arg deriving Inhabited instance : ToString NamedArg where toString s := "(" ++ toString s.name ++ " := " ++ toString s.val ++ ")" def throwInvalidNamedArg {α} (namedArg : NamedArg) (fn? : Option Name) : TermElabM α := withRef namedArg.ref $ match fn? with | some fn => throwError! "invalid argument name '{namedArg.name}' for function '{fn}'" | none => throwError! "invalid argument name '{namedArg.name}' for function" /-- Add a new named argument to `namedArgs`, and throw an error if it already contains a named argument with the same name. -/ def addNamedArg (namedArgs : Array NamedArg) (namedArg : NamedArg) : TermElabM (Array NamedArg) := do if namedArgs.any (namedArg.name == ·.name) then throwError! "argument '{namedArg.name}' was already set" pure $ namedArgs.push namedArg private def ensureArgType (f : Expr) (arg : Expr) (expectedType : Expr) : TermElabM Expr := do let argType ← inferType arg ensureHasTypeAux expectedType argType arg f /- Relevant definitions: ``` class CoeFun (α : Sort u) (γ : α → outParam (Sort v)) abbrev coeFun {α : Sort u} {γ : α → Sort v} (a : α) [CoeFun α γ] : γ a ``` -/ private def tryCoeFun? (α : Expr) (a : Expr) : TermElabM (Option Expr) := do let v ← mkFreshLevelMVar let type ← mkArrow α (mkSort v) let γ ← mkFreshExprMVar type let u ← getLevel α let coeFunInstType := mkAppN (Lean.mkConst `CoeFun [u, v]) #[α, γ] let mvar ← mkFreshExprMVar coeFunInstType MetavarKind.synthetic let mvarId := mvar.mvarId! try if (← synthesizeCoeInstMVarCore mvarId) then pure $ some $ mkAppN (Lean.mkConst `coeFun [u, v]) #[α, γ, a, mvar] else pure none catch _ => pure none def synthesizeAppInstMVars (instMVars : Array MVarId) : TermElabM Unit := for mvarId in instMVars do unless (← synthesizeInstMVarCore mvarId) do registerSyntheticMVarWithCurrRef mvarId SyntheticMVarKind.typeClass namespace ElabAppArgs /- Auxiliary structure for elaborating the application `f args namedArgs`. -/ structure State where explicit : Bool -- true if `@` modifier was used f : Expr fType : Expr args : List Arg -- remaining regular arguments namedArgs : List NamedArg -- remaining named arguments to be processed ellipsis : Bool := false expectedType? : Option Expr etaArgs : Array Expr := #[] toSetErrorCtx : Array MVarId := #[] -- metavariables that we need the set the error context using the application being built instMVars : Array MVarId := #[] -- metavariables for the instance implicit arguments that have already been processed -- The following field is used to implement the `propagateExpectedType` heuristic. propagateExpected : Bool -- true when expectedType has not been propagated yet abbrev M := StateRefT State TermElabM /- Add the given metavariable to the collection of metavariables associated with instance-implicit arguments. -/ private def addInstMVar (mvarId : MVarId) : M Unit := modify fun s => { s with instMVars := s.instMVars.push mvarId } /- Try to synthesize metavariables are `instMVars` using type class resolution. The ones that cannot be synthesized yet are registered. Remark: we use this method before trying to apply coercions to function. -/ def synthesizeAppInstMVars : M Unit := do let s ← get let instMVars := s.instMVars modify fun s => { s with instMVars := #[] } Lean.Elab.Term.synthesizeAppInstMVars instMVars /- fType may become a forallE after we synthesize pending metavariables. -/ private def synthesizePendingAndNormalizeFunType : M Unit := do synthesizeAppInstMVars synthesizeSyntheticMVars let s ← get let fType ← whnfForall s.fType match fType with | Expr.forallE _ _ _ _ => modify fun s => { s with fType := fType } | _ => match (← tryCoeFun? fType s.f) with | some f => let fType ← inferType f modify fun s => { s with f := f, fType := fType } | none => for namedArg in s.namedArgs do match s.f.getAppFn with | Expr.const fn .. => throwInvalidNamedArg namedArg fn | _ => throwInvalidNamedArg namedArg none throwError! "function expected at{indentExpr s.f}\nterm has type{indentExpr fType}" /- Normalize and return the function type. -/ private def normalizeFunType : M Expr := do let s ← get let fType ← whnfForall s.fType modify fun s => { s with fType := fType } pure fType /- Return the binder name at `fType`. This method assumes `fType` is a function type. -/ private def getBindingName : M Name := return (← get).fType.bindingName! /- Return the next argument expected type. This method assumes `fType` is a function type. -/ private def getArgExpectedType : M Expr := return (← get).fType.bindingDomain! def eraseNamedArgCore (namedArgs : List NamedArg) (binderName : Name) : List NamedArg := namedArgs.filter (·.name != binderName) /- Remove named argument with name `binderName` from `namedArgs`. -/ def eraseNamedArg (binderName : Name) : M Unit := modify fun s => { s with namedArgs := eraseNamedArgCore s.namedArgs binderName } /- Add a new argument to the result. That is, `f := f arg`, update `fType`. This method assumes `fType` is a function type. -/ private def addNewArg (arg : Expr) : M Unit := modify fun s => { s with f := mkApp s.f arg, fType := s.fType.bindingBody!.instantiate1 arg } /- Elaborate the given `Arg` and add it to the result. See `addNewArg`. Recall that, `Arg` may be wrapping an already elaborated `Expr`. -/ private def elabAndAddNewArg (arg : Arg) : M Unit := do let s ← get let expectedType ← getArgExpectedType match arg with | Arg.expr val => let arg ← ensureArgType s.f val expectedType addNewArg arg | Arg.stx val => let val ← elabTerm val expectedType let arg ← ensureArgType s.f val expectedType addNewArg arg /- Return true if the given type contains `OptParam` or `AutoParams` -/ private def hasOptAutoParams (type : Expr) : M Bool := do forallTelescopeReducing type fun xs type => xs.anyM fun x => do let xType ← inferType x pure $ xType.getOptParamDefault?.isSome || xType.getAutoParamTactic?.isSome /- Return true if `fType` contains `OptParam` or `AutoParams` -/ private def fTypeHasOptAutoParams : M Bool := do hasOptAutoParams (← get).fType /- Auxiliary function for retrieving the resulting type of a function application. See `propagateExpectedType`. Remark: `(explicit : Bool) == true` when `@` modifier is used. -/ private partial def getForallBody (explicit : Bool) : Nat → List NamedArg → Expr → Option Expr | i, namedArgs, type@(Expr.forallE n d b c) => match namedArgs.find? fun (namedArg : NamedArg) => namedArg.name == n with | some _ => getForallBody explicit i (eraseNamedArgCore namedArgs n) b | none => if !explicit && !c.binderInfo.isExplicit then getForallBody explicit i namedArgs b else if i > 0 then getForallBody explicit (i-1) namedArgs b else if d.isAutoParam || d.isOptParam then getForallBody explicit i namedArgs b else some type | 0, [], type => some type | _, _, _ => none private def shouldPropagateExpectedTypeFor (nextArg : Arg) : Bool := match nextArg with | Arg.expr _ => false -- it has already been elaborated | Arg.stx stx => -- TODO: make this configurable? stx.getKind != `Lean.Parser.Term.hole && stx.getKind != `Lean.Parser.Term.syntheticHole && stx.getKind != `Lean.Parser.Term.byTactic /- Auxiliary method for propagating the expected type. We call it as soon as we find the first explict argument. The goal is to propagate the expected type in applications of functions such as ```lean Add.add {α : Type u} : α → α → α List.cons {α : Type u} : α → List α → List α ``` This is particularly useful when there applicable coercions. For example, assume we have a coercion from `Nat` to `Int`, and we have `(x : Nat)` and the expected type is `List Int`. Then, if we don't use this function, the elaborator will fail to elaborate ``` List.cons x [] ``` First, the elaborator creates a new metavariable `?α` for the implicit argument `{α : Type u}`. Then, when it processes `x`, it assigns `?α := Nat`, and then obtain the resultant type `List Nat` which is **not** definitionally equal to `List Int`. We solve the problem by executing this method before we elaborate the first explicit argument (`x` in this example). This method infers that the resultant type is `List ?α` and unifies it with `List Int`. Then, when we elaborate `x`, the elaborate realizes the coercion from `Nat` to `Int` must be used, and the term ``` @List.cons Int (coe x) (@List.nil Int) ``` is produced. The method will do nothing if 1- The resultant type depends on the remaining arguments (i.e., `!eTypeBody.hasLooseBVars`). 2- The resultant type contains optional/auto params. We have considered adding the following extra conditions a) The resultant type does not contain any type metavariable. b) The resultant type contains a nontype metavariable. These two conditions would restrict the method to simple functions that are "morally" in the Hindley&Milner fragment. If users need to disable expected type propagation, we can add an attribute `[elabWithoutExpectedType]`. -/ private def propagateExpectedType (arg : Arg) : M Unit := do if shouldPropagateExpectedTypeFor arg then let s ← get -- TODO: handle s.etaArgs.size > 0 unless !s.etaArgs.isEmpty || !s.propagateExpected do match s.expectedType? with | none => pure () | some expectedType => /- We don't propagate `Prop` because we often use `Prop` as a more general "Bool" (e.g., `if-then-else`). If we propagate `expectedType == Prop` in the following examples, the elaborator would fail ``` def f1 (s : Nat × Bool) : Bool := if s.2 then false else true def f2 (s : List Bool) : Bool := if s.head! then false else true def f3 (s : List Bool) : Bool := if List.head! (s.map not) then false else true ``` They would all fail for the same reason. So, let's focus on the first one. We would elaborate `s.2` with `expectedType == Prop`. Before we elaborate `s`, this method would be invoked, and `s.fType` is `?α × ?β → ?β` and after propagation we would have `?α × Prop → Prop`. Then, when we would try to elaborate `s`, and get a type error because `?α × Prop` cannot be unified with `Nat × Bool` Most users would have a hard time trying to understand why these examples failed. Here is a possible alternative workarounds. We give up the idea of using `Prop` at `if-then-else`. Drawback: users use `if-then-else` with conditions that are not Decidable. So, users would have to embrace `propDecidable` and `choice`. This may not be that bad since the developers and users don't seem to care about constructivism. We currently use a different workaround, we just don't propagate the expected type when it is `Prop`. -/ if expectedType.isProp then modify fun s => { s with propagateExpected := false } else let numRemainingArgs := s.args.length trace[Elab.app.propagateExpectedType]! "etaArgs.size: {s.etaArgs.size}, numRemainingArgs: {numRemainingArgs}, fType: {s.fType}" match getForallBody s.explicit numRemainingArgs s.namedArgs s.fType with | none => pure () | some fTypeBody => unless fTypeBody.hasLooseBVars do unless (← hasOptAutoParams fTypeBody) do trace[Elab.app.propagateExpectedType]! "{expectedType} =?= {fTypeBody}" if (← isDefEq expectedType fTypeBody) then /- Note that we only set `propagateExpected := false` when propagation has succeeded. -/ modify fun s => { s with propagateExpected := false } /- Create a fresh local variable with the current binder name and argument type, add it to `etaArgs` and `f`, and then execute the continuation `k`.-/ private def addEtaArg (k : M Expr) : M Expr := do let n ← getBindingName let type ← getArgExpectedType withLocalDeclD n type fun x => do modify fun s => { s with etaArgs := s.etaArgs.push x } addNewArg x k /- This method execute after all application arguments have been processed. -/ private def finalize : M Expr := do let s ← get let mut e := s.f -- all user explicit arguments have been consumed trace[Elab.app.finalize]! e let ref ← getRef -- Register the error context of implicits for mvarId in s.toSetErrorCtx do registerMVarErrorImplicitArgInfo mvarId ref e if !s.etaArgs.isEmpty then e ← mkLambdaFVars s.etaArgs e /- Remark: we should not use `s.fType` as `eType` even when `s.etaArgs.isEmpty`. Reason: it may have been unfolded. -/ let eType ← inferType e trace[Elab.app.finalize]! "after etaArgs, {e} : {eType}" match s.expectedType? with | none => pure () | some expectedType => trace[Elab.app.finalize]! "expected type: {expectedType}" -- Try to propagate expected type. Ignore if types are not definitionally equal, caller must handle it. discard <| isDefEq expectedType eType synthesizeAppInstMVars pure e private def addImplicitArg (k : M Expr) : M Expr := do let argType ← getArgExpectedType let arg ← mkFreshExprMVar argType if (← isTypeFormer arg) then modify fun s => { s with toSetErrorCtx := s.toSetErrorCtx.push arg.mvarId! } addNewArg arg k /- Return true if there is a named argument that depends on the next argument. -/ private def anyNamedArgDependsOnCurrent : M Bool := do let s ← get if s.namedArgs.isEmpty then return false else forallTelescopeReducing s.fType fun xs _ => do let curr := xs[0] for i in [1:xs.size] do let xDecl ← getLocalDecl xs[i].fvarId! if s.namedArgs.any fun arg => arg.name == xDecl.userName then if (← getMCtx).localDeclDependsOn xDecl curr.fvarId! then return true return false /- Process a `fType` of the form `(x : A) → B x`. This method assume `fType` is a function type -/ private def processExplictArg (k : M Expr) : M Expr := do let s ← get match s.args with | arg::args => propagateExpectedType arg modify fun s => { s with args := args } elabAndAddNewArg arg k | _ => let argType ← getArgExpectedType match s.explicit, argType.getOptParamDefault?, argType.getAutoParamTactic? with | false, some defVal, _ => addNewArg defVal; k | false, _, some (Expr.const tacticDecl _ _) => let env ← getEnv let opts ← getOptions match evalSyntaxConstant env opts tacticDecl with | Except.error err => throwError err | Except.ok tacticSyntax => -- TODO(Leo): does this work correctly for tactic sequences? let tacticBlock ← `(by $tacticSyntax) -- tacticBlock does not have any position information. -- So, we use the current ref let ref ← getRef let tacticBlock := tacticBlock.copyInfo ref let argType := argType.getArg! 0 -- `autoParam type := by tactic` ==> `type` let argNew := Arg.stx tacticBlock propagateExpectedType argNew elabAndAddNewArg argNew k | false, _, some _ => throwError "invalid autoParam, argument must be a constant" | _, _, _ => if !s.namedArgs.isEmpty then if (← anyNamedArgDependsOnCurrent) then addImplicitArg k else addEtaArg k else if !s.explicit then if (← fTypeHasOptAutoParams) then addEtaArg k else if (← get).ellipsis then addImplicitArg k else finalize else finalize /- Process a `fType` of the form `{x : A} → B x`. This method assume `fType` is a function type -/ private def processImplicitArg (k : M Expr) : M Expr := do if (← get).explicit then processExplictArg k else addImplicitArg k /- Return true if the next argument at `args` is of the form `_` -/ private def isNextArgHole : M Bool := do match (← get).args with | Arg.stx (Syntax.node `Lean.Parser.Term.hole _) :: _ => pure true | _ => pure false /- Process a `fType` of the form `[x : A] → B x`. This method assume `fType` is a function type -/ private def processInstImplicitArg (k : M Expr) : M Expr := do if (← get).explicit then if (← isNextArgHole) then /- Recall that if '@' has been used, and the argument is '_', then we still use type class resolution -/ let arg ← mkFreshExprMVar (← getArgExpectedType) MetavarKind.synthetic modify fun s => { s with args := s.args.tail! } addInstMVar arg.mvarId! addNewArg arg k else processExplictArg k else let arg ← mkFreshExprMVar (← getArgExpectedType) MetavarKind.synthetic addInstMVar arg.mvarId! addNewArg arg k /- Return true if there are regular or named arguments to be processed. -/ private def hasArgsToProcess : M Bool := do let s ← get pure $ !s.args.isEmpty || !s.namedArgs.isEmpty /- Elaborate function application arguments. -/ partial def main : M Expr := do let s ← get let fType ← normalizeFunType match fType with | Expr.forallE binderName _ _ c => let s ← get match s.namedArgs.find? fun (namedArg : NamedArg) => namedArg.name == binderName with | some namedArg => propagateExpectedType namedArg.val eraseNamedArg binderName elabAndAddNewArg namedArg.val main | none => match c.binderInfo with | BinderInfo.implicit => processImplicitArg main | BinderInfo.instImplicit => processInstImplicitArg main | _ => processExplictArg main | _ => if (← hasArgsToProcess) then synthesizePendingAndNormalizeFunType main else finalize end ElabAppArgs private def propagateExpectedTypeFor (f : Expr) : TermElabM Bool := match f.getAppFn with | Expr.const declName .. => return !hasElabWithoutExpectedType (← getEnv) declName | _ => return true private def elabAppArgs (f : Expr) (namedArgs : Array NamedArg) (args : Array Arg) (expectedType? : Option Expr) (explicit ellipsis : Bool) : TermElabM Expr := do let fType ← inferType f let fType ← instantiateMVars fType trace[Elab.app.args]! "explicit: {explicit}, {f} : {fType}" unless namedArgs.isEmpty && args.isEmpty do tryPostponeIfMVar fType ElabAppArgs.main.run' { args := args.toList, expectedType? := expectedType?, explicit := explicit, ellipsis := ellipsis, namedArgs := namedArgs.toList, f := f, fType := fType propagateExpected := (← propagateExpectedTypeFor f) } /-- Auxiliary inductive datatype that represents the resolution of an `LVal`. -/ inductive LValResolution where | projFn (baseStructName : Name) (structName : Name) (fieldName : Name) | projIdx (structName : Name) (idx : Nat) | const (baseStructName : Name) (structName : Name) (constName : Name) | localRec (baseName : Name) (fullName : Name) (fvar : Expr) | getOp (fullName : Name) (idx : Syntax) private def throwLValError {α} (e : Expr) (eType : Expr) (msg : MessageData) : TermElabM α := throwError! "{msg}{indentExpr e}\nhas type{indentExpr eType}" /-- `findMethod? env S fName`. 1- If `env` contains `S ++ fName`, return `(S, S++fName)` 2- Otherwise if `env` contains private name `prv` for `S ++ fName`, return `(S, prv)`, o 3- Otherwise for each parent structure `S'` of `S`, we try `findMethod? env S' fname` -/ private partial def findMethod? (env : Environment) (structName fieldName : Name) : Option (Name × Name) := let fullName := structName ++ fieldName match env.find? fullName with | some _ => some (structName, fullName) | none => let fullNamePrv := mkPrivateName env fullName match env.find? fullNamePrv with | some _ => some (structName, fullNamePrv) | none => if isStructureLike env structName then (getParentStructures env structName).findSome? fun parentStructName => findMethod? env parentStructName fieldName else none private def resolveLValAux (e : Expr) (eType : Expr) (lval : LVal) : TermElabM LValResolution := do match eType.getAppFn, lval with | Expr.const structName _ _, LVal.fieldIdx idx => if idx == 0 then throwError "invalid projection, index must be greater than 0" let env ← getEnv unless isStructureLike env structName do throwLValError e eType "invalid projection, structure expected" let fieldNames := getStructureFields env structName if h : idx - 1 < fieldNames.size then if isStructure env structName then pure $ LValResolution.projFn structName structName (fieldNames.get ⟨idx - 1, h⟩) else /- `structName` was declared using `inductive` command. So, we don't projection functions for it. Thus, we use `Expr.proj` -/ pure $ LValResolution.projIdx structName (idx - 1) else throwLValError e eType m!"invalid projection, structure has only {fieldNames.size} field(s)" | Expr.const structName _ _, LVal.fieldName fieldName => let env ← getEnv let searchEnv : Unit → TermElabM LValResolution := fun _ => do match findMethod? env structName (Name.mkSimple fieldName) with | some (baseStructName, fullName) => pure $ LValResolution.const baseStructName structName fullName | none => throwLValError e eType m!"invalid field notation, '{fieldName}' is not a valid \"field\" because environment does not contain '{Name.mkStr structName fieldName}'" -- search local context first, then environment let searchCtx : Unit → TermElabM LValResolution := fun _ => do let fullName := Name.mkStr structName fieldName let currNamespace ← getCurrNamespace let localName := fullName.replacePrefix currNamespace Name.anonymous let lctx ← getLCtx match lctx.findFromUserName? localName with | some localDecl => if localDecl.binderInfo == BinderInfo.auxDecl then /- LVal notation is being used to make a "local" recursive call. -/ pure $ LValResolution.localRec structName fullName localDecl.toExpr else searchEnv () | none => searchEnv () if isStructure env structName then match findField? env structName (Name.mkSimple fieldName) with | some baseStructName => pure $ LValResolution.projFn baseStructName structName (Name.mkSimple fieldName) | none => searchCtx () else searchCtx () | Expr.const structName _ _, LVal.getOp idx => let env ← getEnv let fullName := Name.mkStr structName "getOp" match env.find? fullName with | some _ => pure $ LValResolution.getOp fullName idx | none => throwLValError e eType m!"invalid [..] notation because environment does not contain '{fullName}'" | _, LVal.getOp idx => throwLValError e eType "invalid [..] notation, type is not of the form (C ...) where C is a constant" | _, _ => throwLValError e eType "invalid field notation, type is not of the form (C ...) where C is a constant" /- whnfCore + implicit consumption. Example: given `e` with `eType := {α : Type} → (fun β => List β) α `, it produces `(e ?m, List ?m)` where `?m` is fresh metavariable. -/ private partial def consumeImplicits (e eType : Expr) : TermElabM (Expr × Expr) := do let eType ← whnfCore eType match eType with | Expr.forallE n d b c => if !c.binderInfo.isExplicit then let mvar ← mkFreshExprMVar d consumeImplicits (mkApp e mvar) (b.instantiate1 mvar) else match d.getOptParamDefault? with | some defVal => consumeImplicits (mkApp e defVal) (b.instantiate1 defVal) -- TODO: we do not handle autoParams here. | _ => pure (e, eType) | _ => pure (e, eType) private partial def resolveLValLoop (lval : LVal) (e eType : Expr) (previousExceptions : Array Exception) : TermElabM (Expr × LValResolution) := do let (e, eType) ← consumeImplicits e eType tryPostponeIfMVar eType try let lvalRes ← resolveLValAux e eType lval pure (e, lvalRes) catch | ex@(Exception.error _ _) => let eType? ← unfoldDefinition? eType match eType? with | some eType => resolveLValLoop lval e eType (previousExceptions.push ex) | none => previousExceptions.forM fun ex => logException ex throw ex | ex@(Exception.internal _ _) => throw ex private def resolveLVal (e : Expr) (lval : LVal) : TermElabM (Expr × LValResolution) := do let eType ← inferType e resolveLValLoop lval e eType #[] private partial def mkBaseProjections (baseStructName : Name) (structName : Name) (e : Expr) : TermElabM Expr := do let env ← getEnv match getPathToBaseStructure? env baseStructName structName with | none => throwError "failed to access field in parent structure" | some path => let mut e := e for projFunName in path do let projFn ← mkConst projFunName e ← elabAppArgs projFn #[{ name := `self, val := Arg.expr e }] (args := #[]) (expectedType? := none) (explicit := false) (ellipsis := false) return e /- Auxiliary method for field notation. It tries to add `e` as a new argument to `args` or `namedArgs`. This method first finds the parameter with a type of the form `(baseName ...)`. When the parameter is found, if it an explicit one and `args` is big enough, we add `e` to `args`. Otherwise, if there isn't another parameter with the same name, we add `e` to `namedArgs`. Remark: `fullName` is the name of the resolved "field" access function. It is used for reporting errors -/ private def addLValArg (baseName : Name) (fullName : Name) (e : Expr) (args : Array Arg) (namedArgs : Array NamedArg) (fType : Expr) : TermElabM (Array Arg × Array NamedArg) := forallTelescopeReducing fType fun xs _ => do let mut argIdx := 0 -- position of the next explicit argument let mut remainingNamedArgs := namedArgs for i in [:xs.size] do let x := xs[i] let xDecl ← getLocalDecl x.fvarId! /- If there is named argument with name `xDecl.userName`, then we skip it. -/ match remainingNamedArgs.findIdx? (fun namedArg => namedArg.name == xDecl.userName) with | some idx => remainingNamedArgs := remainingNamedArgs.eraseIdx idx | none => let mut foundIt := false let type := xDecl.type if type.consumeMData.isAppOf baseName then foundIt := true if !foundIt then /- Normalize type and try again -/ let type ← withReducible $ whnf type if type.consumeMData.isAppOf baseName then foundIt := true if foundIt then /- We found a type of the form (baseName ...). First, we check if the current argument is an explicit one, and the current explicit position "fits" at `args` (i.e., it must be ≤ arg.size) -/ if argIdx ≤ args.size && xDecl.binderInfo.isExplicit then /- We insert `e` as an explicit argument -/ return (args.insertAt argIdx (Arg.expr e), namedArgs) /- If we can't add `e` to `args`, we try to add it using a named argument, but this is only possible if there isn't an argument with the same name occurring before it. -/ for j in [:i] do let prev := xs[j] let prevDecl ← getLocalDecl prev.fvarId! if prevDecl.userName == xDecl.userName then throwError! "invalid field notation, function '{fullName}' has argument with the expected type{indentExpr type}\nbut it cannot be used" return (args, namedArgs.push { name := xDecl.userName, val := Arg.expr e }) if xDecl.binderInfo.isExplicit then -- advance explicit argument position argIdx := argIdx + 1 throwError! "invalid field notation, function '{fullName}' does not have argument with type ({baseName} ...) that can be used, it must be explicit or implicit with an unique name" private def elabAppLValsAux (namedArgs : Array NamedArg) (args : Array Arg) (expectedType? : Option Expr) (explicit ellipsis : Bool) (f : Expr) (lvals : List LVal) : TermElabM Expr := let rec loop : Expr → List LVal → TermElabM Expr | f, [] => elabAppArgs f namedArgs args expectedType? explicit ellipsis | f, lval::lvals => do let (f, lvalRes) ← resolveLVal f lval match lvalRes with | LValResolution.projIdx structName idx => let f := mkProj structName idx f loop f lvals | LValResolution.projFn baseStructName structName fieldName => let f ← mkBaseProjections baseStructName structName f let projFn ← mkConst (baseStructName ++ fieldName) if lvals.isEmpty then let namedArgs ← addNamedArg namedArgs { name := `self, val := Arg.expr f } elabAppArgs projFn namedArgs args expectedType? explicit ellipsis else let f ← elabAppArgs projFn #[{ name := `self, val := Arg.expr f }] #[] (expectedType? := none) (explicit := false) (ellipsis := false) loop f lvals | LValResolution.const baseStructName structName constName => let f ← if baseStructName != structName then mkBaseProjections baseStructName structName f else pure f let projFn ← mkConst constName if lvals.isEmpty then let projFnType ← inferType projFn let (args, namedArgs) ← addLValArg baseStructName constName f args namedArgs projFnType elabAppArgs projFn namedArgs args expectedType? explicit ellipsis else let f ← elabAppArgs projFn #[] #[Arg.expr f] (expectedType? := none) (explicit := false) (ellipsis := false) loop f lvals | LValResolution.localRec baseName fullName fvar => if lvals.isEmpty then let fvarType ← inferType fvar let (args, namedArgs) ← addLValArg baseName fullName f args namedArgs fvarType elabAppArgs fvar namedArgs args expectedType? explicit ellipsis else let f ← elabAppArgs fvar #[] #[Arg.expr f] (expectedType? := none) (explicit := false) (ellipsis := false) loop f lvals | LValResolution.getOp fullName idx => let getOpFn ← mkConst fullName if lvals.isEmpty then let namedArgs ← addNamedArg namedArgs { name := `self, val := Arg.expr f } let namedArgs ← addNamedArg namedArgs { name := `idx, val := Arg.stx idx } elabAppArgs getOpFn namedArgs args expectedType? explicit ellipsis else let f ← elabAppArgs getOpFn #[{ name := `self, val := Arg.expr f }, { name := `idx, val := Arg.stx idx }] #[] (expectedType? := none) (explicit := false) (ellipsis := false) loop f lvals loop f lvals private def elabAppLVals (f : Expr) (lvals : List LVal) (namedArgs : Array NamedArg) (args : Array Arg) (expectedType? : Option Expr) (explicit ellipsis : Bool) : TermElabM Expr := do if !lvals.isEmpty && explicit then throwError "invalid use of field notation with `@` modifier" elabAppLValsAux namedArgs args expectedType? explicit ellipsis f lvals def elabExplicitUnivs (lvls : Array Syntax) : TermElabM (List Level) := do lvls.foldrM (fun stx lvls => do pure ((← elabLevel stx)::lvls)) [] /- Interaction between `errToSorry` and `observing`. - The method `elabTerm` catches exceptions, log them, and returns a synthetic sorry (IF `ctx.errToSorry` == true). - When we elaborate choice nodes (and overloaded identifiers), we track multiple results using the `observing x` combinator. The `observing x` executes `x` and returns a `TermElabResult`. `observing `x does not check for synthetic sorry's, just an exception. Thus, it may think `x` worked when it didn't if a synthetic sorry was introduced. We decided that checking for synthetic sorrys at `observing` is not a good solution because it would not be clear to decide what the "main" error message for the alternative is. When the result contains a synthetic `sorry`, it is not clear which error message corresponds to the `sorry`. Moreover, while executing `x`, many error messages may have been logged. Recall that we need an error per alternative at `mergeFailures`. Thus, we decided to set `errToSorry` to `false` whenever processing choice nodes and overloaded symbols. Important: we rely on the property that after `errToSorry` is set to false, no elaboration function executed by `x` will reset it to `true`. -/ private partial def elabAppFnId (fIdent : Syntax) (fExplicitUnivs : List Level) (lvals : List LVal) (namedArgs : Array NamedArg) (args : Array Arg) (expectedType? : Option Expr) (explicit ellipsis overloaded : Bool) (acc : Array TermElabResult) : TermElabM (Array TermElabResult) := do match fIdent with | Syntax.ident _ _ n preresolved => let funLVals ← withRef fIdent $ resolveName n preresolved fExplicitUnivs let overloaded := overloaded || funLVals.length > 1 -- Set `errToSorry` to `false` if `funLVals` > 1. See comment above about the interaction between `errToSorry` and `observing`. withReader (fun ctx => { ctx with errToSorry := funLVals.length == 1 && ctx.errToSorry }) do funLVals.foldlM (init := acc) fun acc ⟨f, fields⟩ => do let lvals' := fields.map LVal.fieldName let s ← observing do let e ← elabAppLVals f (lvals' ++ lvals) namedArgs args expectedType? explicit ellipsis if overloaded then ensureHasType expectedType? e else pure e pure $ acc.push s | _ => throwUnsupportedSyntax private partial def elabAppFn (f : Syntax) (lvals : List LVal) (namedArgs : Array NamedArg) (args : Array Arg) (expectedType? : Option Expr) (explicit ellipsis overloaded : Bool) (acc : Array TermElabResult) : TermElabM (Array TermElabResult) := if f.getKind == choiceKind then -- Set `errToSorry` to `false` when processing choice nodes. See comment above about the interaction between `errToSorry` and `observing`. withReader (fun ctx => { ctx with errToSorry := false }) do f.getArgs.foldlM (fun acc f => elabAppFn f lvals namedArgs args expectedType? explicit ellipsis true acc) acc else match f with | `($(e).$idx:fieldIdx) => let idx := idx.isFieldIdx?.get! elabAppFn e (LVal.fieldIdx idx :: lvals) namedArgs args expectedType? explicit ellipsis overloaded acc | `($e |>. $field) => do let f ← `($(e).$field) elabAppFn f lvals namedArgs args expectedType? explicit ellipsis overloaded acc | `($(e).$field:ident) => let newLVals := field.getId.eraseMacroScopes.components.map (fun n => LVal.fieldName (toString n)) elabAppFn e (newLVals ++ lvals) namedArgs args expectedType? explicit ellipsis overloaded acc | `($e[$idx]) => elabAppFn e (LVal.getOp idx :: lvals) namedArgs args expectedType? explicit ellipsis overloaded acc | `($id:ident@$t:term) => throwError "unexpected occurrence of named pattern" | `($id:ident) => do elabAppFnId id [] lvals namedArgs args expectedType? explicit ellipsis overloaded acc | `($id:ident.{$us,*}) => do let us ← elabExplicitUnivs us elabAppFnId id us lvals namedArgs args expectedType? explicit ellipsis overloaded acc | `(@$id:ident) => elabAppFn id lvals namedArgs args expectedType? (explicit := true) ellipsis overloaded acc | `(@$id:ident.{$us,*}) => elabAppFn (f.getArg 1) lvals namedArgs args expectedType? (explicit := true) ellipsis overloaded acc | `(@$t) => throwUnsupportedSyntax -- invalid occurrence of `@` | `(_) => throwError "placeholders '_' cannot be used where a function is expected" | _ => do let catchPostpone := !overloaded /- If we are processing a choice node, then we should use `catchPostpone == false` when elaborating terms. Recall that `observing` does not catch `postponeExceptionId`. -/ if lvals.isEmpty && namedArgs.isEmpty && args.isEmpty then /- Recall that elabAppFn is used for elaborating atomics terms **and** choice nodes that may contain arbitrary terms. If they are not being used as a function, we should elaborate using the expectedType. -/ let s ← if overloaded then observing $ elabTermEnsuringType f expectedType? catchPostpone else observing $ elabTerm f expectedType? pure $ acc.push s else let s ← observing do let f ← elabTerm f none catchPostpone let e ← elabAppLVals f lvals namedArgs args expectedType? explicit ellipsis if overloaded then ensureHasType expectedType? e else pure e pure $ acc.push s private def isSuccess (candidate : TermElabResult) : Bool := match candidate with | EStateM.Result.ok _ _ => true | _ => false private def getSuccess (candidates : Array TermElabResult) : Array TermElabResult := candidates.filter isSuccess private def toMessageData (ex : Exception) : TermElabM MessageData := do let pos ← getRefPos match ex.getRef.getPos with | none => pure ex.toMessageData | some exPos => if pos == exPos then pure ex.toMessageData else let exPosition := (← getFileMap).toPosition exPos pure m!"{exPosition.line}:{exPosition.column} {ex.toMessageData}" private def toMessageList (msgs : Array MessageData) : MessageData := indentD (MessageData.joinSep msgs.toList m!"\n\n") private def mergeFailures {α} (failures : Array TermElabResult) : TermElabM α := do let msgs ← failures.mapM fun failure => match failure with | EStateM.Result.ok _ _ => unreachable! | EStateM.Result.error ex _ => toMessageData ex throwError! "overloaded, errors {toMessageList msgs}" private def elabAppAux (f : Syntax) (namedArgs : Array NamedArg) (args : Array Arg) (ellipsis : Bool) (expectedType? : Option Expr) : TermElabM Expr := do let candidates ← elabAppFn f [] namedArgs args expectedType? (explicit := false) (ellipsis := ellipsis) (overloaded := false) #[] if candidates.size == 1 then applyResult candidates[0] else let successes := getSuccess candidates if successes.size == 1 then let e ← applyResult successes[0] pure e else if successes.size > 1 then let lctx ← getLCtx let opts ← getOptions let msgs : Array MessageData := successes.map fun success => match success with | EStateM.Result.ok e s => MessageData.withContext { env := s.core.env, mctx := s.meta.mctx, lctx := lctx, opts := opts } e | _ => unreachable! throwErrorAt! f "ambiguous, possible interpretations {toMessageList msgs}" else withRef f $ mergeFailures candidates partial def expandApp (stx : Syntax) (pattern := false) : TermElabM (Syntax × Array NamedArg × Array Arg × Bool) := do let f := stx[0] let args := stx[1].getArgs let (args, ellipsis) := if args.isEmpty then (args, false) else if args.back.isOfKind `Lean.Parser.Term.ellipsis then (args.pop, true) else (args, false) let (namedArgs, args) ← args.foldlM (init := (#[], #[])) fun (namedArgs, args) stx => do if stx.getKind == `Lean.Parser.Term.namedArgument then -- tparser! try ("(" >> ident >> " := ") >> termParser >> ")" let name := stx[1].getId.eraseMacroScopes let val := stx[3] let namedArgs ← addNamedArg namedArgs { ref := stx, name := name, val := Arg.stx val } pure (namedArgs, args) else if stx.getKind == `Lean.Parser.Term.ellipsis then throwErrorAt stx "unexpected '..'" else pure (namedArgs, args.push $ Arg.stx stx) pure (f, namedArgs, args, ellipsis) @[builtinTermElab app] def elabApp : TermElab := fun stx expectedType? => withoutPostponingUniverseConstraints do let (f, namedArgs, args, ellipsis) ← expandApp stx elabAppAux f namedArgs args (ellipsis := ellipsis) expectedType? private def elabAtom : TermElab := fun stx expectedType? => elabAppAux stx #[] #[] (ellipsis := false) expectedType? @[builtinTermElab ident] def elabIdent : TermElab := elabAtom @[builtinTermElab namedPattern] def elabNamedPattern : TermElab := elabAtom @[builtinTermElab explicitUniv] def elabExplicitUniv : TermElab := elabAtom @[builtinTermElab pipeProj] def expandPipeProj : TermElab := elabAtom @[builtinTermElab explicit] def elabExplicit : TermElab := fun stx expectedType? => match stx with | `(@$id:ident) => elabAtom stx expectedType? -- Recall that `elabApp` also has support for `@` | `(@$id:ident.{$us,*}) => elabAtom stx expectedType? | `(@($t)) => elabTermWithoutImplicitLambdas t expectedType? -- `@` is being used just to disable implicit lambdas | `(@$t) => elabTermWithoutImplicitLambdas t expectedType? -- `@` is being used just to disable implicit lambdas | _ => throwUnsupportedSyntax @[builtinTermElab choice] def elabChoice : TermElab := elabAtom @[builtinTermElab proj] def elabProj : TermElab := elabAtom @[builtinTermElab arrayRef] def elabArrayRef : TermElab := elabAtom @[builtinTermElab binrel] def elabBinRel : TermElab := fun stx expectedType? => do match (← resolveId? stx[1]) with | some f => let (lhs, rhs) ← withSynthesize (mayPostpone := true) do let mut lhs ← elabTerm stx[2] none let mut rhs ← elabTerm stx[3] none if lhs.isAppOfArity `OfNat.ofNat 3 then lhs ← ensureHasType (← inferType rhs) lhs else if rhs.isAppOfArity `OfNat.ofNat 3 then rhs ← ensureHasType (← inferType lhs) rhs return (lhs, rhs) let lhsType ← inferType lhs let rhsType ← inferType rhs let (lhs, rhs) ← try pure (lhs, ← withRef stx[3] do ensureHasType lhsType rhs) catch ex => try pure (← withRef stx[2] do ensureHasType rhsType lhs, rhs) catch _ => throw ex elabAppArgs f #[] #[Arg.expr lhs, Arg.expr rhs] expectedType? (explicit := false) (ellipsis := false) | none => throwUnknownConstant stx[1].getId builtin_initialize registerTraceClass `Elab.app end Lean.Elab.Term
dcc3009a6a20b8167ebfbcef409feef427b2e4a3
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/library/init/state.lean
08ed7347c150d0f036473e4c8781af72dba51bba
[ "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
2,137
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import init.logic init.monad init.alternative init.prod definition state (S : Type) (A : Type) : Type := S → A × S section set_option pp.all true variables {S : Type} {A B : Type} attribute [inline] definition state_fmap (f : A → B) (a : state S A) : state S B := λ s, match (a s) with (a', s') := (f a', s') end attribute [inline] definition state_return (a : A) : state S A := λ s, (a, s) attribute [inline] definition state_bind (a : state S A) (b : A → state S B) : state S B := λ s, match (a s) with (a', s') := b a' s' end attribute [instance] definition state_is_monad (S : Type) : monad (state S) := monad.mk (@state_fmap S) (@state_return S) (@state_bind S) end namespace state attribute [inline] definition read {S : Type} : state S S := λ s, (s, s) attribute [inline] definition write {S : Type} : S → state S unit := λ s' s, ((), s') end state definition stateT (S : Type) (M : Type → Type) [monad M] (A : Type) : Type := S → M (A × S) section variable {S : Type} variable {M : Type → Type} variable [monad M] variables {A B : Type} definition stateT_fmap (f : A → B) (act : stateT S M A) : stateT S M B := λ s, show M (B × S), from do (a, new_s) ← act s, return (f a, new_s) definition stateT_return (a : A) : stateT S M A := λ s, show M (A × S), from return (a, s) definition stateT_bind (act₁ : stateT S M A) (act₂ : A → stateT S M B) : stateT S M B := λ s, show M (B × S), from do (a, new_s) ← act₁ s, act₂ a new_s end attribute [instance] definition stateT_is_monad (S : Type) (M : Type → Type) [monad M] : monad (stateT S M) := monad.mk (@stateT_fmap S M _) (@stateT_return S M _) (@stateT_bind S M _) namespace stateT definition read {S : Type} {M : Type → Type} [monad M] : stateT S M S := λ s, return (s, s) definition write {S : Type} {M : Type → Type} [monad M] : S → stateT S M unit := λ s' s, return ((), s') end stateT
043c26bbb57ae9d1dce73b4394efb3de7c35e765
02005f45e00c7ecf2c8ca5db60251bd1e9c860b5
/src/field_theory/primitive_element.lean
4bac81b5fed320c1cc16a551f083325f7152dea9
[ "Apache-2.0" ]
permissive
anthony2698/mathlib
03cd69fe5c280b0916f6df2d07c614c8e1efe890
407615e05814e98b24b2ff322b14e8e3eb5e5d67
refs/heads/master
1,678,792,774,873
1,614,371,563,000
1,614,371,563,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
7,812
lean
/- Copyright (c) 2020 Thomas Browning and Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning and Patrick Lutz -/ import field_theory.adjoin import field_theory.separable /-! # Primitive Element Theorem In this file we prove the primitive element theorem. ## Main results - `exists_primitive_element`: a finite separable extension `E / F` has a primitive element, i.e. there is an `α : E` such that `F⟮α⟯ = (⊤ : subalgebra F E)`. ## Implementation notes In declaration names, `primitive_element` abbreviates `adjoin_simple_eq_top`: it stands for the statement `F⟮α⟯ = (⊤ : subalgebra F E)`. We did not add an extra declaration `is_primitive_element F α := F⟮α⟯ = (⊤ : subalgebra F E)` because this requires more unfolding without much obvious benefit. ## Tags primitive element, separable field extension, separable extension, intermediate field, adjoin, exists_adjoin_simple_eq_top -/ noncomputable theory open_locale classical open finite_dimensional polynomial intermediate_field namespace field section primitive_element_finite variables (F : Type*) [field F] (E : Type*) [field E] [algebra F E] /-! ### Primitive element theorem for finite fields -/ /-- Primitive element theorem assuming E is finite. -/ lemma exists_primitive_element_of_fintype_top [fintype E] : ∃ α : E, F⟮α⟯ = ⊤ := begin obtain ⟨α, hα⟩ := is_cyclic.exists_generator (units E), use α, apply eq_top_iff.mpr, rintros x -, by_cases hx : x = 0, { rw hx, exact F⟮α.val⟯.zero_mem }, { obtain ⟨n, hn⟩ := set.mem_range.mp (hα (units.mk0 x hx)), rw (show x = α^n, by { norm_cast, rw [hn, units.coe_mk0] }), exact pow_mem F⟮↑α⟯ (mem_adjoin_simple_self F ↑α) n, }, end /-- Primitive element theorem for finite dimensional extension of a finite field. -/ theorem exists_primitive_element_of_fintype_bot [fintype F] [finite_dimensional F E] : ∃ α : E, F⟮α⟯ = ⊤ := begin haveI : fintype E := fintype_of_fintype F E, exact exists_primitive_element_of_fintype_top F E, end end primitive_element_finite /-! ### Primitive element theorem for infinite fields -/ section primitive_element_inf variables {F : Type*} [field F] [infinite F] {E : Type*} [field E] (ϕ : F →+* E) (α β : E) lemma primitive_element_inf_aux_exists_c (f g : polynomial F) : ∃ c : F, ∀ (α' ∈ (f.map ϕ).roots) (β' ∈ (g.map ϕ).roots), -(α' - α)/(β' - β) ≠ ϕ c := begin let sf := (f.map ϕ).roots, let sg := (g.map ϕ).roots, let s := (sf.bind (λ α', sg.map (λ β', -(α' - α) / (β' - β)))).to_finset, let s' := s.preimage ϕ (λ x hx y hy h, ϕ.injective h), obtain ⟨c, hc⟩ := infinite.exists_not_mem_finset s', simp_rw [finset.mem_preimage, multiset.mem_to_finset, multiset.mem_bind, multiset.mem_map] at hc, push_neg at hc, exact ⟨c, hc⟩, end variables [algebra F E] -- This is the heart of the proof of the primitive element theorem. It shows that if `F` is -- infinite and `α` and `β` are separable over `F` then `F⟮α, β⟯` is generated by a single element. lemma primitive_element_inf_aux (F_sep : is_separable F E) : ∃ γ : E, F⟮α, β⟯ = F⟮γ⟯ := begin have hα := F_sep.is_integral α, have hβ := F_sep.is_integral β, let f := minpoly F α, let g := minpoly F β, let ιFE := algebra_map F E, let ιEE' := algebra_map E (splitting_field (g.map ιFE)), obtain ⟨c, hc⟩ := primitive_element_inf_aux_exists_c (ιEE'.comp ιFE) (ιEE' α) (ιEE' β) f g, let γ := α + c • β, suffices β_in_Fγ : β ∈ F⟮γ⟯, { use γ, apply le_antisymm, { rw adjoin_le_iff, have α_in_Fγ : α ∈ F⟮γ⟯, { rw ← add_sub_cancel α (c • β), exact F⟮γ⟯.sub_mem (mem_adjoin_simple_self F γ) (F⟮γ⟯.to_subalgebra.smul_mem β_in_Fγ c)}, exact λ x hx, by cases hx; cases hx; cases hx; assumption }, { rw adjoin_le_iff, change {γ} ⊆ _, rw set.singleton_subset_iff, have α_in_Fαβ : α ∈ F⟮α, β⟯ := subset_adjoin F {α, β} (set.mem_insert α {β}), have β_in_Fαβ : β ∈ F⟮α, β⟯ := subset_adjoin F {α, β} (set.mem_insert_of_mem α rfl), exact F⟮α,β⟯.add_mem α_in_Fαβ (F⟮α, β⟯.smul_mem β_in_Fαβ) } }, let p := euclidean_domain.gcd ((f.map (algebra_map F F⟮γ⟯)).comp (C (adjoin_simple.gen F γ) - (C ↑c * X))) (g.map (algebra_map F F⟮γ⟯)), let h := euclidean_domain.gcd ((f.map ιFE).comp (C γ - (C (ιFE c) * X))) (g.map ιFE), have map_g_ne_zero : g.map ιFE ≠ 0 := map_ne_zero (minpoly.ne_zero hβ), have h_ne_zero : h ≠ 0 := mt euclidean_domain.gcd_eq_zero_iff.mp (not_and.mpr (λ _, map_g_ne_zero)), suffices p_linear : p.map (algebra_map F⟮γ⟯ E) = (C h.leading_coeff) * (X - C β), { have finale : β = algebra_map F⟮γ⟯ E (-p.coeff 0 / p.coeff 1), { rw [ring_hom.map_div, ring_hom.map_neg, ←coeff_map, ←coeff_map, p_linear], simp [mul_sub, coeff_C, mul_div_cancel_left β (mt leading_coeff_eq_zero.mp h_ne_zero)] }, rw finale, exact subtype.mem (-p.coeff 0 / p.coeff 1) }, have h_sep : h.separable := separable_gcd_right _ (separable.map (F_sep.separable β)), have h_root : h.eval β = 0, { apply eval_gcd_eq_zero, { rw [eval_comp, eval_sub, eval_mul, eval_C, eval_C, eval_X, eval_map, ←aeval_def, ←algebra.smul_def, add_sub_cancel, minpoly.aeval] }, { rw [eval_map, ←aeval_def, minpoly.aeval] } }, have h_splits : splits ιEE' h := splits_of_splits_gcd_right ιEE' map_g_ne_zero (splitting_field.splits _), have h_roots : ∀ x ∈ (h.map ιEE').roots, x = ιEE' β, { intros x hx, rw mem_roots_map h_ne_zero at hx, specialize hc ((ιEE' γ) - (ιEE' (ιFE c)) * x) (begin have f_root := root_left_of_root_gcd hx, rw [eval₂_comp, eval₂_sub, eval₂_mul,eval₂_C, eval₂_C, eval₂_X, eval₂_map] at f_root, exact (mem_roots_map (minpoly.ne_zero hα)).mpr f_root, end), specialize hc x (begin rw [mem_roots_map (minpoly.ne_zero hβ), ←eval₂_map], exact root_right_of_root_gcd hx, end), by_contradiction a, apply hc, apply (div_eq_iff (sub_ne_zero.mpr a)).mpr, simp only [algebra.smul_def, ring_hom.map_add, ring_hom.map_mul, ring_hom.comp_apply], ring }, rw ← eq_X_sub_C_of_separable_of_root_eq h_ne_zero h_sep h_root h_splits h_roots, transitivity euclidean_domain.gcd (_ : polynomial E) (_ : polynomial E), { dsimp only [p], convert (gcd_map (algebra_map F⟮γ⟯ E)).symm }, { simpa [map_comp, map_map, ←is_scalar_tower.algebra_map_eq, h] }, end end primitive_element_inf variables {F : Type*} [field F] {E : Type*} [field E] [algebra F E] /-- Primitive element theorem: a finite separable field extension `E` of `F` has a primitive element, i.e. there is an `α ∈ E` such that `F⟮α⟯ = (⊤ : subalgebra F E)`.-/ theorem exists_primitive_element [finite_dimensional F E] (F_sep : is_separable F E) : ∃ α : E, F⟮α⟯ = ⊤ := begin by_cases F_finite : nonempty (fintype F), { exact nonempty.elim F_finite (λ h, by haveI := h; exact exists_primitive_element_of_fintype_bot F E) }, { let P : intermediate_field F E → Prop := λ K, ∃ α : E, F⟮α⟯ = K, have base : P ⊥ := ⟨0, adjoin_zero⟩, have ih : ∀ (K : intermediate_field F E) (x : E), P K → P ↑K⟮x⟯, { intros K β hK, cases hK with α hK, rw [←hK, adjoin_simple_adjoin_simple], haveI : infinite F := not_nonempty_fintype.mp F_finite, cases primitive_element_inf_aux α β F_sep with γ hγ, exact ⟨γ, hγ.symm⟩ }, exact induction_on_adjoin P base ih ⊤ }, end end field
63eda34c0a0847c0e188dcf6efba756ac589e190
618003631150032a5676f229d13a079ac875ff77
/src/tactic/squeeze.lean
471afee4507d787b1cd751d22f8f5fc99c8f7daa
[ "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
12,283
lean
/- Copyright (c) 2019 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Simon Hudon -/ import control.traversable.basic import tactic.simpa open interactive interactive.types lean.parser private meta def loc.to_string_aux : option name → string | none := "⊢" | (some x) := to_string x /-- pretty print a `loc` -/ meta def loc.to_string : loc → string | (loc.ns []) := "" | (loc.ns [none]) := "" | (loc.ns ls) := string.join $ list.intersperse " " (" at" :: ls.map loc.to_string_aux) | loc.wildcard := " at *" /-- shift `pos` `n` columns to the left -/ meta def pos.move_left (p : pos) (n : ℕ) : pos := { line := p.line, column := p.column - n } namespace tactic /-- `erase_simp_args hs s` removes from `s` each name `n` such that `const n` is an element of `hs` -/ meta def erase_simp_args (hs : list simp_arg_type) (s : name_set) : tactic name_set := do -- TODO: when Lean 3.4 support is dropped, use `decode_simp_arg_list_with_symm` on the next line: (hs, _, _) ← decode_simp_arg_list hs, pure $ hs.foldr (λ (h : pexpr) (s : name_set), match h.get_app_fn h with | (expr.const n _) := s.erase n | _ := s end) s open list /-- parse structure instance of the shape `{ field1 := value1, .. , field2 := value2 }` -/ meta def struct_inst : lean.parser pexpr := do tk "{", ls ← sep_by (skip_info (tk ",")) ( sum.inl <$> (tk ".." *> texpr) <|> sum.inr <$> (prod.mk <$> ident <* tk ":=" <*> texpr)), tk "}", let (srcs,fields) := partition_map id ls, let (names,values) := unzip fields, pure $ pexpr.mk_structure_instance { field_names := names, field_values := values, sources := srcs } /-- pretty print structure instance -/ meta def struct.to_tactic_format (e : pexpr) : tactic format := do r ← e.get_structure_instance_info, fs ← mzip_with (λ n v, do v ← to_expr v >>= pp, pure $ format!"{n} := {v}" ) r.field_names r.field_values, let ss := r.sources.map (λ s, format!" .. {s}"), let x : format := format.join $ list.intersperse ", " (fs ++ ss), pure format!" {{{x}}" /-- Attribute containing a table that accumulates multiple `squeeze_simp` suggestions -/ @[user_attribute] private meta def squeeze_loc_attr : user_attribute unit (option (list (pos × string × list simp_arg_type × string))) := { name := `_squeeze_loc, parser := fail "this attribute should not be used", descr := "table to accumulate multiple `squeeze_simp` suggestions" } /-- dummy declaration used as target of `squeeze_loc` attribute -/ def squeeze_loc_attr_carrier := () run_cmd squeeze_loc_attr.set ``squeeze_loc_attr_carrier none tt /-- Emit a suggestion to the user. If inside a `squeeze_scope` block, the suggestions emitted through `mk_suggestion` will be aggregated so that every tactic that makes a suggestion can consider multiple execution of the same invocation. If `at_pos` is true, make the suggestion at `p` instead of the current position. -/ meta def mk_suggestion (p : pos) (pre post : string) (args : list simp_arg_type) (at_pos := ff) : tactic unit := do xs ← squeeze_loc_attr.get_param ``squeeze_loc_attr_carrier, match xs with | none := do args ← to_line_wrap_format <$> args.mmap pp, if at_pos then @scope_trace _ p.line p.column $ λ _, _root_.trace sformat!"{pre}{args}{post}" (pure () : tactic unit) else trace sformat!"{pre}{args}{post}" | some xs := do squeeze_loc_attr.set ``squeeze_loc_attr_carrier ((p,pre,args,post) :: xs) ff end local postfix `?`:9001 := optional /-- translate a `pexpr` into a `simp` configuration -/ meta def parse_config : option pexpr → tactic (simp_config_ext × format) | none := pure ({}, "") | (some cfg) := do e ← to_expr ``(%%cfg : simp_config_ext), fmt ← has_to_tactic_format.to_tactic_format cfg, prod.mk <$> eval_expr simp_config_ext e <*> struct.to_tactic_format cfg /-- `same_result proof tac` runs tactic `tac` and checks if the proof produced by `tac` is equivalent to `proof`. -/ meta def same_result (pr : proof_state) (tac : tactic unit) : tactic bool := do s ← get_proof_state_after tac, pure $ some pr = s private meta def filter_simp_set_aux (tac : bool → list simp_arg_type → tactic unit) (args : list simp_arg_type) (pr : proof_state) : list simp_arg_type → list simp_arg_type → list simp_arg_type → tactic (list simp_arg_type × list simp_arg_type) | [] ys ds := pure (ys.reverse, ds.reverse) | (x :: xs) ys ds := do b ← same_result pr (tac tt (args ++ xs ++ ys)), if b then filter_simp_set_aux xs ys (x:: ds) else filter_simp_set_aux xs (x :: ys) ds declare_trace squeeze.deleted /-- `filter_simp_set g call_simp user_args simp_args` returns `args'` such that, when calling `call_simp tt /- only -/ args'` on the goal `g` (`g` is a meta var) we end up in the same state as if we had called `call_simp ff (user_args ++ simp_args)` and removing any one element of `args'` changes the resulting proof. -/ meta def filter_simp_set (tac : bool → list simp_arg_type → tactic unit) (user_args simp_args : list simp_arg_type) : tactic (list simp_arg_type) := do some s ← get_proof_state_after (tac ff (user_args ++ simp_args)), (simp_args', _) ← filter_simp_set_aux tac user_args s simp_args [] [], (user_args', ds) ← filter_simp_set_aux tac simp_args' s user_args [] [], when (is_trace_enabled_for `squeeze.deleted = tt ∧ ¬ ds.empty) trace!"deleting provided arguments {ds}", pure (user_args' ++ simp_args') /-- make a `simp_arg_type` that references the name given as an argument -/ meta def name.to_simp_args (n : name) : tactic simp_arg_type := do e ← resolve_name' n, pure $ simp_arg_type.expr e /-- tactic combinator to create a `simp`-like tactic that minimizes its argument list. * `no_dflt`: did the user use the `only` keyword? * `args`: list of `simp` arguments * `tac`: how to invoke the underlying `simp` tactic -/ meta def squeeze_simp_core (no_dflt : bool) (args : list simp_arg_type) (tac : Π (no_dflt : bool) (args : list simp_arg_type), tactic unit) (mk_suggestion : list simp_arg_type → tactic unit) : tactic unit := do v ← target >>= mk_meta_var, g ← retrieve $ do { g ← main_goal, tac no_dflt args, instantiate_mvars g }, let vs := g.list_constant, vs ← vs.mfilter is_simp_lemma, vs ← vs.mmap strip_prefix, vs ← erase_simp_args args vs, vs ← vs.to_list.mmap name.to_simp_args, with_local_goals' [v] (filter_simp_set tac args vs) >>= mk_suggestion, tac no_dflt args namespace interactive attribute [derive decidable_eq] simp_arg_type /-- combinator meant to aggregate the suggestions issued by multiple calls of `squeeze_simp` (due, for instance, to `;`). Can be used as: ```lean example {α β} (xs ys : list α) (f : α → β) : (xs ++ ys.tail).map f = xs.map f ∧ (xs.tail.map f).length = xs.length := begin have : xs = ys, admit, squeeze_scope { split; squeeze_simp, -- `squeeze_simp` is run twice, the first one requires -- `list.map_append` and the second one `[list.length_map, list.length_tail]` -- prints only one message and combine the suggestions: -- > Try this: simp only [list.length_map, list.length_tail, list.map_append] squeeze_simp [this] -- `squeeze_simp` is run only once -- prints: -- > Try this: simp only [this] }, end ``` -/ meta def squeeze_scope (tac : itactic) : tactic unit := do none ← squeeze_loc_attr.get_param ``squeeze_loc_attr_carrier | pure (), squeeze_loc_attr.set ``squeeze_loc_attr_carrier (some []) ff, finally tac $ do some xs ← squeeze_loc_attr.get_param ``squeeze_loc_attr_carrier | fail "invalid state", let m := native.rb_lmap.of_list xs, squeeze_loc_attr.set ``squeeze_loc_attr_carrier none ff, m.to_list.reverse.mmap' $ λ ⟨p,suggs⟩, do { let ⟨pre,_,post⟩ := suggs.head, let suggs : list (list simp_arg_type) := suggs.map $ prod.fst ∘ prod.snd, mk_suggestion p pre post (suggs.foldl list.union []) tt, pure () } /-- `squeeze_simp` and `squeeze_simpa` perform the same task with the difference that `squeeze_simp` relates to `simp` while `squeeze_simpa` relates to `simpa`. The following applies to both `squeeze_simp` and `squeeze_simpa`. `squeeze_simp` behaves like `simp` (including all its arguments) and prints a `simp only` invokation to skip the search through the `simp` lemma list. For instance, the following is easily solved with `simp`: ```lean example : 0 + 1 = 1 + 0 := by simp ``` To guide the proof search and speed it up, we may replace `simp` with `squeeze_simp`: ```lean example : 0 + 1 = 1 + 0 := by squeeze_simp -- prints: -- Try this: simp only [add_zero, eq_self_iff_true, zero_add] ``` `squeeze_simp` suggests a replacement which we can use instead of `squeeze_simp`. ```lean example : 0 + 1 = 1 + 0 := by simp only [add_zero, eq_self_iff_true, zero_add] ``` `squeeze_simp only` prints nothing as it already skips the `simp` list. This tactic is useful for speeding up the compilation of a complete file. Steps: 1. search and replace ` simp` with ` squeeze_simp` (the space helps avoid the replacement of `simp` in `@[simp]`) throughout the file. 2. Starting at the beginning of the file, go to each printout in turn, copy the suggestion in place of `squeeze_simp`. 3. after all the suggestions were applied, search and replace `squeeze_simp` with `simp` to remove the occurrences of `squeeze_simp` that did not produce a suggestion. Known limitation(s): * in cases where `squeeze_simp` is used after a `;` (e.g. `cases x; squeeze_simp`), `squeeze_simp` will produce as many suggestions as the number of goals it is applied to. It is likely that none of the suggestion is a good replacement but they can all be combined by concatenating their list of lemmas. `squeeze_scope` can be used to combine the suggestions: `by squeeze_scope { cases x; squeeze_simp }` -/ meta def squeeze_simp (key : parse cur_pos) (use_iota_eqn : parse (tk "!")?) (no_dflt : parse only_flag) (hs : parse simp_arg_list) (attr_names : parse with_ident_list) (locat : parse location) (cfg : parse struct_inst?) : tactic unit := do (cfg',c) ← parse_config cfg, squeeze_simp_core no_dflt hs (λ l_no_dft l_args, simp use_iota_eqn l_no_dft l_args attr_names locat cfg') (λ args, let use_iota_eqn := if use_iota_eqn.is_some then "!" else "", attrs := if attr_names.empty then "" else string.join (list.intersperse " " (" with" :: attr_names.map to_string)), loc := loc.to_string locat in mk_suggestion (key.move_left 1) sformat!"Try this: simp{use_iota_eqn} only " sformat!"{attrs}{loc}{c}" args) /-- see `squeeze_simp` -/ meta def squeeze_simpa (key : parse cur_pos) (use_iota_eqn : parse (tk "!")?) (no_dflt : parse only_flag) (hs : parse simp_arg_list) (attr_names : parse with_ident_list) (tgt : parse (tk "using" *> texpr)?) (cfg : parse struct_inst?) : tactic unit := do (cfg',c) ← parse_config cfg, tgt' ← traverse (λ t, do t ← to_expr t >>= pp, pure format!" using {t}") tgt, squeeze_simp_core no_dflt hs (λ l_no_dft l_args, simpa use_iota_eqn l_no_dft l_args attr_names tgt cfg') (λ args, let use_iota_eqn := if use_iota_eqn.is_some then "!" else "", attrs := if attr_names.empty then "" else string.join (list.intersperse " " (" with" :: attr_names.map to_string)), tgt' := tgt'.get_or_else "" in mk_suggestion (key.move_left 1) sformat!"Try this: simpa{use_iota_eqn} only " sformat!"{attrs}{tgt'}{c}" args) end interactive end tactic open tactic.interactive add_tactic_doc { name := "squeeze_simp / squeeze_simpa / squeeze_scope", category := doc_category.tactic, decl_names := [``squeeze_simp, ``squeeze_simpa, ``squeeze_scope], tags := ["simplification", "Try this"], inherit_description_from := ``squeeze_simp }
72bf70738c273bea136a412481838922e89a7420
94e33a31faa76775069b071adea97e86e218a8ee
/src/group_theory/submonoid/pointwise.lean
a91f171ad906e88574d62f82d657b97b98260a27
[ "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,758
lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import data.set.pointwise import group_theory.submonoid.membership /-! # Pointwise instances on `submonoid`s and `add_submonoid`s This file provides: * `submonoid.has_inv` * `add_submonoid.has_neg` and the actions * `submonoid.pointwise_mul_action` * `add_submonoid.pointwise_mul_action` which matches the action of `mul_action_set`. These are all available in the `pointwise` locale. Additionally, it provides various degrees of monoid structure: * `add_submonoid.has_one` * `add_submonoid.has_mul` * `add_submonoid.mul_one_class` * `add_submonoid.semigroup` * `add_submonoid.monoid` which is available globally to match the monoid structure implied by `submodule.semiring`. ## Implementation notes Most of the lemmas in this file are direct copies of lemmas from `algebra/pointwise.lean`. While the statements of these lemmas are defeq, we repeat them here due to them not being syntactically equal. Before adding new lemmas here, consider if they would also apply to the action on `set`s. -/ open set variables {α : Type*} {G : Type*} {M : Type*} {R : Type*} {A : Type*} variables [monoid M] [add_monoid A] namespace submonoid variables [group G] open_locale pointwise /-- The submonoid with every element inverted. -/ @[to_additive /-" The additive submonoid with every element negated. "-/] protected def has_inv : has_inv (submonoid G):= { inv := λ S, { carrier := (S : set G)⁻¹, one_mem' := show (1 : G)⁻¹ ∈ S, by { rw inv_one, exact S.one_mem }, mul_mem' := λ a b (ha : a⁻¹ ∈ S) (hb : b⁻¹ ∈ S), show (a * b)⁻¹ ∈ S, by { rw mul_inv_rev, exact S.mul_mem hb ha } } } localized "attribute [instance] submonoid.has_inv" in pointwise open_locale pointwise @[simp, to_additive] lemma coe_inv (S : submonoid G) : ↑(S⁻¹) = (S : set G)⁻¹ := rfl @[simp, to_additive] lemma mem_inv {g : G} {S : submonoid G} : g ∈ S⁻¹ ↔ g⁻¹ ∈ S := iff.rfl @[to_additive] instance : has_involutive_inv (submonoid G) := set_like.coe_injective.has_involutive_inv _ $ λ _, rfl @[simp, to_additive] lemma inv_le_inv (S T : submonoid G) : S⁻¹ ≤ T⁻¹ ↔ S ≤ T := set_like.coe_subset_coe.symm.trans set.inv_subset_inv @[to_additive] lemma inv_le (S T : submonoid G) : S⁻¹ ≤ T ↔ S ≤ T⁻¹ := set_like.coe_subset_coe.symm.trans set.inv_subset /-- `submonoid.has_inv` as an order isomorphism. -/ @[to_additive /-" `add_submonoid.has_neg` as an order isomorphism "-/, simps] def inv_order_iso : submonoid G ≃o submonoid G := { to_equiv := equiv.inv _, map_rel_iff' := inv_le_inv } @[to_additive] lemma closure_inv (s : set G) : closure s⁻¹ = (closure s)⁻¹ := begin apply le_antisymm, { rw [closure_le, coe_inv, ←set.inv_subset, inv_inv], exact subset_closure }, { rw [inv_le, closure_le, coe_inv, ←set.inv_subset], exact subset_closure } end @[simp, to_additive] lemma inv_inf (S T : submonoid G) : (S ⊓ T)⁻¹ = S⁻¹ ⊓ T⁻¹ := set_like.coe_injective set.inter_inv @[simp, to_additive] lemma inv_sup (S T : submonoid G) : (S ⊔ T)⁻¹ = S⁻¹ ⊔ T⁻¹ := (inv_order_iso : submonoid G ≃o submonoid G).map_sup S T @[simp, to_additive] lemma inv_bot : (⊥ : submonoid G)⁻¹ = ⊥ := set_like.coe_injective $ (set.inv_singleton 1).trans $ congr_arg _ inv_one @[simp, to_additive] lemma inv_top : (⊤ : submonoid G)⁻¹ = ⊤ := set_like.coe_injective $ set.inv_univ @[simp, to_additive] lemma inv_infi {ι : Sort*} (S : ι → submonoid G) : (⨅ i, S i)⁻¹ = ⨅ i, (S i)⁻¹ := (inv_order_iso : submonoid G ≃o submonoid G).map_infi _ @[simp, to_additive] lemma inv_supr {ι : Sort*} (S : ι → submonoid G) : (⨆ i, S i)⁻¹ = ⨆ i, (S i)⁻¹ := (inv_order_iso : submonoid G ≃o submonoid G).map_supr _ end submonoid namespace submonoid section monoid variables [monoid α] [mul_distrib_mul_action α M] /-- The action on a submonoid corresponding to applying the action to every element. This is available as an instance in the `pointwise` locale. -/ protected def pointwise_mul_action : mul_action α (submonoid M) := { smul := λ a S, S.map (mul_distrib_mul_action.to_monoid_End _ M a), one_smul := λ S, by { ext, simp, }, mul_smul := λ a₁ a₂ S, (congr_arg (λ f : monoid.End M, S.map f) (monoid_hom.map_mul _ _ _)).trans (S.map_map _ _).symm,} localized "attribute [instance] submonoid.pointwise_mul_action" in pointwise open_locale pointwise @[simp] lemma coe_pointwise_smul (a : α) (S : submonoid M) : ↑(a • S) = a • (S : set M) := rfl lemma smul_mem_pointwise_smul (m : M) (a : α) (S : submonoid M) : m ∈ S → a • m ∈ a • S := (set.smul_mem_smul_set : _ → _ ∈ a • (S : set M)) lemma mem_smul_pointwise_iff_exists (m : M) (a : α) (S : submonoid M) : m ∈ a • S ↔ ∃ (s : M), s ∈ S ∧ a • s = m := (set.mem_smul_set : m ∈ a • (S : set M) ↔ _) instance pointwise_central_scalar [mul_distrib_mul_action αᵐᵒᵖ M] [is_central_scalar α M] : is_central_scalar α (submonoid M) := ⟨λ a S, congr_arg (λ f : monoid.End M, S.map f) $ monoid_hom.ext $ by exact op_smul_eq_smul _⟩ end monoid section group variables [group α] [mul_distrib_mul_action α M] open_locale pointwise @[simp] lemma smul_mem_pointwise_smul_iff {a : α} {S : submonoid M} {x : M} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff lemma mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : submonoid M} {x : M} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem lemma mem_inv_pointwise_smul_iff {a : α} {S : submonoid M} {x : M} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] lemma pointwise_smul_le_pointwise_smul_iff {a : α} {S T : submonoid M} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff lemma pointwise_smul_subset_iff {a : α} {S T : submonoid M} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff lemma subset_pointwise_smul_iff {a : α} {S T : submonoid M} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff end group section group_with_zero variables [group_with_zero α] [mul_distrib_mul_action α M] open_locale pointwise @[simp] lemma smul_mem_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : submonoid M) (x : M) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : set M) x lemma mem_pointwise_smul_iff_inv_smul_mem₀ {a : α} (ha : a ≠ 0) (S : submonoid M) (x : M) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : set M) x lemma mem_inv_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : submonoid M) (x : M) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : set M) x @[simp] lemma pointwise_smul_le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : submonoid M} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff₀ ha lemma pointwise_smul_le_iff₀ {a : α} (ha : a ≠ 0) {S T : submonoid M} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff₀ ha lemma le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : submonoid M} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff₀ ha end group_with_zero open_locale pointwise @[to_additive] lemma mem_closure_inv {G : Type*} [group G] (S : set G) (x : G) : x ∈ submonoid.closure S⁻¹ ↔ x⁻¹ ∈ submonoid.closure S := by rw [closure_inv, mem_inv] end submonoid namespace add_submonoid section monoid variables [monoid α] [distrib_mul_action α A] /-- The action on an additive submonoid corresponding to applying the action to every element. This is available as an instance in the `pointwise` locale. -/ protected def pointwise_mul_action : mul_action α (add_submonoid A) := { smul := λ a S, S.map (distrib_mul_action.to_add_monoid_End _ A a), one_smul := λ S, (congr_arg (λ f : add_monoid.End A, S.map f) (monoid_hom.map_one _)).trans S.map_id, mul_smul := λ a₁ a₂ S, (congr_arg (λ f : add_monoid.End A, S.map f) (monoid_hom.map_mul _ _ _)).trans (S.map_map _ _).symm,} localized "attribute [instance] add_submonoid.pointwise_mul_action" in pointwise open_locale pointwise @[simp] lemma coe_pointwise_smul (a : α) (S : add_submonoid A) : ↑(a • S) = a • (S : set A) := rfl lemma smul_mem_pointwise_smul (m : A) (a : α) (S : add_submonoid A) : m ∈ S → a • m ∈ a • S := (set.smul_mem_smul_set : _ → _ ∈ a • (S : set A)) instance pointwise_central_scalar [distrib_mul_action αᵐᵒᵖ A] [is_central_scalar α A] : is_central_scalar α (add_submonoid A) := ⟨λ a S, congr_arg (λ f : add_monoid.End A, S.map f) $ add_monoid_hom.ext $ by exact op_smul_eq_smul _⟩ end monoid section group variables [group α] [distrib_mul_action α A] open_locale pointwise @[simp] lemma smul_mem_pointwise_smul_iff {a : α} {S : add_submonoid A} {x : A} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff lemma mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : add_submonoid A} {x : A} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem lemma mem_smul_pointwise_iff_exists (m : A) (a : α) (S : add_submonoid A) : m ∈ a • S ↔ ∃ (s : A), s ∈ S ∧ a • s = m := (set.mem_smul_set : m ∈ a • (S : set A) ↔ _) lemma mem_inv_pointwise_smul_iff {a : α} {S : add_submonoid A} {x : A} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] lemma pointwise_smul_le_pointwise_smul_iff {a : α} {S T : add_submonoid A} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff lemma pointwise_smul_le_iff {a : α} {S T : add_submonoid A} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff lemma le_pointwise_smul_iff {a : α} {S T : add_submonoid A} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff end group section group_with_zero variables [group_with_zero α] [distrib_mul_action α A] open_locale pointwise @[simp] lemma smul_mem_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : add_submonoid A) (x : A) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : set A) x lemma mem_pointwise_smul_iff_inv_smul_mem₀ {a : α} (ha : a ≠ 0) (S : add_submonoid A) (x : A) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : set A) x lemma mem_inv_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : add_submonoid A) (x : A) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : set A) x @[simp] lemma pointwise_smul_le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : add_submonoid A} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff₀ ha lemma pointwise_smul_le_iff₀ {a : α} (ha : a ≠ 0) {S T : add_submonoid A} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff₀ ha lemma le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : add_submonoid A} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff₀ ha end group_with_zero end add_submonoid /-! ### Elementwise monoid structure of additive submonoids These definitions are a cut-down versions of the ones around `submodule.has_mul`, as that API is usually more useful. -/ namespace add_submonoid open_locale pointwise section add_monoid_with_one variables [add_monoid_with_one R] instance : has_one (add_submonoid R) := ⟨(nat.cast_add_monoid_hom R).mrange⟩ theorem one_eq_mrange : (1 : add_submonoid R) = (nat.cast_add_monoid_hom R).mrange := rfl lemma nat_cast_mem_one (n : ℕ) : (n : R) ∈ (1 : add_submonoid R) := ⟨_, rfl⟩ @[simp] lemma mem_one {x : R} : x ∈ (1 : add_submonoid R) ↔ ∃ n : ℕ, ↑n = x := iff.rfl theorem one_eq_closure : (1 : add_submonoid R) = closure {1} := begin simp only [closure_singleton_eq, mul_one, one_eq_mrange], congr' 1 with n, simp, end theorem one_eq_closure_one_set : (1 : add_submonoid R) = closure 1 := one_eq_closure end add_monoid_with_one section non_unital_non_assoc_semiring variables [non_unital_non_assoc_semiring R] /-- Multiplication of additive submonoids of a semiring R. The additive submonoid `S * T` is the smallest R-submodule of `R` containing the elements `s * t` for `s ∈ S` and `t ∈ T`. -/ instance : has_mul (add_submonoid R) := ⟨λ M N, ⨆ s : M, N.map $ add_monoid_hom.mul s.1⟩ theorem mul_mem_mul {M N : add_submonoid R} {m n : R} (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N := (le_supr _ ⟨m, hm⟩ : _ ≤ M * N) ⟨n, hn, rfl⟩ theorem mul_le {M N P : add_submonoid R} : M * N ≤ P ↔ ∀ (m ∈ M) (n ∈ N), m * n ∈ P := ⟨λ H m hm n hn, H $ mul_mem_mul hm hn, λ H, supr_le $ λ ⟨m, hm⟩, map_le_iff_le_comap.2 $ λ n hn, H m hm n hn⟩ @[elab_as_eliminator] protected theorem mul_induction_on {M N : add_submonoid R} {C : R → Prop} {r : R} (hr : r ∈ M * N) (hm : ∀ (m ∈ M) (n ∈ N), C (m * n)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := (@mul_le _ _ _ _ ⟨C, ha, by simpa only [zero_mul] using hm _ (zero_mem _) _ (zero_mem _)⟩).2 hm hr open_locale pointwise -- this proof is copied directly from `submodule.span_mul_span` theorem closure_mul_closure (S T : set R) : closure S * closure T = closure (S * T) := begin apply le_antisymm, { rw mul_le, intros a ha b hb, apply closure_induction ha, work_on_goal 1 { intros, apply closure_induction hb, work_on_goal 1 { intros, exact subset_closure ⟨_, _, ‹_›, ‹_›, rfl⟩ } }, all_goals { intros, simp only [mul_zero, zero_mul, zero_mem, left_distrib, right_distrib, mul_smul_comm, smul_mul_assoc], solve_by_elim [add_mem _ _, zero_mem _] { max_depth := 4, discharger := tactic.interactive.apply_instance } } }, { rw closure_le, rintros _ ⟨a, b, ha, hb, rfl⟩, exact mul_mem_mul (subset_closure ha) (subset_closure hb) } end lemma mul_eq_closure_mul_set (M N : add_submonoid R) : M * N = closure (M * N) := by rw [←closure_mul_closure, closure_eq, closure_eq] @[simp] theorem mul_bot (S : add_submonoid R) : S * ⊥ = ⊥ := eq_bot_iff.2 $ mul_le.2 $ λ m hm n hn, by rw [add_submonoid.mem_bot] at hn ⊢; rw [hn, mul_zero] @[simp] theorem bot_mul (S : add_submonoid R) : ⊥ * S = ⊥ := eq_bot_iff.2 $ mul_le.2 $ λ m hm n hn, by rw [add_submonoid.mem_bot] at hm ⊢; rw [hm, zero_mul] @[mono] theorem mul_le_mul {M N P Q : add_submonoid R} (hmp : M ≤ P) (hnq : N ≤ Q) : M * N ≤ P * Q := mul_le.2 $ λ m hm n hn, mul_mem_mul (hmp hm) (hnq hn) theorem mul_le_mul_left {M N P : add_submonoid R} (h : M ≤ N) : M * P ≤ N * P := mul_le_mul h (le_refl P) theorem mul_le_mul_right {M N P : add_submonoid R} (h : N ≤ P) : M * N ≤ M * P := mul_le_mul (le_refl M) h lemma mul_subset_mul {M N : add_submonoid R} : (↑M : set R) * (↑N : set R) ⊆ (↑(M * N) : set R) := by { rintros _ ⟨i, j, hi, hj, rfl⟩, exact mul_mem_mul hi hj } end non_unital_non_assoc_semiring section non_unital_non_assoc_ring variables [non_unital_non_assoc_ring R] /-- `add_submonoid.has_pointwise_neg` distributes over multiplication. This is available as an instance in the `pointwise` locale. -/ protected def has_distrib_neg : has_distrib_neg (add_submonoid R) := { neg := has_neg.neg, neg_mul := λ x y, begin refine le_antisymm (mul_le.2 $ λ m hm n hn, _) ((add_submonoid.neg_le _ _).2 $ mul_le.2 $ λ m hm n hn, _); simp only [add_submonoid.mem_neg, ←neg_mul] at *, { exact mul_mem_mul hm hn }, { exact mul_mem_mul (neg_mem_neg.2 hm) hn }, end, mul_neg := λ x y, begin refine le_antisymm (mul_le.2 $ λ m hm n hn, _) ((add_submonoid.neg_le _ _).2 $ mul_le.2 $ λ m hm n hn, _); simp only [add_submonoid.mem_neg, ←mul_neg] at *, { exact mul_mem_mul hm hn,}, { exact mul_mem_mul hm (neg_mem_neg.2 hn) }, end, ..add_submonoid.has_involutive_neg } localized "attribute [instance] add_submonoid.has_distrib_neg" in pointwise end non_unital_non_assoc_ring section non_assoc_semiring variables [non_assoc_semiring R] instance : mul_one_class (add_submonoid R) := { one := 1, mul := (*), one_mul := λ M, by rw [one_eq_closure_one_set, ←closure_eq M, closure_mul_closure, one_mul], mul_one := λ M, by rw [one_eq_closure_one_set, ←closure_eq M, closure_mul_closure, mul_one] } end non_assoc_semiring section non_unital_semiring variables [non_unital_semiring R] instance : semigroup (add_submonoid R) := { mul := (*), mul_assoc := λ M N P, le_antisymm (mul_le.2 $ λ mn hmn p hp, suffices M * N ≤ (M * (N * P)).comap (add_monoid_hom.mul_right p), from this hmn, mul_le.2 $ λ m hm n hn, show m * n * p ∈ M * (N * P), from (mul_assoc m n p).symm ▸ mul_mem_mul hm (mul_mem_mul hn hp)) (mul_le.2 $ λ m hm np hnp, suffices N * P ≤ (M * N * P).comap (add_monoid_hom.mul_left m), from this hnp, mul_le.2 $ λ n hn p hp, show m * (n * p) ∈ M * N * P, from mul_assoc m n p ▸ mul_mem_mul (mul_mem_mul hm hn) hp) } end non_unital_semiring section semiring variables [semiring R] instance : monoid (add_submonoid R) := { one := 1, mul := (*), ..add_submonoid.semigroup, ..add_submonoid.mul_one_class } lemma closure_pow (s : set R) : ∀ n : ℕ, closure s ^ n = closure (s ^ n) | 0 := by rw [pow_zero, pow_zero, one_eq_closure_one_set] | (n + 1) := by rw [pow_succ, pow_succ, closure_pow, closure_mul_closure] lemma pow_eq_closure_pow_set (s : add_submonoid R) (n : ℕ) : s ^ n = closure ((s : set R) ^ n) := by rw [←closure_pow, closure_eq] lemma pow_subset_pow {s : add_submonoid R} {n : ℕ} : (↑s : set R)^n ⊆ ↑(s^n) := (pow_eq_closure_pow_set s n).symm ▸ subset_closure end semiring end add_submonoid
ee9e102a91fdc2c7cea136228dadc57a8fac5508
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/match_tac4.lean
787cc25dc39b6994f0ce2e09afefea6bfeaa6612
[ "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
759
lean
notation `⟪`:max t:(foldr `,` (e r, and.intro e r)) `⟫`:0 := t check ⟪ trivial, trivial, trivial ⟫ theorem tst (a b c d : Prop) : a ∧ b ∧ c ∧ d ↔ d ∧ c ∧ b ∧ a := begin apply iff.intro, begin intro H, match H with | ⟪ H₁, H₂, H₃, H₄ ⟫ := ⟪ H₄, H₃, H₂, H₁ ⟫ end end, begin intro H, match H with | ⟪ H₁, H₂, H₃, H₄ ⟫ := begin repeat (apply and.intro | assumption) end end end end reveal tst print definition tst theorem tst2 (a b c d : Prop) : a ∧ b ∧ c ∧ d ↔ d ∧ c ∧ b ∧ a := begin apply iff.intro, repeat (intro H; repeat (cases H with [H', H] | apply and.intro | assumption)) end reveal tst2 print definition tst2
c3617c84200a8f5243782d8a8c75ce7442ddaf97
94e33a31faa76775069b071adea97e86e218a8ee
/src/category_theory/functor/flat.lean
826bb9a02ff200570a68acdb3177b705cb473111
[ "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
16,390
lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import category_theory.limits.filtered_colimit_commutes_finite_limit import category_theory.limits.preserves.functor_category import category_theory.limits.preserves.shapes.equalizers import category_theory.limits.bicones import category_theory.limits.comma import category_theory.limits.preserves.finite import category_theory.limits.shapes.finite_limits /-! # Representably flat functors We define representably flat functors as functors such that the category of structured arrows over `X` is cofiltered for each `X`. This concept is also known as flat functors as in [Elephant] Remark C2.3.7, and this name is suggested by Mike Shulman in https://golem.ph.utexas.edu/category/2011/06/flat_functors_and_morphisms_of.html to avoid confusion with other notions of flatness. This definition is equivalent to left exact functors (functors that preserves finite limits) when `C` has all finite limits. ## Main results * `flat_of_preserves_finite_limits`: If `F : C ⥤ D` preserves finite limits and `C` has all finite limits, then `F` is flat. * `preserves_finite_limits_of_flat`: If `F : C ⥤ D` is flat, then it preserves all finite limits. * `preserves_finite_limits_iff_flat`: If `C` has all finite limits, then `F` is flat iff `F` is left_exact. * `Lan_preserves_finite_limits_of_flat`: If `F : C ⥤ D` is a flat functor between small categories, then the functor `Lan F.op` between presheaves of sets preserves all finite limits. * `flat_iff_Lan_flat`: If `C`, `D` are small and `C` has all finite limits, then `F` is flat iff `Lan F.op : (Cᵒᵖ ⥤ Type*) ⥤ (Dᵒᵖ ⥤ Type*)` is flat. * `preserves_finite_limits_iff_Lan_preserves_finite_limits`: If `C`, `D` are small and `C` has all finite limits, then `F` preserves finite limits iff `Lan F.op : (Cᵒᵖ ⥤ Type*) ⥤ (Dᵒᵖ ⥤ Type*)` does. -/ universes w v₁ v₂ v₃ u₁ u₂ u₃ open category_theory open category_theory.limits open opposite namespace category_theory namespace structured_arrow_cone open structured_arrow variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₁} D] variables {J : Type w} [small_category J] variables {K : J ⥤ C} (F : C ⥤ D) (c : cone K) /-- Given a cone `c : cone K` and a map `f : X ⟶ c.X`, we can construct a cone of structured arrows over `X` with `f` as the cone point. This is the underlying diagram. -/ @[simps] def to_diagram : J ⥤ structured_arrow c.X K := { obj := λ j, structured_arrow.mk (c.π.app j), map := λ j k g, structured_arrow.hom_mk g (by simpa) } /-- Given a diagram of `structured_arrow X F`s, we may obtain a cone with cone point `X`. -/ @[simps] def diagram_to_cone {X : D} (G : J ⥤ structured_arrow X F) : cone (G ⋙ proj X F ⋙ F) := { X := X, π := { app := λ j, (G.obj j).hom } } /-- Given a cone `c : cone K` and a map `f : X ⟶ F.obj c.X`, we can construct a cone of structured arrows over `X` with `f` as the cone point. -/ @[simps] def to_cone {X : D} (f : X ⟶ F.obj c.X) : cone (to_diagram (F.map_cone c) ⋙ map f ⋙ pre _ K F) := { X := mk f, π := { app := λ j, hom_mk (c.π.app j) rfl, naturality' := λ j k g, by { ext, dsimp, simp } } } end structured_arrow_cone section representably_flat variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D] variables {E : Type u₃} [category.{v₃} E] /-- A functor `F : C ⥤ D` is representably-flat functor if the comma category `(X/F)` is cofiltered for each `X : C`. -/ class representably_flat (F : C ⥤ D) : Prop := (cofiltered : ∀ (X : D), is_cofiltered (structured_arrow X F)) attribute [instance] representably_flat.cofiltered local attribute [instance] is_cofiltered.nonempty instance representably_flat.id : representably_flat (𝟭 C) := begin constructor, intro X, haveI : nonempty (structured_arrow X (𝟭 C)) := ⟨structured_arrow.mk (𝟙 _)⟩, suffices : is_cofiltered_or_empty (structured_arrow X (𝟭 C)), { resetI, constructor }, constructor, { intros Y Z, use structured_arrow.mk (𝟙 _), use structured_arrow.hom_mk Y.hom (by erw [functor.id_map, category.id_comp]), use structured_arrow.hom_mk Z.hom (by erw [functor.id_map, category.id_comp]) }, { intros Y Z f g, use structured_arrow.mk (𝟙 _), use structured_arrow.hom_mk Y.hom (by erw [functor.id_map, category.id_comp]), ext, transitivity Z.hom; simp } end instance representably_flat.comp (F : C ⥤ D) (G : D ⥤ E) [representably_flat F] [representably_flat G] : representably_flat (F ⋙ G) := begin constructor, intro X, haveI : nonempty (structured_arrow X (F ⋙ G)), { have f₁ : structured_arrow X G := nonempty.some infer_instance, have f₂ : structured_arrow f₁.right F := nonempty.some infer_instance, exact ⟨structured_arrow.mk (f₁.hom ≫ G.map f₂.hom)⟩ }, suffices : is_cofiltered_or_empty (structured_arrow X (F ⋙ G)), { resetI, constructor }, constructor, { intros Y Z, let W := @is_cofiltered.min (structured_arrow X G) _ _ (structured_arrow.mk Y.hom) (structured_arrow.mk Z.hom), let Y' : W ⟶ _ := is_cofiltered.min_to_left _ _, let Z' : W ⟶ _ := is_cofiltered.min_to_right _ _, let W' := @is_cofiltered.min (structured_arrow W.right F) _ _ (structured_arrow.mk Y'.right) (structured_arrow.mk Z'.right), let Y'' : W' ⟶ _ := is_cofiltered.min_to_left _ _, let Z'' : W' ⟶ _ := is_cofiltered.min_to_right _ _, use structured_arrow.mk (W.hom ≫ G.map W'.hom), use structured_arrow.hom_mk Y''.right (by simp [← G.map_comp]), use structured_arrow.hom_mk Z''.right (by simp [← G.map_comp]) }, { intros Y Z f g, let W := @is_cofiltered.eq (structured_arrow X G) _ _ (structured_arrow.mk Y.hom) (structured_arrow.mk Z.hom) (structured_arrow.hom_mk (F.map f.right) (structured_arrow.w f)) (structured_arrow.hom_mk (F.map g.right) (structured_arrow.w g)), let h : W ⟶ _ := is_cofiltered.eq_hom _ _, let h_cond : h ≫ _ = h ≫ _ := is_cofiltered.eq_condition _ _, let W' := @is_cofiltered.eq (structured_arrow W.right F) _ _ (structured_arrow.mk h.right) (structured_arrow.mk (h.right ≫ F.map f.right)) (structured_arrow.hom_mk f.right rfl) (structured_arrow.hom_mk g.right (congr_arg comma_morphism.right h_cond).symm), let h' : W' ⟶ _ := is_cofiltered.eq_hom _ _, let h'_cond : h' ≫ _ = h' ≫ _ := is_cofiltered.eq_condition _ _, use structured_arrow.mk (W.hom ≫ G.map W'.hom), use structured_arrow.hom_mk h'.right (by simp [← G.map_comp]), ext, exact (congr_arg comma_morphism.right h'_cond : _) } end end representably_flat section has_limit variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₁} D] local attribute [instance] has_finite_limits_of_has_finite_limits_of_size @[priority 100] instance cofiltered_of_has_finite_limits [has_finite_limits C] : is_cofiltered C := { cocone_objs := λ A B, ⟨limits.prod A B, limits.prod.fst, limits.prod.snd, trivial⟩, cocone_maps := λ A B f g, ⟨equalizer f g, equalizer.ι f g, equalizer.condition f g⟩, nonempty := ⟨⊤_ C⟩ } lemma flat_of_preserves_finite_limits [has_finite_limits C] (F : C ⥤ D) [preserves_finite_limits F] : representably_flat F := ⟨λ X, begin haveI : has_finite_limits (structured_arrow X F) := begin apply has_finite_limits_of_has_finite_limits_of_size.{v₁} (structured_arrow X F), intros J sJ fJ, resetI, constructor end, apply_instance end⟩ namespace preserves_finite_limits_of_flat open structured_arrow open structured_arrow_cone variables {J : Type v₁} [small_category J] [fin_category J] {K : J ⥤ C} variables (F : C ⥤ D) [representably_flat F] {c : cone K} (hc : is_limit c) (s : cone (K ⋙ F)) include hc /-- (Implementation). Given a limit cone `c : cone K` and a cone `s : cone (K ⋙ F)` with `F` representably flat, `s` can factor through `F.map_cone c`. -/ noncomputable def lift : s.X ⟶ F.obj c.X := let s' := is_cofiltered.cone (to_diagram s ⋙ structured_arrow.pre _ K F) in s'.X.hom ≫ (F.map $ hc.lift $ (cones.postcompose ({ app := λ X, 𝟙 _, naturality' := by simp } : (to_diagram s ⋙ pre s.X K F) ⋙ proj s.X F ⟶ K)).obj $ (structured_arrow.proj s.X F).map_cone s') lemma fac (x : J) : lift F hc s ≫ (F.map_cone c).π.app x = s.π.app x := by simpa [lift, ←functor.map_comp] local attribute [simp] eq_to_hom_map lemma uniq {K : J ⥤ C} {c : cone K} (hc : is_limit c) (s : cone (K ⋙ F)) (f₁ f₂ : s.X ⟶ F.obj c.X) (h₁ : ∀ (j : J), f₁ ≫ (F.map_cone c).π.app j = s.π.app j) (h₂ : ∀ (j : J), f₂ ≫ (F.map_cone c).π.app j = s.π.app j) : f₁ = f₂ := begin -- We can make two cones over the diagram of `s` via `f₁` and `f₂`. let α₁ : to_diagram (F.map_cone c) ⋙ map f₁ ⟶ to_diagram s := { app := λ X, eq_to_hom (by simp [←h₁]), naturality' := λ _ _ _, by { ext, simp } }, let α₂ : to_diagram (F.map_cone c) ⋙ map f₂ ⟶ to_diagram s := { app := λ X, eq_to_hom (by simp [←h₂]), naturality' := λ _ _ _, by { ext, simp } }, let c₁ : cone (to_diagram s ⋙ pre s.X K F) := (cones.postcompose (whisker_right α₁ (pre s.X K F) : _)).obj (to_cone F c f₁), let c₂ : cone (to_diagram s ⋙ pre s.X K F) := (cones.postcompose (whisker_right α₂ (pre s.X K F) : _)).obj (to_cone F c f₂), -- The two cones can then be combined and we may obtain a cone over the two cones since -- `structured_arrow s.X F` is cofiltered. let c₀ := is_cofiltered.cone (bicone_mk _ c₁ c₂), let g₁ : c₀.X ⟶ c₁.X := c₀.π.app (bicone.left), let g₂ : c₀.X ⟶ c₂.X := c₀.π.app (bicone.right), -- Then `g₁.right` and `g₂.right` are two maps from the same cone into the `c`. have : ∀ (j : J), g₁.right ≫ c.π.app j = g₂.right ≫ c.π.app j, { intro j, injection c₀.π.naturality (bicone_hom.left j) with _ e₁, injection c₀.π.naturality (bicone_hom.right j) with _ e₂, simpa using e₁.symm.trans e₂ }, have : c.extend g₁.right = c.extend g₂.right, { unfold cone.extend, congr' 1, ext x, apply this }, -- And thus they are equal as `c` is the limit. have : g₁.right = g₂.right, calc g₁.right = hc.lift (c.extend g₁.right) : by { apply hc.uniq (c.extend _), tidy } ... = hc.lift (c.extend g₂.right) : by { congr, exact this } ... = g₂.right : by { symmetry, apply hc.uniq (c.extend _), tidy }, -- Finally, since `fᵢ` factors through `F(gᵢ)`, the result follows. calc f₁ = 𝟙 _ ≫ f₁ : by simp ... = c₀.X.hom ≫ F.map g₁.right : g₁.w ... = c₀.X.hom ≫ F.map g₂.right : by rw this ... = 𝟙 _ ≫ f₂ : g₂.w.symm ... = f₂ : by simp end end preserves_finite_limits_of_flat /-- Representably flat functors preserve finite limits. -/ noncomputable def preserves_finite_limits_of_flat (F : C ⥤ D) [representably_flat F] : preserves_finite_limits F := begin apply preserves_finite_limits_of_preserves_finite_limits_of_size, intros J _ _, constructor, intros K, constructor, intros c hc, exactI { lift := preserves_finite_limits_of_flat.lift F hc, fac' := preserves_finite_limits_of_flat.fac F hc, uniq' := λ s m h, by { apply preserves_finite_limits_of_flat.uniq F hc, exact h, exact preserves_finite_limits_of_flat.fac F hc s } } end /-- If `C` is finitely cocomplete, then `F : C ⥤ D` is representably flat iff it preserves finite limits. -/ noncomputable def preserves_finite_limits_iff_flat [has_finite_limits C] (F : C ⥤ D) : representably_flat F ≃ preserves_finite_limits F := { to_fun := λ _, by exactI preserves_finite_limits_of_flat F, inv_fun := λ _, by exactI flat_of_preserves_finite_limits F, left_inv := λ _, proof_irrel _ _, right_inv := λ x, by { cases x, unfold preserves_finite_limits_of_flat, dunfold preserves_finite_limits_of_preserves_finite_limits_of_size, congr } } end has_limit section small_category variables {C D : Type u₁} [small_category C] [small_category D] (E : Type u₂) [category.{u₁} E] /-- (Implementation) The evaluation of `Lan F` at `X` is the colimit over the costructured arrows over `X`. -/ noncomputable def Lan_evaluation_iso_colim (F : C ⥤ D) (X : D) [∀ (X : D), has_colimits_of_shape (costructured_arrow F X) E] : Lan F ⋙ (evaluation D E).obj X ≅ ((whiskering_left _ _ E).obj (costructured_arrow.proj F X)) ⋙ colim := nat_iso.of_components (λ G, colim.map_iso (iso.refl _)) begin intros G H i, ext, simp only [functor.comp_map, colimit.ι_desc_assoc, functor.map_iso_refl, evaluation_obj_map, whiskering_left_obj_map, category.comp_id, Lan_map_app, category.assoc], erw [colimit.ι_pre_assoc (Lan.diagram F H X) (costructured_arrow.map j.hom), category.id_comp, category.comp_id, colimit.ι_map], rcases j with ⟨j_left, ⟨⟨⟩⟩, j_hom⟩, congr, rw [costructured_arrow.map_mk, category.id_comp, costructured_arrow.mk] end variables [concrete_category.{u₁} E] [has_limits E] [has_colimits E] variables [reflects_limits (forget E)] [preserves_filtered_colimits (forget E)] variables [preserves_limits (forget E)] /-- If `F : C ⥤ D` is a representably flat functor between small categories, then the functor `Lan F.op` that takes presheaves over `C` to presheaves over `D` preserves finite limits. -/ noncomputable instance Lan_preserves_finite_limits_of_flat (F : C ⥤ D) [representably_flat F] : preserves_finite_limits (Lan F.op : _ ⥤ (Dᵒᵖ ⥤ E)) := begin apply preserves_finite_limits_of_preserves_finite_limits_of_size.{u₁}, intros J _ _, resetI, apply preserves_limits_of_shape_of_evaluation (Lan F.op : (Cᵒᵖ ⥤ E) ⥤ (Dᵒᵖ ⥤ E)) J, intro K, haveI : is_filtered (costructured_arrow F.op K) := is_filtered.of_equivalence (structured_arrow_op_equivalence F (unop K)), exact preserves_limits_of_shape_of_nat_iso (Lan_evaluation_iso_colim _ _ _).symm, end instance Lan_flat_of_flat (F : C ⥤ D) [representably_flat F] : representably_flat (Lan F.op : _ ⥤ (Dᵒᵖ ⥤ E)) := flat_of_preserves_finite_limits _ variable [has_finite_limits C] noncomputable instance Lan_preserves_finite_limits_of_preserves_finite_limits (F : C ⥤ D) [preserves_finite_limits F] : preserves_finite_limits (Lan F.op : _ ⥤ (Dᵒᵖ ⥤ E)) := begin haveI := flat_of_preserves_finite_limits F, apply_instance end lemma flat_iff_Lan_flat (F : C ⥤ D) : representably_flat F ↔ representably_flat (Lan F.op : _ ⥤ (Dᵒᵖ ⥤ Type u₁)) := ⟨λ H, by exactI infer_instance, λ H, begin resetI, haveI := preserves_finite_limits_of_flat (Lan F.op : _ ⥤ (Dᵒᵖ ⥤ Type u₁)), haveI : preserves_finite_limits F := begin apply preserves_finite_limits_of_preserves_finite_limits_of_size.{u₁}, intros, resetI, apply preserves_limit_of_Lan_presesrves_limit end, apply flat_of_preserves_finite_limits end⟩ /-- If `C` is finitely complete, then `F : C ⥤ D` preserves finite limits iff `Lan F.op : (Cᵒᵖ ⥤ Type*) ⥤ (Dᵒᵖ ⥤ Type*)` preserves finite limits. -/ noncomputable def preserves_finite_limits_iff_Lan_preserves_finite_limits (F : C ⥤ D) : preserves_finite_limits F ≃ preserves_finite_limits (Lan F.op : _ ⥤ (Dᵒᵖ ⥤ Type u₁)) := { to_fun := λ _, by exactI infer_instance, inv_fun := λ _, begin apply preserves_finite_limits_of_preserves_finite_limits_of_size.{u₁}, intros, resetI, apply preserves_limit_of_Lan_presesrves_limit end, left_inv := λ x, begin cases x, unfold preserves_finite_limits_of_flat, dunfold preserves_finite_limits_of_preserves_finite_limits_of_size, congr end, right_inv := λ x, begin cases x, unfold preserves_finite_limits_of_flat, congr, unfold category_theory.Lan_preserves_finite_limits_of_preserves_finite_limits category_theory.Lan_preserves_finite_limits_of_flat, dunfold preserves_finite_limits_of_preserves_finite_limits_of_size, congr end } end small_category end category_theory
4757edfc36b810cce3dd98c388bdc1ee5a969b4d
a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7
/src/data/padics/padic_integers.lean
6bd2c4debc09ed22c9a6c20d859074daf9ee7ac9
[ "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
10,571
lean
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Mario Carneiro -/ import data.int.modeq import data.padics.padic_numbers /-! # p-adic integers This file defines the p-adic integers ℤ_p as the subtype of ℚ_p with norm ≤ 1. We show that ℤ_p is a complete nonarchimedean normed local ring. ## Important definitions * `padic_int` : the type of p-adic numbers ## Notation We introduce the notation ℤ_[p] for the p-adic integers. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking (prime p) as a type class argument. Coercions into ℤ_p are set up to work with the `norm_cast` tactic. ## References * [F. Q. Gouêva, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, p-adic integer -/ open nat padic metric noncomputable theory open_locale classical /-- The p-adic integers ℤ_p are the p-adic numbers with norm ≤ 1. -/ def padic_int (p : ℕ) [fact p.prime] := {x : ℚ_[p] // ∥x∥ ≤ 1} notation `ℤ_[`p`]` := padic_int p namespace padic_int variables {p : ℕ} [fact p.prime] instance : has_coe ℤ_[p] ℚ_[p] := ⟨subtype.val⟩ @[ext] lemma ext {x y : ℤ_[p]} : (x : ℚ_[p]) = y → x = y := subtype.ext_iff_val.2 /-- Addition on ℤ_p is inherited from ℚ_p. -/ instance : has_add ℤ_[p] := ⟨λ ⟨x, hx⟩ ⟨y, hy⟩, ⟨x+y, le_trans (padic_norm_e.nonarchimedean _ _) (max_le_iff.2 ⟨hx,hy⟩)⟩⟩ /-- Multiplication on ℤ_p is inherited from ℚ_p. -/ instance : has_mul ℤ_[p] := ⟨λ ⟨x, hx⟩ ⟨y, hy⟩, ⟨x*y, begin rw padic_norm_e.mul, apply mul_le_one; {assumption <|> apply norm_nonneg} end⟩⟩ /-- Negation on ℤ_p is inherited from ℚ_p. -/ instance : has_neg ℤ_[p] := ⟨λ ⟨x, hx⟩, ⟨-x, by simpa⟩⟩ /-- Zero on ℤ_p is inherited from ℚ_p. -/ instance : has_zero ℤ_[p] := ⟨⟨0, by norm_num⟩⟩ instance : inhabited ℤ_[p] := ⟨0⟩ /-- One on ℤ_p is inherited from ℚ_p. -/ instance : has_one ℤ_[p] := ⟨⟨1, by norm_num⟩⟩ @[simp] lemma mk_zero {h} : (⟨0, h⟩ : ℤ_[p]) = (0 : ℤ_[p]) := rfl @[simp] lemma val_eq_coe (z : ℤ_[p]) : z.val = z := rfl @[simp, norm_cast] lemma coe_add : ∀ (z1 z2 : ℤ_[p]), ((z1 + z2 : ℤ_[p]) : ℚ_[p]) = z1 + z2 | ⟨_, _⟩ ⟨_, _⟩ := rfl @[simp, norm_cast] lemma coe_mul : ∀ (z1 z2 : ℤ_[p]), ((z1 * z2 : ℤ_[p]) : ℚ_[p]) = z1 * z2 | ⟨_, _⟩ ⟨_, _⟩ := rfl @[simp, norm_cast] lemma coe_neg : ∀ (z1 : ℤ_[p]), ((-z1 : ℤ_[p]) : ℚ_[p]) = -z1 | ⟨_, _⟩ := rfl @[simp, norm_cast] lemma coe_one : ((1 : ℤ_[p]) : ℚ_[p]) = 1 := rfl @[simp, norm_cast] lemma coe_coe : ∀ n : ℕ, ((n : ℤ_[p]) : ℚ_[p]) = n | 0 := rfl | (k+1) := by simp [coe_coe] @[simp, norm_cast] lemma coe_zero : ((0 : ℤ_[p]) : ℚ_[p]) = 0 := rfl instance : ring ℤ_[p] := begin refine { add := (+), mul := (*), neg := has_neg.neg, zero := 0, one := 1, .. }; intros; ext; simp; ring end @[simp, norm_cast] lemma coe_sub : ∀ (z1 z2 : ℤ_[p]), (↑(z1 - z2) : ℚ_[p]) = ↑z1 - ↑z2 | ⟨_, _⟩ ⟨_, _⟩ := rfl @[simp, norm_cast] lemma cast_pow (x : ℤ_[p]) : ∀ (n : ℕ), (↑(x^n) : ℚ_[p]) = (↑x : ℚ_[p])^n | 0 := by simp | (k+1) := by simp [monoid.pow, pow]; congr; apply cast_pow @[simp] lemma mk_coe : ∀ (k : ℤ_[p]), (⟨k, k.2⟩ : ℤ_[p]) = k | ⟨_, _⟩ := rfl /-- The inverse of a p-adic integer with norm equal to 1 is also a p-adic integer. Otherwise, the inverse is defined to be 0. -/ def inv : ℤ_[p] → ℤ_[p] | ⟨k, _⟩ := if h : ∥k∥ = 1 then ⟨1/k, by simp [h]⟩ else 0 end padic_int section instances variables {p : ℕ} [fact p.prime] instance : metric_space ℤ_[p] := subtype.metric_space instance : has_norm ℤ_[p] := ⟨λ z, ∥(z : ℚ_[p])∥⟩ lemma padic_norm_z {z : ℤ_[p]} : ∥z∥ = ∥(z : ℚ_[p])∥ := rfl instance : normed_ring ℤ_[p] := { dist_eq := λ ⟨_, _⟩ ⟨_, _⟩, rfl, norm_mul := λ ⟨_, _⟩ ⟨_, _⟩, norm_mul_le _ _ } instance padic_norm_z.is_absolute_value : is_absolute_value (λ z : ℤ_[p], ∥z∥) := { abv_nonneg := norm_nonneg, abv_eq_zero := λ ⟨_, _⟩, by simp [norm_eq_zero], abv_add := λ ⟨_,_⟩ ⟨_, _⟩, norm_add_le _ _, abv_mul := λ _ _, by simp [padic_norm_z] } protected lemma padic_int.pmul_comm : ∀ z1 z2 : ℤ_[p], z1*z2 = z2*z1 | ⟨q1, h1⟩ ⟨q2, h2⟩ := show (⟨q1*q2, _⟩ : ℤ_[p]) = ⟨q2*q1, _⟩, by simp [mul_comm] instance : comm_ring ℤ_[p] := { mul_comm := padic_int.pmul_comm, ..padic_int.ring } protected lemma padic_int.zero_ne_one : (0 : ℤ_[p]) ≠ 1 := show (⟨(0 : ℚ_[p]), _⟩ : ℤ_[p]) ≠ ⟨(1 : ℚ_[p]), _⟩, from mt subtype.ext_iff_val.1 zero_ne_one protected lemma padic_int.eq_zero_or_eq_zero_of_mul_eq_zero : ∀ (a b : ℤ_[p]), a * b = 0 → a = 0 ∨ b = 0 | ⟨a, ha⟩ ⟨b, hb⟩ := λ h : (⟨a * b, _⟩ : ℤ_[p]) = ⟨0, _⟩, have a * b = 0, from subtype.ext_iff_val.1 h, (mul_eq_zero.1 this).elim (λ h1, or.inl (by simp [h1]; refl)) (λ h2, or.inr (by simp [h2]; refl)) instance : integral_domain ℤ_[p] := { eq_zero_or_eq_zero_of_mul_eq_zero := padic_int.eq_zero_or_eq_zero_of_mul_eq_zero, zero_ne_one := padic_int.zero_ne_one, ..padic_int.comm_ring } end instances namespace padic_norm_z variables {p : ℕ} [fact p.prime] lemma le_one : ∀ z : ℤ_[p], ∥z∥ ≤ 1 | ⟨_, h⟩ := h @[simp] lemma one : ∥(1 : ℤ_[p])∥ = 1 := by simp [norm, padic_norm_z] @[simp] lemma mul (z1 z2 : ℤ_[p]) : ∥z1 * z2∥ = ∥z1∥ * ∥z2∥ := by simp [padic_norm_z] @[simp] lemma pow (z : ℤ_[p]) : ∀ n : ℕ, ∥z^n∥ = ∥z∥^n | 0 := by simp | (k+1) := show ∥z*z^k∥ = ∥z∥*∥z∥^k, by {rw mul, congr, apply pow} theorem nonarchimedean : ∀ (q r : ℤ_[p]), ∥q + r∥ ≤ max (∥q∥) (∥r∥) | ⟨_, _⟩ ⟨_, _⟩ := padic_norm_e.nonarchimedean _ _ theorem add_eq_max_of_ne : ∀ {q r : ℤ_[p]}, ∥q∥ ≠ ∥r∥ → ∥q+r∥ = max (∥q∥) (∥r∥) | ⟨_, _⟩ ⟨_, _⟩ := padic_norm_e.add_eq_max_of_ne lemma norm_one : ∥(1 : ℤ_[p])∥ = 1 := normed_field.norm_one lemma eq_of_norm_add_lt_right {z1 z2 : ℤ_[p]} (h : ∥z1 + z2∥ < ∥z2∥) : ∥z1∥ = ∥z2∥ := by_contradiction $ λ hne, not_lt_of_ge (by rw padic_norm_z.add_eq_max_of_ne hne; apply le_max_right) h lemma eq_of_norm_add_lt_left {z1 z2 : ℤ_[p]} (h : ∥z1 + z2∥ < ∥z1∥) : ∥z1∥ = ∥z2∥ := by_contradiction $ λ hne, not_lt_of_ge (by rw padic_norm_z.add_eq_max_of_ne hne; apply le_max_left) h @[simp] lemma padic_norm_e_of_padic_int (z : ℤ_[p]) : ∥(↑z : ℚ_[p])∥ = ∥z∥ := by simp [padic_norm_z] @[simp] lemma padic_norm_z_eq_padic_norm_e {q : ℚ_[p]} (hq : ∥q∥ ≤ 1) : @norm ℤ_[p] _ ⟨q, hq⟩ = ∥q∥ := rfl end padic_norm_z private lemma mul_lt_one {α} [decidable_linear_ordered_comm_ring α] {a b : α} (hbz : 0 < b) (ha : a < 1) (hb : b < 1) : a * b < 1 := suffices a*b < 1*1, by simpa, mul_lt_mul ha (le_of_lt hb) hbz zero_le_one private lemma mul_lt_one_of_le_of_lt {α} [decidable_linear_ordered_comm_ring α] {a b : α} (ha : a ≤ 1) (hbz : 0 ≤ b) (hb : b < 1) : a * b < 1 := if hb' : b = 0 then by simpa [hb'] using zero_lt_one else if ha' : a = 1 then by simpa [ha'] else mul_lt_one (lt_of_le_of_ne hbz (ne.symm hb')) (lt_of_le_of_ne ha ha') hb namespace padic_int variables {p : ℕ} [fact p.prime] local attribute [reducible] padic_int lemma mul_inv : ∀ {z : ℤ_[p]}, ∥z∥ = 1 → z * z.inv = 1 | ⟨k, _⟩ h := begin have hk : k ≠ 0, from λ h', @zero_ne_one ℚ_[p] _ _ _ (by simpa [h'] using h), unfold padic_int.inv, split_ifs, { change (⟨k * (1/k), _⟩ : ℤ_[p]) = 1, simp [hk], refl }, { apply subtype.ext_iff_val.2, simp [mul_inv_cancel hk] } end lemma inv_mul {z : ℤ_[p]} (hz : ∥z∥ = 1) : z.inv * z = 1 := by rw [mul_comm, mul_inv hz] lemma is_unit_iff {z : ℤ_[p]} : is_unit z ↔ ∥z∥ = 1 := ⟨λ h, begin rcases is_unit_iff_dvd_one.1 h with ⟨w, eq⟩, refine le_antisymm (padic_norm_z.le_one _) _, have := mul_le_mul_of_nonneg_left (padic_norm_z.le_one w) (norm_nonneg z), rwa [mul_one, ← padic_norm_z.mul, ← eq, padic_norm_z.one] at this end, λ h, ⟨⟨z, z.inv, mul_inv h, inv_mul h⟩, rfl⟩⟩ lemma norm_lt_one_add {z1 z2 : ℤ_[p]} (hz1 : ∥z1∥ < 1) (hz2 : ∥z2∥ < 1) : ∥z1 + z2∥ < 1 := lt_of_le_of_lt (padic_norm_z.nonarchimedean _ _) (max_lt hz1 hz2) lemma norm_lt_one_mul {z1 z2 : ℤ_[p]} (hz2 : ∥z2∥ < 1) : ∥z1 * z2∥ < 1 := calc ∥z1 * z2∥ = ∥z1∥ * ∥z2∥ : by simp ... < 1 : mul_lt_one_of_le_of_lt (padic_norm_z.le_one _) (norm_nonneg _) hz2 @[simp] lemma mem_nonunits {z : ℤ_[p]} : z ∈ nonunits ℤ_[p] ↔ ∥z∥ < 1 := by rw lt_iff_le_and_ne; simp [padic_norm_z.le_one z, nonunits, is_unit_iff] instance : local_ring ℤ_[p] := local_of_nonunits_ideal zero_ne_one $ λ x y, by simp; exact norm_lt_one_add private def cau_seq_to_rat_cau_seq (f : cau_seq ℤ_[p] norm) : cau_seq ℚ_[p] (λ a, ∥a∥) := ⟨ λ n, f n, λ _ hε, by simpa [norm, padic_norm_z] using f.cauchy hε ⟩ instance complete : cau_seq.is_complete ℤ_[p] norm := ⟨ λ f, have hqn : ∥cau_seq.lim (cau_seq_to_rat_cau_seq f)∥ ≤ 1, from padic_norm_e_lim_le zero_lt_one (λ _, padic_norm_z.le_one _), ⟨ ⟨_, hqn⟩, λ ε, by simpa [norm, padic_norm_z] using cau_seq.equiv_lim (cau_seq_to_rat_cau_seq f) ε⟩⟩ /-- The coercion from ℤ[p] to ℚ[p] as a ring homomorphism. -/ def coe.ring_hom : ℤ_[p] →+* ℚ_[p] := { to_fun := (coe : ℤ_[p] → ℚ_[p]), map_zero' := rfl, map_one' := rfl, map_mul' := coe_mul, map_add' := coe_add } instance : algebra ℤ_[p] ℚ_[p] := (coe.ring_hom : ℤ_[p] →+* ℚ_[p]).to_algebra end padic_int namespace padic_norm_z variables {p : ℕ} [fact p.prime] lemma padic_val_of_cong_pow_p {z1 z2 : ℤ} {n : ℕ} (hz : z1 ≡ z2 [ZMOD ↑(p^n)]) : ∥(z1 - z2 : ℚ_[p])∥ ≤ ↑(↑p ^ (-n : ℤ) : ℚ) := have hdvd : ↑(p^n) ∣ z2 - z1, from int.modeq.modeq_iff_dvd.1 hz, have (z2 - z1 : ℚ_[p]) = ↑(↑(z2 - z1) : ℚ), by norm_cast, begin rw [norm_sub_rev, this, padic_norm_e.eq_padic_norm], exact_mod_cast padic_norm.le_of_dvd p hdvd end end padic_norm_z
5a11920a8fc88122a35238484aae0f86f457a2a0
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
/08_Building_Theories_and_Proofs.org.38.lean
29376c360592337a598c32a648c88acb516ff0d0
[]
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
116
lean
import standard import data.list open list local abbreviation induction_on := @list.induction_on check induction_on
bab00c7db5e70bf839006c3a571ad0e4219570a9
d0f9af2b0ace5ce352570d61b09019c8ef4a3b96
/notes/2020.02.25-higher_order.lean
bb78dae66cb6254e5cfdb6ecc219b42900148253
[]
no_license
jngo13/Discrete-Mathematics
8671540ef2da7c75915d32332dd20c02f001474e
bf674a866e61f60e6e6d128df85fa73819091787
refs/heads/master
1,675,615,657,924
1,609,142,011,000
1,609,142,011,000
267,190,341
0
0
null
null
null
null
UTF-8
Lean
false
false
988
lean
def apply {α β : Type} (f : α → β) (a : α) : β := f a #eval apply nat.succ 1 #eval apply nat.pred 1 #eval apply string.length "I love logic!" --type string to nat, α string and β nat /- Returns function as a result -/ def apply_twice {α : Type} (f : α → α): α → α := --takes a function and returns a function as a result λ a, f (f a) -- a function that takes an argument a --and returns f applied twice to a #reduce apply_twice nat.succ #reduce apply_twice nat.pred def double (n : ℕ) := 2*n #eval apply_twice nat.succ 3 -- application is left associative #eval apply_twice nat.pred 3 #eval (apply_twice double) 3 def square (n : ℕ) := n^2 def square_twice := apply_twice square def double_twice := apply_twice double #eval square_twice 5 --if you want to return a function you have to use a lamda expression /- That's composition of a function with itself, but we can also compose different functions. Here's a special case -/
6fb68e6e05c2a1c39ac7991d09e1453989da5e3d
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
/src/algebra/module/submodule.lean
7148ba1a2626af2f845f49ac6eb8a1b144c60428
[ "Apache-2.0" ]
permissive
waynemunro/mathlib
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
065a70810b5480d584033f7bbf8e0409480c2118
refs/heads/master
1,693,417,182,397
1,634,644,781,000
1,634,644,781,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
14,072
lean
/- Copyright (c) 2015 Nathaniel Thomas. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro -/ import algebra.module.linear_map import data.equiv.module import group_theory.group_action.sub_mul_action /-! # Submodules of a module In this file we define * `submodule R M` : a subset of a `module` `M` that contains zero and is closed with respect to addition and scalar multiplication. * `subspace k M` : an abbreviation for `submodule` assuming that `k` is a `field`. ## Tags submodule, subspace, linear map -/ open function open_locale big_operators universes u' u v w variables {S : Type u'} {R : Type u} {M : Type v} {ι : Type w} set_option old_structure_cmd true /-- A submodule of a module is one which is closed under vector operations. This is a sufficient condition for the subset of vectors in the submodule to themselves form a module. -/ structure submodule (R : Type u) (M : Type v) [semiring R] [add_comm_monoid M] [module R M] extends add_submonoid M, sub_mul_action R M : Type v. /-- Reinterpret a `submodule` as an `add_submonoid`. -/ add_decl_doc submodule.to_add_submonoid /-- Reinterpret a `submodule` as an `sub_mul_action`. -/ add_decl_doc submodule.to_sub_mul_action namespace submodule variables [semiring R] [add_comm_monoid M] [module R M] instance : set_like (submodule R M) M := ⟨submodule.carrier, λ p q h, by cases p; cases q; congr'⟩ @[simp] theorem mem_to_add_submonoid (p : submodule R M) (x : M) : x ∈ p.to_add_submonoid ↔ x ∈ p := iff.rfl variables {p q : submodule R M} @[simp] lemma mem_mk {S : set M} {x : M} (h₁ h₂ h₃) : x ∈ (⟨S, h₁, h₂, h₃⟩ : submodule R M) ↔ x ∈ S := iff.rfl @[simp] lemma coe_set_mk (S : set M) (h₁ h₂ h₃) : ((⟨S, h₁, h₂, h₃⟩ : submodule R M) : set M) = S := rfl @[simp] lemma mk_le_mk {S S' : set M} (h₁ h₂ h₃ h₁' h₂' h₃') : (⟨S, h₁, h₂, h₃⟩ : submodule R M) ≤ (⟨S', h₁', h₂', h₃'⟩ : submodule R M) ↔ S ⊆ S' := iff.rfl @[ext] theorem ext (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := set_like.ext h /-- Copy of a submodule with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (p : submodule R M) (s : set M) (hs : s = ↑p) : submodule R M := { carrier := s, zero_mem' := hs.symm ▸ p.zero_mem', add_mem' := hs.symm ▸ p.add_mem', smul_mem' := hs.symm ▸ p.smul_mem' } @[simp] lemma coe_copy (S : submodule R M) (s : set M) (hs : s = ↑S) : (S.copy s hs : set M) = s := rfl lemma copy_eq (S : submodule R M) (s : set M) (hs : s = ↑S) : S.copy s hs = S := set_like.coe_injective hs theorem to_add_submonoid_injective : injective (to_add_submonoid : submodule R M → add_submonoid M) := λ p q h, set_like.ext'_iff.2 (show _, from set_like.ext'_iff.1 h) @[simp] theorem to_add_submonoid_eq : p.to_add_submonoid = q.to_add_submonoid ↔ p = q := to_add_submonoid_injective.eq_iff @[mono] lemma to_add_submonoid_strict_mono : strict_mono (to_add_submonoid : submodule R M → add_submonoid M) := λ _ _, id @[mono] lemma to_add_submonoid_mono : monotone (to_add_submonoid : submodule R M → add_submonoid M) := to_add_submonoid_strict_mono.monotone @[simp] theorem coe_to_add_submonoid (p : submodule R M) : (p.to_add_submonoid : set M) = p := rfl theorem to_sub_mul_action_injective : injective (to_sub_mul_action : submodule R M → sub_mul_action R M) := λ p q h, set_like.ext'_iff.2 (show _, from set_like.ext'_iff.1 h) @[simp] theorem to_sub_mul_action_eq : p.to_sub_mul_action = q.to_sub_mul_action ↔ p = q := to_sub_mul_action_injective.eq_iff @[mono] lemma to_sub_mul_action_strict_mono : strict_mono (to_sub_mul_action : submodule R M → sub_mul_action R M) := λ _ _, id @[mono] lemma to_sub_mul_action_mono : monotone (to_sub_mul_action : submodule R M → sub_mul_action R M) := to_sub_mul_action_strict_mono.monotone @[simp] theorem coe_to_sub_mul_action (p : submodule R M) : (p.to_sub_mul_action : set M) = p := rfl end submodule namespace submodule section add_comm_monoid variables [semiring S] [semiring R] [add_comm_monoid M] -- We can infer the module structure implicitly from the bundled submodule, -- rather than via typeclass resolution. variables {module_M : module R M} variables {p q : submodule R M} variables {r : R} {x y : M} variables [has_scalar S R] [module S M] [is_scalar_tower S R M] variables (p) @[simp] lemma mem_carrier : x ∈ p.carrier ↔ x ∈ (p : set M) := iff.rfl @[simp] lemma zero_mem : (0 : M) ∈ p := p.zero_mem' lemma add_mem (h₁ : x ∈ p) (h₂ : y ∈ p) : x + y ∈ p := p.add_mem' h₁ h₂ lemma smul_mem (r : R) (h : x ∈ p) : r • x ∈ p := p.smul_mem' r h lemma smul_of_tower_mem (r : S) (h : x ∈ p) : r • x ∈ p := p.to_sub_mul_action.smul_of_tower_mem r h lemma sum_mem {t : finset ι} {f : ι → M} : (∀c∈t, f c ∈ p) → (∑ i in t, f i) ∈ p := p.to_add_submonoid.sum_mem lemma sum_smul_mem {t : finset ι} {f : ι → M} (r : ι → R) (hyp : ∀ c ∈ t, f c ∈ p) : (∑ i in t, r i • f i) ∈ p := submodule.sum_mem _ (λ i hi, submodule.smul_mem _ _ (hyp i hi)) @[simp] lemma smul_mem_iff' (u : units S) : (u:S) • x ∈ p ↔ x ∈ p := p.to_sub_mul_action.smul_mem_iff' u instance : has_add p := ⟨λx y, ⟨x.1 + y.1, add_mem _ x.2 y.2⟩⟩ instance : has_zero p := ⟨⟨0, zero_mem _⟩⟩ instance : inhabited p := ⟨0⟩ instance : has_scalar S p := ⟨λ c x, ⟨c • x.1, smul_of_tower_mem _ c x.2⟩⟩ protected lemma nonempty : (p : set M).nonempty := ⟨0, p.zero_mem⟩ @[simp] lemma mk_eq_zero {x} (h : x ∈ p) : (⟨x, h⟩ : p) = 0 ↔ x = 0 := subtype.ext_iff_val variables {p} @[simp, norm_cast] lemma coe_eq_zero {x : p} : (x : M) = 0 ↔ x = 0 := (set_like.coe_eq_coe : (x : M) = (0 : p) ↔ x = 0) @[simp, norm_cast] lemma coe_add (x y : p) : (↑(x + y) : M) = ↑x + ↑y := rfl @[simp, norm_cast] lemma coe_zero : ((0 : p) : M) = 0 := rfl @[norm_cast] lemma coe_smul (r : R) (x : p) : ((r • x : p) : M) = r • ↑x := rfl @[simp, norm_cast] lemma coe_smul_of_tower (r : S) (x : p) : ((r • x : p) : M) = r • ↑x := rfl @[simp, norm_cast] lemma coe_mk (x : M) (hx : x ∈ p) : ((⟨x, hx⟩ : p) : M) = x := rfl @[simp] lemma coe_mem (x : p) : (x : M) ∈ p := x.2 variables (p) instance : add_comm_monoid p := { add := (+), zero := 0, .. p.to_add_submonoid.to_add_comm_monoid } instance module' : module S p := by refine {smul := (•), ..p.to_sub_mul_action.mul_action', ..}; { intros, apply set_coe.ext, simp [smul_add, add_smul, mul_smul] } instance : module R p := p.module' instance : is_scalar_tower S R p := p.to_sub_mul_action.is_scalar_tower instance no_zero_smul_divisors [no_zero_smul_divisors R M] : no_zero_smul_divisors R p := ⟨λ c x h, have c = 0 ∨ (x : M) = 0, from eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg coe h), this.imp_right (@subtype.ext_iff _ _ x 0).mpr⟩ /-- Embedding of a submodule `p` to the ambient space `M`. -/ protected def subtype : p →ₗ[R] M := by refine {to_fun := coe, ..}; simp [coe_smul] @[simp] theorem subtype_apply (x : p) : p.subtype x = x := rfl lemma subtype_eq_val : ((submodule.subtype p) : p → M) = subtype.val := rfl /-- Note the `add_submonoid` version of this lemma is called `add_submonoid.coe_finset_sum`. -/ @[simp] lemma coe_sum (x : ι → p) (s : finset ι) : ↑(∑ i in s, x i) = ∑ i in s, (x i : M) := p.subtype.map_sum section restrict_scalars variables (S) [module R M] [is_scalar_tower S R M] /-- `V.restrict_scalars S` is the `S`-submodule of the `S`-module given by restriction of scalars, corresponding to `V`, an `R`-submodule of the original `R`-module. -/ @[simps] def restrict_scalars (V : submodule R M) : submodule S M := { carrier := V.carrier, zero_mem' := V.zero_mem, smul_mem' := λ c m h, V.smul_of_tower_mem c h, add_mem' := λ x y hx hy, V.add_mem hx hy } @[simp] lemma restrict_scalars_mem (V : submodule R M) (m : M) : m ∈ V.restrict_scalars S ↔ m ∈ V := iff.refl _ variables (R S M) lemma restrict_scalars_injective : function.injective (restrict_scalars S : submodule R M → submodule S M) := λ V₁ V₂ h, ext $ by convert set.ext_iff.1 (set_like.ext'_iff.1 h); refl @[simp] lemma restrict_scalars_inj {V₁ V₂ : submodule R M} : restrict_scalars S V₁ = restrict_scalars S V₂ ↔ V₁ = V₂ := (restrict_scalars_injective S _ _).eq_iff /-- Even though `p.restrict_scalars S` has type `submodule S M`, it is still an `R`-module. -/ instance restrict_scalars.orig_module (p : submodule R M) : module R (p.restrict_scalars S) := (by apply_instance : module R p) instance (p : submodule R M) : is_scalar_tower S R (p.restrict_scalars S) := { smul_assoc := λ r s x, subtype.ext $ smul_assoc r s (x : M) } /-- `restrict_scalars S` is an embedding of the lattice of `R`-submodules into the lattice of `S`-submodules. -/ @[simps] def restrict_scalars_embedding : submodule R M ↪o submodule S M := { to_fun := restrict_scalars S, inj' := restrict_scalars_injective S R M, map_rel_iff' := λ p q, by simp [set_like.le_def] } /-- Turning `p : submodule R M` into an `S`-submodule gives the same module structure as turning it into a type and adding a module structure. -/ @[simps {simp_rhs := tt}] def restrict_scalars_equiv (p : submodule R M) : p.restrict_scalars S ≃ₗ[R] p := { to_fun := id, inv_fun := id, map_smul' := λ c x, rfl, .. add_equiv.refl p } end restrict_scalars end add_comm_monoid section add_comm_group variables [ring R] [add_comm_group M] variables {module_M : module R M} variables (p p' : submodule R M) variables {r : R} {x y : M} lemma neg_mem (hx : x ∈ p) : -x ∈ p := p.to_sub_mul_action.neg_mem hx /-- Reinterpret a submodule as an additive subgroup. -/ def to_add_subgroup : add_subgroup M := { neg_mem' := λ _, p.neg_mem , .. p.to_add_submonoid } @[simp] lemma coe_to_add_subgroup : (p.to_add_subgroup : set M) = p := rfl @[simp] lemma mem_to_add_subgroup : x ∈ p.to_add_subgroup ↔ x ∈ p := iff.rfl include module_M theorem to_add_subgroup_injective : injective (to_add_subgroup : submodule R M → add_subgroup M) | p q h := set_like.ext (set_like.ext_iff.1 h : _) @[simp] theorem to_add_subgroup_eq : p.to_add_subgroup = p'.to_add_subgroup ↔ p = p' := to_add_subgroup_injective.eq_iff @[mono] lemma to_add_subgroup_strict_mono : strict_mono (to_add_subgroup : submodule R M → add_subgroup M) := λ _ _, id @[mono] lemma to_add_subgroup_mono : monotone (to_add_subgroup : submodule R M → add_subgroup M) := to_add_subgroup_strict_mono.monotone omit module_M lemma sub_mem : x ∈ p → y ∈ p → x - y ∈ p := p.to_add_subgroup.sub_mem @[simp] lemma neg_mem_iff : -x ∈ p ↔ x ∈ p := p.to_add_subgroup.neg_mem_iff lemma add_mem_iff_left : y ∈ p → (x + y ∈ p ↔ x ∈ p) := p.to_add_subgroup.add_mem_cancel_right lemma add_mem_iff_right : x ∈ p → (x + y ∈ p ↔ y ∈ p) := p.to_add_subgroup.add_mem_cancel_left instance : has_neg p := ⟨λx, ⟨-x.1, neg_mem _ x.2⟩⟩ @[simp, norm_cast] lemma coe_neg (x : p) : ((-x : p) : M) = -x := rfl instance : add_comm_group p := { add := (+), zero := 0, neg := has_neg.neg, ..p.to_add_subgroup.to_add_comm_group } @[simp, norm_cast] lemma coe_sub (x y : p) : (↑(x - y) : M) = ↑x - ↑y := rfl end add_comm_group section ordered_monoid variables [semiring R] /-- A submodule of an `ordered_add_comm_monoid` is an `ordered_add_comm_monoid`. -/ instance to_ordered_add_comm_monoid {M} [ordered_add_comm_monoid M] [module R M] (S : submodule R M) : ordered_add_comm_monoid S := subtype.coe_injective.ordered_add_comm_monoid coe rfl (λ _ _, rfl) /-- A submodule of a `linear_ordered_add_comm_monoid` is a `linear_ordered_add_comm_monoid`. -/ instance to_linear_ordered_add_comm_monoid {M} [linear_ordered_add_comm_monoid M] [module R M] (S : submodule R M) : linear_ordered_add_comm_monoid S := subtype.coe_injective.linear_ordered_add_comm_monoid coe rfl (λ _ _, rfl) /-- A submodule of an `ordered_cancel_add_comm_monoid` is an `ordered_cancel_add_comm_monoid`. -/ instance to_ordered_cancel_add_comm_monoid {M} [ordered_cancel_add_comm_monoid M] [module R M] (S : submodule R M) : ordered_cancel_add_comm_monoid S := subtype.coe_injective.ordered_cancel_add_comm_monoid coe rfl (λ _ _, rfl) /-- A submodule of a `linear_ordered_cancel_add_comm_monoid` is a `linear_ordered_cancel_add_comm_monoid`. -/ instance to_linear_ordered_cancel_add_comm_monoid {M} [linear_ordered_cancel_add_comm_monoid M] [module R M] (S : submodule R M) : linear_ordered_cancel_add_comm_monoid S := subtype.coe_injective.linear_ordered_cancel_add_comm_monoid coe rfl (λ _ _, rfl) end ordered_monoid section ordered_group variables [ring R] /-- A submodule of an `ordered_add_comm_group` is an `ordered_add_comm_group`. -/ instance to_ordered_add_comm_group {M} [ordered_add_comm_group M] [module R M] (S : submodule R M) : ordered_add_comm_group S := subtype.coe_injective.ordered_add_comm_group coe rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) /-- A submodule of a `linear_ordered_add_comm_group` is a `linear_ordered_add_comm_group`. -/ instance to_linear_ordered_add_comm_group {M} [linear_ordered_add_comm_group M] [module R M] (S : submodule R M) : linear_ordered_add_comm_group S := subtype.coe_injective.linear_ordered_add_comm_group coe rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) end ordered_group end submodule namespace submodule variables [division_ring S] [semiring R] [add_comm_monoid M] [module R M] variables [has_scalar S R] [module S M] [is_scalar_tower S R M] variables (p : submodule R M) {s : S} {x y : M} theorem smul_mem_iff (s0 : s ≠ 0) : s • x ∈ p ↔ x ∈ p := p.to_sub_mul_action.smul_mem_iff s0 end submodule /-- Subspace of a vector space. Defined to equal `submodule`. -/ abbreviation subspace (R : Type u) (M : Type v) [field R] [add_comm_group M] [module R M] := submodule R M
c1e2474b77ea3b86fed7efb34c572d79e64db902
649957717d58c43b5d8d200da34bf374293fe739
/src/topology/Top/stalks.lean
7ddaaf8dbe1e417084ffb42899e5807e7c11ef4a
[ "Apache-2.0" ]
permissive
Vtec234/mathlib
b50c7b21edea438df7497e5ed6a45f61527f0370
fb1848bbbfce46152f58e219dc0712f3289d2b20
refs/heads/master
1,592,463,095,113
1,562,737,749,000
1,562,737,749,000
196,202,858
0
0
Apache-2.0
1,562,762,338,000
1,562,762,337,000
null
UTF-8
Lean
false
false
3,569
lean
-- Copyright (c) 2019 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Scott Morrison import topology.Top.open_nhds import topology.Top.presheaf import category_theory.limits.limits universes v u v' u' open category_theory open Top open category_theory.limits open topological_space variables {C : Type u} [𝒞 : category.{v+1} C] include 𝒞 variables [has_colimits.{v} C] variables {X Y Z : Top.{v}} namespace Top.presheaf variables (C) /-- Stalks are functorial with respect to morphisms of presheaves over a fixed `X`. -/ def stalk_functor (x : X) : X.presheaf C ⥤ C := ((whiskering_left _ _ C).obj (open_nhds.inclusion x).op) ⋙ colim variables {C} /-- The stalk of a presheaf `F` at a point `x` is calculated as the colimit of the functor nbhds x ⥤ opens F.X ⥤ C -/ def stalk (ℱ : X.presheaf C) (x : X) : C := (stalk_functor C x).obj ℱ -- -- colimit (nbhds_inclusion x ⋙ ℱ) @[simp] lemma stalk_functor_obj (ℱ : X.presheaf C) (x : X) : (stalk_functor C x).obj ℱ = ℱ.stalk x := rfl variables (C) def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := begin -- This is a hack; Lean doesn't like to elaborate the term written directly. transitivity, swap, exact colimit.pre _ (open_nhds.map f x).op, exact colim.map (whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ), end -- Here are two other potential solutions, suggested by @fpvandoorn at -- https://github.com/leanprover-community/mathlib/pull/1018#discussion_r283978240 -- However, I can't get the subsequent two proofs to work with either one. -- def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- colim.map ((functor.associator _ _ _).inv ≫ -- whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ) ≫ -- colimit.pre ((open_nhds.inclusion x).op ⋙ ℱ) (open_nhds.map f x).op -- def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- (colim.map (whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ) : -- colim.obj ((open_nhds.inclusion (f x) ⋙ opens.map f).op ⋙ ℱ) ⟶ _) ≫ -- colimit.pre ((open_nhds.inclusion x).op ⋙ ℱ) (open_nhds.map f x).op namespace stalk_pushforward local attribute [tidy] tactic.op_induction' @[simp] lemma id (ℱ : X.presheaf C) (x : X) : ℱ.stalk_pushforward C (𝟙 X) x = (stalk_functor C x).map ((pushforward.id ℱ).hom) := begin dsimp [stalk_pushforward, stalk_functor], ext1, tactic.op_induction', cases j, cases j_val, rw [colim.ι_map_assoc, colim.ι_map, colimit.ι_pre, whisker_left.app, whisker_right.app, pushforward.id_hom_app, eq_to_hom_map, eq_to_hom_refl], dsimp, rw [category_theory.functor.map_id] end @[simp] lemma comp (ℱ : X.presheaf C) (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : ℱ.stalk_pushforward C (f ≫ g) x = ((f _* ℱ).stalk_pushforward C g (f x)) ≫ (ℱ.stalk_pushforward C f x) := begin dsimp [stalk_pushforward, stalk_functor, pushforward], ext U, op_induction U, cases U, cases U_val, simp only [colim.ι_map_assoc, colimit.ι_pre_assoc, colimit.ι_pre, whisker_right.app, category.assoc], dsimp, simp only [category.id_comp, category_theory.functor.map_id], -- FIXME A simp lemma which unfortunately doesn't fire: rw [category_theory.functor.map_id], dsimp, simp, end end stalk_pushforward end Top.presheaf
af05a13f73576a011d9cf410752d91c667e97aa2
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/init/data/nat/gcd.lean
ffdb6a935e81022f311e263e4a450758409d957d
[]
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,255
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro Definitions and properties of gcd, lcm, and coprime. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.data.nat.lemmas import Mathlib.Lean3Lib.init.meta.well_founded_tactics namespace Mathlib namespace nat /- gcd -/ def gcd : ℕ → ℕ → ℕ := sorry @[simp] theorem gcd_zero_left (x : ℕ) : gcd 0 x = x := sorry @[simp] theorem gcd_succ (x : ℕ) (y : ℕ) : gcd (Nat.succ x) y = gcd (y % Nat.succ x) (Nat.succ x) := sorry @[simp] theorem gcd_one_left (n : ℕ) : gcd 1 n = 1 := sorry theorem gcd_def (x : ℕ) (y : ℕ) : gcd x y = ite (x = 0) y (gcd (y % x) x) := sorry @[simp] theorem gcd_self (n : ℕ) : gcd n n = n := sorry @[simp] theorem gcd_zero_right (n : ℕ) : gcd n 0 = n := sorry theorem gcd_rec (m : ℕ) (n : ℕ) : gcd m n = gcd (n % m) m := sorry theorem gcd.induction {P : ℕ → ℕ → Prop} (m : ℕ) (n : ℕ) (H0 : ∀ (n : ℕ), P 0 n) (H1 : ∀ (m n : ℕ), 0 < m → P (n % m) m → P m n) : P m n := sorry def lcm (m : ℕ) (n : ℕ) : ℕ := m * n / gcd m n def coprime (m : ℕ) (n : ℕ) := gcd m n = 1
843a50bf17bc6dc74b3e1315df074f10890dd6b2
c777c32c8e484e195053731103c5e52af26a25d1
/src/data/is_R_or_C/lemmas.lean
f4685686068ff0d625c8bece2a1f2226bd4167eb
[ "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
2,617
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 analysis.normed_space.finite_dimension import field_theory.tower import data.is_R_or_C.basic /-! # Further lemmas about `is_R_or_C` -/ variables {K E : Type*} [is_R_or_C K] namespace polynomial open_locale polynomial lemma of_real_eval (p : ℝ[X]) (x : ℝ) : (p.eval x : K) = aeval ↑x p := (@aeval_algebra_map_apply_eq_algebra_map_eval ℝ K _ _ _ x p).symm end polynomial namespace finite_dimensional open_locale classical open is_R_or_C /-- This instance generates a type-class problem with a metavariable `?m` that should satisfy `is_R_or_C ?m`. Since this can only be satisfied by `ℝ` or `ℂ`, this does not cause problems. -/ library_note "is_R_or_C instance" /-- An `is_R_or_C` field is finite-dimensional over `ℝ`, since it is spanned by `{1, I}`. -/ @[nolint dangerous_instance] instance is_R_or_C_to_real : finite_dimensional ℝ K := ⟨⟨{1, I}, begin rw eq_top_iff, intros a _, rw [finset.coe_insert, finset.coe_singleton, submodule.mem_span_insert], refine ⟨re a, (im a) • I, _, _⟩, { rw submodule.mem_span_singleton, use im a }, simp [re_add_im a, algebra.smul_def, algebra_map_eq_of_real] end⟩⟩ variables (K E) [normed_add_comm_group E] [normed_space K E] /-- A finite dimensional vector space over an `is_R_or_C` is a proper metric space. This is not an instance because it would cause a search for `finite_dimensional ?x E` before `is_R_or_C ?x`. -/ lemma proper_is_R_or_C [finite_dimensional K E] : proper_space E := begin letI : normed_space ℝ E := restrict_scalars.normed_space ℝ K E, letI : finite_dimensional ℝ E := finite_dimensional.trans ℝ K E, apply_instance end variable {E} instance is_R_or_C.proper_space_submodule (S : submodule K E) [finite_dimensional K ↥S] : proper_space S := proper_is_R_or_C K S end finite_dimensional namespace is_R_or_C @[simp, is_R_or_C_simps] lemma re_clm_norm : ‖(re_clm : K →L[ℝ] ℝ)‖ = 1 := begin apply le_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _), convert continuous_linear_map.ratio_le_op_norm _ (1 : K), { simp }, { apply_instance } end @[simp, is_R_or_C_simps] lemma conj_cle_norm : ‖(@conj_cle K _ : K →L[ℝ] K)‖ = 1 := (@conj_lie K _).to_linear_isometry.norm_to_continuous_linear_map @[simp, is_R_or_C_simps] lemma of_real_clm_norm : ‖(of_real_clm : ℝ →L[ℝ] K)‖ = 1 := linear_isometry.norm_to_continuous_linear_map of_real_li end is_R_or_C
b1c399a783178ef4027024281d5ac23686573575
947fa6c38e48771ae886239b4edce6db6e18d0fb
/src/data/set/intervals/unordered_interval.lean
ed25f4e8ecb7d10d84ed38e2637de4c7019cdab2
[ "Apache-2.0" ]
permissive
ramonfmir/mathlib
c5dc8b33155473fab97c38bd3aa6723dc289beaa
14c52e990c17f5a00c0cc9e09847af16fabbed25
refs/heads/master
1,661,979,343,526
1,660,830,384,000
1,660,830,384,000
182,072,989
0
0
null
1,555,585,876,000
1,555,585,876,000
null
UTF-8
Lean
false
false
10,196
lean
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import order.bounds import data.set.intervals.image_preimage /-! # Intervals without endpoints ordering In any decidable linear order `α`, we define the set of elements lying between two elements `a` and `b` as `Icc (min a b) (max a b)`. `Icc a b` requires the assumption `a ≤ b` to be meaningful, which is sometimes inconvenient. The interval as defined in this file is always the set of things lying between `a` and `b`, regardless of the relative order of `a` and `b`. For real numbers, `Icc (min a b) (max a b)` is the same as `segment ℝ a b`. ## Notation We use the localized notation `[a, b]` for `interval a b`. One can open the locale `interval` to make the notation available. -/ universe u open_locale pointwise namespace set section linear_order variables {α : Type u} [linear_order α] {a a₁ a₂ b b₁ b₂ c x : α} /-- `interval a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. -/ def interval (a b : α) := Icc (min a b) (max a b) localized "notation `[`a `, ` b `]` := set.interval a b" in interval @[simp] lemma interval_of_le (h : a ≤ b) : [a, b] = Icc a b := by rw [interval, min_eq_left h, max_eq_right h] @[simp] lemma interval_of_ge (h : b ≤ a) : [a, b] = Icc b a := by { rw [interval, min_eq_right h, max_eq_left h] } lemma interval_swap (a b : α) : [a, b] = [b, a] := by rw [interval, interval, min_comm, max_comm] lemma interval_of_lt (h : a < b) : [a, b] = Icc a b := interval_of_le (le_of_lt h) lemma interval_of_gt (h : b < a) : [a, b] = Icc b a := interval_of_ge (le_of_lt h) lemma interval_of_not_le (h : ¬ a ≤ b) : [a, b] = Icc b a := interval_of_gt (lt_of_not_ge h) lemma interval_of_not_ge (h : ¬ b ≤ a) : [a, b] = Icc a b := interval_of_lt (lt_of_not_ge h) @[simp] lemma interval_self : [a, a] = {a} := set.ext $ by simp [le_antisymm_iff, and_comm] @[simp] lemma nonempty_interval : set.nonempty [a, b] := by { simp only [interval, min_le_iff, le_max_iff, nonempty_Icc], left, left, refl } @[simp] lemma left_mem_interval : a ∈ [a, b] := by { rw [interval, mem_Icc], exact ⟨min_le_left _ _, le_max_left _ _⟩ } @[simp] lemma right_mem_interval : b ∈ [a, b] := by { rw interval_swap, exact left_mem_interval } lemma Icc_subset_interval : Icc a b ⊆ [a, b] := Icc_subset_Icc (min_le_left _ _) (le_max_right _ _) lemma Icc_subset_interval' : Icc b a ⊆ [a, b] := by { rw interval_swap, apply Icc_subset_interval } lemma mem_interval_of_le (ha : a ≤ x) (hb : x ≤ b) : x ∈ [a, b] := Icc_subset_interval ⟨ha, hb⟩ lemma mem_interval_of_ge (hb : b ≤ x) (ha : x ≤ a) : x ∈ [a, b] := Icc_subset_interval' ⟨hb, ha⟩ lemma not_mem_interval_of_lt (ha : c < a) (hb : c < b) : c ∉ interval a b := not_mem_Icc_of_lt $ lt_min_iff.mpr ⟨ha, hb⟩ lemma not_mem_interval_of_gt (ha : a < c) (hb : b < c) : c ∉ interval a b := not_mem_Icc_of_gt $ max_lt_iff.mpr ⟨ha, hb⟩ lemma interval_subset_interval (h₁ : a₁ ∈ [a₂, b₂]) (h₂ : b₁ ∈ [a₂, b₂]) : [a₁, b₁] ⊆ [a₂, b₂] := Icc_subset_Icc (le_min h₁.1 h₂.1) (max_le h₁.2 h₂.2) lemma interval_subset_Icc (ha : a₁ ∈ Icc a₂ b₂) (hb : b₁ ∈ Icc a₂ b₂) : [a₁, b₁] ⊆ Icc a₂ b₂ := Icc_subset_Icc (le_min ha.1 hb.1) (max_le ha.2 hb.2) lemma interval_subset_interval_iff_mem : [a₁, b₁] ⊆ [a₂, b₂] ↔ a₁ ∈ [a₂, b₂] ∧ b₁ ∈ [a₂, b₂] := iff.intro (λh, ⟨h left_mem_interval, h right_mem_interval⟩) (λ h, interval_subset_interval h.1 h.2) lemma interval_subset_interval_iff_le : [a₁, b₁] ⊆ [a₂, b₂] ↔ min a₂ b₂ ≤ min a₁ b₁ ∧ max a₁ b₁ ≤ max a₂ b₂ := by { rw [interval, interval, Icc_subset_Icc_iff], exact min_le_max } lemma interval_subset_interval_right (h : x ∈ [a, b]) : [x, b] ⊆ [a, b] := interval_subset_interval h right_mem_interval lemma interval_subset_interval_left (h : x ∈ [a, b]) : [a, x] ⊆ [a, b] := interval_subset_interval left_mem_interval h /-- A sort of triangle inequality. -/ lemma interval_subset_interval_union_interval : [a, c] ⊆ [a, b] ∪ [b, c] := begin rintro x hx, obtain hac | hac := le_total a c, { rw interval_of_le hac at hx, obtain hb | hb := le_total x b, { exact or.inl (mem_interval_of_le hx.1 hb) }, { exact or.inr (mem_interval_of_le hb hx.2) } }, { rw interval_of_ge hac at hx, obtain hb | hb := le_total x b, { exact or.inr (mem_interval_of_ge hx.1 hb) }, { exact or.inl (mem_interval_of_ge hb hx.2) } } end lemma bdd_below_bdd_above_iff_subset_interval (s : set α) : bdd_below s ∧ bdd_above s ↔ ∃ a b, s ⊆ [a, b] := begin rw [bdd_below_bdd_above_iff_subset_Icc], split, { rintro ⟨a, b, h⟩, exact ⟨a, b, λ x hx, Icc_subset_interval (h hx)⟩ }, { rintro ⟨a, b, h⟩, exact ⟨min a b, max a b, h⟩ } end /-- The open-closed interval with unordered bounds. -/ def interval_oc : α → α → set α := λ a b, Ioc (min a b) (max a b) -- Below is a capital iota localized "notation `Ι` := set.interval_oc" in interval lemma interval_oc_of_le (h : a ≤ b) : Ι a b = Ioc a b := by simp [interval_oc, h] lemma interval_oc_of_lt (h : b < a) : Ι a b = Ioc b a := by simp [interval_oc, le_of_lt h] lemma interval_oc_eq_union : Ι a b = Ioc a b ∪ Ioc b a := by cases le_total a b; simp [interval_oc, *] lemma forall_interval_oc_iff {P : α → Prop} : (∀ x ∈ Ι a b, P x) ↔ (∀ x ∈ Ioc a b, P x) ∧ (∀ x ∈ Ioc b a, P x) := by simp only [interval_oc_eq_union, mem_union_eq, or_imp_distrib, forall_and_distrib] lemma interval_oc_subset_interval_oc_of_interval_subset_interval {a b c d : α} (h : [a, b] ⊆ [c, d]) : Ι a b ⊆ Ι c d := Ioc_subset_Ioc (interval_subset_interval_iff_le.1 h).1 (interval_subset_interval_iff_le.1 h).2 lemma interval_oc_swap (a b : α) : Ι a b = Ι b a := by simp only [interval_oc, min_comm a b, max_comm a b] lemma Ioc_subset_interval_oc : Ioc a b ⊆ Ι a b := Ioc_subset_Ioc (min_le_left _ _) (le_max_right _ _) lemma Ioc_subset_interval_oc' : Ioc a b ⊆ Ι b a := Ioc_subset_Ioc (min_le_right _ _) (le_max_left _ _) end linear_order open_locale interval section ordered_add_comm_group variables {α : Type u} [linear_ordered_add_comm_group α] (a b c x y : α) @[simp] lemma preimage_const_add_interval : (λ x, a + x) ⁻¹' [b, c] = [b - a, c - a] := by simp only [interval, preimage_const_add_Icc, min_sub_sub_right, max_sub_sub_right] @[simp] lemma preimage_add_const_interval : (λ x, x + a) ⁻¹' [b, c] = [b - a, c - a] := by simpa only [add_comm] using preimage_const_add_interval a b c @[simp] lemma preimage_neg_interval : - [a, b] = [-a, -b] := by simp only [interval, preimage_neg_Icc, min_neg_neg, max_neg_neg] @[simp] lemma preimage_sub_const_interval : (λ x, x - a) ⁻¹' [b, c] = [b + a, c + a] := by simp [sub_eq_add_neg] @[simp] lemma preimage_const_sub_interval : (λ x, a - x) ⁻¹' [b, c] = [a - b, a - c] := by { rw [interval, interval, preimage_const_sub_Icc], simp only [sub_eq_add_neg, min_add_add_left, max_add_add_left, min_neg_neg, max_neg_neg], } @[simp] lemma image_const_add_interval : (λ x, a + x) '' [b, c] = [a + b, a + c] := by simp [add_comm] @[simp] lemma image_add_const_interval : (λ x, x + a) '' [b, c] = [b + a, c + a] := by simp @[simp] lemma image_const_sub_interval : (λ x, a - x) '' [b, c] = [a - b, a - c] := by simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)] @[simp] lemma image_sub_const_interval : (λ x, x - a) '' [b, c] = [b - a, c - a] := by simp [sub_eq_add_neg, add_comm] lemma image_neg_interval : has_neg.neg '' [a, b] = [-a, -b] := by simp variables {a b c x y} /-- If `[x, y]` is a subinterval of `[a, b]`, then the distance between `x` and `y` is less than or equal to that of `a` and `b` -/ lemma abs_sub_le_of_subinterval (h : [x, y] ⊆ [a, b]) : |y - x| ≤ |b - a| := begin rw [← max_sub_min_eq_abs, ← max_sub_min_eq_abs], rw [interval_subset_interval_iff_le] at h, exact sub_le_sub h.2 h.1, end /-- If `x ∈ [a, b]`, then the distance between `a` and `x` is less than or equal to that of `a` and `b` -/ lemma abs_sub_left_of_mem_interval (h : x ∈ [a, b]) : |x - a| ≤ |b - a| := abs_sub_le_of_subinterval (interval_subset_interval_left h) /-- If `x ∈ [a, b]`, then the distance between `x` and `b` is less than or equal to that of `a` and `b` -/ lemma abs_sub_right_of_mem_interval (h : x ∈ [a, b]) : |b - x| ≤ |b - a| := abs_sub_le_of_subinterval (interval_subset_interval_right h) end ordered_add_comm_group section linear_ordered_field variables {k : Type u} [linear_ordered_field k] {a : k} @[simp] lemma preimage_mul_const_interval (ha : a ≠ 0) (b c : k) : (λ x, x * a) ⁻¹' [b, c] = [b / a, c / a] := (lt_or_gt_of_ne ha).elim (λ ha, by simp [interval, ha, ha.le, min_div_div_right_of_nonpos, max_div_div_right_of_nonpos]) (λ (ha : 0 < a), by simp [interval, ha, ha.le, min_div_div_right, max_div_div_right]) @[simp] lemma preimage_const_mul_interval (ha : a ≠ 0) (b c : k) : (λ x, a * x) ⁻¹' [b, c] = [b / a, c / a] := by simp only [← preimage_mul_const_interval ha, mul_comm] @[simp] lemma preimage_div_const_interval (ha : a ≠ 0) (b c : k) : (λ x, x / a) ⁻¹' [b, c] = [b * a, c * a] := by simp only [div_eq_mul_inv, preimage_mul_const_interval (inv_ne_zero ha), inv_inv] @[simp] lemma image_mul_const_interval (a b c : k) : (λ x, x * a) '' [b, c] = [b * a, c * a] := if ha : a = 0 then by simp [ha] else calc (λ x, x * a) '' [b, c] = (λ x, x * a⁻¹) ⁻¹' [b, c] : (units.mk0 a ha).mul_right.image_eq_preimage _ ... = (λ x, x / a) ⁻¹' [b, c] : by simp only [div_eq_mul_inv] ... = [b * a, c * a] : preimage_div_const_interval ha _ _ @[simp] lemma image_const_mul_interval (a b c : k) : (λ x, a * x) '' [b, c] = [a * b, a * c] := by simpa only [mul_comm] using image_mul_const_interval a b c @[simp] lemma image_div_const_interval (a b c : k) : (λ x, x / a) '' [b, c] = [b / a, c / a] := by simp only [div_eq_mul_inv, image_mul_const_interval] end linear_ordered_field end set
a8ebf3bbf08abedf70b5da5897092f82deae47dc
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/algebra/direct_sum/ring.lean
94ebf29cfd92d975199b812daa64ff697716d939
[ "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
17,915
lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import algebra.algebra.basic import algebra.algebra.operations import algebra.direct_sum.basic import group_theory.subgroup.basic import algebra.graded_monoid /-! # Additively-graded multiplicative structures on `⨁ i, A i` This module provides a set of heterogeneous typeclasses for defining a multiplicative structure over `⨁ i, A i` such that `(*) : A i → A j → A (i + j)`; that is to say, `A` forms an additively-graded ring. The typeclasses are: * `direct_sum.gnon_unital_non_assoc_semiring A` * `direct_sum.gsemiring A` * `direct_sum.gcomm_semiring A` Respectively, these imbue the external direct sum `⨁ i, A i` with: * `direct_sum.non_unital_non_assoc_semiring` * `direct_sum.semiring`, `direct_sum.ring` * `direct_sum.comm_semiring`, `direct_sum.comm_ring` the base ring `A 0` with: * `direct_sum.grade_zero.non_unital_non_assoc_semiring` * `direct_sum.grade_zero.semiring`, `direct_sum.grade_zero.ring` * `direct_sum.grade_zero.comm_semiring`, `direct_sum.grade_zero.comm_ring` and the `i`th grade `A i` with `A 0`-actions (`•`) defined as left-multiplication: * `direct_sum.grade_zero.has_scalar (A 0)`, `direct_sum.grade_zero.smul_with_zero (A 0)` * `direct_sum.grade_zero.module (A 0)` * (nothing) Note that in the presence of these instances, `⨁ i, A i` itself inherits an `A 0`-action. `direct_sum.of_zero_ring_hom : A 0 →+* ⨁ i, A i` provides `direct_sum.of A 0` as a ring homomorphism. `direct_sum.to_semiring` extends `direct_sum.to_add_monoid` to produce a `ring_hom`. ## Direct sums of subobjects Additionally, this module provides helper functions to construct `gsemiring` and `gcomm_semiring` instances for: * `A : ι → submonoid S`: `direct_sum.gsemiring.of_add_submonoids`, `direct_sum.gcomm_semiring.of_add_submonoids`. * `A : ι → subgroup S`: `direct_sum.gsemiring.of_add_subgroups`, `direct_sum.gcomm_semiring.of_add_subgroups`. * `A : ι → submodule S`: `direct_sum.gsemiring.of_submodules`, `direct_sum.gcomm_semiring.of_submodules`. If `complete_lattice.independent (set.range A)`, these provide a gradation of `⨆ i, A i`, and the mapping `⨁ i, A i →+ ⨆ i, A i` can be obtained as `direct_sum.to_monoid (λ i, add_submonoid.inclusion $ le_supr A i)`. ## tags graded ring, filtered ring, direct sum, add_submonoid -/ set_option old_structure_cmd true variables {ι : Type*} [decidable_eq ι] namespace direct_sum open_locale direct_sum /-! ### Typeclasses -/ section defs variables (A : ι → Type*) /-- A graded version of `non_unital_non_assoc_semiring`. -/ class gnon_unital_non_assoc_semiring [has_add ι] [Π i, add_comm_monoid (A i)] extends graded_monoid.ghas_mul A := (mul_zero : ∀ {i j} (a : A i), mul a (0 : A j) = 0) (zero_mul : ∀ {i j} (b : A j), mul (0 : A i) b = 0) (mul_add : ∀ {i j} (a : A i) (b c : A j), mul a (b + c) = mul a b + mul a c) (add_mul : ∀ {i j} (a b : A i) (c : A j), mul (a + b) c = mul a c + mul b c) end defs section defs variables (A : ι → Type*) /-- A graded version of `semiring`. -/ class gsemiring [add_monoid ι] [Π i, add_comm_monoid (A i)] extends gnon_unital_non_assoc_semiring A, graded_monoid.gmonoid A /-- A graded version of `comm_semiring`. -/ class gcomm_semiring [add_comm_monoid ι] [Π i, add_comm_monoid (A i)] extends gsemiring A, graded_monoid.gcomm_monoid A end defs lemma of_eq_of_graded_monoid_eq {A : ι → Type*} [Π (i : ι), add_comm_monoid (A i)] {i j : ι} {a : A i} {b : A j} (h : graded_monoid.mk i a = graded_monoid.mk j b) : direct_sum.of A i a = direct_sum.of A j b := dfinsupp.single_eq_of_sigma_eq h variables (A : ι → Type*) /-! ### Instances for `⨁ i, A i` -/ section one variables [has_zero ι] [graded_monoid.ghas_one A] [Π i, add_comm_monoid (A i)] instance : has_one (⨁ i, A i) := { one := direct_sum.of (λ i, A i) 0 graded_monoid.ghas_one.one} end one section mul variables [has_add ι] [Π i, add_comm_monoid (A i)] [gnon_unital_non_assoc_semiring A] open add_monoid_hom (map_zero map_add flip_apply coe_comp comp_hom_apply_apply) /-- The piecewise multiplication from the `has_mul` instance, as a bundled homomorphism. -/ @[simps] def gmul_hom {i j} : A i →+ A j →+ A (i + j) := { to_fun := λ a, { to_fun := λ b, graded_monoid.ghas_mul.mul a b, map_zero' := gnon_unital_non_assoc_semiring.mul_zero _, map_add' := gnon_unital_non_assoc_semiring.mul_add _ }, map_zero' := add_monoid_hom.ext $ λ a, gnon_unital_non_assoc_semiring.zero_mul a, map_add' := λ a₁ a₂, add_monoid_hom.ext $ λ b, gnon_unital_non_assoc_semiring.add_mul _ _ _} /-- The multiplication from the `has_mul` instance, as a bundled homomorphism. -/ def mul_hom : (⨁ i, A i) →+ (⨁ i, A i) →+ ⨁ i, A i := direct_sum.to_add_monoid $ λ i, add_monoid_hom.flip $ direct_sum.to_add_monoid $ λ j, add_monoid_hom.flip $ (direct_sum.of A _).comp_hom.comp $ gmul_hom A instance : non_unital_non_assoc_semiring (⨁ i, A i) := { mul := λ a b, mul_hom A a b, zero := 0, add := (+), zero_mul := λ a, by simp only [map_zero, add_monoid_hom.zero_apply], mul_zero := λ a, by simp only [map_zero], left_distrib := λ a b c, by simp only [map_add], right_distrib := λ a b c, by simp only [map_add, add_monoid_hom.add_apply], .. direct_sum.add_comm_monoid _ _} variables {A} lemma mul_hom_of_of {i j} (a : A i) (b : A j) : mul_hom A (of _ i a) (of _ j b) = of _ (i + j) (graded_monoid.ghas_mul.mul a b) := begin unfold mul_hom, rw [to_add_monoid_of, flip_apply, to_add_monoid_of, flip_apply, coe_comp, function.comp_app, comp_hom_apply_apply, coe_comp, function.comp_app, gmul_hom_apply_apply], end lemma of_mul_of {i j} (a : A i) (b : A j) : of _ i a * of _ j b = of _ (i + j) (graded_monoid.ghas_mul.mul a b) := mul_hom_of_of a b end mul section semiring variables [Π i, add_comm_monoid (A i)] [add_monoid ι] [gsemiring A] open add_monoid_hom (flip_hom coe_comp comp_hom_apply_apply flip_apply flip_hom_apply) private lemma one_mul (x : ⨁ i, A i) : 1 * x = x := suffices mul_hom A 1 = add_monoid_hom.id (⨁ i, A i), from add_monoid_hom.congr_fun this x, begin apply add_hom_ext, intros i xi, unfold has_one.one, rw mul_hom_of_of, exact of_eq_of_graded_monoid_eq (one_mul $ graded_monoid.mk i xi), end private lemma mul_one (x : ⨁ i, A i) : x * 1 = x := suffices (mul_hom A).flip 1 = add_monoid_hom.id (⨁ i, A i), from add_monoid_hom.congr_fun this x, begin apply add_hom_ext, intros i xi, unfold has_one.one, rw [flip_apply, mul_hom_of_of], exact of_eq_of_graded_monoid_eq (mul_one $ graded_monoid.mk i xi), end private lemma mul_assoc (a b c : ⨁ i, A i) : a * b * c = a * (b * c) := suffices (mul_hom A).comp_hom.comp (mul_hom A) -- `λ a b c, a * b * c` as a bundled hom = (add_monoid_hom.comp_hom flip_hom $ -- `λ a b c, a * (b * c)` as a bundled hom (mul_hom A).flip.comp_hom.comp (mul_hom A)).flip, from add_monoid_hom.congr_fun (add_monoid_hom.congr_fun (add_monoid_hom.congr_fun this a) b) c, begin ext ai ax bi bx ci cx : 6, dsimp only [coe_comp, function.comp_app, comp_hom_apply_apply, flip_apply, flip_hom_apply], rw [mul_hom_of_of, mul_hom_of_of, mul_hom_of_of, mul_hom_of_of], exact of_eq_of_graded_monoid_eq (mul_assoc (graded_monoid.mk ai ax) ⟨bi, bx⟩ ⟨ci, cx⟩), end /-- The `semiring` structure derived from `gsemiring A`. -/ instance semiring : semiring (⨁ i, A i) := { one := 1, mul := (*), zero := 0, add := (+), one_mul := one_mul A, mul_one := mul_one A, mul_assoc := mul_assoc A, ..direct_sum.non_unital_non_assoc_semiring _, } lemma of_pow {i} (a : A i) (n : ℕ) : of _ i a ^ n = of _ (n • i) (graded_monoid.gmonoid.gnpow _ a) := begin induction n with n, { exact of_eq_of_graded_monoid_eq (pow_zero $ graded_monoid.mk _ a).symm, }, { rw [pow_succ, n_ih, of_mul_of], exact of_eq_of_graded_monoid_eq (pow_succ (graded_monoid.mk _ a) n).symm, }, end end semiring section comm_semiring variables [Π i, add_comm_monoid (A i)] [add_comm_monoid ι] [gcomm_semiring A] private lemma mul_comm (a b : ⨁ i, A i) : a * b = b * a := suffices mul_hom A = (mul_hom A).flip, from add_monoid_hom.congr_fun (add_monoid_hom.congr_fun this a) b, begin apply add_hom_ext, intros ai ax, apply add_hom_ext, intros bi bx, rw [add_monoid_hom.flip_apply, mul_hom_of_of, mul_hom_of_of], exact of_eq_of_graded_monoid_eq (gcomm_semiring.mul_comm ⟨ai, ax⟩ ⟨bi, bx⟩), end /-- The `comm_semiring` structure derived from `gcomm_semiring A`. -/ instance comm_semiring : comm_semiring (⨁ i, A i) := { one := 1, mul := (*), zero := 0, add := (+), mul_comm := mul_comm A, ..direct_sum.semiring _, } end comm_semiring section ring variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gsemiring A] /-- The `ring` derived from `gsemiring A`. -/ instance ring : ring (⨁ i, A i) := { one := 1, mul := (*), zero := 0, add := (+), neg := has_neg.neg, ..(direct_sum.semiring _), ..(direct_sum.add_comm_group _), } end ring section comm_ring variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gcomm_semiring A] /-- The `comm_ring` derived from `gcomm_semiring A`. -/ instance comm_ring : comm_ring (⨁ i, A i) := { one := 1, mul := (*), zero := 0, add := (+), neg := has_neg.neg, ..(direct_sum.ring _), ..(direct_sum.comm_semiring _), } end comm_ring /-! ### Instances for `A 0` The various `g*` instances are enough to promote the `add_comm_monoid (A 0)` structure to various types of multiplicative structure. -/ section grade_zero section one variables [has_zero ι] [graded_monoid.ghas_one A] [Π i, add_comm_monoid (A i)] @[simp] lemma of_zero_one : of _ 0 (1 : A 0) = 1 := rfl end one section mul variables [add_monoid ι] [Π i, add_comm_monoid (A i)] [gnon_unital_non_assoc_semiring A] @[simp] lemma of_zero_smul {i} (a : A 0) (b : A i) : of _ _ (a • b) = of _ _ a * of _ _ b := (of_eq_of_graded_monoid_eq (graded_monoid.mk_zero_smul a b)).trans (of_mul_of _ _).symm @[simp] lemma of_zero_mul (a b : A 0) : of _ 0 (a * b) = of _ 0 a * of _ 0 b:= of_zero_smul A a b instance grade_zero.non_unital_non_assoc_semiring : non_unital_non_assoc_semiring (A 0) := function.injective.non_unital_non_assoc_semiring (of A 0) dfinsupp.single_injective (of A 0).map_zero (of A 0).map_add (of_zero_mul A) instance grade_zero.smul_with_zero (i : ι) : smul_with_zero (A 0) (A i) := begin letI := smul_with_zero.comp_hom (⨁ i, A i) (of A 0).to_zero_hom, refine dfinsupp.single_injective.smul_with_zero (of A i).to_zero_hom (of_zero_smul A), end end mul section semiring variables [Π i, add_comm_monoid (A i)] [add_monoid ι] [gsemiring A] /-- The `semiring` structure derived from `gsemiring A`. -/ instance grade_zero.semiring : semiring (A 0) := function.injective.semiring (of A 0) dfinsupp.single_injective (of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A) /-- `of A 0` is a `ring_hom`, using the `direct_sum.grade_zero.semiring` structure. -/ def of_zero_ring_hom : A 0 →+* (⨁ i, A i) := { map_one' := of_zero_one A, map_mul' := of_zero_mul A, ..(of _ 0) } /-- Each grade `A i` derives a `A 0`-module structure from `gsemiring A`. Note that this results in an overall `module (A 0) (⨁ i, A i)` structure via `direct_sum.module`. -/ instance grade_zero.module {i} : module (A 0) (A i) := begin letI := module.comp_hom (⨁ i, A i) (of_zero_ring_hom A), exact dfinsupp.single_injective.module (A 0) (of A i) (λ a, of_zero_smul A a), end end semiring section comm_semiring variables [Π i, add_comm_monoid (A i)] [add_comm_monoid ι] [gcomm_semiring A] /-- The `comm_semiring` structure derived from `gcomm_semiring A`. -/ instance grade_zero.comm_semiring : comm_semiring (A 0) := function.injective.comm_semiring (of A 0) dfinsupp.single_injective (of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A) end comm_semiring section ring variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gsemiring A] /-- The `ring` derived from `gsemiring A`. -/ instance grade_zero.ring : ring (A 0) := function.injective.ring (of A 0) dfinsupp.single_injective (of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A) (of A 0).map_neg (of A 0).map_sub end ring section comm_ring variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gcomm_semiring A] /-- The `comm_ring` derived from `gcomm_semiring A`. -/ instance grade_zero.comm_ring : comm_ring (A 0) := function.injective.comm_ring (of A 0) dfinsupp.single_injective (of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A) (of A 0).map_neg (of A 0).map_sub end comm_ring end grade_zero section to_semiring variables {R : Type*} [Π i, add_comm_monoid (A i)] [add_monoid ι] [gsemiring A] [semiring R] variables {A} /-- If two ring homomorphisms from `⨁ i, A i` are equal on each `of A i y`, then they are equal. See note [partially-applied ext lemmas]. -/ @[ext] lemma ring_hom_ext' (F G : (⨁ i, A i) →+* R) (h : ∀ i, (F : (⨁ i, A i) →+ R).comp (of _ i) = (G : (⨁ i, A i) →+ R).comp (of _ i)) : F = G := ring_hom.coe_add_monoid_hom_injective $ direct_sum.add_hom_ext' h /-- A family of `add_monoid_hom`s preserving `direct_sum.ghas_one.one` and `direct_sum.ghas_mul.mul` describes a `ring_hom`s on `⨁ i, A i`. This is a stronger version of `direct_sum.to_monoid`. Of particular interest is the case when `A i` are bundled subojects, `f` is the family of coercions such as `add_submonoid.subtype (A i)`, and the `[gsemiring A]` structure originates from `direct_sum.gsemiring.of_add_submonoids`, in which case the proofs about `ghas_one` and `ghas_mul` can be discharged by `rfl`. -/ @[simps] def to_semiring (f : Π i, A i →+ R) (hone : f _ (graded_monoid.ghas_one.one) = 1) (hmul : ∀ {i j} (ai : A i) (aj : A j), f _ (graded_monoid.ghas_mul.mul ai aj) = f _ ai * f _ aj) : (⨁ i, A i) →+* R := { to_fun := to_add_monoid f, map_one' := begin change (to_add_monoid f) (of _ 0 _) = 1, rw to_add_monoid_of, exact hone end, map_mul' := begin rw (to_add_monoid f).map_mul_iff, ext xi xv yi yv : 4, show to_add_monoid f (of A xi xv * of A yi yv) = to_add_monoid f (of A xi xv) * to_add_monoid f (of A yi yv), rw [of_mul_of, to_add_monoid_of, to_add_monoid_of, to_add_monoid_of], exact hmul _ _, end, .. to_add_monoid f} @[simp] lemma to_semiring_of (f : Π i, A i →+ R) (hone hmul) (i : ι) (x : A i) : to_semiring f hone hmul (of _ i x) = f _ x := to_add_monoid_of f i x @[simp] lemma to_semiring_coe_add_monoid_hom (f : Π i, A i →+ R) (hone hmul): (to_semiring f hone hmul : (⨁ i, A i) →+ R) = to_add_monoid f := rfl /-- Families of `add_monoid_hom`s preserving `direct_sum.ghas_one.one` and `direct_sum.ghas_mul.mul` are isomorphic to `ring_hom`s on `⨁ i, A i`. This is a stronger version of `dfinsupp.lift_add_hom`. -/ @[simps] def lift_ring_hom : {f : Π {i}, A i →+ R // f (graded_monoid.ghas_one.one) = 1 ∧ ∀ {i j} (ai : A i) (aj : A j), f (graded_monoid.ghas_mul.mul ai aj) = f ai * f aj} ≃ ((⨁ i, A i) →+* R) := { to_fun := λ f, to_semiring f.1 f.2.1 f.2.2, inv_fun := λ F, ⟨λ i, (F : (⨁ i, A i) →+ R).comp (of _ i), begin simp only [add_monoid_hom.comp_apply, ring_hom.coe_add_monoid_hom], rw ←F.map_one, refl end, λ i j ai aj, begin simp only [add_monoid_hom.comp_apply, ring_hom.coe_add_monoid_hom], rw [←F.map_mul, of_mul_of], end⟩, left_inv := λ f, begin ext xi xv, exact to_add_monoid_of f.1 xi xv, end, right_inv := λ F, begin apply ring_hom.coe_add_monoid_hom_injective, ext xi xv, simp only [ring_hom.coe_add_monoid_hom_mk, direct_sum.to_add_monoid_of, add_monoid_hom.mk_coe, add_monoid_hom.comp_apply, to_semiring_coe_add_monoid_hom], end} /-- Two `ring_hom`s out of a direct sum are equal if they agree on the generators. See note [partially-applied ext lemmas]. -/ @[ext] lemma ring_hom_ext ⦃f g : (⨁ i, A i) →+* R⦄ (h : ∀ i, (↑f : (⨁ i, A i) →+ R).comp (of A i) = (↑g : (⨁ i, A i) →+ R).comp (of A i)) : f = g := direct_sum.lift_ring_hom.symm.injective $ subtype.ext $ funext h end to_semiring end direct_sum /-! ### Concrete instances -/ section uniform variables (ι) /-- A direct sum of copies of a `semiring` inherits the multiplication structure. -/ instance non_unital_non_assoc_semiring.direct_sum_gnon_unital_non_assoc_semiring {R : Type*} [add_monoid ι] [non_unital_non_assoc_semiring R] : direct_sum.gnon_unital_non_assoc_semiring (λ i : ι, R) := { mul_zero := λ i j, mul_zero, zero_mul := λ i j, zero_mul, mul_add := λ i j, mul_add, add_mul := λ i j, add_mul, ..has_mul.ghas_mul ι } /-- A direct sum of copies of a `semiring` inherits the multiplication structure. -/ instance semiring.direct_sum_gsemiring {R : Type*} [add_monoid ι] [semiring R] : direct_sum.gsemiring (λ i : ι, R) := { ..non_unital_non_assoc_semiring.direct_sum_gnon_unital_non_assoc_semiring ι, ..monoid.gmonoid ι } open_locale direct_sum -- To check `has_mul.ghas_mul_mul` matches example {R : Type*} [add_monoid ι] [semiring R] (i j : ι) (a b : R) : (direct_sum.of _ i a * direct_sum.of _ j b : ⨁ i, R) = direct_sum.of _ (i + j) (by exact a * b) := by rw [direct_sum.of_mul_of, has_mul.ghas_mul_mul] /-- A direct sum of copies of a `comm_semiring` inherits the commutative multiplication structure. -/ instance comm_semiring.direct_sum_gcomm_semiring {R : Type*} [add_comm_monoid ι] [comm_semiring R] : direct_sum.gcomm_semiring (λ i : ι, R) := { ..comm_monoid.gcomm_monoid ι, ..semiring.direct_sum_gsemiring ι } end uniform
f97c7abff6013948b2ef89fc73a8161272bde431
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/algebra/associated.lean
7225bb23b9df0d1ef0bbcebb8ebf9498a4490ef8
[ "Apache-2.0" ]
permissive
lacker/mathlib
f2439c743c4f8eb413ec589430c82d0f73b2d539
ddf7563ac69d42cfa4a1bfe41db1fed521bd795f
refs/heads/master
1,671,948,326,773
1,601,479,268,000
1,601,479,268,000
298,686,743
0
0
Apache-2.0
1,601,070,794,000
1,601,070,794,000
null
UTF-8
Lean
false
false
27,417
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.basic import algebra.divisibility /-! # Associated, prime, and irreducible elements. -/ variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} 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_monoid α] {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_monoid α] {x : α} : is_unit x ↔ ∀ y, x ∣ y := is_unit_iff_dvd_one.trans ⟨λ h y, dvd.trans h (one_dvd _), λ h, h _⟩ theorem is_unit_of_dvd_unit {α} [comm_monoid α] {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 := ⟨begin rintro ⟨u, rfl⟩, exact (int.units_eq_one_or u).elim (by simp) (by simp) end, λ h, is_unit_iff_dvd_one.2 ⟨n, by rw [← int.nat_abs_mul_self, h]; refl⟩⟩ lemma is_unit_of_dvd_one [comm_monoid α] : ∀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 [comm_cancel_monoid_with_zero α] {x y : α} : x ∣ y ∧ ¬y ∣ x ↔ dvd_not_unit x y := ⟨λ ⟨⟨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, mul_left_cancel' hx0 $ by conv {to_lhs, rw [he, hdx]};simp [mul_assoc]⟩)⟩⟩ lemma pow_dvd_pow_iff [comm_cancel_monoid_with_zero α] {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 ^ m * x ∣ x ^ m * 1, { rw [← pow_succ', mul_one], exact dvd_trans (pow_dvd_pow _ (nat.succ_le_of_lt hmn)) h }, rwa [mul_dvd_mul_iff_left, ← is_unit_iff_dvd_one] at this, apply pow_ne_zero m h0 }, { apply pow_dvd_pow } end section prime variables [comm_monoid_with_zero α] /-- prime element of a `comm_monoid_with_zero` -/ def prime (p : α) : Prop := p ≠ 0 ∧ ¬ is_unit p ∧ (∀a b, p ∣ a * b → p ∣ a ∨ p ∣ b) namespace prime variables {p : α} (hp : prime p) lemma ne_zero (hp : prime p) : p ≠ 0 := hp.1 lemma not_unit (hp : prime p) : ¬ is_unit p := hp.2.1 lemma ne_one (hp : prime p) : p ≠ 1 := λ h, hp.2.1 (h.symm ▸ is_unit_one) lemma div_or_div (hp : prime p) {a b : α} (h : p ∣ a * b) : p ∣ a ∨ p ∣ b := hp.2.2 a b h lemma dvd_of_dvd_pow (hp : prime p) {a : α} {n : ℕ} (h : p ∣ a^n) : p ∣ a := begin induction n with n ih, { rw pow_zero at h, have := is_unit_of_dvd_one _ h, have := not_unit hp, contradiction }, rw pow_succ at h, cases div_or_div hp h with dvd_a dvd_pow, { assumption }, exact ih dvd_pow end end prime @[simp] lemma not_prime_zero : ¬ prime (0 : α) := λ h, h.ne_zero rfl @[simp] lemma not_prime_one : ¬ prime (1 : α) := λ h, h.not_unit is_unit_one lemma exists_mem_multiset_dvd_of_prime {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 end prime lemma left_dvd_or_dvd_right_of_dvd_prime_mul [comm_cancel_monoid_with_zero α] {a : α} : ∀ {b p : α}, prime p → a ∣ p * b → p ∣ a ∨ a ∣ b := begin rintros b p hp ⟨c, hc⟩, rcases hp.2.2 a c (hc ▸ dvd_mul_right _ _) with h | ⟨x, rfl⟩, { exact or.inl h }, { rw [mul_left_comm, mul_right_inj' hp.ne_zero] at hc, exact or.inr (hc.symm ▸ dvd_mul_right _ _) } 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 [monoid_with_zero α] : ¬ 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 [monoid_with_zero α] : ∀ {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 [comm_cancel_monoid_with_zero α] {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, mul_right_cancel' (show a ≠ 0, from λ h, by simp [*, prime] at *) $ 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, mul_right_cancel' (show b ≠ 0, from λ h, by simp [*, prime] at *) $ 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 [comm_cancel_monoid_with_zero α] {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, 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 [mul_right_inj' hp0] at h⟩, (hp.div_or_div hpd).elim (λ ⟨d, hd⟩, or.inl ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩) (λ ⟨d, hd⟩, or.inr ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩) /-- If `p` and `q` are irreducible, then `p ∣ q` implies `q ∣ p`. -/ lemma dvd_symm_of_irreducible [monoid α] {p q : α} (hp : irreducible p) (hq : irreducible q) : p ∣ q → q ∣ p := begin tactic.unfreeze_local_instances, rintros ⟨q', rfl⟩, rw is_unit.mul_right_dvd (or.resolve_left (of_irreducible_mul hq) hp.not_unit), end lemma dvd_symm_iff_of_irreducible [monoid α] {p q : α} (hp : irreducible p) (hq : irreducible q) : p ∣ q ↔ q ∣ p := ⟨dvd_symm_of_irreducible hp hq, dvd_symm_of_irreducible hq hp⟩ /-- 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]⟩ /-- The setoid of the relation `x ~ᵤ y` iff there is a unit `u` such that `x * u = y` -/ 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 _).symm⟩) (assume ⟨c, h⟩, associated.symm ⟨c, by simp [h]⟩) theorem associated_zero_iff_eq_zero [monoid_with_zero α] (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]⟩ lemma dvd_of_associated [monoid α] {a b : α} : a ~ᵤ b → a ∣ b := λ ⟨u, hu⟩, ⟨u, hu.symm⟩ lemma dvd_dvd_of_associated [monoid α] {a b : α} (h : a ~ᵤ b) : a ∣ b ∧ b ∣ a := ⟨dvd_of_associated h, dvd_of_associated h.symm⟩ theorem associated_of_dvd_dvd [cancel_monoid_with_zero α] {a b : α} (hab : a ∣ b) (hba : b ∣ a) : a ~ᵤ b := begin rcases hab with ⟨c, rfl⟩, rcases hba with ⟨d, a_eq⟩, by_cases ha0 : a = 0, { simp [*] at * }, have hac0 : a * c ≠ 0, { intro con, rw [con, zero_mul] at a_eq, apply ha0 a_eq, }, have : a * (c * d) = a * 1 := by rw [← mul_assoc, ← a_eq, mul_one], have hcd : (c * d) = 1, from mul_left_cancel' ha0 this, have : a * c * (d * c) = a * c * 1 := by rw [← mul_assoc, ← a_eq, mul_one], have hdc : d * c = 1, from mul_left_cancel' hac0 this, exact ⟨⟨c, d, hcd, hdc⟩, rfl⟩ end theorem dvd_dvd_iff_associated [cancel_monoid_with_zero α] {a b : α} : a ∣ b ∧ b ∣ a ↔ a ~ᵤ b := ⟨λ ⟨h1, h2⟩, associated_of_dvd_dvd h1 h2, dvd_dvd_of_associated⟩ lemma exists_associated_mem_of_dvd_prod [comm_cancel_monoid_with_zero α] {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_monoid_with_zero α] {a b c : α} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c := let ⟨u, hu⟩ := h in hu ▸ units.mul_right_dvd.symm lemma dvd_iff_dvd_of_rel_right [comm_monoid_with_zero α] {a b c : α} (h : b ~ᵤ c) : a ∣ b ↔ a ∣ c := let ⟨u, hu⟩ := h in hu ▸ units.dvd_mul_right.symm lemma eq_zero_iff_of_associated [comm_monoid_with_zero α] {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_monoid_with_zero α] {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_monoid_with_zero α] {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, hu.symm]⟩, hu ▸ by { simp [units.mul_right_dvd], intros a b, exact hp.div_or_div }⟩⟩ lemma prime_iff_of_associated [comm_monoid_with_zero α] {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_monoid_with_zero α] {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]⟩)⟩ lemma irreducible_iff_of_associated [comm_monoid_with_zero α] {p q : α} (h : p ~ᵤ q) : irreducible p ↔ irreducible q := ⟨irreducible_of_associated h, irreducible_of_associated h.symm⟩ lemma associated_mul_left_cancel [comm_cancel_monoid_with_zero α] {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 α), mul_left_cancel' ha 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 [comm_cancel_monoid_with_zero α] {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 /-- The quotient of a monoid by the `associated` relation. Two elements `x` and `y` are associated iff there is a unit `u` such that `x * u = y`. There is a natural monoid structure on `associates α`. -/ def associates (α : Type*) [monoid α] : Type* := quotient (associated.setoid α) namespace associates open associated /-- The canonical quotient map from a monoid `α` into the `associates` of `α` -/ 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) theorem mk_surjective [monoid α] : function.surjective (@associates.mk α _) := forall_associated.2 (λ a, ⟨a, rfl⟩) instance [monoid α] : has_one (associates α) := ⟨⟦ 1 ⟧⟩ theorem one_eq_mk_one [monoid α] : (1 : associates α) = associates.mk 1 := rfl instance [monoid α] : has_bot (associates α) := ⟨1⟩ lemma exists_rep [monoid α] (a : associates α) : ∃ a0 : α, associates.mk a0 = a := quot.exists_rep a 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 := has_dvd.dvd, le_refl := dvd_refl, le_trans := λ a b c, dvd_trans} @[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 units_eq_one (u : units (associates α)) : u = 1 := units.ext (mul_eq_one_iff.1 u.val_inv).1 instance unique_units : unique (units (associates α)) := { default := 1, uniq := associates.units_eq_one } theorem coe_unit_eq_one (u : units (associates α)): (u : associates α) = 1 := by simp theorem is_unit_iff_eq_one (a : associates α) : is_unit a ↔ a = 1 := iff.intro (assume ⟨u, h⟩, h ▸ 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, hy, mul_comm, mul_assoc, mul_left_comm]⟩ theorem one_le {a : associates α} : 1 ≤ a := dvd.intro _ (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_monoid_with_zero variables [comm_monoid_with_zero α] @[simp] theorem mk_eq_zero {a : α} : associates.mk a = 0 ↔ a = 0 := ⟨assume h, (associated_zero_iff_eq_zero a).1 $ quotient.exact h, assume h, h.symm ▸ rfl⟩ instance : comm_monoid_with_zero (associates α) := { zero_mul := by { rintro ⟨a⟩, show associates.mk (0 * a) = associates.mk 0, rw [zero_mul] }, mul_zero := by { rintro ⟨a⟩, show associates.mk (a * 0) = associates.mk 0, rw [mul_zero] }, .. associates.comm_monoid, .. associates.has_zero } instance [nontrivial α] : nontrivial (associates α) := ⟨⟨0, 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⟩⟩ lemma exists_non_zero_rep {a : associates α} : a ≠ 0 → ∃ a0 : α, a0 ≠ 0 ∧ associates.mk a0 = a := quotient.induction_on a (λ b nz, ⟨b, mt (congr_arg quotient.mk) nz, rfl⟩) 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 : hd.symm ... = 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 theorem mk_dvd_mk {a b : α} : associates.mk a ∣ associates.mk b ↔ a ∣ b := iff.intro dvd_of_mk_le_mk mk_le_mk_of_dvd 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.symm).1).elim) $ assume a s ih h, have p ≤ a * s.prod, by simpa using h, match prime.le_or_le hp 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 [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_eq_zero] }, apply and_congr, { rw [is_unit_mk], }, apply forall_congr, assume a, apply forall_congr, assume b, rw [mk_mul_mk, mk_dvd_mk, mk_dvd_mk, mk_dvd_mk], end theorem irreducible_mk (a : α) : irreducible (associates.mk a) ↔ irreducible a := begin simp only [irreducible, is_unit_mk], apply and_congr iff.rfl, split, { rintro h x y rfl, simpa [is_unit_mk] using h (associates.mk x) (associates.mk y) rfl }, { intros h x y, refine quotient.induction_on₂ x y (assume x y a_eq, _), rcases quotient.exact a_eq.symm with ⟨u, a_eq⟩, rw mul_assoc at a_eq, show is_unit (associates.mk x) ∨ is_unit (associates.mk y), simpa [is_unit_mk] using h _ _ a_eq.symm } end theorem mk_dvd_not_unit_mk_iff {a b : α} : dvd_not_unit (associates.mk a) (associates.mk b) ↔ dvd_not_unit a b := begin rw [dvd_not_unit, dvd_not_unit, ne, ne, mk_eq_zero], apply and_congr_right, intro ane0, split, { contrapose!, rw forall_associated, intros h x hx hbax, rw [mk_mul_mk, mk_eq_mk_iff_associated] at hbax, cases hbax with u hu, apply h (x * ↑u⁻¹), { rw is_unit_mk at hx, rw is_unit_iff_of_associated, apply hx, use u, simp, }, simp [← mul_assoc, ← hu] }, { rintro ⟨x, ⟨hx, rfl⟩⟩, use associates.mk x, simp [is_unit_mk, mk_mul_mk, hx], } end theorem dvd_not_unit_of_lt {a b : associates α} (hlt : a < b) : dvd_not_unit a b := begin split, { rintro rfl, apply not_lt_of_le _ hlt, apply dvd_zero }, rcases hlt with ⟨⟨x, rfl⟩, ndvd⟩, refine ⟨x, _, rfl⟩, contrapose! ndvd, rcases ndvd with ⟨u, rfl⟩, simp, end end comm_monoid_with_zero section comm_cancel_monoid_with_zero variable [comm_cancel_monoid_with_zero α] instance : partial_order (associates α) := { le_antisymm := λ a' b', quotient.induction_on₂ a' b' (λ a b hab hba, quot.sound $ associated_of_dvd_dvd (dvd_of_mk_le_mk hab) (dvd_of_mk_le_mk hba)) .. 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).symm⟩, .. associates.partial_order } instance : no_zero_divisors (associates α) := ⟨λ x y, (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.1 this, this.imp (assume h, h.symm ▸ rfl) (assume h, h.symm ▸ rfl))⟩ theorem irreducible_iff_prime_iff : (∀ a : α, irreducible a ↔ prime a) ↔ (∀ a : (associates α), irreducible a ↔ prime a) := begin rw forall_associated, split; intros h a; have ha := h a; rw irreducible_mk at *; rw prime_mk at *; exact ha, 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, mul_left_cancel' (mt mk_eq_zero.2 ha) hu⟩ end lemma eq_of_mul_eq_mul_right : ∀(a b c : associates α), b ≠ 0 → a * b = c * b → a = c := λ a b c bne0, (mul_comm b a) ▸ (mul_comm b c) ▸ (eq_of_mul_eq_mul_left b a c bne0) 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 (dvd_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 instance : comm_cancel_monoid_with_zero (associates α) := { mul_left_cancel_of_ne_zero := eq_of_mul_eq_mul_left, mul_right_cancel_of_ne_zero := eq_of_mul_eq_mul_right, .. (infer_instance : comm_monoid_with_zero (associates α)) } theorem dvd_not_unit_iff_lt {a b : associates α} : dvd_not_unit a b ↔ a < b := dvd_and_not_dvd_iff.symm end comm_cancel_monoid_with_zero end associates
7e9e2499563f8efa105f9f6220991008dc00b54f
bb31430994044506fa42fd667e2d556327e18dfe
/src/algebra/quandle.lean
481d9047c8649dd8fce01da000118bca703c7815
[ "Apache-2.0" ]
permissive
sgouezel/mathlib
0cb4e5335a2ba189fa7af96d83a377f83270e503
00638177efd1b2534fc5269363ebf42a7871df9a
refs/heads/master
1,674,527,483,042
1,673,665,568,000
1,673,665,568,000
119,598,202
0
0
null
1,517,348,647,000
1,517,348,646,000
null
UTF-8
Lean
false
false
24,733
lean
/- Copyright (c) 2020 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import algebra.hom.equiv.basic import algebra.hom.aut import data.zmod.defs import tactic.group /-! # Racks and Quandles This file defines racks and quandles, algebraic structures for sets that bijectively act on themselves with a self-distributivity property. If `R` is a rack and `act : R → (R ≃ R)` is the self-action, then the self-distributivity is, equivalently, that ``` act (act x y) = act x * act y * (act x)⁻¹ ``` where multiplication is composition in `R ≃ R` as a group. Quandles are racks such that `act x x = x` for all `x`. One example of a quandle (not yet in mathlib) is the action of a Lie algebra on itself, defined by `act x y = Ad (exp x) y`. Quandles and racks were independently developed by multiple mathematicians. David Joyce introduced quandles in his thesis [Joyce1982] to define an algebraic invariant of knot and link complements that is analogous to the fundamental group of the exterior, and he showed that the quandle associated to an oriented knot is invariant up to orientation-reversed mirror image. Racks were used by Fenn and Rourke for framed codimension-2 knots and links.[FennRourke1992] The name "rack" came from wordplay by Conway and Wraith for the "wrack and ruin" of forgetting everything but the conjugation operation for a group. ## Main definitions * `shelf` is a type with a self-distributive action * `rack` is a shelf whose action for each element is invertible * `quandle` is a rack whose action for an element fixes that element * `quandle.conj` defines a quandle of a group acting on itself by conjugation. * `shelf_hom` is homomorphisms of shelves, racks, and quandles. * `rack.envel_group` gives the universal group the rack maps to as a conjugation quandle. * `rack.opp` gives the rack with the action replaced by its inverse. ## Main statements * `rack.envel_group` is left adjoint to `quandle.conj` (`to_envel_group.map`). The universality statements are `to_envel_group.univ` and `to_envel_group.univ_uniq`. ## Notation The following notation is localized in `quandles`: * `x ◃ y` is `shelf.act x y` * `x ◃⁻¹ y` is `rack.inv_act x y` * `S →◃ S'` is `shelf_hom S S'` Use `open_locale quandles` to use these. ## Todo * If `g` is the Lie algebra of a Lie group `G`, then `(x ◃ y) = Ad (exp x) x` forms a quandle. * If `X` is a symmetric space, then each point has a corresponding involution that acts on `X`, forming a quandle. * Alexander quandle with `a ◃ b = t * b + (1 - t) * b`, with `a` and `b` elements of a module over `Z[t,t⁻¹]`. * If `G` is a group, `H` a subgroup, and `z` in `H`, then there is a quandle `(G/H;z)` defined by `yH ◃ xH = yzy⁻¹xH`. Every homogeneous quandle (i.e., a quandle `Q` whose automorphism group acts transitively on `Q` as a set) is isomorphic to such a quandle. There is a generalization to this arbitrary quandles in [Joyce's paper (Theorem 7.2)][Joyce1982]. ## Tags rack, quandle -/ open mul_opposite universes u v /-- A *shelf* is a structure with a self-distributive binary operation. The binary operation is regarded as a left action of the type on itself. -/ class shelf (α : Type u) := (act : α → α → α) (self_distrib : ∀ {x y z : α}, act x (act y z) = act (act x y) (act x z)) /-- The type of homomorphisms between shelves. This is also the notion of rack and quandle homomorphisms. -/ @[ext] structure shelf_hom (S₁ : Type*) (S₂ : Type*) [shelf S₁] [shelf S₂] := (to_fun : S₁ → S₂) (map_act' : ∀ {x y : S₁}, to_fun (shelf.act x y) = shelf.act (to_fun x) (to_fun y)) /-- A *rack* is an automorphic set (a set with an action on itself by bijections) that is self-distributive. It is a shelf such that each element's action is invertible. The notations `x ◃ y` and `x ◃⁻¹ y` denote the action and the inverse action, respectively, and they are right associative. -/ class rack (α : Type u) extends shelf α := (inv_act : α → α → α) (left_inv : ∀ x, function.left_inverse (inv_act x) (act x)) (right_inv : ∀ x, function.right_inverse (inv_act x) (act x)) localized "infixr (name := shelf.act) ` ◃ `:65 := shelf.act" in quandles localized "infixr (name := rack.inv_act) ` ◃⁻¹ `:65 := rack.inv_act" in quandles localized "infixr (name := shelf_hom) ` →◃ `:25 := shelf_hom" in quandles open_locale quandles namespace rack variables {R : Type*} [rack R] lemma self_distrib {x y z : R} : x ◃ (y ◃ z) = (x ◃ y) ◃ (x ◃ z) := shelf.self_distrib /-- A rack acts on itself by equivalences. -/ def act (x : R) : R ≃ R := { to_fun := shelf.act x, inv_fun := inv_act x, left_inv := left_inv x, right_inv := right_inv x } @[simp] lemma act_apply (x y : R) : act x y = x ◃ y := rfl @[simp] lemma act_symm_apply (x y : R) : (act x).symm y = x ◃⁻¹ y := rfl @[simp] lemma inv_act_apply (x y : R) : (act x)⁻¹ y = x ◃⁻¹ y := rfl @[simp] lemma inv_act_act_eq (x y : R) : x ◃⁻¹ x ◃ y = y := left_inv x y @[simp] lemma act_inv_act_eq (x y : R) : x ◃ x ◃⁻¹ y = y := right_inv x y lemma left_cancel (x : R) {y y' : R} : x ◃ y = x ◃ y' ↔ y = y' := by { split, apply (act x).injective, rintro rfl, refl } lemma left_cancel_inv (x : R) {y y' : R} : x ◃⁻¹ y = x ◃⁻¹ y' ↔ y = y' := by { split, apply (act x).symm.injective, rintro rfl, refl } lemma self_distrib_inv {x y z : R} : x ◃⁻¹ y ◃⁻¹ z = (x ◃⁻¹ y) ◃⁻¹ (x ◃⁻¹ z) := begin rw [←left_cancel (x ◃⁻¹ y), right_inv, ←left_cancel x, right_inv, self_distrib], repeat {rw right_inv }, end /-- The *adjoint action* of a rack on itself is `op'`, and the adjoint action of `x ◃ y` is the conjugate of the action of `y` by the action of `x`. It is another way to understand the self-distributivity axiom. This is used in the natural rack homomorphism `to_conj` from `R` to `conj (R ≃ R)` defined by `op'`. -/ lemma ad_conj {R : Type*} [rack R] (x y : R) : act (x ◃ y) = act x * act y * (act x)⁻¹ := begin rw [eq_mul_inv_iff_mul_eq], ext z, apply self_distrib.symm, end /-- The opposite rack, swapping the roles of `◃` and `◃⁻¹`. -/ instance opposite_rack : rack Rᵐᵒᵖ := { act := λ x y, op (inv_act (unop x) (unop y)), self_distrib := mul_opposite.rec $ λ x, mul_opposite.rec $ λ y, mul_opposite.rec $ λ z, begin simp only [unop_op, op_inj], exact self_distrib_inv, end, inv_act := λ x y, op (shelf.act (unop x) (unop y)), left_inv := mul_opposite.rec $ λ x, mul_opposite.rec $ λ y, by simp, right_inv := mul_opposite.rec $ λ x, mul_opposite.rec $ λ y, by simp } @[simp] lemma op_act_op_eq {x y : R} : (op x) ◃ (op y) = op (x ◃⁻¹ y) := rfl @[simp] lemma op_inv_act_op_eq {x y : R} : (op x) ◃⁻¹ (op y) = op (x ◃ y) := rfl @[simp] lemma self_act_act_eq {x y : R} : (x ◃ x) ◃ y = x ◃ y := by { rw [←right_inv x y, ←self_distrib] } @[simp] lemma self_inv_act_inv_act_eq {x y : R} : (x ◃⁻¹ x) ◃⁻¹ y = x ◃⁻¹ y := by { have h := @self_act_act_eq _ _ (op x) (op y), simpa using h } @[simp] lemma self_act_inv_act_eq {x y : R} : (x ◃ x) ◃⁻¹ y = x ◃⁻¹ y := by { rw ←left_cancel (x ◃ x), rw right_inv, rw self_act_act_eq, rw right_inv } @[simp] lemma self_inv_act_act_eq {x y : R} : (x ◃⁻¹ x) ◃ y = x ◃ y := by { have h := @self_act_inv_act_eq _ _ (op x) (op y), simpa using h } lemma self_act_eq_iff_eq {x y : R} : x ◃ x = y ◃ y ↔ x = y := begin split, swap, rintro rfl, refl, intro h, transitivity (x ◃ x) ◃⁻¹ (x ◃ x), rw [←left_cancel (x ◃ x), right_inv, self_act_act_eq], rw [h, ←left_cancel (y ◃ y), right_inv, self_act_act_eq], end lemma self_inv_act_eq_iff_eq {x y : R} : x ◃⁻¹ x = y ◃⁻¹ y ↔ x = y := by { have h := @self_act_eq_iff_eq _ _ (op x) (op y), simpa using h } /-- The map `x ↦ x ◃ x` is a bijection. (This has applications for the regular isotopy version of the Reidemeister I move for knot diagrams.) -/ def self_apply_equiv (R : Type*) [rack R] : R ≃ R := { to_fun := λ x, x ◃ x, inv_fun := λ x, x ◃⁻¹ x, left_inv := λ x, by simp, right_inv := λ x, by simp } /-- An involutory rack is one for which `rack.op R x` is an involution for every x. -/ def is_involutory (R : Type*) [rack R] : Prop := ∀ x : R, function.involutive (shelf.act x) lemma involutory_inv_act_eq_act {R : Type*} [rack R] (h : is_involutory R) (x y : R) : x ◃⁻¹ y = x ◃ y := begin rw [←left_cancel x, right_inv], exact ((h x).left_inverse y).symm, end /-- An abelian rack is one for which the mediality axiom holds. -/ def is_abelian (R : Type*) [rack R] : Prop := ∀ (x y z w : R), (x ◃ y) ◃ (z ◃ w) = (x ◃ z) ◃ (y ◃ w) /-- Associative racks are uninteresting. -/ lemma assoc_iff_id {R : Type*} [rack R] {x y z : R} : x ◃ y ◃ z = (x ◃ y) ◃ z ↔ x ◃ z = z := by { rw self_distrib, rw left_cancel } end rack namespace shelf_hom variables {S₁ : Type*} {S₂ : Type*} {S₃ : Type*} [shelf S₁] [shelf S₂] [shelf S₃] instance : has_coe_to_fun (S₁ →◃ S₂) (λ _, S₁ → S₂) := ⟨shelf_hom.to_fun⟩ @[simp] lemma to_fun_eq_coe (f : S₁ →◃ S₂) : f.to_fun = f := rfl @[simp] lemma map_act (f : S₁ →◃ S₂) {x y : S₁} : f (x ◃ y) = f x ◃ f y := map_act' f /-- The identity homomorphism -/ def id (S : Type*) [shelf S] : S →◃ S := { to_fun := id, map_act' := by simp } instance inhabited (S : Type*) [shelf S] : inhabited (S →◃ S) := ⟨id S⟩ /-- The composition of shelf homomorphisms -/ def comp (g : S₂ →◃ S₃) (f : S₁ →◃ S₂) : S₁ →◃ S₃ := { to_fun := g.to_fun ∘ f.to_fun, map_act' := by simp } @[simp] lemma comp_apply (g : S₂ →◃ S₃) (f : S₁ →◃ S₂) (x : S₁) : (g.comp f) x = g (f x) := rfl end shelf_hom /-- A quandle is a rack such that each automorphism fixes its corresponding element. -/ class quandle (α : Type*) extends rack α := (fix : ∀ {x : α}, act x x = x) namespace quandle open rack variables {Q : Type*} [quandle Q] attribute [simp] fix @[simp] lemma fix_inv {x : Q} : x ◃⁻¹ x = x := by { rw ←left_cancel x, simp } instance opposite_quandle : quandle Qᵐᵒᵖ := { fix := λ x, by { induction x using mul_opposite.rec, simp } } /-- The conjugation quandle of a group. Each element of the group acts by the corresponding inner automorphism. -/ @[nolint has_nonempty_instance] def conj (G : Type*) := G instance conj.quandle (G : Type*) [group G] : quandle (conj G) := { act := (λ x, @mul_aut.conj G _ x), self_distrib := λ x y z, begin dsimp only [mul_equiv.coe_to_equiv, mul_aut.conj_apply, conj], group, end, inv_act := (λ x, (@mul_aut.conj G _ x).symm), left_inv := λ x y, by { dsimp [act, conj], group }, right_inv := λ x y, by { dsimp [act, conj], group }, fix := λ x, by simp } @[simp] lemma conj_act_eq_conj {G : Type*} [group G] (x y : conj G) : x ◃ y = ((x : G) * (y : G) * (x : G)⁻¹ : G) := rfl lemma conj_swap {G : Type*} [group G] (x y : conj G) : x ◃ y = y ↔ y ◃ x = x := begin dsimp [conj] at *, split, repeat { intro h, conv_rhs { rw eq_mul_inv_of_mul_eq (eq_mul_inv_of_mul_eq h) }, simp, }, end /-- `conj` is functorial -/ def conj.map {G : Type*} {H : Type*} [group G] [group H] (f : G →* H) : conj G →◃ conj H := { to_fun := f, map_act' := by simp } instance {G : Type*} {H : Type*} [group G] [group H] : has_lift (G →* H) (conj G →◃ conj H) := { lift := conj.map } /-- The dihedral quandle. This is the conjugation quandle of the dihedral group restrict to flips. Used for Fox n-colorings of knots. -/ @[nolint has_nonempty_instance] def dihedral (n : ℕ) := zmod n /-- The operation for the dihedral quandle. It does not need to be an equivalence because it is an involution (see `dihedral_act.inv`). -/ def dihedral_act (n : ℕ) (a : zmod n) : zmod n → zmod n := λ b, 2 * a - b lemma dihedral_act.inv (n : ℕ) (a : zmod n) : function.involutive (dihedral_act n a) := by { intro b, dsimp [dihedral_act], ring } instance (n : ℕ) : quandle (dihedral n) := { act := dihedral_act n, self_distrib := λ x y z, begin dsimp [dihedral_act], ring, end, inv_act := dihedral_act n, left_inv := λ x, (dihedral_act.inv n x).left_inverse, right_inv := λ x, (dihedral_act.inv n x).right_inverse, fix := λ x, begin dsimp [dihedral_act], ring, end } end quandle namespace rack /-- This is the natural rack homomorphism to the conjugation quandle of the group `R ≃ R` that acts on the rack. -/ def to_conj (R : Type*) [rack R] : R →◃ quandle.conj (R ≃ R) := { to_fun := act, map_act' := ad_conj } section envel_group /-! ### Universal enveloping group of a rack The universal enveloping group `envel_group R` of a rack `R` is the universal group such that every rack homomorphism `R →◃ conj G` is induced by a unique group homomorphism `envel_group R →* G`. For quandles, Joyce called this group `AdConj R`. The `envel_group` functor is left adjoint to the `conj` forgetful functor, and the way we construct the enveloping group is via a technique that should work for left adjoints of forgetful functors in general. It involves thinking a little about 2-categories, but the payoff is that the map `envel_group R →* G` has a nice description. Let's think of a group as being a one-object category. The first step is to define `pre_envel_group`, which gives formal expressions for all the 1-morphisms and includes the unit element, elements of `R`, multiplication, and inverses. To introduce relations, the second step is to define `pre_envel_group_rel'`, which gives formal expressions for all 2-morphisms between the 1-morphisms. The 2-morphisms include associativity, multiplication by the unit, multiplication by inverses, compatibility with multiplication and inverses (`congr_mul` and `congr_inv`), the axioms for an equivalence relation, and, importantly, the relationship between conjugation and the rack action (see `rack.ad_conj`). None of this forms a 2-category yet, for example due to lack of associativity of `trans`. The `pre_envel_group_rel` relation is a `Prop`-valued version of `pre_envel_group_rel'`, and making it `Prop`-valued essentially introduces enough 3-isomorphisms so that every pair of compatible 2-morphisms is isomorphic. Now, while composition in `pre_envel_group` does not strictly satisfy the category axioms, `pre_envel_group` and `pre_envel_group_rel'` do form a weak 2-category. Since we just want a 1-category, the last step is to quotient `pre_envel_group` by `pre_envel_group_rel'`, and the result is the group `envel_group`. For a homomorphism `f : R →◃ conj G`, how does `envel_group.map f : envel_group R →* G` work? Let's think of `G` as being a 2-category with one object, a 1-morphism per element of `G`, and a single 2-morphism called `eq.refl` for each 1-morphism. We define the map using a "higher `quotient.lift`" -- not only do we evaluate elements of `pre_envel_group` as expressions in `G` (this is `to_envel_group.map_aux`), but we evaluate elements of `pre_envel_group'` as expressions of 2-morphisms of `G` (this is `to_envel_group.map_aux.well_def`). That is to say, `to_envel_group.map_aux.well_def` recursively evaluates formal expressions of 2-morphisms as equality proofs in `G`. Now that all morphisms are accounted for, the map descends to a homomorphism `envel_group R →* G`. Note: `Type`-valued relations are not common. The fact it is `Type`-valued is what makes `to_envel_group.map_aux.well_def` have well-founded recursion. -/ /-- Free generators of the enveloping group. -/ inductive pre_envel_group (R : Type u) : Type u | unit : pre_envel_group | incl (x : R) : pre_envel_group | mul (a b : pre_envel_group) : pre_envel_group | inv (a : pre_envel_group) : pre_envel_group instance pre_envel_group.inhabited (R : Type u) : inhabited (pre_envel_group R) := ⟨pre_envel_group.unit⟩ open pre_envel_group /-- Relations for the enveloping group. This is a type-valued relation because `to_envel_group.map_aux.well_def` inducts on it to show `to_envel_group.map` is well-defined. The relation `pre_envel_group_rel` is the `Prop`-valued version, which is used to define `envel_group` itself. -/ inductive pre_envel_group_rel' (R : Type u) [rack R] : pre_envel_group R → pre_envel_group R → Type u | refl {a : pre_envel_group R} : pre_envel_group_rel' a a | symm {a b : pre_envel_group R} (hab : pre_envel_group_rel' a b) : pre_envel_group_rel' b a | trans {a b c : pre_envel_group R} (hab : pre_envel_group_rel' a b) (hbc : pre_envel_group_rel' b c) : pre_envel_group_rel' a c | congr_mul {a b a' b' : pre_envel_group R} (ha : pre_envel_group_rel' a a') (hb : pre_envel_group_rel' b b') : pre_envel_group_rel' (mul a b) (mul a' b') | congr_inv {a a' : pre_envel_group R} (ha : pre_envel_group_rel' a a') : pre_envel_group_rel' (inv a) (inv a') | assoc (a b c : pre_envel_group R) : pre_envel_group_rel' (mul (mul a b) c) (mul a (mul b c)) | one_mul (a : pre_envel_group R) : pre_envel_group_rel' (mul unit a) a | mul_one (a : pre_envel_group R) : pre_envel_group_rel' (mul a unit) a | mul_left_inv (a : pre_envel_group R) : pre_envel_group_rel' (mul (inv a) a) unit | act_incl (x y : R) : pre_envel_group_rel' (mul (mul (incl x) (incl y)) (inv (incl x))) (incl (x ◃ y)) instance pre_envel_group_rel'.inhabited (R : Type u) [rack R] : inhabited (pre_envel_group_rel' R unit unit) := ⟨pre_envel_group_rel'.refl⟩ /-- The `pre_envel_group_rel` relation as a `Prop`. Used as the relation for `pre_envel_group.setoid`. -/ inductive pre_envel_group_rel (R : Type u) [rack R] : pre_envel_group R → pre_envel_group R → Prop | rel {a b : pre_envel_group R} (r : pre_envel_group_rel' R a b) : pre_envel_group_rel a b /-- A quick way to convert a `pre_envel_group_rel'` to a `pre_envel_group_rel`. -/ lemma pre_envel_group_rel'.rel {R : Type u} [rack R] {a b : pre_envel_group R} : pre_envel_group_rel' R a b → pre_envel_group_rel R a b := pre_envel_group_rel.rel @[refl] lemma pre_envel_group_rel.refl {R : Type u} [rack R] {a : pre_envel_group R} : pre_envel_group_rel R a a := pre_envel_group_rel.rel pre_envel_group_rel'.refl @[symm] lemma pre_envel_group_rel.symm {R : Type u} [rack R] {a b : pre_envel_group R} : pre_envel_group_rel R a b → pre_envel_group_rel R b a | ⟨r⟩ := r.symm.rel @[trans] lemma pre_envel_group_rel.trans {R : Type u} [rack R] {a b c : pre_envel_group R} : pre_envel_group_rel R a b → pre_envel_group_rel R b c → pre_envel_group_rel R a c | ⟨rab⟩ ⟨rbc⟩ := (rab.trans rbc).rel instance pre_envel_group.setoid (R : Type*) [rack R] : setoid (pre_envel_group R) := { r := pre_envel_group_rel R, iseqv := begin split, apply pre_envel_group_rel.refl, split, apply pre_envel_group_rel.symm, apply pre_envel_group_rel.trans end } /-- The universal enveloping group for the rack R. -/ def envel_group (R : Type*) [rack R] := quotient (pre_envel_group.setoid R) -- Define the `group` instances in two steps so `inv` can be inferred correctly. -- TODO: is there a non-invasive way of defining the instance directly? instance (R : Type*) [rack R] : div_inv_monoid (envel_group R) := { mul := λ a b, quotient.lift_on₂ a b (λ a b, ⟦pre_envel_group.mul a b⟧) (λ a b a' b' ⟨ha⟩ ⟨hb⟩, quotient.sound (pre_envel_group_rel'.congr_mul ha hb).rel), one := ⟦unit⟧, inv := λ a, quotient.lift_on a (λ a, ⟦pre_envel_group.inv a⟧) (λ a a' ⟨ha⟩, quotient.sound (pre_envel_group_rel'.congr_inv ha).rel), mul_assoc := λ a b c, quotient.induction_on₃ a b c (λ a b c, quotient.sound (pre_envel_group_rel'.assoc a b c).rel), one_mul := λ a, quotient.induction_on a (λ a, quotient.sound (pre_envel_group_rel'.one_mul a).rel), mul_one := λ a, quotient.induction_on a (λ a, quotient.sound (pre_envel_group_rel'.mul_one a).rel),} instance (R : Type*) [rack R] : group (envel_group R) := { mul_left_inv := λ a, quotient.induction_on a (λ a, quotient.sound (pre_envel_group_rel'.mul_left_inv a).rel), .. envel_group.div_inv_monoid _ } instance envel_group.inhabited (R : Type*) [rack R] : inhabited (envel_group R) := ⟨1⟩ /-- The canonical homomorphism from a rack to its enveloping group. Satisfies universal properties given by `to_envel_group.map` and `to_envel_group.univ`. -/ def to_envel_group (R : Type*) [rack R] : R →◃ quandle.conj (envel_group R) := { to_fun := λ x, ⟦incl x⟧, map_act' := λ x y, quotient.sound (pre_envel_group_rel'.act_incl x y).symm.rel } /-- The preliminary definition of the induced map from the enveloping group. See `to_envel_group.map`. -/ def to_envel_group.map_aux {R : Type*} [rack R] {G : Type*} [group G] (f : R →◃ quandle.conj G) : pre_envel_group R → G | unit := 1 | (incl x) := f x | (mul a b) := to_envel_group.map_aux a * to_envel_group.map_aux b | (inv a) := (to_envel_group.map_aux a)⁻¹ namespace to_envel_group.map_aux open pre_envel_group_rel' /-- Show that `to_envel_group.map_aux` sends equivalent expressions to equal terms. -/ lemma well_def {R : Type*} [rack R] {G : Type*} [group G] (f : R →◃ quandle.conj G) : Π {a b : pre_envel_group R}, pre_envel_group_rel' R a b → to_envel_group.map_aux f a = to_envel_group.map_aux f b | a b refl := rfl | a b (symm h) := (well_def h).symm | a b (trans hac hcb) := eq.trans (well_def hac) (well_def hcb) | _ _ (congr_mul ha hb) := by { simp [to_envel_group.map_aux, well_def ha, well_def hb] } | _ _ (congr_inv ha) := by { simp [to_envel_group.map_aux, well_def ha] } | _ _ (assoc a b c) := by { apply mul_assoc } | _ _ (one_mul a) := by { simp [to_envel_group.map_aux] } | _ _ (mul_one a) := by { simp [to_envel_group.map_aux] } | _ _ (mul_left_inv a) := by { simp [to_envel_group.map_aux] } | _ _ (act_incl x y) := by { simp [to_envel_group.map_aux] } end to_envel_group.map_aux /-- Given a map from a rack to a group, lift it to being a map from the enveloping group. More precisely, the `envel_group` functor is left adjoint to `quandle.conj`. -/ def to_envel_group.map {R : Type*} [rack R] {G : Type*} [group G] : (R →◃ quandle.conj G) ≃ (envel_group R →* G) := { to_fun := λ f, { to_fun := λ x, quotient.lift_on x (to_envel_group.map_aux f) (λ a b ⟨hab⟩, to_envel_group.map_aux.well_def f hab), map_one' := begin change quotient.lift_on ⟦rack.pre_envel_group.unit⟧ (to_envel_group.map_aux f) _ = 1, simp [to_envel_group.map_aux], end, map_mul' := λ x y, quotient.induction_on₂ x y (λ x y, begin change quotient.lift_on ⟦mul x y⟧ (to_envel_group.map_aux f) _ = _, simp [to_envel_group.map_aux], end) }, inv_fun := λ F, (quandle.conj.map F).comp (to_envel_group R), left_inv := λ f, by { ext, refl }, right_inv := λ F, monoid_hom.ext $ λ x, quotient.induction_on x $ λ x, begin induction x, { exact F.map_one.symm, }, { refl, }, { have hm : ⟦x_a.mul x_b⟧ = @has_mul.mul (envel_group R) _ ⟦x_a⟧ ⟦x_b⟧ := rfl, rw [hm, F.map_mul, monoid_hom.map_mul, ←x_ih_a, ←x_ih_b] }, { have hm : ⟦x_a.inv⟧ = @has_inv.inv (envel_group R) _ ⟦x_a⟧ := rfl, rw [hm, F.map_inv, monoid_hom.map_inv, x_ih], } end, } /-- Given a homomorphism from a rack to a group, it factors through the enveloping group. -/ lemma to_envel_group.univ (R : Type*) [rack R] (G : Type*) [group G] (f : R →◃ quandle.conj G) : (quandle.conj.map (to_envel_group.map f)).comp (to_envel_group R) = f := to_envel_group.map.symm_apply_apply f /-- The homomorphism `to_envel_group.map f` is the unique map that fits into the commutative triangle in `to_envel_group.univ`. -/ lemma to_envel_group.univ_uniq (R : Type*) [rack R] (G : Type*) [group G] (f : R →◃ quandle.conj G) (g : envel_group R →* G) (h : f = (quandle.conj.map g).comp (to_envel_group R)) : g = to_envel_group.map f := h.symm ▸ (to_envel_group.map.apply_symm_apply g).symm /-- The induced group homomorphism from the enveloping group into bijections of the rack, using `rack.to_conj`. Satisfies the property `envel_action_prop`. This gives the rack `R` the structure of an augmented rack over `envel_group R`. -/ def envel_action {R : Type*} [rack R] : envel_group R →* (R ≃ R) := to_envel_group.map (to_conj R) @[simp] lemma envel_action_prop {R : Type*} [rack R] (x y : R) : envel_action (to_envel_group R x) y = x ◃ y := rfl end envel_group end rack
67d733767e5c62c35d229aced0a7b3d807f83057
b7f22e51856f4989b970961f794f1c435f9b8f78
/hott/algebra/category/precategory.hlean
46748fb390224d7685c7a274d8517ad4eb37f8b0
[ "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
12,413
hlean
/- Copyright (c) 2015 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import types.trunc types.pi arity open eq is_trunc pi equiv namespace category /- Just as in Coq-HoTT we add two redundant fields to precategories: assoc' and id_id. The first is to make (Cᵒᵖ)ᵒᵖ = C definitionally when C is a constructor. The second is to ensure that the functor from the terminal category 1 ⇒ Cᵒᵖ is opposite to the functor 1 ⇒ C. -/ structure precategory [class] (ob : Type) : Type := mk' :: (hom : ob → ob → Type) (comp : Π⦃a b c : ob⦄, hom b c → hom a b → hom a c) (ID : Π (a : ob), hom a a) (assoc : Π ⦃a b c d : ob⦄ (h : hom c d) (g : hom b c) (f : hom a b), comp h (comp g f) = comp (comp h g) f) (assoc' : Π ⦃a b c d : ob⦄ (h : hom c d) (g : hom b c) (f : hom a b), comp (comp h g) f = comp h (comp g f)) (id_left : Π ⦃a b : ob⦄ (f : hom a b), comp !ID f = f) (id_right : Π ⦃a b : ob⦄ (f : hom a b), comp f !ID = f) (id_id : Π (a : ob), comp !ID !ID = ID a) (is_set_hom : Π(a b : ob), is_set (hom a b)) attribute precategory.is_set_hom [instance] infixr ∘ := precategory.comp -- input ⟶ using \--> (this is a different arrow than \-> (→)) infixl [parsing_only] ` ⟶ `:60 := precategory.hom namespace hom infixl ` ⟶ `:60 := precategory.hom -- if you open this namespace, hom a b is printed as a ⟶ b end hom abbreviation hom [unfold 2] := @precategory.hom abbreviation comp [unfold 2] := @precategory.comp abbreviation ID [unfold 2] := @precategory.ID abbreviation assoc [unfold 2] := @precategory.assoc abbreviation assoc' [unfold 2] := @precategory.assoc' abbreviation id_left [unfold 2] := @precategory.id_left abbreviation id_right [unfold 2] := @precategory.id_right abbreviation id_id [unfold 2] := @precategory.id_id abbreviation is_set_hom [unfold 2] := @precategory.is_set_hom definition is_prop_hom_eq {ob : Type} [C : precategory ob] {x y : ob} (f g : x ⟶ y) : is_prop (f = g) := _ -- the constructor you want to use in practice protected definition precategory.mk [constructor] {ob : Type} (hom : ob → ob → Type) [set : Π (a b : ob), is_set (hom a b)] (comp : Π ⦃a b c : ob⦄, hom b c → hom a b → hom a c) (ID : Π (a : ob), hom a a) (ass : Π ⦃a b c d : ob⦄ (h : hom c d) (g : hom b c) (f : hom a b), comp h (comp g f) = comp (comp h g) f) (idl : Π ⦃a b : ob⦄ (f : hom a b), comp (ID b) f = f) (idr : Π ⦃a b : ob⦄ (f : hom a b), comp f (ID a) = f) : precategory ob := precategory.mk' hom comp ID ass (λa b c d h g f, !ass⁻¹) idl idr (λa, !idl) set section basic_lemmas variables {ob : Type} [C : precategory ob] variables {a b c d : ob} {h : c ⟶ d} {g : hom b c} {f f' : hom a b} {i : a ⟶ a} include C definition id [reducible] [unfold 2] := ID a definition id_leftright (f : hom a b) : id ∘ f ∘ id = f := !id_left ⬝ !id_right definition comp_id_eq_id_comp (f : hom a b) : f ∘ id = id ∘ f := !id_right ⬝ !id_left⁻¹ definition id_comp_eq_comp_id (f : hom a b) : id ∘ f = f ∘ id := !id_left ⬝ !id_right⁻¹ definition hom_whisker_left (g : b ⟶ c) (p : f = f') : g ∘ f = g ∘ f' := ap (λx, g ∘ x) p definition hom_whisker_right (g : c ⟶ a) (p : f = f') : f ∘ g = f' ∘ g := ap (λx, x ∘ g) p /- many variants of hom_pathover are defined in .iso and .functor.basic -/ definition left_id_unique (H : Π{b} {f : hom b a}, i ∘ f = f) : i = id := calc i = i ∘ id : by rewrite id_right ... = id : by rewrite H definition right_id_unique (H : Π{b} {f : hom a b}, f ∘ i = f) : i = id := calc i = id ∘ i : by rewrite id_left ... = id : by rewrite H definition homset [reducible] [constructor] (x y : ob) : Set := Set.mk (hom x y) _ end basic_lemmas section squares parameters {ob : Type} [C : precategory ob] local infixl ` ⟶ `:25 := @precategory.hom ob C local infixr ∘ := @precategory.comp ob C _ _ _ definition compose_squares {xa xb xc ya yb yc : ob} {xg : xb ⟶ xc} {xf : xa ⟶ xb} {yg : yb ⟶ yc} {yf : ya ⟶ yb} {wa : xa ⟶ ya} {wb : xb ⟶ yb} {wc : xc ⟶ yc} (xyab : wb ∘ xf = yf ∘ wa) (xybc : wc ∘ xg = yg ∘ wb) : wc ∘ (xg ∘ xf) = (yg ∘ yf) ∘ wa := calc wc ∘ (xg ∘ xf) = (wc ∘ xg) ∘ xf : by rewrite assoc ... = (yg ∘ wb) ∘ xf : by rewrite xybc ... = yg ∘ (wb ∘ xf) : by rewrite assoc ... = yg ∘ (yf ∘ wa) : by rewrite xyab ... = (yg ∘ yf) ∘ wa : by rewrite assoc definition compose_squares_2x2 {xa xb xc ya yb yc za zb zc : ob} {xg : xb ⟶ xc} {xf : xa ⟶ xb} {yg : yb ⟶ yc} {yf : ya ⟶ yb} {zg : zb ⟶ zc} {zf : za ⟶ zb} {va : ya ⟶ za} {vb : yb ⟶ zb} {vc : yc ⟶ zc} {wa : xa ⟶ ya} {wb : xb ⟶ yb} {wc : xc ⟶ yc} (xyab : wb ∘ xf = yf ∘ wa) (xybc : wc ∘ xg = yg ∘ wb) (yzab : vb ∘ yf = zf ∘ va) (yzbc : vc ∘ yg = zg ∘ vb) : (vc ∘ wc) ∘ (xg ∘ xf) = (zg ∘ zf) ∘ (va ∘ wa) := calc (vc ∘ wc) ∘ (xg ∘ xf) = vc ∘ (wc ∘ (xg ∘ xf)) : by rewrite (assoc vc wc _) ... = vc ∘ ((yg ∘ yf) ∘ wa) : by rewrite (compose_squares xyab xybc) ... = (vc ∘ (yg ∘ yf)) ∘ wa : by rewrite assoc ... = ((zg ∘ zf) ∘ va) ∘ wa : by rewrite (compose_squares yzab yzbc) ... = (zg ∘ zf) ∘ (va ∘ wa) : by rewrite assoc definition square_precompose {xa xb xc yb yc : ob} {xg : xb ⟶ xc} {yg : yb ⟶ yc} {wb : xb ⟶ yb} {wc : xc ⟶ yc} (H : wc ∘ xg = yg ∘ wb) (xf : xa ⟶ xb) : wc ∘ xg ∘ xf = yg ∘ wb ∘ xf := calc wc ∘ xg ∘ xf = (wc ∘ xg) ∘ xf : by rewrite assoc ... = (yg ∘ wb) ∘ xf : by rewrite H ... = yg ∘ wb ∘ xf : by rewrite assoc definition square_postcompose {xb xc yb yc yd : ob} {xg : xb ⟶ xc} {yg : yb ⟶ yc} {wb : xb ⟶ yb} {wc : xc ⟶ yc} (H : wc ∘ xg = yg ∘ wb) (yh : yc ⟶ yd) : (yh ∘ wc) ∘ xg = (yh ∘ yg) ∘ wb := calc (yh ∘ wc) ∘ xg = yh ∘ wc ∘ xg : by rewrite assoc ... = yh ∘ yg ∘ wb : by rewrite H ... = (yh ∘ yg) ∘ wb : by rewrite assoc definition square_prepostcompose {xa xb xc yb yc yd : ob} {xg : xb ⟶ xc} {yg : yb ⟶ yc} {wb : xb ⟶ yb} {wc : xc ⟶ yc} (H : wc ∘ xg = yg ∘ wb) (yh : yc ⟶ yd) (xf : xa ⟶ xb) : (yh ∘ wc) ∘ (xg ∘ xf) = (yh ∘ yg) ∘ (wb ∘ xf) := square_precompose (square_postcompose H yh) xf end squares structure Precategory : Type := (carrier : Type) (struct : precategory carrier) definition precategory.Mk [reducible] [constructor] {ob} (C) : Precategory := Precategory.mk ob C definition precategory.MK [reducible] [constructor] (a b c d e f g h) : Precategory := Precategory.mk a (@precategory.mk a b c d e f g h) abbreviation carrier [unfold 1] := @Precategory.carrier attribute Precategory.carrier [coercion] attribute Precategory.struct [instance] [priority 10000] [coercion] -- definition precategory.carrier [coercion] [reducible] := Precategory.carrier -- definition precategory.struct [instance] [coercion] := Precategory.struct notation g ` ∘[`:60 C:0 `] `:0 f:60 := @comp (Precategory.carrier C) (Precategory.struct C) _ _ _ g f -- TODO: make this left associative definition Precategory.eta (C : Precategory) : Precategory.mk C C = C := Precategory.rec (λob c, idp) C /-Characterization of paths between precategories-/ -- introduction tule for paths between precategories definition precategory_eq {ob : Type} {C D : precategory ob} (p : Π{a b}, @hom ob C a b = @hom ob D a b) (q : Πa b c g f, cast p (@comp ob C a b c g f) = @comp ob D a b c (cast p g) (cast p f)) : C = D := begin induction C with hom1 comp1 ID1 a b il ir, induction D with hom2 comp2 ID2 a' b' il' ir', esimp at *, revert q, eapply homotopy2.rec_on @p, esimp, clear p, intro p q, induction p, esimp at *, have H : comp1 = comp2, begin apply eq_of_homotopy3, intros, apply eq_of_homotopy2, intros, apply q end, induction H, have K : ID1 = ID2, begin apply eq_of_homotopy, intro a, exact !ir'⁻¹ ⬝ !il end, induction K, apply ap0111111 (precategory.mk' hom1 comp1 ID1): apply is_prop.elim end definition precategory_eq_of_equiv {ob : Type} {C D : precategory ob} (p : Π⦃a b⦄, @hom ob C a b ≃ @hom ob D a b) (q : Π{a b c} g f, p (@comp ob C a b c g f) = @comp ob D a b c (p g) (p f)) : C = D := begin fapply precategory_eq, { intro a b, exact ua !@p}, { intros, refine !cast_ua ⬝ !q ⬝ _, apply ap011 !@comp !cast_ua⁻¹ !cast_ua⁻¹}, end /- if we need to prove properties about precategory_eq, it might be easier with the following proof: begin induction C with hom1 comp1 ID1, induction D with hom2 comp2 ID2, esimp at *, have H : Σ(s : hom1 = hom2), (λa b, equiv_of_eq (apd100 s a b)) = p, begin fconstructor, { apply eq_of_homotopy2, intros, apply ua, apply p}, { apply eq_of_homotopy2, intros, rewrite [to_right_inv !eq_equiv_homotopy2, equiv_of_eq_ua]} end, induction H with H1 H2, induction H1, esimp at H2, have K : (λa b, equiv.refl) = p, begin refine _ ⬝ H2, apply eq_of_homotopy2, intros, exact !equiv_of_eq_refl⁻¹ end, induction K, clear H2, esimp at *, have H : comp1 = comp2, begin apply eq_of_homotopy3, intros, apply eq_of_homotopy2, intros, apply q end, have K : ID1 = ID2, begin apply eq_of_homotopy, intros, apply r end, induction H, induction K, apply ap0111111 (precategory.mk' hom1 comp1 ID1): apply is_prop.elim end -/ definition Precategory_eq {C D : Precategory} (p : carrier C = carrier D) (q : Π{a b : C}, a ⟶ b = cast p a ⟶ cast p b) (r : Π{a b c : C} (g : b ⟶ c) (f : a ⟶ b), cast q (g ∘ f) = cast q g ∘ cast q f) : C = D := begin induction C with X C, induction D with Y D, esimp at *, induction p, esimp at *, apply ap (Precategory.mk X), apply precategory_eq @q @r end definition Precategory_eq_of_equiv {C D : Precategory} (p : carrier C ≃ carrier D) (q : Π⦃a b : C⦄, a ⟶ b ≃ p a ⟶ p b) (r : Π{a b c : C} (g : b ⟶ c) (f : a ⟶ b), q (g ∘ f) = q g ∘ q f) : C = D := begin induction C with X C, induction D with Y D, esimp at *, revert q r, eapply equiv.rec_on_ua p, clear p, intro p, induction p, esimp, intros, apply ap (Precategory.mk X), apply precategory_eq_of_equiv @q @r end -- elimination rules for paths between precategories. -- The first elimination rule is "ap carrier" definition Precategory_eq_hom [unfold 3] {C D : Precategory} (p : C = D) (a b : C) : hom a b = hom (cast (ap carrier p) a) (cast (ap carrier p) b) := by induction p; reflexivity --(ap10 (ap10 (apdt (λx, @hom (carrier x) (Precategory.struct x)) p⁻¹ᵖ) a) b)⁻¹ᵖ ⬝ _ -- beta/eta rules definition ap_Precategory_eq' {C D : Precategory} (p : carrier C = carrier D) (q : Π{a b : C}, a ⟶ b = cast p a ⟶ cast p b) (r : Π{a b c : C} (g : b ⟶ c) (f : a ⟶ b), cast q (g ∘ f) = cast q g ∘ cast q f) (s : Πa, cast q (ID a) = ID (cast p a)) : ap carrier (Precategory_eq p @q @r) = p := begin induction C with X C, induction D with Y D, esimp at *, induction p, rewrite [↑Precategory_eq, -ap_compose,↑function.compose,ap_constant] end /- theorem Precategory_eq'_eta {C D : Precategory} (p : C = D) : Precategory_eq (ap carrier p) (Precategory_eq_hom p) (by induction p; intros; reflexivity) = p := begin induction p, induction C with X C, unfold Precategory_eq, induction C, unfold precategory_eq, exact sorry end -/ /- theorem Precategory_eq2 {C D : Precategory} (p q : C = D) (r : ap carrier p = ap carrier q) (s : Precategory_eq_hom p =[r] Precategory_eq_hom q) : p = q := begin end -/ end category
732046c1f0db564c60556f6cb7df0dfcfc4e40b0
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
/tests/lean/lua18.lean
739fc999219c5bbfa6424a32f46040303e5b9cff
[ "Apache-2.0" ]
permissive
codyroux/lean0.1
1ce92751d664aacff0529e139083304a7bbc8a71
0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef
refs/heads/master
1,610,830,535,062
1,402,150,480,000
1,402,150,480,000
19,588,851
2
0
null
null
null
null
UTF-8
Lean
false
false
587
lean
import Int. (* macro("MyMacro", { macro_arg.Expr, macro_arg.Comma, macro_arg.Expr }, function (env, e1, e2) return Const({"Int", "add"})(e1, e2) end) macro("Sum", { macro_arg.Exprs }, function (env, es) if #es == 0 then return iVal(0) end local r = es[1] local add = Const({"Int", "add"}) for i = 2, #es do r = add(r, es[i]) end return r end) *) print (MyMacro 10, 20) + 20 print (Sum) print Sum 10 20 30 40 print fun x, Sum x 10 x 20 eval (fun x, Sum x 10 x 20) 100
7153805bd3621f1fae781388003ab52b225a97f8
63abd62053d479eae5abf4951554e1064a4c45b4
/src/data/fin.lean
81358af99cd58b9d669bc23fa1dc16ace9816d06
[ "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
42,368
lean
/- Copyright (c) 2017 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Keeley Hoek -/ import data.nat.cast import tactic.localized import logic.embedding /-! # The finite type with `n` elements `fin n` is the type whose elements are natural numbers smaller than `n`. This file expands on the development in the core library. ## Main definitions ### Induction principles * `fin_zero_elim` : Elimination principle for the empty set `fin 0`, generalizes `fin.elim0`. * `fin.succ_rec` : Define `C n i` by induction on `i : fin n` interpreted as `(0 : fin (n - i)).succ.succ…`. This function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple, and `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element of `n`-tuple. * `fin.succ_rec_on` : same as `fin.succ_rec` but `i : fin n` is the first argument; * `fin.induction` : Define `C i` by induction on `i : fin (n + 1)`, separating into the `nat`-like base cases of `C 0` and `C (i.succ)`. * `fin.induction_on` : same as `fin.induction` but with `i : fin (n + 1)` as the first argument. ### Casts * `cast_lt i h` : embed `i` into a `fin` where `h` proves it belongs into; * `cast_le h` : embed `fin n` into `fin m`, `h : n ≤ m`; * `cast eq` : embed `fin n` into `fin m`, `eq : n = m`; * `cast_add m` : embed `fin n` into `fin (n+m)`; * `cast_succ` : embed `fin n` into `fin (n+1)`; * `succ_above p` : embed `fin n` into `fin (n + 1)` with a hole around `p`; * `pred_above p i h` : embed `i : fin (n+1)` into `fin n` by ignoring `p`; * `sub_nat i h` : subtract `m` from `i ≥ m`, generalizes `fin.pred`; * `add_nat i h` : add `m` on `i` on the right, generalizes `fin.succ`; * `nat_add i h` adds `n` on `i` on the left; * `clamp n m` : `min n m` as an element of `fin (m + 1)`; ### Operation on tuples We interpret maps `Π i : fin n, α i` as tuples `(α 0, …, α (n-1))`. If `α i` is a constant map, then tuples are isomorphic (but not definitionally equal) to `vector`s. We define the following operations: * `tail` : the tail of an `n+1` tuple, i.e., its last `n` entries; * `cons` : adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple; * `init` : the beginning of an `n+1` tuple, i.e., its first `n` entries; * `snoc` : adding an element at the end of an `n`-tuple, to get an `n+1`-tuple. The name `snoc` comes from `cons` (i.e., adding an element to the left of a tuple) read in reverse order. * `find p` : returns the first index `n` where `p n` is satisfied, and `none` if it is never satisfied. ### Misc definitions * `fin.last n` : The greatest value of `fin (n+1)`. -/ universe u open fin nat function /-- Elimination principle for the empty set `fin 0`, dependent version. -/ def fin_zero_elim {α : fin 0 → Sort u} (x : fin 0) : α x := x.elim0 lemma fact.succ.pos {n} : fact (0 < succ n) := zero_lt_succ _ lemma fact.bit0.pos {n} [h : fact (0 < n)] : fact (0 < bit0 n) := nat.zero_lt_bit0 $ ne_of_gt h lemma fact.bit1.pos {n} : fact (0 < bit1 n) := nat.zero_lt_bit1 _ lemma fact.pow.pos {p n : ℕ} [h : fact $ 0 < p] : fact (0 < p ^ n) := pow_pos h _ localized "attribute [instance] fact.succ.pos" in fin_fact localized "attribute [instance] fact.bit0.pos" in fin_fact localized "attribute [instance] fact.bit1.pos" in fin_fact localized "attribute [instance] fact.pow.pos" in fin_fact namespace fin variables {n m : ℕ} {a b : fin n} instance fin_to_nat (n : ℕ) : has_coe (fin n) nat := ⟨subtype.val⟩ lemma is_lt (i : fin n) : (i : ℕ) < n := i.2 /-- convert a `ℕ` to `fin n`, provided `n` is positive -/ def of_nat' [h : fact (0 < n)] (i : ℕ) : fin n := ⟨i%n, mod_lt _ h⟩ @[simp] protected lemma eta (a : fin n) (h : (a : ℕ) < n) : (⟨(a : ℕ), h⟩ : fin n) = a := by cases a; refl @[ext] lemma ext {a b : fin n} (h : (a : ℕ) = b) : a = b := eq_of_veq h lemma ext_iff (a b : fin n) : a = b ↔ (a : ℕ) = b := iff.intro (congr_arg _) fin.eq_of_veq lemma coe_injective {n : ℕ} : injective (coe : fin n → ℕ) := subtype.coe_injective lemma eq_iff_veq (a b : fin n) : a = b ↔ a.1 = b.1 := ⟨veq_of_eq, eq_of_veq⟩ lemma ne_iff_vne (a b : fin n) : a ≠ b ↔ a.1 ≠ b.1 := ⟨vne_of_ne, ne_of_vne⟩ @[simp] lemma mk_eq_subtype_mk (a : ℕ) (h : a < n) : mk a h = ⟨a, h⟩ := rfl protected lemma mk.inj_iff {n a b : ℕ} {ha : a < n} {hb : b < n} : (⟨a, ha⟩ : fin n) = ⟨b, hb⟩ ↔ a = b := ⟨subtype.mk.inj, λ h, by subst h⟩ lemma mk_val {m n : ℕ} (h : m < n) : (⟨m, h⟩ : fin n).val = m := rfl lemma eq_mk_iff_coe_eq {k : ℕ} {hk : k < n} : a = ⟨k, hk⟩ ↔ (a : ℕ) = k := fin.eq_iff_veq a ⟨k, hk⟩ @[simp, norm_cast] lemma coe_mk {m n : ℕ} (h : m < n) : ((⟨m, h⟩ : fin n) : ℕ) = m := rfl lemma mk_coe (i : fin n) : (⟨i, i.is_lt⟩ : fin n) = i := fin.eta _ _ lemma coe_eq_val (a : fin n) : (a : ℕ) = a.val := rfl @[simp] lemma val_eq_coe (a : fin n) : a.val = a := rfl attribute [simp] val_zero @[simp] lemma val_one {n : ℕ} : (1 : fin (n+2)).val = 1 := rfl @[simp] lemma val_two {n : ℕ} : (2 : fin (n+3)).val = 2 := rfl @[simp] lemma coe_zero {n : ℕ} : ((0 : fin (n+1)) : ℕ) = 0 := rfl @[simp] lemma coe_one {n : ℕ} : ((1 : fin (n+2)) : ℕ) = 1 := rfl @[simp] lemma coe_two {n : ℕ} : ((2 : fin (n+3)) : ℕ) = 2 := rfl /-- `a < b` as natural numbers if and only if `a < b` in `fin n`. -/ @[norm_cast, simp] lemma coe_fin_lt {n : ℕ} {a b : fin n} : (a : ℕ) < (b : ℕ) ↔ a < b := iff.rfl /-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `fin n`. -/ @[norm_cast, simp] lemma coe_fin_le {n : ℕ} {a b : fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b := iff.rfl lemma val_add {n : ℕ} : ∀ a b : fin n, (a + b).val = (a.val + b.val) % n | ⟨_, _⟩ ⟨_, _⟩ := rfl lemma coe_add {n : ℕ} : ∀ a b : fin n, ((a + b : fin n) : ℕ) = (a + b) % n | ⟨_, _⟩ ⟨_, _⟩ := rfl lemma val_mul {n : ℕ} : ∀ a b : fin n, (a * b).val = (a.val * b.val) % n | ⟨_, _⟩ ⟨_, _⟩ := rfl lemma coe_mul {n : ℕ} : ∀ a b : fin n, ((a * b : fin n) : ℕ) = (a * b) % n | ⟨_, _⟩ ⟨_, _⟩ := rfl lemma one_val {n : ℕ} : (1 : fin (n+1)).val = 1 % (n+1) := rfl lemma coe_one' {n : ℕ} : ((1 : fin (n+1)) : ℕ) = 1 % (n+1) := rfl @[simp] lemma val_zero' (n) : (0 : fin (n+1)).val = 0 := rfl @[simp] lemma mk_zero : (⟨0, nat.succ_pos'⟩ : fin (n + 1)) = (0 : fin _) := rfl @[simp] lemma mk_one : (⟨1, nat.succ_lt_succ (nat.succ_pos n)⟩ : fin (n + 2)) = (1 : fin _) := rfl section bit @[simp] lemma mk_bit0 {m n : ℕ} (h : bit0 m < n) : (⟨bit0 m, h⟩ : fin n) = (bit0 ⟨m, (nat.le_add_right m m).trans_lt h⟩ : fin _) := eq_of_veq (nat.mod_eq_of_lt h).symm @[simp] lemma mk_bit1 {m n : ℕ} (h : bit1 m < n + 1) : (⟨bit1 m, h⟩ : fin (n + 1)) = (bit1 ⟨m, (nat.le_add_right m m).trans_lt ((m + m).lt_succ_self.trans h)⟩ : fin _) := begin ext, simp only [bit1, bit0] at h, simp only [bit1, bit0, coe_add, coe_one', coe_mk, ←nat.add_mod, nat.mod_eq_of_lt h], end end bit @[simp] lemma of_nat_eq_coe (n : ℕ) (a : ℕ) : (of_nat a : fin (n+1)) = a := begin induction a with a ih, { refl }, ext, show (a+1) % (n+1) = subtype.val (a+1 : fin (n+1)), { rw [val_add, ← ih, of_nat], exact add_mod _ _ _ } end /-- Converting an in-range number to `fin (n + 1)` produces a result whose value is the original number. -/ lemma coe_val_of_lt {n : ℕ} {a : ℕ} (h : a < n + 1) : ((a : fin (n + 1)).val) = a := begin rw ←of_nat_eq_coe, exact nat.mod_eq_of_lt h end /-- Converting the value of a `fin (n + 1)` to `fin (n + 1)` results in the same value. -/ lemma coe_val_eq_self {n : ℕ} (a : fin (n + 1)) : (a.val : fin (n + 1)) = a := begin rw fin.eq_iff_veq, exact coe_val_of_lt a.property end /-- Coercing an in-range number to `fin (n + 1)`, and converting back to `ℕ`, results in that number. -/ lemma coe_coe_of_lt {n : ℕ} {a : ℕ} (h : a < n + 1) : ((a : fin (n + 1)) : ℕ) = a := coe_val_of_lt h /-- Converting a `fin (n + 1)` to `ℕ` and back results in the same value. -/ @[simp] lemma coe_coe_eq_self {n : ℕ} (a : fin (n + 1)) : ((a : ℕ) : fin (n + 1)) = a := coe_val_eq_self a /-- Assume `k = l`. If two functions defined on `fin k` and `fin l` are equal on each element, then they coincide (in the heq sense). -/ protected lemma heq_fun_iff {α : Type*} {k l : ℕ} (h : k = l) {f : fin k → α} {g : fin l → α} : f == g ↔ (∀ (i : fin k), f i = g ⟨(i : ℕ), h ▸ i.2⟩) := by { induction h, simp [heq_iff_eq, function.funext_iff] } protected lemma heq_ext_iff {k l : ℕ} (h : k = l) {i : fin k} {j : fin l} : i == j ↔ (i : ℕ) = (j : ℕ) := by { induction h, simp [ext_iff] } instance {n : ℕ} : nontrivial (fin (n + 2)) := ⟨⟨0, 1, dec_trivial⟩⟩ instance {n : ℕ} : linear_order (fin n) := { le := (≤), lt := (<), decidable_le := fin.decidable_le, decidable_lt := fin.decidable_lt, decidable_eq := fin.decidable_eq _, ..linear_order.lift (coe : fin n → ℕ) (@fin.eq_of_veq _) } lemma exists_iff {p : fin n → Prop} : (∃ i, p i) ↔ ∃ i h, p ⟨i, h⟩ := ⟨λ h, exists.elim h (λ ⟨i, hi⟩ hpi, ⟨i, hi, hpi⟩), λ h, exists.elim h (λ i hi, ⟨⟨i, hi.fst⟩, hi.snd⟩)⟩ lemma forall_iff {p : fin n → Prop} : (∀ i, p i) ↔ ∀ i h, p ⟨i, h⟩ := ⟨λ h i hi, h ⟨i, hi⟩, λ h ⟨i, hi⟩, h i hi⟩ lemma lt_iff_coe_lt_coe : a < b ↔ (a : ℕ) < b := iff.rfl lemma le_iff_coe_le_coe : a ≤ b ↔ (a : ℕ) ≤ b := iff.rfl lemma zero_le (a : fin (n + 1)) : 0 ≤ a := zero_le a.1 @[simp] lemma coe_succ (j : fin n) : (j.succ : ℕ) = j + 1 := by cases j; simp [fin.succ] lemma succ_pos (a : fin n) : (0 : fin (n + 1)) < a.succ := by simp [lt_iff_coe_lt_coe] protected theorem succ.inj (p : fin.succ a = fin.succ b) : a = b := by cases a; cases b; exact eq_of_veq (nat.succ.inj (veq_of_eq p)) @[simp] lemma succ_inj {a b : fin n} : a.succ = b.succ ↔ a = b := ⟨λh, succ.inj h, λh, by rw h⟩ @[simp] lemma succ_le_succ_iff : a.succ ≤ b.succ ↔ a ≤ b := by { simp only [le_iff_coe_le_coe, coe_succ], exact ⟨le_of_succ_le_succ, succ_le_succ⟩ } @[simp] lemma succ_lt_succ_iff : a.succ < b.succ ↔ a < b := by { simp only [lt_iff_coe_lt_coe, coe_succ], exact ⟨lt_of_succ_lt_succ, succ_lt_succ⟩ } lemma succ_injective (n : ℕ) : injective (@fin.succ n) := λa b, succ.inj lemma succ_ne_zero {n} : ∀ k : fin n, fin.succ k ≠ 0 | ⟨k, hk⟩ heq := nat.succ_ne_zero k $ (ext_iff _ _).1 heq @[simp] lemma succ_zero_eq_one : fin.succ (0 : fin (n + 1)) = 1 := rfl lemma mk_succ_pos (i : ℕ) (h : i < n) : (0 : fin (n + 1)) < ⟨i.succ, add_lt_add_right h 1⟩ := by { rw [lt_iff_coe_lt_coe, coe_zero], exact nat.succ_pos i } lemma one_lt_succ_succ (a : fin n) : (1 : fin (n + 2)) < a.succ.succ := by { cases n, { exact fin_zero_elim a }, { rw [←succ_zero_eq_one, succ_lt_succ_iff], exact succ_pos a } } lemma succ_succ_ne_one (a : fin n) : fin.succ (fin.succ a) ≠ 1 := ne_of_gt (one_lt_succ_succ a) @[simp] lemma coe_pred (j : fin (n+1)) (h : j ≠ 0) : (j.pred h : ℕ) = j - 1 := by { cases j, refl } @[simp] lemma succ_pred : ∀(i : fin (n+1)) (h : i ≠ 0), (i.pred h).succ = i | ⟨0, h⟩ hi := by contradiction | ⟨n + 1, h⟩ hi := rfl @[simp] lemma pred_succ (i : fin n) {h : i.succ ≠ 0} : i.succ.pred h = i := by { cases i, refl } @[simp] lemma pred_mk_succ (i : ℕ) (h : i < n + 1) : fin.pred ⟨i + 1, add_lt_add_right h 1⟩ (ne_of_vne (ne_of_gt (mk_succ_pos i h))) = ⟨i, h⟩ := by simp only [ext_iff, coe_pred, coe_mk, nat.add_sub_cancel] @[simp] lemma pred_inj : ∀ {a b : fin (n + 1)} {ha : a ≠ 0} {hb : b ≠ 0}, a.pred ha = b.pred hb ↔ a = b | ⟨0, _⟩ b ha hb := by contradiction | ⟨i+1, _⟩ ⟨0, _⟩ ha hb := by contradiction | ⟨i+1, hi⟩ ⟨j+1, hj⟩ ha hb := by simp [fin.eq_iff_veq] /-- The greatest value of `fin (n+1)` -/ def last (n : ℕ) : fin (n+1) := ⟨_, n.lt_succ_self⟩ /-- `cast_lt i h` embeds `i` into a `fin` where `h` proves it belongs into. -/ def cast_lt (i : fin m) (h : i.1 < n) : fin n := ⟨i.1, h⟩ /-- `cast_le h i` embeds `i` into a larger `fin` type. -/ def cast_le (h : n ≤ m) (a : fin n) : fin m := cast_lt a (lt_of_lt_of_le a.2 h) /-- `cast eq i` embeds `i` into a equal `fin` type. -/ def cast (eq : n = m) : fin n → fin m := cast_le $ le_of_eq eq /-- `cast_add m i` embeds `i : fin n` in `fin (n+m)`. -/ def cast_add (m) : fin n → fin (n + m) := cast_le $ le_add_right n m /-- `cast_succ i` embeds `i : fin n` in `fin (n+1)`. -/ def cast_succ : fin n → fin (n + 1) := cast_add 1 /-- `succ_above p i` embeds `fin n` into `fin (n + 1)` with a hole around `p`. -/ def succ_above (p : fin (n + 1)) (i : fin n) : fin (n + 1) := if i.cast_succ < p then i.cast_succ else i.succ /-- `pred_above p i h` embeds `i : fin (n+1)` into `fin n` by ignoring `p`. -/ def pred_above (p : fin (n+1)) (i : fin (n+1)) (hi : i ≠ p) : fin n := if h : i < p then i.cast_lt (lt_of_lt_of_le h $ nat.le_of_lt_succ p.2) else i.pred $ have p < i, from lt_of_le_of_ne (le_of_not_gt h) hi.symm, ne_of_gt (lt_of_le_of_lt (zero_le p) this) /-- `sub_nat i h` subtracts `m` from `i`, generalizes `fin.pred`. -/ def sub_nat (m) (i : fin (n + m)) (h : m ≤ (i : ℕ)) : fin n := ⟨(i : ℕ) - m, by { rw [nat.sub_lt_right_iff_lt_add h], exact i.is_lt }⟩ /-- `add_nat i h` adds `m` on `i`, generalizes `fin.succ`. -/ def add_nat (m) (i : fin n) : fin (n + m) := ⟨(i : ℕ) + m, add_lt_add_right i.2 _⟩ /-- `nat_add i h` adds `n` on `i` -/ def nat_add (n) {m} (i : fin m) : fin (n + m) := ⟨n + (i : ℕ), add_lt_add_left i.2 _⟩ theorem le_last (i : fin (n+1)) : i ≤ last n := le_of_lt_succ i.is_lt @[simp] lemma coe_cast (k : fin n) (h : n = m) : (fin.cast h k : ℕ) = k := rfl @[simp] lemma coe_cast_succ (k : fin n) : (k.cast_succ : ℕ) = k := rfl @[simp] lemma coe_cast_lt (k : fin m) (h : (k : ℕ) < n) : (k.cast_lt h : ℕ) = k := rfl @[simp] lemma coe_cast_le (k : fin m) (h : m ≤ n) : (k.cast_le h : ℕ) = k := rfl @[simp] lemma coe_cast_add (k : fin m) : (k.cast_add n : ℕ) = k := rfl lemma last_val (n : ℕ) : (last n).val = n := rfl @[simp, norm_cast] lemma coe_last {n : ℕ} : (last n : ℕ) = n := rfl @[simp] lemma succ_last (n : ℕ) : (last n).succ = last (n.succ) := rfl @[simp] lemma cast_succ_cast_lt (i : fin (n + 1)) (h : (i : ℕ) < n) : cast_succ (cast_lt i h) = i := fin.eq_of_veq rfl @[simp] lemma cast_lt_cast_succ {n : ℕ} (a : fin n) (h : (a : ℕ) < n) : cast_lt (cast_succ a) h = a := by cases a; refl @[simp] lemma coe_sub_nat (i : fin (n + m)) (h : m ≤ i) : (i.sub_nat m h : ℕ) = i - m := rfl @[simp] lemma coe_add_nat (i : fin (n + m)) : (i.add_nat m : ℕ) = i + m := rfl @[simp] lemma cast_succ_inj {a b : fin n} : a.cast_succ = b.cast_succ ↔ a = b := by simp [eq_iff_veq] lemma cast_succ_lt_last (a : fin n) : cast_succ a < last n := lt_iff_coe_lt_coe.mpr a.is_lt @[simp] lemma cast_succ_zero : cast_succ (0 : fin (n + 1)) = 0 := rfl /-- `cast_succ i` is positive when `i` is positive -/ lemma cast_succ_pos (i : fin (n + 1)) (h : 0 < i) : 0 < cast_succ i := by simpa [lt_iff_coe_lt_coe] using h lemma last_pos : (0 : fin (n + 2)) < last (n + 1) := by simp [lt_iff_coe_lt_coe] lemma coe_nat_eq_last (n) : (n : fin (n + 1)) = fin.last n := by { rw [←fin.of_nat_eq_coe, fin.of_nat, fin.last], simp only [nat.mod_eq_of_lt n.lt_succ_self] } lemma le_coe_last (i : fin (n + 1)) : i ≤ n := by { rw fin.coe_nat_eq_last, exact fin.le_last i } lemma eq_last_of_not_lt {i : fin (n+1)} (h : ¬ (i : ℕ) < n) : i = last n := le_antisymm (le_last i) (not_lt.1 h) lemma add_one_pos (i : fin (n + 1)) (h : i < fin.last n) : (0 : fin (n + 1)) < i + 1 := begin cases n, { exact absurd h (nat.not_lt_zero _) }, { rw [lt_iff_coe_lt_coe, coe_last, ←add_lt_add_iff_right 1] at h, rw [lt_iff_coe_lt_coe, coe_add, coe_zero, coe_one, nat.mod_eq_of_lt h], exact nat.zero_lt_succ _ } end lemma one_pos : (0 : fin (n + 2)) < 1 := succ_pos 0 lemma zero_ne_one : (0 : fin (n + 2)) ≠ 1 := ne_of_lt one_pos @[simp] lemma zero_eq_one_iff : (0 : fin (n + 1)) = 1 ↔ n = 0 := begin split, { cases n; intro h, { refl }, { have := zero_ne_one, contradiction } }, { rintro rfl, refl } end @[simp] lemma one_eq_zero_iff : (1 : fin (n + 1)) = 0 ↔ n = 0 := by rw [eq_comm, zero_eq_one_iff] lemma cast_succ_fin_succ (n : ℕ) (j : fin n) : cast_succ (fin.succ j) = fin.succ (cast_succ j) := by { simp [fin.ext_iff], } lemma cast_succ_lt_succ (i : fin n) : i.cast_succ < i.succ := by { rw [lt_iff_coe_lt_coe, cast_succ, coe_cast_add, coe_succ], exact lt_add_one _ } @[norm_cast, simp] lemma coe_eq_cast_succ : (a : fin (n + 1)) = a.cast_succ := begin rw [cast_succ, cast_add, cast_le, cast_lt, eq_iff_veq], exact coe_val_of_lt (nat.lt.step a.is_lt), end @[simp] lemma coe_succ_eq_succ : a.cast_succ + 1 = a.succ := begin cases n, { exact fin_zero_elim a }, { simp [a.is_lt, eq_iff_veq, add_def, nat.mod_eq_of_lt] } end lemma lt_succ : a.cast_succ < a.succ := by { rw [cast_succ, lt_iff_coe_lt_coe, coe_cast_add, coe_succ], exact lt_add_one a.val } @[simp] lemma pred_one {n : ℕ} : fin.pred (1 : fin (n + 2)) (ne.symm (ne_of_lt one_pos)) = 0 := rfl lemma pred_add_one (i : fin (n + 2)) (h : (i : ℕ) < n + 1) : pred (i + 1) (ne_of_gt (add_one_pos _ (lt_iff_coe_lt_coe.mpr h))) = cast_lt i h := begin rw [ext_iff, coe_pred, coe_cast_lt, coe_add, coe_one, mod_eq_of_lt, nat.add_sub_cancel], exact add_lt_add_right h 1, end /-- `min n m` as an element of `fin (m + 1)` -/ def clamp (n m : ℕ) : fin (m + 1) := of_nat $ min n m @[simp] lemma coe_clamp (n m : ℕ) : (clamp n m : ℕ) = min n m := nat.mod_eq_of_lt $ nat.lt_succ_iff.mpr $ min_le_right _ _ lemma cast_le_injective {n₁ n₂ : ℕ} (h : n₁ ≤ n₂) : injective (fin.cast_le h) | ⟨i₁, h₁⟩ ⟨i₂, h₂⟩ eq := fin.eq_of_veq $ show i₁ = i₂, from fin.veq_of_eq eq lemma cast_succ_injective (n : ℕ) : injective (@fin.cast_succ n) := cast_le_injective (le_add_right n 1) /-- Embedding `i : fin n` into `fin (n + 1)` with a hole around `p : fin (n + 1)` embeds `i` by `cast_succ` when the resulting `i.cast_succ < p` -/ lemma succ_above_below (p : fin (n + 1)) (i : fin n) (h : i.cast_succ < p) : p.succ_above i = i.cast_succ := by { rw [succ_above], exact if_pos h } /-- Embedding `fin n` into `fin (n + 1)` with a hole around zero embeds by `succ` -/ @[simp] lemma succ_above_zero : succ_above (0 : fin (n + 1)) = fin.succ := rfl /-- Embedding `fin n` into `fin (n + 1)` with a whole around `last n` embeds by `cast_succ` -/ @[simp] lemma succ_above_last : succ_above (fin.last n) = cast_succ := by { ext, simp only [succ_above, cast_succ_lt_last, if_true] } /-- Embedding `i : fin n` into `fin (n + 1)` with a hole around `p : fin (n + 1)` embeds `i` by `succ` when the resulting `p < i.succ` -/ lemma succ_above_above (p : fin (n + 1)) (i : fin n) (h : p ≤ i.cast_succ) : p.succ_above i = i.succ := by { rw [succ_above], exact if_neg (not_lt_of_le h) } /-- Embedding `i : fin n` into `fin (n + 1)` is always about some hole `p` -/ lemma succ_above_lt_ge (p : fin (n + 1)) (i : fin n) : i.cast_succ < p ∨ p ≤ i.cast_succ := lt_or_ge (cast_succ i) p /-- Embedding `i : fin n` into `fin (n + 1)` is always about some hole `p` -/ lemma succ_above_lt_gt (p : fin (n + 1)) (i : fin n) : i.cast_succ < p ∨ p < i.succ := or.cases_on (succ_above_lt_ge p i) (λ h, or.inl h) (λ h, or.inr (lt_of_le_of_lt h (cast_succ_lt_succ i))) /-- Embedding `i : fin n` into `fin (n + 1)` using a pivot `p` that is greater results in a value that is less than `p`. -/ @[simp] lemma succ_above_lt_iff (p : fin (n + 1)) (i : fin n) : p.succ_above i < p ↔ i.cast_succ < p := begin refine iff.intro _ _, { intro h, cases succ_above_lt_ge p i with H H, { exact H }, { rw succ_above_above _ _ H at h, exact lt_trans (cast_succ_lt_succ i) h } }, { intro h, rw succ_above_below _ _ h, exact h } end /-- Embedding `i : fin n` into `fin (n + 1)` using a pivot `p` that is lesser results in a value that is greater than `p`. -/ lemma lt_succ_above_iff (p : fin (n + 1)) (i : fin n) : p < p.succ_above i ↔ p ≤ i.cast_succ := begin refine iff.intro _ _, { intro h, cases succ_above_lt_ge p i with H H, { rw succ_above_below _ _ H at h, exact le_of_lt h }, { exact H } }, { intro h, rw succ_above_above _ _ h, exact lt_of_le_of_lt h (cast_succ_lt_succ i) }, end /-- Embedding `i : fin n` into `fin (n + 1)` with a hole around `p : fin (n + 1)` never results in `p` itself -/ theorem succ_above_ne (p : fin (n + 1)) (i : fin n) : p.succ_above i ≠ p := begin intro eq, by_cases H : i.cast_succ < p, { simpa [lt_irrefl, ←succ_above_below _ _ H, eq] using H }, { simpa [←succ_above_above _ _ (le_of_not_lt H), eq] using cast_succ_lt_succ i } end /-- Embedding a positive `fin n` results in a positive fin (n + 1)` -/ lemma succ_above_pos (p : fin (n + 2)) (i : fin (n + 1)) (h : 0 < i) : 0 < p.succ_above i := begin by_cases H : i.cast_succ < p, { simpa [succ_above_below _ _ H] using cast_succ_pos _ h }, { simpa [succ_above_above _ _ (le_of_not_lt H)] using succ_pos _ }, end /-- Given a fixed pivot `x : fin (n + 1)`, `x.succ_above` is injective -/ lemma succ_above_right_inj {x : fin (n + 1)} : x.succ_above a = x.succ_above b ↔ a = b := begin refine iff.intro _ (λ h, by rw h), intro h, cases succ_above_lt_ge x a with ha ha; cases succ_above_lt_ge x b with hb hb, { simpa only [succ_above_below, ha, hb, cast_succ_inj] using h }, { simp only [succ_above_below, succ_above_above, ha, hb] at h, rw h at ha, exact absurd (lt_of_le_of_lt hb (cast_succ_lt_succ _)) (asymm ha) }, { simp only [succ_above_below, succ_above_above, ha, hb] at h, rw ←h at hb, exact absurd (lt_of_le_of_lt ha (cast_succ_lt_succ _)) (asymm hb) }, { simpa only [succ_above_above, ha, hb, succ_inj] using h }, end /-- Given a fixed pivot `x : fin (n + 1)`, `x.succ_above` is injective -/ lemma succ_above_right_injective {x : fin (n + 1)} : injective (succ_above x) := λ _ _, succ_above_right_inj.mp /-- Embedding a `fin (n + 1)` into `fin n` and embedding it back around the same hole gives the starting `fin (n + 1)` -/ @[simp] lemma succ_above_descend (p i : fin (n + 1)) (h : i ≠ p) : p.succ_above (p.pred_above i h) = i := begin rw pred_above, cases lt_or_le i p with H H, { simp only [succ_above_below, cast_succ_cast_lt, H, dif_pos]}, { rw le_iff_coe_le_coe at H, rw succ_above_above, { simp only [le_iff_coe_le_coe, H, not_lt, dif_neg, succ_pred] }, { simp only [le_iff_coe_le_coe, H, coe_pred, not_lt, dif_neg, coe_cast_succ], exact le_pred_of_lt (lt_of_le_of_ne H (vne_of_ne h.symm)) } } end /-- Embedding a `fin n` into `fin (n + 1)` and embedding it back around the same hole gives the starting `fin n` -/ @[simp] lemma pred_above_succ_above (p : fin (n + 1)) (i : fin n) : p.pred_above (p.succ_above i) (succ_above_ne _ _) = i := begin rw pred_above, by_cases H : i.cast_succ < p, { simp [succ_above_below _ _ H, H] }, { cases succ_above_lt_gt p i with h h, { exact absurd h H }, { simp [succ_above_above _ _ (le_of_not_lt H), dif_neg H] } } end /-- `succ_above` is injective at the pivot -/ lemma succ_above_left_inj {x y : fin (n + 1)} : x.succ_above = y.succ_above ↔ x = y := begin refine iff.intro _ (λ h, by rw h), contrapose!, intros H h, have key := congr_fun h (y.pred_above x H), rw [succ_above_descend] at key, exact absurd key (succ_above_ne x _) end /-- `succ_above` is injective at the pivot -/ lemma succ_above_left_injective : injective (@succ_above n) := λ _ _, succ_above_left_inj.mp /-- A function `f` on `fin n` is strictly monotone if and only if `f i < f (i+1)` for all `i`. -/ lemma strict_mono_iff_lt_succ {α : Type*} [preorder α] {f : fin n → α} : strict_mono f ↔ ∀ i (h : i + 1 < n), f ⟨i, lt_of_le_of_lt (nat.le_succ i) h⟩ < f ⟨i+1, h⟩ := begin split, { assume H i hi, apply H, exact nat.lt_succ_self _ }, { assume H, have A : ∀ i j (h : i < j) (h' : j < n), f ⟨i, lt_trans h h'⟩ < f ⟨j, h'⟩, { assume i j h h', induction h with k h IH, { exact H _ _ }, { exact lt_trans (IH (nat.lt_of_succ_lt h')) (H _ _) } }, assume i j hij, convert A (i : ℕ) (j : ℕ) hij j.2; ext; simp only [subtype.coe_eta] } end section rec /-- Define `C n i` by induction on `i : fin n` interpreted as `(0 : fin (n - i)).succ.succ…`. This function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple, and `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element of `n`-tuple. -/ @[elab_as_eliminator] def succ_rec {C : Π n, fin n → Sort*} (H0 : Π n, C (succ n) 0) (Hs : Π n i, C n i → C (succ n) i.succ) : Π {n : ℕ} (i : fin n), C n i | 0 i := i.elim0 | (succ n) ⟨0, _⟩ := H0 _ | (succ n) ⟨succ i, h⟩ := Hs _ _ (succ_rec ⟨i, lt_of_succ_lt_succ h⟩) /-- Define `C n i` by induction on `i : fin n` interpreted as `(0 : fin (n - i)).succ.succ…`. This function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple, and `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element of `n`-tuple. A version of `fin.succ_rec` taking `i : fin n` as the first argument. -/ @[elab_as_eliminator] def succ_rec_on {n : ℕ} (i : fin n) {C : Π n, fin n → Sort*} (H0 : Π n, C (succ n) 0) (Hs : Π n i, C n i → C (succ n) i.succ) : C n i := i.succ_rec H0 Hs @[simp] theorem succ_rec_on_zero {C : ∀ n, fin n → Sort*} {H0 Hs} (n) : @fin.succ_rec_on (succ n) 0 C H0 Hs = H0 n := rfl @[simp] theorem succ_rec_on_succ {C : ∀ n, fin n → Sort*} {H0 Hs} {n} (i : fin n) : @fin.succ_rec_on (succ n) i.succ C H0 Hs = Hs n i (fin.succ_rec_on i H0 Hs) := by cases i; refl /-- Define `C i` by induction on `i : fin (n + 1)` via induction on the underlying `nat` value. This function has two arguments: `h0` handles the base case on `C 0`, and `hs` defines the inductive step using `C i.cast_succ`. -/ @[elab_as_eliminator] def induction {C : fin (n + 1) → Sort*} (h0 : C 0) (hs : ∀ i : fin n, C i.cast_succ → C i.succ) : Π (i : fin (n + 1)), C i := begin rintro ⟨i, hi⟩, induction i with i IH, { rwa [fin.mk_zero] }, { refine hs ⟨i, lt_of_succ_lt_succ hi⟩ _, exact IH (lt_of_succ_lt hi) } end /-- Define `C i` by induction on `i : fin (n + 1)` via induction on the underlying `nat` value. This function has two arguments: `h0` handles the base case on `C 0`, and `hs` defines the inductive step using `C i.cast_succ`. A version of `fin.induction` taking `i : fin (n + 1)` as the first argument. -/ @[elab_as_eliminator] def induction_on (i : fin (n + 1)) {C : fin (n + 1) → Sort*} (h0 : C 0) (hs : ∀ i : fin n, C i.cast_succ → C i.succ) : C i := induction h0 hs i /-- Define `f : Π i : fin n.succ, C i` by separately handling the cases `i = 0` and `i = j.succ`, `j : fin n`. -/ @[elab_as_eliminator] def cases {C : fin (succ n) → Sort*} (H0 : C 0) (Hs : Π i : fin n, C (i.succ)) : Π (i : fin (succ n)), C i := induction H0 (λ i _, Hs i) @[simp] theorem cases_zero {n} {C : fin (succ n) → Sort*} {H0 Hs} : @fin.cases n C H0 Hs 0 = H0 := rfl @[simp] theorem cases_succ {n} {C : fin (succ n) → Sort*} {H0 Hs} (i : fin n) : @fin.cases n C H0 Hs i.succ = Hs i := by cases i; refl @[simp] theorem cases_succ' {n} {C : fin (succ n) → Sort*} {H0 Hs} {i : ℕ} (h : i + 1 < n + 1) : @fin.cases n C H0 Hs ⟨i.succ, h⟩ = Hs ⟨i, lt_of_succ_lt_succ h⟩ := by cases i; refl lemma forall_fin_succ {P : fin (n+1) → Prop} : (∀ i, P i) ↔ P 0 ∧ (∀ i:fin n, P i.succ) := ⟨λ H, ⟨H 0, λ i, H _⟩, λ ⟨H0, H1⟩ i, fin.cases H0 H1 i⟩ lemma exists_fin_succ {P : fin (n+1) → Prop} : (∃ i, P i) ↔ P 0 ∨ (∃i:fin n, P i.succ) := ⟨λ ⟨i, h⟩, fin.cases or.inl (λ i hi, or.inr ⟨i, hi⟩) i h, λ h, or.elim h (λ h, ⟨0, h⟩) $ λ⟨i, hi⟩, ⟨i.succ, hi⟩⟩ end rec section tuple /-! ### Tuples We can think of the type `Π(i : fin n), α i` as `n`-tuples of elements of possibly varying type `α i`. A particular case is `fin n → α` of elements with all the same type. Here are some relevant operations, first about adding or removing elements at the beginning of a tuple. -/ /-- There is exactly one tuple of size zero. -/ instance tuple0_unique (α : fin 0 → Type u) : unique (Π i : fin 0, α i) := { default := fin_zero_elim, uniq := λ x, funext fin_zero_elim } variables {α : fin (n+1) → Type u} (x : α 0) (q : Πi, α i) (p : Π(i : fin n), α (i.succ)) (i : fin n) (y : α i.succ) (z : α 0) /-- The tail of an `n+1` tuple, i.e., its last `n` entries -/ def tail (q : Πi, α i) : (Π(i : fin n), α (i.succ)) := λ i, q i.succ /-- Adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple -/ def cons (x : α 0) (p : Π(i : fin n), α (i.succ)) : Πi, α i := λ j, fin.cases x p j @[simp] lemma tail_cons : tail (cons x p) = p := by simp [tail, cons] @[simp] lemma cons_succ : cons x p i.succ = p i := by simp [cons] @[simp] lemma cons_zero : cons x p 0 = x := by simp [cons] /-- Updating a tuple and adding an element at the beginning commute. -/ @[simp] lemma cons_update : cons x (update p i y) = update (cons x p) i.succ y := begin ext j, by_cases h : j = 0, { rw h, simp [ne.symm (succ_ne_zero i)] }, { let j' := pred j h, have : j'.succ = j := succ_pred j h, rw [← this, cons_succ], by_cases h' : j' = i, { rw h', simp }, { have : j'.succ ≠ i.succ, by rwa [ne.def, succ_inj], rw [update_noteq h', update_noteq this, cons_succ] } } end /-- Adding an element at the beginning of a tuple and then updating it amounts to adding it directly. -/ lemma update_cons_zero : update (cons x p) 0 z = cons z p := begin ext j, by_cases h : j = 0, { rw h, simp }, { simp only [h, update_noteq, ne.def, not_false_iff], let j' := pred j h, have : j'.succ = j := succ_pred j h, rw [← this, cons_succ, cons_succ] } end /-- Concatenating the first element of a tuple with its tail gives back the original tuple -/ @[simp] lemma cons_self_tail : cons (q 0) (tail q) = q := begin ext j, by_cases h : j = 0, { rw h, simp }, { let j' := pred j h, have : j'.succ = j := succ_pred j h, rw [← this, tail, cons_succ] } end /-- Updating the first element of a tuple does not change the tail. -/ @[simp] lemma tail_update_zero : tail (update q 0 z) = tail q := by { ext j, simp [tail, fin.succ_ne_zero] } /-- Updating a nonzero element and taking the tail commute. -/ @[simp] lemma tail_update_succ : tail (update q i.succ y) = update (tail q) i y := begin ext j, by_cases h : j = i, { rw h, simp [tail] }, { simp [tail, (fin.succ_injective n).ne h, h] } end lemma comp_cons {α : Type*} {β : Type*} (g : α → β) (y : α) (q : fin n → α) : g ∘ (cons y q) = cons (g y) (g ∘ q) := begin ext j, by_cases h : j = 0, { rw h, refl }, { let j' := pred j h, have : j'.succ = j := succ_pred j h, rw [← this, cons_succ, comp_app, cons_succ] } end lemma comp_tail {α : Type*} {β : Type*} (g : α → β) (q : fin n.succ → α) : g ∘ (tail q) = tail (g ∘ q) := by { ext j, simp [tail] } /-- `fin.append ho u v` appends two vectors of lengths `m` and `n` to produce one of length `o = m + n`. `ho` provides control of definitional equality for the vector length. -/ def append {α : Type*} {o : ℕ} (ho : o = m + n) (u : fin m → α) (v : fin n → α) : fin o → α := λ i, if h : (i : ℕ) < m then u ⟨i, h⟩ else v ⟨(i : ℕ) - m, (nat.sub_lt_left_iff_lt_add (le_of_not_lt h)).2 (ho ▸ i.property)⟩ end tuple section tuple_right /-! In the previous section, we have discussed inserting or removing elements on the left of a tuple. In this section, we do the same on the right. A difference is that `fin (n+1)` is constructed inductively from `fin n` starting from the left, not from the right. This implies that Lean needs more help to realize that elements belong to the right types, i.e., we need to insert casts at several places. -/ variables {α : fin (n+1) → Type u} (x : α (last n)) (q : Πi, α i) (p : Π(i : fin n), α i.cast_succ) (i : fin n) (y : α i.cast_succ) (z : α (last n)) /-- The beginning of an `n+1` tuple, i.e., its first `n` entries -/ def init (q : Πi, α i) (i : fin n) : α i.cast_succ := q i.cast_succ /-- Adding an element at the end of an `n`-tuple, to get an `n+1`-tuple. The name `snoc` comes from `cons` (i.e., adding an element to the left of a tuple) read in reverse order. -/ def snoc (p : Π(i : fin n), α i.cast_succ) (x : α (last n)) (i : fin (n+1)) : α i := if h : i.val < n then _root_.cast (by rw fin.cast_succ_cast_lt i h) (p (cast_lt i h)) else _root_.cast (by rw eq_last_of_not_lt h) x @[simp] lemma init_snoc : init (snoc p x) = p := begin ext i, have h' := fin.cast_lt_cast_succ i i.is_lt, simp [init, snoc, i.is_lt, h'], convert cast_eq rfl (p i) end @[simp] lemma snoc_cast_succ : snoc p x i.cast_succ = p i := begin have : i.cast_succ.val < n := i.is_lt, have h' := fin.cast_lt_cast_succ i i.is_lt, simp [snoc, this, h'], convert cast_eq rfl (p i) end @[simp] lemma snoc_last : snoc p x (last n) = x := by { simp [snoc] } /-- Updating a tuple and adding an element at the end commute. -/ @[simp] lemma snoc_update : snoc (update p i y) x = update (snoc p x) i.cast_succ y := begin ext j, by_cases h : j.val < n, { simp only [snoc, h, dif_pos], by_cases h' : j = cast_succ i, { have C1 : α i.cast_succ = α j, by rw h', have E1 : update (snoc p x) i.cast_succ y j = _root_.cast C1 y, { have : update (snoc p x) j (_root_.cast C1 y) j = _root_.cast C1 y, by simp, convert this, { exact h'.symm }, { exact heq_of_eq_mp (congr_arg α (eq.symm h')) rfl } }, have C2 : α i.cast_succ = α (cast_succ (cast_lt j h)), by rw [cast_succ_cast_lt, h'], have E2 : update p i y (cast_lt j h) = _root_.cast C2 y, { have : update p (cast_lt j h) (_root_.cast C2 y) (cast_lt j h) = _root_.cast C2 y, by simp, convert this, { simp [h, h'] }, { exact heq_of_eq_mp C2 rfl } }, rw [E1, E2], exact eq_rec_compose _ _ _ }, { have : ¬(cast_lt j h = i), by { assume E, apply h', rw [← E, cast_succ_cast_lt] }, simp [h', this, snoc, h] } }, { rw eq_last_of_not_lt h, simp [ne.symm (ne_of_lt (cast_succ_lt_last i))] } end /-- Adding an element at the beginning of a tuple and then updating it amounts to adding it directly. -/ lemma update_snoc_last : update (snoc p x) (last n) z = snoc p z := begin ext j, by_cases h : j.val < n, { have : j ≠ last n := ne_of_lt h, simp [h, update_noteq, this, snoc] }, { rw eq_last_of_not_lt h, simp } end /-- Concatenating the first element of a tuple with its tail gives back the original tuple -/ @[simp] lemma snoc_init_self : snoc (init q) (q (last n)) = q := begin ext j, by_cases h : j.val < n, { have : j ≠ last n := ne_of_lt h, simp [h, update_noteq, this, snoc, init, cast_succ_cast_lt], have A : cast_succ (cast_lt j h) = j := cast_succ_cast_lt _ _, rw ← cast_eq rfl (q j), congr' 1; rw A }, { rw eq_last_of_not_lt h, simp } end /-- Updating the last element of a tuple does not change the beginning. -/ @[simp] lemma init_update_last : init (update q (last n) z) = init q := by { ext j, simp [init, ne_of_lt, cast_succ_lt_last] } /-- Updating an element and taking the beginning commute. -/ @[simp] lemma init_update_cast_succ : init (update q i.cast_succ y) = update (init q) i y := begin ext j, by_cases h : j = i, { rw h, simp [init] }, { simp [init, h] } end /-- `tail` and `init` commute. We state this lemma in a non-dependent setting, as otherwise it would involve a cast to convince Lean that the two types are equal, making it harder to use. -/ lemma tail_init_eq_init_tail {β : Type*} (q : fin (n+2) → β) : tail (init q) = init (tail q) := by { ext i, simp [tail, init, cast_succ_fin_succ] } /-- `cons` and `snoc` commute. We state this lemma in a non-dependent setting, as otherwise it would involve a cast to convince Lean that the two types are equal, making it harder to use. -/ lemma cons_snoc_eq_snoc_cons {β : Type*} (a : β) (q : fin n → β) (b : β) : @cons n.succ (λ i, β) a (snoc q b) = snoc (cons a q) b := begin ext i, by_cases h : i = 0, { rw h, refl }, set j := pred i h with ji, have : i = j.succ, by rw [ji, succ_pred], rw [this, cons_succ], by_cases h' : j.val < n, { set k := cast_lt j h' with jk, have : j = k.cast_succ, by rw [jk, cast_succ_cast_lt], rw [this, ← cast_succ_fin_succ], simp }, rw [eq_last_of_not_lt h', succ_last], simp end lemma comp_snoc {α : Type*} {β : Type*} (g : α → β) (q : fin n → α) (y : α) : g ∘ (snoc q y) = snoc (g ∘ q) (g y) := begin ext j, by_cases h : j.val < n, { have : j ≠ last n := ne_of_lt h, simp [h, this, snoc, cast_succ_cast_lt] }, { rw eq_last_of_not_lt h, simp } end lemma comp_init {α : Type*} {β : Type*} (g : α → β) (q : fin n.succ → α) : g ∘ (init q) = init (g ∘ q) := by { ext j, simp [init] } end tuple_right section find /-- `find p` returns the first index `n` where `p n` is satisfied, and `none` if it is never satisfied. -/ def find : Π {n : ℕ} (p : fin n → Prop) [decidable_pred p], option (fin n) | 0 p _ := none | (n+1) p _ := by resetI; exact option.cases_on (@find n (λ i, p (i.cast_lt (nat.lt_succ_of_lt i.2))) _) (if h : p (fin.last n) then some (fin.last n) else none) (λ i, some (i.cast_lt (nat.lt_succ_of_lt i.2))) /-- If `find p = some i`, then `p i` holds -/ lemma find_spec : Π {n : ℕ} (p : fin n → Prop) [decidable_pred p] {i : fin n} (hi : i ∈ by exactI fin.find p), p i | 0 p I i hi := option.no_confusion hi | (n+1) p I i hi := begin dsimp [find] at hi, resetI, cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with j, { rw h at hi, dsimp at hi, split_ifs at hi with hl hl, { exact option.some_inj.1 hi ▸ hl }, { exact option.no_confusion hi } }, { rw h at hi, rw [← option.some_inj.1 hi], exact find_spec _ h } end /-- `find p` does not return `none` if and only if `p i` holds at some index `i`. -/ lemma is_some_find_iff : Π {n : ℕ} {p : fin n → Prop} [decidable_pred p], by exactI (find p).is_some ↔ ∃ i, p i | 0 p _ := iff_of_false (λ h, bool.no_confusion h) (λ ⟨i, _⟩, fin_zero_elim i) | (n+1) p _ := ⟨λ h, begin rw [option.is_some_iff_exists] at h, cases h with i hi, exactI ⟨i, find_spec _ hi⟩ end, λ ⟨⟨i, hin⟩, hi⟩, begin resetI, dsimp [find], cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with j, { split_ifs with hl hl, { exact option.is_some_some }, { have := (@is_some_find_iff n (λ x, p (x.cast_lt (nat.lt_succ_of_lt x.2))) _).2 ⟨⟨i, lt_of_le_of_ne (nat.le_of_lt_succ hin) (λ h, by clear_aux_decl; cases h; exact hl hi)⟩, hi⟩, rw h at this, exact this } }, { simp } end⟩ /-- `find p` returns `none` if and only if `p i` never holds. -/ lemma find_eq_none_iff {n : ℕ} {p : fin n → Prop} [decidable_pred p] : find p = none ↔ ∀ i, ¬ p i := by rw [← not_exists, ← is_some_find_iff]; cases (find p); simp /-- If `find p` returns `some i`, then `p j` does not hold for `j < i`, i.e., `i` is minimal among the indices where `p` holds. -/ lemma find_min : Π {n : ℕ} {p : fin n → Prop} [decidable_pred p] {i : fin n} (hi : i ∈ by exactI fin.find p) {j : fin n} (hj : j < i), ¬ p j | 0 p _ i hi j hj hpj := option.no_confusion hi | (n+1) p _ i hi ⟨j, hjn⟩ hj hpj := begin resetI, dsimp [find] at hi, cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with k, { rw [h] at hi, split_ifs at hi with hl hl, { have := option.some_inj.1 hi, subst this, rw [find_eq_none_iff] at h, exact h ⟨j, hj⟩ hpj }, { exact option.no_confusion hi } }, { rw h at hi, dsimp at hi, have := option.some_inj.1 hi, subst this, exact find_min h (show (⟨j, lt_trans hj k.2⟩ : fin n) < k, from hj) hpj } end lemma find_min' {p : fin n → Prop} [decidable_pred p] {i : fin n} (h : i ∈ fin.find p) {j : fin n} (hj : p j) : i ≤ j := le_of_not_gt (λ hij, find_min h hij hj) lemma nat_find_mem_find {p : fin n → Prop} [decidable_pred p] (h : ∃ i, ∃ hin : i < n, p ⟨i, hin⟩) : (⟨nat.find h, (nat.find_spec h).fst⟩ : fin n) ∈ find p := let ⟨i, hin, hi⟩ := h in begin cases hf : find p with f, { rw [find_eq_none_iff] at hf, exact (hf ⟨i, hin⟩ hi).elim }, { refine option.some_inj.2 (le_antisymm _ _), { exact find_min' hf (nat.find_spec h).snd }, { exact nat.find_min' _ ⟨f.2, by convert find_spec p hf; exact fin.eta _ _⟩ } } end lemma mem_find_iff {p : fin n → Prop} [decidable_pred p] {i : fin n} : i ∈ fin.find p ↔ p i ∧ ∀ j, p j → i ≤ j := ⟨λ hi, ⟨find_spec _ hi, λ _, find_min' hi⟩, begin rintros ⟨hpi, hj⟩, cases hfp : fin.find p, { rw [find_eq_none_iff] at hfp, exact (hfp _ hpi).elim }, { exact option.some_inj.2 (le_antisymm (find_min' hfp hpi) (hj _ (find_spec _ hfp))) } end⟩ lemma find_eq_some_iff {p : fin n → Prop} [decidable_pred p] {i : fin n} : fin.find p = some i ↔ p i ∧ ∀ j, p j → i ≤ j := mem_find_iff lemma mem_find_of_unique {p : fin n → Prop} [decidable_pred p] (h : ∀ i j, p i → p j → i = j) {i : fin n} (hi : p i) : i ∈ fin.find p := mem_find_iff.2 ⟨hi, λ j hj, le_of_eq $ h i j hi hj⟩ end find @[simp] lemma coe_of_nat_eq_mod (m n : ℕ) : ((n : fin (succ m)) : ℕ) = n % succ m := by rw [← of_nat_eq_coe]; refl @[simp] lemma coe_of_nat_eq_mod' (m n : ℕ) [I : fact (0 < m)] : (@fin.of_nat' _ I n : ℕ) = n % m := rfl end fin
d59af7a319f04fb3010edc404e44bc23d0e139c6
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/dotNotationAndDefaultInstance.lean
3fb21b032367aa9fc8d22e06f9d14caa780501c0
[ "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
377
lean
namespace Ex class Get (Cont : Type u) (Idx : Type v) (Elem : outParam (Type w)) where get (xs : Cont) (i : Idx) : Elem export Get (get) instance [Inhabited α] : Get (Array α) Nat α where get xs i := xs.get! i example (as : Array (Nat × Bool)) : Bool := (get as 0).2 example (as : Array (Nat × Bool)) : Bool := let r1 (as : _) := (get as 0).2 r1 as end Ex
08a1805d21d8e746a249e52e293a258b243c005e
367134ba5a65885e863bdc4507601606690974c1
/src/data/polynomial/denoms_clearable.lean
2a27d160712e004f27e089717c67487e4f5beff3
[ "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
4,650
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.polynomial.erase_lead /-! # Denominators of evaluation of polynomials at ratios Let `i : R → K` be a homomorphism of semirings. Assume that `K` is commutative. If `a` and `b` are elements of `R` such that `i b ∈ K` is invertible, then for any polynomial `f ∈ polynomial R` the "mathematical" expression `b ^ f.nat_degree * f (a / b) ∈ K` is in the image of the homomorphism `i`. -/ open polynomial finset section denoms_clearable variables {R K : Type*} [semiring R] [comm_semiring K] {i : R →+* K} variables {a b : R} {bi : K} -- TODO: use hypothesis (ub : is_unit (i b)) to work with localizations. /-- `denoms_clearable` formalizes the property that `b ^ N * f (a / b)` does not have denominators, if the inequality `f.nat_degree ≤ N` holds. The definition asserts the existence of an element `D` of `R` and an element `bi = 1 / i b` of `K` such that clearing the denominators of the fraction equals `i D`. -/ def denoms_clearable (a b : R) (N : ℕ) (f : polynomial R) (i : R →+* K) : Prop := ∃ (D : R) (bi : K), bi * i b = 1 ∧ i D = i b ^ N * eval (i a * bi) (f.map i) lemma denoms_clearable_zero (N : ℕ) (a : R) (bu : bi * i b = 1) : denoms_clearable a b N 0 i := ⟨0, bi, bu, by simp only [eval_zero, ring_hom.map_zero, mul_zero, map_zero]⟩ lemma denoms_clearable_C_mul_X_pow {N : ℕ} (a : R) (bu : bi * i b = 1) {n : ℕ} (r : R) (nN : n ≤ N) : denoms_clearable a b N (C r * X ^ n) i := begin refine ⟨r * a ^ n * b ^ (N - n), bi, bu, _⟩, rw [C_mul_X_pow_eq_monomial, map_monomial, ← C_mul_X_pow_eq_monomial, eval_mul, eval_pow, eval_C], rw [ring_hom.map_mul, ring_hom.map_mul, ring_hom.map_pow, ring_hom.map_pow, eval_X, mul_comm], rw [← nat.sub_add_cancel nN] {occs := occurrences.pos [2]}, rw [pow_add, mul_assoc, mul_comm (i b ^ n), mul_pow, mul_assoc, mul_assoc (i a ^ n), ← mul_pow], rw [bu, one_pow, mul_one], end lemma denoms_clearable.add {N : ℕ} {f g : polynomial R} : denoms_clearable a b N f i → denoms_clearable a b N g i → denoms_clearable a b N (f + g) i := λ ⟨Df, bf, bfu, Hf⟩ ⟨Dg, bg, bgu, Hg⟩, ⟨Df + Dg, bf, bfu, begin rw [ring_hom.map_add, polynomial.map_add, eval_add, mul_add, Hf, Hg], congr, refine @inv_unique K _ (i b) bg bf _ _; rwa mul_comm, end ⟩ lemma denoms_clearable_of_nat_degree_le (N : ℕ) (a : R) (bu : bi * i b = 1) : ∀ (f : polynomial R), f.nat_degree ≤ N → denoms_clearable a b N f i := induction_with_nat_degree_le N (denoms_clearable_zero N a bu) (λ N_1 r r0, denoms_clearable_C_mul_X_pow a bu r) (λ f g fN gN df dg, df.add dg) /-- If `i : R → K` is a ring homomorphism, `f` is a polynomial with coefficients in `R`, `a, b` are elements of `R`, with `i b` invertible, then there is a `D ∈ R` such that `b ^ f.nat_degree * f (a / b)` equals `i D`. -/ theorem denoms_clearable_nat_degree (i : R →+* K) (f : polynomial R) (a : R) (bu : bi * i b = 1) : denoms_clearable a b f.nat_degree f i := denoms_clearable_of_nat_degree_le f.nat_degree a bu f le_rfl end denoms_clearable open ring_hom /-- Evaluating a polynomial with integer coefficients at a rational number and clearing denominators, yields a number greater than or equal to one. The target can be any `linear_ordered_field K`. The assumption on `K` could be weakened to `linear_ordered_comm_ring` assuming that the image of the denominator is invertible in `K`. -/ lemma one_le_pow_mul_abs_eval_div {K : Type*} [linear_ordered_field K] {f : polynomial ℤ} {a b : ℤ} (b0 : 0 < b) (fab : eval ((a : K) / b) (f.map (algebra_map ℤ K)) ≠ 0) : (1 : K) ≤ b ^ f.nat_degree * abs (eval ((a : K) / b) (f.map (algebra_map ℤ K))) := begin obtain ⟨ev, bi, bu, hF⟩ := @denoms_clearable_nat_degree _ _ _ _ b _ (algebra_map ℤ K) f a (by { rw [eq_int_cast, one_div_mul_cancel], rw [int.cast_ne_zero], exact (b0.ne.symm) }), obtain Fa := congr_arg abs hF, rw [eq_one_div_of_mul_eq_one_left bu, eq_int_cast, eq_int_cast, abs_mul] at Fa, rw [abs_of_pos (pow_pos (int.cast_pos.mpr b0) _ : 0 < (b : K) ^ _), one_div, eq_int_cast] at Fa, rw [div_eq_mul_inv, ← Fa, ← int.cast_abs, ← int.cast_one, int.cast_le], refine int.le_of_lt_add_one ((lt_add_iff_pos_left 1).mpr (abs_pos.mpr (λ F0, fab _))), rw [eq_one_div_of_mul_eq_one_left bu, F0, one_div, eq_int_cast, int.cast_zero, zero_eq_mul] at hF, cases hF with hF hF, { exact (not_le.mpr b0 (le_of_eq (int.cast_eq_zero.mp (pow_eq_zero hF)))).elim }, { exact hF } end
31971d443497ae6c3240d2f7f1c54ee4f7e7a130
2eab05920d6eeb06665e1a6df77b3157354316ad
/src/category_theory/adjunction/limits.lean
7ee6eb77c7c557845084d0657ff081595156abcf
[ "Apache-2.0" ]
permissive
ayush1801/mathlib
78949b9f789f488148142221606bf15c02b960d2
ce164e28f262acbb3de6281b3b03660a9f744e3c
refs/heads/master
1,692,886,907,941
1,635,270,866,000
1,635,270,866,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
11,993
lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Johan Commelin -/ import category_theory.adjunction.basic import category_theory.limits.creates open opposite namespace category_theory.adjunction open category_theory open category_theory.functor open category_theory.limits universes u₁ u₂ v variables {C : Type u₁} [category.{v} C] {D : Type u₂} [category.{v} D] variables {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) include adj section preservation_colimits variables {J : Type v} [small_category J] (K : J ⥤ C) /-- The right adjoint of `cocones.functoriality K F : cocone K ⥤ cocone (K ⋙ F)`. Auxiliary definition for `functoriality_is_left_adjoint`. -/ def functoriality_right_adjoint : cocone (K ⋙ F) ⥤ cocone K := (cocones.functoriality _ G) ⋙ (cocones.precompose (K.right_unitor.inv ≫ (whisker_left K adj.unit) ≫ (associator _ _ _).inv)) local attribute [reducible] functoriality_right_adjoint /-- The unit for the adjunction for `cocones.functoriality K F : cocone K ⥤ cocone (K ⋙ F)`. Auxiliary definition for `functoriality_is_left_adjoint`. -/ @[simps] def functoriality_unit : 𝟭 (cocone K) ⟶ cocones.functoriality _ F ⋙ functoriality_right_adjoint adj K := { app := λ c, { hom := adj.unit.app c.X } } /-- The counit for the adjunction for `cocones.functoriality K F : cocone K ⥤ cocone (K ⋙ F)`. Auxiliary definition for `functoriality_is_left_adjoint`. -/ @[simps] def functoriality_counit : functoriality_right_adjoint adj K ⋙ cocones.functoriality _ F ⟶ 𝟭 (cocone (K ⋙ F)) := { app := λ c, { hom := adj.counit.app c.X } } /-- The functor `cocones.functoriality K F : cocone K ⥤ cocone (K ⋙ F)` is a left adjoint. -/ def functoriality_is_left_adjoint : is_left_adjoint (cocones.functoriality K F) := { right := functoriality_right_adjoint adj K, adj := mk_of_unit_counit { unit := functoriality_unit adj K, counit := functoriality_counit adj K } } /-- A left adjoint preserves colimits. See https://stacks.math.columbia.edu/tag/0038. -/ def left_adjoint_preserves_colimits : preserves_colimits F := { preserves_colimits_of_shape := λ J 𝒥, { preserves_colimit := λ F, by exactI { preserves := λ c hc, is_colimit.iso_unique_cocone_morphism.inv (λ s, @equiv.unique _ _ (is_colimit.iso_unique_cocone_morphism.hom hc _) (((adj.functoriality_is_left_adjoint _).adj).hom_equiv _ _)) } } }. omit adj @[priority 100] -- see Note [lower instance priority] instance is_equivalence_preserves_colimits (E : C ⥤ D) [is_equivalence E] : preserves_colimits E := left_adjoint_preserves_colimits E.adjunction @[priority 100] -- see Note [lower instance priority] instance is_equivalence_reflects_colimits (E : D ⥤ C) [is_equivalence E] : reflects_colimits E := { reflects_colimits_of_shape := λ J 𝒥, by exactI { reflects_colimit := λ K, { reflects := λ c t, begin have l := (is_colimit_of_preserves E.inv t).map_cocone_equiv E.as_equivalence.unit_iso.symm, refine (((is_colimit.precompose_inv_equiv K.right_unitor _).symm) l).of_iso_colimit _, tidy, end } } } @[priority 100] -- see Note [lower instance priority] instance is_equivalence_creates_colimits (H : D ⥤ C) [is_equivalence H] : creates_colimits H := { creates_colimits_of_shape := λ J 𝒥, by exactI { creates_colimit := λ F, { lifts := λ c t, { lifted_cocone := H.map_cocone_inv c, valid_lift := H.map_cocone_map_cocone_inv c } } } } -- verify the preserve_colimits instance works as expected: example (E : C ⥤ D) [is_equivalence E] (c : cocone K) (h : is_colimit c) : is_colimit (E.map_cocone c) := preserves_colimit.preserves h lemma has_colimit_comp_equivalence (E : C ⥤ D) [is_equivalence E] [has_colimit K] : has_colimit (K ⋙ E) := has_colimit.mk { cocone := E.map_cocone (colimit.cocone K), is_colimit := preserves_colimit.preserves (colimit.is_colimit K) } lemma has_colimit_of_comp_equivalence (E : C ⥤ D) [is_equivalence E] [has_colimit (K ⋙ E)] : has_colimit K := @has_colimit_of_iso _ _ _ _ (K ⋙ E ⋙ inv E) K (@has_colimit_comp_equivalence _ _ _ _ _ _ (K ⋙ E) (inv E) _ _) ((functor.right_unitor _).symm ≪≫ iso_whisker_left K (E.as_equivalence.unit_iso)) /-- Transport a `has_colimits_of_shape` instance across an equivalence. -/ lemma has_colimits_of_shape_of_equivalence (E : C ⥤ D) [is_equivalence E] [has_colimits_of_shape J D] : has_colimits_of_shape J C := ⟨λ F, by exactI has_colimit_of_comp_equivalence F E⟩ /-- Transport a `has_colimits` instance across an equivalence. -/ lemma has_colimits_of_equivalence (E : C ⥤ D) [is_equivalence E] [has_colimits D] : has_colimits C := ⟨λ J hJ, by exactI has_colimits_of_shape_of_equivalence E⟩ end preservation_colimits section preservation_limits variables {J : Type v} [small_category J] (K : J ⥤ D) /-- The left adjoint of `cones.functoriality K G : cone K ⥤ cone (K ⋙ G)`. Auxiliary definition for `functoriality_is_right_adjoint`. -/ def functoriality_left_adjoint : cone (K ⋙ G) ⥤ cone K := (cones.functoriality _ F) ⋙ (cones.postcompose ((associator _ _ _).hom ≫ (whisker_left K adj.counit) ≫ K.right_unitor.hom)) local attribute [reducible] functoriality_left_adjoint /-- The unit for the adjunction for`cones.functoriality K G : cone K ⥤ cone (K ⋙ G)`. Auxiliary definition for `functoriality_is_right_adjoint`. -/ @[simps] def functoriality_unit' : 𝟭 (cone (K ⋙ G)) ⟶ functoriality_left_adjoint adj K ⋙ cones.functoriality _ G := { app := λ c, { hom := adj.unit.app c.X, } } /-- The counit for the adjunction for`cones.functoriality K G : cone K ⥤ cone (K ⋙ G)`. Auxiliary definition for `functoriality_is_right_adjoint`. -/ @[simps] def functoriality_counit' : cones.functoriality _ G ⋙ functoriality_left_adjoint adj K ⟶ 𝟭 (cone K) := { app := λ c, { hom := adj.counit.app c.X, } } /-- The functor `cones.functoriality K G : cone K ⥤ cone (K ⋙ G)` is a right adjoint. -/ def functoriality_is_right_adjoint : is_right_adjoint (cones.functoriality K G) := { left := functoriality_left_adjoint adj K, adj := mk_of_unit_counit { unit := functoriality_unit' adj K, counit := functoriality_counit' adj K } } /-- A right adjoint preserves limits. See https://stacks.math.columbia.edu/tag/0038. -/ def right_adjoint_preserves_limits : preserves_limits G := { preserves_limits_of_shape := λ J 𝒥, { preserves_limit := λ K, by exactI { preserves := λ c hc, is_limit.iso_unique_cone_morphism.inv (λ s, @equiv.unique _ _ (is_limit.iso_unique_cone_morphism.hom hc _) (((adj.functoriality_is_right_adjoint _).adj).hom_equiv _ _).symm) } } }. omit adj @[priority 100] -- see Note [lower instance priority] instance is_equivalence_preserves_limits (E : D ⥤ C) [is_equivalence E] : preserves_limits E := right_adjoint_preserves_limits E.inv.adjunction @[priority 100] -- see Note [lower instance priority] instance is_equivalence_reflects_limits (E : D ⥤ C) [is_equivalence E] : reflects_limits E := { reflects_limits_of_shape := λ J 𝒥, by exactI { reflects_limit := λ K, { reflects := λ c t, begin have := (is_limit_of_preserves E.inv t).map_cone_equiv E.as_equivalence.unit_iso.symm, refine (((is_limit.postcompose_hom_equiv K.left_unitor _).symm) this).of_iso_limit _, tidy, end } } } @[priority 100] -- see Note [lower instance priority] instance is_equivalence_creates_limits (H : D ⥤ C) [is_equivalence H] : creates_limits H := { creates_limits_of_shape := λ J 𝒥, by exactI { creates_limit := λ F, { lifts := λ c t, { lifted_cone := H.map_cone_inv c, valid_lift := H.map_cone_map_cone_inv c } } } } -- verify the preserve_limits instance works as expected: example (E : D ⥤ C) [is_equivalence E] (c : cone K) [h : is_limit c] : is_limit (E.map_cone c) := preserves_limit.preserves h lemma has_limit_comp_equivalence (E : D ⥤ C) [is_equivalence E] [has_limit K] : has_limit (K ⋙ E) := has_limit.mk { cone := E.map_cone (limit.cone K), is_limit := preserves_limit.preserves (limit.is_limit K) } lemma has_limit_of_comp_equivalence (E : D ⥤ C) [is_equivalence E] [has_limit (K ⋙ E)] : has_limit K := @has_limit_of_iso _ _ _ _ (K ⋙ E ⋙ inv E) K (@has_limit_comp_equivalence _ _ _ _ _ _ (K ⋙ E) (inv E) _ _) ((iso_whisker_left K E.as_equivalence.unit_iso.symm) ≪≫ (functor.right_unitor _)) /-- Transport a `has_limits_of_shape` instance across an equivalence. -/ lemma has_limits_of_shape_of_equivalence (E : D ⥤ C) [is_equivalence E] [has_limits_of_shape J C] : has_limits_of_shape J D := ⟨λ F, by exactI has_limit_of_comp_equivalence F E⟩ /-- Transport a `has_limits` instance across an equivalence. -/ lemma has_limits_of_equivalence (E : D ⥤ C) [is_equivalence E] [has_limits C] : has_limits D := ⟨λ J hJ, by exactI has_limits_of_shape_of_equivalence E⟩ end preservation_limits /-- auxiliary construction for `cocones_iso` -/ @[simps] def cocones_iso_component_hom {J : Type v} [small_category J] {K : J ⥤ C} (Y : D) (t : ((cocones J D).obj (op (K ⋙ F))).obj Y) : (G ⋙ (cocones J C).obj (op K)).obj Y := { app := λ j, (adj.hom_equiv (K.obj j) Y) (t.app j), naturality' := λ j j' f, by { erw [← adj.hom_equiv_naturality_left, t.naturality], dsimp, simp } } /-- auxiliary construction for `cocones_iso` -/ @[simps] def cocones_iso_component_inv {J : Type v} [small_category J] {K : J ⥤ C} (Y : D) (t : (G ⋙ (cocones J C).obj (op K)).obj Y) : ((cocones J D).obj (op (K ⋙ F))).obj Y := { app := λ j, (adj.hom_equiv (K.obj j) Y).symm (t.app j), naturality' := λ j j' f, begin erw [← adj.hom_equiv_naturality_left_symm, ← adj.hom_equiv_naturality_right_symm, t.naturality], dsimp, simp end } /-- When `F ⊣ G`, the functor associating to each `Y` the cocones over `K ⋙ F` with cone point `Y` is naturally isomorphic to the functor associating to each `Y` the cocones over `K` with cone point `G.obj Y`. -/ -- Note: this is natural in K, but we do not yet have the tools to formulate that. def cocones_iso {J : Type v} [small_category J] {K : J ⥤ C} : (cocones J D).obj (op (K ⋙ F)) ≅ G ⋙ ((cocones J C).obj (op K)) := nat_iso.of_components (λ Y, { hom := cocones_iso_component_hom adj Y, inv := cocones_iso_component_inv adj Y, }) (by tidy) /-- auxiliary construction for `cones_iso` -/ @[simps] def cones_iso_component_hom {J : Type v} [small_category J] {K : J ⥤ D} (X : Cᵒᵖ) (t : (functor.op F ⋙ (cones J D).obj K).obj X) : ((cones J C).obj (K ⋙ G)).obj X := { app := λ j, (adj.hom_equiv (unop X) (K.obj j)) (t.app j), naturality' := λ j j' f, begin erw [← adj.hom_equiv_naturality_right, ← t.naturality, category.id_comp, category.id_comp], refl end } /-- auxiliary construction for `cones_iso` -/ @[simps] def cones_iso_component_inv {J : Type v} [small_category J] {K : J ⥤ D} (X : Cᵒᵖ) (t : ((cones J C).obj (K ⋙ G)).obj X) : (functor.op F ⋙ (cones J D).obj K).obj X := { app := λ j, (adj.hom_equiv (unop X) (K.obj j)).symm (t.app j), naturality' := λ j j' f, begin erw [← adj.hom_equiv_naturality_right_symm, ← t.naturality, category.id_comp, category.id_comp] end } -- Note: this is natural in K, but we do not yet have the tools to formulate that. /-- When `F ⊣ G`, the functor associating to each `X` the cones over `K` with cone point `F.op.obj X` is naturally isomorphic to the functor associating to each `X` the cones over `K ⋙ G` with cone point `X`. -/ def cones_iso {J : Type v} [small_category J] {K : J ⥤ D} : F.op ⋙ ((cones J D).obj K) ≅ (cones J C).obj (K ⋙ G) := nat_iso.of_components (λ X, { hom := cones_iso_component_hom adj X, inv := cones_iso_component_inv adj X, } ) (by tidy) end category_theory.adjunction
c7e957f97ffd88e2349350fe32514cc4f88e9b15
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/src/lake/test/buildArgs/foo/foo.lean
dccecb1f5ca9be55ddfde0f69465845a787e56a5
[ "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
53
lean
def main : IO Unit := IO.println s!"Hello, world!"
2ed291985ff66171f9d5541d09f5f49a9ed15eab
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/algebraic_geometry/presheafed_space/gluing.lean
c964bb9f338bf5a14af675d03e3d214a86d33bb9
[ "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
26,443
lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import topology.gluing import algebraic_geometry.open_immersion.basic import algebraic_geometry.locally_ringed_space.has_colimits /-! # Gluing Structured spaces > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Given a family of gluing data of structured spaces (presheafed spaces, sheafed spaces, or locally ringed spaces), we may glue them together. The construction should be "sealed" and considered as a black box, while only using the API provided. ## Main definitions * `algebraic_geometry.PresheafedSpace.glue_data`: A structure containing the family of gluing data. * `category_theory.glue_data.glued`: The glued presheafed space. This is defined as the multicoequalizer of `∐ V i j ⇉ ∐ U i`, so that the general colimit API can be used. * `category_theory.glue_data.ι`: The immersion `ι i : U i ⟶ glued` for each `i : J`. ## Main results * `algebraic_geometry.PresheafedSpace.glue_data.ι_is_open_immersion`: The map `ι i : U i ⟶ glued` is an open immersion for each `i : J`. * `algebraic_geometry.PresheafedSpace.glue_data.ι_jointly_surjective` : The underlying maps of `ι i : U i ⟶ glued` are jointly surjective. * `algebraic_geometry.PresheafedSpace.glue_data.V_pullback_cone_is_limit` : `V i j` is the pullback (intersection) of `U i` and `U j` over the glued space. Analogous results are also provided for `SheafedSpace` and `LocallyRingedSpace`. ## Implementation details Almost the whole file is dedicated to showing tht `ι i` is an open immersion. The fact that this is an open embedding of topological spaces follows from `topology.gluing.lean`, and it remains to construct `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_X, ι i '' U)` for each `U ⊆ U i`. Since `Γ(𝒪_X, ι i '' U)` is the the limit of `diagram_over_open`, the components of the structure sheafs of the spaces in the gluing diagram, we need to construct a map `ι_inv_app_π_app : Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_V, U_V)` for each `V` in the gluing diagram. We will refer to ![this diagram](https://i.imgur.com/P0phrwr.png) in the following doc strings. The `X` is the glued space, and the dotted arrow is a partial inverse guaranteed by the fact that it is an open immersion. The map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_{U_j}, _)` is given by the composition of the red arrows, and the map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_{V_{jk}}, _)` is given by the composition of the blue arrows. To lift this into a map from `Γ(𝒪_X, ι i '' U)`, we also need to show that these commute with the maps in the diagram (the green arrows), which is just a lengthy diagram-chasing. -/ noncomputable theory open topological_space category_theory opposite open category_theory.limits algebraic_geometry.PresheafedSpace open category_theory.glue_data namespace algebraic_geometry universes v u variables (C : Type u) [category.{v} C] namespace PresheafedSpace /-- A family of gluing data consists of 1. An index type `J` 2. A presheafed space `U i` for each `i : J`. 3. A presheafed space `V i j` for each `i j : J`. (Note that this is `J × J → PresheafedSpace C` rather than `J → J → PresheafedSpace C` to connect to the limits library easier.) 4. An open immersion `f i j : V i j ⟶ U i` for each `i j : ι`. 5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some `t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`. 9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`. We can then glue the spaces `U i` together by identifying `V i j` with `V j i`, such that the `U i`'s are open subspaces of the glued space. -/ @[nolint has_nonempty_instance] structure glue_data extends glue_data (PresheafedSpace.{v} C) := (f_open : ∀ i j, is_open_immersion (f i j)) attribute [instance] glue_data.f_open namespace glue_data variables {C} (D : glue_data C) local notation `𝖣` := D.to_glue_data local notation `π₁ `i`, `j`, `k := @pullback.fst _ _ _ _ _ (D.f i j) (D.f i k) _ local notation `π₂ `i`, `j`, `k := @pullback.snd _ _ _ _ _ (D.f i j) (D.f i k) _ local notation `π₁⁻¹ `i`, `j`, `k := (PresheafedSpace.is_open_immersion.pullback_fst_of_right (D.f i j) (D.f i k)).inv_app local notation `π₂⁻¹ `i`, `j`, `k := (PresheafedSpace.is_open_immersion.pullback_snd_of_left (D.f i j) (D.f i k)).inv_app /-- The glue data of topological spaces associated to a family of glue data of PresheafedSpaces. -/ abbreviation to_Top_glue_data : Top.glue_data := { f_open := λ i j, (D.f_open i j).base_open, to_glue_data := 𝖣 .map_glue_data (forget C) } lemma ι_open_embedding [has_limits C] (i : D.J) : open_embedding (𝖣 .ι i).base := begin rw ← (show _ = (𝖣 .ι i).base, from 𝖣 .ι_glued_iso_inv (PresheafedSpace.forget _) _), exact open_embedding.comp (Top.homeo_of_iso (𝖣 .glued_iso (PresheafedSpace.forget _)).symm).open_embedding (D.to_Top_glue_data.ι_open_embedding i) end lemma pullback_base (i j k : D.J) (S : set (D.V (i, j)).carrier) : (π₂ i, j, k) '' ((π₁ i, j, k) ⁻¹' S) = D.f i k ⁻¹' (D.f i j '' S) := begin have eq₁ : _ = (π₁ i, j, k).base := preserves_pullback.iso_hom_fst (forget C) _ _, have eq₂ : _ = (π₂ i, j, k).base := preserves_pullback.iso_hom_snd (forget C) _ _, rw [coe_to_fun_eq, coe_to_fun_eq, ← eq₁, ← eq₂, coe_comp, set.image_comp, coe_comp, set.preimage_comp, set.image_preimage_eq, Top.pullback_snd_image_fst_preimage], refl, rw ← Top.epi_iff_surjective, apply_instance end /-- The red and the blue arrows in ![this diagram](https://i.imgur.com/0GiBUh6.png) commute. -/ @[simp, reassoc] lemma f_inv_app_f_app (i j k : D.J) (U : (opens (D.V (i, j)).carrier)) : (D.f_open i j).inv_app U ≫ (D.f i k).c.app _ = (π₁ i, j, k).c.app (op U) ≫ (π₂⁻¹ i, j, k) (unop _) ≫ (D.V _).presheaf.map (eq_to_hom (begin delta is_open_immersion.open_functor, dsimp only [functor.op, is_open_map.functor, opens.map, unop_op], congr, apply pullback_base, end)) := begin have := PresheafedSpace.congr_app (@pullback.condition _ _ _ _ _ (D.f i j) (D.f i k) _), dsimp only [comp_c_app] at this, rw [← cancel_epi (inv ((D.f_open i j).inv_app U)), is_iso.inv_hom_id_assoc, is_open_immersion.inv_inv_app], simp_rw category.assoc, erw [(π₁ i, j, k).c.naturality_assoc, reassoc_of this, ← functor.map_comp_assoc, is_open_immersion.inv_naturality_assoc, is_open_immersion.app_inv_app_assoc, ← (D.V (i, k)).presheaf.map_comp, ← (D.V (i, k)).presheaf.map_comp], convert (category.comp_id _).symm, erw (D.V (i, k)).presheaf.map_id, refl end /-- We can prove the `eq` along with the lemma. Thus this is bundled together here, and the lemma itself is separated below. -/ lemma snd_inv_app_t_app' (i j k : D.J) (U : opens (pullback (D.f i j) (D.f i k)).carrier) : ∃ eq, (π₂⁻¹ i, j, k) U ≫ (D.t k i).c.app _ ≫ (D.V (k, i)).presheaf.map (eq_to_hom eq) = (D.t' k i j).c.app _ ≫ (π₁⁻¹ k, j, i) (unop _) := begin split, rw [← is_iso.eq_inv_comp, is_open_immersion.inv_inv_app, category.assoc, (D.t' k i j).c.naturality_assoc], simp_rw ← category.assoc, erw ← comp_c_app, rw [congr_app (D.t_fac k i j), comp_c_app], simp_rw category.assoc, erw [is_open_immersion.inv_naturality, is_open_immersion.inv_naturality_assoc, is_open_immersion.app_inv_app'_assoc], simp_rw [← (𝖣 .V (k, i)).presheaf.map_comp, eq_to_hom_map (functor.op _), eq_to_hom_op, eq_to_hom_trans], rintros x ⟨y, hy, eq⟩, replace eq := concrete_category.congr_arg ((𝖣 .t i k).base) eq, change ((π₂ i, j, k) ≫ D.t i k).base y = (D.t k i ≫ D.t i k).base x at eq, rw [𝖣 .t_inv, id_base, Top.id_app] at eq, subst eq, use (inv (D.t' k i j)).base y, change ((inv (D.t' k i j)) ≫ (π₁ k, i, j)).base y = _, congr' 2, rw [is_iso.inv_comp_eq, 𝖣 .t_fac_assoc, 𝖣 .t_inv, category.comp_id] end /-- The red and the blue arrows in ![this diagram](https://i.imgur.com/q6X1GJ9.png) commute. -/ @[simp, reassoc] lemma snd_inv_app_t_app (i j k : D.J) (U : opens (pullback (D.f i j) (D.f i k)).carrier) : (π₂⁻¹ i, j, k) U ≫ (D.t k i).c.app _ = (D.t' k i j).c.app _ ≫ (π₁⁻¹ k, j, i) (unop _) ≫ (D.V (k, i)).presheaf.map (eq_to_hom (D.snd_inv_app_t_app' i j k U).some.symm) := begin have e := (D.snd_inv_app_t_app' i j k U).some_spec, reassoc! e, rw ← e, simp [eq_to_hom_map], end variable [has_limits C] lemma ι_image_preimage_eq (i j : D.J) (U : opens (D.U i).carrier) : (opens.map (𝖣 .ι j).base).obj ((D.ι_open_embedding i).is_open_map.functor.obj U) = (D.f_open j i).open_functor.obj ((opens.map (𝖣 .t j i).base).obj ((opens.map (𝖣 .f i j).base).obj U)) := begin ext1, dsimp only [opens.map_coe, is_open_map.functor_obj_coe], rw [← (show _ = (𝖣 .ι i).base, from 𝖣 .ι_glued_iso_inv (PresheafedSpace.forget _) i), ← (show _ = (𝖣 .ι j).base, from 𝖣 .ι_glued_iso_inv (PresheafedSpace.forget _) j), coe_comp, coe_comp, set.image_comp, set.preimage_comp, set.preimage_image_eq], refine eq.trans (D.to_Top_glue_data.preimage_image_eq_image' _ _ _) _, rw [coe_comp, set.image_comp], congr' 1, erw set.eq_preimage_iff_image_eq, rw ← set.image_comp, change (D.t i j ≫ D.t j i).base '' _ = _, rw 𝖣 .t_inv, { simp }, { change function.bijective (Top.homeo_of_iso (as_iso _)), exact homeomorph.bijective _, apply_instance }, { rw ← Top.mono_iff_injective, apply_instance } end /-- (Implementation). The map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_{U_j}, 𝖣.ι j ⁻¹' (𝖣.ι i '' U))` -/ def opens_image_preimage_map (i j : D.J) (U : opens (D.U i).carrier) : (D.U i).presheaf.obj (op U) ⟶ (D.U j).presheaf.obj _ := (D.f i j).c.app (op U) ≫ (D.t j i).c.app _ ≫ (D.f_open j i).inv_app (unop _) ≫ (𝖣 .U j).presheaf.map (eq_to_hom (D.ι_image_preimage_eq i j U)).op lemma opens_image_preimage_map_app' (i j k : D.J) (U : opens (D.U i).carrier) : ∃ eq, D.opens_image_preimage_map i j U ≫ (D.f j k).c.app _ = ((π₁ j, i, k) ≫ D.t j i ≫ D.f i j).c.app (op U) ≫ (π₂⁻¹ j, i, k) (unop _) ≫ (D.V (j, k)).presheaf.map (eq_to_hom eq) := begin split, delta opens_image_preimage_map, simp_rw category.assoc, rw [(D.f j k).c.naturality, f_inv_app_f_app_assoc], erw ← (D.V (j, k)).presheaf.map_comp, simp_rw ← category.assoc, erw [← comp_c_app, ← comp_c_app], simp_rw category.assoc, dsimp only [functor.op, unop_op, quiver.hom.unop_op], rw [eq_to_hom_map (opens.map _), eq_to_hom_op, eq_to_hom_trans], congr end /-- The red and the blue arrows in ![this diagram](https://i.imgur.com/mBzV1Rx.png) commute. -/ lemma opens_image_preimage_map_app (i j k : D.J) (U : opens (D.U i).carrier) : D.opens_image_preimage_map i j U ≫ (D.f j k).c.app _ = ((π₁ j, i, k) ≫ D.t j i ≫ D.f i j).c.app (op U) ≫ (π₂⁻¹ j, i, k) (unop _) ≫ (D.V (j, k)).presheaf.map (eq_to_hom ((opens_image_preimage_map_app' D i j k U).some)) := (opens_image_preimage_map_app' D i j k U).some_spec -- This is proved separately since `reassoc` somehow timeouts. lemma opens_image_preimage_map_app_assoc (i j k : D.J) (U : opens (D.U i).carrier) {X' : C} (f' : _ ⟶ X') : D.opens_image_preimage_map i j U ≫ (D.f j k).c.app _ ≫ f' = ((π₁ j, i, k) ≫ D.t j i ≫ D.f i j).c.app (op U) ≫ (π₂⁻¹ j, i, k) (unop _) ≫ (D.V (j, k)).presheaf.map (eq_to_hom ((opens_image_preimage_map_app' D i j k U).some)) ≫ f' := by simpa only [category.assoc] using congr_arg (λ g, g ≫ f') (opens_image_preimage_map_app D i j k U) /-- (Implementation) Given an open subset of one of the spaces `U ⊆ Uᵢ`, the sheaf component of the image `ι '' U` in the glued space is the limit of this diagram. -/ abbreviation diagram_over_open {i : D.J} (U : opens (D.U i).carrier) : (walking_multispan _ _)ᵒᵖ ⥤ C := componentwise_diagram 𝖣 .diagram.multispan ((D.ι_open_embedding i).is_open_map.functor.obj U) /-- (Implementation) The projection from the limit of `diagram_over_open` to a component of `D.U j`. -/ abbreviation diagram_over_open_π {i : D.J} (U : opens (D.U i).carrier) (j : D.J) := limit.π (D.diagram_over_open U) (op (walking_multispan.right j)) /-- (Implementation) We construct the map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_V, U_V)` for each `V` in the gluing diagram. We will lift these maps into `ι_inv_app`. -/ def ι_inv_app_π_app {i : D.J} (U : opens (D.U i).carrier) (j) : (𝖣 .U i).presheaf.obj (op U) ⟶ (D.diagram_over_open U).obj (op j) := begin rcases j with (⟨j, k⟩|j), { refine D.opens_image_preimage_map i j U ≫ (D.f j k).c.app _ ≫ (D.V (j, k)).presheaf.map (eq_to_hom _), rw [functor.op_obj], congr' 1, ext1, dsimp only [functor.op_obj, opens.map_coe, unop_op, is_open_map.functor_obj_coe], rw set.preimage_preimage, change (D.f j k ≫ 𝖣 .ι j).base ⁻¹' _ = _, congr' 3, exact colimit.w 𝖣 .diagram.multispan (walking_multispan.hom.fst (j, k)) }, { exact D.opens_image_preimage_map i j U } end /-- (Implementation) The natural map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_X, 𝖣.ι i '' U)`. This forms the inverse of `(𝖣.ι i).c.app (op U)`. -/ def ι_inv_app {i : D.J} (U : opens (D.U i).carrier) : (D.U i).presheaf.obj (op U) ⟶ limit (D.diagram_over_open U) := limit.lift (D.diagram_over_open U) { X := (D.U i).presheaf.obj (op U), π := { app := λ j, D.ι_inv_app_π_app U (unop j), naturality' := λ X Y f', begin induction X using opposite.rec, induction Y using opposite.rec, let f : Y ⟶ X := f'.unop, have : f' = f.op := rfl, clear_value f, subst this, rcases f with (_|⟨j,k⟩|⟨j,k⟩), { erw [category.id_comp, category_theory.functor.map_id], rw category.comp_id }, { erw category.id_comp, congr' 1 }, erw category.id_comp, -- It remains to show that the blue is equal to red + green in the original diagram. -- The proof strategy is illustrated in ![this diagram](https://i.imgur.com/mBzV1Rx.png) -- where we prove red = pink = light-blue = green = blue. change D.opens_image_preimage_map i j U ≫ (D.f j k).c.app _ ≫ (D.V (j, k)).presheaf.map (eq_to_hom _) = D.opens_image_preimage_map _ _ _ ≫ ((D.f k j).c.app _ ≫ (D.t j k).c.app _) ≫ (D.V (j, k)).presheaf.map (eq_to_hom _), erw opens_image_preimage_map_app_assoc, simp_rw category.assoc, erw [opens_image_preimage_map_app_assoc, (D.t j k).c.naturality_assoc], rw snd_inv_app_t_app_assoc, erw ← PresheafedSpace.comp_c_app_assoc, -- light-blue = green is relatively easy since the part that differs does not involve -- partial inverses. have : D.t' j k i ≫ (π₁ k, i, j) ≫ D.t k i ≫ 𝖣 .f i k = (pullback_symmetry _ _).hom ≫ (π₁ j, i, k) ≫ D.t j i ≫ D.f i j, { rw [← 𝖣 .t_fac_assoc, 𝖣 .t'_comp_eq_pullback_symmetry_assoc, pullback_symmetry_hom_comp_snd_assoc, pullback.condition, 𝖣 .t_fac_assoc] }, rw congr_app this, erw PresheafedSpace.comp_c_app_assoc (pullback_symmetry _ _).hom, simp_rw category.assoc, congr' 1, rw ← is_iso.eq_inv_comp, erw is_open_immersion.inv_inv_app, simp_rw category.assoc, erw [nat_trans.naturality_assoc, ← PresheafedSpace.comp_c_app_assoc, congr_app (pullback_symmetry_hom_comp_snd _ _)], simp_rw category.assoc, erw [is_open_immersion.inv_naturality_assoc, is_open_immersion.inv_naturality_assoc, is_open_immersion.inv_naturality_assoc, is_open_immersion.app_inv_app_assoc], repeat { erw ← (D.V (j, k)).presheaf.map_comp }, congr, end } } /-- `ι_inv_app` is the left inverse of `D.ι i` on `U`. -/ lemma ι_inv_app_π {i : D.J} (U : opens (D.U i).carrier) : ∃ eq, D.ι_inv_app U ≫ D.diagram_over_open_π U i = (D.U i).presheaf.map (eq_to_hom eq) := begin split, delta ι_inv_app, rw limit.lift_π, change D.opens_image_preimage_map i i U = _, dsimp [opens_image_preimage_map], rw [congr_app (D.t_id _), id_c_app, ← functor.map_comp], erw [is_open_immersion.inv_naturality_assoc, is_open_immersion.app_inv_app'_assoc], simp only [eq_to_hom_op, eq_to_hom_trans, eq_to_hom_map (functor.op _), ← functor.map_comp], rw set.range_iff_surjective.mpr _, { simp }, { rw ← Top.epi_iff_surjective, apply_instance } end /-- The `eq_to_hom` given by `ι_inv_app_π`. -/ abbreviation ι_inv_app_π_eq_map {i : D.J} (U : opens (D.U i).carrier) := (D.U i).presheaf.map (eq_to_iso (D.ι_inv_app_π U).some).inv /-- `ι_inv_app` is the right inverse of `D.ι i` on `U`. -/ lemma π_ι_inv_app_π (i j : D.J) (U : opens (D.U i).carrier) : D.diagram_over_open_π U i ≫ D.ι_inv_app_π_eq_map U ≫ D.ι_inv_app U ≫ D.diagram_over_open_π U j = D.diagram_over_open_π U j := begin rw ← cancel_mono ((componentwise_diagram 𝖣 .diagram.multispan _).map (quiver.hom.op (walking_multispan.hom.snd (i, j))) ≫ (𝟙 _)), simp_rw category.assoc, rw limit.w_assoc, erw limit.lift_π_assoc, rw [category.comp_id, category.comp_id], change _ ≫ _ ≫ (_ ≫ _) ≫ _ = _, rw [congr_app (D.t_id _), id_c_app], simp_rw category.assoc, rw [← functor.map_comp_assoc, is_open_immersion.inv_naturality_assoc], erw is_open_immersion.app_inv_app_assoc, iterate 3 { rw ← functor.map_comp_assoc }, rw nat_trans.naturality_assoc, erw ← (D.V (i, j)).presheaf.map_comp, convert limit.w (componentwise_diagram 𝖣 .diagram.multispan _) (quiver.hom.op (walking_multispan.hom.fst (i, j))), { rw category.comp_id, apply_with mono_comp { instances := ff }, change mono ((_ ≫ D.f j i).c.app _), rw comp_c_app, apply_with mono_comp { instances := ff }, erw D.ι_image_preimage_eq i j U, all_goals { apply_instance } }, end /-- `ι_inv_app` is the inverse of `D.ι i` on `U`. -/ lemma π_ι_inv_app_eq_id (i : D.J) (U : opens (D.U i).carrier) : D.diagram_over_open_π U i ≫ D.ι_inv_app_π_eq_map U ≫ D.ι_inv_app U = 𝟙 _ := begin ext j, induction j using opposite.rec, rcases j with (⟨j, k⟩|⟨j⟩), { rw [← limit.w (componentwise_diagram 𝖣 .diagram.multispan _) (quiver.hom.op (walking_multispan.hom.fst (j, k))), ← category.assoc, category.id_comp], congr' 1, simp_rw category.assoc, apply π_ι_inv_app_π }, { simp_rw category.assoc, rw category.id_comp, apply π_ι_inv_app_π } end instance componentwise_diagram_π_is_iso (i : D.J) (U : opens (D.U i).carrier) : is_iso (D.diagram_over_open_π U i) := begin use D.ι_inv_app_π_eq_map U ≫ D.ι_inv_app U, split, { apply π_ι_inv_app_eq_id }, { rw [category.assoc, (D.ι_inv_app_π _).some_spec], exact iso.inv_hom_id ((D.to_glue_data.U i).presheaf.map_iso (eq_to_iso _)) } end instance ι_is_open_immersion (i : D.J) : is_open_immersion (𝖣 .ι i) := { base_open := D.ι_open_embedding i, c_iso := λ U, by { erw ← colimit_presheaf_obj_iso_componentwise_limit_hom_π, apply_instance } } /-- The following diagram is a pullback, i.e. `Vᵢⱼ` is the intersection of `Uᵢ` and `Uⱼ` in `X`. Vᵢⱼ ⟶ Uᵢ | | ↓ ↓ Uⱼ ⟶ X -/ def V_pullback_cone_is_limit (i j : D.J) : is_limit (𝖣 .V_pullback_cone i j) := pullback_cone.is_limit_aux' _ $ λ s, begin refine ⟨_, _, _, _⟩, { refine PresheafedSpace.is_open_immersion.lift (D.f i j) s.fst _, erw ← D.to_Top_glue_data.preimage_range j i, have : s.fst.base ≫ D.to_Top_glue_data.to_glue_data.ι i = s.snd.base ≫ D.to_Top_glue_data.to_glue_data.ι j, { rw [← 𝖣 .ι_glued_iso_hom (PresheafedSpace.forget _) _, ← 𝖣 .ι_glued_iso_hom (PresheafedSpace.forget _) _], have := congr_arg PresheafedSpace.hom.base s.condition, rw [comp_base, comp_base] at this, reassoc! this, exact this _ }, rw [← set.image_subset_iff, ← set.image_univ, ← set.image_comp, set.image_univ, ← coe_comp, this, coe_comp, ← set.image_univ, set.image_comp], exact set.image_subset_range _ _ }, { apply is_open_immersion.lift_fac }, { rw [← cancel_mono (𝖣 .ι j), category.assoc, ← (𝖣 .V_pullback_cone i j).condition], conv_rhs { rw ← s.condition }, erw is_open_immersion.lift_fac_assoc }, { intros m e₁ e₂, rw ← cancel_mono (D.f i j), erw e₁, rw is_open_immersion.lift_fac } end lemma ι_jointly_surjective (x : 𝖣 .glued) : ∃ (i : D.J) (y : D.U i), (𝖣 .ι i).base y = x := 𝖣 .ι_jointly_surjective (PresheafedSpace.forget _ ⋙ category_theory.forget Top) x end glue_data end PresheafedSpace namespace SheafedSpace variables (C) [has_products.{v} C] /-- A family of gluing data consists of 1. An index type `J` 2. A sheafed space `U i` for each `i : J`. 3. A sheafed space `V i j` for each `i j : J`. (Note that this is `J × J → SheafedSpace C` rather than `J → J → SheafedSpace C` to connect to the limits library easier.) 4. An open immersion `f i j : V i j ⟶ U i` for each `i j : ι`. 5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some `t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`. 9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`. We can then glue the spaces `U i` together by identifying `V i j` with `V j i`, such that the `U i`'s are open subspaces of the glued space. -/ @[nolint has_nonempty_instance] structure glue_data extends glue_data (SheafedSpace.{v} C) := (f_open : ∀ i j, SheafedSpace.is_open_immersion (f i j)) attribute [instance] glue_data.f_open namespace glue_data variables {C} (D : glue_data C) local notation `𝖣` := D.to_glue_data /-- The glue data of presheafed spaces associated to a family of glue data of sheafed spaces. -/ abbreviation to_PresheafedSpace_glue_data : PresheafedSpace.glue_data C := { f_open := D.f_open, to_glue_data := 𝖣 .map_glue_data forget_to_PresheafedSpace } variable [has_limits C] /-- The gluing as sheafed spaces is isomorphic to the gluing as presheafed spaces. -/ abbreviation iso_PresheafedSpace : 𝖣 .glued.to_PresheafedSpace ≅ D.to_PresheafedSpace_glue_data.to_glue_data.glued := 𝖣 .glued_iso forget_to_PresheafedSpace lemma ι_iso_PresheafedSpace_inv (i : D.J) : D.to_PresheafedSpace_glue_data.to_glue_data.ι i ≫ D.iso_PresheafedSpace.inv = 𝖣 .ι i := 𝖣 .ι_glued_iso_inv _ _ instance ι_is_open_immersion (i : D.J) : is_open_immersion (𝖣 .ι i) := by { rw ← D.ι_iso_PresheafedSpace_inv, apply_instance } lemma ι_jointly_surjective (x : 𝖣 .glued) : ∃ (i : D.J) (y : D.U i), (𝖣 .ι i).base y = x := 𝖣 .ι_jointly_surjective (SheafedSpace.forget _ ⋙ category_theory.forget Top) x /-- The following diagram is a pullback, i.e. `Vᵢⱼ` is the intersection of `Uᵢ` and `Uⱼ` in `X`. Vᵢⱼ ⟶ Uᵢ | | ↓ ↓ Uⱼ ⟶ X -/ def V_pullback_cone_is_limit (i j : D.J) : is_limit (𝖣 .V_pullback_cone i j) := 𝖣 .V_pullback_cone_is_limit_of_map forget_to_PresheafedSpace i j (D.to_PresheafedSpace_glue_data.V_pullback_cone_is_limit _ _) end glue_data end SheafedSpace namespace LocallyRingedSpace /-- A family of gluing data consists of 1. An index type `J` 2. A locally ringed space `U i` for each `i : J`. 3. A locally ringed space `V i j` for each `i j : J`. (Note that this is `J × J → LocallyRingedSpace` rather than `J → J → LocallyRingedSpace` to connect to the limits library easier.) 4. An open immersion `f i j : V i j ⟶ U i` for each `i j : ι`. 5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some `t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`. 9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`. We can then glue the spaces `U i` together by identifying `V i j` with `V j i`, such that the `U i`'s are open subspaces of the glued space. -/ @[nolint has_nonempty_instance] structure glue_data extends glue_data LocallyRingedSpace := (f_open : ∀ i j, LocallyRingedSpace.is_open_immersion (f i j)) attribute [instance] glue_data.f_open namespace glue_data variables (D : glue_data) local notation `𝖣` := D.to_glue_data /-- The glue data of ringed spaces associated to a family of glue data of locally ringed spaces. -/ abbreviation to_SheafedSpace_glue_data : SheafedSpace.glue_data CommRing := { f_open := D.f_open, to_glue_data := 𝖣 .map_glue_data forget_to_SheafedSpace } /-- The gluing as locally ringed spaces is isomorphic to the gluing as ringed spaces. -/ abbreviation iso_SheafedSpace : 𝖣 .glued.to_SheafedSpace ≅ D.to_SheafedSpace_glue_data.to_glue_data.glued := 𝖣 .glued_iso forget_to_SheafedSpace lemma ι_iso_SheafedSpace_inv (i : D.J) : D.to_SheafedSpace_glue_data.to_glue_data.ι i ≫ D.iso_SheafedSpace.inv = (𝖣 .ι i).1 := 𝖣 .ι_glued_iso_inv forget_to_SheafedSpace i instance ι_is_open_immersion (i : D.J) : is_open_immersion (𝖣 .ι i) := by { delta is_open_immersion, rw ← D.ι_iso_SheafedSpace_inv, apply PresheafedSpace.is_open_immersion.comp } instance (i j k : D.J) : preserves_limit (cospan (𝖣 .f i j) (𝖣 .f i k)) forget_to_SheafedSpace := infer_instance lemma ι_jointly_surjective (x : 𝖣 .glued) : ∃ (i : D.J) (y : D.U i), (𝖣 .ι i).1.base y = x := 𝖣 .ι_jointly_surjective ((LocallyRingedSpace.forget_to_SheafedSpace ⋙ SheafedSpace.forget _) ⋙ forget Top) x /-- The following diagram is a pullback, i.e. `Vᵢⱼ` is the intersection of `Uᵢ` and `Uⱼ` in `X`. Vᵢⱼ ⟶ Uᵢ | | ↓ ↓ Uⱼ ⟶ X -/ def V_pullback_cone_is_limit (i j : D.J) : is_limit (𝖣 .V_pullback_cone i j) := 𝖣 .V_pullback_cone_is_limit_of_map forget_to_SheafedSpace i j (D.to_SheafedSpace_glue_data.V_pullback_cone_is_limit _ _) end glue_data end LocallyRingedSpace end algebraic_geometry
9f4cfaaf3e329adfb05c35d1413c5f58fd2329d5
bb31430994044506fa42fd667e2d556327e18dfe
/src/data/int/dvd/pow.lean
1c74d4e8d51a7fd28ac724961e0eb9158267e84a
[ "Apache-2.0" ]
permissive
sgouezel/mathlib
0cb4e5335a2ba189fa7af96d83a377f83270e503
00638177efd1b2534fc5269363ebf42a7871df9a
refs/heads/master
1,674,527,483,042
1,673,665,568,000
1,673,665,568,000
119,598,202
0
0
null
1,517,348,647,000
1,517,348,646,000
null
UTF-8
Lean
false
false
1,265
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import data.int.dvd.basic import data.nat.pow /-! # Basic lemmas about the divisibility relation in `ℤ` involving powers. > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. -/ open nat namespace int @[simp] theorem sign_pow_bit1 (k : ℕ) : ∀ n : ℤ, n.sign ^ (bit1 k) = n.sign | (n+1:ℕ) := one_pow (bit1 k) | 0 := zero_pow (nat.zero_lt_bit1 k) | -[1+ n] := (neg_pow_bit1 1 k).trans (congr_arg (λ x, -x) (one_pow (bit1 k))) lemma pow_dvd_of_le_of_pow_dvd {p m n : ℕ} {k : ℤ} (hmn : m ≤ n) (hdiv : ↑(p ^ n) ∣ k) : ↑(p ^ m) ∣ k := begin induction k, { apply int.coe_nat_dvd.2, apply pow_dvd_of_le_of_pow_dvd hmn, apply int.coe_nat_dvd.1 hdiv }, change -[1+k] with -(↑(k+1) : ℤ), apply dvd_neg_of_dvd, apply int.coe_nat_dvd.2, apply pow_dvd_of_le_of_pow_dvd hmn, apply int.coe_nat_dvd.1, apply dvd_of_dvd_neg, exact hdiv, end 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 end int